feat: handle picture change events

This commit is contained in:
Adhiraj Singh
2022-09-27 11:28:41 +05:30
parent da359aaee2
commit b329c73b20
3 changed files with 39 additions and 4 deletions

View File

@@ -152,6 +152,17 @@ const startSock = async() => {
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']) {
console.log('chats deleted ', events['chats.delete'])
}

View File

@@ -261,6 +261,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
const result: Partial<proto.IWebMessageInfo> = { }
const [child] = getAllBinaryNodeChildren(node)
const nodeType = node.attrs.type
const from = jidNormalizedUser(node.attrs.from)
switch (nodeType) {
case 'w:gp2':
@@ -291,10 +292,26 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
break
case 'picture':
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.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

View File

@@ -7,6 +7,13 @@ export interface Contact {
/** I have no idea */
verifiedName?: string
// 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
}