feat: group mentions + improved user mentions (#2602)
* added logic to mention groups + fixed user mentions * usage example updated * docs fixed * window.injectToFunction clarifications * usage example clarifications * fix: typo * docs: added missed docs
This commit is contained in:
parent
8d683a668b
commit
e0d955f130
1 changed files with 164 additions and 25 deletions
|
|
@ -187,14 +187,32 @@ class Message extends Base {
|
|||
} : undefined;
|
||||
|
||||
/**
|
||||
* Indicates the mentions in the message body.
|
||||
* @type {Array<string>}
|
||||
* @typedef {Object} Mention
|
||||
* @property {string} server
|
||||
* @property {string} user
|
||||
* @property {string} _serialized
|
||||
*/
|
||||
this.mentionedIds = [];
|
||||
|
||||
if (data.mentionedJidList) {
|
||||
this.mentionedIds = data.mentionedJidList;
|
||||
}
|
||||
/**
|
||||
* Indicates the mentions in the message body.
|
||||
* @type {Mention[]}
|
||||
*/
|
||||
this.mentionedIds = data.mentionedJidList || [];
|
||||
|
||||
/**
|
||||
* @typedef {Object} GroupMention
|
||||
* @property {string} groupSubject The name of the group
|
||||
* @property {Object} groupJid The group ID
|
||||
* @property {string} groupJid.server
|
||||
* @property {string} groupJid.user
|
||||
* @property {string} groupJid._serialized
|
||||
*/
|
||||
|
||||
/**
|
||||
* Indicates whether there are group mentions in the message body
|
||||
* @type {GroupMention[]}
|
||||
*/
|
||||
this.groupMentions = data.groupMentions || [];
|
||||
|
||||
/**
|
||||
* Order ID for message type ORDER
|
||||
|
|
@ -341,6 +359,14 @@ class Message extends Base {
|
|||
async getMentions() {
|
||||
return await Promise.all(this.mentionedIds.map(async m => await this.client.getContactById(m)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns groups mentioned in this message
|
||||
* @returns {Promise<GroupChat[]|[]>}
|
||||
*/
|
||||
async getGroupMentions() {
|
||||
return await Promise.all(this.groupMentions.map(async (m) => await this.client.getChatById(m.groupJid._serialized)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the quoted message, if any
|
||||
|
|
@ -649,12 +675,20 @@ class Message extends Base {
|
|||
* @returns {Promise<?Message>}
|
||||
*/
|
||||
async edit(content, options = {}) {
|
||||
if (options.mentions && options.mentions.some(possiblyContact => possiblyContact instanceof Contact)) {
|
||||
options.mentions = options.mentions.map(a => a.id._serialized);
|
||||
if (options.mentions) {
|
||||
!Array.isArray(options.mentions) && (options.mentions = [options.mentions]);
|
||||
if (options.mentions.some((possiblyContact) => possiblyContact instanceof Contact)) {
|
||||
console.warn('Mentions with an array of Contact are now deprecated. See more at https://github.com/pedroslopez/whatsapp-web.js/pull/2166.');
|
||||
options.mentions = options.mentions.map((a) => a.id._serialized);
|
||||
}
|
||||
}
|
||||
|
||||
options.groupMentions && !Array.isArray(options.groupMentions) && (options.groupMentions = [options.groupMentions]);
|
||||
|
||||
let internalOptions = {
|
||||
linkPreview: options.linkPreview === false ? undefined : true,
|
||||
mentionedJidList: Array.isArray(options.mentions) ? options.mentions : [],
|
||||
mentionedJidList: options.mentions || [],
|
||||
groupMentions: options.groupMentions,
|
||||
extraOptions: options.extra
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue