Web Bots: Some fixes (#1873)

This commit is contained in:
Alexander Zinchuk 2022-05-16 13:34:24 +02:00
parent ccaa82bec1
commit 183a5fad5b
3 changed files with 17 additions and 6 deletions

View File

@ -10,6 +10,7 @@ import {
} from '../../../config'; } from '../../../config';
import { callApi } from '../../../api/gramjs'; import { callApi } from '../../../api/gramjs';
import { import {
selectBot,
selectChat, selectChatBot, selectChatMessage, selectCurrentChat, selectCurrentMessageList, selectChat, selectChatBot, selectChatMessage, selectCurrentChat, selectCurrentMessageList,
selectIsTrustedBot, selectReplyingToId, selectSendAs, selectUser, selectIsTrustedBot, selectReplyingToId, selectSendAs, selectUser,
} from '../../selectors'; } from '../../selectors';
@ -115,7 +116,7 @@ addActionHandler('clickBotInlineButton', (global, actions, payload) => {
if (!chatId) { if (!chatId) {
return; return;
} }
const bot = selectChatBot(global, chatId); const bot = selectBot(global, chatId);
if (!bot) { if (!bot) {
return; return;
} }
@ -139,7 +140,7 @@ addActionHandler('clickBotInlineButton', (global, actions, payload) => {
if (!message.viaBotId && !message.senderId) { if (!message.viaBotId && !message.senderId) {
return; return;
} }
const bot = selectChatBot(global, message.viaBotId! || message.senderId!); const bot = selectBot(global, message.viaBotId! || message.senderId!);
if (!bot) { if (!bot) {
return; return;
} }
@ -459,12 +460,12 @@ addActionHandler('requestWebView', async (global, actions, payload) => {
}); });
}); });
addActionHandler('prolongWebView', (global, actions, payload) => { addActionHandler('prolongWebView', async (global, actions, payload) => {
const { const {
bot, peer, isSilent, replyToMessageId, queryId, bot, peer, isSilent, replyToMessageId, queryId,
} = payload; } = payload;
const result = callApi('prolongWebView', { const result = await callApi('prolongWebView', {
bot, bot,
peer, peer,
isSilent, isSilent,

View File

@ -5,7 +5,7 @@ import { ApiError } from '../../../api/types';
import { IS_SINGLE_COLUMN_LAYOUT, IS_TABLET_COLUMN_LAYOUT } from '../../../util/environment'; import { IS_SINGLE_COLUMN_LAYOUT, IS_TABLET_COLUMN_LAYOUT } from '../../../util/environment';
import getReadableErrorText from '../../../util/getReadableErrorText'; import getReadableErrorText from '../../../util/getReadableErrorText';
import { import {
selectChatBot, selectChatMessage, selectCurrentMessageList, selectIsTrustedBot, selectBot, selectChatMessage, selectCurrentMessageList, selectIsTrustedBot,
} from '../../selectors'; } from '../../selectors';
import generateIdFor from '../../../util/generateIdFor'; import generateIdFor from '../../../util/generateIdFor';
@ -298,7 +298,7 @@ addActionHandler('openGame', (global, actions, payload) => {
if (!message) return; if (!message) return;
const botId = message.viaBotId || message.senderId; const botId = message.viaBotId || message.senderId;
const bot = botId && selectChatBot(global, botId); const bot = botId && selectBot(global, botId);
if (!bot) return; if (!bot) return;
if (!selectIsTrustedBot(global, bot)) { if (!selectIsTrustedBot(global, bot)) {

View File

@ -1,5 +1,6 @@
import { GlobalState } from '../types'; import { GlobalState } from '../types';
import { ApiChat, ApiUser, ApiUserStatus } from '../../api/types'; import { ApiChat, ApiUser, ApiUserStatus } from '../../api/types';
import { isUserBot } from '../helpers';
export function selectUser(global: GlobalState, userId: string): ApiUser | undefined { export function selectUser(global: GlobalState, userId: string): ApiUser | undefined {
return global.users.byId[userId]; return global.users.byId[userId];
@ -33,3 +34,12 @@ export function selectUserByPhoneNumber(global: GlobalState, phoneNumber: string
export function selectIsUserOrChatContact(global: GlobalState, userOrChat: ApiUser | ApiChat) { export function selectIsUserOrChatContact(global: GlobalState, userOrChat: ApiUser | ApiChat) {
return global.contactList && global.contactList.userIds.includes(userOrChat.id); 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;
}