Skip to content

Commit

Permalink
notif [nfc]: Clarify meaning of last-message-ID extra
Browse files Browse the repository at this point in the history
Each notification can be showing several Zulip messages.  This extra
carries the message ID of specifically the latest one.
  • Loading branch information
gnprice committed Aug 20, 2024
1 parent f2c8e40 commit aa5c31d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions lib/notifications/display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class NotificationDisplayManager {
number: messagingStyle.messages.length,
extras: {
// Used to decide when a `RemoveFcmMessage` event should clear this notification.
kExtraZulipMessageId: data.zulipMessageId.toString(),
kExtraLastZulipMessageId: data.zulipMessageId.toString(),
},

contentIntent: PendingIntent(
Expand Down Expand Up @@ -227,7 +227,7 @@ class NotificationDisplayManager {
// https://github.com/zulip/zulip-mobile/pull/4842#pullrequestreview-725817909
var haveRemaining = false;
final activeNotifications = await _androidHost.getActiveNotifications(
desiredExtras: [kExtraZulipMessageId]);
desiredExtras: [kExtraLastZulipMessageId]);
for (final statusBarNotification in activeNotifications) {
if (statusBarNotification == null) continue; // TODO(pigeon) eliminate this case

Expand All @@ -248,7 +248,7 @@ class NotificationDisplayManager {
// Don't act on the summary notification for the group.
if (statusBarNotification.tag == groupKey) continue;

final lastMessageIdStr = notification.extras[kExtraZulipMessageId];
final lastMessageIdStr = notification.extras[kExtraLastZulipMessageId];
assert(lastMessageIdStr != null);
if (lastMessageIdStr == null) continue; // TODO(log)
final lastMessageId = int.parse(lastMessageIdStr, radix: 10);
Expand Down Expand Up @@ -277,13 +277,13 @@ class NotificationDisplayManager {
}
}

/// The key for the message-id entry in [Notification.extras] metadata.
/// A key we use in [Notification.extras] for the [Message.id] of the
/// latest Zulip message in the notification's conversation.
///
/// Currently, it is used to store the message-id in the respective
/// notification which is later fetched to determine if a [RemoveFcmMessage]
/// event should clear that specific notification.
/// We use this to determine if a [RemoveFcmMessage] event should
/// clear that specific notification.
@visibleForTesting
static const kExtraZulipMessageId = 'zulipMessageId';
static const kExtraLastZulipMessageId = 'lastZulipMessageId';

/// A notification ID, derived as a hash of the given string key.
///
Expand Down
4 changes: 2 additions & 2 deletions test/notifications/display_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void main() {
..smallIconResourceName.equals('zulip_notification')
..extras.which((it) => it.isNotNull()
..deepEquals(<String, String>{
NotificationDisplayManager.kExtraZulipMessageId: data.zulipMessageId.toString(),
NotificationDisplayManager.kExtraLastZulipMessageId: data.zulipMessageId.toString(),
}))
..groupKey.equals(expectedGroupKey)
..isGroupSummary.isNull()
Expand Down Expand Up @@ -258,7 +258,7 @@ void main() {
..notification.which((it) => it
..group.equals(expectedGroupKey)
..extras.deepEquals(<String, String>{
NotificationDisplayManager.kExtraZulipMessageId: data.zulipMessageId.toString(),
NotificationDisplayManager.kExtraLastZulipMessageId: data.zulipMessageId.toString(),
}))
..tag.equals(expectedTag);
}
Expand Down

0 comments on commit aa5c31d

Please sign in to comment.