stream-chat-react-native-core 5.8.0-beta.2 → 5.8.0-beta.4

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 (23) hide show
  1. package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js +8 -2
  2. package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js.map +1 -1
  3. package/lib/commonjs/components/MessageInput/MessageInput.js +50 -34
  4. package/lib/commonjs/components/MessageInput/MessageInput.js.map +1 -1
  5. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +17 -7
  6. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  7. package/lib/commonjs/version.json +1 -1
  8. package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js +8 -2
  9. package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js.map +1 -1
  10. package/lib/module/components/MessageInput/MessageInput.js +50 -34
  11. package/lib/module/components/MessageInput/MessageInput.js.map +1 -1
  12. package/lib/module/contexts/messageInputContext/MessageInputContext.js +17 -7
  13. package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  14. package/lib/module/version.json +1 -1
  15. package/package.json +2 -2
  16. package/src/components/ChannelPreview/hooks/__tests__/useChannelPreviewDisplayName.test.tsx +2 -2
  17. package/src/components/ChannelPreview/hooks/useChannelPreviewDisplayName.ts +10 -2
  18. package/src/components/MessageInput/MessageInput.tsx +34 -5
  19. package/src/components/MessageInput/__tests__/MessageInput.test.js +61 -11
  20. package/src/contexts/messageInputContext/MessageInputContext.tsx +21 -10
  21. package/src/contexts/messageInputContext/__tests__/pickFile.test.tsx +26 -0
  22. package/src/version.json +1 -1
  23. package/src/components/MessageInput/__tests__/__snapshots__/MessageInput.test.js.snap +0 -746
@@ -590,17 +590,28 @@ export const MessageInputProvider = <
590
590
  const result = await pickDocument({
591
591
  maxNumberOfFiles: value.maxNumberOfFiles - numberOfUploads,
592
592
  });
593
+
594
+ const MEGA_BYTES_TO_BYTES = 1024 * 1024;
595
+ const MAX_FILE_SIZE_TO_UPLOAD_IN_MB = 100;
596
+
593
597
  if (!result.cancelled && result.docs) {
594
- result.docs.forEach((doc) => {
595
- /**
596
- * TODO: The current tight coupling of images to the image
597
- * picker does not allow images picked from the file picker
598
- * to be rendered in a preview via the uploadNewImage call.
599
- * This should be updated alongside allowing image a file
600
- * uploads together.
601
- */
602
- uploadNewFile(doc);
603
- });
598
+ const totalFileSize = result.docs.reduce((acc, doc) => acc + Number(doc.size), 0);
599
+ if (totalFileSize / MEGA_BYTES_TO_BYTES > MAX_FILE_SIZE_TO_UPLOAD_IN_MB) {
600
+ Alert.alert(
601
+ `Maximum file size upload limit reached, please upload files below ${MAX_FILE_SIZE_TO_UPLOAD_IN_MB}MB.`,
602
+ );
603
+ } else {
604
+ result.docs.forEach((doc) => {
605
+ /**
606
+ * TODO: The current tight coupling of images to the image
607
+ * picker does not allow images picked from the file picker
608
+ * to be rendered in a preview via the uploadNewImage call.
609
+ * This should be updated alongside allowing image a file
610
+ * uploads together.
611
+ */
612
+ uploadNewFile(doc);
613
+ });
614
+ }
604
615
  }
605
616
  };
606
617
 
@@ -4,6 +4,10 @@ import { act } from 'react-test-renderer';
4
4
 
5
5
  import { renderHook } from '@testing-library/react-hooks';
6
6
 
7
+ import { generateFileAttachment } from '../../../mock-builders/generator/attachment';
8
+
9
+ import * as NativeUtils from '../../../native';
10
+
7
11
  import type { DefaultStreamChatGenerics } from '../../../types/types';
8
12
  import {
9
13
  InputMessageInputContextValue,
@@ -34,6 +38,15 @@ afterEach(jest.clearAllMocks);
34
38
 
35
39
  describe("MessageInputContext's pickFile", () => {
36
40
  jest.spyOn(Alert, 'alert');
41
+ jest.spyOn(NativeUtils, 'pickDocument').mockImplementation(
42
+ jest.fn().mockResolvedValue({
43
+ cancelled: false,
44
+ docs: [
45
+ generateFileAttachment({ size: 500000000 }),
46
+ generateFileAttachment({ size: 600000000 }),
47
+ ],
48
+ }),
49
+ );
37
50
 
38
51
  const initialProps = {
39
52
  editing: true,
@@ -64,4 +77,17 @@ describe("MessageInputContext's pickFile", () => {
64
77
  expect(Alert.alert).toHaveBeenCalledTimes(numberOfTimesCalled);
65
78
  },
66
79
  );
80
+
81
+ it('trigger file size threshold limit alert when file size above the limit', () => {
82
+ const { result } = renderHook(() => useMessageInputContext(), {
83
+ initialProps,
84
+ wrapper: Wrapper,
85
+ });
86
+
87
+ act(() => {
88
+ result.current.pickFile();
89
+ });
90
+
91
+ expect(Alert.alert).toHaveBeenCalledTimes(1);
92
+ });
67
93
  });
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.8.0-beta.2"
2
+ "version": "5.8.0-beta.4"
3
3
  }