stream-chat-react-native-core 9.0.2-beta.2 → 9.1.0-beta.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 (212) hide show
  1. package/lib/commonjs/components/Attachment/Attachment.js +38 -10
  2. package/lib/commonjs/components/Attachment/Attachment.js.map +1 -1
  3. package/lib/commonjs/components/Attachment/AttachmentFileUploadProgressIndicator.js +97 -0
  4. package/lib/commonjs/components/Attachment/AttachmentFileUploadProgressIndicator.js.map +1 -0
  5. package/lib/commonjs/components/Attachment/AttachmentUploadIndicator.js +97 -0
  6. package/lib/commonjs/components/Attachment/AttachmentUploadIndicator.js.map +1 -0
  7. package/lib/commonjs/components/Attachment/CircularProgressIndicator.js +141 -0
  8. package/lib/commonjs/components/Attachment/CircularProgressIndicator.js.map +1 -0
  9. package/lib/commonjs/components/Attachment/FileAttachment.js +18 -4
  10. package/lib/commonjs/components/Attachment/FileAttachment.js.map +1 -1
  11. package/lib/commonjs/components/Attachment/Gallery.js +7 -1
  12. package/lib/commonjs/components/Attachment/Gallery.js.map +1 -1
  13. package/lib/commonjs/components/Attachment/MediaUploadProgressOverlay.js +59 -0
  14. package/lib/commonjs/components/Attachment/MediaUploadProgressOverlay.js.map +1 -0
  15. package/lib/commonjs/components/Attachment/VideoThumbnail.js +18 -8
  16. package/lib/commonjs/components/Attachment/VideoThumbnail.js.map +1 -1
  17. package/lib/commonjs/components/Attachment/utils/buildGallery/buildThumbnail.js +2 -0
  18. package/lib/commonjs/components/Attachment/utils/buildGallery/buildThumbnail.js.map +1 -1
  19. package/lib/commonjs/components/Channel/Channel.js +94 -92
  20. package/lib/commonjs/components/Channel/Channel.js.map +1 -1
  21. package/lib/commonjs/components/Chat/Chat.js +10 -1
  22. package/lib/commonjs/components/Chat/Chat.js.map +1 -1
  23. package/lib/commonjs/components/MessageInput/components/AttachmentPreview/AttachmentUploadProgressIndicator.js +42 -54
  24. package/lib/commonjs/components/MessageInput/components/AttachmentPreview/AttachmentUploadProgressIndicator.js.map +1 -1
  25. package/lib/commonjs/components/MessageInput/components/AttachmentPreview/AudioAttachmentUploadPreview.js +10 -6
  26. package/lib/commonjs/components/MessageInput/components/AttachmentPreview/AudioAttachmentUploadPreview.js.map +1 -1
  27. package/lib/commonjs/components/MessageInput/components/AttachmentPreview/FileAttachmentUploadPreview.js +12 -6
  28. package/lib/commonjs/components/MessageInput/components/AttachmentPreview/FileAttachmentUploadPreview.js.map +1 -1
  29. package/lib/commonjs/components/MessageInput/components/AttachmentPreview/ImageAttachmentUploadPreview.js +13 -7
  30. package/lib/commonjs/components/MessageInput/components/AttachmentPreview/ImageAttachmentUploadPreview.js.map +1 -1
  31. package/lib/commonjs/components/MessageInput/components/AttachmentPreview/VideoAttachmentUploadPreview.js +6 -2
  32. package/lib/commonjs/components/MessageInput/components/AttachmentPreview/VideoAttachmentUploadPreview.js.map +1 -1
  33. package/lib/commonjs/components/index.js +33 -0
  34. package/lib/commonjs/components/index.js.map +1 -1
  35. package/lib/commonjs/contexts/componentsContext/defaultComponents.js +6 -0
  36. package/lib/commonjs/contexts/componentsContext/defaultComponents.js.map +1 -1
  37. package/lib/commonjs/contexts/messageInputContext/hooks/useCreateMessageInputContext.js +3 -1
  38. package/lib/commonjs/contexts/messageInputContext/hooks/useCreateMessageInputContext.js.map +1 -1
  39. package/lib/commonjs/contexts/messageInputContext/hooks/useMessageComposerHasSendableData.js +4 -1
  40. package/lib/commonjs/contexts/messageInputContext/hooks/useMessageComposerHasSendableData.js.map +1 -1
  41. package/lib/commonjs/contexts/themeContext/utils/theme.js +5 -0
  42. package/lib/commonjs/contexts/themeContext/utils/theme.js.map +1 -1
  43. package/lib/commonjs/hooks/index.js +11 -0
  44. package/lib/commonjs/hooks/index.js.map +1 -1
  45. package/lib/commonjs/hooks/usePendingAttachmentUpload.js +106 -0
  46. package/lib/commonjs/hooks/usePendingAttachmentUpload.js.map +1 -0
  47. package/lib/commonjs/index.js +12 -0
  48. package/lib/commonjs/index.js.map +1 -1
  49. package/lib/commonjs/middlewares/attachments.js +2 -0
  50. package/lib/commonjs/middlewares/attachments.js.map +1 -1
  51. package/lib/commonjs/native.js +8 -1
  52. package/lib/commonjs/native.js.map +1 -1
  53. package/lib/commonjs/nativeMultipartUpload.js +237 -0
  54. package/lib/commonjs/nativeMultipartUpload.js.map +1 -0
  55. package/lib/commonjs/types/types.js.map +1 -1
  56. package/lib/commonjs/utils/installNativeMultipartAdapter.js +223 -0
  57. package/lib/commonjs/utils/installNativeMultipartAdapter.js.map +1 -0
  58. package/lib/commonjs/utils/utils.js +2 -2
  59. package/lib/commonjs/utils/utils.js.map +1 -1
  60. package/lib/commonjs/version.json +1 -1
  61. package/lib/module/components/Attachment/Attachment.js +38 -10
  62. package/lib/module/components/Attachment/Attachment.js.map +1 -1
  63. package/lib/module/components/Attachment/AttachmentFileUploadProgressIndicator.js +97 -0
  64. package/lib/module/components/Attachment/AttachmentFileUploadProgressIndicator.js.map +1 -0
  65. package/lib/module/components/Attachment/AttachmentUploadIndicator.js +97 -0
  66. package/lib/module/components/Attachment/AttachmentUploadIndicator.js.map +1 -0
  67. package/lib/module/components/Attachment/CircularProgressIndicator.js +141 -0
  68. package/lib/module/components/Attachment/CircularProgressIndicator.js.map +1 -0
  69. package/lib/module/components/Attachment/FileAttachment.js +18 -4
  70. package/lib/module/components/Attachment/FileAttachment.js.map +1 -1
  71. package/lib/module/components/Attachment/Gallery.js +7 -1
  72. package/lib/module/components/Attachment/Gallery.js.map +1 -1
  73. package/lib/module/components/Attachment/MediaUploadProgressOverlay.js +59 -0
  74. package/lib/module/components/Attachment/MediaUploadProgressOverlay.js.map +1 -0
  75. package/lib/module/components/Attachment/VideoThumbnail.js +18 -8
  76. package/lib/module/components/Attachment/VideoThumbnail.js.map +1 -1
  77. package/lib/module/components/Attachment/utils/buildGallery/buildThumbnail.js +2 -0
  78. package/lib/module/components/Attachment/utils/buildGallery/buildThumbnail.js.map +1 -1
  79. package/lib/module/components/Channel/Channel.js +94 -92
  80. package/lib/module/components/Channel/Channel.js.map +1 -1
  81. package/lib/module/components/Chat/Chat.js +10 -1
  82. package/lib/module/components/Chat/Chat.js.map +1 -1
  83. package/lib/module/components/MessageInput/components/AttachmentPreview/AttachmentUploadProgressIndicator.js +42 -54
  84. package/lib/module/components/MessageInput/components/AttachmentPreview/AttachmentUploadProgressIndicator.js.map +1 -1
  85. package/lib/module/components/MessageInput/components/AttachmentPreview/AudioAttachmentUploadPreview.js +10 -6
  86. package/lib/module/components/MessageInput/components/AttachmentPreview/AudioAttachmentUploadPreview.js.map +1 -1
  87. package/lib/module/components/MessageInput/components/AttachmentPreview/FileAttachmentUploadPreview.js +12 -6
  88. package/lib/module/components/MessageInput/components/AttachmentPreview/FileAttachmentUploadPreview.js.map +1 -1
  89. package/lib/module/components/MessageInput/components/AttachmentPreview/ImageAttachmentUploadPreview.js +13 -7
  90. package/lib/module/components/MessageInput/components/AttachmentPreview/ImageAttachmentUploadPreview.js.map +1 -1
  91. package/lib/module/components/MessageInput/components/AttachmentPreview/VideoAttachmentUploadPreview.js +6 -2
  92. package/lib/module/components/MessageInput/components/AttachmentPreview/VideoAttachmentUploadPreview.js.map +1 -1
  93. package/lib/module/components/index.js +33 -0
  94. package/lib/module/components/index.js.map +1 -1
  95. package/lib/module/contexts/componentsContext/defaultComponents.js +6 -0
  96. package/lib/module/contexts/componentsContext/defaultComponents.js.map +1 -1
  97. package/lib/module/contexts/messageInputContext/hooks/useCreateMessageInputContext.js +3 -1
  98. package/lib/module/contexts/messageInputContext/hooks/useCreateMessageInputContext.js.map +1 -1
  99. package/lib/module/contexts/messageInputContext/hooks/useMessageComposerHasSendableData.js +4 -1
  100. package/lib/module/contexts/messageInputContext/hooks/useMessageComposerHasSendableData.js.map +1 -1
  101. package/lib/module/contexts/themeContext/utils/theme.js +5 -0
  102. package/lib/module/contexts/themeContext/utils/theme.js.map +1 -1
  103. package/lib/module/hooks/index.js +11 -0
  104. package/lib/module/hooks/index.js.map +1 -1
  105. package/lib/module/hooks/usePendingAttachmentUpload.js +106 -0
  106. package/lib/module/hooks/usePendingAttachmentUpload.js.map +1 -0
  107. package/lib/module/index.js +12 -0
  108. package/lib/module/index.js.map +1 -1
  109. package/lib/module/middlewares/attachments.js +2 -0
  110. package/lib/module/middlewares/attachments.js.map +1 -1
  111. package/lib/module/native.js +8 -1
  112. package/lib/module/native.js.map +1 -1
  113. package/lib/module/nativeMultipartUpload.js +237 -0
  114. package/lib/module/nativeMultipartUpload.js.map +1 -0
  115. package/lib/module/types/types.js.map +1 -1
  116. package/lib/module/utils/installNativeMultipartAdapter.js +223 -0
  117. package/lib/module/utils/installNativeMultipartAdapter.js.map +1 -0
  118. package/lib/module/utils/utils.js +2 -2
  119. package/lib/module/utils/utils.js.map +1 -1
  120. package/lib/module/version.json +1 -1
  121. package/lib/typescript/components/Attachment/Attachment.d.ts.map +1 -1
  122. package/lib/typescript/components/Attachment/AttachmentFileUploadProgressIndicator.d.ts +14 -0
  123. package/lib/typescript/components/Attachment/AttachmentFileUploadProgressIndicator.d.ts.map +1 -0
  124. package/lib/typescript/components/Attachment/AttachmentUploadIndicator.d.ts +18 -0
  125. package/lib/typescript/components/Attachment/AttachmentUploadIndicator.d.ts.map +1 -0
  126. package/lib/typescript/components/Attachment/CircularProgressIndicator.d.ts +18 -0
  127. package/lib/typescript/components/Attachment/CircularProgressIndicator.d.ts.map +1 -0
  128. package/lib/typescript/components/Attachment/FileAttachment.d.ts.map +1 -1
  129. package/lib/typescript/components/Attachment/Gallery.d.ts.map +1 -1
  130. package/lib/typescript/components/Attachment/MediaUploadProgressOverlay.d.ts +12 -0
  131. package/lib/typescript/components/Attachment/MediaUploadProgressOverlay.d.ts.map +1 -0
  132. package/lib/typescript/components/Attachment/VideoThumbnail.d.ts +4 -0
  133. package/lib/typescript/components/Attachment/VideoThumbnail.d.ts.map +1 -1
  134. package/lib/typescript/components/Attachment/utils/buildGallery/buildThumbnail.d.ts.map +1 -1
  135. package/lib/typescript/components/Attachment/utils/buildGallery/types.d.ts +2 -0
  136. package/lib/typescript/components/Attachment/utils/buildGallery/types.d.ts.map +1 -1
  137. package/lib/typescript/components/Channel/Channel.d.ts.map +1 -1
  138. package/lib/typescript/components/Chat/Chat.d.ts +10 -0
  139. package/lib/typescript/components/Chat/Chat.d.ts.map +1 -1
  140. package/lib/typescript/components/MessageInput/components/AttachmentPreview/AttachmentUploadProgressIndicator.d.ts +7 -2
  141. package/lib/typescript/components/MessageInput/components/AttachmentPreview/AttachmentUploadProgressIndicator.d.ts.map +1 -1
  142. package/lib/typescript/components/MessageInput/components/AttachmentPreview/AudioAttachmentUploadPreview.d.ts.map +1 -1
  143. package/lib/typescript/components/MessageInput/components/AttachmentPreview/FileAttachmentUploadPreview.d.ts.map +1 -1
  144. package/lib/typescript/components/MessageInput/components/AttachmentPreview/ImageAttachmentUploadPreview.d.ts.map +1 -1
  145. package/lib/typescript/components/MessageInput/components/AttachmentPreview/VideoAttachmentUploadPreview.d.ts.map +1 -1
  146. package/lib/typescript/components/index.d.ts +3 -0
  147. package/lib/typescript/components/index.d.ts.map +1 -1
  148. package/lib/typescript/contexts/componentsContext/defaultComponents.d.ts +5 -2
  149. package/lib/typescript/contexts/componentsContext/defaultComponents.d.ts.map +1 -1
  150. package/lib/typescript/contexts/messageInputContext/hooks/useCreateMessageInputContext.d.ts +1 -1
  151. package/lib/typescript/contexts/messageInputContext/hooks/useCreateMessageInputContext.d.ts.map +1 -1
  152. package/lib/typescript/contexts/messageInputContext/hooks/useMessageComposerHasSendableData.d.ts.map +1 -1
  153. package/lib/typescript/contexts/themeContext/ThemeContext.d.ts +5 -0
  154. package/lib/typescript/contexts/themeContext/ThemeContext.d.ts.map +1 -1
  155. package/lib/typescript/contexts/themeContext/utils/theme.d.ts +5 -0
  156. package/lib/typescript/contexts/themeContext/utils/theme.d.ts.map +1 -1
  157. package/lib/typescript/hooks/index.d.ts +1 -0
  158. package/lib/typescript/hooks/index.d.ts.map +1 -1
  159. package/lib/typescript/hooks/usePendingAttachmentUpload.d.ts +14 -0
  160. package/lib/typescript/hooks/usePendingAttachmentUpload.d.ts.map +1 -0
  161. package/lib/typescript/index.d.ts +1 -0
  162. package/lib/typescript/index.d.ts.map +1 -1
  163. package/lib/typescript/middlewares/attachments.d.ts.map +1 -1
  164. package/lib/typescript/native.d.ts +5 -2
  165. package/lib/typescript/native.d.ts.map +1 -1
  166. package/lib/typescript/nativeMultipartUpload.d.ts +98 -0
  167. package/lib/typescript/nativeMultipartUpload.d.ts.map +1 -0
  168. package/lib/typescript/types/types.d.ts +2 -0
  169. package/lib/typescript/types/types.d.ts.map +1 -1
  170. package/lib/typescript/utils/installNativeMultipartAdapter.d.ts +8 -0
  171. package/lib/typescript/utils/installNativeMultipartAdapter.d.ts.map +1 -0
  172. package/lib/typescript/utils/utils.d.ts +1 -1
  173. package/lib/typescript/utils/utils.d.ts.map +1 -1
  174. package/package.json +2 -2
  175. package/src/__tests__/nativeMultipartUpload.test.ts +267 -0
  176. package/src/components/Attachment/Attachment.tsx +54 -5
  177. package/src/components/Attachment/AttachmentFileUploadProgressIndicator.tsx +108 -0
  178. package/src/components/Attachment/AttachmentUploadIndicator.tsx +112 -0
  179. package/src/components/Attachment/CircularProgressIndicator.tsx +161 -0
  180. package/src/components/Attachment/FileAttachment.tsx +22 -6
  181. package/src/components/Attachment/Gallery.tsx +9 -1
  182. package/src/components/Attachment/MediaUploadProgressOverlay.tsx +77 -0
  183. package/src/components/Attachment/VideoThumbnail.tsx +17 -9
  184. package/src/components/Attachment/__tests__/Attachment.test.tsx +63 -16
  185. package/src/components/Attachment/utils/buildGallery/buildThumbnail.ts +3 -0
  186. package/src/components/Attachment/utils/buildGallery/types.ts +2 -0
  187. package/src/components/Channel/Channel.tsx +65 -61
  188. package/src/components/Chat/Chat.tsx +20 -0
  189. package/src/components/MessageInput/__tests__/AttachmentUploadPreviewList.test.tsx +51 -6
  190. package/src/components/MessageInput/__tests__/AudioAttachmentUploadPreview.test.tsx +31 -1
  191. package/src/components/MessageInput/components/AttachmentPreview/AttachmentUploadProgressIndicator.tsx +30 -44
  192. package/src/components/MessageInput/components/AttachmentPreview/AudioAttachmentUploadPreview.tsx +11 -5
  193. package/src/components/MessageInput/components/AttachmentPreview/FileAttachmentUploadPreview.tsx +20 -5
  194. package/src/components/MessageInput/components/AttachmentPreview/ImageAttachmentUploadPreview.tsx +20 -9
  195. package/src/components/MessageInput/components/AttachmentPreview/VideoAttachmentUploadPreview.tsx +7 -1
  196. package/src/components/index.ts +3 -0
  197. package/src/contexts/componentsContext/defaultComponents.ts +6 -0
  198. package/src/contexts/messageInputContext/hooks/useCreateMessageInputContext.ts +3 -1
  199. package/src/contexts/messageInputContext/hooks/useMessageComposerHasSendableData.ts +5 -1
  200. package/src/contexts/themeContext/utils/theme.ts +10 -0
  201. package/src/hooks/__tests__/usePendingAttachmentUpload.test.tsx +106 -0
  202. package/src/hooks/index.ts +1 -0
  203. package/src/hooks/usePendingAttachmentUpload.ts +131 -0
  204. package/src/index.ts +1 -0
  205. package/src/middlewares/attachments.ts +2 -0
  206. package/src/native.ts +28 -0
  207. package/src/nativeMultipartUpload.ts +384 -0
  208. package/src/types/types.ts +2 -0
  209. package/src/utils/__tests__/installNativeMultipartAdapter.test.ts +437 -0
  210. package/src/utils/installNativeMultipartAdapter.ts +302 -0
  211. package/src/utils/utils.ts +3 -3
  212. package/src/version.json +1 -1
