refactor: Follow up handle logout and login with new client
This commit is contained in:
parent
2ba5b1170d
commit
2616ba6e4b
5 changed files with 26 additions and 15 deletions
|
|
@ -44,13 +44,17 @@ abstract class AppRoutes {
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
GoRouterState state,
|
GoRouterState state,
|
||||||
) =>
|
) =>
|
||||||
Matrix.of(context).client.isLogged() ? '/rooms' : null;
|
Matrix.of(context).widget.clients.any((client) => client.isLogged())
|
||||||
|
? '/rooms'
|
||||||
|
: null;
|
||||||
|
|
||||||
static FutureOr<String?> loggedOutRedirect(
|
static FutureOr<String?> loggedOutRedirect(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
GoRouterState state,
|
GoRouterState state,
|
||||||
) =>
|
) =>
|
||||||
Matrix.of(context).client.isLogged() ? null : '/home';
|
Matrix.of(context).widget.clients.any((client) => client.isLogged())
|
||||||
|
? null
|
||||||
|
: '/home';
|
||||||
|
|
||||||
AppRoutes();
|
AppRoutes();
|
||||||
|
|
||||||
|
|
@ -58,7 +62,9 @@ abstract class AppRoutes {
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/',
|
path: '/',
|
||||||
redirect: (context, state) =>
|
redirect: (context, state) =>
|
||||||
Matrix.of(context).client.isLogged() ? '/rooms' : '/home',
|
Matrix.of(context).widget.clients.any((client) => client.isLogged())
|
||||||
|
? '/rooms'
|
||||||
|
: '/home',
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/home',
|
path: '/home',
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ class HomeserverPickerView extends StatelessWidget {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
return LoginScaffold(
|
return LoginScaffold(
|
||||||
enforceMobileMode: Matrix.of(context).client.isLogged(),
|
enforceMobileMode:
|
||||||
|
Matrix.of(context).widget.clients.any((client) => client.isLogged()),
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
title: Text(
|
title: Text(
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ class LoginController extends State<Login> {
|
||||||
identifier = AuthenticationUserIdentifier(user: username);
|
identifier = AuthenticationUserIdentifier(user: username);
|
||||||
}
|
}
|
||||||
final client = await matrix.getLoginClient();
|
final client = await matrix.getLoginClient();
|
||||||
client.login(
|
await client.login(
|
||||||
LoginType.mLoginPassword,
|
LoginType.mLoginPassword,
|
||||||
identifier: identifier,
|
identifier: identifier,
|
||||||
// To stay compatible with older server versions
|
// To stay compatible with older server versions
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ class LoginView extends StatelessWidget {
|
||||||
final titleParts = title.split(homeserver);
|
final titleParts = title.split(homeserver);
|
||||||
|
|
||||||
return LoginScaffold(
|
return LoginScaffold(
|
||||||
enforceMobileMode: Matrix.of(context).client.isLogged(),
|
enforceMobileMode:
|
||||||
|
Matrix.of(context).widget.clients.any((client) => client.isLogged()),
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
leading: controller.loading ? null : const Center(child: BackButton()),
|
leading: controller.loading ? null : const Center(child: BackButton()),
|
||||||
automaticallyImplyLeading: !controller.loading,
|
automaticallyImplyLeading: !controller.loading,
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
_loginClientCandidate = null;
|
_loginClientCandidate = null;
|
||||||
FluffyChatApp.router.go('/rooms');
|
FluffyChatApp.router.go('/rooms');
|
||||||
});
|
});
|
||||||
|
if (widget.clients.isEmpty) widget.clients.add(candidate);
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -282,12 +283,12 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
onLoginStateChanged[name] ??= c.onLoginStateChanged.stream.listen((state) {
|
onLoginStateChanged[name] ??= c.onLoginStateChanged.stream.listen((state) {
|
||||||
final loggedInWithMultipleClients = widget.clients.length > 1;
|
final loggedInWithMultipleClients = widget.clients.length > 1;
|
||||||
if (state == LoginState.loggedOut) {
|
if (state == LoginState.loggedOut) {
|
||||||
InitWithRestoreExtension.deleteSessionBackup(name);
|
|
||||||
}
|
|
||||||
if (loggedInWithMultipleClients && state != LoginState.loggedIn) {
|
|
||||||
_cancelSubs(c.clientName);
|
_cancelSubs(c.clientName);
|
||||||
widget.clients.remove(c);
|
widget.clients.remove(c);
|
||||||
ClientManager.removeClientNameFromStore(c.clientName, store);
|
ClientManager.removeClientNameFromStore(c.clientName, store);
|
||||||
|
InitWithRestoreExtension.deleteSessionBackup(name);
|
||||||
|
}
|
||||||
|
if (loggedInWithMultipleClients && state != LoginState.loggedIn) {
|
||||||
ScaffoldMessenger.of(
|
ScaffoldMessenger.of(
|
||||||
FluffyChatApp.router.routerDelegate.navigatorKey.currentContext ??
|
FluffyChatApp.router.routerDelegate.navigatorKey.currentContext ??
|
||||||
context,
|
context,
|
||||||
|
|
@ -379,12 +380,14 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
Logs().v('AppLifecycleState = $state');
|
Logs().v('AppLifecycleState = $state');
|
||||||
final foreground = state != AppLifecycleState.inactive &&
|
final foreground = state != AppLifecycleState.inactive &&
|
||||||
state != AppLifecycleState.paused;
|
state != AppLifecycleState.paused;
|
||||||
client.syncPresence =
|
for (final client in widget.clients) {
|
||||||
state == AppLifecycleState.resumed ? null : PresenceType.unavailable;
|
client.syncPresence =
|
||||||
if (PlatformInfos.isMobile) {
|
state == AppLifecycleState.resumed ? null : PresenceType.unavailable;
|
||||||
client.backgroundSync = foreground;
|
if (PlatformInfos.isMobile) {
|
||||||
client.requestHistoryOnLimitedTimeline = !foreground;
|
client.backgroundSync = foreground;
|
||||||
Logs().v('Set background sync to', foreground);
|
client.requestHistoryOnLimitedTimeline = !foreground;
|
||||||
|
Logs().v('Set background sync to', foreground);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue