Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 19 additions & 3 deletions src/Socket/groups.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Boom } from '@hapi/boom'
import { proto } from '../../WAProto/index.js'
import type { GroupMetadata, GroupParticipant, ParticipantAction, SocketConfig, WAMessageKey } from '../Types'
import { WAMessageAddressingMode, WAMessageStubType } from '../Types'
Expand Down Expand Up @@ -301,7 +302,18 @@ export const makeGroupsSocket = (config: SocketConfig) => {
}

export const extractGroupMetadata = (result: BinaryNode) => {
const group = getBinaryNodeChild(result, 'group')!
const group = getBinaryNodeChild(result, 'group')
if (!group) {
const errorNode = getBinaryNodeChild(result, 'error')
if (errorNode) {
throw new Boom(`Group metadata query failed with error ${errorNode.attrs.code}: ${errorNode.attrs.text}`, {
data: errorNode
})
}

throw new Boom('Invalid group metadata response, missing <group> node', { data: result })
}

const descChild = getBinaryNodeChild(group, 'description')
let desc: string | undefined
let descId: string | undefined
Expand All @@ -316,11 +328,15 @@ export const extractGroupMetadata = (result: BinaryNode) => {
descId = descChild.attrs.id
}

const groupId = group.attrs.id!.includes('@') ? group.attrs.id : jidEncode(group.attrs.id!, 'g.us')
if (!group.attrs.id) {
throw new Boom('Group id is missing from metadata', { data: group })
}

const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us')
const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration
const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add'
const metadata: GroupMetadata = {
id: groupId!,
id: groupId,
notify: group.attrs.notify,
addressingMode: group.attrs.addressing_mode === 'lid' ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN,
subject: group.attrs.subject!,
Expand Down
Loading
Loading