@droppii-org/chat-mobile 0.2.16 → 0.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/lib/module/components/AttachmentPreview.js +9 -7
  2. package/lib/module/components/AttachmentPreview.js.map +1 -1
  3. package/lib/module/components/MergedImageGrid.js +28 -18
  4. package/lib/module/components/MergedImageGrid.js.map +1 -1
  5. package/lib/module/components/messages/mergedMessage/index.js +4 -7
  6. package/lib/module/components/messages/mergedMessage/index.js.map +1 -1
  7. package/lib/module/hooks/useImageAttachment.js +16 -8
  8. package/lib/module/hooks/useImageAttachment.js.map +1 -1
  9. package/lib/module/hooks/useVideoAttachment.js +1 -1
  10. package/lib/module/screens/MediaView/VideoPlayer.js +1 -0
  11. package/lib/module/screens/MediaView/VideoPlayer.js.map +1 -1
  12. package/lib/module/screens/MediaView/index.js +7 -9
  13. package/lib/module/screens/MediaView/index.js.map +1 -1
  14. package/lib/module/screens/chat-detail/ChatListLegend.js +11 -2
  15. package/lib/module/screens/chat-detail/ChatListLegend.js.map +1 -1
  16. package/lib/module/services/attachmentHandlers/videoAttachmentHandler.js +1 -1
  17. package/lib/module/translation/resources/i18n.js +1 -0
  18. package/lib/module/translation/resources/i18n.js.map +1 -1
  19. package/lib/module/utils/videoThumbnail.js +76 -3
  20. package/lib/module/utils/videoThumbnail.js.map +1 -1
  21. package/lib/typescript/src/components/AttachmentPreview.d.ts.map +1 -1
  22. package/lib/typescript/src/components/MergedImageGrid.d.ts +2 -2
  23. package/lib/typescript/src/components/MergedImageGrid.d.ts.map +1 -1
  24. package/lib/typescript/src/components/messages/mergedMessage/index.d.ts.map +1 -1
  25. package/lib/typescript/src/hooks/useImageAttachment.d.ts.map +1 -1
  26. package/lib/typescript/src/screens/MediaView/VideoPlayer.d.ts.map +1 -1
  27. package/lib/typescript/src/screens/MediaView/index.d.ts.map +1 -1
  28. package/lib/typescript/src/screens/chat-detail/ChatListLegend.d.ts.map +1 -1
  29. package/lib/typescript/src/translation/resources/i18n.d.ts.map +1 -1
  30. package/lib/typescript/src/utils/videoThumbnail.d.ts.map +1 -1
  31. package/package.json +1 -1
  32. package/src/components/AttachmentPreview.tsx +11 -5
  33. package/src/components/MergedImageGrid.tsx +36 -23
  34. package/src/components/messages/mergedMessage/index.tsx +5 -7
  35. package/src/hooks/useImageAttachment.ts +22 -12
  36. package/src/hooks/useVideoAttachment.ts +1 -1
  37. package/src/screens/MediaView/VideoPlayer.tsx +1 -0
  38. package/src/screens/MediaView/index.tsx +7 -6
  39. package/src/screens/chat-detail/ChatListLegend.tsx +9 -2
  40. package/src/services/attachmentHandlers/videoAttachmentHandler.ts +1 -1
  41. package/src/translation/resources/i18n.ts +1 -0
  42. package/src/utils/videoThumbnail.ts +77 -3
@@ -1,3 +1,4 @@
1
+ import { Platform } from 'react-native';
1
2
  import RNFS from 'react-native-fs';
2
3
  import { createThumbnail } from 'react-native-create-thumbnail';
3
4
 
@@ -13,6 +14,64 @@ interface ThumbnailResult {
13
14
  height: number;
14
15
  }
15
16
 
