mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: correctly set latest message in chat + lastMsgRecvTimestamp
This commit is contained in:
@@ -74,7 +74,12 @@ export type ChatModification =
|
|||||||
| { delete: true, lastMessages: LastMessageList }
|
| { delete: true, lastMessages: LastMessageList }
|
||||||
|
|
||||||
export type InitialReceivedChatsState = {
|
export type InitialReceivedChatsState = {
|
||||||
[jid: string]: { lastMsgRecvTimestamp: number }
|
[jid: string]: {
|
||||||
|
/** the last message received from the other party */
|
||||||
|
lastMsgRecvTimestamp?: number
|
||||||
|
/** the absolute last message in the chat */
|
||||||
|
lastMsgTimestamp: number
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type InitialAppStateSyncOptions = {
|
export type InitialAppStateSyncOptions = {
|
||||||
|
|||||||
@@ -45,20 +45,30 @@ export const processHistoryMessage = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const msgs = chat.messages || []
|
const msgs = chat.messages || []
|
||||||
|
delete chat.messages
|
||||||
|
|
||||||
for(const item of msgs) {
|
for(const item of msgs) {
|
||||||
const message = item.message!
|
const message = item.message!
|
||||||
const uqId = `${message.key.remoteJid}:${message.key.id}`
|
const uqId = `${message.key.remoteJid}:${message.key.id}`
|
||||||
if(!historyCache.has(uqId)) {
|
if(!historyCache.has(uqId)) {
|
||||||
messages.push(message)
|
messages.push(message)
|
||||||
|
|
||||||
const curItem = recvChats[message.key.remoteJid!]
|
let curItem = recvChats[message.key.remoteJid!]
|
||||||
const timestamp = toNumber(message.messageTimestamp)
|
const timestamp = toNumber(message.messageTimestamp)
|
||||||
if(!curItem || timestamp > curItem.lastMsgRecvTimestamp) {
|
if(!curItem || timestamp > curItem.lastMsgTimestamp) {
|
||||||
recvChats[chat.id] = { lastMsgRecvTimestamp: timestamp }
|
curItem = { lastMsgTimestamp: timestamp }
|
||||||
|
recvChats[chat.id] = curItem
|
||||||
// keep only the most recent message in the chat array
|
// keep only the most recent message in the chat array
|
||||||
chat.messages = [{ message }]
|
chat.messages = [{ message }]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(
|
||||||
|
!message.key.fromMe
|
||||||
|
&& (!curItem?.lastMsgRecvTimestamp || timestamp > curItem.lastMsgRecvTimestamp)
|
||||||
|
) {
|
||||||
|
curItem.lastMsgRecvTimestamp = timestamp
|
||||||
|
}
|
||||||
|
|
||||||
historyCache.add(uqId)
|
historyCache.add(uqId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user