Skip to content

Commit

Permalink
Don't delay unread badge update by async dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
tmolitor-stud-tu committed Mar 24, 2024
1 parent 9cf7c49 commit f0a4bd5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Monal/Classes/MLNotificationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Monal/Classes/MonalAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f0a4bd5

Please sign in to comment.