diff --git a/packages/core/src/modules/basic-messages/BasicMessageEvents.ts b/packages/core/src/modules/basic-messages/BasicMessageEvents.ts index 31ba778bf2..7c25f5b9c4 100644 --- a/packages/core/src/modules/basic-messages/BasicMessageEvents.ts +++ b/packages/core/src/modules/basic-messages/BasicMessageEvents.ts @@ -3,11 +3,10 @@ import type { BasicMessage } from './messages' import type { BasicMessageRecord } from './repository' export enum BasicMessageEventTypes { - BasicMessageReceived = 'BasicMessageReceived', + BasicMessageStateChanged = 'BasicMessageStateChanged', } - -export interface BasicMessageReceivedEvent extends BaseEvent { - type: typeof BasicMessageEventTypes.BasicMessageReceived +export interface BasicMessageStateChangedEvent extends BaseEvent { + type: typeof BasicMessageEventTypes.BasicMessageStateChanged payload: { message: BasicMessage basicMessageRecord: BasicMessageRecord diff --git a/packages/core/src/modules/basic-messages/__tests__/BasicMessageService.test.ts b/packages/core/src/modules/basic-messages/__tests__/BasicMessageService.test.ts index 4eeb72bf14..79f5ccbd12 100644 --- a/packages/core/src/modules/basic-messages/__tests__/BasicMessageService.test.ts +++ b/packages/core/src/modules/basic-messages/__tests__/BasicMessageService.test.ts @@ -1,6 +1,6 @@ import type { AgentConfig } from '../../../agent/AgentConfig' import type { StorageService } from '../../../storage/StorageService' -import type { BasicMessageReceivedEvent } from '../BasicMessageEvents' +import type { BasicMessageStateChangedEvent } from '../BasicMessageEvents' import { getAgentConfig, getMockConnection } from '../../../../tests/helpers' import { EventEmitter } from '../../../agent/EventEmitter' @@ -50,7 +50,7 @@ describe('BasicMessageService', () => { it(`emits newMessage with message and basic message record`, async () => { const eventListenerMock = jest.fn() - eventEmitter.on(BasicMessageEventTypes.BasicMessageReceived, eventListenerMock) + eventEmitter.on(BasicMessageEventTypes.BasicMessageStateChanged, eventListenerMock) const basicMessage = new BasicMessage({ id: '123', @@ -65,7 +65,7 @@ describe('BasicMessageService', () => { await basicMessageService.save(messageContext, mockConnectionRecord) expect(eventListenerMock).toHaveBeenCalledWith({ - type: 'BasicMessageReceived', + type: 'BasicMessageStateChanged', payload: { basicMessageRecord: expect.objectContaining({ connectionId: mockConnectionRecord.id, diff --git a/packages/core/src/modules/basic-messages/services/BasicMessageService.ts b/packages/core/src/modules/basic-messages/services/BasicMessageService.ts index 31e7b2b232..9f08c0d471 100644 --- a/packages/core/src/modules/basic-messages/services/BasicMessageService.ts +++ b/packages/core/src/modules/basic-messages/services/BasicMessageService.ts @@ -1,6 +1,6 @@ import type { InboundMessageContext } from '../../../agent/models/InboundMessageContext' import type { ConnectionRecord } from '../../connections/repository/ConnectionRecord' -import type { BasicMessageReceivedEvent } from '../BasicMessageEvents' +import type { BasicMessageStateChangedEvent } from '../BasicMessageEvents' import type { BasicMessageTags } from '../repository' import { Lifecycle, scoped } from 'tsyringe' @@ -33,6 +33,10 @@ export class BasicMessageService { }) await this.basicMessageRepository.save(basicMessageRecord) + this.eventEmitter.emit({ + type: BasicMessageEventTypes.BasicMessageStateChanged, + payload: { message: basicMessage, basicMessageRecord }, + }) return basicMessage } @@ -50,8 +54,8 @@ export class BasicMessageService { }) await this.basicMessageRepository.save(basicMessageRecord) - this.eventEmitter.emit({ - type: BasicMessageEventTypes.BasicMessageReceived, + this.eventEmitter.emit({ + type: BasicMessageEventTypes.BasicMessageStateChanged, payload: { message, basicMessageRecord }, }) } diff --git a/packages/core/tests/helpers.ts b/packages/core/tests/helpers.ts index d5e05f3680..3d3c67e950 100644 --- a/packages/core/tests/helpers.ts +++ b/packages/core/tests/helpers.ts @@ -2,7 +2,7 @@ import type { SubjectMessage } from '../../../tests/transport/SubjectInboundTran import type { AutoAcceptProof, BasicMessage, - BasicMessageReceivedEvent, + BasicMessageStateChangedEvent, ConnectionRecordProps, CredentialDefinitionTemplate, CredentialOfferTemplate, @@ -184,17 +184,17 @@ export async function waitForCredentialRecord( export async function waitForBasicMessage(agent: Agent, { content }: { content?: string }): Promise { return new Promise((resolve) => { - const listener = (event: BasicMessageReceivedEvent) => { + const listener = (event: BasicMessageStateChangedEvent) => { const contentMatches = content === undefined || event.payload.message.content === content if (contentMatches) { - agent.events.off(BasicMessageEventTypes.BasicMessageReceived, listener) + agent.events.off(BasicMessageEventTypes.BasicMessageStateChanged, listener) resolve(event.payload.message) } } - agent.events.on(BasicMessageEventTypes.BasicMessageReceived, listener) + agent.events.on(BasicMessageEventTypes.BasicMessageStateChanged, listener) }) }