From f7c5953f5d57477d972fc0c1ead3437b66eb163b Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Fri, 3 Feb 2023 16:54:48 +1100 Subject: [PATCH] feat: add all iterators and tests --- .../libsession_util/InstrumentedTests.kt | 14 +++++- libsession-util/src/main/cpp/conversation.cpp | 45 +++++++++++++++++-- .../loki/messenger/libsession_util/Config.kt | 3 ++ 3 files changed, 58 insertions(+), 4 deletions(-) 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 6272eac39c..55800c0e6f 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 @@ -535,6 +535,7 @@ class InstrumentedTests { assertTrue(seen.contains("1-to-1: 055000000000000000000000000000000000000000000000000000000000000000")) assertTrue(seen.contains("og: http://example.org:5678/r/sudokuroom")) assertTrue(seen.contains("cl: 05cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc")) + assertTrue(seen.size == 4) // for some reason iterative checks aren't working in test cases } assertFalse(convos.needsPush()) @@ -543,7 +544,18 @@ class InstrumentedTests { convos.eraseOneToOne("055000000000000000000000000000000000000000000000000000000000000000") assertTrue(convos.needsPush()) - + assertEquals(1, convos.allOneToOnes().size) + assertEquals("051111111111111111111111111111111111111111111111111111111111111111", + convos.allOneToOnes().map(Conversation.OneToOne::sessionId).first() + ) + assertEquals(1, convos.allOpenGroups().size) + assertEquals("http://example.org:5678", + convos.allOpenGroups().map(Conversation.OpenGroup::baseUrl).first() + ) + assertEquals(1, convos.allLegacyClosedGroups().size) + assertEquals("05cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + convos.allLegacyClosedGroups().map(Conversation.LegacyClosedGroup::groupId).first() + ) } } \ No newline at end of file diff --git a/libsession-util/src/main/cpp/conversation.cpp b/libsession-util/src/main/cpp/conversation.cpp index 684f473ada..71cd32ccf6 100644 --- a/libsession-util/src/main/cpp/conversation.cpp +++ b/libsession-util/src/main/cpp/conversation.cpp @@ -323,14 +323,53 @@ extern "C" JNIEXPORT jobject JNICALL Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_all(JNIEnv *env, jobject thiz) { - auto contacts = ptrToConvoInfo(env, thiz); + auto convos = ptrToConvoInfo(env, thiz); jclass stack = env->FindClass("java/util/Stack"); jmethodID init = env->GetMethodID(stack, "", "()V"); jobject our_stack = env->NewObject(stack, init); jmethodID push = env->GetMethodID(stack, "push", "(Ljava/lang/Object;)Ljava/lang/Object;"); - for (const auto& contact : *contacts) { - auto contact_obj = serialize_any(env, contact); + for (const auto& convo : *convos) { + auto contact_obj = serialize_any(env, convo); env->CallObjectMethod(our_stack, push, contact_obj); } return our_stack; +} +extern "C" +JNIEXPORT jobject JNICALL +Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_allOneToOnes(JNIEnv *env, + jobject thiz) { + auto convos = ptrToConvoInfo(env, thiz); + jclass stack = env->FindClass("java/util/Stack"); + jmethodID init = env->GetMethodID(stack, "", "()V"); + jobject our_stack = env->NewObject(stack, init); + jmethodID push = env->GetMethodID(stack, "push", "(Ljava/lang/Object;)Ljava/lang/Object;"); + for (auto contact = convos->begin_1to1(); contact != convos->end(); ++contact) + env->CallObjectMethod(our_stack, push, serialize_one_to_one(env, *contact)); + return our_stack; +} +extern "C" +JNIEXPORT jobject JNICALL +Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_allOpenGroups(JNIEnv *env, + jobject thiz) { + auto convos = ptrToConvoInfo(env, thiz); + jclass stack = env->FindClass("java/util/Stack"); + jmethodID init = env->GetMethodID(stack, "", "()V"); + jobject our_stack = env->NewObject(stack, init); + jmethodID push = env->GetMethodID(stack, "push", "(Ljava/lang/Object;)Ljava/lang/Object;"); + for (auto contact = convos->begin_open(); contact != convos->end(); ++contact) + env->CallObjectMethod(our_stack, push, serialize_open_group(env, *contact)); + return our_stack; +} +extern "C" +JNIEXPORT jobject JNICALL +Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_allLegacyClosedGroups( + JNIEnv *env, jobject thiz) { + auto convos = ptrToConvoInfo(env, thiz); + jclass stack = env->FindClass("java/util/Stack"); + jmethodID init = env->GetMethodID(stack, "", "()V"); + jobject our_stack = env->NewObject(stack, init); + jmethodID push = env->GetMethodID(stack, "push", "(Ljava/lang/Object;)Ljava/lang/Object;"); + for (auto contact = convos->begin_legacy_closed(); contact != convos->end(); ++contact) + env->CallObjectMethod(our_stack, push, serialize_legacy_group(env, *contact)); + return our_stack; } \ 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 376324bccc..62c482b3b9 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 @@ -107,6 +107,9 @@ class ConversationVolatileConfig(pointer: Long): ConfigBase(pointer) { external fun empty(): Boolean + external fun allOneToOnes(): List + external fun allOpenGroups(): List + external fun allLegacyClosedGroups(): List external fun all(): List } \ No newline at end of file