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:
parent
e71e0df324
commit
913f366a41
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue