Skip to content

Commit b88bb4d

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 1aeee3e commit b88bb4d

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);
@@ -471,6 +473,8 @@ class NotificationDisplayManager {
471473
required BuildContext context,
472474
required Uri url,
473475
}) {
476+
assert(defaultTargetPlatform == TargetPlatform.android);
477+
474478
final globalStore = GlobalStoreWidget.of(context);
475479

476480
assert(debugLog('got notif: url: $url'));
@@ -499,6 +503,7 @@ class NotificationDisplayManager {
499503
/// generated with [NotificationOpenPayload.buildUrl] while creating
500504
/// the notification.
501505
static Future<void> navigateForNotification(Uri url) async {
506+
assert(defaultTargetPlatform == TargetPlatform.android);
502507
assert(debugLog('opened notif: url: $url'));
503508

504509
NavigatorState navigator = await ZulipApp.navigator;
@@ -527,6 +532,8 @@ class NotificationDisplayManager {
527532
}
528533

529534
static Future<void> removeNotificationsForAccount(Uri realmUri, int userId) async {
535+
assert(defaultTargetPlatform == TargetPlatform.android);
536+
530537
final groupKey = _groupKey(realmUri, userId);
531538
final activeNotifications = await _androidHost.getActiveNotifications(desiredExtras: [kExtraLastZulipMessageId]);
532539
for (final statusBarNotification in activeNotifications) {

0 commit comments

Comments
 (0)