Fix opening deeplink to unknown bot (#2065)

This commit is contained in:
Alexander Zinchuk 2022-10-10 14:37:54 +02:00
parent ba622e8f00
commit 957819cff4
2 changed files with 19 additions and 7 deletions

View File

@ -893,7 +893,10 @@ function processResolvedPeer(result?: GramJs.contacts.TypeResolvedPeer) {
updateLocalDb(result);
return chat;
return {
chat,
user: buildApiUser(users[0]),
};
}
export function togglePreHistoryHidden({

View File

@ -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 }),
});