Skip to content

Commit 238e801

Browse files
authored
feat: keep attachments array and remove file and image uploads in MessageInput state (#2445)
BREAKING CHANGE: Removed fileOrder, imageOrder, fileUploads, imageUploads, uploadFile, uploadImage, removeFile, removeImage from the MessageInputContext. Use attachments, uploadAttachment, uploadNewFiles, upsertAttachments, removeAttachments instead.
1 parent 6431954 commit 238e801

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+582
-1683
lines changed
-243 KB
Loading
-2.79 KB
Loading
2.55 KB
Loading

docusaurus/docs/React/components/contexts/message-input-context.mdx

Lines changed: 22 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ Additional props to be passed to the underlying `AutoCompleteTextarea` component
2929

3030
### attachments
3131

32-
An array of attachments added to the current message.
32+
An array of attachments added to the current message. Every attachment object carries attribute `localMetadata` that is internally used to manage the attachment state in the composer (update, remove attachments from the state, keep reference to uploaded files, keep information about the file upload state). The `localMetadata` object is discarded from each attachment object before sending the resulting message to the server. The attachments array does not contain attachments created by URL enrichment. These scraped attachments are kept in `linkPreviews` map.
3333

34-
| Type |
35-
| ------------ |
36-
| Attachment[] |
34+
| Type |
35+
| ----------------- |
36+
| LocalAttachment[] |
3737

3838
### autocompleteTriggers
3939

@@ -181,22 +181,6 @@ Custom error handler function to be called with a file/image upload fails.
181181
| ------------------------------------------------------------------------------------------------- |
182182
| (error: Error, type: string, file: (FileUpload \| ImageUpload)['file'] & { id?: string }) => void |
183183

184-
### fileOrder
185-
186-
The order in which file attachments have been added to the current message.
187-
188-
| Type |
189-
| -------- |
190-
| string[] |
191-
192-
### fileUploads
193-
194-
A mapping of the file attachments added to the current message.
195-
196-
| Type |
197-
| ---------------------------- |
198-
| { [id: string]: FileUpload } |
199-
200184
### findAndEnqueueURLsToEnrich
201185

202186
A function responsible for initiating URL discovery and their subsequent enrichment. It is available only if link preview rendering is enabled. Link previews are disabled by default.
@@ -253,22 +237,6 @@ Allows to hide MessageInput's send button. Used by `MessageSimple` to hide the s
253237
| ------- | ------- |
254238
| boolean | false |
255239

256-
### imageOrder
257-
258-
The order in which image attachments have been added to the current message.
259-
260-
| Type |
261-
| -------- |
262-
| string[] |
263-
264-
### imageUploads
265-
266-
A mapping of the image attachments added to the current message.
267-
268-
| Type |
269-
| ----------------------------- |
270-
| { [id: string]: ImageUpload } |
271-
272240
### insertText
273241

274242
Function to insert text into the value of the underlying `textarea` component.
@@ -304,7 +272,7 @@ If specified, this function overrides the default behavior specified previously.
304272

305273
### maxFilesLeft
306274

307-
The maximum number of allowed uploads minus the current number of uploads.
275+
The maximum number of allowed uploads minus the current number of successful uploads.
308276

309277
| Type |
310278
| ------ |
@@ -368,7 +336,7 @@ If true, disables file uploads for all attachments except for those with type 'i
368336

369337
### numberOfUploads
370338

371-
The number of file uploads on the current message.
339+
The number of successfully uploaded files for the current message.
372340

373341
| Type |
374342
| ------ |
@@ -468,22 +436,6 @@ const Component = () => {
468436
};
469437
```
470438

471-
### removeFile
472-
473-
Function to remove a file from the `fileUploads` mapping.
474-
475-
| Type |
476-
| -------------------- |
477-
| (id: string) => void |
478-
479-
### removeImage
480-
481-
Function to remove an image from the `imageUploads` mapping.
482-
483-
| Type |
484-
| -------------------- |
485-
| (id: string) => void |
486-
487439
### setCooldownRemaining
488440

489441
React state hook function that sets the `cooldownRemaining` value.
@@ -532,25 +484,30 @@ React mutable ref placed on the underlying `textarea` component.
532484
| -------------------------------------------- |
533485
| React.MutableRefObject<HTMLTextAreaElement\> |
534486

535-
### uploadFile
487+
### uploadAttachment
536488

537-
Function to upload a file to the `fileUploads` mapping.
489+
Uploads the file that comes as a part of the `attachment` object argument. The function expects the `attachment` object to contain attribute `localMetadata`, which in turn should contain `file` attribute referring to the file to be uploaded and an attribute `id` with attachment's unique identifier string. The `localMetadata` object is discarded when the message is posted.
538490

539-
| Type |
540-
| -------------------- |
541-
| (id: string) => void |
491+
So the minimum required `attachment` object for upload would be:
542492

543-
### uploadImage
493+
```
494+
type MinimumUploadAttachment = {
495+
localMetadata: {
496+
file: File | Blob;
497+
id: string;
498+
}
499+
}
500+
```
544501

545-
Function to upload an image.
502+
The function returns `undefined` if, custom upload function (`doImageUploadRequest`, `doFileUploadRequest`) fails.
546503

547-
| Type |
548-
| -------------------- |
549-
| (id: string) => void |
504+
| Type |
505+
| ---------------------------------------------------------------------------------------------------------------- |
506+
| `(attachment: LocalAttachment<StreamChatGenerics>) => Promise<LocalAttachment<StreamChatGenerics> \| undefined>` |
550507

551508
### uploadNewFiles
552509

553-
Function to upload an array of files to the `fileUploads` and `imageUploads` mappings.
510+
Function to upload an array of files and store the results as `LocalAttachment` objects in `attachments` array of the `MessageInputContext`.
554511

555512
| Type |
556513
| ----------------------------------- |

0 commit comments

Comments
 (0)