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

Commit 3abd0b3d authored by Philipp Heckel's avatar Philipp Heckel
Browse files

All the things; this should be it

parent c772d150
Loading
Loading
Loading
Loading
+2 −36
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
  "formatVersion": 1,
  "database": {
    "version": 7,
    "identityHash": "eda2cb9740c4542f24462779eb6ff81d",
    "identityHash": "ecb1b85b2ae822dc62b2843620368477",
    "entities": [
      {
        "tableName": "Subscription",
@@ -65,7 +65,6 @@
              "baseUrl",
              "topic"
            ],
            "orders": [],
            "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_Subscription_baseUrl_topic` ON `${TABLE_NAME}` (`baseUrl`, `topic`)"
          },
          {
@@ -74,7 +73,6 @@
            "columnNames": [
              "upConnectorToken"
            ],
            "orders": [],
            "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_Subscription_upConnectorToken` ON `${TABLE_NAME}` (`upConnectorToken`)"
          }
        ],
@@ -198,38 +196,6 @@
        "indices": [],
        "foreignKeys": []
      },
      {
        "tableName": "User",
        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`baseUrl` TEXT NOT NULL, `username` TEXT NOT NULL, `password` TEXT NOT NULL, PRIMARY KEY(`baseUrl`))",
        "fields": [
          {
            "fieldPath": "baseUrl",
            "columnName": "baseUrl",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "username",
            "columnName": "username",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "password",
            "columnName": "password",
            "affinity": "TEXT",
            "notNull": true
          }
        ],
        "primaryKey": {
          "columnNames": [
            "baseUrl"
          ],
          "autoGenerate": false
        },
        "indices": [],
        "foreignKeys": []
      },
      {
        "tableName": "Log",
        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `timestamp` INTEGER NOT NULL, `tag` TEXT NOT NULL, `level` INTEGER NOT NULL, `message` TEXT NOT NULL, `exception` TEXT)",
@@ -284,7 +250,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, 'eda2cb9740c4542f24462779eb6ff81d')"
      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ecb1b85b2ae822dc62b2843620368477')"
    ]
  }
}
 No newline at end of file
