Merge branch 'charlesmchen/notificationsVsConcurrency'

pull/1/head
Matthew Chen 8 years ago
commit 2c46220ebf

@ -211,8 +211,7 @@
- (void)presentNotification:(UILocalNotification *)notification identifier:(NSString *)identifier - (void)presentNotification:(UILocalNotification *)notification identifier:(NSString *)identifier
{ {
AssertIsOnMainThread(); dispatch_async(dispatch_get_main_queue(), ^{
// Replace any existing notification // Replace any existing notification
// e.g. when an "Incoming Call" notification gets replaced with a "Missed Call" notification. // e.g. when an "Incoming Call" notification gets replaced with a "Missed Call" notification.
if (self.currentNotifications[identifier]) { if (self.currentNotifications[identifier]) {
@ -223,19 +222,22 @@
DDLogDebug(@"%@ presenting notification with identifier: %@", self.tag, identifier); DDLogDebug(@"%@ presenting notification with identifier: %@", self.tag, identifier);
self.currentNotifications[identifier] = notification; self.currentNotifications[identifier] = notification;
});
} }
- (void)cancelNotificationWithIdentifier:(NSString *)identifier - (void)cancelNotificationWithIdentifier:(NSString *)identifier
{ {
AssertIsOnMainThread(); dispatch_async(dispatch_get_main_queue(), ^{
UILocalNotification *notification = self.currentNotifications[identifier]; UILocalNotification *notification = self.currentNotifications[identifier];
if (!notification) { if (!notification) {
DDLogWarn(@"%@ Couldn't cancel notification because none was found with identifier: %@", self.tag, identifier); DDLogWarn(
@"%@ Couldn't cancel notification because none was found with identifier: %@", self.tag, identifier);
return; return;
} }
[self.currentNotifications removeObjectForKey:identifier]; [self.currentNotifications removeObjectForKey:identifier];
[[UIApplication sharedApplication] cancelLocalNotification:notification]; [[UIApplication sharedApplication] cancelLocalNotification:notification];
});
} }
#pragma mark - Logging #pragma mark - Logging

@ -431,8 +431,7 @@ NSString *const PushManagerUserInfoKeysCallBackSignalRecipientId = @"PushManager
- (void)presentNotification:(UILocalNotification *)notification checkForCancel:(BOOL)checkForCancel - (void)presentNotification:(UILocalNotification *)notification checkForCancel:(BOOL)checkForCancel
{ {
OWSAssert([NSThread isMainThread]); dispatch_async(dispatch_get_main_queue(), ^{
NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key]; NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key];
if (checkForCancel && threadId != nil) { if (checkForCancel && threadId != nil) {
// The longer we wait, the more obsolete notifications we can suppress - // The longer we wait, the more obsolete notifications we can suppress -
@ -444,19 +443,22 @@ NSString *const PushManagerUserInfoKeysCallBackSignalRecipientId = @"PushManager
[[UIApplication sharedApplication] scheduleLocalNotification:notification]; [[UIApplication sharedApplication] scheduleLocalNotification:notification];
[self.currentNotifications addObject:notification]; [self.currentNotifications addObject:notification];
});
} }
- (void)cancelNotificationsWithThreadId:(NSString *)threadId { - (void)cancelNotificationsWithThreadId:(NSString *)threadId
OWSAssert([NSThread isMainThread]); {
dispatch_async(dispatch_get_main_queue(), ^{
NSMutableArray *toDelete = [NSMutableArray array]; NSMutableArray *toDelete = [NSMutableArray array];
[self.currentNotifications enumerateObjectsUsingBlock:^(UILocalNotification *notif, NSUInteger idx, BOOL *stop) { [self.currentNotifications
enumerateObjectsUsingBlock:^(UILocalNotification *notif, NSUInteger idx, BOOL *stop) {
if ([notif.userInfo[Signal_Thread_UserInfo_Key] isEqualToString:threadId]) { if ([notif.userInfo[Signal_Thread_UserInfo_Key] isEqualToString:threadId]) {
[[UIApplication sharedApplication] cancelLocalNotification:notif]; [[UIApplication sharedApplication] cancelLocalNotification:notif];
[toDelete addObject:notif]; [toDelete addObject:notif];
} }
}]; }];
[self.currentNotifications removeObjectsInArray:toDelete]; [self.currentNotifications removeObjectsInArray:toDelete];
});
} }
+ (NSString *)tag + (NSString *)tag

Loading…
Cancel
Save