mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-19 03:42:23 -06:00
Merge pull request #981 from yousseefspires/feat/delete-messages
feat: add logical or permanent message deletion based on env config
This commit is contained in:
@@ -3040,7 +3040,49 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
|
||||
public async deleteMessage(del: DeleteMessage) {
|
||||
try {
|
||||
return await this.client.sendMessage(del.remoteJid, { delete: del });
|
||||
const response = await this.client.sendMessage(del.remoteJid, { delete: del });
|
||||
if (response) {
|
||||
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 },
|
||||
});
|
||||
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 },
|
||||
data: {
|
||||
key: {
|
||||
...existingKey,
|
||||
deleted: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await this.prismaRepository.message.deleteMany({
|
||||
where: {
|
||||
id: messageId,
|
||||
},
|
||||
});
|
||||
}
|
||||
this.sendDataWebhook(Events.MESSAGES_DELETE, {
|
||||
id: message.id,
|
||||
instanceId: message.instanceId,
|
||||
key: message.key,
|
||||
messageType: message.messageType,
|
||||
status: message.status,
|
||||
source: message.source,
|
||||
messageTimestamp: message.messageTimestamp,
|
||||
pushName: message.pushName,
|
||||
participant: message.participant,
|
||||
message: message.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
throw new InternalServerErrorException('Error while deleting message for everyone', error?.toString());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user