diff --git a/src/Client.js b/src/Client.js index ecc2ead..965223b 100644 --- a/src/Client.js +++ b/src/Client.js @@ -402,32 +402,14 @@ class Client extends EventEmitter { } const newMessage = await this.pupPage.evaluate(async (chatId, message, options, sendSeen) => { - let chat = window.Store.Chat.get(chatId); - let msg; - if (!chat) { // The chat is not available in the previously chatted list + const chatWid = window.Store.WidFactory.createWid(chatId); + const chat = await window.Store.Chat.find(chatWid); - let newChatId = await window.WWebJS.getNumberId(chatId); - if (newChatId) { - //get the topmost chat object and assign the new chatId to it . - //This is just a workaround.May cause problem if there are no chats at all. Need to dig in and emulate how whatsapp web does - let chat = window.Store.Chat.models[0]; - if (!chat) - throw 'Chat List empty! Need at least one open conversation with any of your contact'; - - let originalChatObjId = chat.id; - chat.id = newChatId; - - msg = await window.WWebJS.sendMessage(chat, message, options); - chat.id = originalChatObjId; //replace the chat with its original id - } - } - else { - if(sendSeen) { - window.WWebJS.sendSeen(chatId); - } - - msg = await window.WWebJS.sendMessage(chat, message, options, sendSeen); + if(sendSeen) { + window.WWebJS.sendSeen(chatId); } + + const msg = await window.WWebJS.sendMessage(chat, message, options, sendSeen); return msg.serialize(); }, chatId, content, internalOptions, sendSeen); diff --git a/src/util/Injected.js b/src/util/Injected.js index d2f4309..9acc8cd 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -25,6 +25,7 @@ exports.ExposeStore = (moduleRaidStr) => { window.Store.MediaTypes = window.mR.findModule('msgToMediaType')[0]; window.Store.UserConstructor = window.mR.findModule((module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null)[0].default; window.Store.Validators = window.mR.findModule('findLinks')[0]; + window.Store.WidFactory = window.mR.findModule('createWid')[0]; }; exports.LoadUtils = () => {