UNPKG

anju-xpro-baileys

Version:
67 lines (66 loc) 2.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.USyncDeviceProtocol = void 0; const WABinary_1 = require("../../WABinary"); class USyncDeviceProtocol { constructor() { this.name = 'devices'; } getQueryElement() { return { tag: 'devices', attrs: { version: '2', }, }; } getUserElement( /* user: USyncUser */) { //TODO: Implement device phashing, ts and expectedTs //TODO: if all are not present, return null <- current behavior //TODO: otherwise return a node w tag 'devices' w those as attrs return null; } parser(node) { const deviceList = []; let keyIndex = undefined; if (node.tag === 'devices') { (0, WABinary_1.assertNodeErrorFree)(node); const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(node, 'device-list'); const keyIndexNode = (0, WABinary_1.getBinaryNodeChild)(node, 'key-index-list'); if (deviceListNode && Array.isArray(deviceListNode.content)) { for (const item of deviceListNode.content) { if (item.tag === 'device' && item.attrs) { const id = Number(item.attrs.id) || 0; const keyIndexValue = item.attrs['key-index'] ? Number(item.attrs['key-index']) : undefined; const isHosted = item.attrs['is_hosted'] === 'true'; deviceList.push({ id, keyIndex: keyIndexValue, isHosted }); } } } if ((keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.tag) === 'key-index-list' && keyIndexNode.attrs) { const timestamp = Number(keyIndexNode.attrs['ts']) || 0; const expectedTimestamp = keyIndexNode.attrs['expected_ts'] ? Number(keyIndexNode.attrs['expected_ts']) : undefined; keyIndex = { timestamp, signedKeyIndex: keyIndexNode.content instanceof Uint8Array ? keyIndexNode.content : undefined, expectedTimestamp }; } } return { deviceList: deviceList.length > 0 ? deviceList : undefined, keyIndex }; } } exports.USyncDeviceProtocol = USyncDeviceProtocol;