Message Toolbar: Fix incorrect SVG dialog (#5986)

This commit is contained in:
zubiden 2025-06-04 20:42:13 +02:00 committed by Alexander Zinchuk
parent 39ca8ce15f
commit c226e8fc0b
4 changed files with 29 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import { getActions } from '../../global';
import type { ApiDocument, ApiMessage } from '../../api/types'; import type { ApiDocument, ApiMessage } from '../../api/types';
import type { ObserveFn } from '../../hooks/useIntersectionObserver'; import type { ObserveFn } from '../../hooks/useIntersectionObserver';
import { SVG_EXTENSIONS } from '../../config';
import { import {
getDocumentMediaHash, getDocumentMediaHash,
getMediaFormat, getMediaFormat,
@ -52,7 +53,6 @@ type OwnProps = {
}); });
const BYTES_PER_MB = 1024 * 1024; const BYTES_PER_MB = 1024 * 1024;
const SVG_EXTENSIONS = new Set(['svg', 'svgz']);
const Document = ({ const Document = ({
document, document,

View File

@ -12,6 +12,7 @@ import {
selectCanForwardMessages, selectCanForwardMessages,
selectCanReportSelectedMessages, selectCurrentChat, selectCanReportSelectedMessages, selectCurrentChat,
selectCurrentMessageList, selectHasProtectedMessage, selectCurrentMessageList, selectHasProtectedMessage,
selectHasSvg,
selectSelectedMessagesCount, selectSelectedMessagesCount,
selectTabState, selectTabState,
} from '../../global/selectors'; } from '../../global/selectors';
@ -50,6 +51,7 @@ type StateProps = {
isAnyModalOpen?: boolean; isAnyModalOpen?: boolean;
selectedMessageIds?: number[]; selectedMessageIds?: number[];
shouldWarnAboutSvg?: boolean; shouldWarnAboutSvg?: boolean;
hasSvgs?: boolean;
}; };
const MessageSelectToolbar: FC<OwnProps & StateProps> = ({ const MessageSelectToolbar: FC<OwnProps & StateProps> = ({
@ -67,6 +69,7 @@ const MessageSelectToolbar: FC<OwnProps & StateProps> = ({
isAnyModalOpen, isAnyModalOpen,
selectedMessageIds, selectedMessageIds,
shouldWarnAboutSvg, shouldWarnAboutSvg,
hasSvgs,
}) => { }) => {
const { const {
exitMessageSelectMode, exitMessageSelectMode,
@ -125,7 +128,7 @@ const MessageSelectToolbar: FC<OwnProps & StateProps> = ({
}); });
const handleMessageDownload = useLastCallback(() => { const handleMessageDownload = useLastCallback(() => {
if (shouldWarnAboutSvg) { if (shouldWarnAboutSvg && hasSvgs) {
openSvgDialog(); openSvgDialog();
return; return;
} }
@ -134,7 +137,7 @@ const MessageSelectToolbar: FC<OwnProps & StateProps> = ({
}); });
const handleSvgConfirm = useLastCallback(() => { const handleSvgConfirm = useLastCallback(() => {
setSharedSettingOption({ shouldWarnAboutSvg: false }); setSharedSettingOption({ shouldWarnAboutSvg: !shouldNotWarnAboutSvg });
closeSvgDialog(); closeSvgDialog();
handleDownload(); handleDownload();
}); });
@ -250,6 +253,7 @@ export default memo(withGlobal<OwnProps>(
const { messageIds: selectedMessageIds } = tabState.selectedMessages || {}; const { messageIds: selectedMessageIds } = tabState.selectedMessages || {};
const hasProtectedMessage = chatId ? selectHasProtectedMessage(global, chatId, selectedMessageIds) : false; const hasProtectedMessage = chatId ? selectHasProtectedMessage(global, chatId, selectedMessageIds) : false;
const canForward = !isSchedule && chatId ? selectCanForwardMessages(global, chatId, selectedMessageIds) : false; const canForward = !isSchedule && chatId ? selectCanForwardMessages(global, chatId, selectedMessageIds) : false;
const hasSvgs = selectedMessageIds && chatId ? selectHasSvg(global, chatId, selectedMessageIds) : false;
const isShareMessageModalOpen = tabState.isShareMessageModalShown; const isShareMessageModalOpen = tabState.isShareMessageModalShown;
const isAnyModalOpen = Boolean(isShareMessageModalOpen || tabState.requestedDraft const isAnyModalOpen = Boolean(isShareMessageModalOpen || tabState.requestedDraft
|| tabState.requestedAttachBotInChat || tabState.requestedAttachBotInstall || tabState.reportModal || tabState.requestedAttachBotInChat || tabState.requestedAttachBotInstall || tabState.reportModal
@ -267,6 +271,7 @@ export default memo(withGlobal<OwnProps>(
hasProtectedMessage, hasProtectedMessage,
isAnyModalOpen, isAnyModalOpen,
shouldWarnAboutSvg, shouldWarnAboutSvg,
hasSvgs,
}; };
}, },
)(MessageSelectToolbar)); )(MessageSelectToolbar));

View File

@ -257,6 +257,7 @@ export const BIRTHDAY_NUMBERS_SET = 'FestiveFontEmoji';
export const RESTRICTED_EMOJI_SET = 'RestrictedEmoji'; export const RESTRICTED_EMOJI_SET = 'RestrictedEmoji';
export const SVG_NAMESPACE = 'http://www.w3.org/2000/svg'; export const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
export const SVG_EXTENSIONS = new Set(['svg', 'svgz']);
export const VIDEO_WEBM_TYPE = 'video/webm'; export const VIDEO_WEBM_TYPE = 'video/webm';
export const GIF_MIME_TYPE = 'image/gif'; export const GIF_MIME_TYPE = 'image/gif';

View File

@ -23,6 +23,7 @@ import { ApiMessageEntityTypes, MAIN_THREAD_ID } from '../../api/types';
import { import {
ANONYMOUS_USER_ID, API_GENERAL_ID_LIMIT, GENERAL_TOPIC_ID, SERVICE_NOTIFICATIONS_USER_ID, ANONYMOUS_USER_ID, API_GENERAL_ID_LIMIT, GENERAL_TOPIC_ID, SERVICE_NOTIFICATIONS_USER_ID,
SVG_EXTENSIONS,
} from '../../config'; } from '../../config';
import { IS_TRANSLATION_SUPPORTED } from '../../util/browser/windowEnvironment'; import { IS_TRANSLATION_SUPPORTED } from '../../util/browser/windowEnvironment';
import { isUserId } from '../../util/entities/ids'; import { isUserId } from '../../util/entities/ids';
@ -31,6 +32,7 @@ import { findLast } from '../../util/iteratees';
import { getMessageKey, isLocalMessageId } from '../../util/keys/messageKey'; import { getMessageKey, isLocalMessageId } from '../../util/keys/messageKey';
import { MEMO_EMPTY_ARRAY } from '../../util/memo'; import { MEMO_EMPTY_ARRAY } from '../../util/memo';
import { getServerTime } from '../../util/serverTime'; import { getServerTime } from '../../util/serverTime';
import { getDocumentExtension } from '../../components/common/helpers/documentInfo';
import { import {
canSendReaction, canSendReaction,
getAllowedAttachmentOptions, getAllowedAttachmentOptions,
@ -1270,6 +1272,24 @@ export function selectCanForwardMessages<T extends GlobalState>(global: T, chatI
&& (message.isForwardingAllowed || isServiceNotificationMessage(message))); && (message.isForwardingAllowed || isServiceNotificationMessage(message)));
} }
export function selectHasSvg<T extends GlobalState>(global: T, chatId: string, messageIds: number[]) {
const messages = selectChatMessages(global, chatId);
return messageIds
.map((id) => messages[id])
.some((message) => {
if (!message) return false;
const document = getMessageDocument(message);
if (!document) return false;
const extension = getDocumentExtension(document);
if (!extension) return false;
return SVG_EXTENSIONS.has(extension);
});
}
export function selectSponsoredMessage<T extends GlobalState>(global: T, chatId: string) { export function selectSponsoredMessage<T extends GlobalState>(global: T, chatId: string) {
const message = global.messages.sponsoredByChatId[chatId]; const message = global.messages.sponsoredByChatId[chatId];