Message Toolbar: Fix incorrect SVG dialog (#5986)
This commit is contained in:
parent
39ca8ce15f
commit
c226e8fc0b
@ -6,6 +6,7 @@ import { getActions } from '../../global';
|
||||
import type { ApiDocument, ApiMessage } from '../../api/types';
|
||||
import type { ObserveFn } from '../../hooks/useIntersectionObserver';
|
||||
|
||||
import { SVG_EXTENSIONS } from '../../config';
|
||||
import {
|
||||
getDocumentMediaHash,
|
||||
getMediaFormat,
|
||||
@ -52,7 +53,6 @@ type OwnProps = {
|
||||
});
|
||||
|
||||
const BYTES_PER_MB = 1024 * 1024;
|
||||
const SVG_EXTENSIONS = new Set(['svg', 'svgz']);
|
||||
|
||||
const Document = ({
|
||||
document,
|
||||
|
||||
@ -12,6 +12,7 @@ import {
|
||||
selectCanForwardMessages,
|
||||
selectCanReportSelectedMessages, selectCurrentChat,
|
||||
selectCurrentMessageList, selectHasProtectedMessage,
|
||||
selectHasSvg,
|
||||
selectSelectedMessagesCount,
|
||||
selectTabState,
|
||||
} from '../../global/selectors';
|
||||
@ -50,6 +51,7 @@ type StateProps = {
|
||||
isAnyModalOpen?: boolean;
|
||||
selectedMessageIds?: number[];
|
||||
shouldWarnAboutSvg?: boolean;
|
||||
hasSvgs?: boolean;
|
||||
};
|
||||
|
||||
const MessageSelectToolbar: FC<OwnProps & StateProps> = ({
|
||||
@ -67,6 +69,7 @@ const MessageSelectToolbar: FC<OwnProps & StateProps> = ({
|
||||
isAnyModalOpen,
|
||||
selectedMessageIds,
|
||||
shouldWarnAboutSvg,
|
||||
hasSvgs,
|
||||
}) => {
|
||||
const {
|
||||
exitMessageSelectMode,
|
||||
@ -125,7 +128,7 @@ const MessageSelectToolbar: FC<OwnProps & StateProps> = ({
|
||||
});
|
||||
|
||||
const handleMessageDownload = useLastCallback(() => {
|
||||
if (shouldWarnAboutSvg) {
|
||||
if (shouldWarnAboutSvg && hasSvgs) {
|
||||
openSvgDialog();
|
||||
return;
|
||||
}
|
||||
@ -134,7 +137,7 @@ const MessageSelectToolbar: FC<OwnProps & StateProps> = ({
|
||||
});
|
||||
|
||||
const handleSvgConfirm = useLastCallback(() => {
|
||||
setSharedSettingOption({ shouldWarnAboutSvg: false });
|
||||
setSharedSettingOption({ shouldWarnAboutSvg: !shouldNotWarnAboutSvg });
|
||||
closeSvgDialog();
|
||||
handleDownload();
|
||||
});
|
||||
@ -250,6 +253,7 @@ export default memo(withGlobal<OwnProps>(
|
||||
const { messageIds: selectedMessageIds } = tabState.selectedMessages || {};
|
||||
const hasProtectedMessage = chatId ? selectHasProtectedMessage(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 isAnyModalOpen = Boolean(isShareMessageModalOpen || tabState.requestedDraft
|
||||
|| tabState.requestedAttachBotInChat || tabState.requestedAttachBotInstall || tabState.reportModal
|
||||
@ -267,6 +271,7 @@ export default memo(withGlobal<OwnProps>(
|
||||
hasProtectedMessage,
|
||||
isAnyModalOpen,
|
||||
shouldWarnAboutSvg,
|
||||
hasSvgs,
|
||||
};
|
||||
},
|
||||
)(MessageSelectToolbar));
|
||||
|
||||
@ -257,6 +257,7 @@ export const BIRTHDAY_NUMBERS_SET = 'FestiveFontEmoji';
|
||||
export const RESTRICTED_EMOJI_SET = 'RestrictedEmoji';
|
||||
|
||||
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 GIF_MIME_TYPE = 'image/gif';
|
||||
|
||||
@ -23,6 +23,7 @@ import { ApiMessageEntityTypes, MAIN_THREAD_ID } from '../../api/types';
|
||||
|
||||
import {
|
||||
ANONYMOUS_USER_ID, API_GENERAL_ID_LIMIT, GENERAL_TOPIC_ID, SERVICE_NOTIFICATIONS_USER_ID,
|
||||
SVG_EXTENSIONS,
|
||||
} from '../../config';
|
||||
import { IS_TRANSLATION_SUPPORTED } from '../../util/browser/windowEnvironment';
|
||||
import { isUserId } from '../../util/entities/ids';
|
||||
@ -31,6 +32,7 @@ import { findLast } from '../../util/iteratees';
|
||||
import { getMessageKey, isLocalMessageId } from '../../util/keys/messageKey';
|
||||
import { MEMO_EMPTY_ARRAY } from '../../util/memo';
|
||||
import { getServerTime } from '../../util/serverTime';
|
||||
import { getDocumentExtension } from '../../components/common/helpers/documentInfo';
|
||||
import {
|
||||
canSendReaction,
|
||||
getAllowedAttachmentOptions,
|
||||
@ -1270,6 +1272,24 @@ export function selectCanForwardMessages<T extends GlobalState>(global: T, chatI
|
||||
&& (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) {
|
||||
const message = global.messages.sponsoredByChatId[chatId];
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user