mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat(feature/group-invite-v4): initial/final commit (#958)
This commit is contained in:
@@ -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 }
|
||||
})
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -746,6 +748,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
: undefined
|
||||
},
|
||||
),
|
||||
//TODO: CACHE
|
||||
getProfilePicUrl: sock.profilePictureUrl,
|
||||
upload: waUploadToServer,
|
||||
mediaCache: config.mediaCache,
|
||||
options: config.options,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -153,6 +161,9 @@ export type AnyRegularMessageContent = (
|
||||
buttonReply: ButtonReplyInfo
|
||||
type: 'template' | 'plain'
|
||||
}
|
||||
| {
|
||||
groupInvite: GroupInviteInfo
|
||||
}
|
||||
| {
|
||||
listReply: Omit<proto.Message.IListResponseMessage, 'contextInfo'>
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 = {}
|
||||
|
||||
Reference in New Issue
Block a user