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 }) => {
|
||||
const chat: Partial<Chat> = { 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<Chat> = { 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] })
|
||||
))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user