cleanup: remove string lid / jid refs and improve hosted support
This commit is contained in:
@@ -122,7 +122,7 @@ export class LIDMappingStore {
|
||||
this.logger.trace(`No LID mapping found for PN user ${pnUser}; batch getting from USync`)
|
||||
const device = decoded.device || 0
|
||||
let normalizedPn = jidNormalizedUser(pn)
|
||||
if (isHostedLidUser(normalizedPn) || isHostedPnUser(normalizedPn)) {
|
||||
if (isHostedPnUser(normalizedPn)) {
|
||||
normalizedPn = `${pnUser}@s.whatsapp.net`
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -707,7 +707,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
const jid = attrs.from
|
||||
const participant = attrs.participant || attrs.from
|
||||
|
||||
if (shouldIgnoreJid(jid!) && jid !== '@s.whatsapp.net') {
|
||||
if (shouldIgnoreJid(jid!) && jid !== S_WHATSAPP_NET) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1021,7 +1021,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
participant: attrs.participant
|
||||
}
|
||||
|
||||
if (shouldIgnoreJid(remoteJid!) && remoteJid !== '@s.whatsapp.net') {
|
||||
if (shouldIgnoreJid(remoteJid!) && remoteJid !== S_WHATSAPP_NET) {
|
||||
logger.debug({ remoteJid }, 'ignoring receipt from jid')
|
||||
await sendMessageAck(node)
|
||||
return
|
||||
@@ -1101,7 +1101,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
|
||||
const handleNotification = async (node: BinaryNode) => {
|
||||
const remoteJid = node.attrs.from
|
||||
if (shouldIgnoreJid(remoteJid!) && remoteJid !== '@s.whatsapp.net') {
|
||||
if (shouldIgnoreJid(remoteJid!) && remoteJid !== S_WHATSAPP_NET) {
|
||||
logger.debug({ remoteJid, id: node.attrs.id }, 'ignored notification')
|
||||
await sendMessageAck(node)
|
||||
return
|
||||
@@ -1137,7 +1137,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
}
|
||||
|
||||
const handleMessage = async (node: BinaryNode) => {
|
||||
if (shouldIgnoreJid(node.attrs.from!) && node.attrs.from !== '@s.whatsapp.net') {
|
||||
if (shouldIgnoreJid(node.attrs.from!) && node.attrs.from !== S_WHATSAPP_NET) {
|
||||
logger.debug({ key: node.attrs.key }, 'ignored message')
|
||||
await sendMessageAck(node, NACK_REASONS.UnhandledError)
|
||||
return
|
||||
@@ -1290,22 +1290,6 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
const from = infoChild.attrs.from! || infoChild.attrs['call-creator']!
|
||||
status = getCallStatusFromNode(infoChild)
|
||||
|
||||
if (isLidUser(from) && infoChild.tag === 'relaylatency') {
|
||||
const verify = await callOfferCache.get(callId)
|
||||
if (!verify) {
|
||||
status = 'offer'
|
||||
const callLid: WACallEvent = {
|
||||
chatId: attrs.from!,
|
||||
from,
|
||||
id: callId,
|
||||
date: new Date(+attrs.t! * 1000),
|
||||
offline: !!attrs.offline,
|
||||
status
|
||||
}
|
||||
await callOfferCache.set(callId, callLid)
|
||||
}
|
||||
}
|
||||
|
||||
const call: WACallEvent = {
|
||||
chatId: attrs.from!,
|
||||
from,
|
||||
|
||||
@@ -281,7 +281,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
|
||||
const requestedLidUsers = new Set<string>()
|
||||
for (const jid of toFetch) {
|
||||
if (jid.includes('@lid') || jid.includes('@hosted.lid')) {
|
||||
if (isLidUser(jid) || isHostedLidUser(jid)) {
|
||||
const user = jidDecode(jid)?.user
|
||||
if (user) requestedLidUsers.add(user)
|
||||
}
|
||||
@@ -405,10 +405,10 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
if (jidsRequiringFetch.length) {
|
||||
// LID if mapped, otherwise original
|
||||
const wireJids = [
|
||||
...jidsRequiringFetch.filter(jid => !!jid.includes('@lid') || !!jid.includes('@hosted.lid')),
|
||||
...jidsRequiringFetch.filter(jid => !!isLidUser(jid) || !!isHostedLidUser(jid)),
|
||||
...(
|
||||
(await signalRepository.lidMapping.getLIDsForPNs(
|
||||
jidsRequiringFetch.filter(jid => !!jid.includes('@s.whatsapp.net') || !!jid.includes('@hosted'))
|
||||
jidsRequiringFetch.filter(jid => !!isPnUser(jid) || !!isHostedPnUser(jid)
|
||||
)) || []
|
||||
).map(a => a.lid)
|
||||
]
|
||||
|
||||
@@ -19,8 +19,8 @@ import {
|
||||
import { unpadRandomMax16 } from './generics'
|
||||
import type { ILogger } from './logger'
|
||||
|
||||
const getDecryptionJid = async (sender: string, repository: SignalRepositoryWithLIDStore): Promise<string> => {
|
||||
if (sender.includes('@lid')) {
|
||||
export const getDecryptionJid = async (sender: string, repository: SignalRepositoryWithLIDStore): Promise<string> => {
|
||||
if (isLidUser(sender) || isHostedLidUser(sender)) {
|
||||
return sender
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ const storeMappingFromEnvelope = async (
|
||||
decryptionJid: string,
|
||||
logger: ILogger
|
||||
): Promise<void> => {
|
||||
// TODO: Handle hosted IDs
|
||||
const { senderAlt } = extractAddressingContext(stanza)
|
||||
|
||||
if (senderAlt && isLidUser(senderAlt) && isPnUser(sender) && decryptionJid === sender) {
|
||||
@@ -259,12 +260,11 @@ export const decryptMessageNode = (
|
||||
|
||||
let msgBuffer: Uint8Array
|
||||
|
||||
const user = isPnUser(sender) ? sender : author // TODO: flaky logic
|
||||
|
||||
const decryptionJid = await getDecryptionJid(user, repository)
|
||||
const decryptionJid = await getDecryptionJid(author, repository)
|
||||
|
||||
if (tag !== 'plaintext') {
|
||||
await storeMappingFromEnvelope(stanza, user, repository, decryptionJid, logger)
|
||||
// TODO: Handle hosted devices
|
||||
await storeMappingFromEnvelope(stanza, author, repository, decryptionJid, logger)
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -112,8 +112,8 @@ export const makeNoiseHandler = ({
|
||||
|
||||
const certDecoded = decrypt(serverHello!.payload!)
|
||||
|
||||
const { intermediate: certIntermediate } = proto.CertChain.decode(certDecoded)
|
||||
|
||||
const { intermediate: certIntermediate, leaf } = proto.CertChain.decode(certDecoded)
|
||||
// TODO: handle this leaf stuff
|
||||
const { issuerSerial } = proto.CertChain.NoiseCertificate.Details.decode(certIntermediate!.details!)
|
||||
|
||||
if (issuerSerial !== WA_CERT_DETAILS.SERIAL) {
|
||||
|
||||
Reference in New Issue
Block a user