mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Fix user access denied page
This commit is contained in:
parent
cecf18f5a0
commit
3bbb09e813
@ -1,6 +1,5 @@
|
|||||||
import 'package:comunic/helpers/account_helper.dart';
|
import 'package:comunic/helpers/account_helper.dart';
|
||||||
import 'package:comunic/ui/routes/app_settings_route.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/conversations_list_screen.dart';
|
||||||
import 'package:comunic/ui/screens/friends_list_screen.dart';
|
import 'package:comunic/ui/screens/friends_list_screen.dart';
|
||||||
import 'package:comunic/ui/screens/group_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/newest_posts.dart';
|
||||||
import 'package:comunic/ui/screens/notifications_screen.dart';
|
import 'package:comunic/ui/screens/notifications_screen.dart';
|
||||||
import 'package:comunic/ui/screens/other_friends_lists_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/ui/widgets/navbar_widget.dart';
|
||||||
import 'package:comunic/utils/account_utils.dart';
|
import 'package:comunic/utils/account_utils.dart';
|
||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
@ -49,11 +50,16 @@ abstract class HomeController extends State<HomeRoute> {
|
|||||||
/// Open user page
|
/// Open user page
|
||||||
void openUserPage(int userID);
|
void openUserPage(int userID);
|
||||||
|
|
||||||
|
void openUserAccessDeniedPage(int userID);
|
||||||
|
|
||||||
/// Open a specific group page specified by its [groupID]
|
/// Open a specific group page specified by its [groupID]
|
||||||
void openGroup(int groupID);
|
void openGroup(int groupID);
|
||||||
|
|
||||||
/// Display the list of friends of a user
|
/// Display the list of friends of a user
|
||||||
void openUserFriendsList(int userID);
|
void openUserFriendsList(int userID);
|
||||||
|
|
||||||
|
/// Pop current page. Last page can not be popped
|
||||||
|
void popPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Private implementation of HomeController
|
/// Private implementation of HomeController
|
||||||
@ -69,8 +75,8 @@ class _HomeRouteState extends HomeController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Pop the page
|
/// Pop the page
|
||||||
void _popPage() {
|
void popPage() {
|
||||||
history.removeLast();
|
if (history.length > 1) history.removeLast();
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +84,7 @@ class _HomeRouteState extends HomeController {
|
|||||||
Future<bool> _willPop() async {
|
Future<bool> _willPop() async {
|
||||||
if (history.length == 1) return true;
|
if (history.length == 1) return true;
|
||||||
|
|
||||||
_popPage();
|
popPage();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +142,10 @@ class _HomeRouteState extends HomeController {
|
|||||||
return FriendsListScreen();
|
return FriendsListScreen();
|
||||||
|
|
||||||
case BarCallbackActions.OPEN_USER_PAGE:
|
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:
|
case BarCallbackActions.OPEN_GROUPS:
|
||||||
return GroupsListScreen();
|
return GroupsListScreen();
|
||||||
@ -212,6 +221,12 @@ class _HomeRouteState extends HomeController {
|
|||||||
CurrPage(BarCallbackActions.OPEN_USER_PAGE, args: {"userID": userID}));
|
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
|
@override
|
||||||
void openUserFriendsList(int userID) {
|
void openUserFriendsList(int userID) {
|
||||||
_pushPage(CurrPage(BarCallbackActions.OPEN_USER_FRIENDS_LIST,
|
_pushPage(CurrPage(BarCallbackActions.OPEN_USER_FRIENDS_LIST,
|
||||||
|
@ -2,29 +2,29 @@ import 'package:comunic/helpers/friends_helper.dart';
|
|||||||
import 'package:comunic/helpers/users_helper.dart';
|
import 'package:comunic/helpers/users_helper.dart';
|
||||||
import 'package:comunic/models/friend_status.dart';
|
import 'package:comunic/models/friend_status.dart';
|
||||||
import 'package:comunic/models/user.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/FrienshipStatusWidget.dart';
|
||||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
import 'package:comunic/utils/ui_utils.dart';
|
import 'package:comunic/utils/ui_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// User access denied route
|
/// User access denied screen
|
||||||
///
|
///
|
||||||
/// @author Pierre HUBERT
|
/// @author Pierre HUBERT
|
||||||
|
|
||||||
class UserAccessDeniedRoute extends StatefulWidget {
|
class UserAccessDeniedScreen extends StatefulWidget {
|
||||||
final int userID;
|
final int userID;
|
||||||
|
|
||||||
const UserAccessDeniedRoute({Key key, @required this.userID})
|
const UserAccessDeniedScreen({Key key, @required this.userID})
|
||||||
: assert(userID != null),
|
: assert(userID != null),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_UserAccessDeniedRouteState createState() => _UserAccessDeniedRouteState();
|
_UserAccessDeniedScreenState createState() => _UserAccessDeniedScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _UserAccessDeniedRouteState extends State<UserAccessDeniedRoute> {
|
class _UserAccessDeniedScreenState extends State<UserAccessDeniedScreen> {
|
||||||
final UsersHelper usersHelper = UsersHelper();
|
final UsersHelper usersHelper = UsersHelper();
|
||||||
final FriendsHelper friendsHelper = FriendsHelper();
|
final FriendsHelper friendsHelper = FriendsHelper();
|
||||||
|
|
||||||
@ -49,14 +49,11 @@ class _UserAccessDeniedRouteState extends State<UserAccessDeniedRoute> {
|
|||||||
final user = await usersHelper.getSingleWithThrow(widget.userID);
|
final user = await usersHelper.getSingleWithThrow(widget.userID);
|
||||||
|
|
||||||
// Check if the two users are friend now
|
// Check if the two users are friend now
|
||||||
if (status.areFriend)
|
if (status.areFriend) {
|
||||||
Navigator.of(context).pushReplacement(
|
final controller = HomeController.of(context);
|
||||||
MaterialPageRoute(
|
controller.popPage();
|
||||||
builder: (c) => UserPageRoute(
|
controller.openUserPage(widget.userID);
|
||||||
userID: widget.userID,
|
}
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_status = status;
|
_status = status;
|
@ -3,7 +3,6 @@ import 'package:comunic/helpers/posts_helper.dart';
|
|||||||
import 'package:comunic/helpers/users_helper.dart';
|
import 'package:comunic/helpers/users_helper.dart';
|
||||||
import 'package:comunic/models/advanced_user_info.dart';
|
import 'package:comunic/models/advanced_user_info.dart';
|
||||||
import 'package:comunic/ui/routes/home_route.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/network_image_widget.dart';
|
||||||
import 'package:comunic/ui/widgets/post_create_form_widget.dart';
|
import 'package:comunic/ui/widgets/post_create_form_widget.dart';
|
||||||
import 'package:comunic/ui/widgets/posts_list_widget.dart';
|
import 'package:comunic/ui/widgets/posts_list_widget.dart';
|
||||||
@ -21,18 +20,18 @@ enum _PageStatus { LOADING, ERROR, READY }
|
|||||||
|
|
||||||
enum _MenuOptions { FRIENDS_LIST }
|
enum _MenuOptions { FRIENDS_LIST }
|
||||||
|
|
||||||
class UserPageRoute extends StatefulWidget {
|
class UserPageScreen extends StatefulWidget {
|
||||||
final int userID;
|
final int userID;
|
||||||
|
|
||||||
const UserPageRoute({Key key, @required this.userID})
|
const UserPageScreen({Key key, @required this.userID})
|
||||||
: assert(userID != null),
|
: assert(userID != null),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_UserPageRouteState createState() => _UserPageRouteState();
|
_UserPageScreenState createState() => _UserPageScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _UserPageRouteState extends State<UserPageRoute> {
|
class _UserPageScreenState extends State<UserPageScreen> {
|
||||||
// Helpers
|
// Helpers
|
||||||
final usersHelper = UsersHelper();
|
final usersHelper = UsersHelper();
|
||||||
final PostsHelper _postsHelper = PostsHelper();
|
final PostsHelper _postsHelper = PostsHelper();
|
||||||
@ -77,14 +76,11 @@ class _UserPageRouteState extends State<UserPageRoute> {
|
|||||||
} on GetUserAdvancedUserError catch (e) {
|
} on GetUserAdvancedUserError catch (e) {
|
||||||
_setStatus(_PageStatus.ERROR);
|
_setStatus(_PageStatus.ERROR);
|
||||||
|
|
||||||
if (e.cause == GetUserAdvancedInformationErrorCause.NOT_AUTHORIZED)
|
if (e.cause == GetUserAdvancedInformationErrorCause.NOT_AUTHORIZED) {
|
||||||
Navigator.of(context).pushReplacement(
|
final controller = HomeController.of(context);
|
||||||
MaterialPageRoute(
|
controller.popPage();
|
||||||
builder: (c) => UserAccessDeniedRoute(
|
controller.openUserAccessDeniedPage(widget.userID);
|
||||||
userID: widget.userID,
|
}
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -18,6 +18,7 @@ enum BarCallbackActions {
|
|||||||
OPEN_GROUPS,
|
OPEN_GROUPS,
|
||||||
OPEN_GROUP_PAGE,
|
OPEN_GROUP_PAGE,
|
||||||
OPEN_USER_PAGE,
|
OPEN_USER_PAGE,
|
||||||
|
OPEN_USER_ACCESS_DENIED_PAGE,
|
||||||
OPEN_APP_SETTINGS,
|
OPEN_APP_SETTINGS,
|
||||||
OPEN_USER_FRIENDS_LIST,
|
OPEN_USER_FRIENDS_LIST,
|
||||||
OPEN_ABOUT_DIALOG,
|
OPEN_ABOUT_DIALOG,
|
||||||
|
Loading…
Reference in New Issue
Block a user