general: preliminary support for @hosted + Usync LID stuff
This commit is contained in:
@@ -39,6 +39,7 @@ import {
|
|||||||
areJidsSameUser,
|
areJidsSameUser,
|
||||||
type BinaryNode,
|
type BinaryNode,
|
||||||
type BinaryNodeAttributes,
|
type BinaryNodeAttributes,
|
||||||
|
type FullJid,
|
||||||
getBinaryNodeChild,
|
getBinaryNodeChild,
|
||||||
getBinaryNodeChildren,
|
getBinaryNodeChildren,
|
||||||
isJidGroup,
|
isJidGroup,
|
||||||
@@ -281,7 +282,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = new USyncQuery().withContext('message').withDeviceProtocol()
|
const query = new USyncQuery().withContext('message').withDeviceProtocol().withLIDProtocol()
|
||||||
|
|
||||||
for (const jid of toFetch) {
|
for (const jid of toFetch) {
|
||||||
query.withUser(new USyncUser().withId(jid)) // todo: investigate - the idea here is that <user> should have an inline lid field with the lid being the pn equivalent
|
query.withUser(new USyncUser().withId(jid)) // todo: investigate - the idea here is that <user> should have an inline lid field with the lid being the pn equivalent
|
||||||
@@ -290,8 +291,9 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
const result = await sock.executeUSyncQuery(query)
|
const result = await sock.executeUSyncQuery(query)
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
// TODO: LID MAP this stuff (lid protocol will now return lid with devices)
|
||||||
const extracted = extractDeviceJids(result?.list, authState.creds.me!.id, ignoreZeroDevices)
|
const extracted = extractDeviceJids(result?.list, authState.creds.me!.id, ignoreZeroDevices)
|
||||||
const deviceMap: { [_: string]: JidWithDevice[] } = {}
|
const deviceMap: { [_: string]: FullJid[] } = {}
|
||||||
|
|
||||||
for (const item of extracted) {
|
for (const item of extracted) {
|
||||||
deviceMap[item.user] = deviceMap[item.user] || []
|
deviceMap[item.user] = deviceMap[item.user] || []
|
||||||
@@ -305,8 +307,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
// Process all devices for this user
|
// Process all devices for this user
|
||||||
for (const item of userDevices) {
|
for (const item of userDevices) {
|
||||||
const finalJid = isLidUser
|
const finalJid = isLidUser
|
||||||
? jidEncode(user, 'lid', item.device)
|
? jidEncode(user, item.server == 'hosted' ? 'hosted.lid' : 'lid', item.device)
|
||||||
: jidEncode(item.user, 's.whatsapp.net', item.device)
|
: jidEncode(item.user, item.server == 'hosted' ? 'hosted' :'s.whatsapp.net', item.device)
|
||||||
|
|
||||||
deviceResults.push({
|
deviceResults.push({
|
||||||
...item,
|
...item,
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ export function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: strin
|
|||||||
let msgType: MessageType
|
let msgType: MessageType
|
||||||
let chatId: string
|
let chatId: string
|
||||||
let author: string
|
let author: string
|
||||||
let fromMe: boolean = false
|
let fromMe = false
|
||||||
|
|
||||||
const msgId = stanza.attrs.id
|
const msgId = stanza.attrs.id
|
||||||
const from = stanza.attrs.from
|
const from = stanza.attrs.from
|
||||||
|
|||||||
+5
-3
@@ -11,6 +11,7 @@ import type {
|
|||||||
import {
|
import {
|
||||||
assertNodeErrorFree,
|
assertNodeErrorFree,
|
||||||
type BinaryNode,
|
type BinaryNode,
|
||||||
|
type FullJid,
|
||||||
getBinaryNodeChild,
|
getBinaryNodeChild,
|
||||||
getBinaryNodeChildBuffer,
|
getBinaryNodeChildBuffer,
|
||||||
getBinaryNodeChildren,
|
getBinaryNodeChildren,
|
||||||
@@ -134,20 +135,21 @@ export const parseAndInjectE2ESessions = async (node: BinaryNode, repository: Si
|
|||||||
export const extractDeviceJids = (result: USyncQueryResultList[], myJid: string, excludeZeroDevices: boolean) => {
|
export const extractDeviceJids = (result: USyncQueryResultList[], myJid: string, excludeZeroDevices: boolean) => {
|
||||||
const { user: myUser, device: myDevice } = jidDecode(myJid)!
|
const { user: myUser, device: myDevice } = jidDecode(myJid)!
|
||||||
|
|
||||||
const extracted: JidWithDevice[] = []
|
const extracted: FullJid[] = []
|
||||||
|
|
||||||
for (const userResult of result) {
|
for (const userResult of result) {
|
||||||
|
// TODO: ADD SUPPORT FOR HOSTED JIDS
|
||||||
const { devices, id } = userResult as { devices: ParsedDeviceInfo; id: string }
|
const { devices, id } = userResult as { devices: ParsedDeviceInfo; id: string }
|
||||||
const { user } = jidDecode(id)!
|
const { user } = jidDecode(id)!
|
||||||
const deviceList = devices?.deviceList as DeviceListData[]
|
const deviceList = devices?.deviceList as DeviceListData[]
|
||||||
if (Array.isArray(deviceList)) {
|
if (Array.isArray(deviceList)) {
|
||||||
for (const { id: device, keyIndex } of deviceList) {
|
for (const { id: device, keyIndex, isHosted } of deviceList) {
|
||||||
if (
|
if (
|
||||||
(!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
(!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 || 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 })
|
extracted.push({ user, device, server: isHosted ? 'hosted' : 's.whatsapp.net' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export const PSA_WID = '0@c.us'
|
|||||||
export const STORIES_JID = 'status@broadcast'
|
export const STORIES_JID = 'status@broadcast'
|
||||||
export const META_AI_JID = '13135550002@c.us'
|
export const META_AI_JID = '13135550002@c.us'
|
||||||
|
|
||||||
export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid' | 'newsletter' | 'bot'
|
export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid' | 'newsletter' | 'bot' | 'hosted' | 'hosted.lid'
|
||||||
|
|
||||||
export type JidWithDevice = {
|
export type JidWithDevice = {
|
||||||
user: string
|
user: string
|
||||||
@@ -14,11 +14,10 @@ export type JidWithDevice = {
|
|||||||
|
|
||||||
export type FullJid = JidWithDevice & {
|
export type FullJid = JidWithDevice & {
|
||||||
server: JidServer
|
server: JidServer
|
||||||
domainType?: number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const jidEncode = (user: string | number | null, server: JidServer, device?: number, agent?: number) => {
|
export const jidEncode = (user: string | number | null, server: JidServer, device?: number, agent?: number) => {
|
||||||
return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`
|
return `${user || ''}${!!agent ? `.${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const jidDecode = (jid: string | undefined): FullJid | undefined => {
|
export const jidDecode = (jid: string | undefined): FullJid | undefined => {
|
||||||
@@ -36,7 +35,6 @@ export const jidDecode = (jid: string | undefined): FullJid | undefined => {
|
|||||||
return {
|
return {
|
||||||
server: server as JidServer,
|
server: server as JidServer,
|
||||||
user,
|
user,
|
||||||
domainType: server === 'lid' ? 1 : 0,
|
|
||||||
device: device ? +device : undefined
|
device: device ? +device : undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,6 +56,10 @@ export const isJidGroup = (jid: string | undefined) => jid?.endsWith('@g.us')
|
|||||||
export const isJidStatusBroadcast = (jid: string) => jid === 'status@broadcast'
|
export const isJidStatusBroadcast = (jid: string) => jid === 'status@broadcast'
|
||||||
/** is the jid a newsletter */
|
/** is the jid a newsletter */
|
||||||
export const isJidNewsletter = (jid: string | undefined) => jid?.endsWith('@newsletter')
|
export const isJidNewsletter = (jid: string | undefined) => jid?.endsWith('@newsletter')
|
||||||
|
/** is the jid a hosted PN */
|
||||||
|
export const isJidHostedPnUser = (jid: string | undefined) => jid?.endsWith('@hosted')
|
||||||
|
/** is the jid a hosted LID */
|
||||||
|
export const isJidHostedLidUser = (jid: string | undefined) => jid?.endsWith('@hosted.lid')
|
||||||
|
|
||||||
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/
|
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user