diff --git a/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt b/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt index 4294986628..b2d08555df 100644 --- a/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt +++ b/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt @@ -41,7 +41,8 @@ class InstrumentedTests { @Test fun jni_user_profile_c_api() { - val userProfile = UserProfile.newInstance(keyPair.secretKey) + val edSk = keyPair.secretKey + val userProfile = UserProfile.newInstance(edSk) // these should be false as empty config assertFalse(userProfile.needsPush()) @@ -123,7 +124,46 @@ class InstrumentedTests { assertArrayEquals(expectedDump, dump) + val newConf = UserProfile.newInstance(edSk) + + val accepted = newConf.merge(arrayOf(expectedPush1Encrypted)) + assertEquals(1, accepted) + + assertTrue(newConf.needsDump()) + assertFalse(newConf.needsPush()) + val _ignore = newConf.dump() + assertFalse(newConf.needsDump()) + + + userProfile.setName("Nibbler") + newConf.setName("Raz") + newConf.setPic(UserPic("http://new.example.com/pic", "qwertyuio".encodeToByteArray())) + + val conf = userProfile.push() + val conf2 = newConf.push() + + val dump1 = userProfile.dump() + val dump2 = userProfile.dump() + + assertFalse(conf.config.contentEquals(conf2.config)) + + newConf.merge(arrayOf(conf.config)) + userProfile.merge(arrayOf(conf2.config)) + + assertTrue(newConf.needsPush()) + assertTrue(userProfile.needsPush()) + + val newSeq1 = userProfile.push() + val newSeq2 = newConf.push() + + assertEquals(3, newSeq1.seqNo) + assertEquals(3, newSeq2.seqNo) + + assertEquals("Nibbler", newConf.getName()) + assertEquals("Nibbler", userProfile.getName()) + userProfile.free() + newConf.free() } @Test diff --git a/libsession-util/src/main/cpp/session_util.cpp b/libsession-util/src/main/cpp/session_util.cpp index 79bffa2357..81c87f5686 100644 --- a/libsession-util/src/main/cpp/session_util.cpp +++ b/libsession-util/src/main/cpp/session_util.cpp @@ -186,9 +186,23 @@ Java_network_loki_messenger_libsession_1util_ConfigBase_encryptionDomain(JNIEnv return env->NewStringUTF(conf->encryption_domain()); } extern "C" -JNIEXPORT jbyteArray JNICALL -Java_network_loki_messenger_libsession_1util_ConfigBase_decrypt(JNIEnv *env, jobject thiz, - jbyteArray encrypted) { - auto profile = ptrToProfile(env, thiz); - auto encrypted_bytes = ustring_from_bytes(env, encrypted); +JNIEXPORT void JNICALL +Java_network_loki_messenger_libsession_1util_ConfigBase_confirmPushed(JNIEnv *env, jobject thiz, + jlong seq_no) { + auto conf = ptrToConfigBase(env, thiz); + conf->confirm_pushed(seq_no); +} +extern "C" +JNIEXPORT jint JNICALL +Java_network_loki_messenger_libsession_1util_ConfigBase_merge(JNIEnv *env, jobject thiz, + jobjectArray to_merge) { + auto conf = ptrToConfigBase(env, thiz); + size_t number = env->GetArrayLength(to_merge); + std::vector configs = {}; + for (int i = 0; i < number; i++) { + auto jArr = (jbyteArray) env->GetObjectArrayElement(to_merge, i); + auto bytes = ustring_from_bytes(env, jArr); + configs.push_back(bytes); + } + return conf->merge(configs); } \ No newline at end of file diff --git a/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt b/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt index 0d44921cf7..38e5506420 100644 --- a/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt +++ b/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt @@ -16,7 +16,8 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) { external fun push(): ConfigWithSeqNo external fun dump(): ByteArray external fun encryptionDomain(): String - external fun decrypt(encrypted: ByteArray): ByteArray + external fun confirmPushed(seqNo: Long) + external fun merge(toMerge: Array): Int } class UserProfile(pointer: Long): ConfigBase(pointer) {