mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Add option to look for deleted keys in shallowChanges
This commit is contained in:
@@ -47,7 +47,7 @@ export class WAConnection extends Base {
|
|||||||
} else {
|
} else {
|
||||||
chat.messages = oldChat.messages
|
chat.messages = oldChat.messages
|
||||||
if (oldChat.t !== chat.t || oldChat.modify_tag !== chat.modify_tag) {
|
if (oldChat.t !== chat.t || oldChat.modify_tag !== chat.modify_tag) {
|
||||||
const changes = shallowChanges (oldChat, chat)
|
const changes = shallowChanges (oldChat, chat, { lookForDeletedKeys: true })
|
||||||
delete chat.metadata // remove group metadata as that may have changed; TODO, write better mechanism for this
|
delete chat.metadata // remove group metadata as that may have changed; TODO, write better mechanism for this
|
||||||
delete changes.messages
|
delete changes.messages
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ export class WAConnection extends Base {
|
|||||||
contact.jid = whatsappID (contact.jid)
|
contact.jid = whatsappID (contact.jid)
|
||||||
const presentContact = contacts[contact.jid]
|
const presentContact = contacts[contact.jid]
|
||||||
if (presentContact) {
|
if (presentContact) {
|
||||||
const changes = shallowChanges(presentContact, contact)
|
const changes = shallowChanges(presentContact, contact, { lookForDeletedKeys: false })
|
||||||
if (changes && Object.keys(changes).length > 0) {
|
if (changes && Object.keys(changes).length > 0) {
|
||||||
updatedContacts.push({ ...changes, jid: contact.jid })
|
updatedContacts.push({ ...changes, jid: contact.jid })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,16 +45,18 @@ export const newMessagesDB = (messages: WAMessage[] = []) => {
|
|||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
export function shallowChanges <T> (old: T, current: T): Partial<T> {
|
export function shallowChanges <T> (old: T, current: T, {lookForDeletedKeys}: {lookForDeletedKeys: boolean}): Partial<T> {
|
||||||
let changes: Partial<T> = {}
|
let changes: Partial<T> = {}
|
||||||
for (let key in current) {
|
for (let key in current) {
|
||||||
if (old[key] !== current[key]) {
|
if (old[key] !== current[key]) {
|
||||||
changes[key] = current[key] || null
|
changes[key] = current[key] || null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let key in old) {
|
if (lookForDeletedKeys) {
|
||||||
if (!changes[key] && old[key] !== current[key]) {
|
for (let key in old) {
|
||||||
changes[key] = current[key] || null
|
if (!changes[key] && old[key] !== current[key]) {
|
||||||
|
changes[key] = current[key] || null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return changes
|
return changes
|
||||||
|
|||||||
Reference in New Issue
Block a user