feat: delete chat, clear chat

This commit is contained in:
Pedro Lopez
2020-02-26 00:39:33 -04:00
parent 37932d9a69
commit 60ee2ca522
2 changed files with 40 additions and 0 deletions

View File

@@ -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<Boolean>} result
*/
async clearMessages() {
return this.client.pupPage.evaluate(chatId => {
return window.WWebJS.sendClearChat(chatId);
}, this.id._serialized);
}
/**
* Deletes the chat
* @returns {Promise<Boolean>} result
*/
async delete() {
return this.client.pupPage.evaluate(chatId => {
return window.WWebJS.sendDeleteChat(chatId);
}, this.id._serialized);
}
}
module.exports = Chat;

View File

@@ -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 = () => {