mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 20:49:14 +00:00
feat: load reactions in message (#1897)
* msg find reactions * reaction list * return hasReaction only true or false --------- Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
This commit is contained in:
14
index.d.ts
vendored
14
index.d.ts
vendored
@@ -649,6 +649,7 @@ declare namespace WAWebJS {
|
|||||||
* broadcast: false,
|
* broadcast: false,
|
||||||
* fromMe: false,
|
* fromMe: false,
|
||||||
* hasQuotedMsg: false,
|
* hasQuotedMsg: false,
|
||||||
|
* hasReaction: false,
|
||||||
* location: undefined,
|
* location: undefined,
|
||||||
* mentionedIds: []
|
* mentionedIds: []
|
||||||
* }
|
* }
|
||||||
@@ -678,6 +679,8 @@ declare namespace WAWebJS {
|
|||||||
hasMedia: boolean,
|
hasMedia: boolean,
|
||||||
/** Indicates if the message was sent as a reply to another message */
|
/** Indicates if the message was sent as a reply to another message */
|
||||||
hasQuotedMsg: boolean,
|
hasQuotedMsg: boolean,
|
||||||
|
/** Indicates whether there are reactions to the message */
|
||||||
|
hasReaction: boolean,
|
||||||
/** Indicates the duration of the message in seconds */
|
/** Indicates the duration of the message in seconds */
|
||||||
duration: string,
|
duration: string,
|
||||||
/** ID that represents the message */
|
/** ID that represents the message */
|
||||||
@@ -779,6 +782,10 @@ declare namespace WAWebJS {
|
|||||||
* Gets the payment details associated with a given message
|
* Gets the payment details associated with a given message
|
||||||
*/
|
*/
|
||||||
getPayment: () => Promise<Payment>,
|
getPayment: () => Promise<Payment>,
|
||||||
|
/**
|
||||||
|
* Gets the reactions associated with the given message
|
||||||
|
*/
|
||||||
|
getReactions: () => Promise<ReactionList[]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ID that represents a message */
|
/** ID that represents a message */
|
||||||
@@ -1381,6 +1388,13 @@ declare namespace WAWebJS {
|
|||||||
senderId: string
|
senderId: string
|
||||||
ack?: number
|
ack?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ReactionList = {
|
||||||
|
id: string,
|
||||||
|
aggregateEmoji: string,
|
||||||
|
hasReactionByMe: boolean,
|
||||||
|
senders: Array<Reaction>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export = WAWebJS
|
export = WAWebJS
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ const MessageMedia = require('./MessageMedia');
|
|||||||
const Location = require('./Location');
|
const Location = require('./Location');
|
||||||
const Order = require('./Order');
|
const Order = require('./Order');
|
||||||
const Payment = require('./Payment');
|
const Payment = require('./Payment');
|
||||||
const { MessageTypes } = require('../util/Constants');
|
const Reaction = require('./Reaction');
|
||||||
|
const {MessageTypes} = require('../util/Constants');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Message on WhatsApp
|
* Represents a Message on WhatsApp
|
||||||
@@ -134,6 +135,12 @@ class Message extends Base {
|
|||||||
*/
|
*/
|
||||||
this.hasQuotedMsg = data.quotedMsg ? true : false;
|
this.hasQuotedMsg = data.quotedMsg ? true : false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether there are reactions to the message
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.hasReaction = data.hasReaction ? true : false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates the duration of the message in seconds
|
* Indicates the duration of the message in seconds
|
||||||
* @type {string}
|
* @type {string}
|
||||||
@@ -529,6 +536,44 @@ class Message extends Base {
|
|||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reaction List
|
||||||
|
* @typedef {Object} ReactionList
|
||||||
|
* @property {string} id Original emoji
|
||||||
|
* @property {string} aggregateEmoji aggregate emoji
|
||||||
|
* @property {boolean} hasReactionByMe Flag who sent the reaction
|
||||||
|
* @property {Array<Reaction>} senders Reaction senders, to this message
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the reactions associated with the given message
|
||||||
|
* @return {Promise<ReactionList[]>}
|
||||||
|
*/
|
||||||
|
async getReactions() {
|
||||||
|
if (!this.hasReaction) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const reactions = await this.client.pupPage.evaluate(async (msgId) => {
|
||||||
|
const msgReactions = await window.Store.Reactions.find(msgId);
|
||||||
|
if (!msgReactions || !msgReactions.reactions.length) return null;
|
||||||
|
return msgReactions.reactions.serialize();
|
||||||
|
}, this.id._serialized);
|
||||||
|
|
||||||
|
if (!reactions) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return reactions.map(reaction => {
|
||||||
|
reaction.senders = reaction.senders.map(sender => {
|
||||||
|
sender.timestamp = Math.round(sender.timestamp / 1000);
|
||||||
|
return new Reaction(this.client, sender);
|
||||||
|
});
|
||||||
|
return reaction;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Message;
|
module.exports = Message;
|
||||||
|
|||||||
Reference in New Issue
Block a user