mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: add readMessages function
This commit is contained in:
@@ -526,6 +526,7 @@ export const getDevice = (id: string) => {
|
||||
return deviceType
|
||||
}
|
||||
|
||||
/** Upserts a receipt in the message */
|
||||
export const updateMessageWithReceipt = (msg: WAMessage, receipt: MessageUserReceipt) => {
|
||||
msg.userReceipt = msg.userReceipt || []
|
||||
const recp = msg.userReceipt.find(m => m.userJid === receipt.userJid)
|
||||
@@ -536,6 +537,27 @@ export const updateMessageWithReceipt = (msg: WAMessage, receipt: MessageUserRec
|
||||
}
|
||||
}
|
||||
|
||||
/** Given a list of message keys, aggregates them by chat & sender. Useful for sending read receipts in bulk */
|
||||
export const aggregateMessageKeysNotFromMe = (keys: proto.IMessageKey[]) => {
|
||||
const keyMap: { [id: string]: { jid: string, participant: string | undefined, messageIds: string[] } } = { }
|
||||
for(const { remoteJid, id, participant, fromMe } of keys) {
|
||||
if(!fromMe) {
|
||||
const uqKey = `${remoteJid}:${participant || ''}`
|
||||
if(!keyMap[uqKey]) {
|
||||
keyMap[uqKey] = {
|
||||
jid: remoteJid,
|
||||
participant,
|
||||
messageIds: []
|
||||
}
|
||||
}
|
||||
|
||||
keyMap[uqKey].messageIds.push(id)
|
||||
}
|
||||
}
|
||||
|
||||
return Object.values(keyMap)
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads the given message. Throws an error if it's not a media message
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user