Page MenuHomePhabricator

Remove relevant notification from notifications center when receiving rescind in NSE
ClosedPublic

Authored by marcin on Mar 1 2023, 3:56 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Apr 12, 3:39 AM
Unknown Object (File)
Fri, Apr 12, 3:39 AM
Unknown Object (File)
Fri, Apr 12, 3:39 AM
Unknown Object (File)
Fri, Apr 12, 3:39 AM
Unknown Object (File)
Fri, Apr 12, 3:39 AM
Unknown Object (File)
Fri, Apr 12, 3:38 AM
Unknown Object (File)
Fri, Apr 12, 3:35 AM
Unknown Object (File)
Feb 25 2024, 11:43 AM
Subscribers

Details

Summary

This differential implements notifications removal from NotificationCenter when receiving rescind. The API used to remove a notification from NotificationCenter is the same as we use in CommIOSNotifications native module. We additionally do a trick with semaphore and dispatch
queue to ensure we don't exit too early from NSE before asynchronous UNUserNotificationCenter API fires.

Test Plan

Remove condition codeVersion > 1000 from send.js and rescind.js in keyserver. Send some notification from one user. Then send some notifications from another user. Generate rescind for only one of those users! Ensure notifications for this one user a removed while for
the other stay in notification center.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

marcin requested review of this revision.Mar 1 2023, 4:11 AM
native/ios/NotificationService/NotificationService.mm
79 ↗(On Diff #23338)

Shouldn't we only call postRemovalCallback within this if condition? I don't understand why we'd call it if we haven't removed anything

81 ↗(On Diff #23338)

What's confusing to me is that it appears postRemovalCallback can be called multiple times.

If it gets called multiple times, won't the semaphore wait be concluded on the first time, and then the subsequent times might be missed?

If it's meant to only be called once, then I think it would be good to add a return or something here, to make it more clear to the reader than it's only called once.

native/ios/NotificationService/NotificationService.mm
81 ↗(On Diff #23338)

I don't understand why we'd call it if we haven't removed anything

I think the naming is bad for this lambda.

Shouldn't we only call postRemovalCallback within this if condition?

This lambda increments zero-valued semaphore that NSE callback is waiting on. If we never execute code inside if statement we might be stuck waiting for the semaphore to be incremented until time-expiration callback fires.
I can imagine a case when user manually removes notification from notification center after rescind arrives but before it starts being processed by NSE. I wanted to avoid it by placing it outside of a conditional.

What's confusing to me is that it appears postRemovalCallback can be called multiple times.

This is my programming mistake. This callback should be fired after for loop scope. This way we call it once and only once.

So the plan is:

  1. Change the name of this variable (or just place its code in appropriate place since it is lambda - I extracted this code to lambda for readability.)
  2. Call it just after the for loop.

Got it, thanks for explaining!

Post semaphore once and only once. Give lambda a better name

Don't have a ton of context here.

This revision is now accepted and ready to land.Mar 6 2023, 4:55 PM

The semaphore dispatch trick looks good.