Remove rows from 'notifications' table when clearing notifications

This commit is contained in:
cketti 2022-02-10 01:49:53 +01:00
parent c61b097f8b
commit 4d0bbd1e8a

View file

@ -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<MessageReference>) -> List<MessageReference>
): 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<NotificationStoreOperation>) {
private fun persistNotificationDataStoreChanges(
account: Account,
operations: List<NotificationStoreOperation>,
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<NotificationStoreOperation>) {