On Android, when a remove push payload arrives, NotificationDisplayManager._onNotifPayloadRemove cancels an entire conversation notification if the payload's message IDs include that notification's latest message, and otherwise does nothing. When we built this for #341, we chose to mirror the legacy zulip-mobile implementation.
However, the server sends a remove payload any time a message stops warranting a notification via do_clear_mobile_push_notifications_for_ids which covers more than just messages being read: it also fires on message deletion, and on edits that remove a mention which had triggered the notification.
Desired behavior
For each message ID in the payload, remove just those messages from the conversations' notifications, cancel a conversation's notification when no messages are left in it, and cancel the group summary when no conversation notifications are left.
Implementation notes
#2380 does some of the groundwork. It records each Zulip message's ID in the extras of its MessagingStyle message, and has getActiveNotifications return each notification's messaging style. So the remove path can see which Zulip messages a notification is showing, and filter them.
Since Android's MessagingStyle offers no way to remove an individual message, applying that filter requires re-posting the conversation's notification, and this repost should not re-alert, otherwise it'll trigger the notification sound and vibration again. With this change, kExtraLastMessageId in the notification's extras becomes unused and can be removed.
CZO Discussion: #mobile > Deleting messages breaks notifications on Android
On Android, when a
removepush payload arrives,NotificationDisplayManager._onNotifPayloadRemovecancels an entire conversation notification if the payload's message IDs include that notification's latest message, and otherwise does nothing. When we built this for #341, we chose to mirror the legacy zulip-mobile implementation.However, the server sends a remove payload any time a message stops warranting a notification via
do_clear_mobile_push_notifications_for_idswhich covers more than just messages being read: it also fires on message deletion, and on edits that remove a mention which had triggered the notification.Desired behavior
For each message ID in the payload, remove just those messages from the conversations' notifications, cancel a conversation's notification when no messages are left in it, and cancel the group summary when no conversation notifications are left.
Implementation notes
#2380 does some of the groundwork. It records each Zulip message's ID in the extras of its
MessagingStylemessage, and hasgetActiveNotificationsreturn each notification's messaging style. So the remove path can see which Zulip messages a notification is showing, and filter them.Since Android's
MessagingStyleoffers no way to remove an individual message, applying that filter requires re-posting the conversation's notification, and this repost should not re-alert, otherwise it'll trigger the notification sound and vibration again. With this change,kExtraLastMessageIdin the notification's extras becomes unused and can be removed.CZO Discussion: #mobile > Deleting messages breaks notifications on Android