stream-chat-react-native-core 5.17.1-beta.1 → 5.17.1

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 (25) hide show
  1. package/lib/commonjs/components/AttachmentPicker/AttachmentPicker.js +7 -5
  2. package/lib/commonjs/components/AttachmentPicker/AttachmentPicker.js.map +1 -1
  3. package/lib/commonjs/components/AttachmentPicker/components/AttachmentPickerItem.js +153 -39
  4. package/lib/commonjs/components/AttachmentPicker/components/AttachmentPickerItem.js.map +1 -1
  5. package/lib/commonjs/components/Channel/Channel.js +46 -58
  6. package/lib/commonjs/components/Channel/Channel.js.map +1 -1
  7. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +25 -36
  8. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  9. package/lib/commonjs/version.json +1 -1
  10. package/lib/module/components/AttachmentPicker/AttachmentPicker.js +7 -5
  11. package/lib/module/components/AttachmentPicker/AttachmentPicker.js.map +1 -1
  12. package/lib/module/components/AttachmentPicker/components/AttachmentPickerItem.js +153 -39
  13. package/lib/module/components/AttachmentPicker/components/AttachmentPickerItem.js.map +1 -1
  14. package/lib/module/components/Channel/Channel.js +46 -58
  15. package/lib/module/components/Channel/Channel.js.map +1 -1
  16. package/lib/module/contexts/messageInputContext/MessageInputContext.js +25 -36
  17. package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  18. package/lib/module/version.json +1 -1
  19. package/lib/typescript/components/AttachmentPicker/components/AttachmentPickerItem.d.ts +3 -5
  20. package/package.json +1 -1
  21. package/src/components/AttachmentPicker/AttachmentPicker.tsx +7 -2
  22. package/src/components/AttachmentPicker/components/AttachmentPickerItem.tsx +77 -35
  23. package/src/components/Channel/Channel.tsx +4 -8
  24. package/src/contexts/messageInputContext/MessageInputContext.tsx +3 -5
  25. package/src/version.json +1 -1
@@ -1,30 +1,32 @@
1
1
  import React from 'react';
2
2
 
3
- import { Alert, ImageBackground, StyleSheet, Text, View } from 'react-native';
3
+ import { Alert, ImageBackground, Platform, StyleSheet, Text, View } from 'react-native';
4
4
 
5
5
  import { TouchableOpacity } from '@gorhom/bottom-sheet';
6
6
  import dayjs from 'dayjs';
7
7
  import { lookup } from 'mime-types';
8
8
 
9
+ import type { AttachmentPickerContextValue } from '../../../contexts/attachmentPickerContext/AttachmentPickerContext';
9
10
  import { useTheme } from '../../../contexts/themeContext/ThemeContext';
10
11
  import { Recorder } from '../../../icons';
12
+ import { getLocalAssetUri } from '../../../native';
11
13
  import type { Asset, File } from '../../../types/types';
12
14
  import { vw } from '../../../utils/utils';
13
15
 
