Implement BackgroundPollWorker

This commit is contained in:
Niels Andriesse 2019-07-19 16:46:04 +10:00
parent 8651f20c9b
commit 2329e9d03d
2 changed files with 22 additions and 0 deletions

View File

@ -6,6 +6,7 @@ buildscript {
ext.gradle_version = "3.4.1" ext.gradle_version = "3.4.1"
ext.kotlin_version = "1.3.31" ext.kotlin_version = "1.3.31"
ext.kovenant_version = "3.3.0" ext.kovenant_version = "3.3.0"
ext.work_manager_version = "2.1.0"
repositories { repositories {
google() google()
@ -179,6 +180,7 @@ dependencies {
implementation "com.squareup.okhttp3:okhttp:3.12.1" implementation "com.squareup.okhttp3:okhttp:3.12.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "nl.komponents.kovenant:kovenant:$kovenant_version" implementation "nl.komponents.kovenant:kovenant:$kovenant_version"
implementation "androidx.work:work-runtime-ktx:$work_manager_version"
} }
android { android {

View File

@ -0,0 +1,20 @@
package org.thoughtcrime.securesms.loki
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import org.whispersystems.signalservice.loki.api.LokiAPI
import org.whispersystems.signalservice.loki.api.LokiAPIDatabaseProtocol
class BackgroundPollWorker(private val userHexEncodedPublicKey: String, private val apiDatabase: LokiAPIDatabaseProtocol, context: Context, parameters: WorkerParameters) : Worker(context, parameters) {
override fun doWork(): Result {
return try {
LokiAPI(userHexEncodedPublicKey, apiDatabase).getMessages().get()
// TODO: Process envelopes
Result.success()
} catch (exception: Exception) {
Result.failure()
}
}
}