From 93991e5cb101bd1d6bc7d84383c8db4b9c37d9a9 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 29 Jun 2021 15:48:24 +0300 Subject: [PATCH] Message List: Fix opening some private channels --- src/api/gramjs/methods/chats.ts | 27 +++++++++++++++++++++++---- src/modules/actions/api/chats.ts | 7 +++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/api/gramjs/methods/chats.ts b/src/api/gramjs/methods/chats.ts index 6e713ec6a..c5d8b46e1 100644 --- a/src/api/gramjs/methods/chats.ts +++ b/src/api/gramjs/methods/chats.ts @@ -904,13 +904,32 @@ export async function openChatByInvite(hash: string) { return undefined; } - if (result instanceof GramJs.ChatInvite) { - await invokeRequest(new GramJs.messages.ImportChatInvite({ hash }), true); + let chat: ApiChat | undefined; - return undefined; + if (result instanceof GramJs.ChatInvite) { + const updates = await invokeRequest(new GramJs.messages.ImportChatInvite({ hash }), true); + if (!(updates instanceof GramJs.Updates) || !updates.chats.length) { + return undefined; + } + + chat = buildApiChatFromPreview(updates.chats[0]); } else { - return buildApiChatFromPreview(result.chat); + chat = buildApiChatFromPreview(result.chat); + + if (chat) { + onUpdate({ + '@type': 'updateChat', + id: chat.id, + chat, + }); + } } + + if (!chat) { + return undefined; + } + + return { chatId: chat.id }; } function preparePeers( diff --git a/src/modules/actions/api/chats.ts b/src/modules/actions/api/chats.ts index 9e8ac84e5..57b035662 100644 --- a/src/modules/actions/api/chats.ts +++ b/src/modules/actions/api/chats.ts @@ -386,13 +386,12 @@ addReducer('openTelegramLink', (global, actions, payload) => { const hash = match[1]; (async () => { - const chat = await callApi('openChatByInvite', hash); - - if (!chat) { + const result = await callApi('openChatByInvite', hash); + if (!result) { return; } - actions.openChat({ id: chat.id }); + actions.openChat({ id: result.chatId }); })(); } else { match = RE_TME_LINK.exec(url)!;