mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: implement event buffer for offline msgs
!BREAKING_CHANGE 1. this allows all offline notifications to be combined into a batch -- to reduce the number of events being sent out 2. to enable the above, the "message.reaction" event has been made an array. Also removes the need for the "operation" field 3. have also now started processing all events under a single queue to prevent state sync problems
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
WAMediaUpload,
|
||||
WAMessage,
|
||||
WAMessageContent,
|
||||
WAMessageKey,
|
||||
WAMessageStatus,
|
||||
WAProto,
|
||||
WATextMessage,
|
||||
@@ -574,7 +575,7 @@ export const getDevice = (id: string) => {
|
||||
}
|
||||
|
||||
/** Upserts a receipt in the message */
|
||||
export const updateMessageWithReceipt = (msg: WAMessage, receipt: MessageUserReceipt) => {
|
||||
export const updateMessageWithReceipt = (msg: Pick<WAMessage, 'userReceipt'>, receipt: MessageUserReceipt) => {
|
||||
msg.userReceipt = msg.userReceipt || []
|
||||
const recp = msg.userReceipt.find(m => m.userJid === receipt.userJid)
|
||||
if(recp) {
|
||||
@@ -584,6 +585,23 @@ export const updateMessageWithReceipt = (msg: WAMessage, receipt: MessageUserRec
|
||||
}
|
||||
}
|
||||
|
||||
const getKeyAuthor = (key: WAMessageKey | undefined | null) => (
|
||||
(key?.fromMe ? 'me' : key?.participant || key?.remoteJid) || ''
|
||||
)
|
||||
|
||||
/** Update the message with a new reaction */
|
||||
export const updateMessageWithReaction = (msg: Pick<WAMessage, 'reactions'>, reaction: proto.IReaction) => {
|
||||
const authorID = getKeyAuthor(reaction.key)
|
||||
|
||||
const reactions = (msg.reactions || [])
|
||||
.filter(r => getKeyAuthor(r.key) !== authorID)
|
||||
if(reaction.text) {
|
||||
reactions.push(reaction)
|
||||
}
|
||||
|
||||
msg.reactions = reactions
|
||||
}
|
||||
|
||||
/** 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[] } } = { }
|
||||
|
||||
Reference in New Issue
Block a user