Page MenuHomePhabricator

Construct local badge-only notif when notification doesn't have body property
ClosedPublic

Authored by marcin on Apr 18 2024, 3:51 AM.
Tags
None
Referenced Files
F3384627: D11684.diff
Thu, Nov 28, 9:58 PM
Unknown Object (File)
Mon, Nov 25, 8:45 AM
Unknown Object (File)
Mon, Nov 25, 8:37 AM
Unknown Object (File)
Mon, Nov 25, 8:35 AM
Unknown Object (File)
Fri, Nov 8, 10:35 PM
Unknown Object (File)
Fri, Nov 8, 1:40 PM
Unknown Object (File)
Fri, Nov 8, 7:14 AM
Unknown Object (File)
Fri, Nov 8, 7:14 AM
Subscribers
None

Details

Summary
Test Plan
  1. Build iOS app.
  2. Make a thread badge only.
  3. Sent notif to this thread.
  4. Ensure that badge is updated and no "ENCRYPTED" notifs are displayed.

Diff Detail

Repository
rCOMM Comm
Branch
marcin/eng-7773
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

An alternative solution to this problem is to set badgeOnly property on a notif payload. However I am of opinion that if we can solve something without putting additional data to notification payload then it should be a preferred solution. However if reviewers disagree I can proceed with this solution.

ashoat requested changes to this revision.Apr 18 2024, 5:03 AM

I think the changes are good here, but I feel like the code comments can be improved, and I'd like to review the updated code comments before this is landed

native/ios/NotificationService/NotificationService.mm
257–258

You're deleting a comment elsewhere that explains why we use a separate notif for the badge count instead of just modifying the remote notif we received. Can you add that explanation here?

563

Is this function useful anymore? I think we can get rid of it and make the check inline

566–569

This comment was extremely helpful for debugging this exact issue. Can you find a way to keep it, and in particular the part explaining that we set BODY to ENCRYPTED for internal builds, and that we need to filter the notif to avoid displaying that to the user?

645

Why would a local badge-only notif need to be created, as opposed to modifying the remote notif we receive?

This revision now requires changes to proceed.Apr 18 2024, 5:03 AM
native/ios/NotificationService/NotificationService.mm
645

Sorry for the confusion. This comment is inaccurate. For notifs that don't have body in payload (rescinds and badgeonly) we costruct new notif locally in this code but we pass it to contentHandler so it is not a local notif but a remote notif. I will delete this comment.

  1. Remove needsSilentBadgeUpdate function and replace it with inline checks.
  2. Bring back useful comment.
ashoat added inline comments.
native/ios/NotificationService/NotificationService.mm
260–264 ↗(On Diff #39271)

Can we say "the server sets" instead of "we set" here?

266–268 ↗(On Diff #39271)

Why aren't we using getBadgeOnlyContentFor here?

This revision is now accepted and ready to land.Apr 19 2024, 6:36 AM
native/ios/NotificationService/NotificationService.mm
645

I'm still confused here, to be honest. If we construct the new notif locally, how is it a remote notif and not a local notif?

native/ios/NotificationService/NotificationService.mm
645

Even though it is an object instantiated in the NSE code we pass it to contentHandler given to the NSE byt the OS so the OS treats it as a remote notif.

native/ios/NotificationService/NotificationService.mm
645

Okay, I think I was using the terms wrong. Let me ask my question again.

Why would a new remote badge-only notif need to be created, as opposed to modifying the remote notif we receive?

native/ios/NotificationService/NotificationService.mm
645

Initially badge only notif/rescind has body set to "ENCRYPTED". I recall that when I was introducing this code I tried first to modify body of received object directly and I found that:

  • setting body to empty string results in empty notif
  • setting body to nil results in bad memory access crash

However creating new notif object without touching its body property worked as desired. Signal does it too: https://github.com/signalapp/Signal-iOS/blob/main/SignalNSE/NotificationService.swift#L80-L83.

I guess that Apple initially sets this field to some flag that prevents system from displaying any visual content.

  1. Update the comment
  2. Use method to get badge only content for notif.
native/ios/NotificationService/NotificationService.mm
645

setting body to empty string results in empty notif

Isn't that what we want, though? An empty notif that only updates badge count?

native/ios/NotificationService/NotificationService.mm
645

I meant visible empty notif bubble.

native/ios/NotificationService/NotificationService.mm
645

Okay, got it. It took a lot of clarification but I think I understand now. Next time hopefully there can be less confusion if we use less ambiguous language