+290 −0
Original line number Diff line number Diff line
{
  "formatVersion": 1,
  "database": {
    "version": 8,
    "identityHash": "eda2cb9740c4542f24462779eb6ff81d",
    "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, `upAppId` TEXT, `upConnectorToken` TEXT, PRIMARY KEY(`id`))",
        "fields": [
          {
            "fieldPath": "id",
            "columnName": "id",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "baseUrl",
            "columnName": "baseUrl",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "topic",
            "columnName": "topic",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "instant",
            "columnName": "instant",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "mutedUntil",
            "columnName": "mutedUntil",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "upAppId",
            "columnName": "upAppId",
            "affinity": "TEXT",
            "notNull": false
          },
          {
            "fieldPath": "upConnectorToken",
            "columnName": "upConnectorToken",
            "affinity": "TEXT",
            "notNull": false
          }
        ],
        "primaryKey": {
          "columnNames": [
            "id"
          ],
          "autoGenerate": false
        },
        "indices": [
          {
            "name": "index_Subscription_baseUrl_topic",
            "unique": true,
            "columnNames": [
              "baseUrl",
              "topic"
            ],
            "orders": [],
            "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_Subscription_baseUrl_topic` ON `${TABLE_NAME}` (`baseUrl`, `topic`)"
          },
          {
            "name": "index_Subscription_upConnectorToken",
            "unique": true,
            "columnNames": [
              "upConnectorToken"
            ],
            "orders": [],
            "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_Subscription_upConnectorToken` ON `${TABLE_NAME}` (`upConnectorToken`)"
          }
        ],
        "foreignKeys": []
      },
      {
        "tableName": "Notification",
        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `subscriptionId` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `title` TEXT NOT NULL, `message` TEXT NOT NULL, `notificationId` INTEGER NOT NULL, `priority` INTEGER NOT NULL DEFAULT 3, `tags` TEXT NOT NULL, `click` TEXT NOT NULL, `deleted` INTEGER NOT NULL, `attachment_name` TEXT, `attachment_type` TEXT, `attachment_size` INTEGER, `attachment_expires` INTEGER, `attachment_url` TEXT, `attachment_contentUri` TEXT, `attachment_progress` INTEGER, PRIMARY KEY(`id`, `subscriptionId`))",
        "fields": [
          {
            "fieldPath": "id",
            "columnName": "id",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "subscriptionId",
            "columnName": "subscriptionId",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "timestamp",
            "columnName": "timestamp",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "title",
            "columnName": "title",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "message",
            "columnName": "message",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "notificationId",
            "columnName": "notificationId",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "priority",
            "columnName": "priority",
            "affinity": "INTEGER",
            "notNull": true,
            "defaultValue": "3"
          },
          {
            "fieldPath": "tags",
            "columnName": "tags",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "click",
            "columnName": "click",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "deleted",
            "columnName": "deleted",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "attachment.name",
            "columnName": "attachment_name",
            "affinity": "TEXT",
            "notNull": false
          },
          {
            "fieldPath": "attachment.type",
            "columnName": "attachment_type",
            "affinity": "TEXT",
            "notNull": false
          },
          {
            "fieldPath": "attachment.size",
            "columnName": "attachment_size",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "attachment.expires",
            "columnName": "attachment_expires",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "attachment.url",
            "columnName": "attachment_url",
            "affinity": "TEXT",
            "notNull": false
          },
          {
            "fieldPath": "attachment.contentUri",
            "columnName": "attachment_contentUri",
            "affinity": "TEXT",
            "notNull": false
          },
          {
            "fieldPath": "attachment.progress",
            "columnName": "attachment_progress",
            "affinity": "INTEGER",
            "notNull": false
          }
        ],
        "primaryKey": {
          "columnNames": [
            "id",
            "subscriptionId"
          ],
          "autoGenerate": false
        },
        "indices": [],
        "foreignKeys": []
      },
      {
        "tableName": "User",
        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`baseUrl` TEXT NOT NULL, `username` TEXT NOT NULL, `password` TEXT NOT NULL, PRIMARY KEY(`baseUrl`))",
        "fields": [
          {
            "fieldPath": "baseUrl",
            "columnName": "baseUrl",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "username",
            "columnName": "username",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "password",
            "columnName": "password",
            "affinity": "TEXT",
            "notNull": true
          }
        ],
        "primaryKey": {
          "columnNames": [
            "baseUrl"
          ],
          "autoGenerate": false
        },
        "indices": [],
        "foreignKeys": []
      },
      {
        "tableName": "Log",
        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `timestamp` INTEGER NOT NULL, `tag` TEXT NOT NULL, `level` INTEGER NOT NULL, `message` TEXT NOT NULL, `exception` TEXT)",
        "fields": [
          {
            "fieldPath": "id",
            "columnName": "id",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "timestamp",
            "columnName": "timestamp",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "tag",
            "columnName": "tag",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "level",
            "columnName": "level",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "message",
            "columnName": "message",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "exception",
            "columnName": "exception",
            "affinity": "TEXT",
            "notNull": false
          }
        ],
        "primaryKey": {
          "columnNames": [
            "id"
          ],
          "autoGenerate": true
        },
        "indices": [],
        "foreignKeys": []
      }
    ],
    "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, 'eda2cb9740c4542f24462779eb6ff81d')"
    ]
  }
}
 No newline at end of file
+9 −2
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ data class LogEntry(
            this(0, timestamp, tag, level, message, exception)
}

@androidx.room.Database(entities = [Subscription::class, Notification::class, User::class, LogEntry::class], version = 7)
@androidx.room.Database(entities = [Subscription::class, Notification::class, User::class, LogEntry::class], version = 8)
abstract class Database : RoomDatabase() {
    abstract fun subscriptionDao(): SubscriptionDao
    abstract fun notificationDao(): NotificationDao
@@ -121,6 +121,7 @@ abstract class Database : RoomDatabase() {
                    .addMigrations(MIGRATION_4_5)
                    .addMigrations(MIGRATION_5_6)
                    .addMigrations(MIGRATION_6_7)
                    .addMigrations(MIGRATION_7_8)
                    .fallbackToDestructiveMigration()
                    .build()
                this.instance = instance
@@ -184,6 +185,12 @@ abstract class Database : RoomDatabase() {
                db.execSQL("CREATE TABLE Log (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, timestamp INT NOT NULL, tag TEXT NOT NULL, level INT NOT NULL, message TEXT NOT NULL, exception TEXT)")
            }
        }

