diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart index 91a3a5785..8876eaf6c 100644 --- a/lib/utils/background_push.dart +++ b/lib/utils/background_push.dart @@ -36,6 +36,7 @@ import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension. import 'package:fluffychat/utils/push_helper.dart'; import '../config/app_config.dart'; import '../config/setting_keys.dart'; +import '../widgets/fluffy_chat_app.dart'; import 'famedlysdk_store.dart'; import 'platform_infos.dart'; @@ -51,7 +52,7 @@ class BackgroundPush { FlutterLocalNotificationsPlugin(); Client client; BuildContext? context; - GlobalKey? router; + GlobalKey get router => FluffyChatApp.routerKey; String? _fcmToken; void Function(String errorMsg, {Uri? link})? onFcmError; L10n? l10n; @@ -82,7 +83,7 @@ class BackgroundPush { ), client: client, l10n: l10n, - activeRoomId: router?.currentState?.pathParameters['roomid'], + activeRoomId: router.currentState?.pathParameters['roomid'], onSelectNotification: goToRoom, ), ); @@ -103,15 +104,12 @@ class BackgroundPush { factory BackgroundPush( Client client, - BuildContext context, - GlobalKey? router, { + BuildContext context, { final void Function(String errorMsg, {Uri? link})? onFcmError, }) { final instance = BackgroundPush.clientOnly(client); instance.context = context; // ignore: prefer_initializing_formals - instance.router = router; - // ignore: prefer_initializing_formals instance.onFcmError = onFcmError; return instance; } @@ -233,7 +231,7 @@ class BackgroundPush { if (details == null || !details.didNotificationLaunchApp || _wentToRoomOnStartup || - router == null) { + router.currentState == null) { return; } _wentToRoomOnStartup = true; @@ -285,7 +283,7 @@ class BackgroundPush { try { final roomId = response?.payload; Logs().v('[Push] Attempting to go to room $roomId...'); - if (router == null || roomId == null) { + if (router.currentState == null || roomId == null) { return; } await client.roomsLoading; @@ -296,7 +294,7 @@ class BackgroundPush { ?.content .tryGet('type') == ClientStoriesExtension.storiesRoomType; - router!.currentState!.toSegments([isStory ? 'stories' : 'rooms', roomId]); + router.currentState!.toSegments([isStory ? 'stories' : 'rooms', roomId]); } catch (e, s) { Logs().e('[Push] Failed to open room', e, s); } @@ -376,7 +374,7 @@ class BackgroundPush { PushNotification.fromJson(data), client: client, l10n: l10n, - activeRoomId: router?.currentState?.pathParameters['roomid'], + activeRoomId: router.currentState?.pathParameters['roomid'], ); } diff --git a/lib/widgets/fluffy_chat_app.dart b/lib/widgets/fluffy_chat_app.dart index 5967bc728..3b34cc52f 100644 --- a/lib/widgets/fluffy_chat_app.dart +++ b/lib/widgets/fluffy_chat_app.dart @@ -78,7 +78,6 @@ class FluffyChatAppState extends State { builder: (context, child) => Matrix( key: FluffyChatApp.matrixKey, context: context, - router: FluffyChatApp.routerKey, clients: widget.clients, child: child, ), diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index 8e52a8c96..2ba246ea9 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -33,6 +33,7 @@ import '../pages/key_verification/key_verification_dialog.dart'; import '../utils/account_bundles.dart'; import '../utils/background_push.dart'; import '../utils/famedlysdk_store.dart'; +import 'fluffy_chat_app.dart'; import 'local_notifications_extension.dart'; // import 'package:flutter_secure_storage/flutter_secure_storage.dart'; @@ -40,7 +41,7 @@ import 'local_notifications_extension.dart'; class Matrix extends StatefulWidget { final Widget? child; - final GlobalKey? router; + GlobalKey get router => FluffyChatApp.routerKey; final BuildContext context; @@ -50,7 +51,6 @@ class Matrix extends StatefulWidget { const Matrix({ this.child, - required this.router, required this.context, required this.clients, this.queryParameters, @@ -177,7 +177,7 @@ class MatrixState extends State with WidgetsBindingObserver { ClientManager.addClientNameToStore(_loginClientCandidate!.clientName); _registerSubs(_loginClientCandidate!.clientName); _loginClientCandidate = null; - widget.router!.currentState!.to('/rooms'); + widget.router.currentState!.to('/rooms'); }); return candidate; } @@ -334,15 +334,15 @@ class MatrixState extends State with WidgetsBindingObserver { ); if (state != LoginState.loggedIn) { - widget.router?.currentState?.to( + widget.router.currentState?.to( '/rooms', - queryParameters: widget.router?.currentState?.queryParameters ?? {}, + queryParameters: widget.router.currentState?.queryParameters ?? {}, ); } } else { - widget.router?.currentState?.to( + widget.router.currentState?.to( state == LoginState.loggedIn ? '/rooms' : '/home', - queryParameters: widget.router?.currentState?.queryParameters ?? {}, + queryParameters: widget.router.currentState?.queryParameters ?? {}, ); } }); @@ -407,7 +407,6 @@ class MatrixState extends State with WidgetsBindingObserver { backgroundPush = BackgroundPush( client, context, - widget.router, onFcmError: (errorMsg, {Uri? link}) async { final result = await showOkCancelAlertDialog( barrierDismissible: true,