mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: do not update chat + contact on prepend messages
This commit is contained in:
@@ -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] })
|
))
|
||||||
))
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user