1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00

Open conversations in their context

This commit is contained in:
Pierre HUBERT 2021-04-06 18:22:45 +02:00
parent 66d8fbd234
commit 1d0609f66e
10 changed files with 43 additions and 17 deletions

View File

@ -111,9 +111,15 @@ abstract class MainController extends State<MainRoute> {
void openCurrentUserPage() => this.openUserPage(userID()); void openCurrentUserPage() => this.openUserPage(userID());
/// Open a specific group page specified by its [groupID] /// 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, type: PageType.GROUP_PAGE,
child: GroupPageScreen(groupID: groupID), child: GroupPageScreen(
groupID: groupID,
conversationID: conversationID,
),
id: groupID)); id: groupID));
/// Display the list of friends of current user /// Display the list of friends of current user
@ -146,8 +152,17 @@ abstract class MainController extends State<MainRoute> {
pushPage(PageInfo( pushPage(PageInfo(
child: w, hideNavBar: hideNavBar, canShowAsDialog: canShowAsDialog)); 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 /// Open a conversation
void openConversation(int convID, {fullScreen: false}) => pushPage(PageInfo( void openConversationById(int convID, {fullScreen: false}) =>
pushPage(PageInfo(
type: PageType.CONVERSATION_PAGE, type: PageType.CONVERSATION_PAGE,
id: convID, id: convID,
child: ConversationRoute(conversationID: convID), child: ConversationRoute(conversationID: convID),

View File

@ -90,12 +90,12 @@ class _TabletRouteState extends MainController {
} }
@override @override
void openConversation(int convID, {fullScreen = false}) { void openConversationById(int convID, {fullScreen = false}) {
if (!fullScreen) { if (!fullScreen) {
popUntilMainRoute(); popUntilMainRoute();
_conversationsKey.currentState.openConversations(convID); _conversationsKey.currentState.openConversations(convID);
} else } else
super.openConversation(convID, fullScreen: fullScreen); super.openConversationById(convID, fullScreen: fullScreen);
} }
@override @override

View File

@ -26,11 +26,13 @@ Color get _headerColor => Colors.blueAccent.shade700;
class AuthorizedGroupPageScreen extends StatefulWidget { class AuthorizedGroupPageScreen extends StatefulWidget {
final AdvancedGroupInfo advancedGroupInfo; final AdvancedGroupInfo advancedGroupInfo;
final int conversationID;
final Function() needRefresh; final Function() needRefresh;
const AuthorizedGroupPageScreen({ const AuthorizedGroupPageScreen({
Key key, Key key,
@required this.advancedGroupInfo, @required this.advancedGroupInfo,
@required this.conversationID,
@required this.needRefresh, @required this.needRefresh,
}) : assert(advancedGroupInfo != null), }) : assert(advancedGroupInfo != null),
assert(needRefresh != null), assert(needRefresh != null),
@ -83,7 +85,11 @@ class _AuthorizedGroupPageScreenState
void initState() { void initState() {
_tabController = TabController( _tabController = TabController(
length: _tabs.length, length: _tabs.length,
initialIndex: 0, initialIndex: widget.conversationID == null
? 0
: 1 +
_group.conversations
.indexWhere((element) => element.id == widget.conversationID),
vsync: this, vsync: this,
); );
@ -105,7 +111,7 @@ class _AuthorizedGroupPageScreenState
Material( Material(
color: _headerColor, color: _headerColor,
child: TabBar( child: TabBar(
isScrollable: true, isScrollable: _tabController.length > 4,
tabs: _tabs.map((e) => e.tab).toList(), tabs: _tabs.map((e) => e.tab).toList(),
controller: _tabController, controller: _tabController,
), ),

View File

@ -108,8 +108,8 @@ class _ConversationScreenState extends SafeState<ConversationsListScreen> {
} }
/// Open a conversation /// Open a conversation
void _openConversation(int conversationId) { void _openConversation(Conversation conv) {
MainController.of(context).openConversation(conversationId); MainController.of(context).openConversation(conv);
if (widget.onOpen != null) widget.onOpen(); if (widget.onOpen != null) widget.onOpen();
} }
@ -191,7 +191,7 @@ class _ConversationScreenState extends SafeState<ConversationsListScreen> {
usersList: _users, usersList: _users,
groupsList: _groups, groupsList: _groups,
onOpen: (c) { onOpen: (c) {
_openConversation(c.id); _openConversation(c);
}, },
onRequestUpdate: _updateConversation, onRequestUpdate: _updateConversation,
onRequestLeave: _requestLeaveConversation, onRequestLeave: _requestLeaveConversation,

View File

@ -12,9 +12,13 @@ import 'package:flutter/material.dart';
class GroupPageScreen extends StatefulWidget { class GroupPageScreen extends StatefulWidget {
final int groupID; final int groupID;
final int conversationID;
const GroupPageScreen({Key key, @required this.groupID}) const GroupPageScreen({
: assert(groupID != null), Key key,
@required this.groupID,
this.conversationID,
}) : assert(groupID != null),
super(key: key); super(key: key);
@override @override
@ -57,6 +61,7 @@ class _GroupPageScreenState extends SafeState<GroupPageScreen> {
// Now we can show group page // Now we can show group page
return AuthorizedGroupPageScreen( return AuthorizedGroupPageScreen(
advancedGroupInfo: _getGroupResult.info, advancedGroupInfo: _getGroupResult.info,
conversationID: widget.conversationID,
needRefresh: () => _refreshPage(), needRefresh: () => _refreshPage(),
); );
} }

View File

@ -104,7 +104,7 @@ class _UnreadConversationsScreenState
]), ]),
), ),
trailing: Text(diffTimeFromNowToStr(conv.message.timeSent)), trailing: Text(diffTimeFromNowToStr(conv.message.timeSent)),
onTap: () => MainController.of(context).openConversation(conv.conv.id), onTap: () => MainController.of(context).openConversationById(conv.conv.id),
); );
} }
} }

View File

@ -301,7 +301,7 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
color: _color)); color: _color));
MainController.of(context).popPage(); MainController.of(context).popPage();
MainController.of(context).openConversation(conversationID); MainController.of(context).openConversationById(conversationID);
return; return;
} }

