From 408ef863b4f1f46c34c697aa51d00f84fa4d692d Mon Sep 17 00:00:00 2001 From: rlee1990 Date: Fri, 29 Apr 2022 23:24:15 -0400 Subject: [PATCH 1/5] Update attachment_file_uploader.dart Added the option to add a Map of extra data that someone might need. --- .../lib/src/core/api/attachment_file_uploader.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/stream_chat/lib/src/core/api/attachment_file_uploader.dart b/packages/stream_chat/lib/src/core/api/attachment_file_uploader.dart index d6dc249f..00c0a13b 100644 --- a/packages/stream_chat/lib/src/core/api/attachment_file_uploader.dart +++ b/packages/stream_chat/lib/src/core/api/attachment_file_uploader.dart @@ -16,6 +16,7 @@ abstract class AttachmentFileUploader { String channelType, { ProgressCallback? onSendProgress, CancelToken? cancelToken, + Map? extraData, }); /// Uploads a [file] to the given channel. @@ -29,6 +30,7 @@ abstract class AttachmentFileUploader { String channelType, { ProgressCallback? onSendProgress, CancelToken? cancelToken, + Map? extraData, }); /// Deletes a image using its [url] from the given channel. @@ -40,6 +42,7 @@ abstract class AttachmentFileUploader { String channelId, String channelType, { CancelToken? cancelToken, + Map? extraData, }); /// Deletes a file using its [url] from the given channel. @@ -51,6 +54,7 @@ abstract class AttachmentFileUploader { String channelId, String channelType, { CancelToken? cancelToken, + Map? extraData, }); } @@ -68,6 +72,7 @@ class StreamAttachmentFileUploader implements AttachmentFileUploader { String channelType, { ProgressCallback? onSendProgress, CancelToken? cancelToken, + Map? extraData, }) async { final multiPartFile = await file.toMultipartFile(); final response = await _client.postFile( @@ -86,6 +91,7 @@ class StreamAttachmentFileUploader implements AttachmentFileUploader { String channelType, { ProgressCallback? onSendProgress, CancelToken? cancelToken, + Map? extraData, }) async { final multiPartFile = await file.toMultipartFile(); final response = await _client.postFile( @@ -103,6 +109,7 @@ class StreamAttachmentFileUploader implements AttachmentFileUploader { String channelId, String channelType, { CancelToken? cancelToken, + Map? extraData, }) async { final response = await _client.delete( '/channels/$channelType/$channelId/image', @@ -118,6 +125,7 @@ class StreamAttachmentFileUploader implements AttachmentFileUploader { String channelId, String channelType, { CancelToken? cancelToken, + Map? extraData, }) async { final response = await _client.delete( '/channels/$channelType/$channelId/file', From a13b926928990094a09c10312ce1a8cba9795edb Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Thu, 5 May 2022 19:24:37 +0530 Subject: [PATCH 2/5] Apply suggestions from code review --- .../src/core/api/attachment_file_uploader.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/stream_chat/lib/src/core/api/attachment_file_uploader.dart b/packages/stream_chat/lib/src/core/api/attachment_file_uploader.dart index 00c0a13b..096b2c2d 100644 --- a/packages/stream_chat/lib/src/core/api/attachment_file_uploader.dart +++ b/packages/stream_chat/lib/src/core/api/attachment_file_uploader.dart @@ -16,7 +16,7 @@ abstract class AttachmentFileUploader { String channelType, { ProgressCallback? onSendProgress, CancelToken? cancelToken, - Map? extraData, + Map? extraData, }); /// Uploads a [file] to the given channel. @@ -30,7 +30,7 @@ abstract class AttachmentFileUploader { String channelType, { ProgressCallback? onSendProgress, CancelToken? cancelToken, - Map? extraData, + Map? extraData, }); /// Deletes a image using its [url] from the given channel. @@ -42,7 +42,7 @@ abstract class AttachmentFileUploader { String channelId, String channelType, { CancelToken? cancelToken, - Map? extraData, + Map? extraData, }); /// Deletes a file using its [url] from the given channel. @@ -54,7 +54,7 @@ abstract class AttachmentFileUploader { String channelId, String channelType, { CancelToken? cancelToken, - Map? extraData, + Map? extraData, }); } @@ -72,7 +72,7 @@ class StreamAttachmentFileUploader implements AttachmentFileUploader { String channelType, { ProgressCallback? onSendProgress, CancelToken? cancelToken, - Map? extraData, + Map? extraData, }) async { final multiPartFile = await file.toMultipartFile(); final response = await _client.postFile( @@ -91,7 +91,7 @@ class StreamAttachmentFileUploader implements AttachmentFileUploader { String channelType, { ProgressCallback? onSendProgress, CancelToken? cancelToken, - Map? extraData, + Map? extraData, }) async { final multiPartFile = await file.toMultipartFile(); final response = await _client.postFile( @@ -109,7 +109,7 @@ class StreamAttachmentFileUploader implements AttachmentFileUploader { String channelId, String channelType, { CancelToken? cancelToken, - Map? extraData, + Map? extraData, }) async { final response = await _client.delete( '/channels/$channelType/$channelId/image', @@ -125,7 +125,7 @@ class StreamAttachmentFileUploader implements AttachmentFileUploader { String channelId, String channelType, { CancelToken? cancelToken, - Map? extraData, + Map? extraData, }) async { final response = await _client.delete( '/channels/$channelType/$channelId/file', From d62d42c8c47b6725faed2d163a606ea74d6ccfdf Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Thu, 5 May 2022 19:48:48 +0530 Subject: [PATCH 3/5] feat(llc): add support for extraData in while uploading file Signed-off-by: xsahil03x --- packages/stream_chat/lib/src/client/channel.dart | 10 ++++++++++ packages/stream_chat/lib/src/client/client.dart | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/stream_chat/lib/src/client/channel.dart b/packages/stream_chat/lib/src/client/channel.dart index abe8cf48..a3a490d4 100644 --- a/packages/stream_chat/lib/src/client/channel.dart +++ b/packages/stream_chat/lib/src/client/channel.dart @@ -436,12 +436,14 @@ class Channel { it.file!, onSendProgress: onSendProgress, cancelToken: cancelToken, + extraData: it.extraData, ).then((it) => it.file); } else { future = sendFile( it.file!, onSendProgress: onSendProgress, cancelToken: cancelToken, + extraData: it.extraData, ).then((it) => it.file); } _cancelableAttachmentUploadRequest[it.id] = cancelToken; @@ -735,6 +737,7 @@ class Channel { AttachmentFile file, { ProgressCallback? onSendProgress, CancelToken? cancelToken, + Map? extraData, }) { _checkInitialized(); return _client.sendFile( @@ -743,6 +746,7 @@ class Channel { type, onSendProgress: onSendProgress, cancelToken: cancelToken, + extraData: extraData, ); } @@ -751,6 +755,7 @@ class Channel { AttachmentFile file, { ProgressCallback? onSendProgress, CancelToken? cancelToken, + Map? extraData, }) { _checkInitialized(); return _client.sendImage( @@ -759,6 +764,7 @@ class Channel { type, onSendProgress: onSendProgress, cancelToken: cancelToken, + extraData: extraData, ); } @@ -783,6 +789,7 @@ class Channel { Future deleteFile( String url, { CancelToken? cancelToken, + Map? extraData, }) { _checkInitialized(); return _client.deleteFile( @@ -790,6 +797,7 @@ class Channel { id!, type, cancelToken: cancelToken, + extraData: extraData, ); } @@ -797,6 +805,7 @@ class Channel { Future deleteImage( String url, { CancelToken? cancelToken, + Map? extraData, }) { _checkInitialized(); return _client.deleteImage( @@ -804,6 +813,7 @@ class Channel { id!, type, cancelToken: cancelToken, + extraData: extraData, ); } diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index 69fd3180..e5efbc64 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -731,6 +731,7 @@ class StreamChatClient { String channelType, { ProgressCallback? onSendProgress, CancelToken? cancelToken, + Map? extraData, }) => _chatApi.fileUploader.sendFile( file, @@ -738,6 +739,7 @@ class StreamChatClient { channelType, onSendProgress: onSendProgress, cancelToken: cancelToken, + extraData: extraData, ); /// Send a [image] to the [channelId] of type [channelType] @@ -747,6 +749,7 @@ class StreamChatClient { String channelType, { ProgressCallback? onSendProgress, CancelToken? cancelToken, + Map? extraData, }) => _chatApi.fileUploader.sendImage( image, @@ -754,6 +757,7 @@ class StreamChatClient { channelType, onSendProgress: onSendProgress, cancelToken: cancelToken, + extraData: extraData, ); /// Delete a file from this channel @@ -762,12 +766,14 @@ class StreamChatClient { String channelId, String channelType, { CancelToken? cancelToken, + Map? extraData, }) => _chatApi.fileUploader.deleteFile( url, channelId, channelType, cancelToken: cancelToken, + extraData: extraData, ); /// Delete an image from this channel @@ -776,12 +782,14 @@ class StreamChatClient { String channelId, String channelType, { CancelToken? cancelToken, + Map? extraData, }) => _chatApi.fileUploader.deleteImage( url, channelId, channelType, cancelToken: cancelToken, + extraData: extraData, ); /// Replaces the [channelId] of type [ChannelType] data with [data]. From 893d28c6730b6fefa1ffaca54f272ac5179c685e Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Thu, 5 May 2022 20:17:01 +0530 Subject: [PATCH 4/5] chore(llc): update changelog Signed-off-by: xsahil03x --- packages/stream_chat/CHANGELOG.md | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/stream_chat/CHANGELOG.md b/packages/stream_chat/CHANGELOG.md index 3edd8c88..f5ed075b 100644 --- a/packages/stream_chat/CHANGELOG.md +++ b/packages/stream_chat/CHANGELOG.md @@ -1,10 +1,17 @@ +## Upcoming + +✅ Added + +- Added support for extra data in attachment file uploader. Thanks, [@rlee1990](https://github.com/rlee1990). + ## 4.0.1 - Minor fixes ## 4.0.0 -For upgrading to V4, please refer to the [V4 Migration Guide](https://getstream.io/chat/docs/sdk/flutter/guides/migration_guide_4_0/) +For upgrading to V4, please refer to +the [V4 Migration Guide](https://getstream.io/chat/docs/sdk/flutter/guides/migration_guide_4_0/) ✅ Added @@ -19,8 +26,10 @@ For upgrading to V4, please refer to the [V4 Migration Guide](https://getstream. any channel. - [[#1047]](https://github.com/GetStream/stream-chat-flutter/issues/1047) `own_capabilities` extraData missing after channel update. -- [[#1054]](https://github.com/GetStream/stream-chat-flutter/issues/1054) Fix `Unsupported operation: Cannot remove from an unmodifiable list`. -- [[#1033]](https://github.com/GetStream/stream-chat-flutter/issues/1033) Hard delete from dashboard does not delete message from client. +- [[#1054]](https://github.com/GetStream/stream-chat-flutter/issues/1054) + Fix `Unsupported operation: Cannot remove from an unmodifiable list`. +- [[#1033]](https://github.com/GetStream/stream-chat-flutter/issues/1033) Hard delete from dashboard does not delete + message from client. - Send only `user_id` while reconnecting. ✅ Added @@ -53,8 +62,10 @@ For upgrading to V4, please refer to the [V4 Migration Guide](https://getstream. any channel. - [[#1047]](https://github.com/GetStream/stream-chat-flutter/issues/1047) `own_capabilities` extraData missing after channel update. -- [[#1054]](https://github.com/GetStream/stream-chat-flutter/issues/1054) Fix `Unsupported operation: Cannot remove from an unmodifiable list`. -- [[#1033]](https://github.com/GetStream/stream-chat-flutter/issues/1033) Hard delete from dashboard does not delete message from client. +- [[#1054]](https://github.com/GetStream/stream-chat-flutter/issues/1054) + Fix `Unsupported operation: Cannot remove from an unmodifiable list`. +- [[#1033]](https://github.com/GetStream/stream-chat-flutter/issues/1033) Hard delete from dashboard does not delete + message from client. - Send only `user_id` while reconnecting. ✅ Added From 2e8f630d5fb12d323016e16454de14feaded0165 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Fri, 6 May 2022 15:56:08 +0530 Subject: [PATCH 5/5] test(llc): update sendImage, sendFile tests Signed-off-by: xsahil03x --- packages/stream_chat/test/src/client/channel_test.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/stream_chat/test/src/client/channel_test.dart b/packages/stream_chat/test/src/client/channel_test.dart index 9452a433..f90430f2 100644 --- a/packages/stream_chat/test/src/client/channel_test.dart +++ b/packages/stream_chat/test/src/client/channel_test.dart @@ -313,6 +313,7 @@ void main() { channelType, onSendProgress: any(named: 'onSendProgress'), cancelToken: any(named: 'cancelToken'), + extraData: any(named: 'extraData'), )).thenAnswer((_) async => sendImageResponse); when(() => client.sendFile( @@ -321,6 +322,7 @@ void main() { channelType, onSendProgress: any(named: 'onSendProgress'), cancelToken: any(named: 'cancelToken'), + extraData: any(named: 'extraData'), )).thenAnswer((_) async => sendFileResponse); when(() => client.sendMessage( @@ -440,6 +442,7 @@ void main() { channelType, onSendProgress: any(named: 'onSendProgress'), cancelToken: any(named: 'cancelToken'), + extraData: any(named: 'extraData'), )).called(2); verify(() => client.sendFile( @@ -448,6 +451,7 @@ void main() { channelType, onSendProgress: any(named: 'onSendProgress'), cancelToken: any(named: 'cancelToken'), + extraData: any(named: 'extraData'), )).called(1); verify(() => client.sendMessage( @@ -524,6 +528,7 @@ void main() { channelType, onSendProgress: any(named: 'onSendProgress'), cancelToken: any(named: 'cancelToken'), + extraData: any(named: 'extraData'), )).thenAnswer((_) async => sendImageResponse); when(() => client.sendFile( @@ -532,6 +537,7 @@ void main() { channelType, onSendProgress: any(named: 'onSendProgress'), cancelToken: any(named: 'cancelToken'), + extraData: any(named: 'extraData'), )).thenAnswer((_) async => sendFileResponse); when(() => client.updateMessage( @@ -649,6 +655,7 @@ void main() { channelType, onSendProgress: any(named: 'onSendProgress'), cancelToken: any(named: 'cancelToken'), + extraData: any(named: 'extraData'), )).called(2); verify(() => client.sendFile( @@ -657,6 +664,7 @@ void main() { channelType, onSendProgress: any(named: 'onSendProgress'), cancelToken: any(named: 'cancelToken'), + extraData: any(named: 'extraData'), )).called(1); verify(() => client.updateMessage(