From 5e94f2993e2dd081a94d204c1937347b76c96151 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Sun, 12 May 2024 16:35:46 +0200 Subject: [PATCH 1/5] fix getInviteCode for group (#3007) --- src/structures/GroupChat.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/structures/GroupChat.js b/src/structures/GroupChat.js index 12448238da..5cbd731c8a 100644 --- a/src/structures/GroupChat.js +++ b/src/structures/GroupChat.js @@ -372,7 +372,12 @@ class GroupChat extends Chat { async revokeInvite() { const codeRes = await this.client.pupPage.evaluate(chatId => { const chatWid = window.Store.WidFactory.createWid(chatId); - return window.Store.GroupInvite.resetGroupInviteCode(chatWid); + + if(window.WWebJS.compareWwebVersions(window.Debug.VERSION, '>', '2.3000.0')){ + return window.Store.GroupInvite.queryGroupInviteCode(chatWid, true); + } else { + return window.Store.GroupInvite.queryGroupInviteCode(chatWid); + } }, this.id._serialized); return codeRes.code; From 69c9afbbb6520035aaf8cee5581b77204db198d1 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Wed, 15 May 2024 06:46:57 +0200 Subject: [PATCH 2/5] move changes to proper getInviteCode method. --- src/structures/GroupChat.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/structures/GroupChat.js b/src/structures/GroupChat.js index 5cbd731c8a..b449e068e4 100644 --- a/src/structures/GroupChat.js +++ b/src/structures/GroupChat.js @@ -359,7 +359,11 @@ class GroupChat extends Chat { async getInviteCode() { const codeRes = await this.client.pupPage.evaluate(async chatId => { const chatWid = window.Store.WidFactory.createWid(chatId); - return window.Store.GroupInvite.queryGroupInviteCode(chatWid); + if(window.WWebJS.compareWwebVersions(window.Debug.VERSION, '>', '2.3000.0')){ + return window.Store.GroupInvite.queryGroupInviteCode(chatWid, true); + } else { + return window.Store.GroupInvite.queryGroupInviteCode(chatWid); + } }, this.id._serialized); return codeRes.code; @@ -372,12 +376,7 @@ class GroupChat extends Chat { async revokeInvite() { const codeRes = await this.client.pupPage.evaluate(chatId => { const chatWid = window.Store.WidFactory.createWid(chatId); - - if(window.WWebJS.compareWwebVersions(window.Debug.VERSION, '>', '2.3000.0')){ - return window.Store.GroupInvite.queryGroupInviteCode(chatWid, true); - } else { - return window.Store.GroupInvite.queryGroupInviteCode(chatWid); - } + return window.Store.GroupInvite.resetGroupInviteCode(chatWid); }, this.id._serialized); return codeRes.code; From a40b0e25bb65b49bdbe1b4f60b411d1aecf3f8e0 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Wed, 15 May 2024 06:47:17 +0200 Subject: [PATCH 3/5] style fix --- src/structures/GroupChat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/GroupChat.js b/src/structures/GroupChat.js index b449e068e4..d277166466 100644 --- a/src/structures/GroupChat.js +++ b/src/structures/GroupChat.js @@ -376,7 +376,7 @@ class GroupChat extends Chat { async revokeInvite() { const codeRes = await this.client.pupPage.evaluate(chatId => { const chatWid = window.Store.WidFactory.createWid(chatId); - return window.Store.GroupInvite.resetGroupInviteCode(chatWid); + return window.Store.GroupInvite.resetGroupInviteCode(chatWid); }, this.id._serialized); return codeRes.code; From c52f15d567edb22ba6b372f4609f4237634fb4e4 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Wed, 15 May 2024 20:42:01 +0300 Subject: [PATCH 4/5] refactor: add try-catch in a case the user is not a group admin --- src/structures/GroupChat.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/structures/GroupChat.js b/src/structures/GroupChat.js index d277166466..315ab81d0e 100644 --- a/src/structures/GroupChat.js +++ b/src/structures/GroupChat.js @@ -359,14 +359,18 @@ class GroupChat extends Chat { async getInviteCode() { const codeRes = await this.client.pupPage.evaluate(async chatId => { const chatWid = window.Store.WidFactory.createWid(chatId); - if(window.WWebJS.compareWwebVersions(window.Debug.VERSION, '>', '2.3000.0')){ - return window.Store.GroupInvite.queryGroupInviteCode(chatWid, true); - } else { - return window.Store.GroupInvite.queryGroupInviteCode(chatWid); + try { + return window.WWebJS.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.0') + ? window.Store.GroupInvite.queryGroupInviteCode(chatWid, true) + : window.Store.GroupInvite.queryGroupInviteCode(chatWid); + } + catch (err) { + if(err.name === 'ServerStatusCodeError') return undefined; + throw err; } }, this.id._serialized); - return codeRes.code; + return codeRes?.code; } /** From ed6076bf5c37e05448b22b51ace4a621a974aedf Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Wed, 15 May 2024 20:45:10 +0300 Subject: [PATCH 5/5] refactor: handle promise properly --- src/structures/GroupChat.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/structures/GroupChat.js b/src/structures/GroupChat.js index 315ab81d0e..2c165e5b6e 100644 --- a/src/structures/GroupChat.js +++ b/src/structures/GroupChat.js @@ -361,8 +361,8 @@ class GroupChat extends Chat { const chatWid = window.Store.WidFactory.createWid(chatId); try { return window.WWebJS.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.0') - ? window.Store.GroupInvite.queryGroupInviteCode(chatWid, true) - : window.Store.GroupInvite.queryGroupInviteCode(chatWid); + ? await window.Store.GroupInvite.queryGroupInviteCode(chatWid, true) + : await window.Store.GroupInvite.queryGroupInviteCode(chatWid); } catch (err) { if(err.name === 'ServerStatusCodeError') return undefined;