diff --git a/src/Client.js b/src/Client.js index e9966a2..52a277a 100644 --- a/src/Client.js +++ b/src/Client.js @@ -478,8 +478,8 @@ class Client extends EventEmitter { * @returns {Promise>} */ async getChats() { - let chats = await this.pupPage.evaluate(() => { - return window.WWebJS.getChats(); + let chats = await this.pupPage.evaluate(async () => { + return await window.WWebJS.getChats(); }); return chats.map(chat => ChatFactory.create(this, chat)); @@ -491,8 +491,8 @@ class Client extends EventEmitter { * @returns {Promise} */ async getChatById(chatId) { - let chat = await this.pupPage.evaluate(chatId => { - return window.WWebJS.getChat(chatId); + let chat = await this.pupPage.evaluate(async chatId => { + return await window.WWebJS.getChat(chatId); }, chatId); return ChatFactory.create(this, chat); diff --git a/src/util/Injected.js b/src/util/Injected.js index b473155..9a2ed1b 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -166,26 +166,29 @@ exports.LoadUtils = () => { return mediaData; }; - window.WWebJS.getChatModel = chat => { + window.WWebJS.getChatModel = async chat => { let res = chat.serialize(); res.isGroup = chat.isGroup; res.formattedTitle = chat.formattedTitle; if (chat.groupMetadata) { + await window.Store.GroupMetadata.update(chat.id._serialized); res.groupMetadata = chat.groupMetadata.serialize(); } return res; }; - window.WWebJS.getChat = chatId => { + window.WWebJS.getChat = async chatId => { const chat = window.Store.Chat.get(chatId); - return window.WWebJS.getChatModel(chat); + return await window.WWebJS.getChatModel(chat); }; - window.WWebJS.getChats = () => { + window.WWebJS.getChats = async () => { const chats = window.Store.Chat.models; - return chats.map(chat => window.WWebJS.getChatModel(chat)); + + const chatPromises = chats.map(chat => window.WWebJS.getChatModel(chat)); + return await Promise.all(chatPromises); }; window.WWebJS.getContactModel = contact => {