chore: add ability to specify ISyncActionMessageRange directly

This commit is contained in:
Adhiraj Singh
2022-04-28 16:26:23 +05:30
parent 87c1a04503
commit 6ee60bff67
3 changed files with 39 additions and 25 deletions

View File

@@ -1,4 +1,4 @@
import { BaileysEventMap, Chat, ChatModification, Contact, LegacySocketConfig, PresenceData, WABusinessProfile, WAFlag, WAMessageKey, WAMessageUpdate, WAMetric, WAPresence } from '../Types'
import { BaileysEventMap, Chat, ChatModification, Contact, LastMessageList, LegacySocketConfig, PresenceData, WABusinessProfile, WAFlag, WAMessageKey, WAMessageUpdate, WAMetric, WAPresence } from '../Types'
import { debouncedTimeout, unixTimestampSeconds } from '../Utils/generics'
import { BinaryNode, jidNormalizedUser } from '../WABinary'
import makeAuthSocket from './auth'
@@ -309,6 +309,14 @@ const makeChatsSocket = (config: LegacySocketConfig) => {
timestampNow = timestampNow || unixTimestampSeconds()
const getIndexKey = (list: LastMessageList) => {
if(Array.isArray(list)) {
return list[list.length - 1].key
}
return list.messages?.[list.messages?.length - 1]?.key
}
if('archive' in modification) {
chatAttrs.type = modification.archive ? 'archive' : 'unarchive'
} else if('pin' in modification) {
@@ -345,14 +353,14 @@ const makeChatsSocket = (config: LegacySocketConfig) => {
}
))
} else if('markRead' in modification) {
const indexKey = modification.lastMessages[modification.lastMessages.length - 1].key
const indexKey = getIndexKey(modification.lastMessages)
return chatRead(indexKey, modification.markRead ? 0 : -1)
} else if('delete' in modification) {
chatAttrs.type = 'delete'
}
if('lastMessages' in modification) {
const indexKey = modification.lastMessages[modification.lastMessages.length - 1].key
const indexKey = getIndexKey(modification.lastMessages)
if(indexKey) {
chatAttrs.index = indexKey.id
chatAttrs.owner = indexKey.fromMe ? 'true' : 'false'