Accept multiple images and videos in attachment picker
This commit is contained in:
parent
6cfe2a09df
commit
01587b0f39
13 changed files with 87 additions and 54 deletions
|
@ -36,3 +36,13 @@ const SUPPORTED_VIDEO_MIME_TYPES: MIMETypeSupportMap = {
|
|||
// See: https://www.chromium.org/audio-video
|
||||
export const isVideoTypeSupported = (mimeType: MIME.MIMEType): boolean =>
|
||||
SUPPORTED_VIDEO_MIME_TYPES[mimeType] === true;
|
||||
|
||||
export const getSupportedImageTypes = (): Array<MIME.MIMEType> => {
|
||||
const keys = Object.keys(SUPPORTED_IMAGE_MIME_TYPES) as Array<MIME.MIMEType>;
|
||||
return keys.filter(contentType => SUPPORTED_IMAGE_MIME_TYPES[contentType]);
|
||||
};
|
||||
|
||||
export const getSupportedVideoTypes = (): Array<MIME.MIMEType> => {
|
||||
const keys = Object.keys(SUPPORTED_VIDEO_MIME_TYPES) as Array<MIME.MIMEType>;
|
||||
return keys.filter(contentType => SUPPORTED_VIDEO_MIME_TYPES[contentType]);
|
||||
};
|
||||
|
|
|
@ -54,7 +54,7 @@ export async function handleAttachmentsProcessing({
|
|||
for (let i = 0; i < files.length; i += 1) {
|
||||
const file = files[i];
|
||||
const processingResult = preProcessAttachment(file, nextDraftAttachments);
|
||||
if (processingResult) {
|
||||
if (processingResult != null) {
|
||||
onShowToast(processingResult);
|
||||
} else {
|
||||
const pendingAttachment = getPendingAttachment(file);
|
||||
|
|
|
@ -15,7 +15,7 @@ import { handleImageAttachment } from './handleImageAttachment';
|
|||
import { handleVideoAttachment } from './handleVideoAttachment';
|
||||
import { isAttachmentSizeOkay } from './isAttachmentSizeOkay';
|
||||
import { isFileDangerous } from './isFileDangerous';
|
||||
import { isHeic, isImage, stringToMIMEType } from '../types/MIME';
|
||||
import { isHeic, isImage, isVideo, stringToMIMEType } from '../types/MIME';
|
||||
import { isImageTypeSupported, isVideoTypeSupported } from './GoogleChrome';
|
||||
|
||||
export function getPendingAttachment(
|
||||
|
@ -57,19 +57,24 @@ export function preProcessAttachment(
|
|||
return AttachmentToastType.ToastMaxAttachments;
|
||||
}
|
||||
|
||||
const haveNonImage = draftAttachments.some(
|
||||
(attachment: AttachmentDraftType) => !isImage(attachment.contentType)
|
||||
const haveNonImageOrVideo = draftAttachments.some(
|
||||
(attachment: AttachmentDraftType) => {
|
||||
return (
|
||||
!isImage(attachment.contentType) && !isVideo(attachment.contentType)
|
||||
);
|
||||
}
|
||||
);
|
||||
// You can't add another attachment if you already have a non-image staged
|
||||
if (haveNonImage) {
|
||||
return AttachmentToastType.ToastOneNonImageAtATime;
|
||||
if (haveNonImageOrVideo) {
|
||||
return AttachmentToastType.ToastUnsupportedMultiAttachment;
|
||||
}
|
||||
|
||||
const fileType = stringToMIMEType(file.type);
|
||||
const imageOrVideo = isImage(fileType) || isVideo(fileType);
|
||||
|
||||
// You can't add a non-image attachment if you already have attachments staged
|
||||
if (!isImage(fileType) && draftAttachments.length > 0) {
|
||||
return AttachmentToastType.ToastCannotMixImageAndNonImageAttachments;
|
||||
if (!imageOrVideo && draftAttachments.length > 0) {
|
||||
return AttachmentToastType.ToastCannotMixMultiAndNonMultiAttachments;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
|
|
|
@ -8,7 +8,7 @@ import type { ToastAlreadyGroupMember } from '../components/ToastAlreadyGroupMem
|
|||
import type { ToastAlreadyRequestedToJoin } from '../components/ToastAlreadyRequestedToJoin';
|
||||
import type { ToastBlocked } from '../components/ToastBlocked';
|
||||
import type { ToastBlockedGroup } from '../components/ToastBlockedGroup';
|
||||
import type { ToastCannotMixImageAndNonImageAttachments } from '../components/ToastCannotMixImageAndNonImageAttachments';
|
||||
import type { ToastUnsupportedMultiAttachment } from '../components/ToastUnsupportedMultiAttachment';
|
||||
import type {
|
||||
ToastCannotOpenGiftBadge,
|
||||
ToastPropsType as ToastCannotOpenGiftBadgePropsType,
|
||||
|
@ -44,7 +44,7 @@ import type { ToastLinkCopied } from '../components/ToastLinkCopied';
|
|||
import type { ToastLoadingFullLogs } from '../components/ToastLoadingFullLogs';
|
||||
import type { ToastMaxAttachments } from '../components/ToastMaxAttachments';
|
||||
import type { ToastMessageBodyTooLong } from '../components/ToastMessageBodyTooLong';
|
||||
import type { ToastOneNonImageAtATime } from '../components/ToastOneNonImageAtATime';
|
||||
|
||||
import type { ToastOriginalMessageNotFound } from '../components/ToastOriginalMessageNotFound';
|
||||
import type { ToastPinnedConversationsFull } from '../components/ToastPinnedConversationsFull';
|
||||
import type { ToastReactionFailed } from '../components/ToastReactionFailed';
|
||||
|
@ -60,9 +60,7 @@ export function showToast(Toast: typeof ToastAlreadyGroupMember): void;
|
|||
export function showToast(Toast: typeof ToastAlreadyRequestedToJoin): void;
|
||||
export function showToast(Toast: typeof ToastBlocked): void;
|
||||
export function showToast(Toast: typeof ToastBlockedGroup): void;
|
||||
export function showToast(
|
||||
Toast: typeof ToastCannotMixImageAndNonImageAttachments
|
||||
): void;
|
||||
export function showToast(Toast: typeof ToastUnsupportedMultiAttachment): void;
|
||||
export function showToast(Toast: typeof ToastCannotStartGroupCall): void;
|
||||
export function showToast(
|
||||
Toast: typeof ToastCannotOpenGiftBadge,
|
||||
|
@ -98,7 +96,7 @@ export function showToast(Toast: typeof ToastLinkCopied): void;
|
|||
export function showToast(Toast: typeof ToastLoadingFullLogs): void;
|
||||
export function showToast(Toast: typeof ToastMaxAttachments): void;
|
||||
export function showToast(Toast: typeof ToastMessageBodyTooLong): void;
|
||||
export function showToast(Toast: typeof ToastOneNonImageAtATime): void;
|
||||
export function showToast(Toast: typeof ToastUnsupportedMultiAttachment): void;
|
||||
export function showToast(Toast: typeof ToastOriginalMessageNotFound): void;
|
||||
export function showToast(Toast: typeof ToastPinnedConversationsFull): void;
|
||||
export function showToast(Toast: typeof ToastReactionFailed): void;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue