diff --git a/src/Client.js b/src/Client.js index 9d35edd..75cc723 100644 --- a/src/Client.js +++ b/src/Client.js @@ -809,8 +809,9 @@ class Client extends EventEmitter { return true; } const MAX_PIN_COUNT = 3; - if (window.Store.Chat.models.length > MAX_PIN_COUNT) { - let maxPinned = window.Store.Chat.models[MAX_PIN_COUNT - 1].pin; + const chatModels = window.Store.Chat.getModelsArray(); + if (chatModels.length > MAX_PIN_COUNT) { + let maxPinned = chatModels[MAX_PIN_COUNT - 1].pin; if (maxPinned) { return false; } @@ -1056,7 +1057,7 @@ class Client extends EventEmitter { async getChatsByLabelId(labelId) { const chatIds = await this.pupPage.evaluate(async (labelId) => { const label = window.Store.Label.get(labelId); - const labelItems = label.labelItemCollection.models; + const labelItems = label.labelItemCollection.getModelsArray(); return labelItems.reduce((result, item) => { if (item.parentType === 'Chat') { result.push(item.parentId); @@ -1074,7 +1075,7 @@ class Client extends EventEmitter { */ async getBlockedContacts() { const blockedContacts = await this.pupPage.evaluate(() => { - let chatIds = window.Store.Blocklist.models.map(a => a.id._serialized); + let chatIds = window.Store.Blocklist.getModelsArray().map(a => a.id._serialized); return Promise.all(chatIds.map(id => window.WWebJS.getContact(id))); }); diff --git a/src/structures/Chat.js b/src/structures/Chat.js index 20aa7dc..26363a8 100644 --- a/src/structures/Chat.js +++ b/src/structures/Chat.js @@ -179,11 +179,11 @@ class Chat extends Base { const msgFilter = m => !m.isNotification; // dont include notification messages const chat = window.Store.Chat.get(chatId); - let msgs = chat.msgs.models.filter(msgFilter); + let msgs = chat.msgs.getModelsArray().filter(msgFilter); if (searchOptions && searchOptions.limit > 0) { while (msgs.length < searchOptions.limit) { - const loadedMessages = await chat.loadEarlierMsgs(); + const loadedMessages = await window.Store.ConversationMsgs.loadEarlierMsgs(chat); if (!loadedMessages) break; msgs = [...loadedMessages.filter(msgFilter), ...msgs]; } diff --git a/src/util/Injected.js b/src/util/Injected.js index 384b658..19ffe68 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -48,6 +48,7 @@ exports.ExposeStore = (moduleRaidStr) => { window.Store.JoinInviteV4 = window.mR.findModule('sendJoinGroupViaInviteV4')[0]; window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups; window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0]; + window.Store.ConversationMsgs = window.mR.findModule('loadEarlierMsgs')[0]; window.Store.StickerTools = { ...window.mR.findModule('toWebpSticker')[0], ...window.mR.findModule('addWebpMetadata')[0] @@ -416,7 +417,7 @@ exports.LoadUtils = () => { }; window.WWebJS.getChats = async () => { - const chats = window.Store.Chat.models; + const chats = window.Store.Chat.getModelsArray(); const chatPromises = chats.map(chat => window.WWebJS.getChatModel(chat)); return await Promise.all(chatPromises); @@ -448,7 +449,7 @@ exports.LoadUtils = () => { }; window.WWebJS.getContacts = () => { - const contacts = window.Store.Contact.models; + const contacts = window.Store.Contact.getModelsArray(); return contacts.map(contact => window.WWebJS.getContactModel(contact)); }; @@ -541,7 +542,7 @@ exports.LoadUtils = () => { }; window.WWebJS.getLabels = () => { - const labels = window.Store.Label.models; + const labels = window.Store.Label.getModelsArray(); return labels.map(label => window.WWebJS.getLabelModel(label)); };