From b8464d36651347a71260faa936566049cf4b56a6 Mon Sep 17 00:00:00 2001 From: devlikeapro <155617407+devlikepro@users.noreply.github.com> Date: Wed, 18 Jun 2025 18:08:09 +0700 Subject: [PATCH] Add lid to Contact - contact sync, history sync, group participants (#1472) --- src/Socket/groups.ts | 5 ++++- src/Types/Contact.ts | 4 ++++ src/Types/GroupMetadata.ts | 1 - src/Utils/chat-utils.ts | 18 ++++++++++++++++-- src/Utils/history.ts | 7 ++++++- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/Socket/groups.ts b/src/Socket/groups.ts index 8f2b39c..c001779 100644 --- a/src/Socket/groups.ts +++ b/src/Socket/groups.ts @@ -13,6 +13,8 @@ import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, + isJidUser, + isLidUser, jidEncode, jidNormalizedUser } from '../WABinary' @@ -348,7 +350,8 @@ export const extractGroupMetadata = (result: BinaryNode) => { participants: getBinaryNodeChildren(group, 'participant').map(({ attrs }) => { return { id: attrs.jid, - jid: attrs.phone_number ? jidNormalizedUser(attrs.phone_number) : undefined, + jid: isJidUser(attrs.jid) ? attrs.jid : jidNormalizedUser(attrs.phone_number), + lid: isLidUser(attrs.jid) ? attrs.jid : attrs.lid, admin: (attrs.type || null) as GroupParticipant['admin'] } }), diff --git a/src/Types/Contact.ts b/src/Types/Contact.ts index 5f57dde..8d5cfca 100644 --- a/src/Types/Contact.ts +++ b/src/Types/Contact.ts @@ -1,6 +1,10 @@ export interface Contact { + /** ID either in lid or jid format **/ id: string + /** ID in Lid (anonymous) format (@lid) **/ lid?: string + /** ID in Phone Number format (@s.whatsapp.net) **/ + jid?: string /** name of the contact, you have saved on your WA */ name?: string /** name of the contact, the contact has set on their own on WA */ diff --git a/src/Types/GroupMetadata.ts b/src/Types/GroupMetadata.ts index 14463e9..543922d 100644 --- a/src/Types/GroupMetadata.ts +++ b/src/Types/GroupMetadata.ts @@ -4,7 +4,6 @@ export type GroupParticipant = Contact & { isAdmin?: boolean isSuperAdmin?: boolean admin?: 'admin' | 'superadmin' | null - jid?: string | undefined } export type ParticipantAction = 'add' | 'remove' | 'promote' | 'demote' | 'modify' diff --git a/src/Utils/chat-utils.ts b/src/Utils/chat-utils.ts index aa72468..3556591 100644 --- a/src/Utils/chat-utils.ts +++ b/src/Utils/chat-utils.ts @@ -15,7 +15,14 @@ import { WAPatchName } from '../Types' import { ChatLabelAssociation, LabelAssociationType, MessageLabelAssociation } from '../Types/LabelAssociation' -import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, jidNormalizedUser } from '../WABinary' +import { + BinaryNode, + getBinaryNodeChild, + getBinaryNodeChildren, + isJidGroup, + isJidUser, + jidNormalizedUser +} from '../WABinary' import { aesDecrypt, aesEncrypt, hkdf, hmacSign } from './crypto' import { toNumber } from './generics' import { ILogger } from './logger' @@ -791,7 +798,14 @@ export const processSyncAction = ( ] }) } else if (action?.contactAction) { - ev.emit('contacts.upsert', [{ id, name: action.contactAction.fullName! }]) + ev.emit('contacts.upsert', [ + { + id: id, + name: action.contactAction.fullName!, + lid: action.contactAction.lidJid || undefined, + jid: isJidUser(id) ? id : undefined + } + ]) } else if (action?.pushNameSetting) { const name = action?.pushNameSetting?.name if (name && me?.name !== name) { diff --git a/src/Utils/history.ts b/src/Utils/history.ts index c42cf6b..20461c7 100644 --- a/src/Utils/history.ts +++ b/src/Utils/history.ts @@ -37,7 +37,12 @@ export const processHistoryMessage = (item: proto.IHistorySync) => { case proto.HistorySync.HistorySyncType.FULL: case proto.HistorySync.HistorySyncType.ON_DEMAND: for (const chat of item.conversations! as Chat[]) { - contacts.push({ id: chat.id, name: chat.name || undefined }) + contacts.push({ + id: chat.id, + name: chat.name || undefined, + lid: chat.lidJid || undefined, + jid: isJidUser(chat.id) ? chat.id : undefined + }) const msgs = chat.messages || [] delete chat.messages