Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(badge): Update realm before updating the badge #1923

Merged
merged 2 commits into from
Jan 8, 2025
Merged

Conversation

SystemKeeper
Copy link
Collaborator

How to reproduce:

  • Write 2 messages and see that your badge is increased by 2
  • Read the messages on web, to mark them as unread
  • Notice that (sometimes) the badge is not decreased by 2 again, but sometimes only by 1 or not at all

After we removed the notifications, we also update the badgenumber:

[_notificationCenter getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) {
for (UNNotification *notification in notifications) {
if (expired) {
dispatch_group_leave(notificationsGroup);
return;
}
removeNotification(notification.request, NO);
}
[self updateAppIconBadgeNumber];
dispatch_group_leave(notificationsGroup);
}];

Since this is wrapped in a dispatch, it is possible that realm was not yet fully updated on the other thread:

dispatch_async(dispatch_get_main_queue(), ^{
[UIApplication sharedApplication].applicationIconBadgeNumber = [[NCDatabaseManager sharedInstance] numberOfUnreadNotifications];
});

Resulting in a wrong badge count.

@SystemKeeper SystemKeeper requested a review from Ivansss December 23, 2024 15:33
@Ivansss Ivansss merged commit 80ea031 into master Jan 8, 2025
11 checks passed
@Ivansss Ivansss deleted the fix-badge-count branch January 8, 2025 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants