mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 02:55:23 +00:00
feat: add pushes seqnos and test for push content
This commit is contained in:
parent
420edc931b
commit
f0aea7aaa9
@ -27,6 +27,23 @@ class ExampleInstrumentedTest {
|
||||
userProfile.free()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun jni_user_profile_c_api() {
|
||||
val userProfile = UserProfile.newInstance()
|
||||
|
||||
assertFalse(userProfile.needsPush())
|
||||
assertFalse(userProfile.needsDump())
|
||||
|
||||
val name = userProfile.getName()
|
||||
assertNull(name)
|
||||
|
||||
val (toPush, seqNo) = userProfile.push()
|
||||
assertEquals("d1:#i0e1:&de1:<le1:=dee", toPush)
|
||||
assertEquals(0, seqNo)
|
||||
|
||||
userProfile.free()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun jni_setting_getting() {
|
||||
val userProfile = UserProfile.newInstance()
|
||||
|
@ -31,25 +31,26 @@ Java_network_loki_messenger_libsession_1util_UserProfile_00024Companion_newInsta
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_UserProfile_setName(
|
||||
JNIEnv* env,
|
||||
jobject obj,
|
||||
jobject thiz,
|
||||
jstring newName) {
|
||||
auto profile = ptrToProfile(env, obj);
|
||||
auto profile = ptrToProfile(env, thiz);
|
||||
profile->set_name(env->GetStringUTFChars(newName, nullptr));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_UserProfile_getName(JNIEnv *env, jobject obj) {
|
||||
auto profile = ptrToProfile(env, obj);
|
||||
Java_network_loki_messenger_libsession_1util_UserProfile_getName(JNIEnv *env, jobject thiz) {
|
||||
auto profile = ptrToProfile(env, thiz);
|
||||
auto name = profile->get_name();
|
||||
if (name == nullptr) return nullptr;
|
||||
jstring returnString = env->NewStringUTF(name->c_str());
|
||||
return returnString;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_UserProfile_free(JNIEnv *env, jobject obj) {
|
||||
auto profile = ptrToProfile(env, obj);
|
||||
Java_network_loki_messenger_libsession_1util_UserProfile_free(JNIEnv *env, jobject thiz) {
|
||||
auto profile = ptrToProfile(env, thiz);
|
||||
delete profile;
|
||||
}
|
||||
|
||||
@ -58,4 +59,29 @@ JNIEXPORT jboolean JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_ConfigBase_dirty(JNIEnv *env, jobject thiz) {
|
||||
auto* configBase = ptrToConfigBase(env, thiz);
|
||||
return configBase->is_dirty();
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_ConfigBase_needsPush(JNIEnv *env, jobject thiz) {
|
||||
auto config = ptrToConfigBase(env, thiz);
|
||||
return config->needs_push();
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_ConfigBase_needsDump(JNIEnv *env, jobject thiz) {
|
||||
auto config = ptrToConfigBase(env, thiz);
|
||||
return config->needs_dump();
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_ConfigBase_push(JNIEnv *env, jobject thiz) {
|
||||
auto config = ptrToConfigBase(env, thiz);
|
||||
auto pair = config->push();
|
||||
std::string to_push_str = pair.first;
|
||||
jstring returnString = env->NewStringUTF(to_push_str.c_str());
|
||||
jlong seqNo = pair.second;
|
||||
jclass returnObjectClass = env->FindClass("network/loki/messenger/libsession_util/util/ConfigWithSeqNo");
|
||||
jmethodID methodId = env->GetMethodID(returnObjectClass, "<init>", "(Ljava/lang/String;J)V");
|
||||
jobject returnObject = env->NewObject(returnObjectClass, methodId, returnString, seqNo);
|
||||
return returnObject;
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package network.loki.messenger.libsession_util
|
||||
|
||||
import network.loki.messenger.libsession_util.util.ConfigWithSeqNo
|
||||
|
||||
|
||||
sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
|
||||
companion object {
|
||||
@ -8,6 +10,9 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
|
||||
}
|
||||
}
|
||||
external fun dirty(): Boolean
|
||||
external fun needsPush(): Boolean
|
||||
external fun needsDump(): Boolean
|
||||
external fun push(): ConfigWithSeqNo
|
||||
}
|
||||
|
||||
class UserProfile(pointer: Long): ConfigBase(pointer) {
|
||||
@ -18,6 +23,6 @@ class UserProfile(pointer: Long): ConfigBase(pointer) {
|
||||
external fun newInstance(): UserProfile
|
||||
}
|
||||
external fun setName(newName: String)
|
||||
external fun getName(): String
|
||||
external fun getName(): String?
|
||||
external fun free()
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package network.loki.messenger.libsession_util.util
|
||||
|
||||
data class StringWithLen(private val bytes: ByteArray, private val len: Long) { // We might not need this class, could be helpful though
|
||||
|
||||
override fun toString(): String = bytes.decodeToString()
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as StringWithLen
|
||||
|
||||
if (!bytes.contentEquals(other.bytes)) return false
|
||||
if (len != other.len) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = bytes.contentHashCode()
|
||||
result = 31 * result + len.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
data class ConfigWithSeqNo(val config: String, val seqNo: Long)
|
Loading…
Reference in New Issue
Block a user