@@ -0,0 +1,302 @@
1
+ import axios from 'axios';
2
+ import type { AxiosAdapter, AxiosProgressEvent, InternalAxiosRequestConfig } from 'axios';
3
+ import type { StreamChat } from 'stream-chat';
4
+
5
+ import {
6
+ isNativeMultipartUploadAvailable,
7
+ NativeHandlers,
8
+ NativeMultipartUploadProgressConfig,
9
+ NativeMultipartUploadRequest,
10
+ } from '../native';
11
+
12
+ type FormDataPartValue =
13
+ | string
14
+ | {
15
+ contentType?: string;
16
+ name?: string;
17
+ type?: string;
18
+ uri: string;
19
+ };
20
+
21
+ type NativeMultipartAxiosRequestConfig = InternalAxiosRequestConfig & {
22
+ onUploadProgress?: (event: AxiosProgressEvent) => void;
23
+ uploadProgressOptions?: NativeMultipartUploadProgressConfig;
24
+ uploadProgress?: (event: AxiosProgressEvent) => void;
25
+ };
26
+
27
+ type ResolvableAxiosAdapter = Parameters<typeof axios.getAdapter>[0];
28
+
29
+ const DEFAULT_COMPLETION_PROGRESS_CAP = 90;
30
+
31
+ const installedAdapters = new WeakSet<StreamChat>();
32
+
33
+ const getFormDataEntries = (data: unknown): [string, FormDataPartValue][] | null => {
34
+ if (!data || typeof data !== 'object') {
35
+ return null;
36
+ }
37
+
38
+ if ('entries' in data && typeof data.entries === 'function') {
39
+ return Array.from(data.entries()) as [string, FormDataPartValue][];
40
+ }
41
+
42
+ const parts = Reflect.get(data, '_parts');
43
+
44
+ if (Array.isArray(parts)) {
45
+ return parts as [string, FormDataPartValue][];
46
+ }
47
+
48
+ return null;
49
+ };
50
+
51
+ const normalizeHeaders = (
52
+ headers: NativeMultipartAxiosRequestConfig['headers'],
53
+ ): Record<string, string> => {
54
+ const rawHeaders = headers?.toJSON() ?? {};
55
+ const normalizedHeaders: Record<string, string> = {};
56
+
57
+ Object.entries(rawHeaders ?? {}).forEach(([key, value]) => {
58
+ if (value == null) {
59
+ return;
60
+ }
61
+
62
+ normalizedHeaders[key] = Array.isArray(value) ? value.join(', ') : String(value);
63
+ });
64
+
65
+ return normalizedHeaders;
66
+ };
67
+
68
+ const getFileNameFromUri = (uri: string) => uri.split('/').filter(Boolean).pop() || 'file';
69
+
70
+ const getNativeProgressOptions = (
71
+ progress?: NativeMultipartUploadProgressConfig,
72
+ ): NativeMultipartUploadProgressConfig | undefined => {
73
+ if (!progress) {
74
+ return undefined;
75
+ }
76
+
77
+ const nativeProgressOptions = { ...progress };
78
+ delete nativeProgressOptions.completionProgressCap;
79
+
80
+ return Object.keys(nativeProgressOptions).length ? nativeProgressOptions : undefined;
81
+ };
82
+
83
+ const createNativeMultipartRequest = (
84
+ client: StreamChat,
85
+ config: NativeMultipartAxiosRequestConfig,
86
+ ): NativeMultipartUploadRequest | null => {
87
+ const entries = getFormDataEntries(config.data);
88
+
89
+ if (!entries) {
90
+ return null;
91
+ }
92
+
93
+ const parts: NativeMultipartUploadRequest['parts'] = [];
94
+
95
+ for (const [fieldName, value] of entries) {
96
+ if (typeof value === 'string') {
97
+ parts.push({
98
+ fieldName,
99
+ kind: 'text',
100
+ value,
101
+ });
102
+ continue;
103
+ }
104
+
105
+ if (value && typeof value === 'object' && 'uri' in value && typeof value.uri === 'string') {
106
+ parts.push({
107
+ fieldName,
108
+ fileName: value.name || getFileNameFromUri(value.uri),
109
+ kind: 'file',
110
+ mimeType: value.type || value.contentType,
111
+ uri: value.uri,
112
+ });
113
+ continue;
114
+ }
115
+
116
+ return null;
117
+ }
118
+
119
+ if (!parts.some((part) => part.kind === 'file')) {
120
+ return null;
121
+ }
122
+
123
+ return {
124
+ headers: normalizeHeaders(config.headers),
125
+ method: (config.method || 'POST').toUpperCase(),
126
+ parts,
127
+ progress: getNativeProgressOptions(config.uploadProgressOptions),
128
+ signal: config.signal,
129
+ timeoutMs: config.timeout,
130
+ url: client.axiosInstance.getUri(config),
131
+ };
132
+ };
133
+
134
+ const toFiniteNumber = (value: unknown) => {
135
+ if (typeof value === 'number') {
136
+ return Number.isFinite(value) ? value : undefined;
137
+ }
138
+
139
+ if (typeof value === 'string' && value.trim()) {
140
+ const parsed = Number(value);
141
+ return Number.isFinite(parsed) ? parsed : undefined;
142
+ }
143
+
144
+ return undefined;
145
+ };
146
+
147
+ const getCompletionProgressCap = (config: NativeMultipartAxiosRequestConfig) => {
148
+ const cap = toFiniteNumber(config.uploadProgressOptions?.completionProgressCap);
149
+ if (cap === undefined) {
150
+ return DEFAULT_COMPLETION_PROGRESS_CAP;
151
+ }
152
+
153
+ return Math.min(100, Math.max(0, cap));
154
+ };
155
+
156
+ const getDisplayLoaded = ({
157
+ completionProgressCap,
158
+ loaded,
159
+ total,
160
+ }: {
161
+ completionProgressCap: number;
162
+ loaded: number;
163
+ total?: number;
164
+ }) => {
165
+ if (typeof total !== 'number' || total <= 0) {
166
+ return loaded;
167
+ }
168
+
169
+ return Math.min(loaded, total * (completionProgressCap / 100));
170
+ };
171
+
172
+ const getUploadProgressCallbacks = (config: NativeMultipartAxiosRequestConfig) => {
173
+ const callbacks = [config.onUploadProgress, config.uploadProgress].filter(
174
+ (callback): callback is NonNullable<typeof config.onUploadProgress> =>
175
+ typeof callback === 'function',
176
+ );
177
+
178
+ return Array.from(new Set(callbacks));
179
+ };
180
+
181
+ const createUploadProgressEvent = ({
182
+ bytes,
183
+ loaded,
184
+ total,
185
+ }: {
186
+ bytes: unknown;
187
+ loaded: unknown;
188
+ total?: unknown;
189
+ }) => {
190
+ const normalizedBytes = toFiniteNumber(bytes) ?? 0;
191
+ const normalizedLoaded = toFiniteNumber(loaded) ?? 0;
192
+ const normalizedTotal = toFiniteNumber(total);
193
+
194
+ return {
195
+ bytes: normalizedBytes,
196
+ download: false,
197
+ event: undefined,
198
+ lengthComputable: typeof normalizedTotal === 'number' && normalizedTotal > 0,
199
+ loaded: normalizedLoaded,
200
+ progress:
201
+ typeof normalizedTotal === 'number' && normalizedTotal > 0
202
+ ? normalizedLoaded / normalizedTotal
203
+ : undefined,
204
+ total: normalizedTotal,
205
+ upload: true,
206
+ };
207
+ };
208
+
209
+ const nativeMultipartAxiosAdapter = async (
210
+ request: NativeMultipartUploadRequest,
211
+ config: NativeMultipartAxiosRequestConfig,
212
+ ) => {
213
+ const uploadProgressCallbacks = getUploadProgressCallbacks(config);
214
+ const completionProgressCap = getCompletionProgressCap(config);
215
+ let lastLoaded = 0;
216
+
217
+ const response = await NativeHandlers.multipartUpload({
218
+ ...request,
219
+ onProgress: uploadProgressCallbacks.length
220
+ ? ({ loaded, total }) => {
221
+ const normalizedLoaded = toFiniteNumber(loaded) ?? 0;
222
+ const normalizedTotal = toFiniteNumber(total);
223
+ const displayLoaded = getDisplayLoaded({
224
+ completionProgressCap,
225
+ loaded: normalizedLoaded,
226
+ total: normalizedTotal,
227
+ });
228
+ const event = createUploadProgressEvent({
229
+ bytes: Math.max(0, displayLoaded - lastLoaded),
230
+ loaded: displayLoaded,
231
+ total: normalizedTotal,
232
+ });
233
+ lastLoaded = displayLoaded;
234
+ uploadProgressCallbacks.forEach((callback) => callback(event));
235
+ }
236
+ : undefined,
237
+ });
238
+
239
+ if (!response) {
240
+ throw new Error('Native multipart upload did not return a response');
241
+ }
242
+
243
+ return {
244
+ config,
245
+ data: response.body,
246
+ headers: response.headers ?? {},
247
+ request: null,
248
+ status: response.status,
249
+ statusText: response.statusText ?? '',
250
+ };
251
+ };
252
+
253
+ const resolveAxiosAdapter = (adapter: ResolvableAxiosAdapter): AxiosAdapter =>
254
+ axios.getAdapter(adapter);
255
+
256
+ const createNativeMultipartAwareAdapter = (
257
+ client: StreamChat,
258
+ fallbackAdapter: ResolvableAxiosAdapter,
259
+ ): AxiosAdapter => {
260
+ const resolvedFallbackAdapter = resolveAxiosAdapter(fallbackAdapter);
261
+
262
+ return (config) => {
263
+ const nativeMultipartRequest = createNativeMultipartRequest(
264
+ client,
265
+ config as NativeMultipartAxiosRequestConfig,
266
+ );
267
+
268
+ if (!nativeMultipartRequest) {
269
+ return resolvedFallbackAdapter(config);
270
+ }
271
+
272
+ return nativeMultipartAxiosAdapter(nativeMultipartRequest, config);
273
+ };
274
+ };
275
+
276
+ export const wrapAxiosAdapterWithNativeMultipart = (
277
+ client: StreamChat,
278
+ fallbackAdapter: ResolvableAxiosAdapter,
279
+ ): AxiosAdapter => {
280
+ if (!isNativeMultipartUploadAvailable()) {
281
+ return resolveAxiosAdapter(fallbackAdapter);
282
+ }
283
+
284
+ return createNativeMultipartAwareAdapter(client, fallbackAdapter);
285
+ };
286
+
287
+ export const installNativeMultipartAdapter = (client: StreamChat) => {
288
+ if (!isNativeMultipartUploadAvailable()) {
289
+ return;
290
+ }
291
+
292
+ if (installedAdapters.has(client)) {
293
+ return;
294
+ }
295
+
296
+ const previousAdapter = client.axiosInstance.defaults.adapter;
297
+ client.axiosInstance.defaults.adapter = wrapAxiosAdapterWithNativeMultipart(
298
+ client,
299
+ previousAdapter,
300
+ );
301
+ installedAdapters.add(client);
302
+ };
@@ -57,14 +57,14 @@ type IndicatorStatesMap = Record<AttachmentLoadingState, Progress | undefined>;
57
57
 
58
58
  export const getIndicatorTypeForFileState = (
59
59
  fileState: AttachmentLoadingState,
60
- enableOfflineSupport: boolean,
60
+ allowSendBeforeAttachmentsUpload: boolean,
61
61
  ): Progress | undefined => {
62
62
  const indicatorMap: IndicatorStatesMap = {
63
- [FileState.UPLOADING]: enableOfflineSupport
63
+ [FileState.UPLOADING]: allowSendBeforeAttachmentsUpload
64
64
  ? ProgressIndicatorTypes.INACTIVE
65
65
  : ProgressIndicatorTypes.IN_PROGRESS,
66
66
  [FileState.BLOCKED]: ProgressIndicatorTypes.NOT_SUPPORTED,
67
- [FileState.FAILED]: enableOfflineSupport
67
+ [FileState.FAILED]: allowSendBeforeAttachmentsUpload
68
68
  ? ProgressIndicatorTypes.INACTIVE
69
69
  : ProgressIndicatorTypes.RETRY,
70
70
  [FileState.PENDING]: ProgressIndicatorTypes.PENDING,
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "9.0.2-beta.2"
2
+ "version": "9.1.0-beta.1"
3
3
  }