Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5101d1a0 authored by Philipp Heckel's avatar Philipp Heckel
Browse files

Make subscription-specific setting work

parent fea0709a
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -2,11 +2,11 @@
  "formatVersion": 1,
  "database": {
    "version": 12,
    "identityHash": "d230005f4d9824ba9aa34c61003bdcbb",
    "identityHash": "40948c056fa4ccc9765735111177cf85",
    "entities": [
      {
        "tableName": "Subscription",
        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `baseUrl` TEXT NOT NULL, `topic` TEXT NOT NULL, `instant` INTEGER NOT NULL, `mutedUntil` INTEGER NOT NULL, `minPriority` INTEGER NOT NULL, `autoDelete` INTEGER NOT NULL, `lastNotificationId` TEXT, `icon` TEXT, `upAppId` TEXT, `upConnectorToken` TEXT, `displayName` TEXT, PRIMARY KEY(`id`))",
        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `baseUrl` TEXT NOT NULL, `topic` TEXT NOT NULL, `instant` INTEGER NOT NULL, `mutedUntil` INTEGER NOT NULL, `minPriority` INTEGER NOT NULL, `autoDelete` INTEGER NOT NULL, `insistent` INTEGER NOT NULL, `lastNotificationId` TEXT, `icon` TEXT, `upAppId` TEXT, `upConnectorToken` TEXT, `displayName` TEXT, PRIMARY KEY(`id`))",
        "fields": [
          {
            "fieldPath": "id",
@@ -50,6 +50,12 @@
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "insistent",
            "columnName": "insistent",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "lastNotificationId",
            "columnName": "lastNotificationId",
@@ -338,7 +344,7 @@
    "views": [],
    "setupQueries": [
      "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'd230005f4d9824ba9aa34c61003bdcbb')"
      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '40948c056fa4ccc9765735111177cf85')"
    ]
  }
}
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ class Backuper(val context: Context) {
                    mutedUntil = s.mutedUntil,
                    minPriority = s.minPriority ?: Repository.MIN_PRIORITY_USE_GLOBAL,
                    autoDelete = s.autoDelete ?: Repository.AUTO_DELETE_USE_GLOBAL,
                    insistent = s.insistent ?: Repository.INSISTENT_MAX_PRIORITY_USE_GLOBAL,
                    lastNotificationId = s.lastNotificationId,
                    icon = s.icon,
                    upAppId = s.upAppId,
@@ -239,6 +240,7 @@ class Backuper(val context: Context) {
                mutedUntil = s.mutedUntil,
                minPriority = s.minPriority,
                autoDelete = s.autoDelete,
                insistent = s.insistent,
                lastNotificationId = s.lastNotificationId,
                icon = s.icon,
                upAppId = s.upAppId,
@@ -356,6 +358,7 @@ data class Subscription(
    val mutedUntil: Long,
    val minPriority: Int?,
    val autoDelete: Long?,
    val insistent: Int?,
    val lastNotificationId: String?,
    val icon: String?,
    val upAppId: String?,
+41 −8
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ data class Subscription(
    @ColumnInfo(name = "mutedUntil") val mutedUntil: Long,
    @ColumnInfo(name = "minPriority") val minPriority: Int,
    @ColumnInfo(name = "autoDelete") val autoDelete: Long, // Seconds
    //@ColumnInfo(name = "insistent") val insistent: Boolean?, // Seconds
    @ColumnInfo(name = "insistent") val insistent: Int, // Ring constantly for max priority notifications (-1 = use global, 0 = off, 1 = on)
    @ColumnInfo(name = "lastNotificationId") val lastNotificationId: String?, // Used for polling, with since=<id>
    @ColumnInfo(name = "icon") val icon: String?, // content://-URI (or later other identifier)
    @ColumnInfo(name = "upAppId") val upAppId: String?, // UnifiedPush application package name
@@ -29,8 +29,40 @@ data class Subscription(
    @Ignore val lastActive: Long = 0, // Unix timestamp
    @Ignore val state: ConnectionState = ConnectionState.NOT_APPLICABLE
) {
    constructor(id: Long, baseUrl: String, topic: String, instant: Boolean, mutedUntil: Long, minPriority: Int, autoDelete: Long, lastNotificationId: String, icon: String, upAppId: String, upConnectorToken: String, displayName: String?) :
            this(id, baseUrl, topic, instant, mutedUntil, minPriority, autoDelete, lastNotificationId, icon, upAppId, upConnectorToken, displayName, 0, 0, 0, ConnectionState.NOT_APPLICABLE)
    constructor(
        id: Long,
        baseUrl: String,
        topic: String,
        instant: Boolean,
        mutedUntil: Long,
        minPriority: Int,
        autoDelete: Long,
        insistent: Int,
        lastNotificationId: String,
        icon: String,
        upAppId: String,
        upConnectorToken: String,
        displayName: String?
    ) :
            this(
                id,
                baseUrl,
                topic,
                instant,
                mutedUntil,
                minPriority,
                autoDelete,
                insistent,
                lastNotificationId,
                icon,
                upAppId,
                upConnectorToken,
                displayName,
                0,
                0,
                0,
                ConnectionState.NOT_APPLICABLE
            )
}

enum class ConnectionState {
@@ -45,6 +77,7 @@ data class SubscriptionWithMetadata(
    val mutedUntil: Long,
    val autoDelete: Long,
    val minPriority: Int,
    val insistent: Int,
    val lastNotificationId: String?,
    val icon: String?,
    val upAppId: String?,
@@ -291,7 +324,7 @@ abstract class Database : RoomDatabase() {
interface SubscriptionDao {
    @Query("""
        SELECT 
          s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil, s.minPriority, s.autoDelete, s.lastNotificationId, s.icon, s.upAppId, s.upConnectorToken, s.displayName,
          s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil, s.minPriority, s.autoDelete, s.insistent, s.lastNotificationId, s.icon, s.upAppId, s.upConnectorToken, s.displayName,
          COUNT(n.id) totalCount, 
          COUNT(CASE n.notificationId WHEN 0 THEN NULL ELSE n.id END) newCount, 
          IFNULL(MAX(n.timestamp),0) AS lastActive
@@ -304,7 +337,7 @@ interface SubscriptionDao {

    @Query("""
        SELECT 
          s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil, s.minPriority, s.autoDelete, s.lastNotificationId, s.icon, s.upAppId, s.upConnectorToken, s.displayName,
          s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil, s.minPriority, s.autoDelete, s.insistent, s.lastNotificationId, s.icon, s.upAppId, s.upConnectorToken, s.displayName,
          COUNT(n.id) totalCount, 
          COUNT(CASE n.notificationId WHEN 0 THEN NULL ELSE n.id END) newCount, 
          IFNULL(MAX(n.timestamp),0) AS lastActive
@@ -317,7 +350,7 @@ interface SubscriptionDao {

    @Query("""
        SELECT 
          s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil, s.minPriority, s.autoDelete, s.lastNotificationId, s.icon, s.upAppId, s.upConnectorToken, s.displayName,
          s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil, s.minPriority, s.autoDelete, s.insistent, s.lastNotificationId, s.icon, s.upAppId, s.upConnectorToken, s.displayName,
          COUNT(n.id) totalCount, 
          COUNT(CASE n.notificationId WHEN 0 THEN NULL ELSE n.id END) newCount, 
          IFNULL(MAX(n.timestamp),0) AS lastActive
@@ -330,7 +363,7 @@ interface SubscriptionDao {

    @Query("""
        SELECT 
          s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil, s.minPriority, s.autoDelete, s.lastNotificationId, s.icon, s.upAppId, s.upConnectorToken, s.displayName,
          s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil, s.minPriority, s.autoDelete, s.insistent, s.lastNotificationId, s.icon, s.upAppId, s.upConnectorToken, s.displayName,
          COUNT(n.id) totalCount, 
          COUNT(CASE n.notificationId WHEN 0 THEN NULL ELSE n.id END) newCount, 
          IFNULL(MAX(n.timestamp),0) AS lastActive
@@ -343,7 +376,7 @@ interface SubscriptionDao {

    @Query("""
        SELECT 
          s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil, s.minPriority, s.autoDelete, s.lastNotificationId, s.icon, s.upAppId, s.upConnectorToken, s.displayName,
          s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil, s.minPriority, s.autoDelete, s.insistent, s.lastNotificationId, s.icon, s.upAppId, s.upConnectorToken, s.displayName,
          COUNT(n.id) totalCount, 
          COUNT(CASE n.notificationId WHEN 0 THEN NULL ELSE n.id END) newCount, 
          IFNULL(MAX(n.timestamp),0) AS lastActive
+6 −0
Original line number Diff line number Diff line
@@ -402,6 +402,7 @@ class Repository(private val sharedPrefs: SharedPreferences, private val databas
                mutedUntil = s.mutedUntil,
                minPriority = s.minPriority,
                autoDelete = s.autoDelete,
                insistent = s.insistent,
                lastNotificationId = s.lastNotificationId,
                icon = s.icon,
                upAppId = s.upAppId,
@@ -427,6 +428,7 @@ class Repository(private val sharedPrefs: SharedPreferences, private val databas
            mutedUntil = s.mutedUntil,
            minPriority = s.minPriority,
            autoDelete = s.autoDelete,
            insistent = s.insistent,
            lastNotificationId = s.lastNotificationId,
            icon = s.icon,
            upAppId = s.upAppId,
@@ -505,6 +507,10 @@ class Repository(private val sharedPrefs: SharedPreferences, private val databas
        const val AUTO_DELETE_THREE_MONTHS_SECONDS = 90 * ONE_DAY_SECONDS
        const val AUTO_DELETE_DEFAULT_SECONDS = AUTO_DELETE_ONE_MONTH_SECONDS

        const val INSISTENT_MAX_PRIORITY_USE_GLOBAL = -1 // Values must match values.xml
        const val INSISTENT_MAX_PRIORITY_DISABLED = 0
        const val INSISTENT_MAX_PRIORITY_ENABLED = 1

        const val CONNECTION_PROTOCOL_JSONHTTP = "jsonhttp"
        const val CONNECTION_PROTOCOL_WS = "ws"

+2 −1
Original line number Diff line number Diff line
@@ -65,7 +65,8 @@ class NotificationService(val context: Context) {
    private fun displayInternal(subscription: Subscription, notification: Notification, update: Boolean = false) {
        val title = formatTitle(subscription, notification)
        val channelId = toChannelId(notification.priority)
        val insistent = notification.priority == 5 && repository.getInsistentMaxPriorityEnabled()
        val insistent = notification.priority == 5 &&
                (repository.getInsistentMaxPriorityEnabled() || subscription.insistent == Repository.INSISTENT_MAX_PRIORITY_ENABLED)
        val builder = NotificationCompat.Builder(context, channelId)
            .setSmallIcon(R.drawable.ic_notification)
            .setColor(ContextCompat.getColor(context, Colors.notificationIcon(context)))
Loading