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 { LRUCache } from 'lru-cache'
|
||||||
import type { LIDMapping, SignalKeyStoreWithTransaction } from '../Types'
|
import type { LIDMapping, SignalKeyStoreWithTransaction } from '../Types'
|
||||||
import type { ILogger } from '../Utils/logger'
|
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 {
|
export class LIDMappingStore {
|
||||||
private readonly mappingCache = new LRUCache<string, string>({
|
private readonly mappingCache = new LRUCache<string, string>({
|
||||||
@@ -113,11 +113,15 @@ export class LIDMappingStore {
|
|||||||
} else {
|
} else {
|
||||||
this.logger.trace(`No LID mapping found for PN user ${pnUser}; batch getting from USync`)
|
this.logger.trace(`No LID mapping found for PN user ${pnUser}; batch getting from USync`)
|
||||||
const device = decoded.device || 0
|
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]) {
|
if (!usyncFetch[normalizedPn]) {
|
||||||
usyncFetch[normalizedPn] = [device]
|
usyncFetch[normalizedPn] = [device]
|
||||||
} else {
|
} else {
|
||||||
usyncFetch[normalizedPn].push(device)
|
usyncFetch[normalizedPn]?.push(device)
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
@@ -132,7 +136,7 @@ export class LIDMappingStore {
|
|||||||
|
|
||||||
// Push the PN device ID to the LID to maintain device separation
|
// Push the PN device ID to the LID to maintain device separation
|
||||||
const pnDevice = decoded.device !== undefined ? decoded.device : 0
|
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})`)
|
this.logger.trace(`getLIDForPN: ${pn} → ${deviceSpecificLid} (user mapping with device ${pnDevice})`)
|
||||||
successfulPairs[pn] = { lid: deviceSpecificLid, pn }
|
successfulPairs[pn] = { lid: deviceSpecificLid, pn }
|
||||||
@@ -143,19 +147,20 @@ export class LIDMappingStore {
|
|||||||
if (result && result.length > 0) {
|
if (result && result.length > 0) {
|
||||||
this.storeLIDPNMappings(result)
|
this.storeLIDPNMappings(result)
|
||||||
for (const pair of result) {
|
for (const pair of result) {
|
||||||
const pnUser = jidDecode(pair.pn)?.user
|
const pnDecoded = jidDecode(pair.pn)
|
||||||
|
const pnUser = pnDecoded?.user
|
||||||
if (!pnUser) continue
|
if (!pnUser) continue
|
||||||
const lidUser = jidDecode(pair.lid)?.user
|
const lidUser = jidDecode(pair.lid)?.user
|
||||||
if (!lidUser) continue
|
if (!lidUser) continue
|
||||||
|
|
||||||
for (const device of usyncFetch[pair.pn]!) {
|
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(
|
this.logger.trace(
|
||||||
`getLIDForPN: USYNC success for ${pair.pn} → ${deviceSpecificLid} (user mapping with device ${device})`
|
`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 }
|
successfulPairs[deviceSpecificPn] = { lid: deviceSpecificLid, pn: deviceSpecificPn }
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -18,7 +18,7 @@ import {
|
|||||||
getBinaryNodeChildUInt,
|
getBinaryNodeChildUInt,
|
||||||
jidDecode,
|
jidDecode,
|
||||||
S_WHATSAPP_NET,
|
S_WHATSAPP_NET,
|
||||||
WAJIDDomains
|
WAJIDDomains,
|
||||||
} from '../WABinary'
|
} from '../WABinary'
|
||||||
import type { DeviceListData, ParsedDeviceInfo, USyncQueryResultList } from '../WAUSync'
|
import type { DeviceListData, ParsedDeviceInfo, USyncQueryResultList } from '../WAUSync'
|
||||||
import { Curve, generateSignalPubKey } from './crypto'
|
import { Curve, generateSignalPubKey } from './crypto'
|
||||||
@@ -153,7 +153,7 @@ export const extractDeviceJids = (
|
|||||||
((myUser !== user && myLid !== user) || myDevice !== device) && // either different user or if me user, not this device
|
((myUser !== user && myLid !== user) || myDevice !== device) && // either different user or if me user, not this device
|
||||||
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
||||||
) {
|
) {
|
||||||
extracted.push({ user, device, domainType, server })
|
extracted.push({ user, device, domainType: isHosted ? domainType === WAJIDDomains.LID ? WAJIDDomains.HOSTED_LID : WAJIDDomains.HOSTED : domainType, server })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user