Skip to content

Commit

Permalink
[native] Update iOS badge for rescinds
Browse files Browse the repository at this point in the history
Summary:
This resolves [ENG-5452](https://linear.app/comm/issue/ENG-5452/ios-badge-count-is-not-getting-updated-from-rescinds-in-build-276).

@marcin and I pair-programmed this solution together.

Test Plan: I tested both rescinds, badge-only notifs, and normal notifs in my local environment on the iOS simulator. They all worked correctly

Reviewers: marcin, atul

Reviewed By: atul

Subscribers: tomek, wyilio, marcin

Differential Revision: https://phab.comm.dev/D9600
  • Loading branch information
Ashoat committed Oct 25, 2023
1 parent bbcca88 commit 0e369a8
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions native/ios/NotificationService/NotificationService.mm
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request

// Step 5: (optional) create empty notification that
// only provides badge count.
if ([self isBadgeOnly:content.userInfo]) {
if ([self needsSilentBadgeUpdate:content.userInfo]) {
UNMutableNotificationContent *badgeOnlyContent =
[[UNMutableNotificationContent alloc] init];
badgeOnlyContent.badge = content.badge;
Expand Down Expand Up @@ -309,7 +309,7 @@ - (void)serviceExtensionTimeWillExpire {
// At this point we know that the content is at least
// correctly decrypted so we can display it to the user.
// Another operation, like persistence, had failed.
if ([self isBadgeOnly:content.userInfo]) {
if ([self needsSilentBadgeUpdate:content.userInfo]) {
UNNotificationContent *badgeOnlyContent =
[self getBadgeOnlyContentFor:content];
handler(badgeOnlyContent);
Expand Down Expand Up @@ -431,10 +431,19 @@ - (BOOL)isRescind:(NSDictionary *)payload {
[payload[backgroundNotificationTypeKey] isEqualToString:@"CLEAR"];
}

- (BOOL)isBadgeOnly:(NSDictionary *)payload {
- (BOOL)needsSilentBadgeUpdate:(NSDictionary *)payload {
// TODO: refactor this check by introducing
// badgeOnly property in iOS notification payload
return !payload[@"threadID"];
if (!payload[@"threadID"]) {
// This notif only contains a badge update. We could let it go through
// normally, but for internal builds we set the BODY to "ENCRYPTED" for
// debugging purposes. So instead of letting the badge-only notif go
// through, we construct another notif that doesn't have a body.
return true;
}
// If the notif is a rescind, then we'll filter it out. So we need another
// notif to update the badge count.
return [self isRescind:payload];
}

- (BOOL)isCollapsible:(NSDictionary *)payload {
Expand Down

0 comments on commit 0e369a8

Please sign in to comment.