From bed9e384ba6bac53203de785ddd329dd3f564e21 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Thu, 4 Aug 2022 11:55:35 +0530 Subject: [PATCH] feat: added played receipt --- Example/example.ts | 2 +- src/Socket/messages-send.ts | 21 +++++++++++---------- src/Types/Message.ts | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Example/example.ts b/Example/example.ts index 4d109a5..de8f324 100644 --- a/Example/example.ts +++ b/Example/example.ts @@ -119,7 +119,7 @@ const startSock = async() => { for(const msg of upsert.messages) { if(!msg.key.fromMe && doReplies) { console.log('replying to', msg.key.remoteJid) - await sock!.sendReadReceipt(msg.key.remoteJid!, msg.key.participant!, [msg.key.id!]) + await sock!.readMessages([msg.key]) await sendMessageWTyping({ text: 'Hello there!' }, msg.key.remoteJid!) } } diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 7dbaa26..f9dddc6 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -108,19 +108,20 @@ export const makeMessagesSocket = (config: SocketConfig) => { await sendNode(node) } - const sendReadReceipt = async(jid: string, participant: string | undefined, messageIds: string[]) => { - const privacySettings = await fetchPrivacySettings() - // based on privacy settings, we have to change the read type - const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self' - return sendReceipt(jid, participant, messageIds, readType) + /** Correctly bulk send receipts to multiple chats, participants */ + const sendReceipts = async(keys: WAMessageKey[], type: MessageReceiptType) => { + const recps = aggregateMessageKeysNotFromMe(keys) + for(const { jid, participant, messageIds } of recps) { + await sendReceipt(jid, participant, messageIds, type) + } } /** Bulk read messages. Keys can be from different chats & participants */ const readMessages = async(keys: WAMessageKey[]) => { - const recps = aggregateMessageKeysNotFromMe(keys) - for(const { jid, participant, messageIds } of recps) { - await sendReadReceipt(jid, participant, messageIds) - } + const privacySettings = await fetchPrivacySettings() + // based on privacy settings, we have to change the read type + const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self' + await sendReceipts(keys, readType) } /** Fetch all the devices we've to send a message to */ @@ -527,7 +528,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { assertSessions, relayMessage, sendReceipt, - sendReadReceipt, + sendReceipts, readMessages, refreshMediaConn, waUploadToServer, diff --git a/src/Types/Message.ts b/src/Types/Message.ts index 3713447..17e843a 100644 --- a/src/Types/Message.ts +++ b/src/Types/Message.ts @@ -24,7 +24,7 @@ export type MessageType = keyof proto.Message export type DownloadableMessage = { mediaKey?: Uint8Array | null, directPath?: string | null, url?: string | null } -export type MessageReceiptType = 'read' | 'read-self' | 'hist_sync' | 'peer_msg' | 'sender' | 'inactive' | undefined +export type MessageReceiptType = 'read' | 'read-self' | 'hist_sync' | 'peer_msg' | 'sender' | 'inactive' | 'played' | undefined export type MediaConnInfo = { auth: string