diff --git a/app/src/main/java/io/heckel/ntfy/db/Database.kt b/app/src/main/java/io/heckel/ntfy/db/Database.kt index f42a882e..6313bce4 100644 --- a/app/src/main/java/io/heckel/ntfy/db/Database.kt +++ b/app/src/main/java/io/heckel/ntfy/db/Database.kt @@ -484,9 +484,6 @@ interface NotificationDao { @Query("UPDATE notification SET deleted = 1 WHERE subscriptionId = :subscriptionId AND sequence_id = :sequenceId") fun markAsDeletedBySequenceId(subscriptionId: Long, sequenceId: String) - @Query("DELETE FROM notification WHERE subscriptionId = :subscriptionId AND sequence_id = :sequenceId") - fun deleteBySequenceId(subscriptionId: Long, sequenceId: String) - @Query("UPDATE notification SET deleted = 1 WHERE subscriptionId = :subscriptionId") fun markAllAsDeleted(subscriptionId: Long) diff --git a/app/src/main/java/io/heckel/ntfy/db/Repository.kt b/app/src/main/java/io/heckel/ntfy/db/Repository.kt index 7e958242..2c158fb1 100644 --- a/app/src/main/java/io/heckel/ntfy/db/Repository.kt +++ b/app/src/main/java/io/heckel/ntfy/db/Repository.kt @@ -129,9 +129,9 @@ class Repository(private val sharedPrefs: SharedPreferences, database: Database) if (maybeExistingNotification != null) { return false } - // Delete old notifications with the same sequence ID (this is an update to an existing sequence) + // Mark old notifications with the same sequence ID as deleted (this is an update to an existing sequence) if (notification.sequenceId.isNotEmpty()) { - notificationDao.deleteBySequenceId(notification.subscriptionId, notification.sequenceId) + notificationDao.markAsDeletedBySequenceId(notification.subscriptionId, notification.sequenceId) } // If this is a delete notification, don't add it to the database if (notification.deleted) { @@ -154,8 +154,8 @@ class Repository(private val sharedPrefs: SharedPreferences, database: Database) notificationDao.markAsDeleted(notificationId) } - fun deleteBySequenceId(subscriptionId: Long, sequenceId: String) { - notificationDao.deleteBySequenceId(subscriptionId, sequenceId) + fun markAsDeletedBySequenceId(subscriptionId: Long, sequenceId: String) { + notificationDao.markAsDeletedBySequenceId(subscriptionId, sequenceId) } fun markAllAsDeleted(subscriptionId: Long) { diff --git a/app/src/main/java/io/heckel/ntfy/msg/Poller.kt b/app/src/main/java/io/heckel/ntfy/msg/Poller.kt index c92a6e6b..102b685c 100644 --- a/app/src/main/java/io/heckel/ntfy/msg/Poller.kt +++ b/app/src/main/java/io/heckel/ntfy/msg/Poller.kt @@ -62,7 +62,7 @@ class Poller( latestBySequenceId.filter { it.deleted }.forEach { notification -> val sequenceId = notification.sequenceId.ifEmpty { notification.id } Log.d(TAG, "Deleting notifications with sequenceId $sequenceId") - repository.deleteBySequenceId(subscriptionId, sequenceId) + repository.markAsDeletedBySequenceId(subscriptionId, sequenceId) } // Add only non-deleted latest notifications diff --git a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt index 36464e3a..83e889c8 100644 --- a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt +++ b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt @@ -317,7 +317,7 @@ class SubscriberService : Service() { // Delete existing notification with same sequenceId, if any if (notification.sequenceId.isNotEmpty()) { - repository.deleteBySequenceId(subscription.id, notification.sequenceId) + repository.markAsDeletedBySequenceId(subscription.id, notification.sequenceId) } // Add notification to database and dispatch to be displayed/canceled val added = repository.addNotification(notification) diff --git a/app/src/play/java/io/heckel/ntfy/firebase/FirebaseService.kt b/app/src/play/java/io/heckel/ntfy/firebase/FirebaseService.kt index 89a78c98..3fb09032 100644 --- a/app/src/play/java/io/heckel/ntfy/firebase/FirebaseService.kt +++ b/app/src/play/java/io/heckel/ntfy/firebase/FirebaseService.kt @@ -159,7 +159,7 @@ class FirebaseService : FirebaseMessagingService() { // Delete existing notification with same sequenceId, if any if (notification.sequenceId.isNotEmpty()) { - repository.deleteBySequenceId(subscription.id, notification.sequenceId) + repository.markAsDeletedBySequenceId(subscription.id, notification.sequenceId) } // Add notification to database and dispatch to be displayed/canceled val added = repository.addNotification(notification)