From 9b3d987711883dca38a4d0af276a4b5ff7124947 Mon Sep 17 00:00:00 2001 From: RendyCraft047 <75566525+RC047@users.noreply.github.com> Date: Wed, 8 Oct 2025 02:11:37 +0700 Subject: [PATCH] fix: getPinnedMessages() (#3797) * fix duplicate store * fix: handle async calls properly * fix: filter out only pinned messages Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com> --------- Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com> Co-authored-by: BenyFilho <168232825+BenyFilho@users.noreply.github.com> --- src/Client.js | 11 +++++++++-- src/util/Injected/Store.js | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Client.js b/src/Client.js index 8f02a78..4ae134e 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1225,11 +1225,18 @@ class Client extends EventEmitter { const msgs = await window.Store.PinnedMsgUtils.getTable().equals(['chatId'], chatWid.toString()); - const pinnedMsgs = msgs.map((msg) => window.Store.Msg.get(msg.parentMsgKey)); + const pinnedMsgs = ( + await Promise.all( + msgs.filter(msg => msg.pinType == 1).map(async (msg) => { + const res = await window.Store.Msg.getMessagesById([msg.parentMsgKey]); + return res?.messages?.[0]; + }) + ) + ).filter(Boolean); return !pinnedMsgs.length ? [] - : pinnedMsgs.map((msg) => window.WWebJS.getMessageModel(msg)); + : await Promise.all(pinnedMsgs.map((msg) => window.WWebJS.getMessageModel(msg))); }, chatId); return pinnedMsgs.map((msg) => new Message(this, msg)); diff --git a/src/util/Injected/Store.js b/src/util/Injected/Store.js index ceb5941..73217b5 100644 --- a/src/util/Injected/Store.js +++ b/src/util/Injected/Store.js @@ -97,9 +97,7 @@ exports.ExposeStore = () => { window.Store.HistorySync = window.require('WAWebSendNonMessageDataRequest'); window.Store.AddonReactionTable = window.require('WAWebAddonReactionTableMode').reactionTableMode; window.Store.AddonPollVoteTable = window.require('WAWebAddonPollVoteTableMode').pollVoteTableMode; - 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'); window.Store.FindOrCreateChat = window.require('WAWebFindChatAction'); @@ -118,6 +116,10 @@ exports.ExposeStore = () => { window.Store.ForwardUtils = { ...window.require('WAWebChatForwardMessage') }; + window.Store.PinnedMsgUtils = { + ...window.require('WAWebPinInChatSchema'), + ...window.require('WAWebSendPinMessageAction') + }; window.Store.ScheduledEventMsgUtils = { ...window.require('WAWebGenerateEventCallLink'), ...window.require('WAWebSendEventEditMsgAction'),