Merge master into fix/carousel-send-render-clean
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package proto;
|
package proto;
|
||||||
|
|
||||||
/// WhatsApp Version: 2.3000.1035216863
|
/// WhatsApp Version: 2.3000.1035302375
|
||||||
|
|
||||||
message ADVDeviceIdentity {
|
message ADVDeviceIdentity {
|
||||||
optional uint32 rawId = 1;
|
optional uint32 rawId = 1;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"version":[2,3000,1035223526]}
|
{"version":[2,3000,1035317910]}
|
||||||
|
|||||||
+52
-12
@@ -439,6 +439,39 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resolveSessionJid = async (jid: string) => {
|
||||||
|
if (isLidUser(jid) || isHostedLidUser(jid)) {
|
||||||
|
return jid
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPnUser(jid) || isHostedPnUser(jid)) {
|
||||||
|
return await signalRepository.lidMapping.getLIDForPN(jid) || jid
|
||||||
|
}
|
||||||
|
|
||||||
|
return jid
|
||||||
|
}
|
||||||
|
|
||||||
|
const canonicalizeSessionRecipients = async (recipientJids: string[]) => {
|
||||||
|
const uniqueRecipients = [...new Set(recipientJids)]
|
||||||
|
const canonicalRecipients: string[] = []
|
||||||
|
|
||||||
|
for (const jid of uniqueRecipients) {
|
||||||
|
const canonicalJid = await resolveSessionJid(jid)
|
||||||
|
if (!canonicalRecipients.includes(canonicalJid)) {
|
||||||
|
canonicalRecipients.push(canonicalJid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (canonicalRecipients.length !== uniqueRecipients.length || canonicalRecipients.some((jid, index) => jid !== uniqueRecipients[index])) {
|
||||||
|
logger.debug(
|
||||||
|
{ before: uniqueRecipients, after: canonicalRecipients },
|
||||||
|
'[SESSION] Canonicalized recipient addressing for session reuse'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return canonicalRecipients
|
||||||
|
}
|
||||||
|
|
||||||
const assertSessions = async (jids: string[], force?: boolean) => {
|
const assertSessions = async (jids: string[], force?: boolean) => {
|
||||||
let didFetchNewSession = false
|
let didFetchNewSession = false
|
||||||
const uniqueJids = [...new Set(jids)] // Deduplicate JIDs
|
const uniqueJids = [...new Set(jids)] // Deduplicate JIDs
|
||||||
@@ -448,22 +481,32 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
// Check peerSessionsCache and validate sessions using libsignal loadSession
|
// Check peerSessionsCache and validate sessions using libsignal loadSession
|
||||||
for (const jid of uniqueJids) {
|
for (const jid of uniqueJids) {
|
||||||
const signalId = signalRepository.jidToSignalProtocolAddress(jid)
|
const canonicalJid = await resolveSessionJid(jid)
|
||||||
const cachedSession = peerSessionsCache.get(signalId)
|
const signalIds = [
|
||||||
|
signalRepository.jidToSignalProtocolAddress(jid),
|
||||||
|
signalRepository.jidToSignalProtocolAddress(canonicalJid)
|
||||||
|
]
|
||||||
|
const cachedSession = signalIds
|
||||||
|
.map(signalId => peerSessionsCache.get(signalId))
|
||||||
|
.find(session => session !== undefined)
|
||||||
|
|
||||||
if (cachedSession !== undefined) {
|
if (cachedSession !== undefined) {
|
||||||
if (cachedSession && !force) {
|
if (cachedSession && !force) {
|
||||||
continue // Session exists in cache
|
continue // Session exists in cache
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const sessionValidation = await signalRepository.validateSession(jid)
|
const sessionValidation = await signalRepository.validateSession(canonicalJid)
|
||||||
const hasSession = sessionValidation.exists
|
const hasSession = sessionValidation.exists
|
||||||
peerSessionsCache.set(signalId, hasSession)
|
for (const signalId of signalIds) {
|
||||||
|
peerSessionsCache.set(signalId, hasSession)
|
||||||
|
}
|
||||||
|
|
||||||
if (hasSession && !force) {
|
if (hasSession && !force) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jidsRequiringFetch.push(jid)
|
jidsRequiringFetch.push(canonicalJid)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jidsRequiringFetch.length) {
|
if (jidsRequiringFetch.length) {
|
||||||
@@ -1199,13 +1242,10 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
allRecipients.push(jid)
|
allRecipients.push(jid)
|
||||||
}
|
}
|
||||||
|
|
||||||
const isCarouselFanout = isCarouselMessage(message)
|
|
||||||
const effectiveMeRecipients = isCarouselFanout
|
await assertSessions(allRecipients)
|
||||||
? await canonicalizeCarouselRecipients(meRecipients)
|
const effectiveMeRecipients = await canonicalizeSessionRecipients(meRecipients)
|
||||||
: meRecipients
|
const effectiveOtherRecipients = await canonicalizeSessionRecipients(otherRecipients)
|
||||||
const effectiveOtherRecipients = isCarouselFanout
|
|
||||||
? await canonicalizeCarouselRecipients(otherRecipients)
|
|
||||||
: otherRecipients
|
|
||||||
const effectiveAllRecipients = [...effectiveMeRecipients, ...effectiveOtherRecipients]
|
const effectiveAllRecipients = [...effectiveMeRecipients, ...effectiveOtherRecipients]
|
||||||
|
|
||||||
await assertSessions(effectiveAllRecipients)
|
await assertSessions(effectiveAllRecipients)
|
||||||
|
|||||||
Reference in New Issue
Block a user