lid-mapping,signal: improvements to hosted device support in lid map
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { LRUCache } from 'lru-cache'
|
||||
import type { LIDMapping, SignalKeyStoreWithTransaction } from '../Types'
|
||||
import type { ILogger } from '../Utils/logger'
|
||||
import { isLidUser, isPnUser, jidDecode, jidNormalizedUser } from '../WABinary'
|
||||
import { isJidHostedLidUser, isJidHostedPnUser, isLidUser, isPnUser, jidDecode, jidNormalizedUser } from '../WABinary'
|
||||
|
||||
export class LIDMappingStore {
|
||||
private readonly mappingCache = new LRUCache<string, string>({
|
||||
@@ -113,11 +113,15 @@ export class LIDMappingStore {
|
||||
} else {
|
||||
this.logger.trace(`No LID mapping found for PN user ${pnUser}; batch getting from USync`)
|
||||
const device = decoded.device || 0
|
||||
const normalizedPn = jidNormalizedUser(pn)
|
||||
let normalizedPn = jidNormalizedUser(pn)
|
||||
if (isJidHostedLidUser(normalizedPn) || isJidHostedPnUser(normalizedPn)) {
|
||||
normalizedPn = `${pnUser}@s.whatsapp.net`
|
||||
}
|
||||
|
||||
if (!usyncFetch[normalizedPn]) {
|
||||
usyncFetch[normalizedPn] = [device]
|
||||
} else {
|
||||
usyncFetch[normalizedPn].push(device)
|
||||
usyncFetch[normalizedPn]?.push(device)
|
||||
}
|
||||
|
||||
continue
|
||||
@@ -132,7 +136,7 @@ export class LIDMappingStore {
|
||||
|
||||
// Push the PN device ID to the LID to maintain device separation
|
||||
const pnDevice = decoded.device !== undefined ? decoded.device : 0
|
||||
const deviceSpecificLid = `${lidUser}${!!pnDevice ? `:${pnDevice}` : ``}@lid`
|
||||
const deviceSpecificLid = `${lidUser}${!!pnDevice ? `:${pnDevice}` : ``}@${decoded.server === 'hosted' ? 'hosted.lid' : 'lid'}`
|
||||
|
||||
this.logger.trace(`getLIDForPN: ${pn} → ${deviceSpecificLid} (user mapping with device ${pnDevice})`)
|
||||
successfulPairs[pn] = { lid: deviceSpecificLid, pn }
|
||||
@@ -143,19 +147,20 @@ export class LIDMappingStore {
|
||||
if (result && result.length > 0) {
|
||||
this.storeLIDPNMappings(result)
|
||||
for (const pair of result) {
|
||||
const pnUser = jidDecode(pair.pn)?.user
|
||||
const pnDecoded = jidDecode(pair.pn)
|
||||
const pnUser = pnDecoded?.user
|
||||
if (!pnUser) continue
|
||||
const lidUser = jidDecode(pair.lid)?.user
|
||||
if (!lidUser) continue
|
||||
|
||||
for (const device of usyncFetch[pair.pn]!) {
|
||||
const deviceSpecificLid = `${lidUser}${!!device ? `:${device}` : ``}@lid`
|
||||
const deviceSpecificLid = `${lidUser}${!!device ? `:${device}` : ``}@${device == 99 ? 'hosted.lid' : 'lid'}`
|
||||
|
||||
this.logger.trace(
|
||||
`getLIDForPN: USYNC success for ${pair.pn} → ${deviceSpecificLid} (user mapping with device ${device})`
|
||||
)
|
||||
|
||||
const deviceSpecificPn = `${pnUser}${!!device ? `:${device}` : ``}@s.whatsapp.net`
|
||||
const deviceSpecificPn = `${pnUser}${!!device ? `:${device}` : ``}@${device == 99 ? 'hosted' : 's.whatsapp.net'}`
|
||||
|
||||
successfulPairs[deviceSpecificPn] = { lid: deviceSpecificLid, pn: deviceSpecificPn }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user