Skip to content

Commit

Permalink
persist notifications longer for deduplication
Browse files Browse the repository at this point in the history
  • Loading branch information
crc-32 committed Aug 6, 2024
1 parent c957988 commit 084c459
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import java.util.UUID
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.random.Random
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.milliseconds

@Singleton
Expand Down Expand Up @@ -231,7 +231,10 @@ class NotificationProcessor @Inject constructor(
if (result.responseValue != BlobResponse.BlobStatus.Success) {
Timber.e("Failed to send notification to Pebble, blobdb returned ${result.responseValue}")
}
persistedNotifDao.deleteOlderThan(System.currentTimeMillis() - 1.hours.inWholeMilliseconds)
val deleted = persistedNotifDao.deleteOlderThan(System.currentTimeMillis() - 7.days.inWholeMilliseconds)
if (deleted > 0) {
Timber.w("Deleted $deleted old notifications that were never deleted on dismissal")
}
delay(10)
}
}
Expand Down Expand Up @@ -354,5 +357,6 @@ class NotificationProcessor @Inject constructor(
)
blobDBService.send(packet, PacketPriority.LOW)
}
persistedNotifDao.delete(sbn.key)
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package io.rebble.cobble.shared.database.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.*
import io.rebble.cobble.shared.database.entity.PersistedNotification

@Dao
interface PersistedNotificationDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(notification: PersistedNotification)
@Delete
suspend fun delete(notification: PersistedNotification)
@Query("DELETE FROM PersistedNotification WHERE sbnKey = :key")
suspend fun delete(key: String)

@Query("SELECT * FROM PersistedNotification WHERE sbnKey = :key")
suspend fun get(key: String): PersistedNotification?
Expand All @@ -18,5 +19,5 @@ interface PersistedNotificationDao {
suspend fun getDuplicates(key:String, packageName: String, title: String, text: String): List<PersistedNotification>

@Query("DELETE FROM PersistedNotification WHERE postTime < :time")
suspend fun deleteOlderThan(time: Long)
suspend fun deleteOlderThan(time: Long): Int
}

0 comments on commit 084c459

Please sign in to comment.