Mark as deleted instead of hard delete

This commit is contained in:
Philipp Heckel 2026-01-08 14:48:58 -05:00
parent d1d42cea84
commit fb604e5dc0
5 changed files with 7 additions and 10 deletions

View file

@ -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)

View file

@ -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) {

View file

@ -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

View file

@ -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)

View file

@ -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)