@nexustechpro/baileys 2.1.0 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/Defaults/index.js +1 -0
- package/lib/Socket/chats.js +180 -272
- package/lib/Socket/messages-recv.js +8 -5
- package/lib/Socket/messages-send.js +16 -15
- package/lib/Utils/chat-utils.js +318 -619
- package/lib/Utils/key-store.js +10 -5
- package/lib/Utils/lt-hash.js +2 -43
- package/lib/Utils/messages.js +89 -64
- package/lib/Utils/process-message.js +234 -215
- package/lib/Utils/tc-token-utils.js +38 -73
- package/lib/Utils/use-multi-file-auth-state.js +18 -8
- package/lib/index.js +1 -1
- package/package.json +2 -2
|
@@ -278,7 +278,8 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
278
278
|
if (senderTs === null || senderTs === undefined || isTcTokenExpired(senderTs)) return
|
|
279
279
|
logger.debug({ jid: normalizedJid, senderTimestamp: senderTs }, 'identity changed, re-issuing tctoken')
|
|
280
280
|
const getPNForLID = signalRepository.lidMapping.getPNForLID.bind(signalRepository.lidMapping)
|
|
281
|
-
const
|
|
281
|
+
const issueToLid = sock.serverProps?.lidTrustedTokenIssueToLid ?? false
|
|
282
|
+
const issueJid = await resolveIssuanceJid(normalizedJid, issueToLid, getLIDForPN, getPNForLID)
|
|
282
283
|
const result = await issuePrivacyTokens([issueJid], senderTs)
|
|
283
284
|
await storeTcTokensFromIqResult({ result, fallbackJid: tcJid, keys: authState.keys, getLIDForPN, onNewJidStored: trackTcTokenJid })
|
|
284
285
|
})().catch(err => logger.debug({ jid: from, err: err?.message }, 'failed to re-issue tctoken after identity change'))
|
|
@@ -526,7 +527,7 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
526
527
|
|
|
527
528
|
const tcTokenKnownJids = new Set()
|
|
528
529
|
const tcTokenIndexLoaded = (async () => {
|
|
529
|
-
try { const jids = await readTcTokenIndex(authState.keys); for (const jid of jids) tcTokenKnownJids.add(jid); logger.debug({ count: tcTokenKnownJids.size }, 'loaded tctoken index') }
|
|
530
|
+
try { const jids = await readTcTokenIndex(authState.keys); for (const jid of jids) tcTokenKnownJids.add(jid); if (tcTokenKnownJids.size > 0) logger.debug({ count: tcTokenKnownJids.size }, 'loaded tctoken index') }
|
|
530
531
|
catch (err) { logger.warn({ err: err?.message }, 'failed to load tctoken index') }
|
|
531
532
|
})()
|
|
532
533
|
|
|
@@ -831,7 +832,8 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
831
832
|
try {
|
|
832
833
|
const getPNForLID = signalRepository.lidMapping.getPNForLID.bind(signalRepository.lidMapping)
|
|
833
834
|
const tcStorageJid = await resolveTcTokenJid(ackFrom, getLIDForPN)
|
|
834
|
-
const
|
|
835
|
+
const issueToLid = sock.serverProps?.lidTrustedTokenIssueToLid ?? false
|
|
836
|
+
const issueJid = await resolveIssuanceJid(ackFrom, issueToLid, getLIDForPN, getPNForLID)
|
|
835
837
|
const result = await issuePrivacyTokens([issueJid], unixTimestampSeconds())
|
|
836
838
|
await storeTcTokensFromIqResult({ result, fallbackJid: tcStorageJid, keys: authState.keys, getLIDForPN, onNewJidStored: trackTcTokenJid })
|
|
837
839
|
logger.debug({ from: ackFrom }, 'completed 463 token recovery issuance')
|
|
@@ -940,7 +942,8 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
940
942
|
else survivors.add(jid)
|
|
941
943
|
}
|
|
942
944
|
if (mutated === 0) return
|
|
943
|
-
await authState.keys
|
|
945
|
+
const indexWrite = await buildMergedTcTokenIndexWrite(authState.keys, [...survivors])
|
|
946
|
+
await authState.keys.set({ tctoken: { ...writes, ...indexWrite } })
|
|
944
947
|
tcTokenKnownJids.clear()
|
|
945
948
|
for (const jid of survivors) tcTokenKnownJids.add(jid)
|
|
946
949
|
logger.debug({ mutated, remaining: survivors.size }, 'pruned expired tctokens')
|
|
@@ -960,5 +963,5 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
960
963
|
sendActiveReceipts = false
|
|
961
964
|
})
|
|
962
965
|
|
|
963
|
-
return { ...sock, sendMessageAck, sendRetryRequest, rejectCall, offerCall, fetchMessageHistory, requestPlaceholderResend, messageRetryManager }
|
|
966
|
+
return { ...sock, sendMessageAck, sendRetryRequest, rejectCall, offerCall, fetchMessageHistory, requestPlaceholderResend, messageRetryManager, tcTokenIndexLoaded }
|
|
964
967
|
}
|
|
@@ -362,12 +362,11 @@ export const makeMessagesSocket = (config) => {
|
|
|
362
362
|
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList, quoted } = {}) => {
|
|
363
363
|
const meId = authState.creds.me.id
|
|
364
364
|
const meLid = authState.creds.me?.lid
|
|
365
|
-
|
|
365
|
+
let { user, server } = jidDecode(jid)
|
|
366
366
|
const isGroup = server === 'g.us'
|
|
367
367
|
const isStatus = jid === 'status@broadcast'
|
|
368
|
-
|
|
368
|
+
let isLid = server === 'lid'
|
|
369
369
|
const isNewsletter = server === 'newsletter'
|
|
370
|
-
|
|
371
370
|
let activeSender = meId
|
|
372
371
|
let groupAddressingMode = 'pn'
|
|
373
372
|
if (isGroup && !isStatus) {
|
|
@@ -536,6 +535,14 @@ export const makeMessagesSocket = (config) => {
|
|
|
536
535
|
if (isLid && meLid) { ownId = meLid; logger.debug({ to: jid, ownId }, 'Using LID identity') }
|
|
537
536
|
|
|
538
537
|
const { user: ownUser } = jidDecode(ownId)
|
|
538
|
+
const targetUserServer = isLid ? 'lid' : 's.whatsapp.net'
|
|
539
|
+
devices.push({ user, device: 0, jid: jidEncode(user, targetUserServer, 0) })
|
|
540
|
+
|
|
541
|
+
if (user !== ownUser) {
|
|
542
|
+
const ownUserServer = isLid ? 'lid' : 's.whatsapp.net'
|
|
543
|
+
const ownUserForAddressing = isLid && meLid ? jidDecode(meLid).user : jidDecode(meId).user
|
|
544
|
+
devices.push({ user: ownUserForAddressing, device: 0, jid: jidEncode(ownUserForAddressing, ownUserServer, 0) })
|
|
545
|
+
}
|
|
539
546
|
|
|
540
547
|
if (!participant) {
|
|
541
548
|
const targetUserServer = isLid ? 'lid' : 's.whatsapp.net'
|
|
@@ -564,22 +571,16 @@ export const makeMessagesSocket = (config) => {
|
|
|
564
571
|
}
|
|
565
572
|
}
|
|
566
573
|
}
|
|
567
|
-
|
|
568
574
|
const allRecipients = [], meRecipients = [], otherRecipients = []
|
|
569
575
|
const { user: mePnUser } = jidDecode(meId)
|
|
570
576
|
const { user: meLidUser } = meLid ? jidDecode(meLid) : { user: null }
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
if (isMe) meRecipients.push(jid)
|
|
577
|
-
else otherRecipients.push(jid)
|
|
578
|
-
allRecipients.push(jid)
|
|
577
|
+
for (const { user: devUser, jid: devJid } of devices) {
|
|
578
|
+
const isOwnUser = devUser === mePnUser || devUser === meLidUser
|
|
579
|
+
if (isOwnUser) meRecipients.push(devJid)
|
|
580
|
+
else otherRecipients.push(devJid)
|
|
581
|
+
allRecipients.push(devJid)
|
|
579
582
|
}
|
|
580
|
-
|
|
581
583
|
await assertSessions(allRecipients)
|
|
582
|
-
|
|
583
584
|
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
584
585
|
createParticipantNodes(meRecipients, meMsg || message, extraAttrs),
|
|
585
586
|
createParticipantNodes(otherRecipients, message, extraAttrs, meMsg)
|
|
@@ -607,7 +608,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
607
608
|
id: finalMsgId,
|
|
608
609
|
to: destinationJid,
|
|
609
610
|
type: getMessageType(message),
|
|
610
|
-
...(
|
|
611
|
+
...((isGroup && groupAddressingMode === 'lid') ? { addressing_mode: 'lid' } : {}),
|
|
611
612
|
...(hasDeviceFanoutFalse ? { device_fanout: 'false' } : {}),
|
|
612
613
|
...(additionalAttributes || {})
|
|
613
614
|
},
|