Skip to content

Commit 2b0f248

Browse files
committed
notif [nfc]: Add Android-only asserts in NotificationDisplayManager methods
NotificationDisplayManager's public methods only get invoked on Android, and their implementations basically assume the platform is Android. So, add these asserts, to make that assumption clearer and to fail early if we accidentally call one of these on iOS. When we eventually take more hands-on control of notifications on iOS, we might either adapt this class to support iOS too, or make a new class for iOS and make this one's name and interface clearer that it's Android-only. Discussion: https://chat.zulip.org/#narrow/channel/243-mobile-team/topic/NotificationDisplayManager.20Android-only/near/2099196
1 parent 33896a0 commit 2b0f248

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/notifications/display.dart

+7
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,12 @@ class NotificationChannelManager {
217217
/// Service for managing the notifications shown to the user.
218218
class NotificationDisplayManager {
219219
static Future<void> init() async {
220+
assert(defaultTargetPlatform == TargetPlatform.android);
220221
await NotificationChannelManager.ensureChannel();
221222
}
222223

223224
static void onFcmMessage(FcmMessage data, Map<String, dynamic> dataJson) {
225+
assert(defaultTargetPlatform == TargetPlatform.android);
224226
switch (data) {
225227
case MessageFcmMessage(): _onMessageFcmMessage(data, dataJson);
226228
case RemoveFcmMessage(): _onRemoveFcmMessage(data);
@@ -434,6 +436,8 @@ class NotificationDisplayManager {
434436
}
435437

436438
static Future<void> removeNotificationsForAccount(Uri realmUrl, int userId) async {
439+
assert(defaultTargetPlatform == TargetPlatform.android);
440+
437441
final groupKey = _groupKey(realmUrl, userId);
438442
final activeNotifications = await _androidHost.getActiveNotifications(
439443
desiredExtras: []);
@@ -488,6 +492,8 @@ class NotificationDisplayManager {
488492
required BuildContext context,
489493
required Uri url,
490494
}) {
495+
assert(defaultTargetPlatform == TargetPlatform.android);
496+
491497
final globalStore = GlobalStoreWidget.of(context);
492498

493499
assert(debugLog('got notif: url: $url'));
@@ -516,6 +522,7 @@ class NotificationDisplayManager {
516522
/// generated with [NotificationOpenPayload.buildUrl] while creating
517523
/// the notification.
518524
static Future<void> navigateForNotification(Uri url) async {
525+
assert(defaultTargetPlatform == TargetPlatform.android);
519526
assert(debugLog('opened notif: url: $url'));
520527

521528
NavigatorState navigator = await ZulipApp.navigator;

0 commit comments

Comments
 (0)