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

Fix user access denied page

This commit is contained in:
Pierre HUBERT 2020-04-16 13:26:04 +02:00
parent cecf18f5a0
commit 3bbb09e813
4 changed files with 41 additions and 32 deletions

View File

@ -1,6 +1,5 @@
import 'package:comunic/helpers/account_helper.dart';
import 'package:comunic/ui/routes/app_settings_route.dart';
import 'package:comunic/ui/routes/user_page_route.dart';
import 'package:comunic/ui/screens/conversations_list_screen.dart';
import 'package:comunic/ui/screens/friends_list_screen.dart';
import 'package:comunic/ui/screens/group_screen.dart';
@ -8,6 +7,8 @@ import 'package:comunic/ui/screens/groups_list_screen.dart';
import 'package:comunic/ui/screens/newest_posts.dart';
import 'package:comunic/ui/screens/notifications_screen.dart';
import 'package:comunic/ui/screens/other_friends_lists_screen.dart';
import 'package:comunic/ui/screens/user_access_denied_screen.dart';
import 'package:comunic/ui/screens/user_page_screen.dart';
import 'package:comunic/ui/widgets/navbar_widget.dart';
import 'package:comunic/utils/account_utils.dart';
import 'package:comunic/utils/intl_utils.dart';
@ -49,11 +50,16 @@ abstract class HomeController extends State<HomeRoute> {
/// Open user page
void openUserPage(int userID);
void openUserAccessDeniedPage(int userID);
/// Open a specific group page specified by its [groupID]
void openGroup(int groupID);
/// Display the list of friends of a user
void openUserFriendsList(int userID);
/// Pop current page. Last page can not be popped
void popPage();
}
/// Private implementation of HomeController
@ -69,8 +75,8 @@ class _HomeRouteState extends HomeController {
}
/// Pop the page
void _popPage() {
history.removeLast();
void popPage() {
if (history.length > 1) history.removeLast();
setState(() {});
}
@ -78,7 +84,7 @@ class _HomeRouteState extends HomeController {
Future<bool> _willPop() async {
if (history.length == 1) return true;
_popPage();
popPage();
return false;
}
@ -136,7 +142,10 @@ class _HomeRouteState extends HomeController {
return FriendsListScreen();
case BarCallbackActions.OPEN_USER_PAGE:
return UserPageRoute(userID: _currTab.args["userID"]);
return UserPageScreen(userID: _currTab.args["userID"]);
case BarCallbackActions.OPEN_USER_ACCESS_DENIED_PAGE:
return UserAccessDeniedScreen(userID: _currTab.args["userID"]);
case BarCallbackActions.OPEN_GROUPS:
return GroupsListScreen();
@ -212,6 +221,12 @@ class _HomeRouteState extends HomeController {
CurrPage(BarCallbackActions.OPEN_USER_PAGE, args: {"userID": userID}));
}
@override
void openUserAccessDeniedPage(int userID) {
_pushPage(CurrPage(BarCallbackActions.OPEN_USER_ACCESS_DENIED_PAGE,
args: {"userID": userID}));
}
@override
void openUserFriendsList(int userID) {
_pushPage(CurrPage(BarCallbackActions.OPEN_USER_FRIENDS_LIST,

View File

@ -2,29 +2,29 @@ import 'package:comunic/helpers/friends_helper.dart';
import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/models/friend_status.dart';
import 'package:comunic/models/user.dart';
import 'package:comunic/ui/routes/user_page_route.dart';
import 'package:comunic/ui/routes/home_route.dart';
import 'package:comunic/ui/widgets/FrienshipStatusWidget.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart';
/// User access denied route
/// User access denied screen
///
/// @author Pierre HUBERT
class UserAccessDeniedRoute extends StatefulWidget {
class UserAccessDeniedScreen extends StatefulWidget {
final int userID;
const UserAccessDeniedRoute({Key key, @required this.userID})
const UserAccessDeniedScreen({Key key, @required this.userID})
: assert(userID != null),
super(key: key);
@override
_UserAccessDeniedRouteState createState() => _UserAccessDeniedRouteState();
_UserAccessDeniedScreenState createState() => _UserAccessDeniedScreenState();
}
class _UserAccessDeniedRouteState extends State<UserAccessDeniedRoute> {
class _UserAccessDeniedScreenState extends State<UserAccessDeniedScreen> {
final UsersHelper usersHelper = UsersHelper();
final FriendsHelper friendsHelper = FriendsHelper();
@ -49,14 +49,11 @@ class _UserAccessDeniedRouteState extends State<UserAccessDeniedRoute> {
final user = await usersHelper.getSingleWithThrow(widget.userID);
// Check if the two users are friend now
if (status.areFriend)
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (c) => UserPageRoute(
userID: widget.userID,
),
),
);
if (status.areFriend) {
final controller = HomeController.of(context);
controller.popPage();
controller.openUserPage(widget.userID);
}
setState(() {
_status = status;

View File

@ -3,7 +3,6 @@ import 'package:comunic/helpers/posts_helper.dart';
import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/models/advanced_user_info.dart';
import 'package:comunic/ui/routes/home_route.dart';
import 'package:comunic/ui/routes/user_access_denied_route.dart';
import 'package:comunic/ui/widgets/network_image_widget.dart';
import 'package:comunic/ui/widgets/post_create_form_widget.dart';
import 'package:comunic/ui/widgets/posts_list_widget.dart';
@ -21,18 +20,18 @@ enum _PageStatus { LOADING, ERROR, READY }
enum _MenuOptions { FRIENDS_LIST }
class UserPageRoute extends StatefulWidget {
class UserPageScreen extends StatefulWidget {
final int userID;
const UserPageRoute({Key key, @required this.userID})
const UserPageScreen({Key key, @required this.userID})
: assert(userID != null),
super(key: key);
@override
_UserPageRouteState createState() => _UserPageRouteState();
_UserPageScreenState createState() => _UserPageScreenState();
}
class _UserPageRouteState extends State<UserPageRoute> {
class _UserPageScreenState extends State<UserPageScreen> {
// Helpers
final usersHelper = UsersHelper();
final PostsHelper _postsHelper = PostsHelper();
@ -77,14 +76,11 @@ class _UserPageRouteState extends State<UserPageRoute> {
} on GetUserAdvancedUserError catch (e) {
_setStatus(_PageStatus.ERROR);
if (e.cause == GetUserAdvancedInformationErrorCause.NOT_AUTHORIZED)
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (c) => UserAccessDeniedRoute(
userID: widget.userID,
),
),
);
if (e.cause == GetUserAdvancedInformationErrorCause.NOT_AUTHORIZED) {
final controller = HomeController.of(context);
controller.popPage();
controller.openUserAccessDeniedPage(widget.userID);
}
}
}

View File

@ -18,6 +18,7 @@ enum BarCallbackActions {
OPEN_GROUPS,
OPEN_GROUP_PAGE,
OPEN_USER_PAGE,
OPEN_USER_ACCESS_DENIED_PAGE,
OPEN_APP_SETTINGS,
OPEN_USER_FRIENDS_LIST,
OPEN_ABOUT_DIALOG,