View File

@ -175,7 +175,7 @@ class _ConversationWindowState extends SafeState<ConversationWindow> {
} }
void _openFullScreen() { void _openFullScreen() {
MainController.of(context).openConversation(_convID, fullScreen: true); MainController.of(context).openConversationById(_convID, fullScreen: true);
widget.onClose(); widget.onClose();
} }

View File

@ -223,7 +223,7 @@ class _MembershipsPanelState extends SafeState<MembershipsPanel> {
subtitle: Text(diffTimeFromNowToStr(membership.lastActive) + subtitle: Text(diffTimeFromNowToStr(membership.lastActive) +
(conversation.isHavingCall ? "\n" + tr("Ongoing call") : "")), (conversation.isHavingCall ? "\n" + tr("Ongoing call") : "")),
onTap: () => MainController.of(context) onTap: () => MainController.of(context)
.openConversation(conversation.id, fullScreen: true), .openConversationById(conversation.id, fullScreen: true),
trailing: conversation.isHavingCall trailing: conversation.isHavingCall
? FloatingActionButton( ? FloatingActionButton(
heroTag: null, heroTag: null,

View File

@ -14,7 +14,7 @@ Future<bool> openPrivateConversation(BuildContext context, int userID) async {
final convID = await ConversationsHelper().getPrivate(userID); final convID = await ConversationsHelper().getPrivate(userID);
// Open the conversation // Open the conversation
MainController.of(context).openConversation(convID); MainController.of(context).openConversationById(convID);
return true; return true;
} catch (e, s) { } catch (e, s) {