fix: correctly get models and fetchMessages in WhatsApp Web v2.2220.8

* Fix models is undefined

* Feat models is undefined

* Feat models is undefined

* Fix loadEarlierMsgs

* use `getModelsArray()` to get models

* fix: correctly loadEarlierMsgs with ConversationMsgs module

Co-authored-by: Pedro Lopez <pedroslopez@me.com>
This commit is contained in:
Shir Serlui
2022-06-10 06:41:25 +03:00
committed by GitHub
parent b16e1cdf83
commit ebc56bc280
3 changed files with 11 additions and 9 deletions

View File

@@ -809,8 +809,9 @@ class Client extends EventEmitter {
return true; return true;
} }
const MAX_PIN_COUNT = 3; const MAX_PIN_COUNT = 3;
if (window.Store.Chat.models.length > MAX_PIN_COUNT) { const chatModels = window.Store.Chat.getModelsArray();
let maxPinned = window.Store.Chat.models[MAX_PIN_COUNT - 1].pin; if (chatModels.length > MAX_PIN_COUNT) {
let maxPinned = chatModels[MAX_PIN_COUNT - 1].pin;
if (maxPinned) { if (maxPinned) {
return false; return false;
} }
@@ -1056,7 +1057,7 @@ class Client extends EventEmitter {
async getChatsByLabelId(labelId) { async getChatsByLabelId(labelId) {
const chatIds = await this.pupPage.evaluate(async (labelId) => { const chatIds = await this.pupPage.evaluate(async (labelId) => {
const label = window.Store.Label.get(labelId); const label = window.Store.Label.get(labelId);
const labelItems = label.labelItemCollection.models; const labelItems = label.labelItemCollection.getModelsArray();
return labelItems.reduce((result, item) => { return labelItems.reduce((result, item) => {
if (item.parentType === 'Chat') { if (item.parentType === 'Chat') {
result.push(item.parentId); result.push(item.parentId);
@@ -1074,7 +1075,7 @@ class Client extends EventEmitter {
*/ */
async getBlockedContacts() { async getBlockedContacts() {
const blockedContacts = await this.pupPage.evaluate(() => { 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))); return Promise.all(chatIds.map(id => window.WWebJS.getContact(id)));
}); });

View File

@@ -179,11 +179,11 @@ class Chat extends Base {
const msgFilter = m => !m.isNotification; // dont include notification messages const msgFilter = m => !m.isNotification; // dont include notification messages
const chat = window.Store.Chat.get(chatId); 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) { if (searchOptions && searchOptions.limit > 0) {
while (msgs.length < searchOptions.limit) { while (msgs.length < searchOptions.limit) {
const loadedMessages = await chat.loadEarlierMsgs(); const loadedMessages = await window.Store.ConversationMsgs.loadEarlierMsgs(chat);
if (!loadedMessages) break; if (!loadedMessages) break;
msgs = [...loadedMessages.filter(msgFilter), ...msgs]; msgs = [...loadedMessages.filter(msgFilter), ...msgs];
} }

View File

@@ -48,6 +48,7 @@ exports.ExposeStore = (moduleRaidStr) => {
window.Store.JoinInviteV4 = window.mR.findModule('sendJoinGroupViaInviteV4')[0]; window.Store.JoinInviteV4 = window.mR.findModule('sendJoinGroupViaInviteV4')[0];
window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups; window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups;
window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0]; window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0];
window.Store.ConversationMsgs = window.mR.findModule('loadEarlierMsgs')[0];
window.Store.StickerTools = { window.Store.StickerTools = {
...window.mR.findModule('toWebpSticker')[0], ...window.mR.findModule('toWebpSticker')[0],
...window.mR.findModule('addWebpMetadata')[0] ...window.mR.findModule('addWebpMetadata')[0]
@@ -416,7 +417,7 @@ exports.LoadUtils = () => {
}; };
window.WWebJS.getChats = async () => { 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)); const chatPromises = chats.map(chat => window.WWebJS.getChatModel(chat));
return await Promise.all(chatPromises); return await Promise.all(chatPromises);
@@ -448,7 +449,7 @@ exports.LoadUtils = () => {
}; };
window.WWebJS.getContacts = () => { window.WWebJS.getContacts = () => {
const contacts = window.Store.Contact.models; const contacts = window.Store.Contact.getModelsArray();
return contacts.map(contact => window.WWebJS.getContactModel(contact)); return contacts.map(contact => window.WWebJS.getContactModel(contact));
}; };
@@ -541,7 +542,7 @@ exports.LoadUtils = () => {
}; };
window.WWebJS.getLabels = () => { window.WWebJS.getLabels = () => {
const labels = window.Store.Label.models; const labels = window.Store.Label.getModelsArray();
return labels.map(label => window.WWebJS.getLabelModel(label)); return labels.map(label => window.WWebJS.getLabelModel(label));
}; };