From c5de42fcba4a17620599003feb5e80825197adc5 Mon Sep 17 00:00:00 2001 From: Julian KOUNE Date: Wed, 20 Sep 2023 14:56:09 +0200 Subject: [PATCH] feat: enhance chat app bar from draft --- lib/config/go_routes/go_router.dart | 9 +++++++++ .../room/create_new_group_chat_state.dart | 8 ++++++-- .../room/create_new_group_chat_interactor.dart | 7 ++++++- lib/pages/chat/chat.dart | 4 ++++ lib/pages/chat/chat_app_bar_title.dart | 17 ++++++++++------- lib/pages/chat/chat_view.dart | 1 + lib/pages/chat_draft/draft_chat.dart | 2 ++ lib/pages/new_group/new_group.dart | 13 ++++++++++--- pubspec.lock | 2 +- 9 files changed, 49 insertions(+), 14 deletions(-) diff --git a/lib/config/go_routes/go_router.dart b/lib/config/go_routes/go_router.dart index 590de2b579..27767ed13a 100644 --- a/lib/config/go_routes/go_router.dart +++ b/lib/config/go_routes/go_router.dart @@ -343,6 +343,15 @@ abstract class AppRoutes { final extra = state.extra as ChatRouterInputArgument; switch (extra.type) { case ChatRouterInputArgumentType.draft: + if (extra.data is String?) { + return NoTransitionPage( + child: Chat( + roomId: state.pathParameters['roomid']!, + key: Key(state.pathParameters['roomid']!), + roomName: extra.data as String?, + ), + ); + } return NoTransitionPage( child: Chat( roomId: state.pathParameters['roomid']!, diff --git a/lib/domain/app_state/room/create_new_group_chat_state.dart b/lib/domain/app_state/room/create_new_group_chat_state.dart index 8801dd97a8..999b9e625e 100644 --- a/lib/domain/app_state/room/create_new_group_chat_state.dart +++ b/lib/domain/app_state/room/create_new_group_chat_state.dart @@ -13,11 +13,15 @@ class CreateNewGroupChatLoading extends Success { class CreateNewGroupChatSuccess extends Success { final String roomId; + final String? groupName; - const CreateNewGroupChatSuccess({required this.roomId}); + const CreateNewGroupChatSuccess({ + required this.roomId, + this.groupName, + }); @override - List get props => [roomId]; + List get props => [roomId, groupName]; } class CreateNewGroupChatFailed extends Failure { diff --git a/lib/domain/usecase/room/create_new_group_chat_interactor.dart b/lib/domain/usecase/room/create_new_group_chat_interactor.dart index 95ec46489c..f0829ef329 100644 --- a/lib/domain/usecase/room/create_new_group_chat_interactor.dart +++ b/lib/domain/usecase/room/create_new_group_chat_interactor.dart @@ -31,7 +31,12 @@ class CreateNewGroupChatInteractor { ); if (roomId.isNotEmpty) { - yield Right(CreateNewGroupChatSuccess(roomId: roomId)); + yield Right( + CreateNewGroupChatSuccess( + roomId: roomId, + groupName: createNewGroupChatRequest.groupName, + ), + ); } else { yield Left( CreateNewGroupChatFailed( diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index d28e3cd1fc..29da44ff02 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -73,12 +73,14 @@ class Chat extends StatefulWidget { final String roomId; final Widget? sideView; final MatrixFile? shareFile; + final String? roomName; const Chat({ Key? key, this.sideView, required this.roomId, this.shareFile, + this.roomName, }) : super(key: key); @override @@ -109,6 +111,8 @@ class ChatController extends State MatrixFile? get shareFile => widget.shareFile; + String? get roomName => widget.roomName; + String? get roomId => widget.roomId; bool get isEmptyChat => diff --git a/lib/pages/chat/chat_app_bar_title.dart b/lib/pages/chat/chat_app_bar_title.dart index e29cc8bdf9..ee6fe20494 100644 --- a/lib/pages/chat/chat_app_bar_title.dart +++ b/lib/pages/chat/chat_app_bar_title.dart @@ -19,11 +19,13 @@ class ChatAppBarTitle extends StatelessWidget { final TextEditingController sendController; final Stream getStreamInstance; final VoidCallback onPushDetails; + final String? roomName; const ChatAppBarTitle({ Key? key, required this.actions, this.room, + this.roomName, required this.selectedEvents, required this.isArchived, required this.sendController, @@ -73,9 +75,10 @@ class ChatAppBarTitle extends StatelessWidget { child: Avatar( fontSize: ChatAppBarTitleStyle.avatarFontSize, mxContent: room!.avatar, - name: room!.getLocalizedDisplayname( - MatrixLocals(L10n.of(context)!), - ), + name: roomName ?? + room!.getLocalizedDisplayname( + MatrixLocals(L10n.of(context)!), + ), size: ChatAppBarTitleStyle.avatarSize(context), ), ), @@ -87,9 +90,10 @@ class ChatAppBarTitle extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - room!.getLocalizedDisplayname( - MatrixLocals(L10n.of(context)!), - ), + roomName ?? + room!.getLocalizedDisplayname( + MatrixLocals(L10n.of(context)!), + ), maxLines: 1, overflow: TextOverflow.ellipsis, style: ChatAppBarTitleStyle.appBarTitleStyle(context), @@ -109,7 +113,6 @@ class ChatAppBarTitle extends StatelessWidget { ) { final TextStyle? statusTextStyle = ChatAppBarTitleStyle.statusTextStyle(context); - return StreamBuilder( stream: getStreamInstance, builder: (context, snapshot) { diff --git a/lib/pages/chat/chat_view.dart b/lib/pages/chat/chat_view.dart index 1756a1cae4..4ba5fb8e53 100644 --- a/lib/pages/chat/chat_view.dart +++ b/lib/pages/chat/chat_view.dart @@ -176,6 +176,7 @@ class ChatView extends StatelessWidget { .getStreamInstance(), actions: _appBarActions(context), onPushDetails: controller.onPushDetails, + roomName: controller.roomName, ); }, ), diff --git a/lib/pages/chat_draft/draft_chat.dart b/lib/pages/chat_draft/draft_chat.dart index cb5563aacc..d47158b735 100644 --- a/lib/pages/chat_draft/draft_chat.dart +++ b/lib/pages/chat_draft/draft_chat.dart @@ -166,6 +166,8 @@ class DraftChatController extends State '/rooms/${room.id}/', extra: ChatRouterInputArgument( type: ChatRouterInputArgumentType.draft, + data: presentationContact?.displayName ?? + presentationContact?.matrixId, ), ); } diff --git a/lib/pages/new_group/new_group.dart b/lib/pages/new_group/new_group.dart index 39e967805e..4ccb8d3a06 100644 --- a/lib/pages/new_group/new_group.dart +++ b/lib/pages/new_group/new_group.dart @@ -18,6 +18,7 @@ import 'package:fluffychat/pages/new_group/new_group_chat_info.dart'; import 'package:fluffychat/pages/new_group/new_group_info_controller.dart'; import 'package:fluffychat/presentation/mixins/common_media_picker_mixin.dart'; import 'package:fluffychat/presentation/mixins/single_image_picker_mixin.dart'; +import 'package:fluffychat/presentation/model/chat/chat_router_input_argument.dart'; import 'package:fluffychat/presentation/model/presentation_contact.dart'; import 'package:fluffychat/utils/dialog/warning_dialog.dart'; import 'package:fluffychat/utils/platform_infos.dart'; @@ -273,7 +274,7 @@ class NewGroupController extends ContactsSelectionController 'NewGroupController::_handleCreateNewGroupChatChatOnData() - success: $success', ); if (success is CreateNewGroupChatSuccess) { - _goToRoom(context, success.roomId); + _goToRoom(success); } }, ); @@ -289,8 +290,14 @@ class NewGroupController extends ContactsSelectionController ); } - void _goToRoom(BuildContext context, String roomId) { - context.go("/rooms/$roomId"); + void _goToRoom(CreateNewGroupChatSuccess success) { + context.go( + "/rooms/${success.roomId}", + extra: ChatRouterInputArgument( + type: ChatRouterInputArgumentType.draft, + data: success.groupName, + ), + ); } void _getImageOnWeb( diff --git a/pubspec.lock b/pubspec.lock index 78d739061a..f3dbf07a5f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1534,7 +1534,7 @@ packages: description: path: "." ref: twake-supported - resolved-ref: f81a5a805f801902046c4c9442b0d960e4976e54 + resolved-ref: a3d6992e4cf420f96fd855efc710af69e3562859 url: "git@github.com:linagora/matrix-dart-sdk.git" source: git version: "0.22.2"