Improve push notifications (#4896)

Besides the refactoring these improvements:
* Track last push distributor and reset settings and subscription on any
incompatible change (ie. uninstall)
* Only update (push) notification settings on server if needed
* Allow to only fetch notifications for one account (the one for which a
push message was received)

This is (also) the revival of
https://github.com/tuskyapp/Tusky/pull/3642

It's not really well tested so far. (Ie. with two or more accounts or
two or more push providers.)
This commit is contained in:
UlrichKu 2025-02-20 12:27:06 +01:00 committed by GitHub
commit 6450af6edb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 274 additions and 127 deletions

View file

@ -68,13 +68,19 @@ class TuskyApplication : Application(), Configuration.Provider {
Security.insertProviderAt(Conscrypt.newProvider(), 1)
val workManager = WorkManager.getInstance(this)
// Migrate shared preference keys and defaults from version to version.
val oldVersion = preferences.getInt(
PrefKeys.SCHEMA_VERSION,
NEW_INSTALL_SCHEMA_VERSION
)
if (oldVersion != SCHEMA_VERSION) {
// TODO SCHEMA_VERSION is outdated / not updated in code
if (oldVersion < 2025021701) {
// A new periodic work request is enqueued by unique name (and not tag anymore): stop the old one
workManager.cancelAllWorkByTag("pullNotifications")
}
upgradeSharedPreferences(oldVersion, SCHEMA_VERSION)
}
@ -93,7 +99,7 @@ class TuskyApplication : Application(), Configuration.Provider {
val pruneCacheWorker = PeriodicWorkRequestBuilder<PruneCacheWorker>(12, TimeUnit.HOURS)
.setConstraints(Constraints.Builder().setRequiresDeviceIdle(true).build())
.build()
WorkManager.getInstance(this).enqueueUniquePeriodicWork(
workManager.enqueueUniquePeriodicWork(
PruneCacheWorker.PERIODIC_WORK_TAG,
ExistingPeriodicWorkPolicy.KEEP,
pruneCacheWorker