Attach Menu: Fix uploading audio files (#4806)
This commit is contained in:
parent
f3743bd556
commit
4169b5c6ad
@ -27,7 +27,7 @@ import type {
|
||||
} from '../../types';
|
||||
import type { UniversalMessage } from './messages';
|
||||
|
||||
import { SUPPORTED_IMAGE_CONTENT_TYPES, SUPPORTED_VIDEO_CONTENT_TYPES, VIDEO_WEBM_TYPE } from '../../../config';
|
||||
import { SUPPORTED_PHOTO_CONTENT_TYPES, SUPPORTED_VIDEO_CONTENT_TYPES, VIDEO_WEBM_TYPE } from '../../../config';
|
||||
import { pick } from '../../../util/iteratees';
|
||||
import {
|
||||
addMediaToLocalDb, addStoryToLocalDb, type MediaRepairContext, serializeBytes,
|
||||
@ -402,7 +402,7 @@ export function buildApiDocument(document: GramJs.TypeDocument): ApiDocument | u
|
||||
height: photoSize.h,
|
||||
};
|
||||
|
||||
if (SUPPORTED_IMAGE_CONTENT_TYPES.has(mimeType)) {
|
||||
if (SUPPORTED_PHOTO_CONTENT_TYPES.has(mimeType)) {
|
||||
innerMediaType = 'photo';
|
||||
|
||||
const imageAttribute = attributes
|
||||
|
||||
@ -39,7 +39,7 @@ import {
|
||||
SERVICE_NOTIFICATIONS_USER_ID,
|
||||
SPONSORED_MESSAGE_CACHE_MS,
|
||||
SUPPORTED_AUDIO_CONTENT_TYPES,
|
||||
SUPPORTED_IMAGE_CONTENT_TYPES,
|
||||
SUPPORTED_PHOTO_CONTENT_TYPES,
|
||||
SUPPORTED_VIDEO_CONTENT_TYPES,
|
||||
} from '../../../config';
|
||||
import { getEmojiOnlyCountForMessage } from '../../../global/helpers/getEmojiOnlyCountForMessage';
|
||||
@ -987,7 +987,7 @@ export function buildUploadingMedia(
|
||||
if (!shouldSendAsFile) {
|
||||
if (attachment.quick) {
|
||||
// TODO Handle GIF as video, but support playback in <video>
|
||||
if (SUPPORTED_IMAGE_CONTENT_TYPES.has(mimeType)) {
|
||||
if (SUPPORTED_PHOTO_CONTENT_TYPES.has(mimeType)) {
|
||||
const { width, height } = attachment.quick;
|
||||
return {
|
||||
photo: {
|
||||
|
||||
@ -37,7 +37,7 @@ import {
|
||||
MENTION_UNREAD_SLICE,
|
||||
PINNED_MESSAGES_LIMIT,
|
||||
REACTION_UNREAD_SLICE,
|
||||
SUPPORTED_IMAGE_CONTENT_TYPES,
|
||||
SUPPORTED_PHOTO_CONTENT_TYPES,
|
||||
SUPPORTED_VIDEO_CONTENT_TYPES,
|
||||
} from '../../../config';
|
||||
import { getEmojiOnlyCountForMessage } from '../../../global/helpers/getEmojiOnlyCountForMessage';
|
||||
@ -706,7 +706,7 @@ async function uploadMedia(message: ApiMessage, attachment: ApiAttachment, onPro
|
||||
const attributes: GramJs.TypeDocumentAttribute[] = [new GramJs.DocumentAttributeFilename({ fileName: filename })];
|
||||
if (!shouldSendAsFile) {
|
||||
if (quick) {
|
||||
if (SUPPORTED_IMAGE_CONTENT_TYPES.has(mimeType) && mimeType !== GIF_MIME_TYPE) {
|
||||
if (SUPPORTED_PHOTO_CONTENT_TYPES.has(mimeType) && mimeType !== GIF_MIME_TYPE) {
|
||||
return new GramJs.InputMediaUploadedPhoto({
|
||||
file: inputFile,
|
||||
spoiler: shouldSendAsSpoiler,
|
||||
|
||||
@ -22,7 +22,7 @@ import {
|
||||
MIN_SCREEN_WIDTH_FOR_STATIC_RIGHT_COLUMN,
|
||||
MOBILE_SCREEN_MAX_WIDTH,
|
||||
SAFE_SCREEN_WIDTH_FOR_STATIC_RIGHT_COLUMN,
|
||||
SUPPORTED_IMAGE_CONTENT_TYPES,
|
||||
SUPPORTED_PHOTO_CONTENT_TYPES,
|
||||
TMP_CHAT_ID,
|
||||
} from '../../config';
|
||||
import { requestMeasure, requestMutation } from '../../lib/fasterdom/fasterdom';
|
||||
@ -157,7 +157,7 @@ type StateProps = {
|
||||
};
|
||||
|
||||
function isImage(item: DataTransferItem) {
|
||||
return item.kind === 'file' && item.type && SUPPORTED_IMAGE_CONTENT_TYPES.has(item.type);
|
||||
return item.kind === 'file' && item.type && SUPPORTED_PHOTO_CONTENT_TYPES.has(item.type);
|
||||
}
|
||||
|
||||
const LAYER_ANIMATION_DURATION_MS = 450 + ANIMATION_END_DELAY;
|
||||
|
||||
@ -10,7 +10,7 @@ import type { ISettings, ThreadId } from '../../../types';
|
||||
|
||||
import {
|
||||
CONTENT_TYPES_WITH_PREVIEW, DEBUG_LOG_FILENAME, SUPPORTED_AUDIO_CONTENT_TYPES,
|
||||
SUPPORTED_IMAGE_CONTENT_TYPES,
|
||||
SUPPORTED_PHOTO_CONTENT_TYPES,
|
||||
SUPPORTED_VIDEO_CONTENT_TYPES,
|
||||
} from '../../../config';
|
||||
import {
|
||||
@ -132,7 +132,7 @@ const AttachMenu: FC<OwnProps> = ({
|
||||
const handleQuickSelect = useLastCallback(() => {
|
||||
openSystemFilesDialog(
|
||||
Array.from(canSendVideoAndPhoto ? CONTENT_TYPES_WITH_PREVIEW : (
|
||||
canSendPhotos ? SUPPORTED_IMAGE_CONTENT_TYPES : SUPPORTED_VIDEO_CONTENT_TYPES
|
||||
canSendPhotos ? SUPPORTED_PHOTO_CONTENT_TYPES : SUPPORTED_VIDEO_CONTENT_TYPES
|
||||
)).join(','),
|
||||
(e) => handleFileSelect(e, true),
|
||||
);
|
||||
|
||||
@ -15,11 +15,11 @@ import {
|
||||
BASE_EMOJI_KEYWORD_LANG,
|
||||
EDITABLE_INPUT_MODAL_ID,
|
||||
SUPPORTED_AUDIO_CONTENT_TYPES,
|
||||
SUPPORTED_IMAGE_CONTENT_TYPES,
|
||||
SUPPORTED_PHOTO_CONTENT_TYPES,
|
||||
SUPPORTED_VIDEO_CONTENT_TYPES,
|
||||
} from '../../../config';
|
||||
import { requestMutation } from '../../../lib/fasterdom/fasterdom';
|
||||
import { getAttachmentType, isUserId } from '../../../global/helpers';
|
||||
import { getAttachmentMediaType, isUserId } from '../../../global/helpers';
|
||||
import { selectChatFullInfo, selectIsChatWithSelf } from '../../../global/selectors';
|
||||
import { selectCurrentLimit } from '../../../global/selectors/limits';
|
||||
import buildClassName from '../../../util/buildClassName';
|
||||
@ -155,7 +155,7 @@ const AttachmentModal: FC<OwnProps & StateProps> = ({
|
||||
|
||||
const isEditing = editingMessage && Boolean(editingMessage);
|
||||
const isInAlbum = editingMessage && editingMessage?.groupedId;
|
||||
const isEditingMessageFile = isEditing && attachments?.length && getAttachmentType(attachments[0]);
|
||||
const isEditingMessageFile = isEditing && attachments?.length && getAttachmentMediaType(attachments[0]);
|
||||
const notEditingFile = isEditingMessageFile !== 'file';
|
||||
|
||||
const [isSymbolMenuOpen, openSymbolMenu, closeSymbolMenu] = useFlag();
|
||||
@ -428,7 +428,7 @@ const AttachmentModal: FC<OwnProps & StateProps> = ({
|
||||
|
||||
const [areAllPhotos, areAllVideos, areAllAudios] = useMemo(() => {
|
||||
if (!isQuickGallery || !renderingAttachments) return [false, false, false];
|
||||
const everyPhoto = renderingAttachments.every((a) => SUPPORTED_IMAGE_CONTENT_TYPES.has(a.mimeType));
|
||||
const everyPhoto = renderingAttachments.every((a) => SUPPORTED_PHOTO_CONTENT_TYPES.has(a.mimeType));
|
||||
const everyVideo = renderingAttachments.every((a) => SUPPORTED_VIDEO_CONTENT_TYPES.has(a.mimeType));
|
||||
const everyAudio = renderingAttachments.every((a) => SUPPORTED_AUDIO_CONTENT_TYPES.has(a.mimeType));
|
||||
return [everyPhoto, everyVideo, everyAudio];
|
||||
|
||||
@ -3,7 +3,7 @@ import React, { memo, useMemo } from '../../../lib/teact/teact';
|
||||
|
||||
import type { ApiAttachment } from '../../../api/types';
|
||||
|
||||
import { SUPPORTED_IMAGE_CONTENT_TYPES, SUPPORTED_VIDEO_CONTENT_TYPES } from '../../../config';
|
||||
import { SUPPORTED_PHOTO_CONTENT_TYPES, SUPPORTED_VIDEO_CONTENT_TYPES } from '../../../config';
|
||||
import buildClassName from '../../../util/buildClassName';
|
||||
import { formatMediaDuration } from '../../../util/dates/dateFormat';
|
||||
import { getFileExtension } from '../../common/helpers/documentInfo';
|
||||
@ -47,7 +47,7 @@ const AttachmentModalItem: FC<OwnProps> = ({
|
||||
|
||||
const content = useMemo(() => {
|
||||
switch (displayType) {
|
||||
case 'image':
|
||||
case 'photo':
|
||||
return (
|
||||
<img
|
||||
className={styles.preview}
|
||||
@ -135,8 +135,8 @@ const AttachmentModalItem: FC<OwnProps> = ({
|
||||
|
||||
export function getDisplayType(attachment: ApiAttachment, shouldDisplayCompressed?: boolean) {
|
||||
if (shouldDisplayCompressed && attachment.quick) {
|
||||
if (SUPPORTED_IMAGE_CONTENT_TYPES.has(attachment.mimeType)) {
|
||||
return 'image';
|
||||
if (SUPPORTED_PHOTO_CONTENT_TYPES.has(attachment.mimeType)) {
|
||||
return 'photo';
|
||||
}
|
||||
if (SUPPORTED_VIDEO_CONTENT_TYPES.has(attachment.mimeType)) {
|
||||
return 'video';
|
||||
|
||||
@ -3,7 +3,7 @@ import type { ApiAttachment } from '../../../../api/types';
|
||||
import {
|
||||
GIF_MIME_TYPE,
|
||||
SUPPORTED_AUDIO_CONTENT_TYPES,
|
||||
SUPPORTED_IMAGE_CONTENT_TYPES,
|
||||
SUPPORTED_PHOTO_CONTENT_TYPES,
|
||||
SUPPORTED_VIDEO_CONTENT_TYPES,
|
||||
} from '../../../../config';
|
||||
import { parseAudioMetadata } from '../../../../util/audio';
|
||||
@ -29,7 +29,7 @@ export default async function buildAttachment(
|
||||
let previewBlobUrl;
|
||||
let shouldSendAsFile;
|
||||
|
||||
if (SUPPORTED_IMAGE_CONTENT_TYPES.has(mimeType)) {
|
||||
if (SUPPORTED_PHOTO_CONTENT_TYPES.has(mimeType)) {
|
||||
const img = await preloadImage(blobUrl);
|
||||
const { width, height } = img;
|
||||
shouldSendAsFile = !validateAspectRatio(width, height);
|
||||
@ -117,7 +117,7 @@ export function prepareAttachmentsToSend(
|
||||
|
||||
return {
|
||||
...attach,
|
||||
shouldSendAsFile: !attach.voice ? true : undefined,
|
||||
shouldSendAsFile: !(attach.voice || attach.audio) || undefined,
|
||||
shouldSendAsSpoiler: undefined,
|
||||
};
|
||||
});
|
||||
|
||||
@ -3,7 +3,7 @@ import { getActions } from '../../../../global';
|
||||
|
||||
import type { ApiAttachment, ApiMessage } from '../../../../api/types';
|
||||
|
||||
import { canReplaceMessageMedia, getAttachmentType } from '../../../../global/helpers';
|
||||
import { canReplaceMessageMedia, getAttachmentMediaType } from '../../../../global/helpers';
|
||||
import { MEMO_EMPTY_ARRAY } from '../../../../util/memo';
|
||||
import buildAttachment from '../helpers/buildAttachment';
|
||||
|
||||
@ -55,11 +55,11 @@ export default function useAttachmentModal({
|
||||
}
|
||||
|
||||
if (newAttachments.some((attachment) => {
|
||||
const type = getAttachmentType(attachment);
|
||||
const type = getAttachmentMediaType(attachment);
|
||||
|
||||
return (type === 'audio' && !canSendAudios && !canSendDocuments)
|
||||
|| (type === 'video' && !canSendVideos && !canSendDocuments)
|
||||
|| (type === 'image' && !canSendPhotos && !canSendDocuments)
|
||||
|| (type === 'photo' && !canSendPhotos && !canSendDocuments)
|
||||
|| (type === 'file' && !canSendDocuments);
|
||||
})) {
|
||||
showAllowedMessageTypesNotification({ chatId });
|
||||
@ -70,11 +70,11 @@ export default function useAttachmentModal({
|
||||
} else {
|
||||
setAttachments(newAttachments);
|
||||
const shouldForce = newAttachments.some((attachment) => {
|
||||
const type = getAttachmentType(attachment);
|
||||
const type = getAttachmentMediaType(attachment);
|
||||
|
||||
return (type === 'audio' && !canSendAudios)
|
||||
|| (type === 'video' && !canSendVideos)
|
||||
|| (type === 'image' && !canSendPhotos);
|
||||
|| (type === 'photo' && !canSendPhotos);
|
||||
});
|
||||
|
||||
setShouldForceAsFile(Boolean(shouldForce && canSendDocuments));
|
||||
|
||||
@ -230,7 +230,7 @@ export const GIF_MIME_TYPE = 'image/gif';
|
||||
export const LOTTIE_STICKER_MIME_TYPE = 'application/x-tgsticker';
|
||||
export const VIDEO_STICKER_MIME_TYPE = VIDEO_WEBM_TYPE;
|
||||
|
||||
export const SUPPORTED_IMAGE_CONTENT_TYPES = new Set([
|
||||
export const SUPPORTED_PHOTO_CONTENT_TYPES = new Set([
|
||||
'image/png', 'image/jpeg', GIF_MIME_TYPE,
|
||||
]);
|
||||
|
||||
@ -251,7 +251,7 @@ export const SUPPORTED_AUDIO_CONTENT_TYPES = new Set([
|
||||
]);
|
||||
|
||||
export const CONTENT_TYPES_WITH_PREVIEW = new Set([
|
||||
...SUPPORTED_IMAGE_CONTENT_TYPES,
|
||||
...SUPPORTED_PHOTO_CONTENT_TYPES,
|
||||
...SUPPORTED_VIDEO_CONTENT_TYPES,
|
||||
]);
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ import {
|
||||
RE_TELEGRAM_LINK,
|
||||
SERVICE_NOTIFICATIONS_USER_ID,
|
||||
SUPPORTED_AUDIO_CONTENT_TYPES,
|
||||
SUPPORTED_IMAGE_CONTENT_TYPES,
|
||||
SUPPORTED_PHOTO_CONTENT_TYPES,
|
||||
SUPPORTED_VIDEO_CONTENT_TYPES,
|
||||
} from '../../../config';
|
||||
import { copyTextToClipboardFromPromise } from '../../../util/clipboard';
|
||||
@ -2246,10 +2246,10 @@ function getAttachmentType(attachment: ApiAttachment) {
|
||||
const {
|
||||
shouldSendAsFile, mimeType,
|
||||
} = attachment;
|
||||
if (SUPPORTED_AUDIO_CONTENT_TYPES.has(mimeType)) return 'audio';
|
||||
if (shouldSendAsFile) return 'file';
|
||||
if (mimeType === GIF_MIME_TYPE) return 'gif';
|
||||
if (SUPPORTED_IMAGE_CONTENT_TYPES.has(mimeType) || SUPPORTED_VIDEO_CONTENT_TYPES.has(mimeType)) return 'media';
|
||||
if (SUPPORTED_AUDIO_CONTENT_TYPES.has(mimeType)) return 'audio';
|
||||
if (SUPPORTED_PHOTO_CONTENT_TYPES.has(mimeType) || SUPPORTED_VIDEO_CONTENT_TYPES.has(mimeType)) return 'media';
|
||||
if (attachment.voice) return 'voice';
|
||||
return 'file';
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ import {
|
||||
MAX_BUFFER_SIZE,
|
||||
} from '../../util/windowEnvironment';
|
||||
import { getDocumentHasPreview } from '../../components/common/helpers/documentInfo';
|
||||
import { getAttachmentType, matchLinkInMessageText } from './messages';
|
||||
import { getAttachmentMediaType, matchLinkInMessageText } from './messages';
|
||||
|
||||
export type MediaWithThumbs = ApiPhoto | ApiVideo | ApiDocument | ApiSticker | ApiMediaExtendedPreview;
|
||||
export type DownloadableMedia = ApiPhoto | ApiVideo | ApiDocument | ApiSticker | ApiAudio | ApiVoice | ApiWebDocument;
|
||||
@ -618,10 +618,10 @@ export function canReplaceMessageMedia(message: ApiMessage, attachment: ApiAttac
|
||||
const isFile = Boolean(getMessageAudio(message)
|
||||
|| getMessageVoice(message) || getMessageDocument(message));
|
||||
|
||||
const fileType = getAttachmentType(attachment);
|
||||
const fileType = getAttachmentMediaType(attachment);
|
||||
|
||||
return (
|
||||
(isPhotoOrVideo && (fileType === 'image' || fileType === 'video'))
|
||||
(isPhotoOrVideo && (fileType === 'photo' || fileType === 'video'))
|
||||
|| (isFile && (fileType === 'audio' || fileType === 'file'))
|
||||
);
|
||||
}
|
||||
|
||||
@ -13,10 +13,15 @@ import type { ThreadId } from '../../types';
|
||||
import { ApiMessageEntityTypes, MAIN_THREAD_ID } from '../../api/types';
|
||||
|
||||
import {
|
||||
CONTENT_NOT_SUPPORTED, LOTTIE_STICKER_MIME_TYPE,
|
||||
CONTENT_NOT_SUPPORTED,
|
||||
LOTTIE_STICKER_MIME_TYPE,
|
||||
RE_LINK_TEMPLATE,
|
||||
SERVICE_NOTIFICATIONS_USER_ID, SUPPORTED_AUDIO_CONTENT_TYPES,
|
||||
SUPPORTED_IMAGE_CONTENT_TYPES, SUPPORTED_VIDEO_CONTENT_TYPES, TME_LINK_PREFIX, VIDEO_STICKER_MIME_TYPE,
|
||||
SERVICE_NOTIFICATIONS_USER_ID,
|
||||
SUPPORTED_AUDIO_CONTENT_TYPES,
|
||||
SUPPORTED_PHOTO_CONTENT_TYPES,
|
||||
SUPPORTED_VIDEO_CONTENT_TYPES,
|
||||
TME_LINK_PREFIX,
|
||||
VIDEO_STICKER_MIME_TYPE,
|
||||
} from '../../config';
|
||||
import { areSortedArraysIntersecting, unique } from '../../util/iteratees';
|
||||
import { isLocalMessageId } from '../../util/messageKey';
|
||||
@ -321,21 +326,21 @@ export function isJoinedChannelMessage(message: ApiMessage) {
|
||||
return message.content.action && message.content.action.type === 'joinedChannel';
|
||||
}
|
||||
|
||||
export function getAttachmentType(attachment: ApiAttachment) {
|
||||
export function getAttachmentMediaType(attachment: ApiAttachment) {
|
||||
if (SUPPORTED_AUDIO_CONTENT_TYPES.has(attachment.mimeType)) {
|
||||
return 'audio';
|
||||
}
|
||||
|
||||
if (attachment.shouldSendAsFile) return 'file';
|
||||
|
||||
if (SUPPORTED_IMAGE_CONTENT_TYPES.has(attachment.mimeType)) {
|
||||
return 'image';
|
||||
if (SUPPORTED_PHOTO_CONTENT_TYPES.has(attachment.mimeType)) {
|
||||
return 'photo';
|
||||
}
|
||||
|
||||
if (SUPPORTED_VIDEO_CONTENT_TYPES.has(attachment.mimeType)) {
|
||||
return 'video';
|
||||
}
|
||||
|
||||
if (SUPPORTED_AUDIO_CONTENT_TYPES.has(attachment.mimeType)) {
|
||||
return 'audio';
|
||||
}
|
||||
|
||||
return 'file';
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user