diff --git a/lib/config/go_routes/go_router.dart b/lib/config/go_routes/go_router.dart index 490b0ede72..37f3aef41a 100644 --- a/lib/config/go_routes/go_router.dart +++ b/lib/config/go_routes/go_router.dart @@ -375,7 +375,9 @@ abstract class AppRoutes { redirect: loggedOutRedirect, pageBuilder: (context, state) => defaultPageBuilder( context, - const HomeserverPicker(), + TwakeWelcome( + arg: state.extra as TwakeWelcomeArg?, + ), ), routes: [ GoRoute( @@ -386,21 +388,12 @@ abstract class AppRoutes { ), redirect: loggedOutRedirect, ), - GoRoute( - path: 'twakeWelcome', - pageBuilder: (context, state) => defaultPageBuilder( - context, - const TwakeWelcome(), - ), - redirect: loggedInRedirect, - ), GoRoute( path: 'homeserverpicker', pageBuilder: (context, state) => defaultPageBuilder( context, const HomeserverPicker(), ), - redirect: loggedInRedirect, ), ], ), diff --git a/lib/pages/twake_welcome/twake_welcome.dart b/lib/pages/twake_welcome/twake_welcome.dart index a091123c57..071d47d7ad 100644 --- a/lib/pages/twake_welcome/twake_welcome.dart +++ b/lib/pages/twake_welcome/twake_welcome.dart @@ -2,8 +2,11 @@ import 'package:fluffychat/config/app_config.dart'; import 'package:equatable/equatable.dart'; import 'package:fluffychat/presentation/mixins/connect_page_mixin.dart'; import 'package:fluffychat/pages/twake_welcome/twake_welcome_view.dart'; +import 'package:fluffychat/utils/client_manager.dart'; +import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_web_auth_2/flutter_web_auth_2.dart'; import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; @@ -38,7 +41,7 @@ class TwakeWelcome extends StatefulWidget { class TwakeWelcomeController extends State with ConnectPageMixin { void goToHomeserverPicker() { if (widget.arg?.isAddAnotherAccount == true) { - context.push('/rooms/addhomeserver'); + context.push('/rooms/addaccount/homeserverpicker'); } else { context.push('/home/homeserverpicker'); } @@ -58,8 +61,10 @@ class TwakeWelcomeController extends State with ConnectPageMixin { MatrixState get matrix => Matrix.of(context); - void onClickSignIn() { + void onClickSignIn() async { Logs().d("TwakeIdController::onClickSignIn: Login Url - $loginUrl"); + final homeserverExisted = await _homeserverExisted(); + if (homeserverExisted) return; _redirectRegistrationUrl(loginUrl); } @@ -79,15 +84,40 @@ class TwakeWelcomeController extends State with ConnectPageMixin { handleTokenFromRegistrationSite(matrix: matrix, uri: uri); } - void onClickCreateTwakeId() { + void onClickCreateTwakeId() async { Logs().d( "TwakeIdController::onClickCreateTwakeId: Signup Url - $signupUrl", ); + final homeserverExisted = await _homeserverExisted(); + if (homeserverExisted) return; _redirectRegistrationUrl(signupUrl); } + Future _homeserverExisted() async { + if (widget.arg?.isAddAnotherAccount == false) return false; + final allHomeserverLoggedIn = (await ClientManager.getClients()) + .map((client) => client.homeserver.toString()) + .toList(); + Logs().i('All homeservers: $allHomeserverLoggedIn'); + final homeserverExists = allHomeserverLoggedIn.any( + (homeserver) => "$homeserver/".contains(AppConfig.homeserver), + ); + + if (homeserverExists && + !AppConfig.supportMultipleAccountsInTheSameHomeserver) { + TwakeSnackBar.show( + context, + L10n.of(context)!.isSingleAccountOnHomeserver, + ); + return true; + } + return false; + } + @override Widget build(BuildContext context) { - return TwakeWelcomeView(controller: this); + return TwakeWelcomeView( + controller: this, + ); } } diff --git a/lib/pages/twake_welcome/twake_welcome_view.dart b/lib/pages/twake_welcome/twake_welcome_view.dart index 82468e2b42..267179f8cb 100644 --- a/lib/pages/twake_welcome/twake_welcome_view.dart +++ b/lib/pages/twake_welcome/twake_welcome_view.dart @@ -2,9 +2,11 @@ import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/pages/twake_welcome/twake_welcome.dart'; import 'package:fluffychat/pages/twake_welcome/twake_welcome_view_style.dart'; import 'package:fluffychat/resource/image_paths.dart'; +import 'package:fluffychat/widgets/twake_components/twake_icon_button.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_svg/flutter_svg.dart'; +import 'package:go_router/go_router.dart'; import 'package:linagora_design_flutter/linagora_design_flutter.dart'; class TwakeWelcomeView extends StatelessWidget { @@ -15,6 +17,17 @@ class TwakeWelcomeView extends StatelessWidget { @override Widget build(BuildContext context) { return TwakeWelcomeScreen( + appBar: controller.widget.arg?.isAddAnotherAccount == true + ? AppBar( + backgroundColor: Colors.transparent, + leading: TwakeIconButton( + icon: Icons.arrow_back, + onTap: () => context.pop(), + tooltip: L10n.of(context)!.back, + ), + elevation: 0, + ) + : null, focusColor: Colors.transparent, hoverColor: Colors.transparent, highlightColor: Colors.transparent, diff --git a/pubspec.lock b/pubspec.lock index dcc623e3b3..a724c39959 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1533,8 +1533,8 @@ packages: dependency: "direct main" description: path: "." - ref: master - resolved-ref: "7ed486ea00f7e91254555a4a828ff3a625b4e1ae" + ref: add-app-bar-for-twake-welcome + resolved-ref: "495ca81748fdf90faf426c0ed11a922b7d1ca60b" url: "git@github.com:linagora/linagora-design-flutter.git" source: git version: "0.0.1" diff --git a/pubspec.yaml b/pubspec.yaml index b7fbc48751..24945cf0ea 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,7 +29,7 @@ dependencies: linagora_design_flutter: git: url: git@github.com:linagora/linagora-design-flutter.git - ref: master + ref: add-app-bar-for-twake-welcome flutter_matrix_html: git: url: https://github.com/linagora/flutter_matrix_html.git