From 1b946940f495bb121c6b4ffdb159afdfa82ce28b Mon Sep 17 00:00:00 2001 From: Marcelo Carvalho Date: Mon, 28 Dec 2020 20:05:45 -0300 Subject: [PATCH] feat: star/unstar messages (#494) --- index.d.ts | 4 ++++ src/structures/Message.js | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/index.d.ts b/index.d.ts index 799d6a6..930f193 100644 --- a/index.d.ts +++ b/index.d.ts @@ -524,6 +524,10 @@ declare namespace WAWebJS { * Forwards this message to another chat */ forward: (chat: Chat | string) => Promise, + /** Star this message */ + star: () => Promise + /** Unstar this message */ + unstar: () => Promise } /** ID that represents a message */ diff --git a/src/structures/Message.js b/src/structures/Message.js index 2722165..45112d4 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -278,6 +278,32 @@ class Message extends Base { return window.Store.Cmd.sendDeleteMsgs(msg.chat, [msg], true); }, this.id._serialized, everyone); } + + /** + * Stars this message + */ + async star() { + await this.pupPage.evaluate((msgId) => { + let msg = window.Store.Msg.get(msgId); + + if (msg.canStar()) { + return msg.chat.sendStarMsgs([msg], true); + } + }, this.id._serialized); + } + + /** + * Unstars this message + */ + async unstar() { + await this.pupPage.evaluate((msgId) => { + let msg = window.Store.Msg.get(msgId); + + if (msg.canStar()) { + return msg.chat.sendStarMsgs([msg], false); + } + }, this.id._serialized); + } } module.exports = Message;