From 537e843a49529488b8d735f6c28503dc676c5731 Mon Sep 17 00:00:00 2001 From: jurajmatus Date: Wed, 10 Aug 2022 18:31:04 +0200 Subject: [PATCH 1/3] Async buffer->BASE64 conversion (#1481) * Async buffer->BASE64 conversion * ESLint fixes --- src/structures/Message.js | 2 +- src/util/Injected.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index 7c1d3d0..dc4acaf 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -410,7 +410,7 @@ class Message extends Base { signal: (new AbortController).signal }); - const data = window.WWebJS.arrayBufferToBase64(decryptedMedia); + const data = await window.WWebJS.arrayBufferToBase64Async(decryptedMedia); return { data, diff --git a/src/util/Injected.js b/src/util/Injected.js index a5eeae3..b09b27e 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -480,6 +480,20 @@ exports.LoadUtils = () => { return window.btoa(binary); }; + window.WWebJS.arrayBufferToBase64Async = (arrayBuffer) => + new Promise((resolve, reject) => { + const blob = new Blob([arrayBuffer], { + type: 'application/octet-stream', + }); + const fileReader = new FileReader(); + fileReader.onload = () => { + const [, data] = fileReader.result.split(','); + resolve(data); + }; + fileReader.onerror = (e) => reject(e); + fileReader.readAsDataURL(blob); + }); + window.WWebJS.getFileHash = async (data) => { let buffer = await data.arrayBuffer(); const hashBuffer = await crypto.subtle.digest('SHA-256', buffer); From ab7ee0eb4f3f93b31220613fe08176450e2b68de Mon Sep 17 00:00:00 2001 From: Yuri <65935022+tuyuribr3@users.noreply.github.com> Date: Wed, 10 Aug 2022 13:46:43 -0300 Subject: [PATCH 2/3] Fixing remote auth optional depencies error (#1640) Co-authored-by: Rajeh Taher --- src/authStrategies/RemoteAuth.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/authStrategies/RemoteAuth.js b/src/authStrategies/RemoteAuth.js index 1645ccd..5ae85cc 100644 --- a/src/authStrategies/RemoteAuth.js +++ b/src/authStrategies/RemoteAuth.js @@ -6,7 +6,9 @@ try { var unzipper = require('unzipper'); var archiver = require('archiver'); } catch { - throw new Error('Optional Dependencies [fs-extra, unzipper, archiver] are required to use RemoteAuth. Make sure to run npm install correctly and remove the --no-optional flag'); + fs = undefined; + unzipper = undefined; + archiver = undefined; } const path = require('path'); @@ -23,6 +25,7 @@ const BaseAuthStrategy = require('./BaseAuthStrategy'); */ class RemoteAuth extends BaseAuthStrategy { constructor({ clientId, dataPath, store, backupSyncIntervalMs } = {}) { + if (!fs && !unzipper && !archiver) throw new Error('Optional Dependencies [fs-extra, unzipper, archiver] are required to use RemoteAuth. Make sure to run npm install correctly and remove the --no-optional flag'); super(); const idRegex = /^[-_\w]+$/i; @@ -198,4 +201,4 @@ class RemoteAuth extends BaseAuthStrategy { } } -module.exports = RemoteAuth; \ No newline at end of file +module.exports = RemoteAuth; From b74246d69a0e1d8478c55a45d5cc126c06b4e2f7 Mon Sep 17 00:00:00 2001 From: Roi Greenberg Date: Sun, 14 Aug 2022 18:30:14 +0300 Subject: [PATCH 3/3] Add "fromMe" option to fetchMessages (#1444) --- index.d.ts | 4 ++++ src/structures/Chat.js | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index a99c508..edf4684 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1062,6 +1062,10 @@ declare namespace WAWebJS { * Set this to Infinity to load all messages. */ limit?: number + /** + * Return only messages from the bot number or vise versa. To get all messages, leave the option undefined. + */ + fromMe?: boolean } /** diff --git a/src/structures/Chat.js b/src/structures/Chat.js index 6f0f0e2..241d297 100644 --- a/src/structures/Chat.js +++ b/src/structures/Chat.js @@ -170,13 +170,22 @@ class Chat extends Base { /** * Loads chat messages, sorted from earliest to latest. - * @param {Object} searchOptions Options for searching messages. Right now only limit is supported. + * @param {Object} searchOptions Options for searching messages. Right now only limit and fromMe is supported. * @param {Number} [searchOptions.limit] The amount of messages to return. If no limit is specified, the available messages will be returned. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages. + * @param {Boolean} [searchOptions.fromMe] Return only messages from the bot number or vise versa. To get all messages, leave the option undefined. * @returns {Promise>} */ async fetchMessages(searchOptions) { let messages = await this.client.pupPage.evaluate(async (chatId, searchOptions) => { - const msgFilter = m => !m.isNotification; // dont include notification messages + const msgFilter = (m) => { + if (m.isNotification) { + return false; // dont include notification messages + } + if (searchOptions && searchOptions.fromMe && m.id.fromMe !== searchOptions.fromMe) { + return false; + } + return true; + }; const chat = window.Store.Chat.get(chatId); let msgs = chat.msgs.getModelsArray().filter(msgFilter);