Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32878460
D6919.1768150828.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D6919.1768150828.diff
View Options
diff --git a/native/ios/NotificationService/NotificationService.mm b/native/ios/NotificationService/NotificationService.mm
--- a/native/ios/NotificationService/NotificationService.mm
+++ b/native/ios/NotificationService/NotificationService.mm
@@ -3,6 +3,9 @@
#import "TemporaryMessageStorage.h"
NSString *const backgroundNotificationTypeKey = @"backgroundNotifType";
+// The context for this constant can be found here:
+// https://linear.app/comm/issue/ENG-3074#comment-bd2f5e28
+int64_t const notificationRemovalDelay = (int64_t)(0.1 * NSEC_PER_SEC);
@interface NotificationService ()
@@ -22,6 +25,8 @@
self.bestAttemptContent = [request.content mutableCopy];
if ([self isRescind:self.bestAttemptContent.userInfo]) {
+ [self removeNotificationWithIdentifier:self.bestAttemptContent
+ .userInfo[@"notificationId"]];
self.contentHandler([[UNNotificationContent alloc] init]);
return;
}
@@ -52,6 +57,34 @@
self.contentHandler(self.bestAttemptContent);
}
+- (void)removeNotificationWithIdentifier:(NSString *)identifier {
+ dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
+
+ void (^delayedSemaphorePostCallback)() = ^() {
+ dispatch_time_t timeToPostSemaphore =
+ dispatch_time(DISPATCH_TIME_NOW, notificationRemovalDelay);
+ dispatch_after(timeToPostSemaphore, dispatch_get_main_queue(), ^{
+ dispatch_semaphore_signal(semaphore);
+ });
+ };
+
+ [UNUserNotificationCenter.currentNotificationCenter
+ getDeliveredNotificationsWithCompletionHandler:^(
+ NSArray<UNNotification *> *_Nonnull notifications) {
+ for (UNNotification *notif in notifications) {
+ if ([identifier isEqual:notif.request.content.userInfo[@"id"]]) {
+ [UNUserNotificationCenter.currentNotificationCenter
+ removeDeliveredNotificationsWithIdentifiers:@[
+ notif.request.identifier
+ ]];
+ }
+ }
+ delayedSemaphorePostCallback();
+ }];
+
+ dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
+}
+
- (BOOL)isRescind:(NSDictionary *)payload {
return payload[backgroundNotificationTypeKey] &&
[payload[backgroundNotificationTypeKey] isEqualToString:@"CLEAR"];
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Jan 11, 5:00 PM (11 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5919687
Default Alt Text
D6919.1768150828.diff (2 KB)
Attached To
Mode
D6919: Remove relevant notification from notifications center when receiving rescind in NSE
Attached
Detach File
Event Timeline
Log In to Comment