fix: Expedite notification fetches via UnifiedPush (#440)

UnifiedPush broadcasts are used to trigger fetching new notifications.
Previously this was a normal one-time work request. Mark it as expedited
to increase the likelihood it will run soon.
This commit is contained in:
Nik Clayton 2024-02-14 12:01:06 +01:00 committed by GitHub
parent e71e0df324
commit 913f366a41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 1 deletions

View File

@ -17,7 +17,10 @@
package app.pachli.receiver
import android.content.Context
import androidx.work.Constraints
import androidx.work.NetworkType
import androidx.work.OneTimeWorkRequest
import androidx.work.OutOfQuotaPolicy
import androidx.work.WorkManager
import app.pachli.components.notifications.registerUnifiedPushEndpoint
import app.pachli.components.notifications.unregisterUnifiedPushEndpoint
@ -44,7 +47,10 @@ class UnifiedPushBroadcastReceiver : MessagingReceiver() {
override fun onMessage(context: Context, message: ByteArray, instance: String) {
Timber.d("New message received for account %s", instance)
val workManager = WorkManager.getInstance(context)
val request = OneTimeWorkRequest.from(NotificationWorker::class.java)
val request = OneTimeWorkRequest.Builder(NotificationWorker::class.java)
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.setConstraints(Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build())
.build()
workManager.enqueue(request)
}