diff --git a/lib/pages/login/login.dart b/lib/pages/login/login.dart index c0a3e10ab..b1eecd0b8 100644 --- a/lib/pages/login/login.dart +++ b/lib/pages/login/login.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; import 'package:fluffychat/l10n/l10n.dart'; @@ -81,6 +82,9 @@ class LoginController extends State { password: passwordController.text, initialDeviceDisplayName: PlatformInfos.clientName, ); + if (mounted) { + context.go('/backup'); + } } on MatrixException catch (exception) { setState(() => passwordError = exception.errorMessage); return setState(() => loading = false); diff --git a/lib/utils/sign_in_flows/check_homeserver.dart b/lib/utils/sign_in_flows/check_homeserver.dart index 754a2d9bf..ef0bf94bb 100644 --- a/lib/utils/sign_in_flows/check_homeserver.dart +++ b/lib/utils/sign_in_flows/check_homeserver.dart @@ -70,6 +70,7 @@ Future connectToHomeserverFlow( if (context.mounted) { setState(AsyncSnapshot.withData(ConnectionState.done, true)); + context.go('/backup'); } } catch (e, s) { setState(AsyncSnapshot.withError(ConnectionState.done, e, s)); diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index 6c66b16d1..60fd73b77 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -177,7 +177,7 @@ class MatrixState extends State with WidgetsBindingObserver { final onRoomKeyRequestSub = {}; final onKeyVerificationRequestSub = {}; final onNotification = {}; - final onLoginStateChanged = >{}; + final onLogoutSub = >{}; final onUiaRequest = >{}; String? _cachedPassword; @@ -255,31 +255,29 @@ class MatrixState extends State with WidgetsBindingObserver { context, ); }); - onLoginStateChanged[name] ??= c.onLoginStateChanged.stream.listen((state) { - final loggedInWithMultipleClients = widget.clients.length > 1; - if (state == LoginState.loggedOut) { - _cancelSubs(c.clientName); - widget.clients.remove(c); - ClientManager.removeClientNameFromStore(c.clientName, store); - InitWithRestoreExtension.deleteSessionBackup(name); - } - if (loggedInWithMultipleClients && state != LoginState.loggedIn) { - ScaffoldMessenger.of( - FluffyChatApp.router.routerDelegate.navigatorKey.currentContext ?? - context, - ).showSnackBar( - SnackBar(content: Text(L10n.of(context).oneClientLoggedOut)), - ); + onLogoutSub[name] ??= c.onLoginStateChanged.stream + .where((state) => state == LoginState.loggedOut) + .listen((state) { + final loggedInWithMultipleClients = widget.clients.length > 1; - if (state != LoginState.loggedIn) { - FluffyChatApp.router.go('/rooms'); - } - } else { - FluffyChatApp.router.go( - state == LoginState.loggedIn ? '/backup' : '/home', - ); - } - }); + _cancelSubs(c.clientName); + widget.clients.remove(c); + ClientManager.removeClientNameFromStore(c.clientName, store); + InitWithRestoreExtension.deleteSessionBackup(name); + + if (loggedInWithMultipleClients) { + ScaffoldMessenger.of( + FluffyChatApp.router.routerDelegate.navigatorKey.currentContext ?? + context, + ).showSnackBar( + SnackBar(content: Text(L10n.of(context).oneClientLoggedOut)), + ); + + if (state != LoginState.loggedIn) { + FluffyChatApp.router.go('/rooms'); + } + } + }); onUiaRequest[name] ??= c.onUiaRequest.stream.listen(uiaRequestHandler); if (PlatformInfos.isWeb || PlatformInfos.isLinux) { c.onSync.stream.first.then((s) { @@ -296,8 +294,8 @@ class MatrixState extends State with WidgetsBindingObserver { onRoomKeyRequestSub.remove(name); onKeyVerificationRequestSub[name]?.cancel(); onKeyVerificationRequestSub.remove(name); - onLoginStateChanged[name]?.cancel(); - onLoginStateChanged.remove(name); + onLogoutSub[name]?.cancel(); + onLogoutSub.remove(name); onNotification[name]?.cancel(); onNotification.remove(name); } @@ -373,7 +371,7 @@ class MatrixState extends State with WidgetsBindingObserver { onRoomKeyRequestSub.values.map((s) => s.cancel()); onKeyVerificationRequestSub.values.map((s) => s.cancel()); - onLoginStateChanged.values.map((s) => s.cancel()); + onLogoutSub.values.map((s) => s.cancel()); onNotification.values.map((s) => s.cancel()); client.httpClient.close();