Skip to content

Commit

Permalink
notif [nfc]: Make shorter local alias for ZulipBinding.instance.andro…
Browse files Browse the repository at this point in the history
…idNotificationHost

This is quite a mouthful and we repeat it a lot in this file.
A nice short local name also helps things fit more easily on a line.
  • Loading branch information
gnprice committed Aug 20, 2024
1 parent bfba284 commit b9addf2
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/notifications/display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import '../widgets/page.dart';
import '../widgets/store.dart';
import '../widgets/theme.dart';

AndroidNotificationHostApi get _androidHost => ZulipBinding.instance.androidNotificationHost;

/// Service for configuring our Android "notification channel".
class NotificationChannelManager {
@visibleForTesting
Expand Down Expand Up @@ -54,7 +56,7 @@ class NotificationChannelManager {
// channel ID and delete it. See zulip-mobile's `createNotificationChannel`
// in android/app/src/main/java/com/zulipmobile/notifications/NotificationChannelManager.kt .
static Future<void> _ensureChannel() async {
await ZulipBinding.instance.androidNotificationHost.createNotificationChannel(NotificationChannel(
await _androidHost.createNotificationChannel(NotificationChannel(
id: kChannelId,
name: 'Messages', // TODO(i18n)
importance: NotificationImportance.high,
Expand Down Expand Up @@ -95,7 +97,7 @@ class NotificationDisplayManager {
final groupKey = _groupKey(data);
final conversationKey = _conversationKey(data, groupKey);

final oldMessagingStyle = await ZulipBinding.instance.androidNotificationHost
final oldMessagingStyle = await _androidHost
.getActiveNotificationMessagingStyleByTag(conversationKey);

final MessagingStyle messagingStyle;
Expand Down Expand Up @@ -141,7 +143,7 @@ class NotificationDisplayManager {
name: data.senderFullName,
iconBitmap: await _fetchBitmap(data.senderAvatarUrl))));

await ZulipBinding.instance.androidNotificationHost.notify(
await _androidHost.notify(
// TODO the notification ID can be constant, instead of matching requestCode
// (This is a legacy of `flutter_local_notifications`.)
id: notificationIdAsHashOf(conversationKey),
Expand Down Expand Up @@ -184,7 +186,7 @@ class NotificationDisplayManager {
autoCancel: true,
);

await ZulipBinding.instance.androidNotificationHost.notify(
await _androidHost.notify(
id: notificationIdAsHashOf(groupKey),
tag: groupKey,
channelId: NotificationChannelManager.kChannelId,
Expand All @@ -210,9 +212,8 @@ class NotificationDisplayManager {
assert(debugLog('notif remove zulipMessageIds: ${data.zulipMessageIds}'));

final groupKey = _groupKey(data);
final activeNotifications =
await ZulipBinding.instance.androidNotificationHost.getActiveNotifications(
desiredExtras: [kExtraZulipMessageId]);
final activeNotifications = await _androidHost.getActiveNotifications(
desiredExtras: [kExtraZulipMessageId]);

var haveRemaining = false;
for (final statusBarNotification in activeNotifications) {
Expand All @@ -237,8 +238,8 @@ class NotificationDisplayManager {
if (data.zulipMessageIds.contains(lastMessageId)) {
// The latest Zulip message in this conversation was read.
// That's our cue to cancel the notification for the conversation.
await ZulipBinding.instance.androidNotificationHost
.cancel(tag: statusBarNotification.tag, id: statusBarNotification.id);
await _androidHost.cancel(
tag: statusBarNotification.tag, id: statusBarNotification.id);
assert(debugLog(' … notif cancelled.'));
} else {
// This notification is for another conversation that's still unread.
Expand All @@ -254,8 +255,8 @@ class NotificationDisplayManager {
// Even though we enable the `autoCancel` flag for summary notification
// during creation, the summary notification doesn't get auto canceled if
// child notifications are canceled programatically as done above.
await ZulipBinding.instance.androidNotificationHost
.cancel(tag: groupKey, id: notificationIdAsHashOf(groupKey));
await _androidHost.cancel(
tag: groupKey, id: notificationIdAsHashOf(groupKey));
}
}

Expand Down

0 comments on commit b9addf2

Please sign in to comment.