stream-chat-react-native 9.0.0-beta.8 → 9.0.0

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.
@@ -1,6 +1,11 @@
1
1
  import { Platform } from 'react-native';
2
+
2
3
  import mime from 'mime';
4
+
3
5
  import { PickImageOptions } from 'stream-chat-react-native-core';
6
+
7
+ import { generateThumbnails } from './generateThumbnail';
8
+
4
9
  let ImagePicker;
5
10
 
6
11
  try {
@@ -24,17 +29,37 @@ export const pickImage = ImagePicker
24
29
  return { askToOpenSettings: true, cancelled: true };
25
30
  }
26
31
  if (!canceled) {
27
- const assets = result.assets.map((asset) => ({
28
- ...asset,
29
- duration: asset.duration ? asset.duration * 1000 : undefined, // in milliseconds
30
- name: asset.fileName,
31
- size: asset.fileSize,
32
- type:
32
+ const assetsWithType = result.assets.map((asset) => {
33
+ const type =
33
34
  asset.type ||
34
35
  mime.getType(asset.fileName || asset.uri) ||
35
- (asset.duration ? 'video/*' : 'image/*'),
36
- uri: asset.uri,
37
- }));
36
+ (asset.duration ? 'video/*' : 'image/*');
37
+
38
+ return {
39
+ asset,
40
+ isVideo: type.includes('video'),
41
+ type,
42
+ };
43
+ });
44
+ const videoUris = assetsWithType
45
+ .filter(({ asset, isVideo }) => isVideo && !!asset.uri)
46
+ .map(({ asset }) => asset.uri);
47
+ const videoThumbnailResults = await generateThumbnails(videoUris);
48
+
49
+ const assets = assetsWithType.map(({ asset, isVideo, type }) => {
50
+ const thumbnailResult =
51
+ isVideo && asset.uri ? videoThumbnailResults[asset.uri] : undefined;
52
+
53
+ return {
54
+ ...asset,
55
+ duration: asset.duration ? asset.duration * 1000 : undefined, // in milliseconds
56
+ name: asset.fileName,
57
+ size: asset.fileSize,
58
+ thumb_url: thumbnailResult?.uri || undefined,
59
+ type,
60
+ uri: asset.uri,
61
+ };
62
+ });
38
63
  return { assets, cancelled: false };
39
64
  } else {
40
65
  return { cancelled: true };
@@ -1,6 +1,9 @@
1
1
  import { AppState, Image, PermissionsAndroid, Platform } from 'react-native';
2
+
2
3
  import mime from 'mime';
3
4
 
5
+ import { generateThumbnails } from './generateThumbnail';
6
+
4
7
  let ImagePicker;
5
8
 
6
9
  try {
@@ -54,12 +57,16 @@ export const takePhoto = ImagePicker
54
57
  if (assetType.includes('video')) {
55
58
  const clearFilter = new RegExp('[.:]', 'g');
56
59
  const date = new Date().toISOString().replace(clearFilter, '_');
60
+ const thumbnailResults = await generateThumbnails([asset.uri]);
61
+ const thumbnailResult = thumbnailResults[asset.uri];
62
+
57
63
  return {
58
64
  ...asset,
59
65
  cancelled: false,
60
66
  duration: asset.duration * 1000,
61
67
  name: 'video_recording_' + date + '.' + asset.fileName.split('.').pop(),
62
68
  size: asset.fileSize,
69
+ thumb_url: thumbnailResult?.uri || undefined,
63
70
  type: assetType,
64
71
  uri: asset.uri,
65
72
  };