refactor: Follow up handle logout and login with new client

This commit is contained in:
Christian Kußowski 2025-06-11 08:19:54 +02:00
commit 2616ba6e4b
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
5 changed files with 26 additions and 15 deletions

View file

@ -174,6 +174,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
_loginClientCandidate = null;
FluffyChatApp.router.go('/rooms');
});
if (widget.clients.isEmpty) widget.clients.add(candidate);
return candidate;
}
@ -282,12 +283,12 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
onLoginStateChanged[name] ??= c.onLoginStateChanged.stream.listen((state) {
final loggedInWithMultipleClients = widget.clients.length > 1;
if (state == LoginState.loggedOut) {
InitWithRestoreExtension.deleteSessionBackup(name);
}
if (loggedInWithMultipleClients && state != LoginState.loggedIn) {
_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,
@ -379,12 +380,14 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
Logs().v('AppLifecycleState = $state');
final foreground = state != AppLifecycleState.inactive &&
state != AppLifecycleState.paused;
client.syncPresence =
state == AppLifecycleState.resumed ? null : PresenceType.unavailable;
if (PlatformInfos.isMobile) {
client.backgroundSync = foreground;
client.requestHistoryOnLimitedTimeline = !foreground;
Logs().v('Set background sync to', foreground);
for (final client in widget.clients) {
client.syncPresence =
state == AppLifecycleState.resumed ? null : PresenceType.unavailable;
if (PlatformInfos.isMobile) {
client.backgroundSync = foreground;
client.requestHistoryOnLimitedTimeline = !foreground;
Logs().v('Set background sync to', foreground);
}
}
}