Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Socket/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,13 @@ export const extractGroupMetadata = (result: BinaryNode) => {
let descId: string | undefined
let descOwner: string | undefined
let descOwnerPn: string | undefined
let descOwnerUsername: string | undefined
let descTime: number | undefined
if (descChild) {
desc = getBinaryNodeChildString(descChild, 'body')
descOwner = descChild.attrs.participant ? jidNormalizedUser(descChild.attrs.participant) : undefined
descOwnerPn = descChild.attrs.participant_pn ? jidNormalizedUser(descChild.attrs.participant_pn) : undefined
descOwnerUsername = descChild.attrs.participant_username || undefined
descTime = +descChild.attrs.t!
descId = descChild.attrs.id
}
Expand All @@ -362,16 +364,19 @@ export const extractGroupMetadata = (result: BinaryNode) => {
subject: group.attrs.subject!,
subjectOwner: group.attrs.s_o,
subjectOwnerPn: group.attrs.s_o_pn,
subjectOwnerUsername: group.attrs.s_o_username,
subjectTime: +(group.attrs.s_t ?? '0'),
size: group.attrs.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length,
creation: +(group.attrs.creation ?? '0'),
owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
ownerPn: group.attrs.creator_pn ? jidNormalizedUser(group.attrs.creator_pn) : undefined,
ownerUsername: group.attrs.creator_username || undefined,
owner_country_code: group.attrs.creator_country_code,
desc,
descId,
descOwner,
descOwnerPn,
descOwnerUsername,
descTime,
linkedParent: getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
restrict: !!getBinaryNodeChild(group, 'locked'),
Expand All @@ -386,6 +391,7 @@ export const extractGroupMetadata = (result: BinaryNode) => {
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,
username: attrs.participant_username || attrs.username || undefined,
admin: (attrs.type || null) as GroupParticipant['admin']
}
}),
Expand Down
1 change: 1 addition & 0 deletions src/Socket/messages-recv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@
return
}

let data: any

Check warning on line 348 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type

Check warning on line 348 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
try {
data = JSON.parse(mexNode.content.toString())
} catch (error) {
Expand Down Expand Up @@ -449,7 +449,7 @@
const settingsNode = getBinaryNodeChild(child, 'settings')
if (settingsNode) {
const update: Record<string, any> = {}
const nameNode = getBinaryNodeChild(settingsNode, 'name')

Check warning on line 452 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type

Check warning on line 452 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
if (nameNode?.content) update.name = nameNode.content.toString()

const descriptionNode = getBinaryNodeChild(settingsNode, 'description')
Expand Down Expand Up @@ -2223,6 +2223,7 @@
fromMe,
participant: node.attrs.participant,
participantAlt,
participantUsername: node.attrs.participant_username,
Comment thread
rsalcara marked this conversation as resolved.
addressingMode,
id: node.attrs.id,
...(msg.key || {})
Expand Down Expand Up @@ -2293,7 +2294,7 @@
}
}
}
}

Check warning on line 2297 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type

