stream-chat-react-native-core 5.15.3 → 5.16.0-beta.2

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 (68) hide show
  1. package/lib/commonjs/components/Attachment/FileAttachmentGroup.js +1 -1
  2. package/lib/commonjs/components/Attachment/FileAttachmentGroup.js.map +1 -1
  3. package/lib/commonjs/components/Channel/Channel.js +1 -1
  4. package/lib/commonjs/components/Channel/Channel.js.map +1 -1
  5. package/lib/commonjs/components/ImageGallery/ImageGallery.js +25 -22
  6. package/lib/commonjs/components/ImageGallery/ImageGallery.js.map +1 -1
  7. package/lib/commonjs/components/MessageInput/FileUploadPreview.js +4 -4
  8. package/lib/commonjs/components/MessageInput/FileUploadPreview.js.map +1 -1
  9. package/lib/commonjs/components/MessageInput/MessageInput.js +1 -1
  10. package/lib/commonjs/components/MessageInput/MessageInput.js.map +1 -1
  11. package/lib/commonjs/components/MessageList/utils/getDateSeparators.js +2 -2
  12. package/lib/commonjs/components/MessageList/utils/getDateSeparators.js.map +1 -1
  13. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +38 -54
  14. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  15. package/lib/commonjs/contexts/messageInputContext/hooks/useMessageDetailsForState.js +4 -4
  16. package/lib/commonjs/contexts/messageInputContext/hooks/useMessageDetailsForState.js.map +1 -1
  17. package/lib/commonjs/contexts/overlayContext/OverlayContext.js +1 -1
  18. package/lib/commonjs/contexts/overlayContext/OverlayContext.js.map +1 -1
  19. package/lib/commonjs/contexts/overlayContext/OverlayProvider.js +14 -12
  20. package/lib/commonjs/contexts/overlayContext/OverlayProvider.js.map +1 -1
  21. package/lib/commonjs/native.js.map +1 -1
  22. package/lib/commonjs/types/types.js.map +1 -1
  23. package/lib/commonjs/version.json +1 -1
  24. package/lib/module/components/Attachment/FileAttachmentGroup.js +1 -1
  25. package/lib/module/components/Attachment/FileAttachmentGroup.js.map +1 -1
  26. package/lib/module/components/Channel/Channel.js +1 -1
  27. package/lib/module/components/Channel/Channel.js.map +1 -1
  28. package/lib/module/components/ImageGallery/ImageGallery.js +25 -22
  29. package/lib/module/components/ImageGallery/ImageGallery.js.map +1 -1
  30. package/lib/module/components/MessageInput/FileUploadPreview.js +4 -4
  31. package/lib/module/components/MessageInput/FileUploadPreview.js.map +1 -1
  32. package/lib/module/components/MessageInput/MessageInput.js +1 -1
  33. package/lib/module/components/MessageInput/MessageInput.js.map +1 -1
  34. package/lib/module/components/MessageList/utils/getDateSeparators.js +2 -2
  35. package/lib/module/components/MessageList/utils/getDateSeparators.js.map +1 -1
  36. package/lib/module/contexts/messageInputContext/MessageInputContext.js +38 -54
  37. package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  38. package/lib/module/contexts/messageInputContext/hooks/useMessageDetailsForState.js +4 -4
  39. package/lib/module/contexts/messageInputContext/hooks/useMessageDetailsForState.js.map +1 -1
  40. package/lib/module/contexts/overlayContext/OverlayContext.js +1 -1
  41. package/lib/module/contexts/overlayContext/OverlayContext.js.map +1 -1
  42. package/lib/module/contexts/overlayContext/OverlayProvider.js +14 -12
  43. package/lib/module/contexts/overlayContext/OverlayProvider.js.map +1 -1
  44. package/lib/module/native.js.map +1 -1
  45. package/lib/module/types/types.js.map +1 -1
  46. package/lib/module/version.json +1 -1
  47. package/lib/typescript/components/ImageGallery/ImageGallery.d.ts +1 -1
  48. package/lib/typescript/contexts/messageInputContext/MessageInputContext.d.ts +1 -1
  49. package/lib/typescript/contexts/overlayContext/OverlayContext.d.ts +1 -0
  50. package/lib/typescript/native.d.ts +1 -1
  51. package/lib/typescript/types/types.d.ts +6 -4
  52. package/package.json +1 -1
  53. package/src/components/Attachment/FileAttachmentGroup.tsx +1 -1
  54. package/src/components/Channel/Channel.tsx +1 -1
  55. package/src/components/ImageGallery/ImageGallery.tsx +4 -1
  56. package/src/components/MessageInput/FileUploadPreview.tsx +3 -3
  57. package/src/components/MessageInput/MessageInput.tsx +2 -2
  58. package/src/components/MessageInput/__tests__/FileUploadPreview.test.js +1 -1
  59. package/src/components/MessageList/utils/getDateSeparators.ts +4 -2
  60. package/src/contexts/messageInputContext/MessageInputContext.tsx +25 -32
  61. package/src/contexts/messageInputContext/__tests__/__snapshots__/sendMessage.test.tsx.snap +10 -12
  62. package/src/contexts/messageInputContext/__tests__/pickFile.test.tsx +2 -2
  63. package/src/contexts/messageInputContext/hooks/useMessageDetailsForState.ts +2 -2
  64. package/src/contexts/overlayContext/OverlayContext.tsx +1 -0
  65. package/src/contexts/overlayContext/OverlayProvider.tsx +2 -0
  66. package/src/native.ts +1 -1
  67. package/src/types/types.ts +9 -4
  68. package/src/version.json +1 -1
