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 {
selectAllowedMessageActions,
selectBot,
selectChat,
selectCurrentMessageList,
selectUser,
@ -123,8 +124,9 @@ export default memo(withGlobal<OwnProps>(
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 {

View File

@ -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<OwnProps>(
};
}
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;

View File

@ -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<OwnProps>(
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(

View File

@ -32,7 +32,7 @@ import {
selectChat,
selectIsInSelectMode,
selectIsChatWithSelf,
selectChatBot,
selectBot,
selectIsChatBotNotStarted,
selectScrollOffset,
selectThreadTopMessageId,
@ -715,7 +715,7 @@ export default memo(withGlobal<OwnProps>(
&& !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)) {

View File

@ -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<OwnProps>(
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;

View File

@ -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<OwnProps>(
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);

View File

@ -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<void> =
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;
}

View File

@ -72,17 +72,6 @@ export function selectChatOnlineCount<T extends GlobalState>(global: T, chat: Ap
}, 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) {
const bot = selectUser(global, 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) {
const chat = selectChat(global, chatId);
const bot = selectChatBot(global, chatId);
const bot = selectBot(global, chatId);
if (!chat || !bot) {
return false;
}

View File

@ -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<T extends GlobalState>(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<T extends GlobalState>(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<T extends GlobalState>(
export function selectCanScheduleUntilOnline<T extends GlobalState>(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,
);