Allow feature-gated 10-minute video uploads (#11388)
This commit is contained in:
@@ -6,6 +6,7 @@ import {msg, plural} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {
|
||||
VIDEO_10_MINUTE_MAX_DURATION_MS,
|
||||
VIDEO_MAX_DURATION_MS,
|
||||
VIDEO_MAX_SIZE,
|
||||
VIDEO_MAX_SIZE_MB,
|
||||
@@ -22,6 +23,7 @@ import {Button} from '#/components/Button'
|
||||
import {useSheetWrapper} from '#/components/Dialog/sheet-wrapper'
|
||||
import {Image_Stroke2_Corner0_Rounded as ImageIcon} from '#/components/icons/Image'
|
||||
import * as toast from '#/components/Toast'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {IS_NATIVE, IS_WEB} from '#/env'
|
||||
import {isAnimatedGif} from './videos/isAnimatedGif'
|
||||
import {hasWebCodecs} from './videos/metadata'
|
||||
@@ -236,9 +238,11 @@ async function processImagePickerAssets(
|
||||
{
|
||||
selectionCountRemaining,
|
||||
allowedAssetTypes,
|
||||
videoMaxDurationMs,
|
||||
}: {
|
||||
selectionCountRemaining: number
|
||||
allowedAssetTypes: AssetType | undefined
|
||||
videoMaxDurationMs: number
|
||||
},
|
||||
) {
|
||||
/*
|
||||
@@ -362,7 +366,7 @@ async function processImagePickerAssets(
|
||||
supportedAssets[0].duration = supportedAssets[0].duration * 1000
|
||||
}
|
||||
|
||||
if (supportedAssets[0].duration > VIDEO_MAX_DURATION_MS) {
|
||||
if (supportedAssets[0].duration > videoMaxDurationMs) {
|
||||
errors.add(SelectedAssetError.VideoTooLong)
|
||||
supportedAssets = []
|
||||
}
|
||||
@@ -393,6 +397,13 @@ export function SelectMediaButton({
|
||||
autoOpen,
|
||||
}: SelectMediaButtonProps) {
|
||||
const {_} = useLingui()
|
||||
const ax = useAnalytics()
|
||||
const allow10MinuteVideos = ax.features.enabled(
|
||||
ax.features.VideoAllow10MinuteEnable,
|
||||
)
|
||||
const videoMaxDurationMs = allow10MinuteVideos
|
||||
? VIDEO_10_MINUTE_MAX_DURATION_MS
|
||||
: VIDEO_MAX_DURATION_MS
|
||||
const {requestPhotoAccessIfNeeded} = usePhotoLibraryPermission()
|
||||
const {requestVideoAccessIfNeeded} = useVideoLibraryPermission()
|
||||
const sheetWrapper = useSheetWrapper()
|
||||
@@ -412,6 +423,7 @@ export function SelectMediaButton({
|
||||
} = await processImagePickerAssets(rawAssets, {
|
||||
selectionCountRemaining,
|
||||
allowedAssetTypes,
|
||||
videoMaxDurationMs,
|
||||
})
|
||||
|
||||
/*
|
||||
@@ -436,9 +448,9 @@ export function SelectMediaButton({
|
||||
[SelectedAssetError.MaxVideos]: _(
|
||||
msg`You can only select one video at a time.`,
|
||||
),
|
||||
[SelectedAssetError.VideoTooLong]: _(
|
||||
msg`Videos must be less than 3 minutes long.`,
|
||||
),
|
||||
[SelectedAssetError.VideoTooLong]: allow10MinuteVideos
|
||||
? _(msg`Videos must be 10 minutes or less.`)
|
||||
: _(msg`Videos must be less than 3 minutes long.`),
|
||||
[SelectedAssetError.MaxGIFs]: _(
|
||||
msg`You can only select one GIF at a time.`,
|
||||
),
|
||||
@@ -458,7 +470,14 @@ export function SelectMediaButton({
|
||||
errors,
|
||||
})
|
||||
},
|
||||
[_, onSelectAssets, selectionCountRemaining, allowedAssetTypes],
|
||||
[
|
||||
_,
|
||||
onSelectAssets,
|
||||
selectionCountRemaining,
|
||||
allowedAssetTypes,
|
||||
videoMaxDurationMs,
|
||||
allow10MinuteVideos,
|
||||
],
|
||||
)
|
||||
|
||||
const onPressSelectMedia = useCallback(async () => {
|
||||
@@ -481,7 +500,7 @@ export function SelectMediaButton({
|
||||
}
|
||||
|
||||
const {assets, canceled} = await sheetWrapper(
|
||||
openUnifiedPicker({selectionCountRemaining}),
|
||||
openUnifiedPicker({selectionCountRemaining, videoMaxDurationMs}),
|
||||
)
|
||||
|
||||
if (canceled) return
|
||||
@@ -494,6 +513,7 @@ export function SelectMediaButton({
|
||||
sheetWrapper,
|
||||
processSelectedAssets,
|
||||
selectionCountRemaining,
|
||||
videoMaxDurationMs,
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user