        private val MIGRATION_7_8 = object : Migration(7, 8) {
            override fun migrate(db: SupportSQLiteDatabase) {
                db.execSQL("CREATE TABLE User (baseUrl TEXT NOT NULL, username TEXT NOT NULL, password TEXT NOT NULL, PRIMARY KEY(baseUrl))")
            }
        }
    }
}

+0 −10
Original line number Diff line number Diff line
@@ -219,16 +219,6 @@ class Repository(private val sharedPrefs: SharedPreferences, private val databas
        return sharedPrefs.getInt(SHARED_PREFS_DARK_MODE, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
    }

    fun getWakelockEnabled(): Boolean {
        return sharedPrefs.getBoolean(SHARED_PREFS_WAKELOCK_ENABLED, false) // Disabled by default!
    }

    fun setWakelockEnabled(enabled: Boolean) {
        sharedPrefs.edit()
            .putBoolean(SHARED_PREFS_WAKELOCK_ENABLED, enabled)
            .apply()
    }

    fun setConnectionProtocol(connectionProtocol: String) {
        if (connectionProtocol == CONNECTION_PROTOCOL_JSONHTTP) {
            sharedPrefs.edit()
+17 −11
Original line number Diff line number Diff line
@@ -6,8 +6,6 @@ import io.heckel.ntfy.BuildConfig
import io.heckel.ntfy.db.Database
import io.heckel.ntfy.db.LogDao
import io.heckel.ntfy.db.LogEntry
import io.heckel.ntfy.db.Repository
import io.heckel.ntfy.util.isIgnoringBatteryOptimizations
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@@ -34,15 +32,19 @@ class Log(private val logsDao: LogDao) {
        }
    }

    fun getFormatted(): String {
        return prependDeviceInfo(formatEntries(scrubEntries(logsDao.getAll())))
    fun getFormatted(scrub: Boolean): String {
        return if (scrub) {
            prependDeviceInfo(formatEntries(scrubEntries(logsDao.getAll())), scrubLine = true)
        } else {
            prependDeviceInfo(formatEntries(logsDao.getAll()), scrubLine = false)
        }
    }

    private fun prependDeviceInfo(s: String): String {
    private fun prependDeviceInfo(s: String, scrubLine: Boolean): String {
        val maybeScrubLine = if (scrubLine) "Server URLs (aside from ntfy.sh) and topics have been replaced with fruits 🍌🥝🍋🥥🥑🍊🍎🍑.\n" else ""
        return """
            This is a log of the ntfy Android app. The log shows up to 2,000 lines.
            Server URLs (aside from ntfy.sh) and topics have been replaced with fruits 🍌🥝🍋🥥🥑🍊🍎🍑.

            This is a log of the ntfy Android app. The log shows up to 1,000 entries.
            $maybeScrubLine
            Device info:
            --
            ntfy: ${BuildConfig.VERSION_NAME} (${BuildConfig.FLAVOR})
@@ -116,7 +118,7 @@ class Log(private val logsDao: LogDao) {
    companion object {
        private const val TAG = "NtfyLog"
        private const val PRUNE_EVERY = 100
        private const val ENTRIES_MAX = 2000
        private const val ENTRIES_MAX = 1000
        private val IGNORE_TERMS = listOf("ntfy.sh")
        private val REPLACE_TERMS = listOf(
            "banana", "kiwi", "lemon", "coconut", "avocado", "orange", "apple", "peach"
@@ -153,8 +155,12 @@ class Log(private val logsDao: LogDao) {
            return getInstance()?.record?.get() ?: false
        }

        fun getFormatted(): String {
            return getInstance()?.getFormatted() ?: "(no logs)"
        fun getFormatted(scrub: Boolean): String {
            return getInstance()?.getFormatted(scrub) ?: "(no logs)"
        }

        fun getScrubTerms(): Map<String, String> {
            return getInstance()?.scrubTerms!!.toMap()
        }

        fun deleteAll() {
Loading