patch messages.update

This commit is contained in:
Adhiraj Singh
2021-07-18 21:41:50 +05:30
parent 6751b5cc73
commit 8a5e6489c0
6 changed files with 26 additions and 17 deletions

View File

@@ -131,9 +131,9 @@ export default(
}
})
ev.on('messages.update', updates => {
for(const update of updates) {
const list = assertMessageList(update.key.remoteJid)
const result = list.updateAssign(update)
for(const { update, key } of updates) {
const list = assertMessageList(key.remoteJid)
const result = list.updateAssign(key.id, update)
if(!result) {
logger.debug({ update }, `got update for non-existent message`)
}
@@ -201,8 +201,8 @@ export default(
const cursorValue = cursorKey ? list.get(cursorKey.id) : undefined
let messages: WAMessage[]
if(messages && mode ==='before' && (!cursorKey || cursorValue)) {
const msgIdx = messages.findIndex(m => m.key.id === cursorKey.id)
if(list && mode === 'before' && (!cursorKey || cursorValue)) {
const msgIdx = list.array.findIndex(m => m.key.id === cursorKey.id)
messages = list.array.slice(0, msgIdx)
const diff = count - messages.length

View File

@@ -46,10 +46,12 @@ const makeOrderedDictionary = function<T>(idGetter: (item: T) => string) {
upsert,
update,
remove,
updateAssign: (update: Partial<T>) => {
const item = get(idGetter(update as any))
updateAssign: (id: string, update: Partial<T>) => {
const item = get(id)
if(item) {
Object.assign(item, update)
delete dict[id]
dict[id] = item
return true
}
return false