From daaa04445fc0aa4cfa4ba60d4f49d99b434668e4 Mon Sep 17 00:00:00 2001 From: BenyFilho <168232825+BenyFilho@users.noreply.github.com> Date: Tue, 10 Jun 2025 03:14:21 -0300 Subject: [PATCH] Fix Send Animated Sticker (#3591) * Fix Send Animated Sitckers * Update Utils.js * Add a condition to ignore channels Add a condition to ignore channels and keep compatibility. * chore: mark channels as done feature --------- Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com> --- README.md | 2 +- src/util/Injected/Store.js | 1 + src/util/Injected/Utils.js | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 886b060..bc26212 100644 --- a/README.md +++ b/README.md @@ -128,9 +128,9 @@ For further details on saving and restoring sessions, explore the provided [Auth | Set user status message | ✅ | | React to messages | ✅ | | Create polls | ✅ | +| Channels | ✅ | | Vote in polls | 🔜 | | Communities | 🔜 | -| Channels | 🔜 | Something missing? Make an issue and let us know! diff --git a/src/util/Injected/Store.js b/src/util/Injected/Store.js index 536552d..48e5916 100644 --- a/src/util/Injected/Store.js +++ b/src/util/Injected/Store.js @@ -98,6 +98,7 @@ exports.ExposeStore = () => { window.Store.HistorySync = window.require('WAWebSendNonMessageDataRequest'); window.Store.AddonReactionTable = window.require('WAWebAddonReactionTableMode').reactionTableMode; window.Store.ChatGetters = window.require('WAWebChatGetters'); + window.Store.UploadUtils = window.require('WAWebUploadManager'); window.Store.Settings = { ...window.require('WAWebUserPrefsGeneral'), diff --git a/src/util/Injected/Utils.js b/src/util/Injected/Utils.js index 75cf0e1..1389540 100644 --- a/src/util/Injected/Utils.js +++ b/src/util/Injected/Utils.js @@ -28,8 +28,9 @@ exports.LoadUtils = () => { let mediaOptions = {}; if (options.media) { - mediaOptions = await window.WWebJS.processMediaData( - options.media, { + mediaOptions = options.sendMediaAsSticker && !isChannel + ? await window.WWebJS.processStickerData(options.media) + : await window.WWebJS.processMediaData(options.media, { forceSticker: options.sendMediaAsSticker, forceGif: options.sendVideoAsGif, forceVoice: options.sendAudioAsVoice, @@ -362,6 +363,34 @@ exports.LoadUtils = () => { }; }; + window.WWebJS.processStickerData = async (mediaInfo) => { + if (mediaInfo.mimetype !== 'image/webp') throw new Error('Invalid media type'); + + const file = window.WWebJS.mediaInfoToFile(mediaInfo); + let filehash = await window.WWebJS.getFileHash(file); + let mediaKey = await window.WWebJS.generateHash(32); + + const controller = new AbortController(); + const uploadedInfo = await window.Store.UploadUtils.encryptAndUpload({ + blob: file, + type: 'sticker', + signal: controller.signal, + mediaKey + }); + + const stickerInfo = { + ...uploadedInfo, + clientUrl: uploadedInfo.url, + deprecatedMms3Url: uploadedInfo.url, + uploadhash: uploadedInfo.encFilehash, + size: file.size, + type: 'sticker', + filehash + }; + + return stickerInfo; + }; + window.WWebJS.processMediaData = async (mediaInfo, { forceSticker, forceGif, forceVoice, forceDocument, forceMediaHd, sendToChannel }) => { const file = window.WWebJS.mediaInfoToFile(mediaInfo); const opaqueData = await window.Store.OpaqueData.createFromData(file, file.type);