diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 96b6069..7c62e00 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -498,34 +498,36 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { } }) - ev.on('messages.upsert', async({ messages }) => { - const chat: Partial = { id: messages[0].key.remoteJid } - const contactNameUpdates: { [_: string]: string } = { } - for(const msg of messages) { - if(!!msg.pushName) { - const jid = msg.key.fromMe ? jidNormalizedUser(authState.creds.me!.id) : (msg.key.participant || msg.key.remoteJid) - contactNameUpdates[jid] = msg.pushName - // update our pushname too - if(msg.key.fromMe && authState.creds.me?.name !== msg.pushName) { - ev.emit('creds.update', { me: { ...authState.creds.me!, name: msg.pushName! } }) + ev.on('messages.upsert', async({ messages, type }) => { + if(type === 'notify' || type === 'append') { + const chat: Partial = { id: messages[0].key.remoteJid } + const contactNameUpdates: { [_: string]: string } = { } + for(const msg of messages) { + if(!!msg.pushName) { + const jid = msg.key.fromMe ? jidNormalizedUser(authState.creds.me!.id) : (msg.key.participant || msg.key.remoteJid) + contactNameUpdates[jid] = msg.pushName + // update our pushname too + if(msg.key.fromMe && authState.creds.me?.name !== msg.pushName) { + ev.emit('creds.update', { me: { ...authState.creds.me!, name: msg.pushName! } }) + } } - } - await processMessage(msg, chat) - if(!!msg.message && !msg.message!.protocolMessage) { - chat.conversationTimestamp = toNumber(msg.messageTimestamp) - if(!msg.key.fromMe) { - chat.unreadCount = (chat.unreadCount || 0) + 1 + await processMessage(msg, chat) + if(!!msg.message && !msg.message!.protocolMessage) { + chat.conversationTimestamp = toNumber(msg.messageTimestamp) + if(!msg.key.fromMe) { + chat.unreadCount = (chat.unreadCount || 0) + 1 + } } } - } - 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] }) - )) + 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] }) + )) + } } })