Skip to content

Commit 22bec90

Browse files
committed
refactor: inject onMissedCall callback into PushNotificationIsolateManager
Replace localPushRepository, missedCallTitle, and unknownCallerFallback constructor params with a single Future<void> Function(String, String?) callback so the manager does not depend on push_notifications internals.
1 parent ef1c2b4 commit 22bec90

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

lib/features/call/services/background_isolate_callbacks.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:webtrit_signaling_service/webtrit_signaling_service.dart';
77
import 'package:webtrit_phone/common/common.dart';
88
import 'package:webtrit_phone/l10n/app_localizations.g.dart';
99
import 'package:webtrit_phone/models/models.dart';
10+
import 'package:webtrit_phone/push_notification/push_notifications.dart';
1011

1112
import 'isolate_manager.dart';
1213

@@ -50,15 +51,20 @@ Future<PushNotificationIsolateManager> _getOrInit(PushIsolateContext context) as
5051
_logger.info('_getOrInit: module factory and handoff callback registered');
5152

5253
final l10n = lookupAppLocalizations(context.locale);
54+
final localPushRepository = context.localPushRepository;
5355
_manager = PushNotificationIsolateManager(
5456
callLogsRepository: context.callLogsRepository,
55-
localPushRepository: context.localPushRepository,
5657
callkeep: BackgroundPushNotificationService(),
5758
storage: context.secureStorage,
5859
certificates: context.appCertificates.trustedCertificates,
5960
logger: Logger('PushNotificationIsolateManager'),
60-
missedCallTitle: l10n.notifications_missedCall_title,
61-
unknownCallerFallback: l10n.notifications_missedCall_unknownCaller,
61+
onMissedCall: (callId, callerName) => localPushRepository.displayPush(
62+
AppLocalPush.missedCall(
63+
callId,
64+
l10n.notifications_missedCall_title,
65+
callerName ?? l10n.notifications_missedCall_unknownCaller,
66+
),
67+
),
6268
);
6369
// init() constructs WebtritSignalingService and wires up the event subscription.
6470
// The WebSocket connection starts in connect(), which is called from run().

lib/features/call/services/isolate_manager.dart

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import 'package:webtrit_signaling_service/webtrit_signaling_service.dart';
1111
import 'package:webtrit_phone/data/data.dart';
1212
import 'package:webtrit_phone/models/models.dart';
1313
import 'package:webtrit_phone/repositories/repositories.dart';
14-
import 'package:webtrit_phone/push_notification/push_notifications.dart';
1514

1615
import '../models/jsep_value.dart';
1716

@@ -30,24 +29,21 @@ class PushNotificationIsolateManager implements CallkeepBackgroundServiceDelegat
3029
required this.storage,
3130
required this.certificates,
3231
required this.logger,
33-
required this.localPushRepository,
34-
required this.missedCallTitle,
35-
required this.unknownCallerFallback,
32+
required Future<void> Function(String callId, String? callerName) onMissedCall,
3633
this.callLogsRepository,
37-
}) : _pushService = callkeep {
34+
}) : _onMissedCall = onMissedCall,
35+
_pushService = callkeep {
3836
// setBackgroundServiceDelegate is called in the constructor so callkeep can
3937
// route performAnswerCall / performEndCall as soon as the object exists,
4038
// before [init] is called.
4139
_pushService.setBackgroundServiceDelegate(this);
4240
}
4341

4442
final Logger logger;
45-
final LocalPushRepository localPushRepository;
4643
final CallLogsRepository? callLogsRepository;
4744
final SecureStorage storage;
4845
final TrustedCertificates certificates;
49-
final String missedCallTitle;
50-
final String unknownCallerFallback;
46+
final Future<void> Function(String callId, String? callerName) _onMissedCall;
5147

5248
final BackgroundPushNotificationService _pushService;
5349

@@ -499,13 +495,7 @@ class PushNotificationIsolateManager implements CallkeepBackgroundServiceDelegat
499495

500496
Future<void> _showMissedCallNotification(HangupEvent event, NewCall call) async {
501497
try {
502-
await localPushRepository.displayPush(
503-
AppLocalPush.missedCall(
504-
event.callId,
505-
missedCallTitle,
506-
_getDisplayNameForMissedCall(event, call) ?? unknownCallerFallback,
507-
),
508-
);
498+
await _onMissedCall(event.callId, _getDisplayNameForMissedCall(event, call));
509499
} catch (e) {
510500
logger.severe('Failed to show missed call notification', e);
511501
}

0 commit comments

Comments
 (0)