signal,messages-send,libsignal: properly parse and ignore hosted devices
This commit is contained in:
+11
-6
@@ -17,7 +17,8 @@ import {
|
||||
getBinaryNodeChildren,
|
||||
getBinaryNodeChildUInt,
|
||||
jidDecode,
|
||||
S_WHATSAPP_NET
|
||||
S_WHATSAPP_NET,
|
||||
WAJIDDomains
|
||||
} from '../WABinary'
|
||||
import type { DeviceListData, ParsedDeviceInfo, USyncQueryResultList } from '../WAUSync'
|
||||
import { Curve, generateSignalPubKey } from './crypto'
|
||||
@@ -131,24 +132,28 @@ export const parseAndInjectE2ESessions = async (node: BinaryNode, repository: Si
|
||||
}
|
||||
}
|
||||
|
||||
export const extractDeviceJids = (result: USyncQueryResultList[], myJid: string, excludeZeroDevices: boolean) => {
|
||||
export const extractDeviceJids = (
|
||||
result: USyncQueryResultList[],
|
||||
myJid: string,
|
||||
myLid: string,
|
||||
excludeZeroDevices: boolean
|
||||
) => {
|
||||
const { user: myUser, device: myDevice } = jidDecode(myJid)!
|
||||
|
||||
const extracted: FullJid[] = []
|
||||
|
||||
for (const userResult of result) {
|
||||
// TODO: ADD SUPPORT FOR HOSTED JIDS
|
||||
const { devices, id } = userResult as { devices: ParsedDeviceInfo; id: string }
|
||||
const { user } = jidDecode(id)!
|
||||
const { user, domainType, server } = jidDecode(id)!
|
||||
const deviceList = devices?.deviceList as DeviceListData[]
|
||||
if (Array.isArray(deviceList)) {
|
||||
for (const { id: device, keyIndex, isHosted } of deviceList) {
|
||||
if (
|
||||
(!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
||||
(myUser !== 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
|
||||
) {
|
||||
extracted.push({ user, device, server: isHosted ? 'hosted' : 's.whatsapp.net' })
|
||||
extracted.push({ user, device, domainType, server })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user