@@ -1,6 +1,5 @@
1
- import React, { PropsWithChildren, useContext, useEffect, useRef, useState } from 'react';
2
-
3
1
  import type { LegacyRef } from 'react';
2
+ import React, { PropsWithChildren, useContext, useEffect, useRef, useState } from 'react';
4
3
  import type { TextInput, TextInputProps } from 'react-native';
5
4
  import { Alert, Keyboard, Platform } from 'react-native';
6
5
 
@@ -591,14 +590,14 @@ export const MessageInputProvider = <
591
590
  const MEGA_BYTES_TO_BYTES = 1024 * 1024;
592
591
  const MAX_FILE_SIZE_TO_UPLOAD_IN_MB = 100;
593
592
 
594
- if (!result.cancelled && result.docs) {
595
- const totalFileSize = result.docs.reduce((acc, doc) => acc + Number(doc.size), 0);
593
+ if (!result.cancelled && result.assets) {
594
+ const totalFileSize = result.assets.reduce((acc, asset) => acc + Number(asset.size), 0);
596
595
  if (totalFileSize / MEGA_BYTES_TO_BYTES > MAX_FILE_SIZE_TO_UPLOAD_IN_MB) {
597
596
  Alert.alert(
598
597
  `Maximum file size upload limit reached, please upload files below ${MAX_FILE_SIZE_TO_UPLOAD_IN_MB}MB.`,
599
598
  );
600
599
  } else {
601
- result.docs.forEach((doc) => {
600
+ result.assets.forEach((asset) => {
602
601
  /**
603
602
  * TODO: The current tight coupling of images to the image
604
603
  * picker does not allow images picked from the file picker
@@ -606,7 +605,7 @@ export const MessageInputProvider = <
606
605
  * This should be updated alongside allowing image a file
607
606
  * uploads together.
608
607
  */
609
- uploadNewFile(doc);
608
+ uploadNewFile(asset);
610
609
  });
611
610
  }
612
611
  }
@@ -652,31 +651,30 @@ export const MessageInputProvider = <
652
651
  };
653
652
 
654
653
  const mapFileUploadToAttachment = (file: FileUpload) => {
655
- const mime_type: string | boolean = lookup(file.file.name as string);
656
- if (file.file.type?.startsWith('image/')) {
654
+ if (file.file.mimeType?.startsWith('image/')) {
657
655
  return {
658
656
  fallback: file.file.name,
659
657
  image_url: file.url,
660
- mime_type: mime_type ? mime_type : undefined,
658
+ mime_type: file.file.mimeType,
661
659
  originalFile: file.file,
662
660
  type: 'image',
663
661
  };
664
- } else if (file.file.type?.startsWith('audio/')) {
662
+ } else if (file.file.mimeType?.startsWith('audio/')) {
665
663
  return {
666
664
  asset_url: file.url || file.file.uri,
667
665
  duration: file.file.duration,
668
666
  file_size: file.file.size,
669
- mime_type: file.file.type,
667
+ mime_type: file.file.mimeType,
670
668
  originalFile: file.file,
671
669
  title: file.file.name,
672
670
  type: 'audio',
673
671
  };
674
- } else if (file.file.type?.startsWith('video/')) {
672
+ } else if (file.file.mimeType?.startsWith('video/')) {
675
673
  return {
676
674
  asset_url: file.url || file.file.uri,
677
675
  duration: file.file.duration,
678
676
  file_size: file.file.size,
679
- mime_type: file.file.type,
677
+ mime_type: file.file.mimeType,
680
678
  originalFile: file.file,
681
679
  thumb_url: file.thumb_url,
682
680
  title: file.file.name,
@@ -686,7 +684,7 @@ export const MessageInputProvider = <
686
684
  return {
687
685
  asset_url: file.url || file.file.uri,
688
686
  file_size: file.file.size,
689
- mime_type: file.file.type,
687
+ mime_type: file.file.mimeType,
690
688
  originalFile: file.file,
691
689
  title: file.file.name,
692
690
  type: 'file',
@@ -915,14 +913,15 @@ export const MessageInputProvider = <
915
913
  }
916
914
  };
917
915
 
918
- const regExcondition = /File (extension \.\w{2,4}|type \S+) is not supported/;
916
+ const regexCondition = /File (extension \.\w{2,4}|type \S+) is not supported/;
919
917
 
920
- const getUploadSetStateAction = <UploadType extends ImageUpload | FileUpload>(
921
- id: string,
922
- fileState: FileStateValue,
923
- extraData: Partial<UploadType> = {},
924
- ): React.SetStateAction<UploadType[]> => {
925
- const uploads: (prevUploads: UploadType[]) => UploadType[] = (prevUploads: UploadType[]) =>
918
+ const getUploadSetStateAction =
919
+ <UploadType extends ImageUpload | FileUpload>(
920
+ id: string,
921
+ fileState: FileStateValue,
922
+ extraData: Partial<UploadType> = {},
923
+ ): React.SetStateAction<UploadType[]> =>
924
+ (prevUploads: UploadType[]) =>
926
925
  prevUploads.map((prevUpload) => {
927
926
  if (prevUpload.id === id) {
928
927
  return {
@@ -934,14 +933,11 @@ export const MessageInputProvider = <
934
933
  return prevUpload;
935
934
  });
936
935
 
937
- return uploads;
938
- };
939
-
940
936
  const handleFileOrImageUploadError = (error: unknown, isImageError: boolean, id: string) => {
941
937
  if (isImageError) {
942
938
  setNumberOfUploads((prevNumberOfUploads) => prevNumberOfUploads - 1);
943
939
  if (error instanceof Error) {
944
- if (regExcondition.test(error.message)) {
940
+ if (regexCondition.test(error.message)) {
945
941
  return setImageUploads(getUploadSetStateAction(id, FileState.NOT_SUPPORTED));
946
942
  }
947
943
 
@@ -951,7 +947,7 @@ export const MessageInputProvider = <
951
947
  setNumberOfUploads((prevNumberOfUploads) => prevNumberOfUploads - 1);
952
948
 
953
949
  if (error instanceof Error) {
954
- if (regExcondition.test(error.message)) {
950
+ if (regexCondition.test(error.message)) {
955
951
  return setFileUploads(getUploadSetStateAction(id, FileState.NOT_SUPPORTED));
956
952
  }
957
953
  return setFileUploads(getUploadSetStateAction(id, FileState.UPLOAD_FAILED));
@@ -969,9 +965,7 @@ export const MessageInputProvider = <
969
965
  if (value.doDocUploadRequest) {
970
966
  response = await value.doDocUploadRequest(file, channel);
971
967
  } else if (channel && file.uri) {
972
- // 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.
973
- const localAssetURI = Platform.OS === 'ios' && file.id && (await getLocalAssetUri(file.id));
974
- response = await channel.sendFile(localAssetURI || file.uri, file.name, file.type);
968
+ response = await channel.sendFile(file.uri, file.name, file.mimeType);
975
969
  }
976
970
  const extraData: Partial<FileUpload> = { thumb_url: response.thumb_url, url: response.file };
977
971
  setFileUploads(getUploadSetStateAction(id, FileState.UPLOADED, extraData));
@@ -996,7 +990,7 @@ export const MessageInputProvider = <
996
990
  /**
997
991
  * We skip compression if:
998
992
  * - the file is from the camera as that should already be compressed
999
- * - the file has not height/width value to maintain for compression
993
+ * - the file has no height/width value to maintain for compression
1000
994
  * - the compressImageQuality number is not present or is 1 (meaning no compression)
1001
995
  */
1002
996
  const compressedUri = await (file.source === 'camera' ||
@@ -1055,7 +1049,6 @@ export const MessageInputProvider = <
1055
1049
 
1056
1050
  const uploadNewFile = async (file: File) => {
1057
1051
  const id: string = generateRandomId();
1058
- const mimeType: string | boolean = lookup(file.name);
1059
1052
 
1060
1053
  const isBlockedFileExtension: boolean | undefined = blockedFileExtensionTypes?.some(
1061
1054
  (fileExtensionType: string) => file.name?.includes(fileExtensionType),
@@ -1071,7 +1064,7 @@ export const MessageInputProvider = <
1071
1064
 
1072
1065
  const newFile: FileUpload = {
1073
1066
  duration: 0,
1074
- file: { ...file, type: mimeType || file?.type },
1067
+ file,
1075
1068
  id: file.id || id,
1076
1069
  paused: true,
1077
1070
  progress: 0,
@@ -42,7 +42,7 @@ Object {
42
42
  Object {
43
43
  "asset_url": undefined,
44
44
  "file_size": undefined,
45
- "mime_type": "file",
45
+ "mime_type": undefined,
46
46
  "originalFile": Object {
47
47
  "name": "dummy.pdf",
48
48
  "state": "uploaded",
@@ -53,41 +53,39 @@ Object {
53
53
  },
54
54
  Object {
55
55
  "asset_url": undefined,
56
- "duration": undefined,
57
56
  "file_size": undefined,
58
- "mime_type": "video/mp4",
57
+ "mime_type": undefined,
59
58
  "originalFile": Object {
60
59
  "name": "dummy.pdf",
61
60
  "state": "finished",
62
61
  "type": "video/mp4",
63
62
  },
64
- "thumb_url": undefined,
65
63
  "title": "dummy.pdf",
66
- "type": "video",
64
+ "type": "file",
67
65
  },
68
66
  Object {
69
67
  "asset_url": undefined,
70
- "duration": undefined,
71
68
  "file_size": undefined,
72
- "mime_type": "audio/mp3",
69
+ "mime_type": undefined,
73
70
  "originalFile": Object {
74
71
  "name": "dummy.pdf",
75
72
  "state": "uploaded",
76
73
  "type": "audio/mp3",
77
74
  },
78
75
  "title": "dummy.pdf",
79
- "type": "audio",
76
+ "type": "file",
80
77
  },
81
78
  Object {
82
- "fallback": "dummy.pdf",
83
- "image_url": undefined,
84
- "mime_type": "application/pdf",
79
+ "asset_url": undefined,
80
+ "file_size": undefined,
81
+ "mime_type": undefined,
85
82
  "originalFile": Object {
86
83
  "name": "dummy.pdf",
87
84
  "state": "finished",
88
85
  "type": "image/jpeg",
89
86
  },
90
- "type": "image",
87
+ "title": "dummy.pdf",
88
+ "type": "file",
91
89
  },
92
90
  ],
93
91
  "mentioned_users": Array [
@@ -40,11 +40,11 @@ describe("MessageInputContext's pickFile", () => {
40
40
  jest.spyOn(Alert, 'alert');
41
41
  jest.spyOn(NativeUtils, 'pickDocument').mockImplementation(
42
42
  jest.fn().mockResolvedValue({
43
- cancelled: false,
44
- docs: [
43
+ assets: [
45
44
  generateFileAttachment({ size: 500000000 }),
46
45
  generateFileAttachment({ size: 600000000 }),
47
46
  ],
47
+ cancelled: false,
48
48
  }),
49
49
  );
50
50
 
@@ -54,9 +54,9 @@ export const useMessageDetailsForState = <
54
54
  const id = generateRandomId();
55
55
  newFileUploads.push({
56
56
  file: {
57
+ mimeType: attachment.mime_type,
57
58
  name: attachment.title || '',
58
59
  size: attachment.file_size,
59
- type: attachment.mime_type,
60
60
  },
61
61
  id,
62
62
  state: 'finished',
@@ -78,9 +78,9 @@ export const useMessageDetailsForState = <
78
78
  const id = generateRandomId();
79
79
  newFileUploads.push({
80
80
  file: {
81
+ mimeType: attachment.mime_type,
81
82
  name: attachment.title || '',
82
83
  size: attachment.file_size,
83
- type: attachment.mime_type,
84
84
  },
85
85
  id,
86
86
  state: 'finished',
@@ -58,6 +58,7 @@ export type OverlayProviderProps<
58
58
  >
59
59
  > &
60
60
  Pick<OverlayContextValue, 'translucentStatusBar'> & {
61
+ autoPlayVideo?: boolean;
61
62
  /**
62
63
  * The giphy version to render - check the keys of the [Image Object](https://developers.giphy.com/docs/api/schema#image-object) for possible values. Uses 'fixed_height' by default
63
64
  * */
@@ -64,6 +64,7 @@ export const OverlayProvider = <
64
64
  ) => {
65
65
  const bottomSheetCloseTimeoutRef = useRef<NodeJS.Timeout>();
66
66
  const {
67
+ autoPlayVideo,
67
68
  AttachmentPickerBottomSheetHandle = DefaultAttachmentPickerBottomSheetHandle,
68
69
  attachmentPickerBottomSheetHandleHeight,
69
70
  attachmentPickerBottomSheetHeight,
@@ -237,6 +238,7 @@ export const OverlayProvider = <
237
238
  )}
238
239
  {overlay === 'gallery' && (
239
240
  <ImageGallery<StreamChatGenerics>
241
+ autoPlayVideo={autoPlayVideo}
240
242
  giphyVersion={giphyVersion}
241
243
  imageGalleryCustomComponents={imageGalleryCustomComponents}
242
244
  imageGalleryGridHandleHeight={imageGalleryGridHandleHeight}
package/src/native.ts CHANGED
@@ -57,7 +57,7 @@ export let NetInfo: NetInfo = {
57
57
  type PickDocument = ({ maxNumberOfFiles }: { maxNumberOfFiles?: number }) =>
58
58
  | Promise<{
59
59
  cancelled: boolean;
60
- docs?: File[];
60
+ assets?: File[];
61
61
  }>
62
62
  | never;
63
63
  export let pickDocument: PickDocument = fail;
@@ -13,15 +13,19 @@ export type Asset = {
13
13
  size?: number | string;
14
14
  };
15
15
 
16
- export type File = {
16
+ export type FileAssetType = {
17
17
  name: string;
18
- duration?: string | null;
19
- id?: string;
18
+ mimeType?: string;
20
19
  size?: number | string;
21
- type?: string;
20
+ // The uri should be of type `string`. But is `string|undefined` because the same type is used for the response from Stream's Attachment. This shall be fixed.
22
21
  uri?: string;
23
22
  };
24
23
 
24
+ export type File = FileAssetType & {
25
+ duration?: string | null;
26
+ id?: string;
27
+ };
28
+
25
29
  export type DefaultAttachmentType = UnknownType & {
26
30
  file_size?: number | string;
27
31
  mime_type?: string;
@@ -34,6 +38,7 @@ interface DefaultUserType extends UnknownType {
34
38
 
35
39
  interface DefaultChannelType extends UnknownType {
36
40
  [key: string]: unknown;
41
+
37
42
  image?: string;
38
43
  }
39
44
 
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.15.3"
2
+ "version": "5.16.0-beta.2"
3
3
  }