mirror of
https://codeberg.org/NextPush/nextpush-android.git
synced 2024-12-26 09:42:39 +01:00
Add Last-Event-ID header
This commit is contained in:
parent
9541ed6aed
commit
67a39da534
@ -14,12 +14,22 @@ class AppStore(context: Context) : Store(context) {
|
||||
.putOrRemove(PREF_DEVICE_ID, value)
|
||||
.apply()
|
||||
|
||||
var lastEventId: String?
|
||||
get() = sharedPreferences
|
||||
.getString(PREF_LAST_EVENT_ID, null)
|
||||
set(value) = sharedPreferences
|
||||
.edit()
|
||||
.putOrRemove(PREF_LAST_EVENT_ID, value)
|
||||
.apply()
|
||||
|
||||
override fun wipe() {
|
||||
deviceId = null
|
||||
lastEventId = null
|
||||
account.wipe()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val PREF_DEVICE_ID = "deviceId"
|
||||
private const val PREF_LAST_EVENT_ID = "lastEventId"
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +92,11 @@ class Api(context: Context) {
|
||||
|
||||
val request = Request.Builder().url(url)
|
||||
.get()
|
||||
.apply {
|
||||
store.lastEventId?.let {
|
||||
header("Last-Event-ID", it)
|
||||
}
|
||||
}
|
||||
.build()
|
||||
|
||||
syncSource.getAndSet(
|
||||
@ -132,6 +137,7 @@ class Api(context: Context) {
|
||||
}
|
||||
})
|
||||
store.deviceId = null
|
||||
store.lastEventId = null
|
||||
}
|
||||
} catch (e: NoProviderException) {
|
||||
e.printStackTrace()
|
||||
|
@ -8,6 +8,7 @@ import okhttp3.Response
|
||||
import okhttp3.sse.EventSource
|
||||
import okhttp3.sse.EventSourceListener
|
||||
import org.unifiedpush.distributor.nextpush.AppCompanion
|
||||
import org.unifiedpush.distributor.nextpush.AppStore
|
||||
import org.unifiedpush.distributor.nextpush.Database
|
||||
import org.unifiedpush.distributor.nextpush.WakeLock
|
||||
import org.unifiedpush.distributor.nextpush.api.response.SSEResponse
|
||||
@ -30,6 +31,8 @@ import kotlin.concurrent.schedule
|
||||
|
||||
class SSEListener(val context: Context) : EventSourceListener() {
|
||||
|
||||
val store = AppStore(context)
|
||||
|
||||
override var timeout: Long? = AppCompanion.keepalive.get().toLong() + TIMEOUT_TOLERANCE
|
||||
|
||||
override fun onOpen(eventSource: EventSource, response: Response) {
|
||||
@ -82,6 +85,7 @@ class SSEListener(val context: Context) : EventSourceListener() {
|
||||
message.token,
|
||||
Base64.decode(message.message, Base64.DEFAULT)
|
||||
)
|
||||
store.lastEventId = id
|
||||
}
|
||||
|
||||
"deleteApp" -> {
|
||||
|
Loading…
Reference in New Issue
Block a user