From 4d0bbd1e8af4cd06660f71eee5b6555a80f9f862 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 10 Feb 2022 01:49:53 +0100 Subject: [PATCH] Remove rows from 'notifications' table when clearing notifications --- .../k9/notification/NotificationRepository.kt | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/core/src/main/java/com/fsck/k9/notification/NotificationRepository.kt b/app/core/src/main/java/com/fsck/k9/notification/NotificationRepository.kt index b18f3686a..f624810c9 100644 --- a/app/core/src/main/java/com/fsck/k9/notification/NotificationRepository.kt +++ b/app/core/src/main/java/com/fsck/k9/notification/NotificationRepository.kt @@ -39,7 +39,11 @@ internal class NotificationRepository( @Synchronized fun addNotification(account: Account, content: NotificationContent, timestamp: Long): AddNotificationResult { return notificationDataStore.addNotification(account, content, timestamp).also { result -> - persistNotificationDataStoreChanges(account, result.notificationStoreOperations) + persistNotificationDataStoreChanges( + account = account, + operations = result.notificationStoreOperations, + updateNewMessageState = true + ) } } @@ -50,9 +54,11 @@ internal class NotificationRepository( selector: (List) -> List ): RemoveNotificationsResult? { return notificationDataStore.removeNotifications(account, selector)?.also { result -> - if (clearNewMessageState) { - persistNotificationDataStoreChanges(account, result.notificationStoreOperations) - } + persistNotificationDataStoreChanges( + account = account, + operations = result.notificationStoreOperations, + updateNewMessageState = clearNewMessageState + ) } } @@ -66,11 +72,17 @@ internal class NotificationRepository( } } - private fun persistNotificationDataStoreChanges(account: Account, operations: List) { + private fun persistNotificationDataStoreChanges( + account: Account, + operations: List, + updateNewMessageState: Boolean + ) { val notificationStore = notificationStoreProvider.getNotificationStore(account) notificationStore.persistNotificationChanges(operations) - setNewMessageState(account, operations) + if (updateNewMessageState) { + setNewMessageState(account, operations) + } } private fun setNewMessageState(account: Account, operations: List) {