From 1d0609f66e79db91becc29e4b033bdcfcfb42924 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 6 Apr 2021 18:22:45 +0200 Subject: [PATCH] Open conversations in their context --- lib/ui/routes/main_route/main_route.dart | 21 ++++++++++++++++--- lib/ui/routes/main_route/tablet_route.dart | 4 ++-- .../screens/authorized_group_page_screen.dart | 10 +++++++-- lib/ui/screens/conversations_list_screen.dart | 6 +++--- lib/ui/screens/group_screen.dart | 9 ++++++-- .../screens/unread_conversations_screen.dart | 2 +- .../screens/update_conversation_screen.dart | 2 +- .../conversations/conversation_window.dart | 2 +- .../tablet_mode/memberships_panel.dart | 2 +- lib/utils/conversations_utils.dart | 2 +- 10 files changed, 43 insertions(+), 17 deletions(-) diff --git a/lib/ui/routes/main_route/main_route.dart b/lib/ui/routes/main_route/main_route.dart index cfa19b9..cc08e87 100644 --- a/lib/ui/routes/main_route/main_route.dart +++ b/lib/ui/routes/main_route/main_route.dart @@ -111,9 +111,15 @@ abstract class MainController extends State { void openCurrentUserPage() => this.openUserPage(userID()); /// Open a specific group page specified by its [groupID] - void openGroup(int groupID) => pushPage(PageInfo( + /// + /// [conversationID] is an optional parameter specifying a conversation + /// that should be opened instead of posts thread + void openGroup(int groupID, {int conversationID}) => pushPage(PageInfo( type: PageType.GROUP_PAGE, - child: GroupPageScreen(groupID: groupID), + child: GroupPageScreen( + groupID: groupID, + conversationID: conversationID, + ), id: groupID)); /// Display the list of friends of current user @@ -146,8 +152,17 @@ abstract class MainController extends State { pushPage(PageInfo( child: w, hideNavBar: hideNavBar, canShowAsDialog: canShowAsDialog)); + /// Open a conversation in its context (in group page for group conversations) + void openConversation(Conversation conv) { + if (conv.isGroupConversation) + openGroup(conv.groupID, conversationID: conv.id); + else + openConversationById(conv.id); + } + /// Open a conversation - void openConversation(int convID, {fullScreen: false}) => pushPage(PageInfo( + void openConversationById(int convID, {fullScreen: false}) => + pushPage(PageInfo( type: PageType.CONVERSATION_PAGE, id: convID, child: ConversationRoute(conversationID: convID), diff --git a/lib/ui/routes/main_route/tablet_route.dart b/lib/ui/routes/main_route/tablet_route.dart index 720355f..45c94ac 100644 --- a/lib/ui/routes/main_route/tablet_route.dart +++ b/lib/ui/routes/main_route/tablet_route.dart @@ -90,12 +90,12 @@ class _TabletRouteState extends MainController { } @override - void openConversation(int convID, {fullScreen = false}) { + void openConversationById(int convID, {fullScreen = false}) { if (!fullScreen) { popUntilMainRoute(); _conversationsKey.currentState.openConversations(convID); } else - super.openConversation(convID, fullScreen: fullScreen); + super.openConversationById(convID, fullScreen: fullScreen); } @override diff --git a/lib/ui/screens/authorized_group_page_screen.dart b/lib/ui/screens/authorized_group_page_screen.dart index 76dcdda..249b3d5 100644 --- a/lib/ui/screens/authorized_group_page_screen.dart +++ b/lib/ui/screens/authorized_group_page_screen.dart @@ -26,11 +26,13 @@ Color get _headerColor => Colors.blueAccent.shade700; class AuthorizedGroupPageScreen extends StatefulWidget { final AdvancedGroupInfo advancedGroupInfo; + final int conversationID; final Function() needRefresh; const AuthorizedGroupPageScreen({ Key key, @required this.advancedGroupInfo, + @required this.conversationID, @required this.needRefresh, }) : assert(advancedGroupInfo != null), assert(needRefresh != null), @@ -83,7 +85,11 @@ class _AuthorizedGroupPageScreenState void initState() { _tabController = TabController( length: _tabs.length, - initialIndex: 0, + initialIndex: widget.conversationID == null + ? 0 + : 1 + + _group.conversations + .indexWhere((element) => element.id == widget.conversationID), vsync: this, ); @@ -105,7 +111,7 @@ class _AuthorizedGroupPageScreenState Material( color: _headerColor, child: TabBar( - isScrollable: true, + isScrollable: _tabController.length > 4, tabs: _tabs.map((e) => e.tab).toList(), controller: _tabController, ), diff --git a/lib/ui/screens/conversations_list_screen.dart b/lib/ui/screens/conversations_list_screen.dart index f001653..c318c43 100644 --- a/lib/ui/screens/conversations_list_screen.dart +++ b/lib/ui/screens/conversations_list_screen.dart @@ -108,8 +108,8 @@ class _ConversationScreenState extends SafeState { } /// Open a conversation - void _openConversation(int conversationId) { - MainController.of(context).openConversation(conversationId); + void _openConversation(Conversation conv) { + MainController.of(context).openConversation(conv); if (widget.onOpen != null) widget.onOpen(); } @@ -191,7 +191,7 @@ class _ConversationScreenState extends SafeState { usersList: _users, groupsList: _groups, onOpen: (c) { - _openConversation(c.id); + _openConversation(c); }, onRequestUpdate: _updateConversation, onRequestLeave: _requestLeaveConversation, diff --git a/lib/ui/screens/group_screen.dart b/lib/ui/screens/group_screen.dart index e19ae19..0f5ccd3 100644 --- a/lib/ui/screens/group_screen.dart +++ b/lib/ui/screens/group_screen.dart @@ -12,9 +12,13 @@ import 'package:flutter/material.dart'; class GroupPageScreen extends StatefulWidget { final int groupID; + final int conversationID; - const GroupPageScreen({Key key, @required this.groupID}) - : assert(groupID != null), + const GroupPageScreen({ + Key key, + @required this.groupID, + this.conversationID, + }) : assert(groupID != null), super(key: key); @override @@ -57,6 +61,7 @@ class _GroupPageScreenState extends SafeState { // Now we can show group page return AuthorizedGroupPageScreen( advancedGroupInfo: _getGroupResult.info, + conversationID: widget.conversationID, needRefresh: () => _refreshPage(), ); } diff --git a/lib/ui/screens/unread_conversations_screen.dart b/lib/ui/screens/unread_conversations_screen.dart index 2202c15..2606e93 100644 --- a/lib/ui/screens/unread_conversations_screen.dart +++ b/lib/ui/screens/unread_conversations_screen.dart @@ -104,7 +104,7 @@ class _UnreadConversationsScreenState ]), ), trailing: Text(diffTimeFromNowToStr(conv.message.timeSent)), - onTap: () => MainController.of(context).openConversation(conv.conv.id), + onTap: () => MainController.of(context).openConversationById(conv.conv.id), ); } } diff --git a/lib/ui/screens/update_conversation_screen.dart b/lib/ui/screens/update_conversation_screen.dart index e31bbf9..c45e681 100644 --- a/lib/ui/screens/update_conversation_screen.dart +++ b/lib/ui/screens/update_conversation_screen.dart @@ -301,7 +301,7 @@ class _UpdateConversationScreen extends State { color: _color)); MainController.of(context).popPage(); - MainController.of(context).openConversation(conversationID); + MainController.of(context).openConversationById(conversationID); return; } diff --git a/lib/ui/widgets/tablet_mode/conversations/conversation_window.dart b/lib/ui/widgets/tablet_mode/conversations/conversation_window.dart index 458741c..13adf8d 100644 --- a/lib/ui/widgets/tablet_mode/conversations/conversation_window.dart +++ b/lib/ui/widgets/tablet_mode/conversations/conversation_window.dart @@ -175,7 +175,7 @@ class _ConversationWindowState extends SafeState { } void _openFullScreen() { - MainController.of(context).openConversation(_convID, fullScreen: true); + MainController.of(context).openConversationById(_convID, fullScreen: true); widget.onClose(); } diff --git a/lib/ui/widgets/tablet_mode/memberships_panel.dart b/lib/ui/widgets/tablet_mode/memberships_panel.dart index fea2c7a..bd22818 100644 --- a/lib/ui/widgets/tablet_mode/memberships_panel.dart +++ b/lib/ui/widgets/tablet_mode/memberships_panel.dart @@ -223,7 +223,7 @@ class _MembershipsPanelState extends SafeState { subtitle: Text(diffTimeFromNowToStr(membership.lastActive) + (conversation.isHavingCall ? "\n" + tr("Ongoing call") : "")), onTap: () => MainController.of(context) - .openConversation(conversation.id, fullScreen: true), + .openConversationById(conversation.id, fullScreen: true), trailing: conversation.isHavingCall ? FloatingActionButton( heroTag: null, diff --git a/lib/utils/conversations_utils.dart b/lib/utils/conversations_utils.dart index 80a192b..d23db9a 100644 --- a/lib/utils/conversations_utils.dart +++ b/lib/utils/conversations_utils.dart @@ -14,7 +14,7 @@ Future openPrivateConversation(BuildContext context, int userID) async { final convID = await ConversationsHelper().getPrivate(userID); // Open the conversation - MainController.of(context).openConversation(convID); + MainController.of(context).openConversationById(convID); return true; } catch (e, s) {