feat: method to mark chat as unread

This commit is contained in:
Neander de Souza
2024-05-06 09:08:36 -03:00
parent 633dbb82d3
commit 8e9a1e2ba5
6 changed files with 100 additions and 0 deletions

View File

@@ -68,6 +68,7 @@ import {
DeleteMessage,
getBase64FromMediaMessageDto,
LastMessage,
MarkChatUnreadDto,
NumberBusiness,
OnWhatsAppDto,
PrivacySettingDto,
@@ -2714,6 +2715,45 @@ export class BaileysStartupService extends ChannelStartupService {
}
}
public async markChatUnread(data: MarkChatUnreadDto) {
this.logger.verbose('Marking chat as unread');
try {
let last_message = data.lastMessage;
let number = data.chat;
if (!last_message && number) {
last_message = await this.getLastMessage(number);
} else {
last_message = data.lastMessage;
last_message.messageTimestamp = last_message?.messageTimestamp ?? Date.now();
number = last_message?.key?.remoteJid;
}
if (!last_message || Object.keys(last_message).length === 0) {
throw new NotFoundException('Last message not found');
}
await this.client.chatModify(
{
markRead: false,
lastMessages: [last_message],
},
this.createJid(number),
);
return {
chatId: number,
markedChatUnread: true,
};
} catch (error) {
throw new InternalServerErrorException({
markedChatUnread: false,
message: ['An error occurred while marked unread the chat. Open a calling.', error.toString()],
});
}
}
public async deleteMessage(del: DeleteMessage) {
this.logger.verbose('Deleting message');
try {

View File

@@ -1258,6 +1258,9 @@ export class BusinessStartupService extends ChannelStartupService {
public async archiveChat() {
throw new BadRequestException('Method not available on WhatsApp Business API');
}
public async markChatUnread() {
throw new BadRequestException('Method not available on WhatsApp Business API');
}
public async fetchProfile() {
throw new BadRequestException('Method not available on WhatsApp Business API');
}