From 183a5fad5b96b6de71794a706ff1393933cc140f Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Mon, 16 May 2022 13:34:24 +0200 Subject: [PATCH] Web Bots: Some fixes (#1873) --- src/global/actions/api/bots.ts | 9 +++++---- src/global/actions/ui/misc.ts | 4 ++-- src/global/selectors/users.ts | 10 ++++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/global/actions/api/bots.ts b/src/global/actions/api/bots.ts index bc53131b6..f76fbca11 100644 --- a/src/global/actions/api/bots.ts +++ b/src/global/actions/api/bots.ts @@ -10,6 +10,7 @@ import { } from '../../../config'; import { callApi } from '../../../api/gramjs'; import { + selectBot, selectChat, selectChatBot, selectChatMessage, selectCurrentChat, selectCurrentMessageList, selectIsTrustedBot, selectReplyingToId, selectSendAs, selectUser, } from '../../selectors'; @@ -115,7 +116,7 @@ addActionHandler('clickBotInlineButton', (global, actions, payload) => { if (!chatId) { return; } - const bot = selectChatBot(global, chatId); + const bot = selectBot(global, chatId); if (!bot) { return; } @@ -139,7 +140,7 @@ addActionHandler('clickBotInlineButton', (global, actions, payload) => { if (!message.viaBotId && !message.senderId) { return; } - const bot = selectChatBot(global, message.viaBotId! || message.senderId!); + const bot = selectBot(global, message.viaBotId! || message.senderId!); if (!bot) { return; } @@ -459,12 +460,12 @@ addActionHandler('requestWebView', async (global, actions, payload) => { }); }); -addActionHandler('prolongWebView', (global, actions, payload) => { +addActionHandler('prolongWebView', async (global, actions, payload) => { const { bot, peer, isSilent, replyToMessageId, queryId, } = payload; - const result = callApi('prolongWebView', { + const result = await callApi('prolongWebView', { bot, peer, isSilent, diff --git a/src/global/actions/ui/misc.ts b/src/global/actions/ui/misc.ts index e0b0726f1..0c1233509 100644 --- a/src/global/actions/ui/misc.ts +++ b/src/global/actions/ui/misc.ts @@ -5,7 +5,7 @@ import { ApiError } from '../../../api/types'; import { IS_SINGLE_COLUMN_LAYOUT, IS_TABLET_COLUMN_LAYOUT } from '../../../util/environment'; import getReadableErrorText from '../../../util/getReadableErrorText'; import { - selectChatBot, selectChatMessage, selectCurrentMessageList, selectIsTrustedBot, + selectBot, selectChatMessage, selectCurrentMessageList, selectIsTrustedBot, } from '../../selectors'; import generateIdFor from '../../../util/generateIdFor'; @@ -298,7 +298,7 @@ addActionHandler('openGame', (global, actions, payload) => { if (!message) return; const botId = message.viaBotId || message.senderId; - const bot = botId && selectChatBot(global, botId); + const bot = botId && selectBot(global, botId); if (!bot) return; if (!selectIsTrustedBot(global, bot)) { diff --git a/src/global/selectors/users.ts b/src/global/selectors/users.ts index 79ece6aef..e3668878a 100644 --- a/src/global/selectors/users.ts +++ b/src/global/selectors/users.ts @@ -1,5 +1,6 @@ import { GlobalState } from '../types'; import { ApiChat, ApiUser, ApiUserStatus } from '../../api/types'; +import { isUserBot } from '../helpers'; export function selectUser(global: GlobalState, userId: string): ApiUser | undefined { return global.users.byId[userId]; @@ -33,3 +34,12 @@ export function selectUserByPhoneNumber(global: GlobalState, phoneNumber: string export function selectIsUserOrChatContact(global: GlobalState, userOrChat: ApiUser | ApiChat) { return global.contactList && global.contactList.userIds.includes(userOrChat.id); } + +export function selectBot(global: GlobalState, userId: string): ApiUser | undefined { + const user = selectUser(global, userId); + if (!user || !isUserBot(user)) { + return undefined; + } + + return user; +}