Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/lib/services/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class NotificationUtil {
_handleAppLinkOrDeepLink(receivedAction.payload!);
}

/// Public entry point for programmatic deep-link navigation (e.g. FCM background/terminated tap)
static void handleNavigateTo(String route) {
_handleAppLinkOrDeepLink({'navigate_to': route});
}

static void _handleAppLinkOrDeepLink(Map<String, dynamic> payload) async {
// Always ensure that all plugins was initialized
// TODO: for what?
Expand Down
15 changes: 15 additions & 0 deletions app/lib/services/notifications/notification_service_fcm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:flutter_timezone/flutter_timezone.dart';

import 'package:omi/backend/http/api/notifications.dart';
import 'package:omi/backend/schema/message.dart';
import 'package:omi/services/notifications.dart' show NotificationUtil;
import 'package:omi/services/notifications/action_item_notification_handler.dart';
import 'package:omi/services/notifications/important_conversation_notification_handler.dart';
import 'package:omi/services/notifications/merge_notification_handler.dart';
Expand Down Expand Up @@ -273,6 +274,20 @@ class _FCMNotificationService implements NotificationInterface {
return;
}
});

void handleNotificationTap(RemoteMessage? message) {
if (message == null) return;
final navigateTo = message.data['navigate_to'];
if (navigateTo is String && navigateTo.isNotEmpty) {
NotificationUtil.handleNavigateTo(navigateTo);
}
}

// Background state: app in background, user taps a push notification
FirebaseMessaging.onMessageOpenedApp.listen(handleNotificationTap);

// Terminated state: app was killed and opened via notification tap
FirebaseMessaging.instance.getInitialMessage().then(handleNotificationTap);
}

final _serverMessageStreamController = StreamController<ServerMessage>.broadcast();
Expand Down