From 729f19ef3eb93a086405f5341587d55513e1d5d9 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Wed, 13 Jul 2022 11:35:34 +0530 Subject: [PATCH] fix: participant count --- src/Socket/messages-send.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 030c189..9f2f506 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -243,7 +243,11 @@ export const makeMessagesSocket = (config: SocketConfig) => { return didFetchNewSession } - const createParticipantNodes = async(jids: string[], bytes: Buffer) => { + const createParticipantNodes = async( + jids: string[], + bytes: Buffer, + extraAttrs?: BinaryNode['attrs'] + ) => { let shouldIncludeDeviceIdentity = false const nodes = await Promise.all( jids.map( @@ -258,7 +262,11 @@ export const makeMessagesSocket = (config: SocketConfig) => { attrs: { jid }, content: [{ tag: 'enc', - attrs: { v: '2', type }, + attrs: { + v: '2', + type, + ...extraAttrs || {} + }, content: ciphertext }] } @@ -291,6 +299,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { const binaryNodeContent: BinaryNode[] = [] const devices: JidWithDevice[] = [] + const extraParticipantNodeAttrs: BinaryNode['attrs'] = { } if(participant) { // when the retry request is not for a group // only send to the specific device that asked for a retry @@ -299,6 +308,8 @@ export const makeMessagesSocket = (config: SocketConfig) => { additionalAttributes = { ...additionalAttributes, device_fanout: 'false' } } + extraParticipantNodeAttrs.count = participant.count.toString() + const { user, device } = jidDecode(participant.jid)! devices.push({ user, device }) } @@ -362,7 +373,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { await assertSessions(senderKeyJids, false) - const result = await createParticipantNodes(senderKeyJids, encSenderKeyMsg) + const result = await createParticipantNodes(senderKeyJids, encSenderKeyMsg, extraParticipantNodeAttrs) shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity participants.push(...result.nodes) @@ -414,8 +425,8 @@ export const makeMessagesSocket = (config: SocketConfig) => { { nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 } ] = await Promise.all([ - createParticipantNodes(meJids, encodedMeMsg), - createParticipantNodes(otherJids, encodedMsg) + createParticipantNodes(meJids, encodedMeMsg, extraParticipantNodeAttrs), + createParticipantNodes(otherJids, encodedMsg, extraParticipantNodeAttrs) ]) participants.push(...meNodes) participants.push(...otherNodes) @@ -423,12 +434,6 @@ export const makeMessagesSocket = (config: SocketConfig) => { shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2 } - if(participant?.count) { - for(const node of participants) { - node.attrs.count = participant.count.toString() - } - } - if(participants.length) { binaryNodeContent.push({ tag: 'participants',