From e717915f94217da3ea23c5b0eb54b3f4786e47af Mon Sep 17 00:00:00 2001 From: Pedro Lopez Date: Sun, 2 Feb 2020 20:37:51 -0400 Subject: [PATCH] fix: don't get chat after accepting invite This will now only return the chatId, since getting the chat at this point is unreliable. --- example.js | 5 ++--- src/Client.js | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/example.js b/example.js index a7dfae1..d5f0e00 100644 --- a/example.js +++ b/example.js @@ -66,10 +66,9 @@ client.on('message', async msg => { } } else if(msg.body.startsWith('!join ')) { const inviteCode = msg.body.split(' ')[1]; - try { - const chat = await client.acceptInvite(inviteCode); - msg.reply(`Joined *${chat.name}*!`); + await client.acceptInvite(inviteCode); + msg.reply('Joined the group!'); } catch(e) { msg.reply('That invite code seems to be invalid.'); } diff --git a/src/Client.js b/src/Client.js index 7eb2770..528d0e0 100644 --- a/src/Client.js +++ b/src/Client.js @@ -239,12 +239,11 @@ class Client extends EventEmitter { * @param {string} inviteCode */ async acceptInvite(inviteCode) { - const chat = await this.pupPage.evaluate(async inviteCode => { - const chatId = await window.Store.Invite.sendJoinGroupViaInvite(inviteCode); - return window.WWebJS.getChat(chatId._serialized); + const chatId = await this.pupPage.evaluate(async inviteCode => { + return await window.Store.Invite.sendJoinGroupViaInvite(inviteCode); }, inviteCode); - return ChatFactory.create(this.client, chat); + return chatId._serialized; } }