The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Re-import messages and events on idle channels when a handle is unblocked (#29104)
neo7737f6a7a30d059
diff --git a/packages/twenty-server/src/modules/calendar/blocklist-manager/jobs/blocklist-reimport-calendar-events.job.ts b/packages/twenty-server/src/modules/calendar/blocklist-manager/jobs/blocklist-reimport-calendar-events.job.tsindex 5376efb1874..76f0c876081 100644--- a/packages/twenty-server/src/modules/calendar/blocklist-manager/jobs/blocklist-reimport-calendar-events.job.ts+++ b/packages/twenty-server/src/modules/calendar/blocklist-manager/jobs/blocklist-reimport-calendar-events.job.ts@@ -130,9 +130,7 @@ export class BlocklistReimportCalendarEventsJob {userWorkspaceId: string | null;}): Promise<string[]> {const where: FindOptionsWhere<CalendarChannelEntity> = {- syncStage: Not(- CalendarChannelSyncStage.CALENDAR_EVENT_LIST_FETCH_PENDING,- ),+ syncStage: Not(CalendarChannelSyncStage.PENDING_CONFIGURATION),workspaceId,};diff --git a/packages/twenty-server/src/modules/messaging/blocklist-manager/jobs/messaging-blocklist-reimport-messages.job.ts b/packages/twenty-server/src/modules/messaging/blocklist-manager/jobs/messaging-blocklist-reimport-messages.job.tsindex 026efad8fb2..4bab85ff490 100644--- a/packages/twenty-server/src/modules/messaging/blocklist-manager/jobs/messaging-blocklist-reimport-messages.job.ts+++ b/packages/twenty-server/src/modules/messaging/blocklist-manager/jobs/messaging-blocklist-reimport-messages.job.ts@@ -140,7 +140,7 @@ export class BlocklistReimportMessagesJob {connectedAccountIds: string[] | null;}): Promise<string[]> {const where: FindOptionsWhere<MessageChannelEntity> = {- syncStage: Not(MessageChannelSyncStage.MESSAGE_LIST_FETCH_PENDING),+ syncStage: Not(MessageChannelSyncStage.PENDING_CONFIGURATION),workspaceId,};diff --git a/packages/twenty-server/test/integration/google/messaging/blocklist-cleanup.integration-spec.ts b/packages/twenty-server/test/integration/google/messaging/blocklist-cleanup.integration-spec.tsindex 16103298227..9fe8e5e9c48 100644--- a/packages/twenty-server/test/integration/google/messaging/blocklist-cleanup.integration-spec.ts+++ b/packages/twenty-server/test/integration/google/messaging/blocklist-cleanup.integration-spec.ts@@ -2,9 +2,11 @@ import { randomUUID } from 'node:crypto';import { BlocklistScope, ConnectedAccountProvider } from 'twenty-shared/types';+import { CalendarChannelEntity } from 'src/engine/metadata-modules/calendar-channel/entities/calendar-channel.entity';import { WORKSPACE_MEMBER_DATA_SEED_IDS } from 'src/engine/workspace-manager/dev-seeder/data/constants/workspace-member-data-seeds.constant';import { createOneOperationFactory } from 'test/integration/graphql/utils/create-one-operation-factory.util';+import { deleteOneOperationFactory } from 'test/integration/graphql/utils/delete-one-operation-factory.util';import { destroyOneOperationFactory } from 'test/integration/graphql/utils/destroy-one-operation-factory.util';import { makeGraphqlApiRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';import { googleCalendarEvent } from 'test/integration/google/mocks/google-calendar-event.util';@@ -16,6 +18,7 @@ import {findImportedCalendarEventTitles,findImportedMessageSubjects,} from 'test/integration/utils/find-imported-records.util';+import { getCoreRepository } from 'test/integration/utils/get-core-repository.util';import { runCalendarChannelEventsImport } from 'test/integration/utils/run-calendar-channel-events-import.util';import { runCalendarChannelListFetch } from 'test/integration/utils/run-calendar-channel-list-fetch.util';import { resetMessageChannelSyncState } from 'test/integration/utils/reset-channel-sync-state.util';@@ -218,4 +221,35 @@ describe('Blocklist cleanup (integration)', () => {]),).toEqual([importedEventTitle]);}, 180000);++ it('re-imports the messages of an unblocked handle on an idle channel and restarts its calendar sync from scratch', async () => {+ const response = await makeGraphqlApiRequest(+ deleteOneOperationFactory({+ objectMetadataSingularName: 'blocklist',+ gqlFields: 'id',+ recordId: blocklistIds[0],+ }),+ );++ expect(response.body.errors).toBeUndefined();++ await waitForAllJobsToFinish();++ const calendarChannel = await getCoreRepository<CalendarChannelEntity>(+ CalendarChannelEntity,+ ).findOneByOrFail({ id: channel.calendarChannelId });++ expect(calendarChannel.syncCursor).toBe('');++ await runMessageChannelSync(channel.channelId);+ await waitForAllJobsToFinish();++ expect(+ await findImportedMessageSubjects([+ blockedSubject,+ workspaceBlockedSubject,+ keptSubject,+ ]),+ ).toEqual([blockedSubject, keptSubject].sort());+ }, 180000);});