mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: handle picture change events
This commit is contained in:
@@ -152,6 +152,17 @@ const startSock = async() => {
|
|||||||
console.log(events['chats.update'])
|
console.log(events['chats.update'])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(events['contacts.update']) {
|
||||||
|
for(const contact of events['contacts.update']) {
|
||||||
|
if(typeof contact.imgUrl !== 'undefined') {
|
||||||
|
const newUrl = contact.imgUrl === null ? null : await sock!.profilePictureUrl(contact.id!)
|
||||||
|
console.log(
|
||||||
|
`contact ${contact.id} has a new profile pic: ${newUrl}`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(events['chats.delete']) {
|
if(events['chats.delete']) {
|
||||||
console.log('chats deleted ', events['chats.delete'])
|
console.log('chats deleted ', events['chats.delete'])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -261,6 +261,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
const result: Partial<proto.IWebMessageInfo> = { }
|
const result: Partial<proto.IWebMessageInfo> = { }
|
||||||
const [child] = getAllBinaryNodeChildren(node)
|
const [child] = getAllBinaryNodeChildren(node)
|
||||||
const nodeType = node.attrs.type
|
const nodeType = node.attrs.type
|
||||||
|
const from = jidNormalizedUser(node.attrs.from)
|
||||||
|
|
||||||
switch (nodeType) {
|
switch (nodeType) {
|
||||||
case 'w:gp2':
|
case 'w:gp2':
|
||||||
@@ -291,10 +292,26 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
break
|
break
|
||||||
case 'picture':
|
case 'picture':
|
||||||
const setPicture = getBinaryNodeChild(node, 'set')
|
const setPicture = getBinaryNodeChild(node, 'set')
|
||||||
if(setPicture) {
|
const delPicture = getBinaryNodeChild(node, 'delete')
|
||||||
|
|
||||||
|
ev.emit('contacts.update', [{
|
||||||
|
id: from,
|
||||||
|
imgUrl: setPicture ? 'changed' : null
|
||||||
|
}])
|
||||||
|
|
||||||
|
if(isJidGroup(from)) {
|
||||||
|
const node = setPicture || delPicture
|
||||||
result.messageStubType = WAMessageStubType.GROUP_CHANGE_ICON
|
result.messageStubType = WAMessageStubType.GROUP_CHANGE_ICON
|
||||||
result.messageStubParameters = [ setPicture.attrs.id ]
|
|
||||||
result.participant = setPicture.attrs.author
|
if(setPicture) {
|
||||||
|
result.messageStubParameters = [ setPicture.attrs.id ]
|
||||||
|
}
|
||||||
|
|
||||||
|
result.participant = node?.attrs.author
|
||||||
|
result.key = {
|
||||||
|
...result.key || {},
|
||||||
|
participant: setPicture?.attrs.author
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ export interface Contact {
|
|||||||
/** I have no idea */
|
/** I have no idea */
|
||||||
verifiedName?: string
|
verifiedName?: string
|
||||||
// Baileys Added
|
// Baileys Added
|
||||||
imgUrl?: string
|
/**
|
||||||
|
* Url of the profile picture of the contact
|
||||||
|
*
|
||||||
|
* 'changed' => if the profile picture has changed
|
||||||
|
* null => if the profile picture has not been set (default profile picture)
|
||||||
|
* any other string => url of the profile picture
|
||||||
|
*/
|
||||||
|
imgUrl?: string | null | 'changed'
|
||||||
status?: string
|
status?: string
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user