about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/view/com/composer/Composer.tsx8
-rw-r--r--src/view/com/composer/text-input/TextInput.web.tsx24
2 files changed, 23 insertions, 9 deletions
diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx
index a637b5996..4c7892bc0 100644
--- a/src/view/com/composer/Composer.tsx
+++ b/src/view/com/composer/Composer.tsx
@@ -303,9 +303,13 @@ export const ComposePost = observer(function ComposePost({
   const onPhotoPasted = useCallback(
     async (uri: string) => {
       track('Composer:PastedPhotos')
-      await gallery.paste(uri)
+      if (uri.startsWith('data:video/')) {
+        selectVideo({uri, type: 'video', height: 0, width: 0})
+      } else {
+        await gallery.paste(uri)
+      }
     },
-    [gallery, track],
+    [gallery, track, selectVideo],
   )
 
   const isAltTextRequiredAndMissing = useMemo(() => {
diff --git a/src/view/com/composer/text-input/TextInput.web.tsx b/src/view/com/composer/text-input/TextInput.web.tsx
index c477ada06..3db25746f 100644
--- a/src/view/com/composer/text-input/TextInput.web.tsx
+++ b/src/view/com/composer/text-input/TextInput.web.tsx
@@ -93,9 +93,9 @@ export const TextInput = React.forwardRef(function TextInputImpl(
     }
   }, [onPressPublish])
   React.useEffect(() => {
-    textInputWebEmitter.addListener('photo-pasted', onPhotoPasted)
+    textInputWebEmitter.addListener('media-pasted', onPhotoPasted)
     return () => {
-      textInputWebEmitter.removeListener('photo-pasted', onPhotoPasted)
+      textInputWebEmitter.removeListener('media-pasted', onPhotoPasted)
     }
   }, [onPhotoPasted])
 
@@ -105,8 +105,8 @@ export const TextInput = React.forwardRef(function TextInputImpl(
       if (transfer) {
         const items = transfer.items
 
-        getImageFromUri(items, (uri: string) => {
-          textInputWebEmitter.emit('photo-pasted', uri)
+        getImageOrVideoFromUri(items, (uri: string) => {
+          textInputWebEmitter.emit('media-pasted', uri)
         })
       }
 
@@ -160,8 +160,8 @@ export const TextInput = React.forwardRef(function TextInputImpl(
               view.pasteText(text)
               preventDefault = true
             }
-            getImageFromUri(clipboardData.items, (uri: string) => {
-              textInputWebEmitter.emit('photo-pasted', uri)
+            getImageOrVideoFromUri(clipboardData.items, (uri: string) => {
+              textInputWebEmitter.emit('media-pasted', uri)
             })
             if (preventDefault) {
               // Return `true` to prevent ProseMirror's default paste behavior.
@@ -346,7 +346,7 @@ const styles = StyleSheet.create({
   },
 })
 
-function getImageFromUri(
+function getImageOrVideoFromUri(
   items: DataTransferItemList,
   callback: (uri: string) => void,
 ) {
@@ -363,6 +363,10 @@ function getImageFromUri(
           if (blob.type.startsWith('image/')) {
             blobToDataUri(blob).then(callback, err => console.error(err))
           }
+
+          if (blob.type.startsWith('video/')) {
+            blobToDataUri(blob).then(callback, err => console.error(err))
+          }
         }
       })
     } else if (type.startsWith('image/')) {
@@ -371,6 +375,12 @@ function getImageFromUri(
       if (file) {
         blobToDataUri(file).then(callback, err => console.error(err))
       }
+    } else if (type.startsWith('video/')) {
+      const file = item.getAsFile()
+
+      if (file) {
+        blobToDataUri(file).then(callback, err => console.error(err))
+      }
     }
   }
 }