fix: Do not route to backup on soft logout

This commit is contained in:
Christian Kußowski 2026-02-25 06:47:28 +01:00
parent 0052a15b54
commit 740f04206a
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
3 changed files with 31 additions and 28 deletions

View file

@ -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<Login> {
password: passwordController.text,
initialDeviceDisplayName: PlatformInfos.clientName,
);
if (mounted) {
context.go('/backup');
}
} on MatrixException catch (exception) {
setState(() => passwordError = exception.errorMessage);
return setState(() => loading = false);

View file

@ -70,6 +70,7 @@ Future<void> connectToHomeserverFlow(
if (context.mounted) {
setState(AsyncSnapshot.withData(ConnectionState.done, true));
context.go('/backup');
}
} catch (e, s) {
setState(AsyncSnapshot.withError(ConnectionState.done, e, s));

View file

@ -177,7 +177,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
final onRoomKeyRequestSub = <String, StreamSubscription>{};
final onKeyVerificationRequestSub = <String, StreamSubscription>{};
final onNotification = <String, StreamSubscription>{};
final onLoginStateChanged = <String, StreamSubscription<LoginState>>{};
final onLogoutSub = <String, StreamSubscription<LoginState>>{};
final onUiaRequest = <String, StreamSubscription<UiaRequest>>{};
String? _cachedPassword;
@ -255,31 +255,29 @@ class MatrixState extends State<Matrix> 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<Matrix> 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<Matrix> 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();