From 2329e9d03d208d37ced03711f25defc8bc9f8355 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 19 Jul 2019 16:46:04 +1000 Subject: [PATCH] Implement BackgroundPollWorker --- build.gradle | 2 ++ .../securesms/loki/BackgroundPollWorker.kt | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/org/thoughtcrime/securesms/loki/BackgroundPollWorker.kt diff --git a/build.gradle b/build.gradle index 19e4767c92..756aff75b2 100644 --- a/build.gradle +++ b/build.gradle @@ -6,6 +6,7 @@ buildscript { ext.gradle_version = "3.4.1" ext.kotlin_version = "1.3.31" ext.kovenant_version = "3.3.0" + ext.work_manager_version = "2.1.0" repositories { google() @@ -179,6 +180,7 @@ dependencies { implementation "com.squareup.okhttp3:okhttp:3.12.1" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "nl.komponents.kovenant:kovenant:$kovenant_version" + implementation "androidx.work:work-runtime-ktx:$work_manager_version" } android { diff --git a/src/org/thoughtcrime/securesms/loki/BackgroundPollWorker.kt b/src/org/thoughtcrime/securesms/loki/BackgroundPollWorker.kt new file mode 100644 index 0000000000..93f28e5301 --- /dev/null +++ b/src/org/thoughtcrime/securesms/loki/BackgroundPollWorker.kt @@ -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() + } + } +} \ No newline at end of file