Skip to content

Commit

Permalink
fix: thread id improvements (openwallet-foundation#1311)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra authored Feb 17, 2023
1 parent 1d782f5 commit 229ed1b
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 18 deletions.
8 changes: 4 additions & 4 deletions packages/action-menu/src/services/ActionMenuService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class ActionMenuService {
connectionId: options.connection.id,
role: ActionMenuRole.Requester,
state: ActionMenuState.AwaitingRootMenu,
threadId: menuRequestMessage.id,
threadId: menuRequestMessage.threadId,
})

await this.actionMenuRepository.save(agentContext, actionMenuRecord)
Expand Down Expand Up @@ -102,7 +102,7 @@ export class ActionMenuService {
connectionId: connection.id,
role: ActionMenuRole.Responder,
state: ActionMenuState.PreparingRootMenu,
threadId: menuRequestMessage.id,
threadId: menuRequestMessage.threadId,
})

await this.actionMenuRepository.save(agentContext, actionMenuRecord)
Expand Down Expand Up @@ -157,7 +157,7 @@ export class ActionMenuService {
role: ActionMenuRole.Responder,
state: ActionMenuState.AwaitingSelection,
menu: options.menu,
threadId: menuMessage.id,
threadId: menuMessage.threadId,
})

await this.actionMenuRepository.save(agentContext, actionMenuRecord)
Expand Down Expand Up @@ -203,7 +203,7 @@ export class ActionMenuService {
connectionId: connection.id,
role: ActionMenuRole.Requester,
state: ActionMenuState.PreparingSelection,
threadId: menuMessage.id,
threadId: menuMessage.threadId,
menu: new ActionMenu({
title: menuMessage.title,
description: menuMessage.description,
Expand Down
19 changes: 16 additions & 3 deletions packages/core/src/agent/Dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { InjectionSymbols } from '../constants'
import { AriesFrameworkError } from '../error/AriesFrameworkError'
import { Logger } from '../logger'
import { injectable, inject } from '../plugins'
import { parseMessageType } from '../utils/messageType'

import { ProblemReportMessage } from './../modules/problem-reports/messages/ProblemReportMessage'
import { EventEmitter } from './EventEmitter'
Expand Down Expand Up @@ -57,9 +58,21 @@ class Dispatcher {
const problemReportMessage = error.problemReport

if (problemReportMessage instanceof ProblemReportMessage && messageContext.connection) {
problemReportMessage.setThread({
threadId: message.threadId,
})
const { protocolUri: problemReportProtocolUri } = parseMessageType(problemReportMessage.type)
const { protocolUri: inboundProtocolUri } = parseMessageType(messageContext.message.type)

// If the inbound protocol uri is the same as the problem report protocol uri, we can see the interaction as the same thread
// However if it is no the same we should see it as a new thread, where the inbound message `@id` is the parentThreadId
if (inboundProtocolUri === problemReportProtocolUri) {
problemReportMessage.setThread({
threadId: message.threadId,
})
} else {
problemReportMessage.setThread({
parentThreadId: message.id,
})
}

outboundMessage = new OutboundMessageContext(problemReportMessage, {
agentContext,
connection: messageContext.connection,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/agent/MessageReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export class MessageReceiver {
},
})
problemReportMessage.setThread({
threadId: plaintextMessage['@id'],
parentThreadId: plaintextMessage['@id'],
})
const outboundMessageContext = new OutboundMessageContext(problemReportMessage, { agentContext, connection })
if (outboundMessageContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class DidExchangeRequestMessage extends AgentMessage {
this.did = options.did

this.setThread({
threadId: this.id,
parentThreadId: options.parentThreadId,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class ConnectionService {
})

connectionRequest.setThread({
threadId: connectionRequest.id,
threadId: connectionRequest.threadId,
parentThreadId: outOfBandInvitation.id,
})

Expand All @@ -136,7 +136,7 @@ export class ConnectionService {
outOfBandId: outOfBandRecord.id,
invitationDid,
imageUrl: outOfBandInvitation.imageUrl,
threadId: connectionRequest.id,
threadId: connectionRequest.threadId,
})

await this.updateState(agentContext, connectionRecord, DidExchangeState.RequestSent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class TrustPingService {

if (message.responseRequested) {
const response = new TrustPingResponseMessage({
threadId: message.id,
threadId: message.threadId,
})

return new OutboundMessageContext(response, { agentContext, connection })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ export class V1CredentialProtocol
// No credential record exists with thread id
credentialRecord = new CredentialExchangeRecord({
connectionId: connection?.id,
threadId: offerMessage.id,
threadId: offerMessage.threadId,
state: CredentialState.OfferReceived,
protocolVersion: 'v1',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class HandshakeReuseMessage extends AgentMessage {
if (options) {
this.id = options.id ?? this.generateId()
this.setThread({
threadId: this.id,
parentThreadId: options.parentThreadId,
})
}
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ export type ProtocolVersion = `${number}.${number}`
export interface PlaintextMessage {
'@type': string
'@id': string
'~thread'?: {
thid?: string
}
[key: string]: unknown
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class QuestionAnswerService {
const questionAnswerRecord = await this.createRecord({
questionText: questionMessage.questionText,
questionDetail: questionMessage.questionDetail,
threadId: questionMessage.id,
threadId: questionMessage.threadId,
connectionId: connectionId,
role: QuestionAnswerRole.Questioner,
signatureRequired: false,
Expand Down Expand Up @@ -97,7 +97,7 @@ export class QuestionAnswerService {
questionText: questionMessage.questionText,
questionDetail: questionMessage.questionDetail,
connectionId: connection?.id,
threadId: questionMessage.id,
threadId: questionMessage.threadId,
role: QuestionAnswerRole.Responder,
signatureRequired: false,
state: QuestionAnswerState.QuestionReceived,
Expand Down
4 changes: 2 additions & 2 deletions samples/extension-module/dummy/services/DummyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class DummyService {
// Create record
const record = new DummyRecord({
connectionId: connectionRecord.id,
threadId: message.id,
threadId: message.threadId,
state: DummyState.Init,
})

Expand Down Expand Up @@ -79,7 +79,7 @@ export class DummyService {
// Create record
const record = new DummyRecord({
connectionId: connectionRecord.id,
threadId: messageContext.message.id,
threadId: messageContext.message.threadId,
state: DummyState.RequestReceived,
})

Expand Down

0 comments on commit 229ed1b

Please sign in to comment.