mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fire contact update if pushname provided
This commit is contained in:
@@ -52,6 +52,7 @@ import makeWASocket, { WASocket, AuthenticationState, DisconnectReason, AnyMessa
|
||||
sock.ev.on('messages.update', m => console.log(m))
|
||||
sock.ev.on('presence.update', m => console.log(m))
|
||||
sock.ev.on('chats.update', m => console.log(m))
|
||||
sock.ev.on('contacts.update', m => console.log(m))
|
||||
return sock
|
||||
}
|
||||
|
||||
|
||||
@@ -423,7 +423,17 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
|
||||
ev.on('messages.upsert', async({ messages }) => {
|
||||
const chat: Partial<Chat> = { id: messages[0].key.remoteJid }
|
||||
const contactNameUpdates: { [_: string]: string } = { }
|
||||
for(const msg of messages) {
|
||||
if(!!msg.pushName) {
|
||||
contactNameUpdates[msg.key.remoteJid!] = msg.pushName
|
||||
// update our pushname too
|
||||
if(msg.key.fromMe && authState.creds.me?.name !== msg.pushName) {
|
||||
authState.creds.me!.name = msg.pushName
|
||||
ev.emit('auth-state.update', authState)
|
||||
}
|
||||
}
|
||||
|
||||
await processMessage(msg, chat)
|
||||
if(!!msg.message && !msg.message!.protocolMessage) {
|
||||
chat.conversationTimestamp = toNumber(msg.messageTimestamp)
|
||||
@@ -435,6 +445,11 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
if(Object.keys(chat).length > 1) {
|
||||
ev.emit('chats.update', [ chat ])
|
||||
}
|
||||
if(Object.keys(contactNameUpdates).length) {
|
||||
ev.emit('contacts.update', Object.keys(contactNameUpdates).map(
|
||||
id => ({ id, notify: contactNameUpdates[id] })
|
||||
))
|
||||
}
|
||||
})
|
||||
|
||||
return sock
|
||||
|
||||
Reference in New Issue
Block a user