mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Update 7.MessagesExtra.ts
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
|||||||
WAUrlInfo,
|
WAUrlInfo,
|
||||||
WAMessageContent, WAMetric, WAFlag, WANode, WAMessage, WAMessageProto, BaileysError, MessageLogLevel, WA_MESSAGE_STATUS_TYPE
|
WAMessageContent, WAMetric, WAFlag, WANode, WAMessage, WAMessageProto, BaileysError, MessageLogLevel, WA_MESSAGE_STATUS_TYPE
|
||||||
} from './Constants'
|
} from './Constants'
|
||||||
import { whatsappID, delay } from './Utils'
|
import { whatsappID, delay, toNumber, unixTimestampSeconds } from './Utils'
|
||||||
|
|
||||||
export class WAConnection extends Base {
|
export class WAConnection extends Base {
|
||||||
|
|
||||||
@@ -194,6 +194,27 @@ export class WAConnection extends Base {
|
|||||||
await delay (200)
|
await delay (200)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Loads all messages sent after a specific date
|
||||||
|
*/
|
||||||
|
async messagesReceivedAfter (date: Date) {
|
||||||
|
const stamp = unixTimestampSeconds (date)
|
||||||
|
// find the index where the chat timestamp becomes greater
|
||||||
|
const idx = this.chats.all ().findIndex (c => c.t < stamp)
|
||||||
|
// all chats before that index -- i.e. all chats that were updated after that
|
||||||
|
const chats = this.chats.all ().slice (0, idx)
|
||||||
|
|
||||||
|
const messages: WAMessage[] = []
|
||||||
|
await Promise.all (
|
||||||
|
chats.map (async chat => {
|
||||||
|
await this.findMessage (chat.jid, 5, m => {
|
||||||
|
if (toNumber(m.messageTimestamp) < stamp) return true
|
||||||
|
messages.push (m)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
)
|
||||||
|
return messages
|
||||||
|
}
|
||||||
/** Load a single message specified by the ID */
|
/** Load a single message specified by the ID */
|
||||||
async loadMessage (jid: string, messageID: string) {
|
async loadMessage (jid: string, messageID: string) {
|
||||||
// load the message before the given message
|
// load the message before the given message
|
||||||
|
|||||||
Reference in New Issue
Block a user