From f0a4bd5c27016faf895bf06fc5d39a95c3e674d8 Mon Sep 17 00:00:00 2001 From: Thilo Molitor Date: Sun, 24 Mar 2024 20:43:41 +0100 Subject: [PATCH] Don't delay unread badge update by async dispatch --- Monal/Classes/MLNotificationManager.m | 5 +++-- Monal/Classes/MonalAppDelegate.m | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Monal/Classes/MLNotificationManager.m b/Monal/Classes/MLNotificationManager.m index 2e3dbab28f..ab0cd16fb4 100644 --- a/Monal/Classes/MLNotificationManager.m +++ b/Monal/Classes/MLNotificationManager.m @@ -252,8 +252,6 @@ -(void) handleDisplayedMessages:(NSNotification*) notification [center removePendingNotificationRequestsWithIdentifiers:@[idval]]; [center removeDeliveredNotificationsWithIdentifiers:@[idval]]; } - //update app badge - [[MLNotificationQueue currentQueue] postNotificationName:kMonalUpdateUnread object:nil]; }; //do this in its own thread because we don't want to block the main thread or other threads here (the removal can take ~50ms) @@ -263,6 +261,9 @@ -(void) handleDisplayedMessages:(NSNotification*) notification else dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), block); + //update app badge + [[MLNotificationQueue currentQueue] postNotificationName:kMonalUpdateUnread object:nil]; + } -(void) handleDeletedMessage:(NSNotification*) notification diff --git a/Monal/Classes/MonalAppDelegate.m b/Monal/Classes/MonalAppDelegate.m index 331c4ade3a..093b30d8f9 100644 --- a/Monal/Classes/MonalAppDelegate.m +++ b/Monal/Classes/MonalAppDelegate.m @@ -348,15 +348,16 @@ -(void) application:(UIApplication*) application didFailToRegisterForRemoteNotif -(void) updateUnread { + DDLogInfo(@"Updating unread called"); //make sure unread badge matches application badge NSNumber* unreadMsgCnt = [[DataLayer sharedInstance] countUnreadMessages]; - dispatch_async(dispatch_get_main_queue(), ^{ + [HelperTools dispatchAsync:NO reentrantOnQueue:dispatch_get_main_queue() withBlock:^{ NSInteger unread = 0; if(unreadMsgCnt != nil) unread = [unreadMsgCnt integerValue]; DDLogInfo(@"Updating unread badge to: %ld", (long)unread); [UIApplication sharedApplication].applicationIconBadgeNumber = unread; - }); + }]; } #pragma mark - app life cycle