From 814533ede6af4d2ba1bf5bf8ee16198e9a12cbdb Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Mon, 10 Jun 2024 13:05:48 +0700 Subject: [PATCH] TW-1587: Fix can't open chat when click on notification --- .../extensions/go_router_extensions.dart | 14 ++++++++++++++ lib/utils/background_push.dart | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 lib/presentation/extensions/go_router_extensions.dart diff --git a/lib/presentation/extensions/go_router_extensions.dart b/lib/presentation/extensions/go_router_extensions.dart new file mode 100644 index 0000000000..7747afe0d2 --- /dev/null +++ b/lib/presentation/extensions/go_router_extensions.dart @@ -0,0 +1,14 @@ +import 'package:go_router/go_router.dart'; + +extension GoRouterExtensions on GoRouter { + String? get activeRoomId { + try { + final path = routeInformationProvider.value.uri.path; + if (path.isEmpty) return null; + if (!path.startsWith('/rooms/')) return null; + return path.split('/')[2]; + } catch (e) { + return null; + } + } +} diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart index 8c9d0b0bee..605f502d4e 100644 --- a/lib/utils/background_push.dart +++ b/lib/utils/background_push.dart @@ -24,6 +24,7 @@ import 'dart:io'; import 'package:fcm_shared_isolate/fcm_shared_isolate.dart'; import 'package:fluffychat/domain/model/extensions/push/push_notification_extension.dart'; import 'package:fluffychat/presentation/extensions/client_extension.dart'; +import 'package:fluffychat/presentation/extensions/go_router_extensions.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart'; import 'package:fluffychat/utils/push_helper.dart'; import 'package:fluffychat/widgets/twake_app.dart'; @@ -369,8 +370,8 @@ class BackgroundPush { Future goToRoom(String? roomId) async { try { - _clearAllNavigatorAvailable(); Logs().v('[Push] Attempting to go to room $roomId...'); + _clearAllNavigatorAvailable(roomId: roomId); if (_matrixState == null || roomId == null) { return; } @@ -609,8 +610,18 @@ class BackgroundPush { ); } - void _clearAllNavigatorAvailable() { - final canPopNavigation = TwakeApp.router.canPop(); + void _clearAllNavigatorAvailable({ + String? roomId, + }) { + Logs().d( + "BackgroundPush:: - Current active room id @2 ${TwakeApp.router.activeRoomId}", + ); + if (roomId != null && + TwakeApp.router.activeRoomId?.contains(roomId) == true) { + return; + } + + final canPopNavigation = TwakeApp.router.routerDelegate.canPop(); Logs().d("BackgroundPush:: - Can pop other Navigation $canPopNavigation"); if (canPopNavigation) { TwakeApp.router.routerDelegate.pop();