Check warning on line 2297 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
const upsertType = node.attrs.offline ? 'append' : 'notify'
await upsertMessage(voMsg, upsertType)
await sendMessageAck(node)
Expand Down Expand Up @@ -2959,7 +2960,7 @@
await relayMessage(jid, msg, { messageId: msgId, useUserDevicesCache: true })
logTcToken('retry_463_ok', { jid, msgId })
} else {
logger.warn({ jid, msgId }, '463 retry: message not found in store')

Check warning on line 2963 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 2963 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
ev.emit('messages.update', [
{ key, update: { status: WAMessageStatus.ERROR, messageStubParameters: ['463'] } }
])
Expand Down
2 changes: 2 additions & 0 deletions src/Types/Contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface Contact {
name?: string
/** name of the contact, the contact has set on their own on WA */
notify?: string
/** username associated with this contact, when provided by WA */
username?: string
/** I have no idea */
verifiedName?: string
// Baileys Added
Expand Down
2 changes: 2 additions & 0 deletions src/Types/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ export type BaileysEventMap = {
id: string
author: string
authorPn?: string
authorUsername?: string
participants: GroupParticipant[]
action: ParticipantAction
}
'group.join-request': {
id: string
author: string
authorPn?: string
authorUsername?: string
participant: string
participantPn?: string
action: RequestJoinAction
Expand Down
4 changes: 4 additions & 0 deletions src/Types/GroupMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ export interface GroupMetadata {
addressingMode?: WAMessageAddressingMode
owner: string | undefined
ownerPn?: string | undefined
ownerUsername?: string | undefined
owner_country_code?: string | undefined
subject: string
/** group subject owner */
subjectOwner?: string
subjectOwnerPn?: string
subjectOwnerUsername?: string
/** group subject modification date */
subjectTime?: number
creation?: number
desc?: string
descOwner?: string
descOwnerPn?: string
descOwnerUsername?: string
descId?: string
descTime?: number
/** if this group is part of a community, it returns the jid of the community to which it belongs */
Expand All @@ -56,6 +59,7 @@ export interface GroupMetadata {
/** the person who added you to group or changed some setting in group */
author?: string
authorPn?: string
authorUsername?: string
}

export interface WAGroupCreateResponse {
Expand Down
2 changes: 2 additions & 0 deletions src/Types/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export type WAContactMessage = proto.Message.IContactMessage
export type WAContactsArrayMessage = proto.Message.IContactsArrayMessage
export type WAMessageKey = proto.IMessageKey & {
remoteJidAlt?: string
remoteJidUsername?: string
participantAlt?: string
participantUsername?: string
server_id?: string
addressingMode?: string
isViewOnce?: boolean // TODO: remove out of the message key, place in WebMessageInfo
Expand Down
1 change: 1 addition & 0 deletions src/Utils/chat-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,7 @@ export const processSyncAction = (
action.lidContactAction.firstName ||
action.lidContactAction.username ||
undefined,
username: action.lidContactAction.username || undefined,
Comment thread
rsalcara marked this conversation as resolved.
lid: id!,
phoneNumber: undefined
}
Expand Down
4 changes: 4 additions & 0 deletions src/Utils/decode-wa-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,14 @@ export function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: strin
const key: WAMessageKey = {
remoteJid: chatId,
remoteJidAlt: !isJidGroup(chatId) ? addressingContext.senderAlt : undefined,
remoteJidUsername: !isJidGroup(chatId)
? stanza.attrs.peer_recipient_username || stanza.attrs.recipient_username
: undefined,
fromMe,
id: msgId,
participant,
participantAlt: isJidGroup(chatId) ? addressingContext.senderAlt : undefined,
participantUsername: stanza.attrs.participant ? stanza.attrs.participant_username : undefined,
addressingMode: addressingContext.addressingMode,
...(msgType === 'newsletter' && stanza.attrs.server_id ? { server_id: stanza.attrs.server_id } : {})
}
Expand Down
1 change: 1 addition & 0 deletions src/Utils/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ export const processHistoryMessage = (item: proto.IHistorySync, logger?: ILogger
contacts.push({
id: chatId,
name: chat.displayName || chat.name || chat.username || undefined,
username: chat.username || undefined,
Comment thread
rsalcara marked this conversation as resolved.
lid: chat.lidJid || chat.accountLid || undefined,
phoneNumber: chat.pnJid || undefined
})
Expand Down
10 changes: 9 additions & 1 deletion src/Utils/process-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,12 +763,19 @@ const processMessage = async (
id: jid,
author: message.key.participant!,
authorPn: message.key.participantAlt!,
authorUsername: message.key.participantUsername!,
participants,
Comment thread
rsalcara marked this conversation as resolved.
action
})
const emitGroupUpdate = (update: Partial<GroupMetadata>) => {
ev.emit('groups.update', [
{ id: jid, ...update, author: message.key.participant ?? undefined, authorPn: message.key.participantAlt }
{
id: jid,
...update,
author: message.key.participant ?? undefined,
authorPn: message.key.participantAlt,
authorUsername: message.key.participantUsername
}
])
}

Expand All @@ -777,6 +784,7 @@ const processMessage = async (
id: jid,
author: message.key.participant!,
authorPn: message.key.participantAlt!,
authorUsername: message.key.participantUsername!,
Comment thread
rsalcara marked this conversation as resolved.
participant: participant.lid,
participantPn: participant.pn,
action,
Expand Down
1 change: 1 addition & 0 deletions src/Utils/sync-action-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const processContactAction = (
{
id,
name: action.fullName || action.firstName || action.username || undefined,
username: action.username || undefined,
Comment thread
rsalcara marked this conversation as resolved.
lid: lidJid || undefined,
phoneNumber
}
Expand Down
32 changes: 29 additions & 3 deletions src/WAUSync/Protocols/USyncContactProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,37 @@ export class USyncContactProtocol implements USyncQueryProtocol {
}

getUserElement(user: USyncUser): BinaryNode {
//TODO: Implement type / username fields (not yet supported)
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: {},
content: user.phone
attrs: {}
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/WAUSync/Protocols/USyncUsernameProtocol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { USyncQueryProtocol } from '../../Types/USync'
import { assertNodeErrorFree, type BinaryNode } from '../../WABinary'
import { USyncUser } from '../USyncUser'

export class USyncUsernameProtocol implements USyncQueryProtocol {
name = 'username'

getQueryElement(): BinaryNode {
return {
tag: 'username',
attrs: {}
}
}

getUserElement(user: USyncUser): BinaryNode | null {
void user
return null
}

parser(node: BinaryNode): string | null {
if (node.tag === 'username') {
assertNodeErrorFree(node)
return typeof node.content === 'string' ? node.content : null
}

return null
}
}
1 change: 1 addition & 0 deletions src/WAUSync/Protocols/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './USyncDeviceProtocol'
export * from './USyncContactProtocol'
export * from './USyncStatusProtocol'
export * from './USyncDisappearingModeProtocol'
export * from './USyncUsernameProtocol'
8 changes: 7 additions & 1 deletion src/WAUSync/USyncQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
USyncContactProtocol,
USyncDeviceProtocol,
USyncDisappearingModeProtocol,
USyncStatusProtocol
USyncStatusProtocol,
USyncUsernameProtocol
} from './Protocols'
import { USyncUser } from './USyncUser'

Expand Down Expand Up @@ -137,4 +138,9 @@ export class USyncQuery {
this.protocols.push(new USyncLIDProtocol())
return this
}

withUsernameProtocol() {
this.protocols.push(new USyncUsernameProtocol())
return this
}
}
12 changes: 12 additions & 0 deletions src/WAUSync/USyncUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export class USyncUser {
id?: string
lid?: string
phone?: string
username?: string
usernameKey?: string
type?: string
personaId?: string

Expand All @@ -20,6 +22,16 @@ export class USyncUser {
return this
}

withUsername(username: string) {
this.username = username
return this
}

withUsernameKey(usernameKey: string) {
this.usernameKey = usernameKey
return this
}

withType(type: string) {
this.type = type
return this
Expand Down
Loading