5629 update blocklist for messaging v2 (#5756)
Closes #5629 - Add subdomain support in blocklist (if @example.com is blocked, every subdomain will be blocked)
This commit is contained in:
@ -66,12 +66,14 @@ export class BlocklistItemDeleteMessagesJob
|
||||
|
||||
const rolesToDelete: ('from' | 'to')[] = ['from', 'to'];
|
||||
|
||||
await this.messageChannelMessageAssociationRepository.deleteByMessageParticipantHandleAndMessageChannelIdsAndRoles(
|
||||
handle,
|
||||
messageChannelIds,
|
||||
rolesToDelete,
|
||||
workspaceId,
|
||||
);
|
||||
for (const messageChannelId of messageChannelIds) {
|
||||
await this.messageChannelMessageAssociationRepository.deleteByMessageParticipantHandleAndMessageChannelIdAndRoles(
|
||||
handle,
|
||||
messageChannelId,
|
||||
rolesToDelete,
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
|
||||
await this.threadCleanerService.cleanWorkspaceThreads(workspaceId);
|
||||
|
||||
|
||||
@ -1,58 +0,0 @@
|
||||
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 { ConnectedAccountRepository } from 'src/modules/connected-account/repositories/connected-account.repository';
|
||||
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||
|
||||
export type BlocklistReimportMessagesJobData = {
|
||||
workspaceId: string;
|
||||
workspaceMemberId: string;
|
||||
handle: string;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class BlocklistReimportMessagesJob
|
||||
implements MessageQueueJob<BlocklistReimportMessagesJobData>
|
||||
{
|
||||
private readonly logger = new Logger(BlocklistReimportMessagesJob.name);
|
||||
|
||||
constructor(
|
||||
@InjectObjectMetadataRepository(ConnectedAccountWorkspaceEntity)
|
||||
private readonly connectedAccountRepository: ConnectedAccountRepository,
|
||||
) {}
|
||||
|
||||
async handle(data: BlocklistReimportMessagesJobData): Promise<void> {
|
||||
const { workspaceId, workspaceMemberId, handle } = data;
|
||||
|
||||
this.logger.log(
|
||||
`Reimporting messages from handle ${handle} in workspace ${workspaceId} for workspace member ${workspaceMemberId}`,
|
||||
);
|
||||
|
||||
const connectedAccount =
|
||||
await this.connectedAccountRepository.getAllByWorkspaceMemberId(
|
||||
workspaceMemberId,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (!connectedAccount || connectedAccount.length === 0) {
|
||||
this.logger.error(
|
||||
`No connected account found for workspace member ${workspaceMemberId} in workspace ${workspaceId}`,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: reimplement that
|
||||
// await this.gmailMessageListFetchJob.fetchConnectedAccountThreads(
|
||||
// workspaceId,
|
||||
// connectedAccount[0].id,
|
||||
// [handle],
|
||||
// );
|
||||
|
||||
this.logger.log(
|
||||
`Reimporting messages from ${handle} in workspace ${workspaceId} for workspace member ${workspaceMemberId} done`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -6,21 +6,28 @@ import { ObjectRecordDeleteEvent } from 'src/engine/integrations/event-emitter/t
|
||||
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service';
|
||||
import { BlocklistWorkspaceEntity } from 'src/modules/connected-account/standard-objects/blocklist.workspace-entity';
|
||||
import {
|
||||
BlocklistReimportMessagesJob,
|
||||
BlocklistReimportMessagesJobData,
|
||||
} from 'src/modules/messaging/blocklist-manager/jobs/messaging-blocklist-reimport-messages.job';
|
||||
import {
|
||||
BlocklistItemDeleteMessagesJobData,
|
||||
BlocklistItemDeleteMessagesJob,
|
||||
} from 'src/modules/messaging/blocklist-manager/jobs/messaging-blocklist-item-delete-messages.job';
|
||||
import { ObjectRecordUpdateEvent } from 'src/engine/integrations/event-emitter/types/object-record-update.event';
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { ConnectedAccountRepository } from 'src/modules/connected-account/repositories/connected-account.repository';
|
||||
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||
import { MessageChannelRepository } from 'src/modules/messaging/common/repositories/message-channel.repository';
|
||||
import { MessagingChannelSyncStatusService } from 'src/modules/messaging/common/services/messaging-channel-sync-status.service';
|
||||
import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||
|
||||
@Injectable()
|
||||
export class MessagingBlocklistListener {
|
||||
constructor(
|
||||
@Inject(MessageQueue.messagingQueue)
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
@InjectObjectMetadataRepository(ConnectedAccountWorkspaceEntity)
|
||||
private readonly connectedAccountRepository: ConnectedAccountRepository,
|
||||
private readonly messagingChannelSyncStatusService: MessagingChannelSyncStatusService,
|
||||
@InjectObjectMetadataRepository(MessageChannelWorkspaceEntity)
|
||||
private readonly messageChannelRepository: MessageChannelRepository,
|
||||
) {}
|
||||
|
||||
@OnEvent('blocklist.created')
|
||||
@ -40,13 +47,28 @@ export class MessagingBlocklistListener {
|
||||
async handleDeletedEvent(
|
||||
payload: ObjectRecordDeleteEvent<BlocklistWorkspaceEntity>,
|
||||
) {
|
||||
await this.messageQueueService.add<BlocklistReimportMessagesJobData>(
|
||||
BlocklistReimportMessagesJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
workspaceMemberId: payload.properties.before.workspaceMember.id,
|
||||
handle: payload.properties.before.handle,
|
||||
},
|
||||
const workspaceMemberId = payload.properties.before.workspaceMember.id;
|
||||
const workspaceId = payload.workspaceId;
|
||||
|
||||
const connectedAccount =
|
||||
await this.connectedAccountRepository.getAllByWorkspaceMemberId(
|
||||
workspaceMemberId,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (!connectedAccount || connectedAccount.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const messageChannel =
|
||||
await this.messageChannelRepository.getByConnectedAccountId(
|
||||
connectedAccount[0].id,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
await this.messagingChannelSyncStatusService.resetAndScheduleFullMessageListFetch(
|
||||
messageChannel[0].id,
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
|
||||
@ -54,21 +76,36 @@ export class MessagingBlocklistListener {
|
||||
async handleUpdatedEvent(
|
||||
payload: ObjectRecordUpdateEvent<BlocklistWorkspaceEntity>,
|
||||
) {
|
||||
const workspaceMemberId = payload.properties.before.workspaceMember.id;
|
||||
const workspaceId = payload.workspaceId;
|
||||
|
||||
await this.messageQueueService.add<BlocklistItemDeleteMessagesJobData>(
|
||||
BlocklistItemDeleteMessagesJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
workspaceId,
|
||||
blocklistItemId: payload.recordId,
|
||||
},
|
||||
);
|
||||
|
||||
await this.messageQueueService.add<BlocklistReimportMessagesJobData>(
|
||||
BlocklistReimportMessagesJob.name,
|
||||
{
|
||||
workspaceId: payload.workspaceId,
|
||||
workspaceMemberId: payload.properties.after.workspaceMember.id,
|
||||
handle: payload.properties.before.handle,
|
||||
},
|
||||
const connectedAccount =
|
||||
await this.connectedAccountRepository.getAllByWorkspaceMemberId(
|
||||
workspaceMemberId,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (!connectedAccount || connectedAccount.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const messageChannel =
|
||||
await this.messageChannelRepository.getByConnectedAccountId(
|
||||
connectedAccount[0].id,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
await this.messagingChannelSyncStatusService.resetAndScheduleFullMessageListFetch(
|
||||
messageChannel[0].id,
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,19 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { BlocklistItemDeleteMessagesJob } from 'src/modules/messaging/blocklist-manager/jobs/messaging-blocklist-item-delete-messages.job';
|
||||
import { MessagingBlocklistListener } from 'src/modules/messaging/blocklist-manager/listeners/messaging-blocklist.listener';
|
||||
import { MessagingCommonModule } from 'src/modules/messaging/common/messaging-common.module';
|
||||
import { MessagingMessageCleanerModule } from 'src/modules/messaging/message-cleaner/messaging-message-cleaner.module';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
providers: [],
|
||||
imports: [MessagingCommonModule, MessagingMessageCleanerModule],
|
||||
providers: [
|
||||
MessagingBlocklistListener,
|
||||
{
|
||||
provide: BlocklistItemDeleteMessagesJob.name,
|
||||
useClass: BlocklistItemDeleteMessagesJob,
|
||||
},
|
||||
],
|
||||
exports: [],
|
||||
})
|
||||
export class MessagingBlocklistManagerModule {}
|
||||
|
||||
Reference in New Issue
Block a user