diff --git a/src/components/middle/MessageSelectToolbar.tsx b/src/components/middle/MessageSelectToolbar.tsx index 1fa12925..1e2103bd 100644 --- a/src/components/middle/MessageSelectToolbar.tsx +++ b/src/components/middle/MessageSelectToolbar.tsx @@ -10,6 +10,7 @@ import { selectCanDownloadSelectedMessages, selectCanReportSelectedMessages, selectCurrentMessageList, + selectHasProtectedMessage, selectSelectedMessagesCount, } from '../../modules/selectors'; import useFlag from '../../hooks/useFlag'; @@ -37,6 +38,7 @@ type StateProps = { canDeleteMessages?: boolean; canReportMessages?: boolean; canDownloadMessages?: boolean; + hasProtectedMessage?: boolean; selectedMessageIds?: number[]; }; @@ -49,6 +51,7 @@ const MessageSelectToolbar: FC = ({ canDeleteMessages, canReportMessages, canDownloadMessages, + hasProtectedMessage, selectedMessageIds, }) => { const { @@ -126,13 +129,15 @@ const MessageSelectToolbar: FC = ({ {!!selectedMessagesCount && (
{messageListType !== 'scheduled' && ( - renderButton('forward', lang('Chat.ForwardActionHeader'), openForwardMenuForSelectedMessages) + renderButton( + 'forward', lang('Chat.ForwardActionHeader'), openForwardMenuForSelectedMessages, hasProtectedMessage, + ) )} {canReportMessages && ( renderButton('flag', lang('Conversation.ReportMessages'), openReportModal) )} {canDownloadMessages && ( - renderButton('download', lang('lng_media_download'), handleDownload) + renderButton('download', lang('lng_media_download'), handleDownload, hasProtectedMessage) )} {renderButton('delete', lang('EditAdminGroupDeleteMessages'), openDeleteModal, !canDeleteMessages, true)}
@@ -154,11 +159,12 @@ const MessageSelectToolbar: FC = ({ export default memo(withGlobal( (global): StateProps => { - const { type: messageListType } = selectCurrentMessageList(global) || {}; + const { type: messageListType, chatId } = selectCurrentMessageList(global) || {}; const { canDelete } = selectCanDeleteSelectedMessages(global); const canReport = selectCanReportSelectedMessages(global); const canDownload = selectCanDownloadSelectedMessages(global); const { messageIds: selectedMessageIds } = global.selectedMessages || {}; + const hasProtectedMessage = chatId ? selectHasProtectedMessage(global, chatId, selectedMessageIds) : false; return { isSchedule: messageListType === 'scheduled', @@ -167,6 +173,7 @@ export default memo(withGlobal( canReportMessages: canReport, canDownloadMessages: canDownload, selectedMessageIds, + hasProtectedMessage, }; }, )(MessageSelectToolbar)); diff --git a/src/modules/selectors/messages.ts b/src/modules/selectors/messages.ts index 8c0fcbe0..674e5277 100644 --- a/src/modules/selectors/messages.ts +++ b/src/modules/selectors/messages.ts @@ -860,6 +860,20 @@ export function selectIsMessageProtected(global: GlobalState, message?: ApiMessa return message ? message.isProtected || selectChat(global, message.chatId)?.isProtected : false; } +export function selectHasProtectedMessage(global: GlobalState, chatId: string, messageIds?: number[]) { + if (selectChat(global, chatId)?.isProtected) { + return true; + } + + if (!messageIds) { + return false; + } + + const messages = selectChatMessages(global, chatId); + + return messageIds.some((messageId) => messages[messageId]?.isProtected); +} + export function selectSponsoredMessage(global: GlobalState, chatId: string) { const chat = selectChat(global, chatId); const message = chat && isChatChannel(chat) ? global.messages.sponsoredByChatId[chatId] : undefined;