From 2616ba6e4b918ccd8c41d5a59ec0fe309b5ae68b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ku=C3=9Fowski?= Date: Wed, 11 Jun 2025 08:19:54 +0200 Subject: [PATCH 1/2] refactor: Follow up handle logout and login with new client --- lib/config/routes.dart | 12 ++++++++--- .../homeserver_picker_view.dart | 3 ++- lib/pages/login/login.dart | 2 +- lib/pages/login/login_view.dart | 3 ++- lib/widgets/matrix.dart | 21 +++++++++++-------- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/lib/config/routes.dart b/lib/config/routes.dart index 231f7872a..9871a013f 100644 --- a/lib/config/routes.dart +++ b/lib/config/routes.dart @@ -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 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', diff --git a/lib/pages/homeserver_picker/homeserver_picker_view.dart b/lib/pages/homeserver_picker/homeserver_picker_view.dart index c1878b8a4..4161f1f9a 100644 --- a/lib/pages/homeserver_picker/homeserver_picker_view.dart +++ b/lib/pages/homeserver_picker/homeserver_picker_view.dart @@ -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( diff --git a/lib/pages/login/login.dart b/lib/pages/login/login.dart index 5ac743eb8..8dee4ba38 100644 --- a/lib/pages/login/login.dart +++ b/lib/pages/login/login.dart @@ -70,7 +70,7 @@ class LoginController extends State { 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 diff --git a/lib/pages/login/login_view.dart b/lib/pages/login/login_view.dart index 71129bd6b..a82b5054f 100644 --- a/lib/pages/login/login_view.dart +++ b/lib/pages/login/login_view.dart @@ -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, diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index 54b26aee3..1115e8756 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -174,6 +174,7 @@ class MatrixState extends State 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 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 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); + } } } From 0edd4e320dff4153e166c822da91cbea361c61d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ku=C3=9Fowski?= Date: Wed, 11 Jun 2025 08:22:25 +0200 Subject: [PATCH 2/2] build: Add changelog for 2.0.0 --- CHANGELOG.md | 11 +++++++++++ pubspec.yaml | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cda73ec3..5bd9dd2ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## v2.0.0 + +This version migrates to Vodozemac and Matrix Dart SDK 1.0.0. This is a breaking +change. The user should not notice the migration at all but downgrading from +v2.0.0 to a previous version is not possible without losing the session. + +- build: Switch to matrix sdk 1.0.0 (Christian Kußowski) +- build: Upgrade flutter to 3.32.2 (krille-chan) +- chore: Add missing mounted check (Christian Kußowski) +- refactor: sdk 1.0 (Christian Kußowski) + ## v1.27.0 - feat: Add confirmation dialog before accepting invite (krille-chan) - feat: Add feature flag for refresh tokens (Christian Kußowski) diff --git a/pubspec.yaml b/pubspec.yaml index 512c9d99e..e7c0ee352 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: fluffychat description: Chat with your friends. publish_to: none # On version bump also increase the build number for F-Droid -version: 1.27.0+3540 +version: 2.0.0+3541 environment: sdk: ">=3.0.0 <4.0.0"