mirror of
https://github.com/danog/telegram-tt.git
synced 2024-11-27 04:45:08 +01:00
Select Toolbar: Disable forward and download for protected messages (#1619)
This commit is contained in:
parent
616682b4af
commit
1597f2ad2f
@ -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<OwnProps & StateProps> = ({
|
||||
canDeleteMessages,
|
||||
canReportMessages,
|
||||
canDownloadMessages,
|
||||
hasProtectedMessage,
|
||||
selectedMessageIds,
|
||||
}) => {
|
||||
const {
|
||||
@ -126,13 +129,15 @@ const MessageSelectToolbar: FC<OwnProps & StateProps> = ({
|
||||
{!!selectedMessagesCount && (
|
||||
<div className="MessageSelectToolbar-actions">
|
||||
{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)}
|
||||
</div>
|
||||
@ -154,11 +159,12 @@ const MessageSelectToolbar: FC<OwnProps & StateProps> = ({
|
||||
|
||||
export default memo(withGlobal<OwnProps>(
|
||||
(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<OwnProps>(
|
||||
canReportMessages: canReport,
|
||||
canDownloadMessages: canDownload,
|
||||
selectedMessageIds,
|
||||
hasProtectedMessage,
|
||||
};
|
||||
},
|
||||
)(MessageSelectToolbar));
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user