fix: do not update chat + contact on prepend messages

This commit is contained in:
Adhiraj Singh
2022-01-07 13:55:26 +05:30
parent 6a2cb5a413
commit da65ae8f42

View File

@@ -498,34 +498,36 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
} }
}) })
ev.on('messages.upsert', async({ messages }) => { ev.on('messages.upsert', async({ messages, type }) => {
const chat: Partial<Chat> = { id: messages[0].key.remoteJid } if(type === 'notify' || type === 'append') {
const contactNameUpdates: { [_: string]: string } = { } const chat: Partial<Chat> = { id: messages[0].key.remoteJid }
for(const msg of messages) { const contactNameUpdates: { [_: string]: string } = { }
if(!!msg.pushName) { for(const msg of messages) {
const jid = msg.key.fromMe ? jidNormalizedUser(authState.creds.me!.id) : (msg.key.participant || msg.key.remoteJid) if(!!msg.pushName) {
contactNameUpdates[jid] = msg.pushName const jid = msg.key.fromMe ? jidNormalizedUser(authState.creds.me!.id) : (msg.key.participant || msg.key.remoteJid)
// update our pushname too contactNameUpdates[jid] = msg.pushName
if(msg.key.fromMe && authState.creds.me?.name !== msg.pushName) { // update our pushname too
ev.emit('creds.update', { me: { ...authState.creds.me!, name: msg.pushName! } }) 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) await processMessage(msg, chat)
if(!!msg.message && !msg.message!.protocolMessage) { if(!!msg.message && !msg.message!.protocolMessage) {
chat.conversationTimestamp = toNumber(msg.messageTimestamp) chat.conversationTimestamp = toNumber(msg.messageTimestamp)
if(!msg.key.fromMe) { if(!msg.key.fromMe) {
chat.unreadCount = (chat.unreadCount || 0) + 1 chat.unreadCount = (chat.unreadCount || 0) + 1
}
} }
} }
} if(Object.keys(chat).length > 1) {
if(Object.keys(chat).length > 1) { ev.emit('chats.update', [ chat ])
ev.emit('chats.update', [ chat ]) }
} if(Object.keys(contactNameUpdates).length) {
if(Object.keys(contactNameUpdates).length) { ev.emit('contacts.update', Object.keys(contactNameUpdates).map(
ev.emit('contacts.update', Object.keys(contactNameUpdates).map( id => ({ id, notify: contactNameUpdates[id] })
id => ({ id, notify: contactNameUpdates[id] }) ))
)) }
} }
}) })