From 23f61dd5ffe643bbbb6d13b694c808a0fadda7ca Mon Sep 17 00:00:00 2001 From: Freek van de Ven Date: Mon, 17 Feb 2025 16:41:02 +0100 Subject: [PATCH] feat: add senderId and chatId to uploadImage --- CHANGELOG.md | 1 + .../lib/src/interfaces/chat_repostory_interface.dart | 4 ++++ .../lib/src/local/local_chat_repository.dart | 2 ++ .../lib/src/services/chat_service.dart | 4 ++++ .../lib/src/firebase_chat_repository.dart | 2 ++ packages/flutter_chat/lib/src/routes.dart | 2 ++ 6 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 962e0d9..f992f83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Added chatTitleResolver that can be used to resolve the chat title from the chat model or return null to allow for default behavior - Added ChatPaginationControls to the ChatOptions to allow for more control over the pagination - Fixed that chat message is automatically sent when the user presses enter on the keyboard in the chat input +- Added sender and chatId to uploadImage in the ChatRepositoryInterface ## 4.0.0 - Move to the new user story architecture diff --git a/packages/chat_repository_interface/lib/src/interfaces/chat_repostory_interface.dart b/packages/chat_repository_interface/lib/src/interfaces/chat_repostory_interface.dart index dfa8872..2ee9ad1 100644 --- a/packages/chat_repository_interface/lib/src/interfaces/chat_repostory_interface.dart +++ b/packages/chat_repository_interface/lib/src/interfaces/chat_repostory_interface.dart @@ -105,9 +105,13 @@ abstract class ChatRepositoryInterface { /// Upload an image with the given parameters. /// [path] is the path of the image. /// [image] is the image data. + /// [senderId] is the sender id. + /// [chatId] is the chat id. /// Returns the image url. Future uploadImage({ required String path, + required String senderId, + required String chatId, required Uint8List image, }); } diff --git a/packages/chat_repository_interface/lib/src/local/local_chat_repository.dart b/packages/chat_repository_interface/lib/src/local/local_chat_repository.dart index 94c5059..fe9db50 100644 --- a/packages/chat_repository_interface/lib/src/local/local_chat_repository.dart +++ b/packages/chat_repository_interface/lib/src/local/local_chat_repository.dart @@ -268,6 +268,8 @@ class LocalChatRepository implements ChatRepositoryInterface { Future uploadImage({ required String path, required Uint8List image, + required String chatId, + required String senderId, }) => Future.value("https://picsum.photos/200/300"); diff --git a/packages/chat_repository_interface/lib/src/services/chat_service.dart b/packages/chat_repository_interface/lib/src/services/chat_service.dart index a465f3c..ebb5705 100644 --- a/packages/chat_repository_interface/lib/src/services/chat_service.dart +++ b/packages/chat_repository_interface/lib/src/services/chat_service.dart @@ -211,14 +211,18 @@ class ChatService { /// Upload an image with the given parameters. /// [path] is the image path. /// [image] is the image bytes. + /// [chatId] is the chat id. /// Returns a [Future] of [String]. Future uploadImage({ required String path, required Uint8List image, + required String chatId, }) => chatRepository.uploadImage( path: path, image: image, + senderId: userId, + chatId: chatId, ); /// Mark the chat as read with the given parameters. diff --git a/packages/firebase_chat_repository/lib/src/firebase_chat_repository.dart b/packages/firebase_chat_repository/lib/src/firebase_chat_repository.dart index 56882cb..0f639ac 100644 --- a/packages/firebase_chat_repository/lib/src/firebase_chat_repository.dart +++ b/packages/firebase_chat_repository/lib/src/firebase_chat_repository.dart @@ -190,6 +190,8 @@ class FirebaseChatRepository implements ChatRepositoryInterface { Future uploadImage({ required String path, required Uint8List image, + required String chatId, + required String senderId, }) async { var ref = _storage.ref().child(_mediaPath).child(path); var uploadTask = ref.putData(image); diff --git a/packages/flutter_chat/lib/src/routes.dart b/packages/flutter_chat/lib/src/routes.dart index 0a72aaf..952fc81 100644 --- a/packages/flutter_chat/lib/src/routes.dart +++ b/packages/flutter_chat/lib/src/routes.dart @@ -54,6 +54,7 @@ MaterialPageRoute chatDetailRoute({ var path = await chatService.uploadImage( path: "chats/$chatId-$userId-${DateTime.now()}", image: data, + chatId: chatId, ); await chatService.sendMessage( messageId: "$chatId-$userId-${DateTime.now()}", @@ -213,6 +214,7 @@ MaterialPageRoute _newGroupChatOverviewRoute({ path = await chatService.uploadImage( path: "groups/$title", image: image, + chatId: "", ); } var chat = await _createGroupChat(