From 5276e30ac61935612c5da9ec9b4c05020961eadf Mon Sep 17 00:00:00 2001 From: Seow Zhen Jun <56989187+seowzhenjun0126@users.noreply.github.com> Date: Sat, 6 Sep 2025 03:19:15 +0800 Subject: [PATCH] fix: Lid is missing in chat table (#3703) * Use window.Store.FindOrCreateChat.findOrCreateLatestChat to get chat * refactor: change find to findOrCreateLatestChat * refactor: update 'injectToFunction' to support nested props in modules * fix: resolve 'Lid is missing in chat table' error --------- Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com> --- src/util/Injected/Store.js | 16 ++++++++++++---- src/util/Injected/Utils.js | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/util/Injected/Store.js b/src/util/Injected/Store.js index 848b08f..2f53421 100644 --- a/src/util/Injected/Store.js +++ b/src/util/Injected/Store.js @@ -102,6 +102,7 @@ exports.ExposeStore = () => { window.Store.PinnedMsgUtils = window.require('WAWebSendPinMessageAction'); window.Store.UploadUtils = window.require('WAWebUploadManager'); window.Store.WAWebStreamModel = window.require('WAWebStreamModel'); + window.Store.FindOrCreateChat = window.require('WAWebFindChatAction'); window.Store.Settings = { ...window.require('WAWebUserPrefsGeneral'), @@ -210,14 +211,21 @@ exports.ExposeStore = () => { * @param {Function} callback Modified function */ window.injectToFunction = (target, callback) => { - const module = window.require(target.module); - const originalFunction = module[target.function]; - const modifiedFunction = (...args) => callback(originalFunction, ...args); - module[target.function] = modifiedFunction; + let module = window.require(target.module); + + const path = target.function.split('.'); + const funcName = path.pop(); + for (const key of path) { + module = module[key]; + } + + const originalFunction = module[funcName]; + module[funcName] = (...args) => callback(originalFunction, ...args); }; window.injectToFunction({ module: 'WAWebBackendJobsCommon', function: 'mediaTypeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage ? null : func(...args); }); window.injectToFunction({ module: 'WAWebE2EProtoUtils', function: 'typeAttributeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage || proto.groupInviteMessage ? 'text' : func(...args); }); + window.injectToFunction({ module: 'WAWebLid1X1MigrationGating', function: 'Lid1X1MigrationUtils.isLidMigrated' }, () => false); }; diff --git a/src/util/Injected/Utils.js b/src/util/Injected/Utils.js index 4b80da9..9281b1a 100644 --- a/src/util/Injected/Utils.js +++ b/src/util/Injected/Utils.js @@ -539,7 +539,7 @@ exports.LoadUtils = () => { chat = null; } } else { - chat = window.Store.Chat.get(chatWid) || (await window.Store.Chat.find(chatWid)); + chat = window.Store.Chat.get(chatWid) || (await window.Store.FindOrCreateChat.findOrCreateLatestChat(chatWid))?.chat; } return getAsModel && chat