diff --git a/lib/config/go_routes/go_router.dart b/lib/config/go_routes/go_router.dart index eb1e99d13a..54a7c9688b 100644 --- a/lib/config/go_routes/go_router.dart +++ b/lib/config/go_routes/go_router.dart @@ -145,7 +145,9 @@ abstract class AppRoutes { state.fullPath?.startsWith('/rooms/settings') == false ? AppAdaptiveScaffold( body: AppAdaptiveScaffoldBody( - activeRoomId: state.pathParameters['roomid'], + args: AppAdaptiveScaffoldBodyArgs( + activeRoomId: state.pathParameters['roomid'], + ), ), secondaryBody: child, ) @@ -160,9 +162,17 @@ abstract class AppRoutes { !_responsive.isMobile(context) ? const ChatBlank() : AppAdaptiveScaffoldBody( - activeRoomId: state.pathParameters['roomid'], - client: - state.extra is Client? ? state.extra as Client? : null, + args: AppAdaptiveScaffoldBodyArgs( + activeRoomId: state.pathParameters['roomid'], + client: state.extra is AppAdaptiveScaffoldBodyArgs + ? (state.extra as AppAdaptiveScaffoldBodyArgs).client + : null, + isLogoutMultipleAccount: + state.extra is AppAdaptiveScaffoldBodyArgs + ? (state.extra as AppAdaptiveScaffoldBodyArgs) + .isLogoutMultipleAccount + : false, + ), ), ), routes: [ diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index 3c930839e5..38ecb50f62 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -808,7 +808,10 @@ class ChatListController extends State @override void didUpdateWidget(covariant ChatList oldWidget) { Logs().d( - "ChatList::didUpdateWidget(): Client ${widget.newClient?.clientName}", + "ChatList::didUpdateWidget(): OldClient $activeClient", + ); + Logs().d( + "ChatList::didUpdateWidget(): NewClient ${widget.newClient?.clientName}", ); if (widget.newClient != activeClient) { initSetActiveClient(); diff --git a/lib/pages/settings_dashboard/settings/settings.dart b/lib/pages/settings_dashboard/settings/settings.dart index b03fefd4f3..0a178871d7 100644 --- a/lib/pages/settings_dashboard/settings/settings.dart +++ b/lib/pages/settings_dashboard/settings/settings.dart @@ -83,10 +83,12 @@ class SettingsController extends State with ConnectPageMixin { OkCancelResult.cancel) { return; } - await tryLogoutSso(context); - final hiveCollectionToMDatabase = getIt.get(); - await hiveCollectionToMDatabase.clear(); final matrix = Matrix.of(context); + if (matrix.twakeIsSupported) { + await tryLogoutSso(context); + final hiveCollectionToMDatabase = getIt.get(); + await hiveCollectionToMDatabase.clear(); + } await TwakeDialog.showFutureLoadingDialogFullScreen( future: () async { if (matrix.backgroundPush != null) { diff --git a/lib/widgets/layouts/adaptive_layout/app_adaptive_scaffold_body.dart b/lib/widgets/layouts/adaptive_layout/app_adaptive_scaffold_body.dart index 7f75c711af..f402549b7d 100644 --- a/lib/widgets/layouts/adaptive_layout/app_adaptive_scaffold_body.dart +++ b/lib/widgets/layouts/adaptive_layout/app_adaptive_scaffold_body.dart @@ -1,3 +1,4 @@ +import 'package:equatable/equatable.dart'; import 'package:fluffychat/config/first_column_inner_routes.dart'; import 'package:fluffychat/pages/chat_list/client_chooser_button.dart'; import 'package:fluffychat/utils/extension/build_context_extension.dart'; @@ -13,14 +14,31 @@ typedef OnCloseSearchPage = Function(); typedef OnClientSelectedSetting = Function(Object object, BuildContext context); typedef OnDestinationSelected = Function(int index); -class AppAdaptiveScaffoldBody extends StatefulWidget { +class AppAdaptiveScaffoldBodyArgs extends Equatable { final String? activeRoomId; final Client? client; + final bool isLogoutMultipleAccount; - const AppAdaptiveScaffoldBody({ - super.key, + const AppAdaptiveScaffoldBodyArgs({ this.activeRoomId, this.client, + this.isLogoutMultipleAccount = false, + }); + + @override + List get props => [ + activeRoomId, + client, + isLogoutMultipleAccount, + ]; +} + +class AppAdaptiveScaffoldBody extends StatefulWidget { + final AppAdaptiveScaffoldBodyArgs args; + + const AppAdaptiveScaffoldBody({ + super.key, + required this.args, }); @override @@ -101,17 +119,35 @@ class AppAdaptiveScaffoldBodyController extends State { pageController.jumpToPage(activeNavigationBar.value.index); } + void _onLogoutMultipleAccountSuccess( + covariant AppAdaptiveScaffoldBody oldWidget, + ) { + Logs().d( + 'AppAdaptiveScaffoldBodyController::_onLogoutMultipleAccountSuccess():oldWidget.isLogoutMultipleAccount: ${oldWidget.args.isLogoutMultipleAccount}', + ); + Logs().d( + 'AppAdaptiveScaffoldBodyController::_onLogoutMultipleAccountSuccess():newIsLogoutMultipleAccount: ${widget.args.isLogoutMultipleAccount}', + ); + if (oldWidget.args.isLogoutMultipleAccount != + widget.args.isLogoutMultipleAccount && + widget.args.isLogoutMultipleAccount) { + activeNavigationBar.value = AdaptiveDestinationEnum.rooms; + pageController.jumpToPage(AdaptiveDestinationEnum.rooms.index); + } + } + MatrixState get matrix => Matrix.of(context); @override void initState() { - activeRoomIdNotifier.value = widget.activeRoomId; + activeRoomIdNotifier.value = widget.args.activeRoomId; super.initState(); } @override void didUpdateWidget(covariant AppAdaptiveScaffoldBody oldWidget) { - activeRoomIdNotifier.value = widget.activeRoomId; + activeRoomIdNotifier.value = widget.args.activeRoomId; + _onLogoutMultipleAccountSuccess(oldWidget); super.didUpdateWidget(oldWidget); } @@ -126,6 +162,6 @@ class AppAdaptiveScaffoldBodyController extends State { onDestinationSelected: onDestinationSelected, onClientSelected: clientSelected, onOpenSettings: _onOpenSettingsPage, - client: widget.client, + client: widget.args.client, ); } diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index f5dfde34ca..911b4b7b59 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -22,6 +22,7 @@ import 'package:fluffychat/utils/twake_snackbar.dart'; import 'package:fluffychat/utils/uia_request_manager.dart'; import 'package:fluffychat/utils/url_launcher.dart'; import 'package:fluffychat/utils/voip_plugin.dart'; +import 'package:fluffychat/widgets/layouts/adaptive_layout/app_adaptive_scaffold_body.dart'; import 'package:fluffychat/widgets/twake_app.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -191,8 +192,10 @@ class MatrixState extends State _registerSubs(_loginClientCandidate!.clientName); TwakeApp.router.go( '/rooms', - extra: getClientByName( - _loginClientCandidate!.clientName, + extra: AppAdaptiveScaffoldBodyArgs( + client: getClientByName( + _loginClientCandidate!.clientName, + ), ), ); _loginClientCandidate = null; @@ -369,7 +372,12 @@ class MatrixState extends State ); if (state != LoginState.loggedIn) { - TwakeApp.router.go('/rooms'); + TwakeApp.router.go( + '/rooms', + extra: const AppAdaptiveScaffoldBodyArgs( + isLogoutMultipleAccount: true, + ), + ); } } else { if (state == LoginState.loggedIn) {