@@ -8,16 +8,13 @@ import 'package:firebase_core/firebase_core.dart';
88
99import 'package:firebase_messaging/firebase_messaging.dart' ;
1010import 'package:flutter_local_notifications/flutter_local_notifications.dart' ;
11- import 'package:on_time_front/core/di/di_setup.dart' ;
1211import 'package:on_time_front/core/logging/app_logger.dart' ;
1312import 'package:on_time_front/core/services/js_interop_service.dart' ;
14- import 'package:on_time_front/core/services/navigation_service.dart' ;
1513import 'package:on_time_front/core/services/notification_content.dart' ;
1614import 'package:on_time_front/core/services/notification_routing.dart' ;
17- import 'package:on_time_front/data/data_sources/notification_remote_data_source .dart' ;
18- import 'package:on_time_front/data/models/fcm_token_register_request_model .dart' ;
15+ import 'package:on_time_front/core/services/notification_tap_router .dart' ;
16+ import 'package:on_time_front/core/services/notification_token_registrar .dart' ;
1917import 'package:on_time_front/domain/entities/alarm_entities.dart' ;
20- import 'package:on_time_front/domain/repositories/alarm_repository.dart' ;
2118import 'package:permission_handler/permission_handler.dart'
2219 as permission_handler;
2320import 'package:timezone/data/latest.dart' as tz_data;
@@ -43,13 +40,18 @@ class NotificationService {
4340 FlutterLocalNotificationsPlugin ? localNotifications,
4441 String Function ()? localeProvider,
4542 bool ? isIOSOverride,
43+ FcmTokenRegistrar ? fcmTokenRegistrar,
44+ NotificationTapRouter ? notificationTapRouter,
4645 Stream <RemoteMessage >? onMessage,
4746 Stream <RemoteMessage >? onMessageOpenedApp,
4847 }) : _messaging = messaging ?? FirebaseMessaging .instance,
4948 _localNotifications =
5049 localNotifications ?? FlutterLocalNotificationsPlugin (),
5150 _localeProvider = localeProvider,
5251 _isIOSOverride = isIOSOverride,
52+ _fcmTokenRegistrar = fcmTokenRegistrar ?? const NoopFcmTokenRegistrar (),
53+ _notificationTapRouter =
54+ notificationTapRouter ?? const NoopNotificationTapRouter (),
5355 _onMessage = onMessage ?? FirebaseMessaging .onMessage,
5456 _onMessageOpenedApp =
5557 onMessageOpenedApp ?? FirebaseMessaging .onMessageOpenedApp;
@@ -62,12 +64,17 @@ class NotificationService {
6264 bool isFlutterLocalNotificationsInitialized = false ,
6365 bool isTimezoneInitialized = false ,
6466 bool ? isIOSOverride,
67+ FcmTokenRegistrar ? fcmTokenRegistrar,
68+ NotificationTapRouter ? notificationTapRouter,
6569 Stream <RemoteMessage >? onMessage,
6670 Stream <RemoteMessage >? onMessageOpenedApp,
6771 }) : _messaging = messaging,
6872 _localNotifications = localNotifications,
6973 _localeProvider = localeProvider,
7074 _isIOSOverride = isIOSOverride,
75+ _fcmTokenRegistrar = fcmTokenRegistrar ?? const NoopFcmTokenRegistrar (),
76+ _notificationTapRouter =
77+ notificationTapRouter ?? const NoopNotificationTapRouter (),
7178 _onMessage = onMessage ?? FirebaseMessaging .onMessage,
7279 _onMessageOpenedApp =
7380 onMessageOpenedApp ?? FirebaseMessaging .onMessageOpenedApp,
@@ -84,6 +91,8 @@ class NotificationService {
8491 final FlutterLocalNotificationsPlugin _localNotifications;
8592 final String Function ()? _localeProvider;
8693 final bool ? _isIOSOverride;
94+ FcmTokenRegistrar _fcmTokenRegistrar;
95+ NotificationTapRouter _notificationTapRouter;
8796 final Stream <RemoteMessage > _onMessage;
8897 final Stream <RemoteMessage > _onMessageOpenedApp;
8998 bool _isFlutterLocalNotificationsInitialized = false ;
@@ -110,6 +119,14 @@ class NotificationService {
110119 }
111120 }
112121
122+ void configureDelegates ({
123+ required FcmTokenRegistrar fcmTokenRegistrar,
124+ required NotificationTapRouter notificationTapRouter,
125+ }) {
126+ _fcmTokenRegistrar = fcmTokenRegistrar;
127+ _notificationTapRouter = notificationTapRouter;
128+ }
129+
113130 Future <void > initialize () {
114131 if (_isInitialized) {
115132 return Future .value ();
@@ -255,13 +272,7 @@ class NotificationService {
255272
256273 if (token != null ) {
257274 try {
258- final deviceId = await getIt.get <AlarmRepository >().getDeviceId ();
259- await getIt.get <NotificationRemoteDataSource >().fcmTokenRegister (
260- FcmTokenRegisterRequestModel (
261- firebaseToken: token,
262- deviceId: deviceId,
263- ),
264- );
275+ await _fcmTokenRegistrar.registerToken (token);
265276 AppLogger .debug ('[FCM] FCM Token 서버 등록 완료' );
266277 } catch (e) {
267278 AppLogger .debug ('[FCM] FCM Token 서버 등록 실패: $e ' );
@@ -274,12 +285,9 @@ class NotificationService {
274285 AppLogger .debug (
275286 '[FCM] token refreshed token=${AppLogger .redactToken (newToken )}' ,
276287 );
277- getIt.get <AlarmRepository >().getDeviceId ().then ((deviceId) {
278- getIt.get <NotificationRemoteDataSource >().fcmTokenRegister (
279- FcmTokenRegisterRequestModel (
280- firebaseToken: newToken,
281- deviceId: deviceId,
282- ),
288+ _fcmTokenRegistrar.registerToken (newToken).catchError ((e) {
289+ AppLogger .debug (
290+ '[FCM] refreshed token server registration failed: $e ' ,
283291 );
284292 });
285293 });
@@ -679,18 +687,11 @@ class NotificationService {
679687
680688 void _handleLocalNotificationTap (String ? payload) {
681689 AppLogger .debug ('[FCM] 알림 탭' );
682- final target = notificationRouteForPayloadString (payload);
683- if (target != null ) {
684- getIt.get <NavigationService >().push (target.path, extra: target.extra);
685- }
690+ _notificationTapRouter.routeLocalNotificationTap (payload);
686691 }
687692
688693 Future <void > _handleBackgroundMessage (RemoteMessage message) async {
689694 AppLogger .debug ('[FCM] 백그라운드 메시지 처리' );
690-
691- final target = notificationRouteForData (message.data);
692- if (target != null ) {
693- getIt.get <NavigationService >().push (target.path, extra: target.extra);
694- }
695+ _notificationTapRouter.routeRemoteNotificationData (message.data);
695696 }
696697}
0 commit comments