Skip to content

Commit

Permalink
Merge pull request #1190 from GrimBit1/main
Browse files Browse the repository at this point in the history
Fix Message deletion in Whatsapp Bailey Service
  • Loading branch information
DavidsonGomes authored Feb 1, 2025
2 parents b096386 + c1494ca commit ff5a8ad
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3552,25 +3552,31 @@ export class BaileysStartupService extends ChannelStartupService {
const messageId = response.message?.protocolMessage?.key?.id;
if (messageId) {
const isLogicalDeleted = configService.get<Database>('DATABASE').DELETE_DATA.LOGICAL_MESSAGE_DELETE;
let message = await this.prismaRepository.message.findUnique({
where: { id: messageId },
let message = await this.prismaRepository.message.findFirst({
where: {
key: {
path: ['id'],
equals: messageId,
},
},
});
if (isLogicalDeleted) {
if (!message) return response;
const existingKey = typeof message?.key === 'object' && message.key !== null ? message.key : {};
message = await this.prismaRepository.message.update({
where: { id: messageId },
where: { id: message.id },
data: {
key: {
...existingKey,
deleted: true,
},
status: 'DELETED',
},
});
} else {
await this.prismaRepository.message.deleteMany({
where: {
id: messageId,
id: message.id,
},
});
}
Expand All @@ -3579,7 +3585,7 @@ export class BaileysStartupService extends ChannelStartupService {
instanceId: message.instanceId,
key: message.key,
messageType: message.messageType,
status: message.status,
status: 'DELETED',
source: message.source,
messageTimestamp: message.messageTimestamp,
pushName: message.pushName,
Expand Down

0 comments on commit ff5a8ad

Please sign in to comment.