Merge pull request #998 from Hexastack/fix/message-attachment-remove
Some checks are pending
Build and Push Docker API Image / build-and-push (push) Waiting to run
Build and Push Docker Base Image / build-and-push (push) Waiting to run
Build and Push Docker UI Image / build-and-push (push) Waiting to run

feat: undo message attachment reference removal
This commit is contained in:
Med Marrouchi 2025-05-12 15:37:21 +01:00 committed by GitHub
commit 75d96650aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 49 deletions

View File

@ -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,

View File

@ -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<Attachment, any, any>,
unknown,
Attachment,
'deleteOne' | 'deleteMany'
>,
criteria: TFilterQuery<Attachment>,
) {
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,
);
}
}
}