refactor: Follow up handle logout and login with new client

pull/1960/head
Christian Kußowski 4 months ago
parent 2ba5b1170d
commit 2616ba6e4b
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652

@ -44,13 +44,17 @@ abstract class AppRoutes {
BuildContext context,
GoRouterState state,
) =>
Matrix.of(context).client.isLogged() ? '/rooms' : null;
Matrix.of(context).widget.clients.any((client) => client.isLogged())
? '/rooms'
: null;
static FutureOr<String?> loggedOutRedirect(
BuildContext context,
GoRouterState state,
) =>
Matrix.of(context).client.isLogged() ? null : '/home';
Matrix.of(context).widget.clients.any((client) => client.isLogged())
? null
: '/home';
AppRoutes();
@ -58,7 +62,9 @@ abstract class AppRoutes {
GoRoute(
path: '/',
redirect: (context, state) =>
Matrix.of(context).client.isLogged() ? '/rooms' : '/home',
Matrix.of(context).widget.clients.any((client) => client.isLogged())
? '/rooms'
: '/home',
),
GoRoute(
path: '/home',

@ -25,7 +25,8 @@ class HomeserverPickerView extends StatelessWidget {
final theme = Theme.of(context);
return LoginScaffold(
enforceMobileMode: Matrix.of(context).client.isLogged(),
enforceMobileMode:
Matrix.of(context).widget.clients.any((client) => client.isLogged()),
appBar: AppBar(
centerTitle: true,
title: Text(

@ -70,7 +70,7 @@ class LoginController extends State<Login> {
identifier = AuthenticationUserIdentifier(user: username);
}
final client = await matrix.getLoginClient();
client.login(
await client.login(
LoginType.mLoginPassword,
identifier: identifier,
// To stay compatible with older server versions

@ -21,7 +21,8 @@ class LoginView extends StatelessWidget {
final titleParts = title.split(homeserver);
return LoginScaffold(
enforceMobileMode: Matrix.of(context).client.isLogged(),
enforceMobileMode:
Matrix.of(context).widget.clients.any((client) => client.isLogged()),
appBar: AppBar(
leading: controller.loading ? null : const Center(child: BackButton()),
automaticallyImplyLeading: !controller.loading,

@ -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,6 +380,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
Logs().v('AppLifecycleState = $state');
final foreground = state != AppLifecycleState.inactive &&
state != AppLifecycleState.paused;
for (final client in widget.clients) {
client.syncPresence =
state == AppLifecycleState.resumed ? null : PresenceType.unavailable;
if (PlatformInfos.isMobile) {
@ -387,6 +389,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
Logs().v('Set background sync to', foreground);
}
}
}
void initSettings() {
AppConfig.fontSizeFactor =

Loading…
Cancel
Save