decode-wa-message, process-message: Fix @hosted lids processing
This commit is contained in:
@@ -113,7 +113,7 @@ 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`)
|
||||||
usyncFetch.push(pn)
|
usyncFetch.push(pn)
|
||||||
continue;
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,9 +131,7 @@ export class LIDMappingStore {
|
|||||||
successfulPairs[pn] = { lid: deviceSpecificLid, pn }
|
successfulPairs[pn] = { lid: deviceSpecificLid, pn }
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(this.pnToLIDFunc)
|
|
||||||
if (usyncFetch.length > 0) {
|
if (usyncFetch.length > 0) {
|
||||||
console.log(usyncFetch)
|
|
||||||
const result = await this.pnToLIDFunc?.(usyncFetch) // this function already adds LIDs to mapping
|
const result = await this.pnToLIDFunc?.(usyncFetch) // this function already adds LIDs to mapping
|
||||||
if (result && result.length > 0) {
|
if (result && result.length > 0) {
|
||||||
this.storeLIDPNMappings(result)
|
this.storeLIDPNMappings(result)
|
||||||
|
|||||||
@@ -1122,7 +1122,6 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
decrypt
|
decrypt
|
||||||
} = decryptMessageNode(node, authState.creds.me!.id, authState.creds.me!.lid || '', signalRepository, logger)
|
} = decryptMessageNode(node, authState.creds.me!.id, authState.creds.me!.lid || '', signalRepository, logger)
|
||||||
|
|
||||||
|
|
||||||
const alt = msg.key.participantAlt || msg.key.remoteJidAlt
|
const alt = msg.key.participantAlt || msg.key.remoteJidAlt
|
||||||
// store new mappings we didn't have before
|
// store new mappings we didn't have before
|
||||||
if (!!alt) {
|
if (!!alt) {
|
||||||
@@ -1235,7 +1234,6 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
cleanMessage(msg, authState.creds.me!.id)
|
cleanMessage(msg, authState.creds.me!.id)
|
||||||
|
|
||||||
|
|
||||||
await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify')
|
await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify')
|
||||||
})
|
})
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -295,8 +295,9 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
const lidResults = result.list.filter(a => !!a.lid)
|
const lidResults = result.list.filter(a => !!a.lid)
|
||||||
if (lidResults.length > 0) {
|
if (lidResults.length > 0) {
|
||||||
logger.trace('Storing LID maps from device call')
|
logger.trace('Storing LID maps from device call')
|
||||||
await signalRepository.lidMapping.storeLIDPNMappings(lidResults.map(a => ({lid: a.lid as string, pn: a.id})))
|
await signalRepository.lidMapping.storeLIDPNMappings(lidResults.map(a => ({ lid: a.lid as string, pn: a.id })))
|
||||||
}
|
}
|
||||||
|
|
||||||
const extracted = extractDeviceJids(result?.list, authState.creds.me!.id, ignoreZeroDevices)
|
const extracted = extractDeviceJids(result?.list, authState.creds.me!.id, ignoreZeroDevices)
|
||||||
const deviceMap: { [_: string]: FullJid[] } = {}
|
const deviceMap: { [_: string]: FullJid[] } = {}
|
||||||
|
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ export const makeSocket = (config: SocketConfig) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pnFromLIDUSync = async (jids: string[]): Promise<LIDMapping[] | undefined> => {
|
const pnFromLIDUSync = async (jids: string[]): Promise<LIDMapping[] | undefined> => {
|
||||||
let usyncQuery = new USyncQuery().withLIDProtocol().withContext('background')
|
const usyncQuery = new USyncQuery().withLIDProtocol().withContext('background')
|
||||||
|
|
||||||
for (const jid of jids) {
|
for (const jid of jids) {
|
||||||
if (isLidUser(jid)) {
|
if (isLidUser(jid)) {
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ import {
|
|||||||
type BinaryNode,
|
type BinaryNode,
|
||||||
isJidBroadcast,
|
isJidBroadcast,
|
||||||
isJidGroup,
|
isJidGroup,
|
||||||
|
isJidHostedLidUser,
|
||||||
|
isJidHostedPnUser,
|
||||||
isJidMetaAI,
|
isJidMetaAI,
|
||||||
isJidNewsletter,
|
isJidNewsletter,
|
||||||
isJidStatusBroadcast,
|
isJidStatusBroadcast,
|
||||||
isLidUser,
|
isLidUser,
|
||||||
isPnUser,
|
isPnUser,
|
||||||
transferDevice
|
// transferDevice
|
||||||
} from '../WABinary'
|
} from '../WABinary'
|
||||||
import { unpadRandomMax16 } from './generics'
|
import { unpadRandomMax16 } from './generics'
|
||||||
import type { ILogger } from './logger'
|
import type { ILogger } from './logger'
|
||||||
@@ -95,7 +97,7 @@ export const extractAddressingContext = (stanza: BinaryNode) => {
|
|||||||
senderAlt = stanza.attrs.participant_pn || stanza.attrs.sender_pn || stanza.attrs.peer_recipient_pn
|
senderAlt = stanza.attrs.participant_pn || stanza.attrs.sender_pn || stanza.attrs.peer_recipient_pn
|
||||||
recipientAlt = stanza.attrs.recipient_pn
|
recipientAlt = stanza.attrs.recipient_pn
|
||||||
// with device data
|
// with device data
|
||||||
if (sender && senderAlt) senderAlt = transferDevice(sender, senderAlt)
|
//if (sender && senderAlt) senderAlt = transferDevice(sender, senderAlt)
|
||||||
} else {
|
} else {
|
||||||
// Message is PN-addressed: sender is PN, extract corresponding LID
|
// Message is PN-addressed: sender is PN, extract corresponding LID
|
||||||
// without device data
|
// without device data
|
||||||
@@ -103,7 +105,7 @@ export const extractAddressingContext = (stanza: BinaryNode) => {
|
|||||||
recipientAlt = stanza.attrs.recipient_lid
|
recipientAlt = stanza.attrs.recipient_lid
|
||||||
|
|
||||||
//with device data
|
//with device data
|
||||||
if (sender && senderAlt) senderAlt = transferDevice(sender, senderAlt)
|
//if (sender && senderAlt) senderAlt = transferDevice(sender, senderAlt)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -133,7 +135,7 @@ export function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: strin
|
|||||||
const isMe = (jid: string) => areJidsSameUser(jid, meId)
|
const isMe = (jid: string) => areJidsSameUser(jid, meId)
|
||||||
const isMeLid = (jid: string) => areJidsSameUser(jid, meLid)
|
const isMeLid = (jid: string) => areJidsSameUser(jid, meLid)
|
||||||
|
|
||||||
if (isPnUser(from) || isLidUser(from)) {
|
if (isPnUser(from) || isLidUser(from) || isJidHostedLidUser(from) || isJidHostedPnUser(from)) {
|
||||||
if (recipient && !isJidMetaAI(recipient)) {
|
if (recipient && !isJidMetaAI(recipient)) {
|
||||||
if (!isMe(from!) && !isMeLid(from!)) {
|
if (!isMe(from!) && !isMeLid(from!)) {
|
||||||
throw new Boom('receipient present, but msg not from me', { data: stanza })
|
throw new Boom('receipient present, but msg not from me', { data: stanza })
|
||||||
|
|||||||
@@ -13,7 +13,16 @@ import type {
|
|||||||
} from '../Types'
|
} from '../Types'
|
||||||
import { WAMessageStubType } from '../Types'
|
import { WAMessageStubType } from '../Types'
|
||||||
import { getContentType, normalizeMessageContent } from '../Utils/messages'
|
import { getContentType, normalizeMessageContent } from '../Utils/messages'
|
||||||
import { areJidsSameUser, isJidBroadcast, isJidStatusBroadcast, jidNormalizedUser } from '../WABinary'
|
import {
|
||||||
|
areJidsSameUser,
|
||||||
|
isJidBroadcast,
|
||||||
|
isJidHostedLidUser,
|
||||||
|
isJidHostedPnUser,
|
||||||
|
isJidStatusBroadcast,
|
||||||
|
jidDecode,
|
||||||
|
jidEncode,
|
||||||
|
jidNormalizedUser
|
||||||
|
} from '../WABinary'
|
||||||
import { aesDecryptGCM, hmacSign } from './crypto'
|
import { aesDecryptGCM, hmacSign } from './crypto'
|
||||||
import { toNumber } from './generics'
|
import { toNumber } from './generics'
|
||||||
import { downloadAndProcessHistorySyncNotification } from './history'
|
import { downloadAndProcessHistorySyncNotification } from './history'
|
||||||
@@ -43,8 +52,24 @@ const REAL_MSG_REQ_ME_STUB_TYPES = new Set([WAMessageStubType.GROUP_PARTICIPANT_
|
|||||||
/** Cleans a received message to further processing */
|
/** Cleans a received message to further processing */
|
||||||
export const cleanMessage = (message: proto.IWebMessageInfo, meId: string) => {
|
export const cleanMessage = (message: proto.IWebMessageInfo, meId: string) => {
|
||||||
// ensure remoteJid and participant doesn't have device or agent in it
|
// ensure remoteJid and participant doesn't have device or agent in it
|
||||||
message.key.remoteJid = jidNormalizedUser(message.key.remoteJid!)
|
if (isJidHostedPnUser(message.key.remoteJid!) || isJidHostedLidUser(message.key.remoteJid!)) {
|
||||||
message.key.participant = message.key.participant ? jidNormalizedUser(message.key.participant) : undefined
|
message.key.remoteJid = jidEncode(
|
||||||
|
jidDecode(message.key.remoteJid!)?.user!,
|
||||||
|
isJidHostedPnUser(message.key.remoteJid!) ? 's.whatsapp.net' : 'lid'
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
message.key.remoteJid = jidNormalizedUser(message.key.remoteJid!)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isJidHostedPnUser(message.key.participant!) || isJidHostedLidUser(message.key.participant!)) {
|
||||||
|
message.key.participant = jidEncode(
|
||||||
|
jidDecode(message.key.participant!)?.user!,
|
||||||
|
isJidHostedPnUser(message.key.participant!) ? 's.whatsapp.net' : 'lid'
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
message.key.participant = jidNormalizedUser(message.key.participant!)
|
||||||
|
}
|
||||||
|
|
||||||
const content = normalizeMessageContent(message.message)
|
const content = normalizeMessageContent(message.message)
|
||||||
// if the message has a reaction, ensure fromMe & remoteJid are from our perspective
|
// if the message has a reaction, ensure fromMe & remoteJid are from our perspective
|
||||||
if (content?.reactionMessage) {
|
if (content?.reactionMessage) {
|
||||||
@@ -67,6 +92,7 @@ export const cleanMessage = (message: proto.IWebMessageInfo, meId: string) => {
|
|||||||
// fromMe automatically becomes false
|
// fromMe automatically becomes false
|
||||||
false
|
false
|
||||||
// set the remoteJid to being the same as the chat the message came from
|
// set the remoteJid to being the same as the chat the message came from
|
||||||
|
// TODO: investigate inconsistencies
|
||||||
msgKey.remoteJid = message.key.remoteJid
|
msgKey.remoteJid = message.key.remoteJid
|
||||||
// set participant of the message
|
// set participant of the message
|
||||||
msgKey.participant = msgKey.participant || message.key.participant
|
msgKey.participant = msgKey.participant || message.key.participant
|
||||||
|
|||||||
Reference in New Issue
Block a user