fix(chats): add LID/PN dual identifier validation for updateBlockStatus

fix(chats): add LID/PN dual identifier validation for updateBlockStatus
This commit is contained in:
Renato Alcara
2026-02-16 00:10:48 -03:00
committed by GitHub
+41 -7
View File
@@ -50,8 +50,8 @@ import {
type BinaryNode, type BinaryNode,
getBinaryNodeChild, getBinaryNodeChild,
getBinaryNodeChildren, getBinaryNodeChildren,
isLidUser, isAnyLidUser,
isPnUser, isAnyPnUser,
jidDecode, jidDecode,
jidNormalizedUser, jidNormalizedUser,
reduceBinaryNodeToDictionary, reduceBinaryNodeToDictionary,
@@ -431,6 +431,43 @@ export const makeChatsSocket = (config: SocketConfig) => {
} }
const updateBlockStatus = async (jid: string, action: 'block' | 'unblock') => { const updateBlockStatus = async (jid: string, action: 'block' | 'unblock') => {
const normalizedJid = jidNormalizedUser(jid)
let lid: string
let pn_jid: string | undefined
if (isAnyLidUser(normalizedJid)) {
lid = normalizedJid
if (action === 'block') {
const pn = await signalRepository.lidMapping.getPNForLID(normalizedJid)
if (!pn) {
throw new Boom(`Unable to resolve PN JID for LID: ${jid}`, { statusCode: 400 })
}
pn_jid = jidNormalizedUser(pn)
}
} else if (isAnyPnUser(normalizedJid)) {
const mapped = await signalRepository.lidMapping.getLIDForPN(normalizedJid)
if (!mapped) {
throw new Boom(`Unable to resolve LID for PN JID: ${jid}`, { statusCode: 400 })
}
lid = mapped
if (action === 'block') {
pn_jid = normalizedJid
}
} else {
throw new Boom(`Invalid jid for block/unblock: ${jid}`, { statusCode: 400 })
}
const itemAttrs: { action: 'block' | 'unblock'; jid: string; pn_jid?: string } = {
action,
jid: lid
}
if (action === 'block' && pn_jid) {
itemAttrs.pn_jid = pn_jid
}
await query({ await query({
tag: 'iq', tag: 'iq',
attrs: { attrs: {
@@ -441,10 +478,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
content: [ content: [
{ {
tag: 'item', tag: 'item',
attrs: { attrs: itemAttrs
action,
jid
}
} }
] ]
}) })
@@ -701,7 +735,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
// and never for own profile pic (Chat model for self has no tcToken). // and never for own profile pic (Chat model for self has no tcToken).
// Including tctoken for own JID causes the server to never respond. // Including tctoken for own JID causes the server to never respond.
const normalizedJid = jidNormalizedUser(jid) const normalizedJid = jidNormalizedUser(jid)
const isUserJid = isPnUser(normalizedJid) || isLidUser(normalizedJid) const isUserJid = isAnyPnUser(normalizedJid) || isAnyLidUser(normalizedJid)
const me = authState.creds.me const me = authState.creds.me
const isSelf = const isSelf =
me && (normalizedJid === jidNormalizedUser(me.id) || (me.lid && normalizedJid === jidNormalizedUser(me.lid))) me && (normalizedJid === jidNormalizedUser(me.id) || (me.lid && normalizedJid === jidNormalizedUser(me.lid)))