14
- type AttachmentPickerItemType = {
16
+ type AttachmentPickerItemType = Pick<
17
+ AttachmentPickerContextValue,
18
+ 'selectedFiles' | 'setSelectedFiles' | 'setSelectedImages' | 'selectedImages' | 'maxNumberOfFiles'
19
+ > & {
15
20
  asset: Asset;
16
21
  ImageOverlaySelectedComponent: React.ComponentType;
17
- maxNumberOfFiles: number;
18
22
  numberOfUploads: number;
19
23
  selected: boolean;
20
- setSelectedFiles: React.Dispatch<React.SetStateAction<File[]>>;
21
- setSelectedImages: React.Dispatch<React.SetStateAction<Asset[]>>;
22
24
  numberOfAttachmentPickerImageColumns?: number;
23
25
  };
24
26
 
25
- type AttachmentImageProps = Omit<AttachmentPickerItemType, 'setSelectedFiles'>;
27
+ type AttachmentImageProps = Omit<AttachmentPickerItemType, 'setSelectedFiles' | 'selectedFiles'>;
26
28
 
27
- type AttachmentVideoProps = Omit<AttachmentPickerItemType, 'setSelectedImages'>;
29
+ type AttachmentVideoProps = Omit<AttachmentPickerItemType, 'setSelectedImages' | 'selectedImages'>;
28
30
 
29
31
  const AttachmentVideo: React.FC<AttachmentVideoProps> = (props) => {
30
32
  const {
@@ -34,6 +36,7 @@ const AttachmentVideo: React.FC<AttachmentVideoProps> = (props) => {
34
36
  numberOfAttachmentPickerImageColumns,
35
37
  numberOfUploads,
36
38
  selected,
39
+ selectedFiles,
37
40
  setSelectedFiles,
38
41
  } = props;
39
42
 
@@ -61,29 +64,43 @@ const AttachmentVideo: React.FC<AttachmentVideoProps> = (props) => {
61
64
 
62
65
  const size = vw(100) / (numberOfAttachmentPickerImageColumns || 3) - 2;
63
66
 
67
+ /* Patches video files with uri and mimetype */
68
+ const patchVideoFile = async (files: File[]) => {
69
+ // For the case of Expo CLI where you need to fetch the file uri from file id. Here it is only done for iOS since for android the file.uri is fine.
70
+ const localAssetURI = Platform.OS === 'ios' && asset.id && (await getLocalAssetUri(asset.id));
71
+ const uri = localAssetURI || asset.uri || '';
72
+ // We need a mime-type to upload a video file.
73
+ const mimeType = lookup(asset.filename) || 'multipart/form-data';
74
+ return [
75
+ ...files,
76
+ {
77
+ duration: durationLabel,
78
+ id: asset.id,
79
+ mimeType,
80
+ name: asset.filename,
81
+ size: asset.fileSize,
82
+ uri,
83
+ },
84
+ ];
85
+ };
86
+
87
+ const updateSelectedFiles = async () => {
88
+ if (numberOfUploads >= maxNumberOfFiles) {
89
+ Alert.alert('Maximum number of files reached');
90
+ return;
91
+ }
92
+ const files = await patchVideoFile(selectedFiles);
93
+ setSelectedFiles(files);
94
+ };
95
+
64
96
  const onPressVideo = () => {
65
97
  if (selected) {
66
- setSelectedFiles((files) => files.filter((file) => file.uri !== asset.uri));
98
+ setSelectedFiles((files) =>
99
+ // `id` is available for Expo MediaLibrary while Cameraroll doesn't share id therefore we use `uri`
100
+ files.filter((file) => (file.id ? file.id !== asset.id : file.uri !== asset.uri)),
101
+ );
67
102
  } else {
68
- setSelectedFiles((files) => {
69
- if (numberOfUploads >= maxNumberOfFiles) {
70
- Alert.alert('Maximum number of files reached');
71
- return files;
72
- }
73
- // We need a mime-type to upload a video file.
74
- const mimeType = lookup(asset.filename) || 'multipart/form-data';
75
- return [
76
- ...files,
77
- {
78
- duration: durationLabel,
79
- id: asset.id,
80
- mimeType,
81
- name: asset.filename,
82
- size: asset.fileSize,
83
- uri: asset.uri,
84
- },
85
- ];
86
- });
103
+ updateSelectedFiles();
87
104
  }
88
105
  };
89
106
 
@@ -126,6 +143,7 @@ const AttachmentImage: React.FC<AttachmentImageProps> = (props) => {
126
143
  numberOfAttachmentPickerImageColumns,
127
144
  numberOfUploads,
128
145
  selected,
146
+ selectedImages,
129
147
  setSelectedImages,
130
148
  } = props;
131
149
  const {
@@ -139,17 +157,37 @@ const AttachmentImage: React.FC<AttachmentImageProps> = (props) => {
139
157
 
140
158
  const { uri } = asset;
141
159
 
160
+ /* Patches image files with uri */
161
+ const patchImageFile = async (images: Asset[]) => {
162
+ // For the case of Expo CLI where you need to fetch the file uri from file id. Here it is only done for iOS since for android the file.uri is fine.
163
+ const localAssetURI = Platform.OS === 'ios' && asset.id && (await getLocalAssetUri(asset.id));
164
+ const uri = localAssetURI || asset.uri || '';
165
+ return [
166
+ ...images,
167
+ {
168
+ ...asset,
169
+ uri,
170
+ },
171
+ ];
172
+ };
173
+
174
+ const updateSelectedImages = async () => {
175
+ if (numberOfUploads >= maxNumberOfFiles) {
176
+ Alert.alert('Maximum number of files reached');
177
+ return;
178
+ }
179
+ const images = await patchImageFile(selectedImages);
180
+ setSelectedImages(images);
181
+ };
182
+
142
183
  const onPressImage = () => {
143
184
  if (selected) {
144
- setSelectedImages((images) => images.filter((image) => image.uri !== asset.uri));
185
+ // `id` is available for Expo MediaLibrary while Cameraroll doesn't share id therefore we use `uri`
186
+ setSelectedImages((images) =>
187
+ images.filter((image) => (image.id ? image.id !== asset.id : image.uri !== asset.uri)),
188
+ );
145
189
  } else {
146
- setSelectedImages((images) => {
147
- if (numberOfUploads >= maxNumberOfFiles) {
148
- Alert.alert('Maximum number of files reached');
149
- return images;
150
- }
151
- return [...images, asset];
152
- });
190
+ updateSelectedImages();
153
191
  }
154
192
  };
155
193
 
@@ -184,6 +222,8 @@ export const renderAttachmentPickerItem = ({ item }: { item: AttachmentPickerIte
184
222
  numberOfAttachmentPickerImageColumns,
185
223
  numberOfUploads,
186
224
  selected,
225
+ selectedFiles,
226
+ selectedImages,
187
227
  setSelectedFiles,
188
228
  setSelectedImages,
189
229
  } = item;
@@ -205,6 +245,7 @@ export const renderAttachmentPickerItem = ({ item }: { item: AttachmentPickerIte
205
245
  numberOfAttachmentPickerImageColumns={numberOfAttachmentPickerImageColumns}
206
246
  numberOfUploads={numberOfUploads}
207
247
  selected={selected}
248
+ selectedFiles={selectedFiles}
208
249
  setSelectedFiles={setSelectedFiles}
209
250
  />
210
251
  );
@@ -218,6 +259,7 @@ export const renderAttachmentPickerItem = ({ item }: { item: AttachmentPickerIte
218
259
  numberOfAttachmentPickerImageColumns={numberOfAttachmentPickerImageColumns}
219
260
  numberOfUploads={numberOfUploads}
220
261
  selected={selected}
262
+ selectedImages={selectedImages}
221
263
  setSelectedImages={setSelectedImages}
222
264
  />
223
265
  );
@@ -1,5 +1,5 @@
1
1
  import React, { PropsWithChildren, useCallback, useEffect, useRef, useState } from 'react';
2
- import { KeyboardAvoidingViewProps, Platform, StyleSheet, Text, View } from 'react-native';
2
+ import { KeyboardAvoidingViewProps, StyleSheet, Text, View } from 'react-native';
3
3
 
4
4
  import debounce from 'lodash/debounce';
5
5
  import throttle from 'lodash/throttle';
@@ -74,7 +74,7 @@ import {
74
74
  ThumbsUpReaction,
75
75
  WutReaction,
76
76
  } from '../../icons';
77
- import { FlatList as FlatListDefault, getLocalAssetUri, pickDocument } from '../../native';
77
+ import { FlatList as FlatListDefault, pickDocument } from '../../native';
78
78
  import * as dbApi from '../../store/apis';
79
79
  import type { DefaultStreamChatGenerics } from '../../types/types';
80
80
  import { addReactionToLocalState } from '../../utils/addReactionToLocalState';
@@ -1295,16 +1295,12 @@ const ChannelWithContext = <
1295
1295
  attachment.image_url &&
1296
1296
  isLocalUrl(attachment.image_url)
1297
1297
  ) {
1298
- // For the case of Expo CLI where you need to fetch the file uri from file id. Here it is only done for iOS since for android the file.uri is fine.
1299
- const localAssetURI =
1300
- Platform.OS === 'ios' && file.id && (await getLocalAssetUri(file.id));
1301
- const uri = localAssetURI || file.uri || '';
1302
- const filename = file.name ?? uri.replace(/^(file:\/\/|content:\/\/)/, '');
1298
+ const filename = file.name ?? file.uri.replace(/^(file:\/\/|content:\/\/)/, '');
1303
1299
  const contentType = lookup(filename) || 'multipart/form-data';
1304
1300
 
1305
1301
  const uploadResponse = doImageUploadRequest
1306
1302
  ? await doImageUploadRequest(file, channel)
1307
- : await channel.sendImage(uri, filename, contentType);
1303
+ : await channel.sendImage(file.uri, filename, contentType);
1308
1304
 
1309
1305
  attachment.image_url = uploadResponse.file;
1310
1306
  delete attachment.originalFile;
@@ -1,7 +1,7 @@
1
1
  import type { LegacyRef } from 'react';
2
2
  import React, { PropsWithChildren, useContext, useEffect, useRef, useState } from 'react';
3
3
  import type { TextInput, TextInputProps } from 'react-native';
4
- import { Alert, Keyboard, Platform } from 'react-native';
4
+ import { Alert, Keyboard } from 'react-native';
5
5
 
6
6
  import uniq from 'lodash/uniq';
7
7
  import { lookup } from 'mime-types';
@@ -35,7 +35,7 @@ import type { MoreOptionsButtonProps } from '../../components/MessageInput/MoreO
35
35
  import type { SendButtonProps } from '../../components/MessageInput/SendButton';
36
36
  import type { UploadProgressIndicatorProps } from '../../components/MessageInput/UploadProgressIndicator';
37
37
  import type { MessageType } from '../../components/MessageList/hooks/useMessageList';
38
- import { compressImage, getLocalAssetUri, pickDocument } from '../../native';
38
+ import { compressImage, pickDocument } from '../../native';
39
39
  import type { Asset, DefaultStreamChatGenerics, File, UnknownType } from '../../types/types';
40
40
  import { removeReservedFields } from '../../utils/removeReservedFields';
41
41
  import {
@@ -984,9 +984,7 @@ export const MessageInputProvider = <
984
984
  let response = {} as SendFileAPIResponse;
985
985
 
986
986
  try {
987
- // For the case of Expo CLI where you need to fetch the file uri from file id. Here it is only done for iOS since for android the file.uri is fine.
988
- const localAssetURI = Platform.OS === 'ios' && file.id && (await getLocalAssetUri(file.id));
989
- const uri = localAssetURI || file.uri || '';
987
+ const uri = file.uri || '';
990
988
  /**
991
989
  * We skip compression if:
992
990
  * - the file is from the camera as that should already be compressed
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.17.1-beta.1"
2
+ "version": "5.17.1"
3
3
  }