mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-19 03:42:23 -06:00
feat: method to mark chat as unread
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user