stream-chat-react-native-core 5.36.1-beta.1 → 5.36.1-beta.3
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.
- package/lib/commonjs/components/AttachmentPicker/components/AttachmentPickerItem.js.map +1 -1
- package/lib/commonjs/components/ChannelList/ChannelListMessenger.js +0 -5
- package/lib/commonjs/components/ChannelList/ChannelListMessenger.js.map +1 -1
- package/lib/commonjs/components/MessageInput/FileUploadPreview.js +1 -0
- package/lib/commonjs/components/MessageInput/FileUploadPreview.js.map +1 -1
- package/lib/commonjs/components/MessageInput/MessageInput.js +116 -47
- package/lib/commonjs/components/MessageInput/MessageInput.js.map +1 -1
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +283 -226
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/commonjs/contexts/messageInputContext/hooks/useMessageDetailsForState.js +11 -5
- package/lib/commonjs/contexts/messageInputContext/hooks/useMessageDetailsForState.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/AttachmentPicker/components/AttachmentPickerItem.js.map +1 -1
- package/lib/module/components/ChannelList/ChannelListMessenger.js +0 -5
- package/lib/module/components/ChannelList/ChannelListMessenger.js.map +1 -1
- package/lib/module/components/MessageInput/FileUploadPreview.js +1 -0
- package/lib/module/components/MessageInput/FileUploadPreview.js.map +1 -1
- package/lib/module/components/MessageInput/MessageInput.js +116 -47
- package/lib/module/components/MessageInput/MessageInput.js.map +1 -1
- package/lib/module/contexts/messageInputContext/MessageInputContext.js +283 -226
- package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/module/contexts/messageInputContext/hooks/useMessageDetailsForState.js +11 -5
- package/lib/module/contexts/messageInputContext/hooks/useMessageDetailsForState.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/AttachmentPicker/components/AttachmentPickerItem.d.ts +1 -1
- package/lib/typescript/components/AttachmentPicker/components/AttachmentPickerItem.d.ts.map +1 -1
- package/lib/typescript/components/ChannelList/ChannelListMessenger.d.ts.map +1 -1
- package/lib/typescript/components/MessageInput/FileUploadPreview.d.ts.map +1 -1
- package/lib/typescript/components/MessageInput/MessageInput.d.ts +1 -1
- package/lib/typescript/components/MessageInput/MessageInput.d.ts.map +1 -1
- package/lib/typescript/contexts/messageContext/MessageContext.d.ts +1 -1
- package/lib/typescript/contexts/messageInputContext/MessageInputContext.d.ts +1 -2
- package/lib/typescript/contexts/messageInputContext/MessageInputContext.d.ts.map +1 -1
- package/lib/typescript/contexts/messageInputContext/hooks/useMessageDetailsForState.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/AttachmentPicker/components/AttachmentPickerItem.tsx +1 -2
- package/src/components/ChannelList/ChannelListMessenger.tsx +0 -4
- package/src/components/MessageInput/FileUploadPreview.tsx +1 -0
- package/src/components/MessageInput/MessageInput.tsx +65 -44
- package/src/contexts/messageInputContext/MessageInputContext.tsx +120 -91
- package/src/contexts/messageInputContext/__tests__/sendMessage.test.tsx +5 -0
- package/src/contexts/messageInputContext/__tests__/updateMessage.test.tsx +5 -0
- package/src/contexts/messageInputContext/hooks/useMessageDetailsForState.ts +8 -3
- package/src/version.json +1 -1
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
useTranslationContext,
|
|
50
50
|
} from '../../contexts/translationContext/TranslationContext';
|
|
51
51
|
|
|
52
|
-
import { triggerHaptic } from '../../native';
|
|
52
|
+
import { isImageMediaLibraryAvailable, triggerHaptic } from '../../native';
|
|
53
53
|
import type { Asset, DefaultStreamChatGenerics } from '../../types/types';
|
|
54
54
|
import { AutoCompleteInput } from '../AutoCompleteInput/AutoCompleteInput';
|
|
55
55
|
|
|
@@ -118,7 +118,6 @@ type MessageInputPropsWithContext<
|
|
|
118
118
|
| 'FileUploadPreview'
|
|
119
119
|
| 'fileUploads'
|
|
120
120
|
| 'giphyActive'
|
|
121
|
-
| 'hasImagePicker'
|
|
122
121
|
| 'ImageUploadPreview'
|
|
123
122
|
| 'imageUploads'
|
|
124
123
|
| 'Input'
|
|
@@ -185,7 +184,6 @@ const MessageInputWithContext = <
|
|
|
185
184
|
FileUploadPreview,
|
|
186
185
|
fileUploads,
|
|
187
186
|
giphyActive,
|
|
188
|
-
hasImagePicker,
|
|
189
187
|
ImageUploadPreview,
|
|
190
188
|
imageUploads,
|
|
191
189
|
Input,
|
|
@@ -349,46 +347,71 @@ const MessageInputWithContext = <
|
|
|
349
347
|
imagesToRemove.forEach((image) => removeImage(image.id));
|
|
350
348
|
};
|
|
351
349
|
|
|
350
|
+
const uploadFilesHandler = async () => {
|
|
351
|
+
const fileToUpload = selectedFiles.find((selectedFile) => {
|
|
352
|
+
const uploadedFile = fileUploads.find(
|
|
353
|
+
(fileUpload) =>
|
|
354
|
+
fileUpload.file.uri === selectedFile.uri || fileUpload.url === selectedFile.uri,
|
|
355
|
+
);
|
|
356
|
+
return !uploadedFile;
|
|
357
|
+
});
|
|
358
|
+
if (fileToUpload) await uploadNewFile(fileToUpload);
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const removeFilesHandler = () => {
|
|
362
|
+
const filesToRemove = fileUploads.filter(
|
|
363
|
+
(fileUpload) =>
|
|
364
|
+
!selectedFiles.find(
|
|
365
|
+
(selectedFile) =>
|
|
366
|
+
selectedFile.uri === fileUpload.file.uri || selectedFile.uri === fileUpload.url,
|
|
367
|
+
),
|
|
368
|
+
);
|
|
369
|
+
filesToRemove.forEach((file) => removeFile(file.id));
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* When a user selects or deselects an image in the image picker using media library.
|
|
374
|
+
*/
|
|
352
375
|
useEffect(() => {
|
|
353
|
-
|
|
354
|
-
if (
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
376
|
+
const uploadOrRemoveImage = async () => {
|
|
377
|
+
if (imagesForInput) {
|
|
378
|
+
if (selectedImagesLength > imageUploadsLength) {
|
|
379
|
+
/** User selected an image in bottom sheet attachment picker */
|
|
380
|
+
await uploadImagesHandler();
|
|
381
|
+
} else {
|
|
382
|
+
/** User de-selected an image in bottom sheet attachment picker */
|
|
383
|
+
removeImagesHandler();
|
|
384
|
+
}
|
|
360
385
|
}
|
|
361
|
-
}
|
|
386
|
+
};
|
|
387
|
+
// If image picker is not available, don't do anything
|
|
388
|
+
if (!isImageMediaLibraryAvailable()) return;
|
|
389
|
+
uploadOrRemoveImage();
|
|
362
390
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
363
391
|
}, [selectedImagesLength]);
|
|
364
392
|
|
|
393
|
+
/**
|
|
394
|
+
* When a user selects or deselects a video in the image picker using media library.
|
|
395
|
+
*/
|
|
365
396
|
useEffect(() => {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
);
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
} else {
|
|
377
|
-
/** User de-selected a video in bottom sheet attachment picker */
|
|
378
|
-
const filesToRemove = fileUploads.filter(
|
|
379
|
-
(fileUpload) =>
|
|
380
|
-
!selectedFiles.find(
|
|
381
|
-
(selectedFile) =>
|
|
382
|
-
selectedFile.uri === fileUpload.file.uri || selectedFile.uri === fileUpload.url,
|
|
383
|
-
),
|
|
384
|
-
);
|
|
385
|
-
filesToRemove.forEach((file) => removeFile(file.id));
|
|
386
|
-
}
|
|
397
|
+
const uploadOrRemoveFile = async () => {
|
|
398
|
+
if (selectedFilesLength > fileUploadsLength) {
|
|
399
|
+
/** User selected a video in bottom sheet attachment picker */
|
|
400
|
+
await uploadFilesHandler();
|
|
401
|
+
} else {
|
|
402
|
+
/** User de-selected a video in bottom sheet attachment picker */
|
|
403
|
+
removeFilesHandler();
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
uploadOrRemoveFile();
|
|
387
407
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
388
408
|
}, [selectedFilesLength]);
|
|
389
409
|
|
|
410
|
+
/**
|
|
411
|
+
* This is for image attachments selected from attachment picker.
|
|
412
|
+
*/
|
|
390
413
|
useEffect(() => {
|
|
391
|
-
if (imagesForInput &&
|
|
414
|
+
if (imagesForInput && isImageMediaLibraryAvailable()) {
|
|
392
415
|
if (imageUploadsLength < selectedImagesLength) {
|
|
393
416
|
// /** User removed some image from seleted images within ImageUploadPreview. */
|
|
394
417
|
const updatedSelectedImages = selectedImages.filter((selectedImage) => {
|
|
@@ -401,9 +424,7 @@ const MessageInputWithContext = <
|
|
|
401
424
|
setSelectedImages(updatedSelectedImages);
|
|
402
425
|
} else if (imageUploadsLength > selectedImagesLength) {
|
|
403
426
|
/**
|
|
404
|
-
* User is editing some message which contains image attachments
|
|
405
|
-
* image attachment is added from custom image picker (other than the default bottomsheet image picker)
|
|
406
|
-
* using `uploadNewImage` function from `MessageInputContext`.
|
|
427
|
+
* User is editing some message which contains image attachments.
|
|
407
428
|
**/
|
|
408
429
|
setSelectedImages(
|
|
409
430
|
imageUploads
|
|
@@ -418,10 +439,13 @@ const MessageInputWithContext = <
|
|
|
418
439
|
}
|
|
419
440
|
}
|
|
420
441
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
421
|
-
}, [imageUploadsLength
|
|
442
|
+
}, [imageUploadsLength]);
|
|
422
443
|
|
|
444
|
+
/**
|
|
445
|
+
* This is for video attachments selected from attachment picker.
|
|
446
|
+
*/
|
|
423
447
|
useEffect(() => {
|
|
424
|
-
if (
|
|
448
|
+
if (isImageMediaLibraryAvailable()) {
|
|
425
449
|
if (fileUploadsLength < selectedFilesLength) {
|
|
426
450
|
/** User removed some video from seleted files within ImageUploadPreview. */
|
|
427
451
|
const updatedSelectedFiles = selectedFiles.filter((selectedFile) => {
|
|
@@ -434,9 +458,7 @@ const MessageInputWithContext = <
|
|
|
434
458
|
setSelectedFiles(updatedSelectedFiles);
|
|
435
459
|
} else if (fileUploadsLength > selectedFilesLength) {
|
|
436
460
|
/**
|
|
437
|
-
* User is editing some message which contains video attachments
|
|
438
|
-
* video attachment is added from custom image picker (other than the default bottom-sheet image picker)
|
|
439
|
-
* using `uploadNewFile` function from `MessageInputContext`.
|
|
461
|
+
* User is editing some message which contains video attachments.
|
|
440
462
|
**/
|
|
441
463
|
setSelectedFiles(
|
|
442
464
|
fileUploads.map((fileUpload) => ({
|
|
@@ -450,9 +472,10 @@ const MessageInputWithContext = <
|
|
|
450
472
|
}
|
|
451
473
|
}
|
|
452
474
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
453
|
-
}, [fileUploadsLength
|
|
475
|
+
}, [fileUploadsLength]);
|
|
454
476
|
|
|
455
477
|
const editingExists = !!editing;
|
|
478
|
+
|
|
456
479
|
useEffect(() => {
|
|
457
480
|
if (editing && inputBoxRef.current) {
|
|
458
481
|
inputBoxRef.current.focus();
|
|
@@ -1036,7 +1059,6 @@ export const MessageInput = <
|
|
|
1036
1059
|
FileUploadPreview,
|
|
1037
1060
|
fileUploads,
|
|
1038
1061
|
giphyActive,
|
|
1039
|
-
hasImagePicker,
|
|
1040
1062
|
ImageUploadPreview,
|
|
1041
1063
|
imageUploads,
|
|
1042
1064
|
Input,
|
|
@@ -1117,7 +1139,6 @@ export const MessageInput = <
|
|
|
1117
1139
|
FileUploadPreview,
|
|
1118
1140
|
fileUploads,
|
|
1119
1141
|
giphyActive,
|
|
1120
|
-
hasImagePicker,
|
|
1121
1142
|
ImageUploadPreview,
|
|
1122
1143
|
imageUploads,
|
|
1123
1144
|
Input,
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import React, {
|
|
2
|
+
LegacyRef,
|
|
3
|
+
PropsWithChildren,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from 'react';
|
|
3
10
|
import { Alert, Keyboard, Linking, TextInput, TextInputProps } from 'react-native';
|
|
4
11
|
|
|
5
12
|
import uniq from 'lodash/uniq';
|
|
@@ -46,7 +53,7 @@ import type { SendButtonProps } from '../../components/MessageInput/SendButton';
|
|
|
46
53
|
import type { UploadProgressIndicatorProps } from '../../components/MessageInput/UploadProgressIndicator';
|
|
47
54
|
import type { MessageType } from '../../components/MessageList/hooks/useMessageList';
|
|
48
55
|
import type { Emoji } from '../../emoji-data';
|
|
49
|
-
import { pickDocument, pickImage, takePhoto } from '../../native';
|
|
56
|
+
import { isImageMediaLibraryAvailable, pickDocument, pickImage, takePhoto } from '../../native';
|
|
50
57
|
import {
|
|
51
58
|
Asset,
|
|
52
59
|
DefaultStreamChatGenerics,
|
|
@@ -657,7 +664,7 @@ export const MessageInputProvider = <
|
|
|
657
664
|
);
|
|
658
665
|
}
|
|
659
666
|
if (!photo.cancelled) {
|
|
660
|
-
|
|
667
|
+
await uploadNewImage(photo);
|
|
661
668
|
}
|
|
662
669
|
};
|
|
663
670
|
|
|
@@ -677,14 +684,11 @@ export const MessageInputProvider = <
|
|
|
677
684
|
);
|
|
678
685
|
}
|
|
679
686
|
if (result.assets && result.assets.length > 0) {
|
|
680
|
-
result.assets.forEach((asset) => {
|
|
687
|
+
result.assets.forEach(async (asset) => {
|
|
681
688
|
if (asset.type.includes('image')) {
|
|
682
|
-
|
|
689
|
+
await uploadNewImage(asset);
|
|
683
690
|
} else {
|
|
684
|
-
|
|
685
|
-
...prevFiles,
|
|
686
|
-
{ ...asset, mimeType: asset.type, type: FileTypes.Video },
|
|
687
|
-
]);
|
|
691
|
+
await uploadNewFile({ ...asset, mimeType: asset.type, type: FileTypes.Video });
|
|
688
692
|
}
|
|
689
693
|
});
|
|
690
694
|
}
|
|
@@ -693,30 +697,30 @@ export const MessageInputProvider = <
|
|
|
693
697
|
/**
|
|
694
698
|
* Function to open the attachment picker if the MediaLibary is installed.
|
|
695
699
|
*/
|
|
696
|
-
const openAttachmentPicker = () => {
|
|
700
|
+
const openAttachmentPicker = useCallback(() => {
|
|
697
701
|
Keyboard.dismiss();
|
|
698
702
|
setSelectedPicker('images');
|
|
699
703
|
openPicker();
|
|
700
|
-
};
|
|
704
|
+
}, [openPicker, setSelectedPicker]);
|
|
701
705
|
|
|
702
706
|
/**
|
|
703
707
|
* Function to close the attachment picker if the MediaLibrary is installed.
|
|
704
708
|
*/
|
|
705
|
-
const closeAttachmentPicker = () => {
|
|
709
|
+
const closeAttachmentPicker = useCallback(() => {
|
|
706
710
|
setSelectedPicker(undefined);
|
|
707
711
|
closePicker();
|
|
708
|
-
};
|
|
712
|
+
}, [closePicker, setSelectedPicker]);
|
|
709
713
|
|
|
710
714
|
/**
|
|
711
715
|
* Function to toggle the attachment picker if the MediaLibrary is installed.
|
|
712
716
|
*/
|
|
713
|
-
const toggleAttachmentPicker = () => {
|
|
717
|
+
const toggleAttachmentPicker = useCallback(() => {
|
|
714
718
|
if (selectedPicker) {
|
|
715
719
|
closeAttachmentPicker();
|
|
716
720
|
} else {
|
|
717
721
|
openAttachmentPicker();
|
|
718
722
|
}
|
|
719
|
-
};
|
|
723
|
+
}, [closeAttachmentPicker, openAttachmentPicker, selectedPicker]);
|
|
720
724
|
|
|
721
725
|
const onSelectItem = (item: UserResponse<StreamChatGenerics>) => {
|
|
722
726
|
setMentionedUsers((prevMentionedUsers) => [...prevMentionedUsers, item.id]);
|
|
@@ -740,7 +744,7 @@ export const MessageInputProvider = <
|
|
|
740
744
|
});
|
|
741
745
|
|
|
742
746
|
if (!result.cancelled && result.assets) {
|
|
743
|
-
result.assets.forEach((asset) => {
|
|
747
|
+
result.assets.forEach(async (asset) => {
|
|
744
748
|
/**
|
|
745
749
|
* TODO: The current tight coupling of images to the image
|
|
746
750
|
* picker does not allow images picked from the file picker
|
|
@@ -748,26 +752,40 @@ export const MessageInputProvider = <
|
|
|
748
752
|
* This should be updated alongside allowing image a file
|
|
749
753
|
* uploads together.
|
|
750
754
|
*/
|
|
751
|
-
uploadNewFile(asset);
|
|
755
|
+
await uploadNewFile(asset);
|
|
752
756
|
});
|
|
753
757
|
}
|
|
754
758
|
};
|
|
755
759
|
|
|
756
|
-
const removeFile = (
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
760
|
+
const removeFile = useCallback(
|
|
761
|
+
(id: string) => {
|
|
762
|
+
if (fileUploads.some((file) => file.id === id)) {
|
|
763
|
+
setFileUploads((prevFileUploads) => prevFileUploads.filter((file) => file.id !== id));
|
|
764
|
+
setNumberOfUploads((prevNumberOfUploads) => prevNumberOfUploads - 1);
|
|
765
|
+
}
|
|
766
|
+
},
|
|
767
|
+
[fileUploads, setFileUploads, setNumberOfUploads],
|
|
768
|
+
);
|
|
762
769
|
|
|
763
|
-
const removeImage = (
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
770
|
+
const removeImage = useCallback(
|
|
771
|
+
(id: string) => {
|
|
772
|
+
if (imageUploads.some((image) => image.id === id)) {
|
|
773
|
+
setImageUploads((prevImageUploads) => prevImageUploads.filter((image) => image.id !== id));
|
|
774
|
+
setNumberOfUploads((prevNumberOfUploads) => prevNumberOfUploads - 1);
|
|
775
|
+
}
|
|
776
|
+
},
|
|
777
|
+
[imageUploads, setImageUploads, setNumberOfUploads],
|
|
778
|
+
);
|
|
769
779
|
|
|
770
780
|
const resetInput = (pendingAttachments: Attachment<StreamChatGenerics>[] = []) => {
|
|
781
|
+
/**
|
|
782
|
+
* If the MediaLibrary is available, reset the selected files and images
|
|
783
|
+
*/
|
|
784
|
+
if (isImageMediaLibraryAvailable()) {
|
|
785
|
+
setSelectedFiles([]);
|
|
786
|
+
setSelectedImages([]);
|
|
787
|
+
}
|
|
788
|
+
|
|
771
789
|
setFileUploads([]);
|
|
772
790
|
setGiphyActive(false);
|
|
773
791
|
setShowMoreOptions(true);
|
|
@@ -1253,87 +1271,98 @@ export const MessageInputProvider = <
|
|
|
1253
1271
|
};
|
|
1254
1272
|
|
|
1255
1273
|
const uploadNewFile = async (file: File) => {
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1274
|
+
try {
|
|
1275
|
+
const id: string = generateRandomId();
|
|
1276
|
+
const fileConfig = getFileUploadConfig();
|
|
1277
|
+
const { size_limit } = fileConfig;
|
|
1259
1278
|
|
|
1260
|
-
|
|
1279
|
+
const isAllowed = isUploadAllowed({ config: fileConfig, file });
|
|
1261
1280
|
|
|
1262
|
-
|
|
1281
|
+
const sizeLimit = size_limit || MAX_FILE_SIZE_TO_UPLOAD;
|
|
1263
1282
|
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1283
|
+
if (file.size && file.size > sizeLimit) {
|
|
1284
|
+
Alert.alert(
|
|
1285
|
+
t('File is too large: {{ size }}, maximum upload size is {{ limit }}', {
|
|
1286
|
+
limit: prettifyFileSize(sizeLimit),
|
|
1287
|
+
size: prettifyFileSize(file.size),
|
|
1288
|
+
}),
|
|
1289
|
+
);
|
|
1290
|
+
setSelectedFiles(selectedFiles.filter((selectedFile) => selectedFile.uri !== file.uri));
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1274
1293
|
|
|
1275
|
-
|
|
1294
|
+
const fileState = isAllowed ? FileState.UPLOADING : FileState.NOT_SUPPORTED;
|
|
1276
1295
|
|
|
1277
|
-
|
|
1278
|
-
|
|
1296
|
+
// If file type is explicitly provided while upload we use it, else we derive the file type.
|
|
1297
|
+
const fileType = file.type || file.mimeType?.split('/')[0];
|
|
1279
1298
|
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1299
|
+
const newFile: FileUpload = {
|
|
1300
|
+
duration: file.duration || 0,
|
|
1301
|
+
file,
|
|
1302
|
+
id: file.id || id,
|
|
1303
|
+
state: fileState,
|
|
1304
|
+
type: fileType,
|
|
1305
|
+
url: file.uri,
|
|
1306
|
+
};
|
|
1287
1307
|
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1308
|
+
await Promise.all([
|
|
1309
|
+
setFileUploads((prevFileUploads) => prevFileUploads.concat([newFile])),
|
|
1310
|
+
setNumberOfUploads((prevNumberOfUploads) => prevNumberOfUploads + 1),
|
|
1311
|
+
]);
|
|
1292
1312
|
|
|
1293
|
-
|
|
1294
|
-
|
|
1313
|
+
if (isAllowed) {
|
|
1314
|
+
await uploadFile({ newFile });
|
|
1315
|
+
}
|
|
1316
|
+
} catch (error) {
|
|
1317
|
+
console.log('Error uploading file', error);
|
|
1295
1318
|
}
|
|
1296
1319
|
};
|
|
1297
1320
|
|
|
1298
1321
|
const uploadNewImage = async (image: Partial<Asset>) => {
|
|
1299
|
-
|
|
1300
|
-
|
|
1322
|
+
try {
|
|
1323
|
+
const id = generateRandomId();
|
|
1324
|
+
const imageUploadConfig = getImageUploadConfig();
|
|
1301
1325
|
|
|
1302
|
-
|
|
1326
|
+
const { size_limit } = imageUploadConfig;
|
|
1303
1327
|
|
|
1304
|
-
|
|
1328
|
+
const isAllowed = isUploadAllowed({ config: imageUploadConfig, file: image });
|
|
1305
1329
|
|
|
1306
|
-
|
|
1330
|
+
const sizeLimit = size_limit || MAX_FILE_SIZE_TO_UPLOAD;
|
|
1307
1331
|
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1332
|
+
if (image.size && image?.size > sizeLimit) {
|
|
1333
|
+
Alert.alert(
|
|
1334
|
+
t('File is too large: {{ size }}, maximum upload size is {{ limit }}', {
|
|
1335
|
+
limit: prettifyFileSize(sizeLimit),
|
|
1336
|
+
size: prettifyFileSize(image.size),
|
|
1337
|
+
}),
|
|
1338
|
+
);
|
|
1339
|
+
setSelectedImages(
|
|
1340
|
+
selectedImages.filter((selectedImage) => selectedImage.uri !== image.uri),
|
|
1341
|
+
);
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1318
1344
|
|
|
1319
|
-
|
|
1345
|
+
const imageState = isAllowed ? FileState.UPLOADING : FileState.NOT_SUPPORTED;
|
|
1320
1346
|
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1347
|
+
const newImage: ImageUpload = {
|
|
1348
|
+
file: image,
|
|
1349
|
+
height: image.height,
|
|
1350
|
+
id,
|
|
1351
|
+
state: imageState,
|
|
1352
|
+
url: image.uri,
|
|
1353
|
+
width: image.width,
|
|
1354
|
+
};
|
|
1329
1355
|
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1356
|
+
await Promise.all([
|
|
1357
|
+
setImageUploads((prevImageUploads) => prevImageUploads.concat([newImage])),
|
|
1358
|
+
setNumberOfUploads((prevNumberOfUploads) => prevNumberOfUploads + 1),
|
|
1359
|
+
]);
|
|
1334
1360
|
|
|
1335
|
-
|
|
1336
|
-
|
|
1361
|
+
if (isAllowed) {
|
|
1362
|
+
await uploadImage({ newImage });
|
|
1363
|
+
}
|
|
1364
|
+
} catch (error) {
|
|
1365
|
+
console.log('Error uploading image', error);
|
|
1337
1366
|
}
|
|
1338
1367
|
};
|
|
1339
1368
|
|
|
@@ -12,6 +12,7 @@ import { generateMessage } from '../../../mock-builders/generator/message';
|
|
|
12
12
|
import { generateUser } from '../../../mock-builders/generator/user';
|
|
13
13
|
import type { DefaultStreamChatGenerics } from '../../../types/types';
|
|
14
14
|
import { FileState } from '../../../utils/utils';
|
|
15
|
+
import * as AttachmentPickerContext from '../../attachmentPickerContext/AttachmentPickerContext';
|
|
15
16
|
import {
|
|
16
17
|
InputMessageInputContextValue,
|
|
17
18
|
MessageInputContextValue,
|
|
@@ -39,6 +40,10 @@ const Wrapper = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultS
|
|
|
39
40
|
|
|
40
41
|
const newMessage = generateMessage({ id: 'new-id' });
|
|
41
42
|
describe("MessageInputContext's sendMessage", () => {
|
|
43
|
+
jest.spyOn(AttachmentPickerContext, 'useAttachmentPickerContext').mockImplementation(() => ({
|
|
44
|
+
setSelectedFiles: jest.fn(),
|
|
45
|
+
setSelectedImages: jest.fn(),
|
|
46
|
+
}));
|
|
42
47
|
const message: boolean | MessageType<DefaultStreamChatGenerics> = generateMessage({
|
|
43
48
|
created_at: 'Sat Jul 02 2022 23:55:13 GMT+0530 (India Standard Time)',
|
|
44
49
|
id: '7a85f744-cc89-4f82-a1d4-5456432cc8bf',
|
|
@@ -11,6 +11,7 @@ import { ChatContextValue, ChatProvider } from '../../../contexts/chatContext/Ch
|
|
|
11
11
|
import { generateMessage } from '../../../mock-builders/generator/message';
|
|
12
12
|
import { generateUser } from '../../../mock-builders/generator/user';
|
|
13
13
|
import type { DefaultStreamChatGenerics } from '../../../types/types';
|
|
14
|
+
import * as AttachmentPickerContext from '../../attachmentPickerContext/AttachmentPickerContext';
|
|
14
15
|
import {
|
|
15
16
|
InputMessageInputContextValue,
|
|
16
17
|
MessageInputContextValue,
|
|
@@ -49,6 +50,10 @@ const Wrapper = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultS
|
|
|
49
50
|
);
|
|
50
51
|
|
|
51
52
|
describe("MessageInputContext's updateMessage", () => {
|
|
53
|
+
jest.spyOn(AttachmentPickerContext, 'useAttachmentPickerContext').mockImplementation(() => ({
|
|
54
|
+
setSelectedFiles: jest.fn(),
|
|
55
|
+
setSelectedImages: jest.fn(),
|
|
56
|
+
}));
|
|
52
57
|
const clearEditingStateMock = jest.fn();
|
|
53
58
|
const generatedMessage: boolean | MessageType<DefaultStreamChatGenerics> = generateMessage({
|
|
54
59
|
created_at: 'Sat Jul 02 2022 23:55:13 GMT+0530 (India Standard Time)',
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
FileUpload,
|
|
9
9
|
ImageUpload,
|
|
10
10
|
} from '../../../types/types';
|
|
11
|
-
import { generateRandomId } from '../../../utils/utils';
|
|
11
|
+
import { generateRandomId, stringifyMessage } from '../../../utils/utils';
|
|
12
12
|
|
|
13
13
|
import type { MessageInputContextValue } from '../MessageInputContext';
|
|
14
14
|
|
|
@@ -37,8 +37,7 @@ export const useMessageDetailsForState = <
|
|
|
37
37
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
38
|
}, [text, imageUploads.length, fileUploads.length]);
|
|
39
39
|
|
|
40
|
-
const messageValue =
|
|
41
|
-
message === undefined ? '' : `${message.id}${message.text}${message.updated_at}`;
|
|
40
|
+
const messageValue = message ? stringifyMessage(message) : '';
|
|
42
41
|
|
|
43
42
|
useEffect(() => {
|
|
44
43
|
if (message && Array.isArray(message?.mentioned_users)) {
|
|
@@ -67,9 +66,11 @@ export const useMessageDetailsForState = <
|
|
|
67
66
|
} else if (attachment.type === FileTypes.Video) {
|
|
68
67
|
return {
|
|
69
68
|
file: {
|
|
69
|
+
duration: attachment.duration,
|
|
70
70
|
mimeType: attachment.mime_type,
|
|
71
71
|
name: attachment.title || '',
|
|
72
72
|
size: attachment.file_size,
|
|
73
|
+
uri: attachment.asset_url,
|
|
73
74
|
},
|
|
74
75
|
id,
|
|
75
76
|
state: 'finished',
|
|
@@ -96,6 +97,7 @@ export const useMessageDetailsForState = <
|
|
|
96
97
|
mimeType: attachment.mime_type,
|
|
97
98
|
name: attachment.title || '',
|
|
98
99
|
size: attachment.file_size,
|
|
100
|
+
uri: attachment.asset_url,
|
|
99
101
|
},
|
|
100
102
|
id,
|
|
101
103
|
state: 'finished',
|
|
@@ -107,6 +109,7 @@ export const useMessageDetailsForState = <
|
|
|
107
109
|
mimeType: attachment.mime_type,
|
|
108
110
|
name: attachment.title || '',
|
|
109
111
|
size: attachment.file_size,
|
|
112
|
+
uri: attachment.asset_url,
|
|
110
113
|
},
|
|
111
114
|
id,
|
|
112
115
|
state: 'finished',
|
|
@@ -128,9 +131,11 @@ export const useMessageDetailsForState = <
|
|
|
128
131
|
const id = generateRandomId();
|
|
129
132
|
newImageUploads.push({
|
|
130
133
|
file: {
|
|
134
|
+
height: attachment.original_height,
|
|
131
135
|
name: attachment.fallback,
|
|
132
136
|
size: attachment.file_size,
|
|
133
137
|
type: attachment.type,
|
|
138
|
+
width: attachment.original_width,
|
|
134
139
|
},
|
|
135
140
|
id,
|
|
136
141
|
state: 'finished',
|
package/src/version.json
CHANGED