Skip to content

Commit

Permalink
fix participant matching
Browse files Browse the repository at this point in the history
  • Loading branch information
bosiraphael committed Aug 20, 2024
1 parent 3ef6831 commit cd3a285
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,6 @@ export class CalendarSaveEventsService {
);
});

this.workspaceEventEmitter.emit(
`calendarEventParticipant.matched`,
[
{
workspaceMemberId: connectedAccount.accountOwnerId,
participants: savedCalendarEventParticipantsToEmit,
},
],
workspaceId,
);

if (calendarChannel.isContactAutoCreationEnabled) {
await this.messageQueueService.add<CreateCompanyAndContactJobData>(
CreateCompanyAndContactJob.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Repository } from 'typeorm';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/workspace-event.type';
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
import { TimelineActivityRepository } from 'src/modules/timeline/repositiories/timeline-activity.repository';
import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity';
Expand All @@ -22,50 +23,54 @@ export class MessageParticipantListener {
) {}

@OnEvent('messageParticipant.matched')
public async handleMessageParticipantMatched(payload: {
workspaceId: string;
workspaceMemberId: string;
participants: MessageParticipantWorkspaceEntity[];
}): Promise<void> {
const messageParticipants = payload.participants ?? [];
public async handleMessageParticipantMatched(
payload: WorkspaceEventBatch<{
workspaceMemberId: string;
participants: MessageParticipantWorkspaceEntity[];
}>,
): Promise<void> {
// TODO: Refactor to insertTimelineActivitiesForObject once
for (const eventPayload of payload.events) {
const messageParticipants = eventPayload.participants ?? [];

// TODO: move to a job?
// TODO: move to a job?

const dataSourceSchema = this.workspaceDataSourceService.getSchemaName(
payload.workspaceId,
);
const dataSourceSchema = this.workspaceDataSourceService.getSchemaName(
payload.workspaceId,
);

const messageObjectMetadata =
await this.objectMetadataRepository.findOneOrFail({
where: {
nameSingular: 'message',
workspaceId: payload.workspaceId,
},
});
const messageObjectMetadata =
await this.objectMetadataRepository.findOneOrFail({
where: {
nameSingular: 'message',
workspaceId: payload.workspaceId,
},
});

const messageParticipantsWithPersonId = messageParticipants.filter(
(participant) => participant.personId,
);
const messageParticipantsWithPersonId = messageParticipants.filter(
(participant) => participant.personId,
);

if (messageParticipantsWithPersonId.length === 0) {
return;
}
if (messageParticipantsWithPersonId.length === 0) {
return;
}

await this.timelineActivityRepository.insertTimelineActivitiesForObject(
'person',
messageParticipantsWithPersonId.map((participant) => ({
dataSourceSchema,
name: 'message.linked',
properties: null,
objectName: 'message',
recordId: participant.personId,
workspaceMemberId: payload.workspaceMemberId,
workspaceId: payload.workspaceId,
linkedObjectMetadataId: messageObjectMetadata.id,
linkedRecordId: participant.messageId,
linkedRecordCachedName: '',
})),
payload.workspaceId,
);
await this.timelineActivityRepository.insertTimelineActivitiesForObject(
'person',
messageParticipantsWithPersonId.map((participant) => ({
dataSourceSchema,
name: 'message.linked',
properties: null,
objectName: 'message',
recordId: participant.personId,
workspaceMemberId: eventPayload.workspaceMemberId,
workspaceId: payload.workspaceId,
linkedObjectMetadataId: messageObjectMetadata.id,
linkedRecordId: participant.messageId,
linkedRecordCachedName: '',
})),
payload.workspaceId,
);
}
}
}

0 comments on commit cd3a285

Please sign in to comment.