mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 02:55:23 +00:00
fix: add max size and maybe fix the non-200 sub requests for batches (for 421s in particular)
This commit is contained in:
parent
78d1e9d387
commit
1c7841333a
@ -171,7 +171,7 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti
|
||||
runBlocking(Dispatchers.IO) {
|
||||
val requestSparseArray = SparseArray<SnodeAPI.SnodeBatchRequestInfo>()
|
||||
// get messages
|
||||
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(snode, userPublicKey)!!.also { personalMessages ->
|
||||
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(snode, userPublicKey, maxSize = -2)!!.also { personalMessages ->
|
||||
// namespaces here should always be set
|
||||
requestSparseArray[personalMessages.namespace!!] = personalMessages
|
||||
}
|
||||
@ -181,7 +181,8 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti
|
||||
hashesToExtend += config.currentHashes()
|
||||
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(
|
||||
snode, userPublicKey,
|
||||
config.configNamespace()
|
||||
config.configNamespace(),
|
||||
maxSize = -8
|
||||
)
|
||||
}.forEach { request ->
|
||||
// namespaces here should always be set
|
||||
|
@ -453,7 +453,7 @@ object SnodeAPI {
|
||||
)
|
||||
}
|
||||
|
||||
fun buildAuthenticatedRetrieveBatchRequest(snode: Snode, publicKey: String, namespace: Int = 0): SnodeBatchRequestInfo? {
|
||||
fun buildAuthenticatedRetrieveBatchRequest(snode: Snode, publicKey: String, namespace: Int = 0, maxSize: Int? = null): SnodeBatchRequestInfo? {
|
||||
val lastHashValue = database.getLastMessageHashValue(snode, publicKey, namespace) ?: ""
|
||||
val params = mutableMapOf<String, Any>(
|
||||
"pubkey" to publicKey,
|
||||
@ -486,6 +486,9 @@ object SnodeAPI {
|
||||
if (namespace != 0) {
|
||||
params["namespace"] = namespace
|
||||
}
|
||||
if (maxSize != null) {
|
||||
params["max_size"] = maxSize
|
||||
}
|
||||
return SnodeBatchRequestInfo(
|
||||
Snode.Method.Retrieve.rawValue,
|
||||
params,
|
||||
@ -511,7 +514,20 @@ object SnodeAPI {
|
||||
val parameters = mutableMapOf<String, Any>(
|
||||
"requests" to requests
|
||||
)
|
||||
return invoke(if (sequence) Snode.Method.Sequence else Snode.Method.Batch, snode, parameters, publicKey)
|
||||
return invoke(if (sequence) Snode.Method.Sequence else Snode.Method.Batch, snode, parameters, publicKey).success { rawResponses ->
|
||||
val responseList = (rawResponses["results"] as List<RawResponse>)
|
||||
responseList.forEachIndexed { index, response ->
|
||||
if (response["code"] as? Int != 200) {
|
||||
Log.w("Loki", "response code was not 200")
|
||||
handleSnodeError(
|
||||
response["code"] as? Int ?: 0,
|
||||
response,
|
||||
snode,
|
||||
publicKey
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getExpiries(messageHashes: List<String>, publicKey: String) : RawResponsePromise {
|
||||
|
Loading…
Reference in New Issue
Block a user