From f8419dd1437bfd670502ed0f9135be15fac945d8 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Fri, 18 Oct 2024 05:01:52 +0300 Subject: [PATCH 1/4] feat: make view once messages downloadable --- src/util/Injected/Store.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/util/Injected/Store.js b/src/util/Injected/Store.js index 2da5871d9f..6e062a8b02 100644 --- a/src/util/Injected/Store.js +++ b/src/util/Injected/Store.js @@ -165,4 +165,39 @@ exports.ExposeStore = () => { window.injectToFunction({ module: 'WAWebE2EProtoUtils', function: 'typeAttributeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage || proto.groupInviteMessage ? 'text' : func(...args); }); + window.injectToFunction( + { + module: "WAWebE2EProtoParser", + function: "parseMsgProto", + }, + (func, ...args) => { + const [msg] = args; + let isViewOnce = false; + + const viewOnceMsg = + msg.viewOnceMessage?.message || + msg.viewOnceMessageV2?.message || + msg.viewOnceMessageV2Extension?.message; + + if (viewOnceMsg) { + args[0] = viewOnceMsg; + isViewOnce = true; + } + + for (const type of [ + "imageMessage", + "videoMessage", + "audioMessage", + ]) { + if (args[0][type]) { + delete args[0][type].viewOnce; + break; + } + } + + const result = func(...args); + result.isViewOnce = isViewOnce; + return result; + } + ); }; From 7184a1c369d93ef6f1dcdb9bf0e8cf5f3e30a506 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Fri, 18 Oct 2024 05:21:03 +0300 Subject: [PATCH 2/4] fix: eslint fix --- src/util/Injected/Store.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util/Injected/Store.js b/src/util/Injected/Store.js index 6e062a8b02..09ec197298 100644 --- a/src/util/Injected/Store.js +++ b/src/util/Injected/Store.js @@ -167,8 +167,8 @@ exports.ExposeStore = () => { window.injectToFunction( { - module: "WAWebE2EProtoParser", - function: "parseMsgProto", + module: 'WAWebE2EProtoParser', + function: 'parseMsgProto', }, (func, ...args) => { const [msg] = args; @@ -185,9 +185,9 @@ exports.ExposeStore = () => { } for (const type of [ - "imageMessage", - "videoMessage", - "audioMessage", + 'imageMessage', + 'videoMessage', + 'audioMessage', ]) { if (args[0][type]) { delete args[0][type].viewOnce; From e89942b1159519c8cf67f3db7b9f6c09b8d739f6 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Fri, 18 Oct 2024 05:33:08 +0300 Subject: [PATCH 3/4] refactor: add isViewOnce prop only when truly --- src/util/Injected/Store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/Injected/Store.js b/src/util/Injected/Store.js index 09ec197298..67a367a61b 100644 --- a/src/util/Injected/Store.js +++ b/src/util/Injected/Store.js @@ -196,7 +196,7 @@ exports.ExposeStore = () => { } const result = func(...args); - result.isViewOnce = isViewOnce; + isViewOnce && (result.isViewOnce = true); return result; } ); From 22ff35eb4e42c0dd795e6ed9ec45ff35d487a1aa Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Sat, 19 Oct 2024 06:46:19 +0300 Subject: [PATCH 4/4] refactor: fix condition --- src/util/Injected/Store.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/util/Injected/Store.js b/src/util/Injected/Store.js index 67a367a61b..20128f5ac5 100644 --- a/src/util/Injected/Store.js +++ b/src/util/Injected/Store.js @@ -172,7 +172,6 @@ exports.ExposeStore = () => { }, (func, ...args) => { const [msg] = args; - let isViewOnce = false; const viewOnceMsg = msg.viewOnceMessage?.message || @@ -181,22 +180,21 @@ exports.ExposeStore = () => { if (viewOnceMsg) { args[0] = viewOnceMsg; - isViewOnce = true; - } - for (const type of [ - 'imageMessage', - 'videoMessage', - 'audioMessage', - ]) { - if (args[0][type]) { - delete args[0][type].viewOnce; - break; + for (const type of [ + 'imageMessage', + 'audioMessage', + 'videoMessage', + ]) { + if (args[0][type]) { + delete args[0][type].viewOnce; + break; + } } } const result = func(...args); - isViewOnce && (result.isViewOnce = true); + viewOnceMsg && (result.isViewOnce = true); return result; } );