From ee7ed1d4e5d45e4e79a89e3e7173cf4db99e5cc2 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Fri, 24 Jun 2022 11:46:47 +0530 Subject: [PATCH] feat: include last message in chat --- src/Utils/history.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Utils/history.ts b/src/Utils/history.ts index 1f8ea46..142260b 100644 --- a/src/Utils/history.ts +++ b/src/Utils/history.ts @@ -41,7 +41,8 @@ export const processHistoryMessage = ( historyCache.add(contactId) } - for(const { message } of chat.messages || []) { + const msgs = chat.messages || [] + for(const { message } of msgs) { const uqId = `${message.key.remoteJid}:${message.key.id}` if(!historyCache.has(uqId)) { messages.push(message) @@ -50,13 +51,14 @@ export const processHistoryMessage = ( const timestamp = toNumber(message.messageTimestamp) if(!message.key.fromMe && (!curItem || timestamp > curItem.lastMsgRecvTimestamp)) { recvChats[message.key.remoteJid] = { lastMsgRecvTimestamp: timestamp } + // keep only the most recent message in the chat array + chat.messages = [{ message }] } historyCache.add(uqId) } } - delete chat.messages if(!historyCache.has(chat.id)) { if(isJidUser(chat.id) && chat.readOnly && chat.archived) { chat.readOnly = false