mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: correctly respond to retry requests
This commit is contained in:
@@ -6,7 +6,7 @@ import { WA_DEFAULT_EPHEMERAL } from '../Defaults'
|
|||||||
import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types'
|
import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types'
|
||||||
import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeWAMessage, encryptMediaRetryRequest, encryptSenderKeyMsgSignalProto, encryptSignalProto, extractDeviceJids, generateMessageID, generateWAMessage, getUrlFromDirectPath, getWAUploadToServer, jidToSignalProtocolAddress, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils'
|
import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeWAMessage, encryptMediaRetryRequest, encryptSenderKeyMsgSignalProto, encryptSignalProto, extractDeviceJids, generateMessageID, generateWAMessage, getUrlFromDirectPath, getWAUploadToServer, jidToSignalProtocolAddress, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils'
|
||||||
import { getUrlInfo } from '../Utils/link-preview'
|
import { getUrlInfo } from '../Utils/link-preview'
|
||||||
import { BinaryNode, BinaryNodeAttributes, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidDecode, jidEncode, jidNormalizedUser, JidWithDevice, reduceBinaryNodeToDictionary, S_WHATSAPP_NET } from '../WABinary'
|
import { areJidsSameUser, BinaryNode, BinaryNodeAttributes, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidDecode, jidEncode, jidNormalizedUser, JidWithDevice, reduceBinaryNodeToDictionary, S_WHATSAPP_NET } from '../WABinary'
|
||||||
import { makeGroupsSocket } from './groups'
|
import { makeGroupsSocket } from './groups'
|
||||||
|
|
||||||
export const makeMessagesSocket = (config: SocketConfig) => {
|
export const makeMessagesSocket = (config: SocketConfig) => {
|
||||||
@@ -327,8 +327,12 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
return groupData
|
return groupData
|
||||||
})(),
|
})(),
|
||||||
(async() => {
|
(async() => {
|
||||||
const result = await authState.keys.get('sender-key-memory', [jid])
|
if(!participant) {
|
||||||
return result[jid] || { }
|
const result = await authState.keys.get('sender-key-memory', [jid])
|
||||||
|
return result[jid] || { }
|
||||||
|
}
|
||||||
|
|
||||||
|
return { }
|
||||||
})()
|
})()
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -342,7 +346,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
// ensure a connection is established with every device
|
// ensure a connection is established with every device
|
||||||
for(const { user, device } of devices) {
|
for(const { user, device } of devices) {
|
||||||
const jid = jidEncode(user, 's.whatsapp.net', device)
|
const jid = jidEncode(user, 's.whatsapp.net', device)
|
||||||
if(!senderKeyMap[jid]) {
|
if(!senderKeyMap[jid] || !!participant) {
|
||||||
senderKeyJids.push(jid)
|
senderKeyJids.push(jid)
|
||||||
// store that this person has had the sender keys sent to them
|
// store that this person has had the sender keys sent to them
|
||||||
senderKeyMap[jid] = true
|
senderKeyMap[jid] = true
|
||||||
@@ -424,11 +428,26 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
attrs: {
|
attrs: {
|
||||||
id: msgId,
|
id: msgId,
|
||||||
type: 'text',
|
type: 'text',
|
||||||
to: destinationJid,
|
|
||||||
...(additionalAttributes || {})
|
...(additionalAttributes || {})
|
||||||
},
|
},
|
||||||
content: binaryNodeContent
|
content: binaryNodeContent
|
||||||
}
|
}
|
||||||
|
// if the participant to send to is explicitly specified (generally retry recp)
|
||||||
|
// ensure the message is only sent to that person
|
||||||
|
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
||||||
|
if(participant) {
|
||||||
|
if(isJidGroup(destinationJid)) {
|
||||||
|
stanza.attrs.to = destinationJid
|
||||||
|
stanza.attrs.participant = participant
|
||||||
|
} else if(areJidsSameUser(participant, meId)) {
|
||||||
|
stanza.attrs.to = participant
|
||||||
|
stanza.attrs.recipient = destinationJid
|
||||||
|
} else {
|
||||||
|
stanza.attrs.to = participant
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stanza.attrs.to = destinationJid
|
||||||
|
}
|
||||||
|
|
||||||
const shouldHaveIdentity = !!participants.find(
|
const shouldHaveIdentity = !!participants.find(
|
||||||
participant => (participant.content! as BinaryNode[]).find(n => n.attrs.type === 'pkmsg')
|
participant => (participant.content! as BinaryNode[]).find(n => n.attrs.type === 'pkmsg')
|
||||||
|
|||||||
Reference in New Issue
Block a user