mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
chore: add ability to specify ISyncActionMessageRange directly
This commit is contained in:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user