From 0812ddecad5deb7d3ef5f26aef9c06052e56d07b Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sun, 18 Jun 2023 12:03:19 +0200 Subject: [PATCH] Bots: Hide "Delete for All" option (#3313) --- src/components/common/DeleteMessageModal.tsx | 4 +++- src/components/middle/HeaderActions.tsx | 4 ++-- src/components/middle/HeaderMenuContainer.tsx | 4 ++-- src/components/middle/MessageList.tsx | 4 ++-- src/components/middle/MiddleColumn.tsx | 4 ++-- src/components/middle/composer/Composer.tsx | 4 ++-- src/global/actions/api/bots.ts | 4 ++-- src/global/selectors/chats.ts | 13 +------------ src/global/selectors/messages.ts | 13 +++++++++---- 9 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/components/common/DeleteMessageModal.tsx b/src/components/common/DeleteMessageModal.tsx index 701569dec..b4ed5c601 100644 --- a/src/components/common/DeleteMessageModal.tsx +++ b/src/components/common/DeleteMessageModal.tsx @@ -7,6 +7,7 @@ import type { IAlbum } from '../../types'; import { selectAllowedMessageActions, + selectBot, selectChat, selectCurrentMessageList, selectUser, @@ -123,8 +124,9 @@ export default memo(withGlobal( const contactName = chat && isUserId(chat.id) ? getUserFirstOrLastName(selectUser(global, getPrivateChatUserId(chat)!)) : undefined; + const isChatWithBot = Boolean(selectBot(global, message.chatId)); - const willDeleteForCurrentUserOnly = chat && isChatBasicGroup(chat) && !canDeleteForAll; + const willDeleteForCurrentUserOnly = (chat && isChatBasicGroup(chat) && !canDeleteForAll) || isChatWithBot; const willDeleteForAll = chat && isChatSuperGroup(chat); return { diff --git a/src/components/middle/HeaderActions.tsx b/src/components/middle/HeaderActions.tsx index 960ee2faa..12eb0969f 100644 --- a/src/components/middle/HeaderActions.tsx +++ b/src/components/middle/HeaderActions.tsx @@ -13,9 +13,9 @@ import { isChatBasicGroup, isChatChannel, isChatSuperGroup, isUserId, } from '../../global/helpers'; import { + selectBot, selectCanAnimateInterface, selectChat, - selectChatBot, selectChatFullInfo, selectIsChatBotNotStarted, selectIsChatWithSelf, @@ -325,7 +325,7 @@ export default memo(withGlobal( }; } - const bot = selectChatBot(global, chatId); + const bot = selectBot(global, chatId); const chatFullInfo = !isUserId(chatId) ? selectChatFullInfo(global, chatId) : undefined; const isChatWithSelf = selectIsChatWithSelf(global, chatId); const isMainThread = messageListType === 'thread' && threadId === MAIN_THREAD_ID; diff --git a/src/components/middle/HeaderMenuContainer.tsx b/src/components/middle/HeaderMenuContainer.tsx index e32a83f63..73474c994 100644 --- a/src/components/middle/HeaderMenuContainer.tsx +++ b/src/components/middle/HeaderMenuContainer.tsx @@ -12,7 +12,7 @@ import { REPLIES_USER_ID } from '../../config'; import { disableScrolling, enableScrolling } from '../../util/scrollLock'; import { selectChat, - selectChatBot, + selectBot, selectChatFullInfo, selectCurrentMessageList, selectIsPremiumPurchaseBlocked, @@ -585,7 +585,7 @@ export default memo(withGlobal( const canReportChat = isMainThread && (isChatChannel(chat) || isChatGroup(chat) || (user && !user.isSelf)); const { chatId: currentChatId, threadId: currentThreadId } = selectCurrentMessageList(global) || {}; - const chatBot = chatId !== REPLIES_USER_ID ? selectChatBot(global, chatId) : undefined; + const chatBot = chatId !== REPLIES_USER_ID ? selectBot(global, chatId) : undefined; const userFullInfo = isPrivate ? selectUserFullInfo(global, chatId) : undefined; const chatFullInfo = !isPrivate ? selectChatFullInfo(global, chatId) : undefined; const canGiftPremium = Boolean( diff --git a/src/components/middle/MessageList.tsx b/src/components/middle/MessageList.tsx index 2e3fadae5..e0c44d00c 100644 --- a/src/components/middle/MessageList.tsx +++ b/src/components/middle/MessageList.tsx @@ -32,7 +32,7 @@ import { selectChat, selectIsInSelectMode, selectIsChatWithSelf, - selectChatBot, + selectBot, selectIsChatBotNotStarted, selectScrollOffset, selectThreadTopMessageId, @@ -715,7 +715,7 @@ export default memo(withGlobal( && !messageIds && !chat.unreadCount && !focusingId && lastMessage && !lastMessage.groupedId ); - const chatBot = selectChatBot(global, chatId)!; + const chatBot = selectBot(global, chatId)!; let isLoadingBotInfo = false; let botInfo; if (selectIsChatBotNotStarted(global, chatId)) { diff --git a/src/components/middle/MiddleColumn.tsx b/src/components/middle/MiddleColumn.tsx index 96a6312b1..0a976a1e1 100644 --- a/src/components/middle/MiddleColumn.tsx +++ b/src/components/middle/MiddleColumn.tsx @@ -32,7 +32,7 @@ import { DropAreaState } from './composer/DropArea'; import { selectCanAnimateInterface, selectChat, - selectChatBot, + selectBot, selectChatFullInfo, selectChatMessage, selectCurrentMessageList, @@ -691,7 +691,7 @@ export default memo(withGlobal( const { chatId, threadId, type: messageListType } = currentMessageList; const isPrivate = isUserId(chatId); const chat = selectChat(global, chatId); - const bot = selectChatBot(global, chatId); + const bot = selectBot(global, chatId); const pinnedIds = selectPinnedIds(global, chatId, threadId); const { chatId: audioChatId, messageId: audioMessageId } = audioPlayer; diff --git a/src/components/middle/composer/Composer.tsx b/src/components/middle/composer/Composer.tsx index 003fcdd60..3d562a8c1 100644 --- a/src/components/middle/composer/Composer.tsx +++ b/src/components/middle/composer/Composer.tsx @@ -42,7 +42,7 @@ import { MEMO_EMPTY_ARRAY } from '../../../util/memo'; import { selectCanScheduleUntilOnline, selectChat, - selectChatBot, + selectBot, selectChatFullInfo, selectChatMessage, selectChatType, @@ -1581,7 +1581,7 @@ export default memo(withGlobal( chatId, threadId, messageListType, isMobile, }): StateProps => { const chat = selectChat(global, chatId); - const chatBot = chatId !== REPLIES_USER_ID ? selectChatBot(global, chatId) : undefined; + const chatBot = chatId !== REPLIES_USER_ID ? selectBot(global, chatId) : undefined; const isChatWithBot = Boolean(chatBot); const isChatWithSelf = selectIsChatWithSelf(global, chatId); const isChatWithUser = isUserId(chatId); diff --git a/src/global/actions/api/bots.ts b/src/global/actions/api/bots.ts index 2bd474483..fa499926c 100644 --- a/src/global/actions/api/bots.ts +++ b/src/global/actions/api/bots.ts @@ -12,7 +12,7 @@ import type { InlineBotSettings } from '../../../types'; import { MAIN_THREAD_ID } from '../../../api/types'; import { callApi } from '../../../api/gramjs'; import { - selectChat, selectChatBot, selectChatMessage, selectCurrentChat, selectCurrentMessageList, selectTabState, + selectChat, selectChatMessage, selectCurrentChat, selectCurrentMessageList, selectTabState, selectBot, selectIsTrustedBot, selectReplyingToId, selectSendAs, selectUser, selectThreadTopMessageId, selectUserFullInfo, } from '../../selectors'; import { addChats, addUsers, removeBlockedContact } from '../../reducers'; @@ -196,7 +196,7 @@ addActionHandler('restartBot', async (global, actions, payload): Promise = const { chatId, tabId = getCurrentTabId() } = payload; const { currentUserId } = global; const chat = selectCurrentChat(global, tabId); - const bot = currentUserId && selectChatBot(global, chatId); + const bot = currentUserId && selectBot(global, chatId); if (!currentUserId || !chat || !bot) { return; } diff --git a/src/global/selectors/chats.ts b/src/global/selectors/chats.ts index 5b9dc969b..0cf581e9f 100644 --- a/src/global/selectors/chats.ts +++ b/src/global/selectors/chats.ts @@ -72,17 +72,6 @@ export function selectChatOnlineCount(global: T, chat: Ap }, 0); } -export function selectChatBot(global: T, chatId: string) { - const chat = selectChat(global, chatId); - const userId = chat && getPrivateChatUserId(chat); - const user = userId && selectUser(global, userId); - if (!user || !isUserBot(user)) { - return undefined; - } - - return user; -} - export function selectIsTrustedBot(global: T, botId: string) { const bot = selectUser(global, botId); return bot && (bot.isVerified || global.trustedBotIds.includes(botId)); @@ -111,7 +100,7 @@ export function selectChatType(global: T, chatId: string) export function selectIsChatBotNotStarted(global: T, chatId: string) { const chat = selectChat(global, chatId); - const bot = selectChatBot(global, chatId); + const bot = selectBot(global, chatId); if (!chat || !bot) { return false; } diff --git a/src/global/selectors/messages.ts b/src/global/selectors/messages.ts index 22d890c91..2e0e398f6 100644 --- a/src/global/selectors/messages.ts +++ b/src/global/selectors/messages.ts @@ -15,10 +15,14 @@ import { GENERAL_TOPIC_ID, REPLIES_USER_ID, SERVICE_NOTIFICATIONS_USER_ID, } from '../../config'; import { - selectChat, selectChatBot, selectChatFullInfo, selectIsChatWithSelf, + selectChat, selectChatFullInfo, selectIsChatWithSelf, } from './chats'; import { - selectIsCurrentUserPremium, selectIsUserOrChatContact, selectUser, selectUserStatus, + selectBot, + selectIsCurrentUserPremium, + selectIsUserOrChatContact, + selectUser, + selectUserStatus, } from './users'; import { getCanPostInChat, @@ -532,6 +536,7 @@ export function selectAllowedMessageActions(global: T, me const isBasicGroup = isChatBasicGroup(chat); const isSuperGroup = isChatSuperGroup(chat); const isChannel = isChatChannel(chat); + const isBotChat = Boolean(selectBot(global, chat.id)); const isLocal = isMessageLocal(message); const isServiceNotification = isServiceNotificationMessage(message); const isOwn = isOwnMessage(message); @@ -588,7 +593,7 @@ export function selectAllowedMessageActions(global: T, me const canReport = !isPrivate && !isOwn; const canDeleteForAll = canDelete && !chat.isForbidden && ( - (isPrivate && !isChatWithSelf) + (isPrivate && !isChatWithSelf && !isBotChat) || (isBasicGroup && ( isOwn || getHasAdminRight(chat, 'deleteMessages') || chat.isCreator )) @@ -1224,7 +1229,7 @@ export function selectShouldSchedule( export function selectCanScheduleUntilOnline(global: T, id: string) { const isChatWithSelf = selectIsChatWithSelf(global, id); - const chatBot = id === REPLIES_USER_ID && selectChatBot(global, id); + const chatBot = id === REPLIES_USER_ID && selectBot(global, id); return Boolean( !isChatWithSelf && !chatBot && isUserId(id) && selectUserStatus(global, id)?.wasOnline, );