mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-24 18:59:36 +00:00
Fix the app badge not resetting when the unread count is unchanged
The notification extension increments the app badge for every notification it delivers, without the app knowing about it. The app used to correct this drift by setting the badge from the room list on every update, but since #6337 the NotificationService only publishes the badge count when it changes. Publish the badge count on every room list update again so the NotificationManager always resets the app badge.
This commit is contained in:
@@ -546,6 +546,7 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
|
||||
|
||||
private func setupUnreadNotificationsObserver() {
|
||||
userSession.notificationService.badgeCountPublisher
|
||||
.removeDuplicates()
|
||||
.weakAssign(to: \.badgeCount, on: chatsTabDetails)
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
@@ -95,7 +95,8 @@ final class NotificationService: NotificationServiceProtocol {
|
||||
for await roomSummaries in roomListPublisher.values {
|
||||
guard let self else { return }
|
||||
|
||||
updateBadgeCount(Int(clientProxy.totalUnreadNotifications))
|
||||
// Sent even when unchanged as the extension may have moved the app badge since.
|
||||
badgeCountSubject.send(Int(clientProxy.totalUnreadNotifications))
|
||||
removeDeliveredNotificationsForFullyReadRooms(roomSummaries)
|
||||
}
|
||||
}
|
||||
@@ -120,11 +121,6 @@ final class NotificationService: NotificationServiceProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
private func updateBadgeCount(_ badgeCount: Int) {
|
||||
guard badgeCount != badgeCountSubject.value else { return }
|
||||
badgeCountSubject.send(badgeCount)
|
||||
}
|
||||
|
||||
/// Sets the pusher when enabled and deletes it otherwise. Nothing to update until the device token is known.
|
||||
private func updatePusher(isEnabled: Bool) async {
|
||||
guard let deviceToken else { return }
|
||||
|
||||
@@ -165,6 +165,21 @@ final class NotificationServiceTests {
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
|
||||
@Test
|
||||
func roomListChangesRepublishAnUnchangedBadgeCount() async throws {
|
||||
let roomListSubject = CurrentValueSubject<[RoomSummary], Never>([])
|
||||
let roomSummaryProvider = RoomSummaryProviderMock(.init())
|
||||
roomSummaryProvider.roomListPublisher = roomListSubject.asCurrentValuePublisher()
|
||||
clientProxy.staticRoomSummaryProvider = roomSummaryProvider
|
||||
clientProxy.totalUnreadNotifications = 3
|
||||
let service = makeService()
|
||||
|
||||
// The extension bumps the app badge without the app knowing, so it needs resetting even when the count is the same.
|
||||
let deferred = deferFulfillment(service.badgeCountPublisher.dropFirst()) { $0 == 3 }
|
||||
roomListSubject.send([])
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
|
||||
// MARK: - Delivered notifications
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user