Attachments: Follow up (#2335)
This commit is contained in:
parent
b52a39671a
commit
58c71fd908
@ -1408,6 +1408,7 @@ function buildUploadingMedia(
|
|||||||
|
|
||||||
if (!shouldSendAsFile) {
|
if (!shouldSendAsFile) {
|
||||||
if (attachment.quick) {
|
if (attachment.quick) {
|
||||||
|
// TODO Handle GIF as video, but support playback in <video>
|
||||||
if (SUPPORTED_IMAGE_CONTENT_TYPES.has(mimeType)) {
|
if (SUPPORTED_IMAGE_CONTENT_TYPES.has(mimeType)) {
|
||||||
const { width, height } = attachment.quick;
|
const { width, height } = attachment.quick;
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import {
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
ALL_FOLDER_ID,
|
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,
|
PINNED_MESSAGES_LIMIT, REACTION_UNREAD_SLICE,
|
||||||
SUPPORTED_IMAGE_CONTENT_TYPES,
|
SUPPORTED_IMAGE_CONTENT_TYPES,
|
||||||
SUPPORTED_VIDEO_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 })];
|
const attributes: GramJs.TypeDocumentAttribute[] = [new GramJs.DocumentAttributeFilename({ fileName: filename })];
|
||||||
if (!shouldSendAsFile) {
|
if (!shouldSendAsFile) {
|
||||||
if (quick) {
|
if (quick) {
|
||||||
if (SUPPORTED_IMAGE_CONTENT_TYPES.has(mimeType)) {
|
if (SUPPORTED_IMAGE_CONTENT_TYPES.has(mimeType) && mimeType !== GIF_MIME_TYPE) {
|
||||||
return new GramJs.InputMediaUploadedPhoto({
|
return new GramJs.InputMediaUploadedPhoto({
|
||||||
file: inputFile,
|
file: inputFile,
|
||||||
spoiler: shouldSendAsSpoiler,
|
spoiler: shouldSendAsSpoiler,
|
||||||
|
|||||||
@ -184,6 +184,7 @@ type StateProps =
|
|||||||
captionLimit: number;
|
captionLimit: number;
|
||||||
isCurrentUserPremium?: boolean;
|
isCurrentUserPremium?: boolean;
|
||||||
canSendVoiceByPrivacy?: boolean;
|
canSendVoiceByPrivacy?: boolean;
|
||||||
|
attachmentSettings: GlobalState['attachmentSettings'];
|
||||||
}
|
}
|
||||||
& Pick<GlobalState, 'connectionState'>;
|
& Pick<GlobalState, 'connectionState'>;
|
||||||
|
|
||||||
@ -263,6 +264,7 @@ const Composer: FC<OwnProps & StateProps> = ({
|
|||||||
botMenuButton,
|
botMenuButton,
|
||||||
attachBots,
|
attachBots,
|
||||||
attachMenuPeerType,
|
attachMenuPeerType,
|
||||||
|
attachmentSettings,
|
||||||
theme,
|
theme,
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
@ -671,8 +673,8 @@ const Composer: FC<OwnProps & StateProps> = ({
|
|||||||
|
|
||||||
const sendAttachments = useCallback(({
|
const sendAttachments = useCallback(({
|
||||||
attachments: attachmentsToSend,
|
attachments: attachmentsToSend,
|
||||||
sendCompressed,
|
sendCompressed = attachmentSettings.shouldCompress,
|
||||||
sendGrouped,
|
sendGrouped = attachmentSettings.shouldSendGrouped,
|
||||||
isSilent,
|
isSilent,
|
||||||
scheduledAt,
|
scheduledAt,
|
||||||
} : {
|
} : {
|
||||||
@ -711,7 +713,10 @@ const Composer: FC<OwnProps & StateProps> = ({
|
|||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
resetComposer();
|
resetComposer();
|
||||||
});
|
});
|
||||||
}, [chatId, checkSlowMode, clearDraft, htmlRef, resetComposer, sendMessage, validateTextLength, connectionState]);
|
}, [
|
||||||
|
attachmentSettings, connectionState, htmlRef, validateTextLength, checkSlowMode, sendMessage, clearDraft, chatId,
|
||||||
|
resetComposer,
|
||||||
|
]);
|
||||||
|
|
||||||
const handleSendAttachments = useCallback((
|
const handleSendAttachments = useCallback((
|
||||||
sendCompressed: boolean,
|
sendCompressed: boolean,
|
||||||
@ -1569,6 +1574,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
captionLimit: selectCurrentLimit(global, 'captionLength'),
|
captionLimit: selectCurrentLimit(global, 'captionLength'),
|
||||||
isCurrentUserPremium: selectIsCurrentUserPremium(global),
|
isCurrentUserPremium: selectIsCurrentUserPremium(global),
|
||||||
canSendVoiceByPrivacy,
|
canSendVoiceByPrivacy,
|
||||||
|
attachmentSettings: global.attachmentSettings,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
)(Composer));
|
)(Composer));
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import type { ApiAttachment } from '../../../../api/types';
|
import type { ApiAttachment } from '../../../../api/types';
|
||||||
import {
|
import {
|
||||||
|
GIF_MIME_TYPE,
|
||||||
SUPPORTED_AUDIO_CONTENT_TYPES,
|
SUPPORTED_AUDIO_CONTENT_TYPES,
|
||||||
SUPPORTED_IMAGE_CONTENT_TYPES,
|
SUPPORTED_IMAGE_CONTENT_TYPES,
|
||||||
SUPPORTED_VIDEO_CONTENT_TYPES,
|
SUPPORTED_VIDEO_CONTENT_TYPES,
|
||||||
@ -28,8 +29,9 @@ export default async function buildAttachment(
|
|||||||
const img = await preloadImage(blobUrl);
|
const img = await preloadImage(blobUrl);
|
||||||
const { width, height } = img;
|
const { width, height } = img;
|
||||||
const shouldShrink = Math.max(width, height) > MAX_QUICK_IMG_SIZE;
|
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(
|
const resizedUrl = await scaleImage(
|
||||||
blobUrl, shouldShrink ? MAX_QUICK_IMG_SIZE / Math.max(width, height) : 1, 'image/jpeg',
|
blobUrl, shouldShrink ? MAX_QUICK_IMG_SIZE / Math.max(width, height) : 1, 'image/jpeg',
|
||||||
);
|
);
|
||||||
|
|||||||
@ -182,8 +182,10 @@ export const SLIDE_TRANSITION_DURATION = 450;
|
|||||||
export const VIDEO_MOV_TYPE = 'video/quicktime';
|
export const VIDEO_MOV_TYPE = 'video/quicktime';
|
||||||
export const VIDEO_WEBM_TYPE = 'video/webm';
|
export const VIDEO_WEBM_TYPE = 'video/webm';
|
||||||
|
|
||||||
|
export const GIF_MIME_TYPE = 'image/gif';
|
||||||
|
|
||||||
export const SUPPORTED_IMAGE_CONTENT_TYPES = new Set([
|
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([
|
export const SUPPORTED_VIDEO_CONTENT_TYPES = new Set([
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user