From 957819cff444d17a9cf6f891abf9f462b52fcc7b Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Mon, 10 Oct 2022 14:37:54 +0200 Subject: [PATCH] Fix opening deeplink to unknown bot (#2065) --- src/api/gramjs/methods/chats.ts | 5 ++++- src/global/actions/api/chats.ts | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/api/gramjs/methods/chats.ts b/src/api/gramjs/methods/chats.ts index ba80e408d..92fe0b351 100644 --- a/src/api/gramjs/methods/chats.ts +++ b/src/api/gramjs/methods/chats.ts @@ -893,7 +893,10 @@ function processResolvedPeer(result?: GramJs.contacts.TypeResolvedPeer) { updateLocalDb(result); - return chat; + return { + chat, + user: buildApiUser(users[0]), + }; } export function togglePreHistoryHidden({ diff --git a/src/global/actions/api/chats.ts b/src/global/actions/api/chats.ts index aa800c3ad..bb7a6ac63 100644 --- a/src/global/actions/api/chats.ts +++ b/src/global/actions/api/chats.ts @@ -24,7 +24,7 @@ import { addChats, addUsers, addUserStatuses, replaceThreadParam, updateChatListIds, updateChats, updateChat, updateChatListSecondaryInfo, updateManagementProgress, leaveChat, replaceUsers, replaceUserStatuses, - replaceChats, replaceChatListIds, addChatMembers, + replaceChats, replaceChatListIds, addChatMembers, updateUser, } from '../../reducers'; import { selectChat, selectUser, selectChatListType, selectIsChatPinned, @@ -1535,13 +1535,17 @@ export async function fetchChatByUsername( return localChat; } - const chat = await callApi('getChatByUsername', username); + const { chat, user } = await callApi('getChatByUsername', username) || {}; if (!chat) { return undefined; } setGlobal(updateChat(getGlobal(), chat.id, chat)); + if (user) { + setGlobal(updateUser(getGlobal(), user.id, user)); + } + return chat; } @@ -1552,13 +1556,17 @@ export async function fetchChatByPhoneNumber(phoneNumber: string) { return selectChat(global, localUser.id); } - const chat = await callApi('getChatByPhoneNumber', phoneNumber); + const { chat, user } = await callApi('getChatByPhoneNumber', phoneNumber) || {}; if (!chat) { return undefined; } setGlobal(updateChat(getGlobal(), chat.id, chat)); + if (user) { + setGlobal(updateUser(getGlobal(), user.id, user)); + } + return chat; } @@ -1566,6 +1574,7 @@ async function getAttachBotOrNotify(global: GlobalState, username: string) { const chat = await fetchChatByUsername(username); if (!chat) return undefined; + global = getGlobal(); const user = selectUser(global, chat.id); if (!user) return undefined; @@ -1591,12 +1600,12 @@ async function openChatByUsername( // Attach in the current chat if (startAttach && !attach) { - const user = await getAttachBotOrNotify(global, username); + const bot = await getAttachBotOrNotify(global, username); - if (!currentChat || !user) return; + if (!currentChat || !bot) return; actions.callAttachBot({ - botId: user.id, + botId: bot.id, chatId: currentChat.id, ...(typeof startAttach === 'string' && { startParam: startAttach }), });