diff --git a/api/src/chat/chat.module.ts b/api/src/chat/chat.module.ts index 1452d296..09b21f7b 100644 --- a/api/src/chat/chat.module.ts +++ b/api/src/chat/chat.module.ts @@ -11,9 +11,6 @@ import { EventEmitter2 } from '@nestjs/event-emitter'; import { MongooseModule } from '@nestjs/mongoose'; import { AttachmentModule } from '@/attachment/attachment.module'; -import { AttachmentRepository } from '@/attachment/repositories/attachment.repository'; -import { AttachmentModel } from '@/attachment/schemas/attachment.schema'; -import { AttachmentService } from '@/attachment/services/attachment.service'; import { ChannelModule } from '@/channel/channel.module'; import { CmsModule } from '@/cms/cms.module'; import { UserModule } from '@/user/user.module'; @@ -61,7 +58,6 @@ import { SubscriberService } from './services/subscriber.service'; SubscriberModel, ConversationModel, SubscriberModel, - AttachmentModel, ]), forwardRef(() => ChannelModule), CmsModule, @@ -96,8 +92,6 @@ import { SubscriberService } from './services/subscriber.service'; ConversationService, ChatService, BotService, - AttachmentService, - AttachmentRepository, ], exports: [ SubscriberService, diff --git a/api/src/chat/services/message.service.ts b/api/src/chat/services/message.service.ts index d6b210ea..604cb51a 100644 --- a/api/src/chat/services/message.service.ts +++ b/api/src/chat/services/message.service.ts @@ -11,14 +11,8 @@ import { InternalServerErrorException, Optional, } from '@nestjs/common'; -import { OnEvent } from '@nestjs/event-emitter'; -import { Document, Query } from 'mongoose'; -import { Attachment } from '@/attachment/schemas/attachment.schema'; -import { AttachmentService } from '@/attachment/services/attachment.service'; -import { DeleteResult } from '@/utils/generics/base-repository'; import { BaseService } from '@/utils/generics/base-service'; -import { TFilterQuery } from '@/utils/types/filter.types'; import { SocketGet, SocketPost, @@ -45,7 +39,6 @@ export class MessageService extends BaseService< constructor( private readonly messageRepository: MessageRepository, - private attachmentService: AttachmentService, @Optional() gateway?: WebsocketGateway, ) { super(messageRepository); @@ -134,40 +127,4 @@ export class MessageService extends BaseService< return lastMessages.reverse(); } - - @OnEvent('hook:attachment:preDelete') - async handleDeleteImage( - _query: Query< - DeleteResult, - Document, - unknown, - Attachment, - 'deleteOne' | 'deleteMany' - >, - criteria: TFilterQuery, - ) { - try { - this.logger.log( - 'deleting attachment messages containing deleted images', - criteria, - ); - const foundAttachments = await this.attachmentService.find(criteria); - - for (const attachment of foundAttachments) { - await this.updateMany( - { - 'message.attachment.payload.id': attachment.id, - }, - { - ['message.attachment.payload.id' as any]: null, - }, - ); - } - } catch (error) { - this.logger.error( - 'Unable to cleanup old messages with attachment ids', - error, - ); - } - } }