fix: Do not route to backup on soft logout
This commit is contained in:
parent
0052a15b54
commit
740f04206a
3 changed files with 31 additions and 28 deletions
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/l10n/l10n.dart';
|
import 'package:fluffychat/l10n/l10n.dart';
|
||||||
|
|
@ -81,6 +82,9 @@ class LoginController extends State<Login> {
|
||||||
password: passwordController.text,
|
password: passwordController.text,
|
||||||
initialDeviceDisplayName: PlatformInfos.clientName,
|
initialDeviceDisplayName: PlatformInfos.clientName,
|
||||||
);
|
);
|
||||||
|
if (mounted) {
|
||||||
|
context.go('/backup');
|
||||||
|
}
|
||||||
} on MatrixException catch (exception) {
|
} on MatrixException catch (exception) {
|
||||||
setState(() => passwordError = exception.errorMessage);
|
setState(() => passwordError = exception.errorMessage);
|
||||||
return setState(() => loading = false);
|
return setState(() => loading = false);
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ Future<void> connectToHomeserverFlow(
|
||||||
|
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
setState(AsyncSnapshot.withData(ConnectionState.done, true));
|
setState(AsyncSnapshot.withData(ConnectionState.done, true));
|
||||||
|
context.go('/backup');
|
||||||
}
|
}
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
setState(AsyncSnapshot.withError(ConnectionState.done, e, s));
|
setState(AsyncSnapshot.withError(ConnectionState.done, e, s));
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
final onRoomKeyRequestSub = <String, StreamSubscription>{};
|
final onRoomKeyRequestSub = <String, StreamSubscription>{};
|
||||||
final onKeyVerificationRequestSub = <String, StreamSubscription>{};
|
final onKeyVerificationRequestSub = <String, StreamSubscription>{};
|
||||||
final onNotification = <String, StreamSubscription>{};
|
final onNotification = <String, StreamSubscription>{};
|
||||||
final onLoginStateChanged = <String, StreamSubscription<LoginState>>{};
|
final onLogoutSub = <String, StreamSubscription<LoginState>>{};
|
||||||
final onUiaRequest = <String, StreamSubscription<UiaRequest>>{};
|
final onUiaRequest = <String, StreamSubscription<UiaRequest>>{};
|
||||||
|
|
||||||
String? _cachedPassword;
|
String? _cachedPassword;
|
||||||
|
|
@ -255,31 +255,29 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
context,
|
context,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
onLoginStateChanged[name] ??= c.onLoginStateChanged.stream.listen((state) {
|
onLogoutSub[name] ??= c.onLoginStateChanged.stream
|
||||||
final loggedInWithMultipleClients = widget.clients.length > 1;
|
.where((state) => state == LoginState.loggedOut)
|
||||||
if (state == LoginState.loggedOut) {
|
.listen((state) {
|
||||||
_cancelSubs(c.clientName);
|
final loggedInWithMultipleClients = widget.clients.length > 1;
|
||||||
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)),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (state != LoginState.loggedIn) {
|
_cancelSubs(c.clientName);
|
||||||
FluffyChatApp.router.go('/rooms');
|
widget.clients.remove(c);
|
||||||
}
|
ClientManager.removeClientNameFromStore(c.clientName, store);
|
||||||
} else {
|
InitWithRestoreExtension.deleteSessionBackup(name);
|
||||||
FluffyChatApp.router.go(
|
|
||||||
state == LoginState.loggedIn ? '/backup' : '/home',
|
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);
|
onUiaRequest[name] ??= c.onUiaRequest.stream.listen(uiaRequestHandler);
|
||||||
if (PlatformInfos.isWeb || PlatformInfos.isLinux) {
|
if (PlatformInfos.isWeb || PlatformInfos.isLinux) {
|
||||||
c.onSync.stream.first.then((s) {
|
c.onSync.stream.first.then((s) {
|
||||||
|
|
@ -296,8 +294,8 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
onRoomKeyRequestSub.remove(name);
|
onRoomKeyRequestSub.remove(name);
|
||||||
onKeyVerificationRequestSub[name]?.cancel();
|
onKeyVerificationRequestSub[name]?.cancel();
|
||||||
onKeyVerificationRequestSub.remove(name);
|
onKeyVerificationRequestSub.remove(name);
|
||||||
onLoginStateChanged[name]?.cancel();
|
onLogoutSub[name]?.cancel();
|
||||||
onLoginStateChanged.remove(name);
|
onLogoutSub.remove(name);
|
||||||
onNotification[name]?.cancel();
|
onNotification[name]?.cancel();
|
||||||
onNotification.remove(name);
|
onNotification.remove(name);
|
||||||
}
|
}
|
||||||
|
|
@ -373,7 +371,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
|
|
||||||
onRoomKeyRequestSub.values.map((s) => s.cancel());
|
onRoomKeyRequestSub.values.map((s) => s.cancel());
|
||||||
onKeyVerificationRequestSub.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());
|
onNotification.values.map((s) => s.cancel());
|
||||||
client.httpClient.close();
|
client.httpClient.close();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue