mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
message ordering bug fix
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { MessageType, Mimetype, delay, promiseTimeout, WA_MESSAGE_STATUS_TYPE, WAMessageStatusUpdate, MessageOptions, toNumber } from '../WAConnection/WAConnection'
|
||||
import { MessageType, Mimetype, delay, promiseTimeout, WA_MESSAGE_STATUS_TYPE, WAMessageStatusUpdate } from '../WAConnection/WAConnection'
|
||||
import {promises as fs} from 'fs'
|
||||
import * as assert from 'assert'
|
||||
import { WAConnectionTest, testJid, sendAndRetreiveMessage, assertChatDBIntegrity } from './Common'
|
||||
|
||||
@@ -195,13 +195,15 @@ export class WAConnection extends Base {
|
||||
const messages = json[2] as WANode[]
|
||||
|
||||
if (messages) {
|
||||
|
||||
messages.reverse().forEach (([,, message]: ['message', null, WAMessage]) => {
|
||||
const jid = message.key.remoteJid
|
||||
const chat = chats.get(jid)
|
||||
if (chat) {
|
||||
const fm = chat.messages.all()[0]
|
||||
const prevEpoch = (fm && fm['epoch']) || 0
|
||||
|
||||
const prevEpoch = (fm && fm['epoch']) || 0
|
||||
|
||||
message['epoch'] = prevEpoch-1
|
||||
chat.messages.insert (message)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ export const waChatKey = (pin: boolean) => ({
|
||||
compare: (k1: string, k2: string) => k2.localeCompare (k1)
|
||||
})
|
||||
export const waMessageKey = {
|
||||
key: (m: WAMessage) => toNumber (m.messageTimestamp).toString(16).padStart(8, '0') + (5000 + (m['epoch'] || 0)).toString(16),
|
||||
key: (m: WAMessage) => (5000 + (m['epoch'] || 0)).toString(16) + toNumber (m.messageTimestamp).toString(16).padStart(8, '0'),
|
||||
compare: (k1: string, k2: string) => k1.localeCompare (k2)
|
||||
}
|
||||
export const WA_MESSAGE_ID = (m: WAMessage) => GET_MESSAGE_ID (m.key)
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"strict": false,
|
||||
"noImplicitThis": true,
|
||||
"esModuleInterop": true,
|
||||
"resolveJsonModule": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"declaration": true,
|
||||
"lib": ["es2019", "esnext.array"]
|
||||
|
||||
Reference in New Issue
Block a user