From 81f13b18eb137ba0fee5ccba241b52ce6ccb3920 Mon Sep 17 00:00:00 2001 From: Gustavo Quadri <87215048+gusquadri@users.noreply.github.com> Date: Tue, 2 Jun 2026 18:49:54 -0300 Subject: [PATCH 1/2] fix(socket): store group notification LID mappings --- src/Socket/messages-recv.ts | 50 +++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 02d0a584091..9c72fe5422e 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -12,6 +12,7 @@ import { } from '../Defaults' import type { GroupParticipant, + LIDMapping, MessageReceiptType, MessageRelayOptions, MessageUserReceipt, @@ -798,12 +799,19 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { } } - const handleGroupNotification = (fullNode: BinaryNode, child: BinaryNode, msg: Partial) => { - // TODO: Support PN/LID (Here is only LID now) - + const handleGroupNotification = async (fullNode: BinaryNode, child: BinaryNode, msg: Partial) => { + const lidPnMappings: LIDMapping[] = [] const actingParticipantLid = fullNode.attrs.participant const actingParticipantPn = fullNode.attrs.participant_pn const actingParticipantUsername = fullNode.attrs.participant_username + if ( + actingParticipantLid && + actingParticipantPn && + isLidUser(actingParticipantLid) && + isPnUser(actingParticipantPn) + ) { + lidPnMappings.push({ lid: actingParticipantLid, pn: actingParticipantPn }) + } const affectedParticipantLid = getBinaryNodeChild(child, 'participant')?.attrs?.jid || actingParticipantLid! const affectedParticipantPn = getBinaryNodeChild(child, 'participant')?.attrs?.phone_number || actingParticipantPn! @@ -815,6 +823,9 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { msg.messageStubType = WAMessageStubType.GROUP_CREATE msg.messageStubParameters = [metadata.subject] msg.key = { participant: metadata.owner, participantAlt: metadata.ownerPn } + if (metadata.owner && metadata.ownerPn && isLidUser(metadata.owner) && isPnUser(metadata.ownerPn)) { + lidPnMappings.push({ lid: metadata.owner, pn: metadata.ownerPn }) + } ev.emit('chats.upsert', [ { @@ -855,11 +866,20 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { msg.messageStubType = WAMessageStubType[stubType as keyof typeof WAMessageStubType] const participants = getBinaryNodeChildren(child, 'participant').map(({ attrs }) => { - // TODO: Store LID MAPPINGS + const participantJid = attrs.jid + const phoneNumber = isLidUser(participantJid) && isPnUser(attrs.phone_number) ? attrs.phone_number : undefined + const lid = isPnUser(participantJid) && isLidUser(attrs.lid) ? attrs.lid : undefined + + if (participantJid && phoneNumber) { + lidPnMappings.push({ lid: participantJid, pn: phoneNumber }) + } else if (participantJid && lid) { + lidPnMappings.push({ lid, pn: participantJid }) + } + return { - id: attrs.jid!, - phoneNumber: isLidUser(attrs.jid) && isPnUser(attrs.phone_number) ? attrs.phone_number : undefined, - lid: isPnUser(attrs.jid) && isLidUser(attrs.lid) ? attrs.lid : undefined, + id: participantJid!, + phoneNumber, + lid, username: attrs.participant_username || attrs.username || undefined, admin: (attrs.type || null) as GroupParticipant['admin'] } @@ -919,6 +939,10 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { break case 'created_membership_requests': msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD + if (isLidUser(affectedParticipantLid) && isPnUser(affectedParticipantPn)) { + lidPnMappings.push({ lid: affectedParticipantLid, pn: affectedParticipantPn }) + } + msg.messageStubParameters = [ JSON.stringify({ lid: affectedParticipantLid, pn: affectedParticipantPn }), 'created', @@ -927,14 +951,21 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { break case 'revoked_membership_requests': const isDenied = areJidsSameUser(affectedParticipantLid, actingParticipantLid) - // TODO: LIDMAPPING SUPPORT msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD + if (isLidUser(affectedParticipantLid) && isPnUser(affectedParticipantPn)) { + lidPnMappings.push({ lid: affectedParticipantLid, pn: affectedParticipantPn }) + } + msg.messageStubParameters = [ JSON.stringify({ lid: affectedParticipantLid, pn: affectedParticipantPn }), isDenied ? 'revoked' : 'rejected' ] break } + + if (lidPnMappings.length) { + await signalRepository.lidMapping.storeLIDPNMappings(lidPnMappings) + } } const handleDevicesNotification = async (node: BinaryNode) => { @@ -1046,8 +1077,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { await handleMexNotification(node) break case 'w:gp2': - // TODO: HANDLE PARTICIPANT_PN - handleGroupNotification(node, child!, result) + await handleGroupNotification(node, child!, result) break case 'mediaretry': const event = decodeMediaRetryNode(node) From 722af7f3ade472635b0006917d35c0fd0f4fcc35 Mon Sep 17 00:00:00 2001 From: Gustavo Quadri <87215048+gusquadri@users.noreply.github.com> Date: Tue, 2 Jun 2026 19:11:02 -0300 Subject: [PATCH 2/2] fix(socket): keep group notifications on mapping failure --- src/Socket/messages-recv.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 9c72fe5422e..7b6aa99ca71 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -964,7 +964,11 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { } if (lidPnMappings.length) { - await signalRepository.lidMapping.storeLIDPNMappings(lidPnMappings) + await signalRepository.lidMapping + .storeLIDPNMappings(lidPnMappings) + .catch(err => + logger.warn({ err, count: lidPnMappings.length }, 'failed to store LID-PN mappings from group notification') + ) } }