mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Add lid to Contact - contact sync, history sync, group participants (#1472)
This commit is contained in:
@@ -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']
|
||||
}
|
||||
}),
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user