mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-29 04:55:15 +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) {
|
runBlocking(Dispatchers.IO) {
|
||||||
val requestSparseArray = SparseArray<SnodeAPI.SnodeBatchRequestInfo>()
|
val requestSparseArray = SparseArray<SnodeAPI.SnodeBatchRequestInfo>()
|
||||||
// get messages
|
// get messages
|
||||||
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(snode, userPublicKey)!!.also { personalMessages ->
|
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(snode, userPublicKey, maxSize = -2)!!.also { personalMessages ->
|
||||||
// namespaces here should always be set
|
// namespaces here should always be set
|
||||||
requestSparseArray[personalMessages.namespace!!] = personalMessages
|
requestSparseArray[personalMessages.namespace!!] = personalMessages
|
||||||
}
|
}
|
||||||
@ -181,7 +181,8 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti
|
|||||||
hashesToExtend += config.currentHashes()
|
hashesToExtend += config.currentHashes()
|
||||||
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(
|
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(
|
||||||
snode, userPublicKey,
|
snode, userPublicKey,
|
||||||
config.configNamespace()
|
config.configNamespace(),
|
||||||
|
maxSize = -8
|
||||||
)
|
)
|
||||||
}.forEach { request ->
|
}.forEach { request ->
|
||||||
// namespaces here should always be set
|
// 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 lastHashValue = database.getLastMessageHashValue(snode, publicKey, namespace) ?: ""
|
||||||
val params = mutableMapOf<String, Any>(
|
val params = mutableMapOf<String, Any>(
|
||||||
"pubkey" to publicKey,
|
"pubkey" to publicKey,
|
||||||
@ -486,6 +486,9 @@ object SnodeAPI {
|
|||||||
if (namespace != 0) {
|
if (namespace != 0) {
|
||||||
params["namespace"] = namespace
|
params["namespace"] = namespace
|
||||||
}
|
}
|
||||||
|
if (maxSize != null) {
|
||||||
|
params["max_size"] = maxSize
|
||||||
|
}
|
||||||
return SnodeBatchRequestInfo(
|
return SnodeBatchRequestInfo(
|
||||||
Snode.Method.Retrieve.rawValue,
|
Snode.Method.Retrieve.rawValue,
|
||||||
params,
|
params,
|
||||||
@ -511,7 +514,20 @@ object SnodeAPI {
|
|||||||
val parameters = mutableMapOf<String, Any>(
|
val parameters = mutableMapOf<String, Any>(
|
||||||
"requests" to requests
|
"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 {
|
fun getExpiries(messageHashes: List<String>, publicKey: String) : RawResponsePromise {
|
||||||
|
Loading…
Reference in New Issue
Block a user