Skip to content

Commit

Permalink
TW-1587: Fix can't open chat when click on notification (#1867)
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and Te-Z committed Jun 18, 2024
1 parent c0b9ec3 commit a01f75b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
14 changes: 14 additions & 0 deletions lib/presentation/extensions/go_router_extensions.dart
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
17 changes: 14 additions & 3 deletions lib/utils/background_push.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -369,8 +370,8 @@ class BackgroundPush {

Future<void> goToRoom(String? roomId) async {
try {
_clearAllNavigatorAvailable();
Logs().v('[Push] Attempting to go to room $roomId...');
_clearAllNavigatorAvailable(roomId: roomId);
if (_matrixState == null || roomId == null) {
return;
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a01f75b

Please sign in to comment.