mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 02:55:23 +00:00
feat: update request responses and their appropriate processing
This commit is contained in:
parent
28e5794624
commit
c8d520c3ce
@ -91,4 +91,23 @@ JNIEXPORT jint JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_ConfigBase_configNamespace(JNIEnv *env, jobject thiz) {
|
||||
auto conf = ptrToConfigBase(env, thiz);
|
||||
return (std::int16_t) conf->storage_namespace();
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT jclass JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_ConfigBase_00024Companion_kindFor(JNIEnv *env,
|
||||
jobject thiz,
|
||||
jint config_namespace) {
|
||||
auto user_class = env->FindClass("network/loki/messenger/libsession_util/UserProfile");
|
||||
auto contact_class = env->FindClass("network/loki/messenger/libsession_util/Contacts");
|
||||
auto convo_volatile_class = env->FindClass("network/loki/messenger/libsession_util/ConversationVolatileConfig");
|
||||
switch (config_namespace) {
|
||||
case (int)session::config::Namespace::UserProfile:
|
||||
return user_class;
|
||||
case (int)session::config::Namespace::Contacts:
|
||||
return contact_class;
|
||||
case (int)session::config::Namespace::ConvoInfoVolatile:
|
||||
return convo_volatile_class;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
|
||||
init {
|
||||
System.loadLibrary("session_util")
|
||||
}
|
||||
external fun kindFor(configNamespace: Int): Class<ConfigBase>
|
||||
}
|
||||
|
||||
external fun dirty(): Boolean
|
||||
|
@ -1,8 +1,13 @@
|
||||
package org.session.libsession.messaging.sending_receiving.pollers
|
||||
|
||||
import android.util.SparseArray
|
||||
import androidx.core.util.keyIterator
|
||||
import androidx.core.util.valueIterator
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import network.loki.messenger.libsession_util.ConfigBase
|
||||
import network.loki.messenger.libsession_util.UserProfile
|
||||
import nl.komponents.kovenant.Deferred
|
||||
import nl.komponents.kovenant.Promise
|
||||
import nl.komponents.kovenant.deferred
|
||||
@ -19,6 +24,7 @@ import org.session.libsession.snode.SnodeModule
|
||||
import org.session.libsession.utilities.ConfigFactoryProtocol
|
||||
import org.session.libsignal.utilities.JsonUtil
|
||||
import org.session.libsignal.utilities.Log
|
||||
import org.session.libsignal.utilities.Namespace
|
||||
import org.session.libsignal.utilities.Snode
|
||||
import java.security.SecureRandom
|
||||
import java.util.Timer
|
||||
@ -132,33 +138,22 @@ class Poller(private val configFactory: ConfigFactoryProtocol) {
|
||||
if (!hasStarted) { return Promise.ofFail(PromiseCanceledException()) }
|
||||
return task {
|
||||
runBlocking(Dispatchers.IO) {
|
||||
val requests = listOfNotNull(
|
||||
// get messages
|
||||
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(snode, userPublicKey),
|
||||
// get user config namespace
|
||||
configFactory.user?.let { currentUserConfig ->
|
||||
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(
|
||||
snode,
|
||||
userPublicKey,
|
||||
currentUserConfig.configNamespace()
|
||||
)
|
||||
},
|
||||
// get contact config namespace
|
||||
configFactory.contacts?.let { currentContacts ->
|
||||
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(
|
||||
snode,
|
||||
userPublicKey,
|
||||
currentContacts.configNamespace()
|
||||
)
|
||||
},
|
||||
// get the latest convo info volatile
|
||||
configFactory.convoVolatile?.let { currentConvoVolatile ->
|
||||
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(
|
||||
snode, userPublicKey,
|
||||
currentConvoVolatile.configNamespace()
|
||||
)
|
||||
}
|
||||
)
|
||||
val requestSparseArray = SparseArray<SnodeAPI.SnodeBatchRequestInfo>()
|
||||
// get messages
|
||||
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(snode, userPublicKey)!!.also { personalMessages ->
|
||||
requestSparseArray[personalMessages.namespace] = personalMessages
|
||||
}
|
||||
// get the latest convo info volatile
|
||||
listOfNotNull(configFactory.user, configFactory.contacts, configFactory.convoVolatile).mapNotNull { config ->
|
||||
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(
|
||||
snode, userPublicKey,
|
||||
config.configNamespace()
|
||||
)
|
||||
}.forEach { request ->
|
||||
requestSparseArray[request.namespace] = request
|
||||
}
|
||||
|
||||
val requests = requestSparseArray.valueIterator().asSequence().toList()
|
||||
|
||||
SnodeAPI.getRawBatchResponse(snode, userPublicKey, requests).bind { rawResponses ->
|
||||
isCaughtUp = true
|
||||
@ -166,7 +161,18 @@ class Poller(private val configFactory: ConfigFactoryProtocol) {
|
||||
return@bind Promise.ofSuccess(Unit)
|
||||
} else {
|
||||
Log.d("Loki-DBG", JsonUtil.toJson(rawResponses))
|
||||
|
||||
val requestList = (rawResponses["results"] as List<RawResponse>)
|
||||
requestSparseArray.keyIterator().withIndex().forEach { (requestIndex, key) ->
|
||||
requestList.getOrNull(requestIndex)?.let { rawResponse ->
|
||||
if (key == Namespace.DEFAULT) {
|
||||
processPersonalMessages(snode, rawResponse)
|
||||
} else {
|
||||
when (ConfigBase.kindFor(key)) {
|
||||
UserProfile ->
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
poll(snode, deferred)
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +100,8 @@ object SnodeAPI {
|
||||
data class SnodeBatchRequestInfo(
|
||||
val method: String,
|
||||
val params: Map<String, Any>,
|
||||
@Transient
|
||||
val namespace: Int
|
||||
) // assume signatures, pubkey and namespaces are attached in parameters if required
|
||||
|
||||
// Internal API
|
||||
@ -398,7 +400,8 @@ object SnodeAPI {
|
||||
}
|
||||
return SnodeBatchRequestInfo(
|
||||
Snode.Method.Retrieve.rawValue,
|
||||
params
|
||||
params,
|
||||
namespace
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -3,5 +3,4 @@ package org.session.libsignal.utilities
|
||||
object Namespace {
|
||||
const val DEFAULT = 0
|
||||
const val UNAUTHENTICATED_CLOSED_GROUP = -10
|
||||
const val CONFIGURATION = 5
|
||||
}
|
Loading…
Reference in New Issue
Block a user