17
+ /**
18
+ * Routes the video source so react-native-create-thumbnail picks the correct
19
+ * native MediaMetadataRetriever.setDataSource overload.
20
+ *
21
+ * Root cause of the Android crash: CreateThumbnailModule.getBitmapAtTime branches
22
+ * on the URL scheme —
23
+ * - "file://..." -> setDataSource(String) ✅ works for local files
24
+ * - "content://" -> setDataSource(Context, Uri)
25
+ * - otherwise -> setDataSource(String, Map headers) ❌ this overload is for
26
+ * REMOTE URIs; a bare local path makes it throw an uncaught
27
+ * RuntimeException (status 0xFFFFFFEA / EINVAL) → app crash.
28
+ * The app strips "file://" before calling, so local videos fall into the broken
29
+ * branch. The fix is to KEEP the file:// scheme so the working overload is used.
30
+ *
31
+ * For Android photo-picker synthetic paths we additionally copy the file into the
32
+ * app cache first (a clean, app-private file the retriever can always open) and
33
+ * still hand it back with a file:// prefix. Returns the path to pass to
34
+ * createThumbnail plus a raw cleanup path for any temp copy.
35
+ */
36
+ const ensureRetrievableVideoPath = async (
37
+ videoPath: string
38
+ ): Promise<{ path: string; cleanupPath: string | null }> => {
39
+ // iOS (and any non-Android platform) is left completely untouched.
40
+ if (Platform.OS !== 'android') {
41
+ return { path: videoPath, cleanupPath: null };
42
+ }
43
+
44
+ // content:// is handled by a dedicated native branch — pass through unchanged.
45
+ if (videoPath.startsWith('content://')) {
46
+ return { path: videoPath, cleanupPath: null };
47
+ }
48
+
49
+ const rawPath = videoPath.startsWith('file://')
50
+ ? videoPath.replace('file://', '')
51
+ : videoPath;
52
+
53
+ const isSynthetic =
54
+ rawPath.includes('/.transforms/') || rawPath.includes('/synthetic/');
55
+
56
+ if (isSynthetic) {
57
+ const ext = (rawPath.split('.').pop() || 'mp4').split('?')[0];
58
+ const dest = `${RNFS.CachesDirectoryPath}/video-thumb-src-${Date.now()}-${Math.floor(
59
+ Math.random() * 1e6
60
+ )}.${ext}`;
61
+
62
+ console.log(
63
+ '[VideoThumbnail] Copying picker video to cache before thumbnail',
64
+ { from: rawPath, to: dest }
65
+ );
66
+ await RNFS.copyFile(rawPath, dest);
67
+ return { path: `file://${dest}`, cleanupPath: dest };
68
+ }
69
+
70
+ // Any other local path: ensure the file:// scheme so the native module routes
71
+ // to setDataSource(String) instead of the broken (String, Map) overload.
72
+ return { path: `file://${rawPath}`, cleanupPath: null };
73
+ };
74
+
16
75
  export const VideoThumbnailUtil = {
17
76
  generateThumbnail: async (
18
77
  videoPath: string,
@@ -20,10 +79,18 @@ export const VideoThumbnailUtil = {
20
79
  ): Promise<ThumbnailResult | null> => {
21
80
  const { time = 800, quality = 80, cacheId } = options; // time in milliseconds
22
81
 
82
+ let tempSourcePath: string | null = null;
83
+
23
84
  try {
85
+ // Normalize the source so the native MediaMetadataRetriever can open it.
86
+ // Android picker paths crash the app otherwise (see ensureRetrievableVideoPath).
87
+ const { path: retrievablePath, cleanupPath } =
88
+ await ensureRetrievableVideoPath(videoPath);
89
+ tempSourcePath = cleanupPath;
90
+
24
91
  // Generate unique cache name per video to avoid conflicts with concurrent generations
25
92
  // Uses provided cacheId or generates one from videoPath filename
26
- const fileName = videoPath.split('/').pop() || String(Date.now());
93
+ const fileName = retrievablePath.split('/').pop() || String(Date.now());
27
94
  const cacheName =
28
95
  cacheId ||
29
96
  `thumb-${fileName.replace(/[^a-zA-Z0-9-_]/g, '')}-${Math.abs(
@@ -31,14 +98,14 @@ export const VideoThumbnailUtil = {
31
98
  )}`;
32
99
 
33
100
  console.log('[VideoThumbnail] Generating thumbnail', {
34
- videoPath,
101
+ videoPath: retrievablePath,
35
102
  timeMs: time,
36
103
  quality,
37
104
  cacheName,
38
105
  });
39
106
 
40
107
  const result = await createThumbnail({
41
- url: videoPath,
108
+ url: retrievablePath,
42
109
  timeStamp: time,
43
110
  format: 'png',
44
111
  dirSize: 100,
@@ -60,6 +127,13 @@ export const VideoThumbnailUtil = {
60
127
  } catch (error) {
61
128
  console.error('[VideoThumbnail] Failed to generate thumbnail', error);
62
129
  return null;
130
+ } finally {
131
+ // Remove the temporary video copy made for synthetic/content sources.
132
+ if (tempSourcePath) {
133
+ RNFS.unlink(tempSourcePath).catch((err) =>
134
+ console.warn('[VideoThumbnail] Temp source cleanup failed:', err)
135
+ );
136
+ }
63
137
  }
64
138
  },
65
139