From ab321f3d7eee802c6f33e34e2997636021f756a4 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Sat, 9 Aug 2025 00:35:40 +0300 Subject: [PATCH] fix: `Message.pin` and `Message.unpin` (#3319) * fix: update function to wweb version >2.3000.0 * feat: add foolproof check * fix: override internal function correctly --- src/util/Injected/Store.js | 2 +- src/util/Injected/Utils.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/util/Injected/Store.js b/src/util/Injected/Store.js index 97b9256..2aaf6f1 100644 --- a/src/util/Injected/Store.js +++ b/src/util/Injected/Store.js @@ -88,7 +88,6 @@ exports.ExposeStore = () => { window.Store.WidToJid = window.require('WAWebWidToJid'); window.Store.JidToWid = window.require('WAWebJidToWid'); window.Store.getMsgInfo = window.require('WAWebApiMessageInfoStore').queryMsgInfo; - window.Store.pinUnpinMsg = window.require('WAWebSendPinMessageAction').sendPinInChatMsg; window.Store.QueryExist = window.require('WAWebQueryExistsJob').queryWidExists; window.Store.ReplyUtils = window.require('WAWebMsgReply'); window.Store.BotSecret = window.require('WAWebBotMessageSecret'); @@ -99,6 +98,7 @@ exports.ExposeStore = () => { window.Store.AddonReactionTable = window.require('WAWebAddonReactionTableMode').reactionTableMode; window.Store.PinnedMsgUtils = window.require('WAWebPinInChatSchema'); window.Store.ChatGetters = window.require('WAWebChatGetters'); + window.Store.PinnedMsgUtils = window.require('WAWebSendPinMessageAction'); window.Store.UploadUtils = window.require('WAWebUploadManager'); window.Store.WAWebStreamModel = window.require('WAWebStreamModel'); diff --git a/src/util/Injected/Utils.js b/src/util/Injected/Utils.js index 2a82fa4..8418277 100644 --- a/src/util/Injected/Utils.js +++ b/src/util/Injected/Utils.js @@ -1100,7 +1100,16 @@ exports.LoadUtils = () => { window.WWebJS.pinUnpinMsgAction = async (msgId, action, duration) => { const message = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0]; if (!message) return false; - const response = await window.Store.pinUnpinMsg(message, action, duration); + + if (typeof duration !== 'number') return false; + + const originalFunction = window.require('WAWebPinMsgConstants').getPinExpiryDuration; + window.require('WAWebPinMsgConstants').getPinExpiryDuration = () => duration; + + const response = await window.Store.PinnedMsgUtils.sendPinInChatMsg(message, action, duration); + + window.require('WAWebPinMsgConstants').getPinExpiryDuration = originalFunction; + return response.messageSendResult === 'OK'; };