From c195e999f13196dc2802210950e61a2d5100a8ba Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Thu, 9 Sep 2021 18:24:33 +0530 Subject: [PATCH] push msg updates for individual chats --- src/Connection/messages.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Connection/messages.ts b/src/Connection/messages.ts index c6a3bc8..9432eb0 100644 --- a/src/Connection/messages.ts +++ b/src/Connection/messages.ts @@ -398,17 +398,29 @@ const makeMessagesSocket = (config: SocketConfig) => { logger.warn({ attributes }, `received unknown message info update`) return } + const keyPartial = { + remoteJid: whatsappID(attributes.to), + fromMe: whatsappID(attributes.from) === getState().user?.jid, + } const updates = ids.map(id => ({ - key: { - remoteJid: whatsappID(attributes.to), - id, - fromMe: whatsappID(attributes.from) === getState().user?.jid, - }, + key: { ...keyPartial, id }, update: { [updateKey]: { [whatsappID(attributes.participant)]: new Date(+attributes.t) } } })) ev.emit('message-info.update', updates) + // for individual messages + // it means the message is marked read/delivered + if(!isGroupID(keyPartial.remoteJid)) { + ev.emit('messages.update', ids.map(id => ( + { + key: { ...keyPartial, id }, + update: { + status: updateKey === 'deliveries' ? WAMessageStatus.DELIVERY_ACK : WAMessageStatus.READ + } + } + ))) + } } socketEvents.on('CB:action,add:relay,received', onMessageStatusUpdate)