Update whatsapp.service.ts

This commit is contained in:
Alan Mosko 2023-07-27 09:24:38 -03:00
parent 52533d4b38
commit 3ae6944307

View File

@ -72,9 +72,9 @@ import {
ArchiveChatDto,
DeleteMessage,
getBase64FromMediaMessageDto,
LastMessage,
NumberBusiness,
OnWhatsAppDto,
LastMessage,
PrivacySettingDto,
ReadMessageDto,
WhatsAppNumberDto,
@ -2351,18 +2351,18 @@ export class WAStartupService {
const messages = await this.fetchMessages({
where: {
key: {
remoteJid: number
remoteJid: number,
},
owner: this.instance.name,
},
owner: this.instance.name
}
});
let lastMessage = messages.pop();
for (const message of messages) {
if (
message.messageTimestamp?.low >= lastMessage.messageTimestamp?.low
|| message.messageTimestamp >= lastMessage.messageTimestamp
message.messageTimestamp?.low >= lastMessage.messageTimestamp?.low ||
message.messageTimestamp >= lastMessage.messageTimestamp
) {
lastMessage = message;
}
@ -2386,16 +2386,16 @@ export class WAStartupService {
}
if (!last_message || Object.keys(last_message).length === 0) {
throw new NotFoundException("Last message not found");
throw new NotFoundException('Last message not found');
}
console.log(last_message);
await this.client.chatModify(
{
archive: data.archive,
lastMessages: [last_message]
lastMessages: [last_message],
},
this.createJid(number)
this.createJid(number),
);
return {