mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-25 21:13:01 +03:00
4746 create created listener on blocklist for calendar (#5046)
Follows #5031. Closes #4746
This commit is contained in:
parent
8f6460bec5
commit
824786ff04
@ -15,7 +15,6 @@ import { GoogleAPIRefreshAccessTokenModule } from 'src/modules/connected-account
|
||||
import { MessageParticipantModule } from 'src/modules/messaging/services/message-participant/message-participant.module';
|
||||
import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module';
|
||||
import { ConnectedAccountObjectMetadata } from 'src/modules/connected-account/standard-objects/connected-account.object-metadata';
|
||||
import { MessageChannelObjectMetadata } from 'src/modules/messaging/standard-objects/message-channel.object-metadata';
|
||||
import { CreateCompanyAndContactJob } from 'src/modules/connected-account/auto-companies-and-contacts-creation/jobs/create-company-and-contact.job';
|
||||
import { AuditLogObjectMetadata } from 'src/modules/timeline/standard-objects/audit-log.object-metadata';
|
||||
import { BillingModule } from 'src/engine/core-modules/billing/billing.module';
|
||||
@ -46,7 +45,7 @@ import { AutoCompaniesAndContactsCreationModule } from 'src/modules/connected-ac
|
||||
import { GmailFetchMessagesFromCacheCronJob } from 'src/modules/messaging/crons/jobs/gmail-fetch-messages-from-cache.cron.job';
|
||||
import { GmailPartialSyncCronJob } from 'src/modules/messaging/crons/jobs/gmail-partial-sync.cron.job';
|
||||
import { DeleteConnectedAccountAssociatedMessagingDataJob } from 'src/modules/messaging/jobs/delete-connected-account-associated-messaging-data.job';
|
||||
import { DeleteMessagesFromHandleJob } from 'src/modules/messaging/jobs/delete-messages-from-handle.job';
|
||||
import { BlocklistItemDeleteMessagesJob } from 'src/modules/messaging/jobs/blocklist-item-delete-messages.job';
|
||||
import { GmailFullSyncJob } from 'src/modules/messaging/jobs/gmail-full-sync.job';
|
||||
import { GmailPartialSyncJob } from 'src/modules/messaging/jobs/gmail-partial-sync.job';
|
||||
import { MessagingCreateCompanyAndContactAfterSyncJob } from 'src/modules/messaging/jobs/messaging-create-company-and-contact-after-sync.job';
|
||||
@ -58,6 +57,8 @@ import { GmailPartialSyncModule } from 'src/modules/messaging/services/gmail-par
|
||||
import { ThreadCleanerModule } from 'src/modules/messaging/services/thread-cleaner/thread-cleaner.module';
|
||||
import { TimelineActivityModule } from 'src/modules/timeline/timeline-activity.module';
|
||||
import { MessageChannelMessageAssociationObjectMetadata } from 'src/modules/messaging/standard-objects/message-channel-message-association.object-metadata';
|
||||
import { MessageChannelObjectMetadata } from 'src/modules/messaging/standard-objects/message-channel.object-metadata';
|
||||
import { BlocklistItemDeleteCalendarEventsJob } from 'src/modules/calendar/jobs/blocklist-item-delete-calendar-events.job';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@ -183,8 +184,12 @@ import { MessageChannelMessageAssociationObjectMetadata } from 'src/modules/mess
|
||||
useClass: GoogleCalendarSyncCronJob,
|
||||
},
|
||||
{
|
||||
provide: DeleteMessagesFromHandleJob.name,
|
||||
useClass: DeleteMessagesFromHandleJob,
|
||||
provide: BlocklistItemDeleteMessagesJob.name,
|
||||
useClass: BlocklistItemDeleteMessagesJob,
|
||||
},
|
||||
{
|
||||
provide: BlocklistItemDeleteCalendarEventsJob.name,
|
||||
useClass: BlocklistItemDeleteCalendarEventsJob,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
@ -0,0 +1,39 @@
|
||||
import { isEmailBlocklisted } from 'src/modules/calendar-messaging-participant/utils/is-email-blocklisted.util';
|
||||
|
||||
describe('isEmailBlocklisted', () => {
|
||||
it('should return true if email is blocklisted', () => {
|
||||
const email = 'hello@example.com';
|
||||
const blocklist = ['hello@example.com', 'hey@example.com'];
|
||||
const result = isEmailBlocklisted(email, blocklist);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
it('should return false if email is not blocklisted', () => {
|
||||
const email = 'hello@twenty.com';
|
||||
const blocklist = ['hey@example.com'];
|
||||
const result = isEmailBlocklisted(email, blocklist);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
it('should return false if email is null', () => {
|
||||
const email = null;
|
||||
const blocklist = ['@example.com'];
|
||||
const result = isEmailBlocklisted(email, blocklist);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
it('should return false if email is undefined', () => {
|
||||
const email = undefined;
|
||||
const blocklist = ['@example.com'];
|
||||
const result = isEmailBlocklisted(email, blocklist);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
it('should return true if email ends with blocklisted domain', () => {
|
||||
const email = 'hello@example.com';
|
||||
const blocklist = ['@example.com'];
|
||||
const result = isEmailBlocklisted(email, blocklist);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
@ -0,0 +1,16 @@
|
||||
export const isEmailBlocklisted = (
|
||||
email: string | null | undefined,
|
||||
blocklist: string[],
|
||||
): boolean => {
|
||||
if (!email) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return blocklist.some((item) => {
|
||||
if (item.startsWith('@')) {
|
||||
return email.endsWith(item);
|
||||
}
|
||||
|
||||
return email === item;
|
||||
});
|
||||
};
|
@ -1,10 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { CalendarBlocklistListener } from 'src/modules/calendar/listeners/calendar-blocklist.listener';
|
||||
import { CalendarChannelListener } from 'src/modules/calendar/listeners/calendar-channel.listener';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
providers: [CalendarChannelListener],
|
||||
providers: [CalendarChannelListener, CalendarBlocklistListener],
|
||||
exports: [],
|
||||
})
|
||||
export class CalendarModule {}
|
||||
|
@ -0,0 +1,83 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import { MessageQueueJob } from 'src/engine/integrations/message-queue/interfaces/message-queue-job.interface';
|
||||
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { CalendarChannelEventAssociationRepository } from 'src/modules/calendar/repositories/calendar-channel-event-association.repository';
|
||||
import { CalendarChannelRepository } from 'src/modules/calendar/repositories/calendar-channel.repository';
|
||||
import { CalendarEventCleanerService } from 'src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.service';
|
||||
import { CalendarChannelEventAssociationObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.object-metadata';
|
||||
import { CalendarChannelObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-channel.object-metadata';
|
||||
import { BlocklistRepository } from 'src/modules/connected-account/repositories/blocklist.repository';
|
||||
import { BlocklistObjectMetadata } from 'src/modules/connected-account/standard-objects/blocklist.object-metadata';
|
||||
|
||||
export type BlocklistItemDeleteCalendarEventsJobData = {
|
||||
workspaceId: string;
|
||||
blocklistItemId: string;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class BlocklistItemDeleteCalendarEventsJob
|
||||
implements MessageQueueJob<BlocklistItemDeleteCalendarEventsJobData>
|
||||
{
|
||||
private readonly logger = new Logger(
|
||||
BlocklistItemDeleteCalendarEventsJob.name,
|
||||
);
|
||||
|
||||
constructor(
|
||||
@InjectObjectMetadataRepository(CalendarChannelObjectMetadata)
|
||||
private readonly calendarChannelRepository: CalendarChannelRepository,
|
||||
@InjectObjectMetadataRepository(
|
||||
CalendarChannelEventAssociationObjectMetadata,
|
||||
)
|
||||
private readonly calendarChannelEventAssociationRepository: CalendarChannelEventAssociationRepository,
|
||||
@InjectObjectMetadataRepository(BlocklistObjectMetadata)
|
||||
private readonly blocklistRepository: BlocklistRepository,
|
||||
private readonly calendarEventCleanerService: CalendarEventCleanerService,
|
||||
) {}
|
||||
|
||||
async handle(data: BlocklistItemDeleteCalendarEventsJobData): Promise<void> {
|
||||
const { workspaceId, blocklistItemId } = data;
|
||||
|
||||
const blocklistItem = await this.blocklistRepository.getById(
|
||||
blocklistItemId,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (!blocklistItem) {
|
||||
this.logger.log(
|
||||
`Blocklist item with id ${blocklistItemId} not found in workspace ${workspaceId}`,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const { handle, workspaceMemberId } = blocklistItem;
|
||||
|
||||
this.logger.log(
|
||||
`Deleting calendar events from ${handle} in workspace ${workspaceId} for workspace member ${workspaceMemberId}`,
|
||||
);
|
||||
|
||||
const calendarChannels =
|
||||
await this.calendarChannelRepository.getIdsByWorkspaceMemberId(
|
||||
workspaceMemberId,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
const calendarChannelIds = calendarChannels.map(({ id }) => id);
|
||||
|
||||
await this.calendarChannelEventAssociationRepository.deleteByCalendarEventParticipantHandleAndCalendarChannelIds(
|
||||
handle,
|
||||
calendarChannelIds,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
await this.calendarEventCleanerService.cleanWorkspaceCalendarEvents(
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
this.logger.log(
|
||||
`Deleted calendar events from handle ${handle} in workspace ${workspaceId} for workspace member ${workspaceMemberId}`,
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordCreateEvent } from 'src/engine/integrations/event-emitter/types/object-record-create.event';
|
||||
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service';
|
||||
import {
|
||||
BlocklistItemDeleteCalendarEventsJobData,
|
||||
BlocklistItemDeleteCalendarEventsJob,
|
||||
} from 'src/modules/calendar/jobs/blocklist-item-delete-calendar-events.job';
|
||||
import { BlocklistObjectMetadata } from 'src/modules/connected-account/standard-objects/blocklist.object-metadata';
|
||||
|
||||
@Injectable()
|
||||
export class CalendarBlocklistListener {
|
||||
constructor(
|
||||
@Inject(MessageQueue.calendarQueue)
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
@OnEvent('blocklist.created')
|
||||
handleCreatedEvent(
|
||||
payload: ObjectRecordCreateEvent<BlocklistObjectMetadata>,
|
||||
) {
|
||||
this.messageQueueService.add<BlocklistItemDeleteCalendarEventsJobData>(
|
||||
BlocklistItemDeleteCalendarEventsJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
blocklistItemId: payload.recordId,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ import { MessageChannelObjectMetadata } from 'src/modules/messaging/standard-obj
|
||||
@Injectable()
|
||||
export class CalendarChannelListener {
|
||||
constructor(
|
||||
@Inject(MessageQueue.messagingQueue)
|
||||
@Inject(MessageQueue.calendarQueue)
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import { EntityManager } from 'typeorm';
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { CalendarChannelEventAssociationObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-channel-event-association.object-metadata';
|
||||
import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/getFlattenedValuesAndValuesStringForBatchRawQuery.util';
|
||||
import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/get-flattened-values-and-values-string-for-batch-raw-query.util';
|
||||
|
||||
@Injectable()
|
||||
export class CalendarChannelEventAssociationRepository {
|
||||
@ -169,4 +169,28 @@ export class CalendarChannelEventAssociationRepository {
|
||||
transactionManager,
|
||||
);
|
||||
}
|
||||
|
||||
public async deleteByCalendarEventParticipantHandleAndCalendarChannelIds(
|
||||
calendarEventParticipantHandle: string,
|
||||
calendarChannelIds: string[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
) {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
await this.workspaceDataSourceService.executeRawQuery(
|
||||
`DELETE FROM ${dataSourceSchema}."calendarChannelEventAssociation"
|
||||
WHERE "id" IN (
|
||||
SELECT "calendarChannelEventAssociation"."id"
|
||||
FROM ${dataSourceSchema}."calendarChannelEventAssociation" "calendarChannelEventAssociation"
|
||||
JOIN ${dataSourceSchema}."calendarEvent" "calendarEvent" ON "calendarChannelEventAssociation"."calendarEventId" = "calendarEvent"."id"
|
||||
JOIN ${dataSourceSchema}."calendarEventParticipant" "calendarEventParticipant" ON "calendarEvent"."id" = "calendarEventParticipant"."calendarEventId"
|
||||
WHERE "calendarEventParticipant"."handle" = $1 AND "calendarChannelEventAssociation"."calendarChannelId" = ANY($2)
|
||||
)`,
|
||||
[calendarEventParticipantHandle, calendarChannelIds],
|
||||
workspaceId,
|
||||
transactionManager,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -95,6 +95,27 @@ export class CalendarChannelRepository {
|
||||
);
|
||||
}
|
||||
|
||||
public async getIdsByWorkspaceMemberId(
|
||||
workspaceMemberId: string,
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<ObjectRecord<CalendarChannelObjectMetadata>[]> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
const calendarChannelIds =
|
||||
await this.workspaceDataSourceService.executeRawQuery(
|
||||
`SELECT "calendarChannel".id FROM ${dataSourceSchema}."calendarChannel" "calendarChannel"
|
||||
JOIN ${dataSourceSchema}."connectedAccount" ON "calendarChannel"."connectedAccountId" = ${dataSourceSchema}."connectedAccount"."id"
|
||||
WHERE ${dataSourceSchema}."connectedAccount"."accountOwnerId" = $1`,
|
||||
[workspaceMemberId],
|
||||
workspaceId,
|
||||
transactionManager,
|
||||
);
|
||||
|
||||
return calendarChannelIds;
|
||||
}
|
||||
|
||||
public async updateSyncCursor(
|
||||
syncCursor: string,
|
||||
calendarChannelId: string,
|
||||
|
@ -6,7 +6,7 @@ import differenceWith from 'lodash.differencewith';
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { CalendarEventParticipantObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event-participant.object-metadata';
|
||||
import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/getFlattenedValuesAndValuesStringForBatchRawQuery.util';
|
||||
import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/get-flattened-values-and-values-string-for-batch-raw-query.util';
|
||||
import {
|
||||
CalendarEventParticipant,
|
||||
CalendarEventParticipantWithId,
|
||||
|
@ -5,7 +5,7 @@ import { EntityManager } from 'typeorm';
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
|
||||
import { CalendarEventObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event.object-metadata';
|
||||
import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/getFlattenedValuesAndValuesStringForBatchRawQuery.util';
|
||||
import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/get-flattened-values-and-values-string-for-batch-raw-query.util';
|
||||
import { CalendarEvent } from 'src/modules/calendar/types/calendar-event';
|
||||
import { CalendarEventParticipantObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event-participant.object-metadata';
|
||||
|
||||
|
@ -6,7 +6,7 @@ import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repos
|
||||
import { PersonRepository } from 'src/modules/person/repositories/person.repository';
|
||||
import { PersonObjectMetadata } from 'src/modules/person/standard-objects/person.object-metadata';
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/getFlattenedValuesAndValuesStringForBatchRawQuery.util';
|
||||
import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/get-flattened-values-and-values-string-for-batch-raw-query.util';
|
||||
import { CalendarEventParticipant } from 'src/modules/calendar/types/calendar-event';
|
||||
import { CalendarEventParticipantRepository } from 'src/modules/calendar/repositories/calendar-event-participant.repository';
|
||||
import { CalendarEventParticipantObjectMetadata } from 'src/modules/calendar/standard-objects/calendar-event-participant.object-metadata';
|
||||
|
@ -12,7 +12,6 @@ import {
|
||||
FeatureFlagKeys,
|
||||
} from 'src/engine/core-modules/feature-flag/feature-flag.entity';
|
||||
import { GoogleCalendarClientProvider } from 'src/modules/calendar/services/providers/google-calendar/google-calendar.provider';
|
||||
import { googleCalendarSearchFilterExcludeEmails } from 'src/modules/calendar/utils/google-calendar-search-filter.util';
|
||||
import { CalendarChannelEventAssociationRepository } from 'src/modules/calendar/repositories/calendar-channel-event-association.repository';
|
||||
import { CalendarChannelRepository } from 'src/modules/calendar/repositories/calendar-channel.repository';
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
@ -29,6 +28,7 @@ import { BlocklistObjectMetadata } from 'src/modules/connected-account/standard-
|
||||
import { CalendarEventCleanerService } from 'src/modules/calendar/services/calendar-event-cleaner/calendar-event-cleaner.service';
|
||||
import { CalendarEventParticipantService } from 'src/modules/calendar/services/calendar-event-participant/calendar-event-participant.service';
|
||||
import { CalendarEventParticipant } from 'src/modules/calendar/types/calendar-event';
|
||||
import { filterOutBlocklistedEvents } from 'src/modules/calendar/utils/filter-out-blocklisted-events.util';
|
||||
|
||||
@Injectable()
|
||||
export class GoogleCalendarSyncService {
|
||||
@ -133,7 +133,6 @@ export class GoogleCalendarSyncService {
|
||||
syncToken,
|
||||
pageToken: nextPageToken,
|
||||
showDeleted: true,
|
||||
q: googleCalendarSearchFilterExcludeEmails(blocklistedEmails),
|
||||
});
|
||||
|
||||
nextSyncToken = googleCalendarEvents.data.nextSyncToken;
|
||||
@ -168,7 +167,12 @@ export class GoogleCalendarSyncService {
|
||||
return;
|
||||
}
|
||||
|
||||
const eventExternalIds = events.map((event) => event.id as string);
|
||||
const filteredEvents = filterOutBlocklistedEvents(
|
||||
events,
|
||||
blocklistedEmails,
|
||||
);
|
||||
|
||||
const eventExternalIds = filteredEvents.map((event) => event.id as string);
|
||||
|
||||
startTime = Date.now();
|
||||
|
||||
@ -204,7 +208,7 @@ export class GoogleCalendarSyncService {
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
const formattedEvents = events
|
||||
const formattedEvents = filteredEvents
|
||||
.filter((event) => event.status !== 'cancelled')
|
||||
.map((event) =>
|
||||
formatGoogleCalendarEvent(event, iCalUIDCalendarEventIdMap),
|
||||
@ -218,7 +222,7 @@ export class GoogleCalendarSyncService {
|
||||
existingEventExternalIds.includes(event.externalId),
|
||||
);
|
||||
|
||||
const cancelledEventExternalIds = events
|
||||
const cancelledEventExternalIds = filteredEvents
|
||||
.filter((event) => event.status === 'cancelled')
|
||||
.map((event) => event.id as string);
|
||||
|
||||
@ -240,7 +244,7 @@ export class GoogleCalendarSyncService {
|
||||
|
||||
let newCalendarEventParticipants: CalendarEventParticipant[] = [];
|
||||
|
||||
if (events.length > 0) {
|
||||
if (filteredEvents.length > 0) {
|
||||
const dataSourceMetadata =
|
||||
await this.workspaceDataSourceService.connectToWorkspaceDataSource(
|
||||
workspaceId,
|
||||
|
@ -0,0 +1,18 @@
|
||||
import { calendar_v3 as calendarV3 } from 'googleapis';
|
||||
|
||||
import { isEmailBlocklisted } from 'src/modules/calendar-messaging-participant/utils/is-email-blocklisted.util';
|
||||
|
||||
export const filterOutBlocklistedEvents = (
|
||||
events: calendarV3.Schema$Event[],
|
||||
blocklist: string[],
|
||||
) => {
|
||||
return events.filter((event) => {
|
||||
if (!event.attendees) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return event.attendees.every(
|
||||
(attendee) => !isEmailBlocklisted(attendee.email, blocklist),
|
||||
);
|
||||
});
|
||||
};
|
@ -5,5 +5,5 @@ export const googleCalendarSearchFilterExcludeEmails = (
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return `email=-(${emails.join(', -')})`;
|
||||
return `-(${emails.join(', ')})`;
|
||||
};
|
||||
|
@ -11,16 +11,16 @@ import { ThreadCleanerService } from 'src/modules/messaging/services/thread-clea
|
||||
import { MessageChannelMessageAssociationObjectMetadata } from 'src/modules/messaging/standard-objects/message-channel-message-association.object-metadata';
|
||||
import { MessageChannelObjectMetadata } from 'src/modules/messaging/standard-objects/message-channel.object-metadata';
|
||||
|
||||
export type DeleteMessagesFromHandleJobData = {
|
||||
export type BlocklistItemDeleteMessagesJobData = {
|
||||
workspaceId: string;
|
||||
blocklistItemId: string;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class DeleteMessagesFromHandleJob
|
||||
implements MessageQueueJob<DeleteMessagesFromHandleJobData>
|
||||
export class BlocklistItemDeleteMessagesJob
|
||||
implements MessageQueueJob<BlocklistItemDeleteMessagesJobData>
|
||||
{
|
||||
private readonly logger = new Logger(DeleteMessagesFromHandleJob.name);
|
||||
private readonly logger = new Logger(BlocklistItemDeleteMessagesJob.name);
|
||||
|
||||
constructor(
|
||||
@InjectObjectMetadataRepository(MessageChannelObjectMetadata)
|
||||
@ -34,7 +34,7 @@ export class DeleteMessagesFromHandleJob
|
||||
private readonly threadCleanerService: ThreadCleanerService,
|
||||
) {}
|
||||
|
||||
async handle(data: DeleteMessagesFromHandleJobData): Promise<void> {
|
||||
async handle(data: BlocklistItemDeleteMessagesJobData): Promise<void> {
|
||||
const { workspaceId, blocklistItemId } = data;
|
||||
|
||||
const blocklistItem = await this.blocklistRepository.getById(
|
||||
@ -64,9 +64,12 @@ export class DeleteMessagesFromHandleJob
|
||||
|
||||
const messageChannelIds = messageChannels.map(({ id }) => id);
|
||||
|
||||
await this.messageChannelMessageAssociationRepository.deleteByMessageParticipantHandleAndMessageChannelIds(
|
||||
const rolesToDelete: ('from' | 'to')[] = ['from', 'to'];
|
||||
|
||||
await this.messageChannelMessageAssociationRepository.deleteByMessageParticipantHandleAndMessageChannelIdsAndRoles(
|
||||
handle,
|
||||
messageChannelIds,
|
||||
rolesToDelete,
|
||||
workspaceId,
|
||||
);
|
||||
|
@ -6,9 +6,9 @@ import { MessageQueue } from 'src/engine/integrations/message-queue/message-queu
|
||||
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service';
|
||||
import { BlocklistObjectMetadata } from 'src/modules/connected-account/standard-objects/blocklist.object-metadata';
|
||||
import {
|
||||
DeleteMessagesFromHandleJobData,
|
||||
DeleteMessagesFromHandleJob,
|
||||
} from 'src/modules/messaging/jobs/delete-messages-from-handle.job';
|
||||
BlocklistItemDeleteMessagesJobData,
|
||||
BlocklistItemDeleteMessagesJob,
|
||||
} from 'src/modules/messaging/jobs/blocklist-item-delete-messages.job';
|
||||
|
||||
@Injectable()
|
||||
export class MessagingBlocklistListener {
|
||||
@ -21,8 +21,8 @@ export class MessagingBlocklistListener {
|
||||
handleCreatedEvent(
|
||||
payload: ObjectRecordCreateEvent<BlocklistObjectMetadata>,
|
||||
) {
|
||||
this.messageQueueService.add<DeleteMessagesFromHandleJobData>(
|
||||
DeleteMessagesFromHandleJob.name,
|
||||
this.messageQueueService.add<BlocklistItemDeleteMessagesJobData>(
|
||||
BlocklistItemDeleteMessagesJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
blocklistItemId: payload.recordId,
|
||||
|
@ -67,9 +67,10 @@ export class MessageChannelMessageAssociationRepository {
|
||||
);
|
||||
}
|
||||
|
||||
public async deleteByMessageParticipantHandleAndMessageChannelIds(
|
||||
public async deleteByMessageParticipantHandleAndMessageChannelIdsAndRoles(
|
||||
messageParticipantHandle: string,
|
||||
messageChannelIds: string[],
|
||||
rolesToDelete: ('from' | 'to' | 'cc' | 'bcc')[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
) {
|
||||
@ -83,7 +84,7 @@ export class MessageChannelMessageAssociationRepository {
|
||||
JOIN ${dataSourceSchema}."message" ON "messageChannelMessageAssociation"."messageId" = ${dataSourceSchema}."message"."id"
|
||||
JOIN ${dataSourceSchema}."messageParticipant" "messageParticipant" ON ${dataSourceSchema}."message"."id" = "messageParticipant"."messageId"
|
||||
WHERE "messageParticipant"."handle" = $1 AND "messageParticipant"."role"= ANY($2) AND "messageChannelMessageAssociation"."messageChannelId" = ANY($3)`,
|
||||
[messageParticipantHandle, ['from', 'to'], messageChannelIds],
|
||||
[messageParticipantHandle, rolesToDelete, messageChannelIds],
|
||||
workspaceId,
|
||||
transactionManager,
|
||||
);
|
||||
|
@ -7,7 +7,7 @@ import { ParticipantWithMessageId } from 'src/modules/messaging/types/gmail-mess
|
||||
import { PersonRepository } from 'src/modules/person/repositories/person.repository';
|
||||
import { PersonObjectMetadata } from 'src/modules/person/standard-objects/person.object-metadata';
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/getFlattenedValuesAndValuesStringForBatchRawQuery.util';
|
||||
import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/get-flattened-values-and-values-string-for-batch-raw-query.util';
|
||||
import { MessageParticipantRepository } from 'src/modules/messaging/repositories/message-participant.repository';
|
||||
import { MessageParticipantObjectMetadata } from 'src/modules/messaging/standard-objects/message-participant.object-metadata';
|
||||
import { AddPersonIdAndWorkspaceMemberIdService } from 'src/modules/calendar-messaging-participant/services/add-person-id-and-workspace-member-id/add-person-id-and-workspace-member-id.service';
|
||||
|
Loading…
Reference in New Issue
Block a user