fix: participant count

This commit is contained in:
Adhiraj Singh
2022-07-13 11:35:34 +05:30
parent 8742bc2fd5
commit 729f19ef3e

View File

@@ -243,7 +243,11 @@ export const makeMessagesSocket = (config: SocketConfig) => {
return didFetchNewSession return didFetchNewSession
} }
const createParticipantNodes = async(jids: string[], bytes: Buffer) => { const createParticipantNodes = async(
jids: string[],
bytes: Buffer,
extraAttrs?: BinaryNode['attrs']
) => {
let shouldIncludeDeviceIdentity = false let shouldIncludeDeviceIdentity = false
const nodes = await Promise.all( const nodes = await Promise.all(
jids.map( jids.map(
@@ -258,7 +262,11 @@ export const makeMessagesSocket = (config: SocketConfig) => {
attrs: { jid }, attrs: { jid },
content: [{ content: [{
tag: 'enc', tag: 'enc',
attrs: { v: '2', type }, attrs: {
v: '2',
type,
...extraAttrs || {}
},
content: ciphertext content: ciphertext
}] }]
} }
@@ -291,6 +299,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
const binaryNodeContent: BinaryNode[] = [] const binaryNodeContent: BinaryNode[] = []
const devices: JidWithDevice[] = [] const devices: JidWithDevice[] = []
const extraParticipantNodeAttrs: BinaryNode['attrs'] = { }
if(participant) { if(participant) {
// when the retry request is not for a group // when the retry request is not for a group
// only send to the specific device that asked for a retry // 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' } additionalAttributes = { ...additionalAttributes, device_fanout: 'false' }
} }
extraParticipantNodeAttrs.count = participant.count.toString()
const { user, device } = jidDecode(participant.jid)! const { user, device } = jidDecode(participant.jid)!
devices.push({ user, device }) devices.push({ user, device })
} }
@@ -362,7 +373,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
await assertSessions(senderKeyJids, false) await assertSessions(senderKeyJids, false)
const result = await createParticipantNodes(senderKeyJids, encSenderKeyMsg) const result = await createParticipantNodes(senderKeyJids, encSenderKeyMsg, extraParticipantNodeAttrs)
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity
participants.push(...result.nodes) participants.push(...result.nodes)
@@ -414,8 +425,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: meNodes, shouldIncludeDeviceIdentity: s1 },
{ nodes: otherNodes, shouldIncludeDeviceIdentity: s2 } { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }
] = await Promise.all([ ] = await Promise.all([
createParticipantNodes(meJids, encodedMeMsg), createParticipantNodes(meJids, encodedMeMsg, extraParticipantNodeAttrs),
createParticipantNodes(otherJids, encodedMsg) createParticipantNodes(otherJids, encodedMsg, extraParticipantNodeAttrs)
]) ])
participants.push(...meNodes) participants.push(...meNodes)
participants.push(...otherNodes) participants.push(...otherNodes)
@@ -423,12 +434,6 @@ export const makeMessagesSocket = (config: SocketConfig) => {
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2 shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2
} }
if(participant?.count) {
for(const node of participants) {
node.attrs.count = participant.count.toString()
}
}
if(participants.length) { if(participants.length) {
binaryNodeContent.push({ binaryNodeContent.push({
tag: 'participants', tag: 'participants',