Bots: Hide "Delete for All" option (#3313)

This commit is contained in:
Alexander Zinchuk 2023-06-18 12:03:19 +02:00
parent 0681ad44e2
commit 0812ddecad
9 changed files with 25 additions and 29 deletions

View File

@ -7,6 +7,7 @@ import type { IAlbum } from '../../types';
import { import {
selectAllowedMessageActions, selectAllowedMessageActions,
selectBot,
selectChat, selectChat,
selectCurrentMessageList, selectCurrentMessageList,
selectUser, selectUser,
@ -123,8 +124,9 @@ export default memo(withGlobal<OwnProps>(
const contactName = chat && isUserId(chat.id) const contactName = chat && isUserId(chat.id)
? getUserFirstOrLastName(selectUser(global, getPrivateChatUserId(chat)!)) ? getUserFirstOrLastName(selectUser(global, getPrivateChatUserId(chat)!))
: undefined; : 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); const willDeleteForAll = chat && isChatSuperGroup(chat);
return { return {

View File

@ -13,9 +13,9 @@ import {
isChatBasicGroup, isChatChannel, isChatSuperGroup, isUserId, isChatBasicGroup, isChatChannel, isChatSuperGroup, isUserId,
} from '../../global/helpers'; } from '../../global/helpers';
import { import {
selectBot,
selectCanAnimateInterface, selectCanAnimateInterface,
selectChat, selectChat,
selectChatBot,
selectChatFullInfo, selectChatFullInfo,
selectIsChatBotNotStarted, selectIsChatBotNotStarted,
selectIsChatWithSelf, selectIsChatWithSelf,
@ -325,7 +325,7 @@ export default memo(withGlobal<OwnProps>(
}; };
} }
const bot = selectChatBot(global, chatId); const bot = selectBot(global, chatId);
const chatFullInfo = !isUserId(chatId) ? selectChatFullInfo(global, chatId) : undefined; const chatFullInfo = !isUserId(chatId) ? selectChatFullInfo(global, chatId) : undefined;
const isChatWithSelf = selectIsChatWithSelf(global, chatId); const isChatWithSelf = selectIsChatWithSelf(global, chatId);
const isMainThread = messageListType === 'thread' && threadId === MAIN_THREAD_ID; const isMainThread = messageListType === 'thread' && threadId === MAIN_THREAD_ID;

View File

@ -12,7 +12,7 @@ import { REPLIES_USER_ID } from '../../config';
import { disableScrolling, enableScrolling } from '../../util/scrollLock'; import { disableScrolling, enableScrolling } from '../../util/scrollLock';
import { import {
selectChat, selectChat,
selectChatBot, selectBot,
selectChatFullInfo, selectChatFullInfo,
selectCurrentMessageList, selectCurrentMessageList,
selectIsPremiumPurchaseBlocked, selectIsPremiumPurchaseBlocked,
@ -585,7 +585,7 @@ export default memo(withGlobal<OwnProps>(
const canReportChat = isMainThread && (isChatChannel(chat) || isChatGroup(chat) || (user && !user.isSelf)); const canReportChat = isMainThread && (isChatChannel(chat) || isChatGroup(chat) || (user && !user.isSelf));
const { chatId: currentChatId, threadId: currentThreadId } = selectCurrentMessageList(global) || {}; 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 userFullInfo = isPrivate ? selectUserFullInfo(global, chatId) : undefined;
const chatFullInfo = !isPrivate ? selectChatFullInfo(global, chatId) : undefined; const chatFullInfo = !isPrivate ? selectChatFullInfo(global, chatId) : undefined;
const canGiftPremium = Boolean( const canGiftPremium = Boolean(

View File

@ -32,7 +32,7 @@ import {
selectChat, selectChat,
selectIsInSelectMode, selectIsInSelectMode,
selectIsChatWithSelf, selectIsChatWithSelf,
selectChatBot, selectBot,
selectIsChatBotNotStarted, selectIsChatBotNotStarted,
selectScrollOffset, selectScrollOffset,
selectThreadTopMessageId, selectThreadTopMessageId,
@ -715,7 +715,7 @@ export default memo(withGlobal<OwnProps>(
&& !messageIds && !chat.unreadCount && !focusingId && lastMessage && !lastMessage.groupedId && !messageIds && !chat.unreadCount && !focusingId && lastMessage && !lastMessage.groupedId
); );
const chatBot = selectChatBot(global, chatId)!; const chatBot = selectBot(global, chatId)!;
let isLoadingBotInfo = false; let isLoadingBotInfo = false;
let botInfo; let botInfo;
if (selectIsChatBotNotStarted(global, chatId)) { if (selectIsChatBotNotStarted(global, chatId)) {

View File

@ -32,7 +32,7 @@ import { DropAreaState } from './composer/DropArea';
import { import {
selectCanAnimateInterface, selectCanAnimateInterface,
selectChat, selectChat,
selectChatBot, selectBot,
selectChatFullInfo, selectChatFullInfo,
selectChatMessage, selectChatMessage,
selectCurrentMessageList, selectCurrentMessageList,
@ -691,7 +691,7 @@ export default memo(withGlobal<OwnProps>(
const { chatId, threadId, type: messageListType } = currentMessageList; const { chatId, threadId, type: messageListType } = currentMessageList;
const isPrivate = isUserId(chatId); const isPrivate = isUserId(chatId);
const chat = selectChat(global, chatId); const chat = selectChat(global, chatId);
const bot = selectChatBot(global, chatId); const bot = selectBot(global, chatId);
const pinnedIds = selectPinnedIds(global, chatId, threadId); const pinnedIds = selectPinnedIds(global, chatId, threadId);
const { chatId: audioChatId, messageId: audioMessageId } = audioPlayer; const { chatId: audioChatId, messageId: audioMessageId } = audioPlayer;

View File

@ -42,7 +42,7 @@ import { MEMO_EMPTY_ARRAY } from '../../../util/memo';
import { import {
selectCanScheduleUntilOnline, selectCanScheduleUntilOnline,
selectChat, selectChat,
selectChatBot, selectBot,
selectChatFullInfo, selectChatFullInfo,
selectChatMessage, selectChatMessage,
selectChatType, selectChatType,
@ -1581,7 +1581,7 @@ export default memo(withGlobal<OwnProps>(
chatId, threadId, messageListType, isMobile, chatId, threadId, messageListType, isMobile,
}): StateProps => { }): StateProps => {
const chat = selectChat(global, chatId); 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 isChatWithBot = Boolean(chatBot);
const isChatWithSelf = selectIsChatWithSelf(global, chatId); const isChatWithSelf = selectIsChatWithSelf(global, chatId);
const isChatWithUser = isUserId(chatId); const isChatWithUser = isUserId(chatId);

View File

@ -12,7 +12,7 @@ import type { InlineBotSettings } from '../../../types';
import { MAIN_THREAD_ID } from '../../../api/types'; import { MAIN_THREAD_ID } from '../../../api/types';
import { callApi } from '../../../api/gramjs'; import { callApi } from '../../../api/gramjs';
import { import {
selectChat, selectChatBot, selectChatMessage, selectCurrentChat, selectCurrentMessageList, selectTabState, selectChat, selectChatMessage, selectCurrentChat, selectCurrentMessageList, selectTabState, selectBot,
selectIsTrustedBot, selectReplyingToId, selectSendAs, selectUser, selectThreadTopMessageId, selectUserFullInfo, selectIsTrustedBot, selectReplyingToId, selectSendAs, selectUser, selectThreadTopMessageId, selectUserFullInfo,
} from '../../selectors'; } from '../../selectors';
import { addChats, addUsers, removeBlockedContact } from '../../reducers'; import { addChats, addUsers, removeBlockedContact } from '../../reducers';
@ -196,7 +196,7 @@ addActionHandler('restartBot', async (global, actions, payload): Promise<void> =
const { chatId, tabId = getCurrentTabId() } = payload; const { chatId, tabId = getCurrentTabId() } = payload;
const { currentUserId } = global; const { currentUserId } = global;
const chat = selectCurrentChat(global, tabId); const chat = selectCurrentChat(global, tabId);
const bot = currentUserId && selectChatBot(global, chatId); const bot = currentUserId && selectBot(global, chatId);
if (!currentUserId || !chat || !bot) { if (!currentUserId || !chat || !bot) {
return; return;
} }

View File

@ -72,17 +72,6 @@ export function selectChatOnlineCount<T extends GlobalState>(global: T, chat: Ap
}, 0); }, 0);
} }
export function selectChatBot<T extends GlobalState>(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<T extends GlobalState>(global: T, botId: string) { export function selectIsTrustedBot<T extends GlobalState>(global: T, botId: string) {
const bot = selectUser(global, botId); const bot = selectUser(global, botId);
return bot && (bot.isVerified || global.trustedBotIds.includes(botId)); return bot && (bot.isVerified || global.trustedBotIds.includes(botId));
@ -111,7 +100,7 @@ export function selectChatType<T extends GlobalState>(global: T, chatId: string)
export function selectIsChatBotNotStarted<T extends GlobalState>(global: T, chatId: string) { export function selectIsChatBotNotStarted<T extends GlobalState>(global: T, chatId: string) {
const chat = selectChat(global, chatId); const chat = selectChat(global, chatId);
const bot = selectChatBot(global, chatId); const bot = selectBot(global, chatId);
if (!chat || !bot) { if (!chat || !bot) {
return false; return false;
} }

View File

@ -15,10 +15,14 @@ import {
GENERAL_TOPIC_ID, REPLIES_USER_ID, SERVICE_NOTIFICATIONS_USER_ID, GENERAL_TOPIC_ID, REPLIES_USER_ID, SERVICE_NOTIFICATIONS_USER_ID,
} from '../../config'; } from '../../config';
import { import {
selectChat, selectChatBot, selectChatFullInfo, selectIsChatWithSelf, selectChat, selectChatFullInfo, selectIsChatWithSelf,
} from './chats'; } from './chats';
import { import {
selectIsCurrentUserPremium, selectIsUserOrChatContact, selectUser, selectUserStatus, selectBot,
selectIsCurrentUserPremium,
selectIsUserOrChatContact,
selectUser,
selectUserStatus,
} from './users'; } from './users';
import { import {
getCanPostInChat, getCanPostInChat,
@ -532,6 +536,7 @@ export function selectAllowedMessageActions<T extends GlobalState>(global: T, me
const isBasicGroup = isChatBasicGroup(chat); const isBasicGroup = isChatBasicGroup(chat);
const isSuperGroup = isChatSuperGroup(chat); const isSuperGroup = isChatSuperGroup(chat);
const isChannel = isChatChannel(chat); const isChannel = isChatChannel(chat);
const isBotChat = Boolean(selectBot(global, chat.id));
const isLocal = isMessageLocal(message); const isLocal = isMessageLocal(message);
const isServiceNotification = isServiceNotificationMessage(message); const isServiceNotification = isServiceNotificationMessage(message);
const isOwn = isOwnMessage(message); const isOwn = isOwnMessage(message);
@ -588,7 +593,7 @@ export function selectAllowedMessageActions<T extends GlobalState>(global: T, me
const canReport = !isPrivate && !isOwn; const canReport = !isPrivate && !isOwn;
const canDeleteForAll = canDelete && !chat.isForbidden && ( const canDeleteForAll = canDelete && !chat.isForbidden && (
(isPrivate && !isChatWithSelf) (isPrivate && !isChatWithSelf && !isBotChat)
|| (isBasicGroup && ( || (isBasicGroup && (
isOwn || getHasAdminRight(chat, 'deleteMessages') || chat.isCreator isOwn || getHasAdminRight(chat, 'deleteMessages') || chat.isCreator
)) ))
@ -1224,7 +1229,7 @@ export function selectShouldSchedule<T extends GlobalState>(
export function selectCanScheduleUntilOnline<T extends GlobalState>(global: T, id: string) { export function selectCanScheduleUntilOnline<T extends GlobalState>(global: T, id: string) {
const isChatWithSelf = selectIsChatWithSelf(global, id); 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( return Boolean(
!isChatWithSelf && !chatBot && isUserId(id) && selectUserStatus(global, id)?.wasOnline, !isChatWithSelf && !chatBot && isUserId(id) && selectUserStatus(global, id)?.wasOnline,
); );