Skip to content

Commit

Permalink
feat(feature/group-invite-v4): initial/final commit (#958)
Browse files Browse the repository at this point in the history
  • Loading branch information
PurpShell authored Aug 14, 2024
1 parent 020add8 commit 7c9f2eb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Socket/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export const makeGroupsSocket = (config: SocketConfig) => {
]
)
const node = getBinaryNodeChild(result, action)
const participantsAffected = getBinaryNodeChildren(node!, 'participant')
const participantsAffected = getBinaryNodeChildren(node, 'participant')
return participantsAffected.map(p => {
return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p }
})
Expand Down Expand Up @@ -232,6 +232,18 @@ export const makeGroupsSocket = (config: SocketConfig) => {
const result = getBinaryNodeChild(results, 'group')
return result?.attrs.jid
},

/**
* revoke a v4 invite for someone
* @param groupJid group jid
* @param invitedJid jid of person you invited
* @returns true if successful
*/
groupRevokeInviteV4: async(groupJid: string, invitedJid: string) => {
const result = await groupQuery(groupJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }])
return !!result
},

/**
* accept a GroupInviteMessage
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
Expand Down
4 changes: 4 additions & 0 deletions src/Socket/messages-send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
return 'product'
} else if(message.interactiveResponseMessage) {
return 'native_flow_response'
} else if(message.groupInviteMessage) {
return 'url'
}
}

Expand Down Expand Up @@ -746,6 +748,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
: undefined
},
),
//TODO: CACHE
getProfilePicUrl: sock.profilePictureUrl,
upload: waUploadToServer,
mediaCache: config.mediaCache,
options: config.options,
Expand Down
12 changes: 12 additions & 0 deletions src/Types/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ export type ButtonReplyInfo = {
index: number
}

export type GroupInviteInfo = {
inviteCode: string
inviteExpiration: number
text: string
jid: string
subject: string
}

export type WASendableProduct = Omit<proto.Message.ProductMessage.IProductSnapshot, 'productImage'> & {
productImage: WAMediaUpload
}
Expand Down Expand Up @@ -153,6 +161,9 @@ export type AnyRegularMessageContent = (
buttonReply: ButtonReplyInfo
type: 'template' | 'plain'
}
| {
groupInvite: GroupInviteInfo
}
| {
listReply: Omit<proto.Message.IListResponseMessage, 'contextInfo'>
}
Expand Down Expand Up @@ -244,6 +255,7 @@ export type MediaGenerationOptions = {
}
export type MessageContentGenerationOptions = MediaGenerationOptions & {
getUrlInfo?: (text: string) => Promise<WAUrlInfo | undefined>
getProfilePicUrl?: (jid: string, type: 'image' | 'preview') => Promise<string | undefined>
}
export type MessageGenerationOptions = MessageContentGenerationOptions & MessageGenerationOptionsFromContent

Expand Down
19 changes: 19 additions & 0 deletions src/Utils/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,25 @@ export const generateWAMessageContent = async(
(message.disappearingMessagesInChat ? WA_DEFAULT_EPHEMERAL : 0) :
message.disappearingMessagesInChat
m = prepareDisappearingMessageSettingContent(exp)
} else if('groupInvite' in message) {
m.groupInviteMessage = {}
m.groupInviteMessage.inviteCode = message.groupInvite.inviteCode
m.groupInviteMessage.inviteExpiration = message.groupInvite.inviteExpiration
m.groupInviteMessage.caption = message.groupInvite.text

m.groupInviteMessage.groupJid = message.groupInvite.jid
m.groupInviteMessage.groupName = message.groupInvite.subject
//TODO: use built-in interface and get disappearing mode info etc.
//TODO: cache / use store!?
if(options.getProfilePicUrl) {
const pfpUrl = await options.getProfilePicUrl(message.groupInvite.jid, 'preview')
if(pfpUrl) {
const resp = await axios.get(pfpUrl, { responseType: 'arraybuffer' })
if(resp.status === 200) {
m.groupInviteMessage.jpegThumbnail = resp.data
}
}
}
} else if('pin' in message) {
m.pinInChatMessage = {}
m.messageContextInfo = {}
Expand Down

0 comments on commit 7c9f2eb

Please sign in to comment.