Attachments: Follow up (#2335)

This commit is contained in:
Alexander Zinchuk 2023-01-28 02:15:24 +01:00
parent b52a39671a
commit 58c71fd908
5 changed files with 18 additions and 7 deletions

View File

@ -1408,6 +1408,7 @@ function buildUploadingMedia(
if (!shouldSendAsFile) {
if (attachment.quick) {
// TODO Handle GIF as video, but support playback in <video>
if (SUPPORTED_IMAGE_CONTENT_TYPES.has(mimeType)) {
const { width, height } = attachment.quick;
return {

View File

@ -24,7 +24,7 @@ import {
import {
ALL_FOLDER_ID,
DEBUG, MAX_INT_32, MENTION_UNREAD_SLICE,
DEBUG, GIF_MIME_TYPE, MAX_INT_32, MENTION_UNREAD_SLICE,
PINNED_MESSAGES_LIMIT, REACTION_UNREAD_SLICE,
SUPPORTED_IMAGE_CONTENT_TYPES,
SUPPORTED_VIDEO_CONTENT_TYPES,
@ -585,7 +585,7 @@ async function uploadMedia(localMessage: ApiMessage, attachment: ApiAttachment,
const attributes: GramJs.TypeDocumentAttribute[] = [new GramJs.DocumentAttributeFilename({ fileName: filename })];
if (!shouldSendAsFile) {
if (quick) {
if (SUPPORTED_IMAGE_CONTENT_TYPES.has(mimeType)) {
if (SUPPORTED_IMAGE_CONTENT_TYPES.has(mimeType) && mimeType !== GIF_MIME_TYPE) {
return new GramJs.InputMediaUploadedPhoto({
file: inputFile,
spoiler: shouldSendAsSpoiler,

View File

@ -184,6 +184,7 @@ type StateProps =
captionLimit: number;
isCurrentUserPremium?: boolean;
canSendVoiceByPrivacy?: boolean;
attachmentSettings: GlobalState['attachmentSettings'];
}
& Pick<GlobalState, 'connectionState'>;
@ -263,6 +264,7 @@ const Composer: FC<OwnProps & StateProps> = ({
botMenuButton,
attachBots,
attachMenuPeerType,
attachmentSettings,
theme,
}) => {
const {
@ -671,8 +673,8 @@ const Composer: FC<OwnProps & StateProps> = ({
const sendAttachments = useCallback(({
attachments: attachmentsToSend,
sendCompressed,
sendGrouped,
sendCompressed = attachmentSettings.shouldCompress,
sendGrouped = attachmentSettings.shouldSendGrouped,
isSilent,
scheduledAt,
} : {
@ -711,7 +713,10 @@ const Composer: FC<OwnProps & StateProps> = ({
requestAnimationFrame(() => {
resetComposer();
});
}, [chatId, checkSlowMode, clearDraft, htmlRef, resetComposer, sendMessage, validateTextLength, connectionState]);
}, [
attachmentSettings, connectionState, htmlRef, validateTextLength, checkSlowMode, sendMessage, clearDraft, chatId,
resetComposer,
]);
const handleSendAttachments = useCallback((
sendCompressed: boolean,
@ -1569,6 +1574,7 @@ export default memo(withGlobal<OwnProps>(
captionLimit: selectCurrentLimit(global, 'captionLength'),
isCurrentUserPremium: selectIsCurrentUserPremium(global),
canSendVoiceByPrivacy,
attachmentSettings: global.attachmentSettings,
};
},
)(Composer));

View File

@ -1,5 +1,6 @@
import type { ApiAttachment } from '../../../../api/types';
import {
GIF_MIME_TYPE,
SUPPORTED_AUDIO_CONTENT_TYPES,
SUPPORTED_IMAGE_CONTENT_TYPES,
SUPPORTED_VIDEO_CONTENT_TYPES,
@ -28,8 +29,9 @@ export default async function buildAttachment(
const img = await preloadImage(blobUrl);
const { width, height } = img;
const shouldShrink = Math.max(width, height) > MAX_QUICK_IMG_SIZE;
const isGif = mimeType === GIF_MIME_TYPE;
if (!options?.compressedBlobUrl && (shouldShrink || mimeType !== 'image/jpeg')) {
if (!options?.compressedBlobUrl && !isGif && (shouldShrink || mimeType !== 'image/jpeg')) {
const resizedUrl = await scaleImage(
blobUrl, shouldShrink ? MAX_QUICK_IMG_SIZE / Math.max(width, height) : 1, 'image/jpeg',
);

View File

@ -182,8 +182,10 @@ export const SLIDE_TRANSITION_DURATION = 450;
export const VIDEO_MOV_TYPE = 'video/quicktime';
export const VIDEO_WEBM_TYPE = 'video/webm';
export const GIF_MIME_TYPE = 'image/gif';
export const SUPPORTED_IMAGE_CONTENT_TYPES = new Set([
'image/png', 'image/gif', 'image/jpeg',
'image/png', 'image/jpeg', GIF_MIME_TYPE,
]);
export const SUPPORTED_VIDEO_CONTENT_TYPES = new Set([