From dc3e30b1154a8e3a562f4b8900cd4270b3835888 Mon Sep 17 00:00:00 2001 From: neo773 <62795688+neo773@users.noreply.github.com> Date: Fri, 21 Nov 2025 15:35:12 +0530 Subject: [PATCH] message channel change 5 (#15964) --- ...lendar-event-participant-manager.module.ts | 2 - ...eate-company-and-contact-after-sync.job.ts | 97 --------------- .../contact-creation-manager.module.ts | 4 - ...acts-creation-calendar-channel.listener.ts | 50 -------- ...tacts-creation-message-channel.listener.ts | 50 -------- ...eate-company-and-contact-after-sync.job.ts | 114 ------------------ .../message-participant-manager.module.ts | 2 - 7 files changed, 319 deletions(-) delete mode 100644 packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/jobs/calendar-create-company-and-contact-after-sync.job.ts delete mode 100644 packages/twenty-server/src/modules/contact-creation-manager/listeners/auto-companies-and-contacts-creation-calendar-channel.listener.ts delete mode 100644 packages/twenty-server/src/modules/contact-creation-manager/listeners/auto-companies-and-contacts-creation-message-channel.listener.ts delete mode 100644 packages/twenty-server/src/modules/messaging/message-participant-manager/jobs/messaging-create-company-and-contact-after-sync.job.ts diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/calendar-event-participant-manager.module.ts b/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/calendar-event-participant-manager.module.ts index 8ae649d1f4..23ff7bf34d 100644 --- a/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/calendar-event-participant-manager.module.ts +++ b/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/calendar-event-participant-manager.module.ts @@ -8,7 +8,6 @@ import { WorkspaceModule } from 'src/engine/core-modules/workspace/workspace.mod import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module'; -import { CalendarCreateCompanyAndPersonAfterSyncJob } from 'src/modules/calendar/calendar-event-participant-manager/jobs/calendar-create-company-and-contact-after-sync.job'; import { CalendarEventParticipantMatchParticipantJob } from 'src/modules/calendar/calendar-event-participant-manager/jobs/calendar-event-participant-match-participant.job'; import { CalendarEventParticipantPersonListener } from 'src/modules/calendar/calendar-event-participant-manager/listeners/calendar-event-participant-person.listener'; import { CalendarEventParticipantWorkspaceMemberListener } from 'src/modules/calendar/calendar-event-participant-manager/listeners/calendar-event-participant-workspace-member.listener'; @@ -28,7 +27,6 @@ import { MatchParticipantModule } from 'src/modules/match-participant/match-part ], providers: [ CalendarEventParticipantService, - CalendarCreateCompanyAndPersonAfterSyncJob, CalendarEventParticipantMatchParticipantJob, CalendarEventParticipantListener, CalendarEventParticipantPersonListener, diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/jobs/calendar-create-company-and-contact-after-sync.job.ts b/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/jobs/calendar-create-company-and-contact-after-sync.job.ts deleted file mode 100644 index 048448f1d5..0000000000 --- a/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/jobs/calendar-create-company-and-contact-after-sync.job.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { Scope } from '@nestjs/common'; - -import { IsNull } from 'typeorm'; -import { FieldActorSource } from 'twenty-shared/types'; - -import { Process } from 'src/engine/core-modules/message-queue/decorators/process.decorator'; -import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator'; -import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants'; -import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager'; -import { type CalendarChannelWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity'; -import { type CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity'; -import { CreateCompanyAndPersonService } from 'src/modules/contact-creation-manager/services/create-company-and-contact.service'; - -export type CalendarCreateCompanyAndPersonAfterSyncJobData = { - workspaceId: string; - calendarChannelId: string; -}; - -@Processor({ - queueName: MessageQueue.calendarQueue, - scope: Scope.REQUEST, -}) -export class CalendarCreateCompanyAndPersonAfterSyncJob { - constructor( - private readonly twentyORMManager: TwentyORMManager, - private readonly createCompanyAndPersonService: CreateCompanyAndPersonService, - ) {} - - @Process(CalendarCreateCompanyAndPersonAfterSyncJob.name) - async handle( - data: CalendarCreateCompanyAndPersonAfterSyncJobData, - ): Promise { - const { workspaceId, calendarChannelId } = data; - - const calendarChannelRepository = - await this.twentyORMManager.getRepository( - 'calendarChannel', - ); - - const calendarChannel = await calendarChannelRepository.findOne({ - where: { - id: calendarChannelId, - }, - relations: ['connectedAccount.accountOwner'], - }); - - if (!calendarChannel) { - throw new Error( - `Calendar channel with id ${calendarChannelId} not found in workspace ${workspaceId}`, - ); - } - - const { handle, isContactAutoCreationEnabled, connectedAccount } = - calendarChannel; - - if (!isContactAutoCreationEnabled || !handle) { - return; - } - - if (!connectedAccount) { - throw new Error( - `Connected account not found in workspace ${workspaceId}`, - ); - } - - const calendarEventParticipantRepository = - await this.twentyORMManager.getRepository( - 'calendarEventParticipant', - ); - - const calendarEventParticipantsWithoutPersonIdAndWorkspaceMemberId = - await calendarEventParticipantRepository.find({ - where: { - calendarEvent: { - calendarChannelEventAssociations: { - calendarChannelId, - }, - calendarEventParticipants: { - person: IsNull(), - workspaceMember: IsNull(), - }, - }, - }, - relations: [ - 'calendarEvent.calendarChannelEventAssociations', - 'calendarEvent.calendarEventParticipants', - ], - }); - - await this.createCompanyAndPersonService.createCompaniesAndPeopleAndUpdateParticipants( - connectedAccount, - calendarEventParticipantsWithoutPersonIdAndWorkspaceMemberId, - workspaceId, - FieldActorSource.CALENDAR, - ); - } -} diff --git a/packages/twenty-server/src/modules/contact-creation-manager/contact-creation-manager.module.ts b/packages/twenty-server/src/modules/contact-creation-manager/contact-creation-manager.module.ts index 0c905cd068..3dd45bf0a5 100644 --- a/packages/twenty-server/src/modules/contact-creation-manager/contact-creation-manager.module.ts +++ b/packages/twenty-server/src/modules/contact-creation-manager/contact-creation-manager.module.ts @@ -5,8 +5,6 @@ import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature- import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module'; -import { AutoCompaniesAndContactsCreationCalendarChannelListener } from 'src/modules/contact-creation-manager/listeners/auto-companies-and-contacts-creation-calendar-channel.listener'; -import { AutoCompaniesAndContactsCreationMessageChannelListener } from 'src/modules/contact-creation-manager/listeners/auto-companies-and-contacts-creation-message-channel.listener'; import { CreateCompanyAndPersonService } from 'src/modules/contact-creation-manager/services/create-company-and-contact.service'; import { CreateCompanyService } from 'src/modules/contact-creation-manager/services/create-company.service'; import { CreatePersonService } from 'src/modules/contact-creation-manager/services/create-person.service'; @@ -21,8 +19,6 @@ import { CreatePersonService } from 'src/modules/contact-creation-manager/servic CreateCompanyService, CreatePersonService, CreateCompanyAndPersonService, - AutoCompaniesAndContactsCreationMessageChannelListener, - AutoCompaniesAndContactsCreationCalendarChannelListener, ], exports: [CreateCompanyAndPersonService], }) diff --git a/packages/twenty-server/src/modules/contact-creation-manager/listeners/auto-companies-and-contacts-creation-calendar-channel.listener.ts b/packages/twenty-server/src/modules/contact-creation-manager/listeners/auto-companies-and-contacts-creation-calendar-channel.listener.ts deleted file mode 100644 index 46c473b1f7..0000000000 --- a/packages/twenty-server/src/modules/contact-creation-manager/listeners/auto-companies-and-contacts-creation-calendar-channel.listener.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { Injectable } from '@nestjs/common'; - -import { OnDatabaseBatchEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-batch-event.decorator'; -import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action'; -import { type ObjectRecordUpdateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-update.event'; -import { objectRecordChangedProperties } from 'src/engine/core-modules/event-emitter/utils/object-record-changed-properties.util'; -import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator'; -import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants'; -import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service'; -import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type'; -import { - CalendarCreateCompanyAndPersonAfterSyncJob, - CalendarCreateCompanyAndPersonAfterSyncJobData, -} from 'src/modules/calendar/calendar-event-participant-manager/jobs/calendar-create-company-and-contact-after-sync.job'; -import { type MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity'; - -@Injectable() -export class AutoCompaniesAndContactsCreationCalendarChannelListener { - constructor( - @InjectMessageQueue(MessageQueue.calendarQueue) - private readonly messageQueueService: MessageQueueService, - ) {} - - @OnDatabaseBatchEvent('calendarChannel', DatabaseEventAction.UPDATED) - async handleUpdatedEvent( - payload: WorkspaceEventBatch< - ObjectRecordUpdateEvent - >, - ) { - await Promise.all( - payload.events.map((eventPayload) => { - if ( - objectRecordChangedProperties( - eventPayload.properties.before, - eventPayload.properties.after, - ).includes('isContactAutoCreationEnabled') && - eventPayload.properties.after.isContactAutoCreationEnabled - ) { - return this.messageQueueService.add( - CalendarCreateCompanyAndPersonAfterSyncJob.name, - { - workspaceId: payload.workspaceId, - calendarChannelId: eventPayload.recordId, - }, - ); - } - }), - ); - } -} diff --git a/packages/twenty-server/src/modules/contact-creation-manager/listeners/auto-companies-and-contacts-creation-message-channel.listener.ts b/packages/twenty-server/src/modules/contact-creation-manager/listeners/auto-companies-and-contacts-creation-message-channel.listener.ts deleted file mode 100644 index 098d7f4f1c..0000000000 --- a/packages/twenty-server/src/modules/contact-creation-manager/listeners/auto-companies-and-contacts-creation-message-channel.listener.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { Injectable } from '@nestjs/common'; - -import { type ObjectRecordUpdateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-update.event'; -import { objectRecordChangedProperties } from 'src/engine/core-modules/event-emitter/utils/object-record-changed-properties.util'; -import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator'; -import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants'; -import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service'; -import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type'; -import { type MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity'; -import { - MessagingCreateCompanyAndContactAfterSyncJob, - type MessagingCreateCompanyAndContactAfterSyncJobData, -} from 'src/modules/messaging/message-participant-manager/jobs/messaging-create-company-and-contact-after-sync.job'; -import { OnDatabaseBatchEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-batch-event.decorator'; -import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action'; - -@Injectable() -export class AutoCompaniesAndContactsCreationMessageChannelListener { - constructor( - @InjectMessageQueue(MessageQueue.contactCreationQueue) - private readonly messageQueueService: MessageQueueService, - ) {} - - @OnDatabaseBatchEvent('messageChannel', DatabaseEventAction.UPDATED) - async handleUpdatedEvent( - payload: WorkspaceEventBatch< - ObjectRecordUpdateEvent - >, - ) { - await Promise.all( - payload.events.map((eventPayload) => { - if ( - objectRecordChangedProperties( - eventPayload.properties.before, - eventPayload.properties.after, - ).includes('isContactAutoCreationEnabled') && - eventPayload.properties.after.isContactAutoCreationEnabled - ) { - return this.messageQueueService.add( - MessagingCreateCompanyAndContactAfterSyncJob.name, - { - workspaceId: payload.workspaceId, - messageChannelId: eventPayload.recordId, - }, - ); - } - }), - ); - } -} diff --git a/packages/twenty-server/src/modules/messaging/message-participant-manager/jobs/messaging-create-company-and-contact-after-sync.job.ts b/packages/twenty-server/src/modules/messaging/message-participant-manager/jobs/messaging-create-company-and-contact-after-sync.job.ts deleted file mode 100644 index 2dec907e12..0000000000 --- a/packages/twenty-server/src/modules/messaging/message-participant-manager/jobs/messaging-create-company-and-contact-after-sync.job.ts +++ /dev/null @@ -1,114 +0,0 @@ -import { Logger } from '@nestjs/common'; - -import { Any, IsNull } from 'typeorm'; -import { FieldActorSource } from 'twenty-shared/types'; - -import { Process } from 'src/engine/core-modules/message-queue/decorators/process.decorator'; -import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator'; -import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants'; -import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager'; -import { type ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity'; -import { CreateCompanyAndPersonService } from 'src/modules/contact-creation-manager/services/create-company-and-contact.service'; -import { MessageDirection } from 'src/modules/messaging/common/enums/message-direction.enum'; -import { - MessageChannelContactAutoCreationPolicy, - type MessageChannelWorkspaceEntity, -} from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity'; -import { type MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity'; - -export type MessagingCreateCompanyAndContactAfterSyncJobData = { - workspaceId: string; - messageChannelId: string; -}; - -@Processor(MessageQueue.messagingQueue) -export class MessagingCreateCompanyAndContactAfterSyncJob { - private readonly logger = new Logger( - MessagingCreateCompanyAndContactAfterSyncJob.name, - ); - constructor( - private readonly createCompanyAndPersonService: CreateCompanyAndPersonService, - private readonly twentyORMManager: TwentyORMManager, - ) {} - - @Process(MessagingCreateCompanyAndContactAfterSyncJob.name) - async handle( - data: MessagingCreateCompanyAndContactAfterSyncJobData, - ): Promise { - this.logger.log( - `create people and companies after sync for workspace ${data.workspaceId} and messageChannel ${data.messageChannelId}`, - ); - const { workspaceId, messageChannelId } = data; - - const messageChannelRepository = - await this.twentyORMManager.getRepository( - 'messageChannel', - ); - - const messageChannel = await messageChannelRepository.findOneOrFail({ - where: { - id: messageChannelId, - }, - }); - - const { contactAutoCreationPolicy, connectedAccountId } = messageChannel; - - if ( - contactAutoCreationPolicy === MessageChannelContactAutoCreationPolicy.NONE - ) { - return; - } - - const connectedAccountRepository = - await this.twentyORMManager.getRepository( - 'connectedAccount', - ); - - const connectedAccount = await connectedAccountRepository.findOne({ - where: { - id: connectedAccountId, - }, - }); - - if (!connectedAccount) { - throw new Error( - `Connected account with id ${connectedAccountId} not found in workspace ${workspaceId}`, - ); - } - - const messageParticipantRepository = - await this.twentyORMManager.getRepository( - 'messageParticipant', - ); - - const directionFilter = - contactAutoCreationPolicy === - MessageChannelContactAutoCreationPolicy.SENT_AND_RECEIVED - ? Any([MessageDirection.INCOMING, MessageDirection.OUTGOING]) - : MessageDirection.OUTGOING; - - const contactsToCreate = await messageParticipantRepository.find({ - where: { - message: { - messageChannelMessageAssociations: { - messageChannelId, - direction: directionFilter, - }, - }, - personId: IsNull(), - workspaceMemberId: IsNull(), - }, - }); - - await this.createCompanyAndPersonService.createCompaniesAndPeopleAndUpdateParticipants( - connectedAccount, - contactsToCreate, - workspaceId, - FieldActorSource.EMAIL, - ); - - this.logger.log( - `create contacts and companies after sync for workspace ${data.workspaceId} and messageChannel ${data.messageChannelId} done`, - ); - } -} diff --git a/packages/twenty-server/src/modules/messaging/message-participant-manager/message-participant-manager.module.ts b/packages/twenty-server/src/modules/messaging/message-participant-manager/message-participant-manager.module.ts index 628efb9d95..d999a32eb5 100644 --- a/packages/twenty-server/src/modules/messaging/message-participant-manager/message-participant-manager.module.ts +++ b/packages/twenty-server/src/modules/messaging/message-participant-manager/message-participant-manager.module.ts @@ -11,7 +11,6 @@ import { ContactCreationManagerModule } from 'src/modules/contact-creation-manag import { MatchParticipantModule } from 'src/modules/match-participant/match-participant.module'; import { MessagingCommonModule } from 'src/modules/messaging/common/messaging-common.module'; import { MessageParticipantMatchParticipantJob } from 'src/modules/messaging/message-participant-manager/jobs/message-participant-match-participant.job'; -import { MessagingCreateCompanyAndContactAfterSyncJob } from 'src/modules/messaging/message-participant-manager/jobs/messaging-create-company-and-contact-after-sync.job'; import { MessageParticipantPersonListener } from 'src/modules/messaging/message-participant-manager/listeners/message-participant-person.listener'; import { MessageParticipantWorkspaceMemberListener } from 'src/modules/messaging/message-participant-manager/listeners/message-participant-workspace-member.listener'; import { MessageParticipantListener } from 'src/modules/messaging/message-participant-manager/listeners/message-participant.listener'; @@ -37,7 +36,6 @@ import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-o providers: [ MessagingMessageParticipantService, MessageParticipantMatchParticipantJob, - MessagingCreateCompanyAndContactAfterSyncJob, MessageParticipantListener, MessageParticipantPersonListener, MessageParticipantWorkspaceMemberListener,