From 60ee2ca522609b67b7ee6db8fdde320da0060b61 Mon Sep 17 00:00:00 2001 From: Pedro Lopez Date: Wed, 26 Feb 2020 00:39:33 -0400 Subject: [PATCH] feat: delete chat, clear chat --- src/structures/Chat.js | 20 ++++++++++++++++++++ src/util/Injected.js | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/structures/Chat.js b/src/structures/Chat.js index dd12d10..e82101d 100644 --- a/src/structures/Chat.js +++ b/src/structures/Chat.js @@ -62,6 +62,26 @@ class Chat extends Base { async sendMessage(content, options) { return this.client.sendMessage(this.id._serialized, content, options); } + + /** + * Clears all messages from the chat + * @returns {Promise} result + */ + async clearMessages() { + return this.client.pupPage.evaluate(chatId => { + return window.WWebJS.sendClearChat(chatId); + }, this.id._serialized); + } + + /** + * Deletes the chat + * @returns {Promise} result + */ + async delete() { + return this.client.pupPage.evaluate(chatId => { + return window.WWebJS.sendDeleteChat(chatId); + }, this.id._serialized); + } } module.exports = Chat; \ No newline at end of file diff --git a/src/util/Injected.js b/src/util/Injected.js index 90e4aa2..14def94 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -10,6 +10,8 @@ exports.ExposeStore = (moduleRaidStr) => { window.Store.Conn = window.mR.findModule('Conn')[0].default; window.Store.CryptoLib = window.mR.findModule('decryptE2EMedia')[0]; window.Store.Wap = window.mR.findModule('Wap')[0].default; + window.Store.SendClear = window.mR.findModule('sendClear')[0]; + window.Store.SendDelete = window.mR.findModule('sendDelete')[0]; window.Store.genId = window.mR.findModule((module) => module.default && typeof module.default === 'function' && module.default.toString().match(/crypto/))[0].default; window.Store.SendMessage = window.mR.findModule('addAndSendMsgToChat')[0]; window.Store.MsgKey = window.mR.findModule((module) => module.default && module.default.fromString)[0].default; @@ -235,6 +237,24 @@ exports.LoadUtils = () => { reader.readAsDataURL(blob); }); }; + + window.WWebJS.sendClearChat = async (chatId) => { + let chat = window.Store.Chat.get(chatId); + if (chat !== undefined) { + await window.Store.SendClear.sendClear(chat, false); + return true; + } + return false; + }; + + window.WWebJS.sendDeleteChat = async (chatId) => { + let chat = window.Store.Chat.get(chatId); + if (chat !== undefined) { + await window.Store.SendDelete.sendDelete(chat); + return true; + } + return false; + }; }; exports.MarkAllRead = () => {