mirror of
https://codeberg.org/NextPush/nextpush-android.git
synced 2025-01-13 18:43:13 +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)
|
.putOrRemove(PREF_DEVICE_ID, value)
|
||||||
.apply()
|
.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() {
|
override fun wipe() {
|
||||||
deviceId = null
|
deviceId = null
|
||||||
|
lastEventId = null
|
||||||
account.wipe()
|
account.wipe()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val PREF_DEVICE_ID = "deviceId"
|
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)
|
val request = Request.Builder().url(url)
|
||||||
.get()
|
.get()
|
||||||
|
.apply {
|
||||||
|
store.lastEventId?.let {
|
||||||
|
header("Last-Event-ID", it)
|
||||||
|
}
|
||||||
|
}
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
syncSource.getAndSet(
|
syncSource.getAndSet(
|
||||||
@ -132,6 +137,7 @@ class Api(context: Context) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
store.deviceId = null
|
store.deviceId = null
|
||||||
|
store.lastEventId = null
|
||||||
}
|
}
|
||||||
} catch (e: NoProviderException) {
|
} catch (e: NoProviderException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
@ -8,6 +8,7 @@ import okhttp3.Response
|
|||||||
import okhttp3.sse.EventSource
|
import okhttp3.sse.EventSource
|
||||||
import okhttp3.sse.EventSourceListener
|
import okhttp3.sse.EventSourceListener
|
||||||
import org.unifiedpush.distributor.nextpush.AppCompanion
|
import org.unifiedpush.distributor.nextpush.AppCompanion
|
||||||
|
import org.unifiedpush.distributor.nextpush.AppStore
|
||||||
import org.unifiedpush.distributor.nextpush.Database
|
import org.unifiedpush.distributor.nextpush.Database
|
||||||
import org.unifiedpush.distributor.nextpush.WakeLock
|
import org.unifiedpush.distributor.nextpush.WakeLock
|
||||||
import org.unifiedpush.distributor.nextpush.api.response.SSEResponse
|
import org.unifiedpush.distributor.nextpush.api.response.SSEResponse
|
||||||
@ -30,6 +31,8 @@ import kotlin.concurrent.schedule
|
|||||||
|
|
||||||
class SSEListener(val context: Context) : EventSourceListener() {
|
class SSEListener(val context: Context) : EventSourceListener() {
|
||||||
|
|
||||||
|
val store = AppStore(context)
|
||||||
|
|
||||||
override var timeout: Long? = AppCompanion.keepalive.get().toLong() + TIMEOUT_TOLERANCE
|
override var timeout: Long? = AppCompanion.keepalive.get().toLong() + TIMEOUT_TOLERANCE
|
||||||
|
|
||||||
override fun onOpen(eventSource: EventSource, response: Response) {
|
override fun onOpen(eventSource: EventSource, response: Response) {
|
||||||
@ -82,6 +85,7 @@ class SSEListener(val context: Context) : EventSourceListener() {
|
|||||||
message.token,
|
message.token,
|
||||||
Base64.decode(message.message, Base64.DEFAULT)
|
Base64.decode(message.message, Base64.DEFAULT)
|
||||||
)
|
)
|
||||||
|
store.lastEventId = id
|
||||||
}
|
}
|
||||||
|
|
||||||
"deleteApp" -> {
|
"deleteApp" -> {
|
||||||
|
Loading…
Reference in New Issue
Block a user