d08a09c35f
* feat: add inbound username support and USync username protocol Aligns with Baileys upstream PR #2480. WhatsApp is rolling out an inbound username field that maps to the user's LID. This change is purely additive — it captures and propagates the new optional field through types, decoders, USync queries, and group/contact events. Skipped intentionally to preserve InfiniteAPI's LID/PN customization: - handleGroupNotification in messages-recv.ts (custom LID->PN flow on groups.upsert / participants.map). Username for these specific events still flows via process-message's emitParticipantsUpdate (reads message.key.participantUsername added in decode-wa-message). Carousel/buttons code (messages.ts, messages-send.ts) untouched. Co-Authored-By: Renato Alcara
59 lines
1020 B
TypeScript
59 lines
1020 B
TypeScript
import type { USyncQueryProtocol } from '../../Types/USync'
|
|
import { assertNodeErrorFree, type BinaryNode } from '../../WABinary'
|
|
import { USyncUser } from '../USyncUser'
|
|
|
|
export class USyncContactProtocol implements USyncQueryProtocol {
|
|
name = 'contact'
|
|
|
|
getQueryElement(): BinaryNode {
|
|
return {
|
|
tag: 'contact',
|
|
attrs: {}
|
|
}
|
|
}
|
|
|
|
getUserElement(user: USyncUser): BinaryNode {
|
|
if (user.phone) {
|
|
return {
|
|
tag: 'contact',
|
|
attrs: {},
|
|
content: user.phone
|
|
}
|
|
}
|
|
|
|
if (user.username) {
|
|
return {
|
|
tag: 'contact',
|
|
attrs: {
|
|
username: user.username,
|
|
...(user.usernameKey ? { pin: user.usernameKey } : {}),
|
|
...(user.lid ? { lid: user.lid } : {})
|
|
}
|
|
}
|
|
}
|
|
|
|
if (user.type) {
|
|
return {
|
|
tag: 'contact',
|
|
attrs: {
|
|
type: user.type
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
tag: 'contact',
|
|
attrs: {}
|
|
}
|
|
}
|
|
|
|
parser(node: BinaryNode): boolean {
|
|
if (node.tag === 'contact') {
|
|
assertNodeErrorFree(node)
|
|
return node?.attrs?.type === 'in'
|
|
}
|
|
|
|
return false
|
|
}
|
|
}
|