fix: compile errors from updating library to use latest branch, now requires cmake 3.22.1

This commit is contained in:
0x330a 2023-02-21 15:45:22 +11:00
parent 0221fb89ce
commit 39c532240c
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
9 changed files with 83 additions and 124 deletions

View File

@ -137,8 +137,8 @@ class Storage(context: Context, helper: SQLCipherOpenHelper, private val configF
// recipient is open group // recipient is open group
recipient.isOpenGroupRecipient -> { recipient.isOpenGroupRecipient -> {
val openGroupJoinUrl = getOpenGroup(threadId)?.joinURL ?: return val openGroupJoinUrl = getOpenGroup(threadId)?.joinURL ?: return
Conversation.OpenGroup.parseFullUrl(openGroupJoinUrl)?.let { (base, room, pubKey) -> Conversation.Community.parseFullUrl(openGroupJoinUrl)?.let { (base, room, pubKey) ->
config.getOrConstructOpenGroup(base, room, pubKey) config.getOrConstructCommunity(base, room, pubKey)
} ?: return } ?: return
} }
// otherwise recipient is one to one // otherwise recipient is one to one
@ -356,10 +356,10 @@ class Storage(context: Context, helper: SQLCipherOpenHelper, private val configF
is Conversation.OneToOne -> conversation.sessionId.let { is Conversation.OneToOne -> conversation.sessionId.let {
getOrCreateThreadIdFor(fromSerialized(it)) getOrCreateThreadIdFor(fromSerialized(it))
} }
is Conversation.LegacyClosedGroup -> conversation.groupId.let { is Conversation.LegacyGroup -> conversation.groupId.let {
getOrCreateThreadIdFor("", it,null) getOrCreateThreadIdFor("", it,null)
} }
is Conversation.OpenGroup -> conversation.baseUrl.let { is Conversation.Community -> conversation.baseUrl.let {
getOrCreateThreadIdFor("",null, it) getOrCreateThreadIdFor("",null, it)
} }
} }

View File

@ -26,7 +26,7 @@ android {
externalNativeBuild { externalNativeBuild {
cmake { cmake {
path "src/main/cpp/CMakeLists.txt" path "src/main/cpp/CMakeLists.txt"
version "3.18.1" version "3.22.1"
} }
} }
compileOptions { compileOptions {

View File

@ -355,41 +355,41 @@ class InstrumentedTests {
@Test @Test
fun test_open_group_urls() { fun test_open_group_urls() {
val (base1, room1, pk1) = Conversation.OpenGroup.parseFullUrl( val (base1, room1, pk1) = Conversation.Community.parseFullUrl(
"https://example.com/" + "https://example.com/" +
"SomeRoom?public_key=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "SomeRoom?public_key=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
)!! )!!
val (base2, room2, pk2) = Conversation.OpenGroup.parseFullUrl( val (base2, room2, pk2) = Conversation.Community.parseFullUrl(
"HTTPS://EXAMPLE.COM/" + "HTTPS://EXAMPLE.COM/" +
"sOMErOOM?public_key=0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" "sOMErOOM?public_key=0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
)!! )!!
val (base3, room3, pk3) = Conversation.OpenGroup.parseFullUrl( val (base3, room3, pk3) = Conversation.Community.parseFullUrl(
"HTTPS://EXAMPLE.COM/r/" + "HTTPS://EXAMPLE.COM/r/" +
"someroom?public_key=0123456789aBcdEF0123456789abCDEF0123456789ABCdef0123456789ABCDEF" "someroom?public_key=0123456789aBcdEF0123456789abCDEF0123456789ABCdef0123456789ABCDEF"
)!! )!!
val (base4, room4, pk4) = Conversation.OpenGroup.parseFullUrl( val (base4, room4, pk4) = Conversation.Community.parseFullUrl(
"http://example.com/r/" + "http://example.com/r/" +
"someroom?public_key=0123456789aBcdEF0123456789abCDEF0123456789ABCdef0123456789ABCDEF" "someroom?public_key=0123456789aBcdEF0123456789abCDEF0123456789ABCdef0123456789ABCDEF"
)!! )!!
val (base5, room5, pk5) = Conversation.OpenGroup.parseFullUrl( val (base5, room5, pk5) = Conversation.Community.parseFullUrl(
"HTTPS://EXAMPLE.com:443/r/" + "HTTPS://EXAMPLE.com:443/r/" +
"someroom?public_key=0123456789aBcdEF0123456789abCDEF0123456789ABCdef0123456789ABCDEF" "someroom?public_key=0123456789aBcdEF0123456789abCDEF0123456789ABCdef0123456789ABCDEF"
)!! )!!
val (base6, room6, pk6) = Conversation.OpenGroup.parseFullUrl( val (base6, room6, pk6) = Conversation.Community.parseFullUrl(
"HTTP://EXAMPLE.com:80/r/" + "HTTP://EXAMPLE.com:80/r/" +
"someroom?public_key=0123456789aBcdEF0123456789abCDEF0123456789ABCdef0123456789ABCDEF" "someroom?public_key=0123456789aBcdEF0123456789abCDEF0123456789ABCdef0123456789ABCDEF"
)!! )!!
val (base7, room7, pk7) = Conversation.OpenGroup.parseFullUrl( val (base7, room7, pk7) = Conversation.Community.parseFullUrl(
"http://example.com:80/r/" + "http://example.com:80/r/" +
"someroom?public_key=ASNFZ4mrze8BI0VniavN7wEjRWeJq83vASNFZ4mrze8" "someroom?public_key=ASNFZ4mrze8BI0VniavN7wEjRWeJq83vASNFZ4mrze8"
)!! )!!
val (base8, room8, pk8) = Conversation.OpenGroup.parseFullUrl( val (base8, room8, pk8) = Conversation.Community.parseFullUrl(
"http://example.com:80/r/" + "http://example.com:80/r/" +
"someroom?public_key=yrtwk3hjixg66yjdeiuauk6p7hy1gtm8tgih55abrpnsxnpm3zzo" "someroom?public_key=yrtwk3hjixg66yjdeiuauk6p7hy1gtm8tgih55abrpnsxnpm3zzo"
)!! )!!
@ -526,8 +526,8 @@ class InstrumentedTests {
for (convo in allConvos) { for (convo in allConvos) {
when (convo) { when (convo) {
is Conversation.OneToOne -> seen.add("1-to-1: ${convo.sessionId}") is Conversation.OneToOne -> seen.add("1-to-1: ${convo.sessionId}")
is Conversation.OpenGroup -> seen.add("og: ${convo.baseUrl}/r/${convo.room}") is Conversation.Community -> seen.add("og: ${convo.baseUrl}/r/${convo.room}")
is Conversation.LegacyClosedGroup -> seen.add("cl: ${convo.groupId}") is Conversation.LegacyGroup -> seen.add("cl: ${convo.groupId}")
} }
} }
@ -550,11 +550,11 @@ class InstrumentedTests {
) )
assertEquals(1, convos.allOpenGroups().size) assertEquals(1, convos.allOpenGroups().size)
assertEquals("http://example.org:5678", assertEquals("http://example.org:5678",
convos.allOpenGroups().map(Conversation.OpenGroup::baseUrl).first() convos.allOpenGroups().map(Conversation.Community::baseUrl).first()
) )
assertEquals(1, convos.allLegacyClosedGroups().size) assertEquals(1, convos.allLegacyClosedGroups().size)
assertEquals("05cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", assertEquals("05cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
convos.allLegacyClosedGroups().map(Conversation.LegacyClosedGroup::groupId).first() convos.allLegacyClosedGroups().map(Conversation.LegacyGroup::groupId).first()
) )
} }

View File

@ -16,14 +16,8 @@ inline jobject serialize_contact(JNIEnv *env, session::config::contact_info info
jmethodID constructor = env->GetMethodID(contactClass, "<init>", jmethodID constructor = env->GetMethodID(contactClass, "<init>",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZLnetwork/loki/messenger/libsession_util/util/UserPic;)V"); "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZLnetwork/loki/messenger/libsession_util/util/UserPic;)V");
jstring id = env->NewStringUTF(info.session_id.data()); jstring id = env->NewStringUTF(info.session_id.data());
jstring name = nullptr; jstring name = env->NewStringUTF(info.name.data());
jstring nickname = nullptr; jstring nickname = env->NewStringUTF(info.nickname.data());
if (info.name) {
name = env->NewStringUTF(info.name->data());
}
if (info.nickname) {
nickname = env->NewStringUTF(info.nickname->data());
}
jboolean approved, approvedMe, blocked; jboolean approved, approvedMe, blocked;
approved = info.approved; approved = info.approved;
approvedMe = info.approved_me; approvedMe = info.approved_me;

View File

@ -5,10 +5,10 @@
extern "C" extern "C"
JNIEXPORT jobject JNICALL JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_util_Conversation_00024OpenGroup_00024Companion_parseFullUrl( Java_network_loki_messenger_libsession_1util_util_Conversation_00024Community_00024Companion_parseFullUrl(
JNIEnv *env, jobject thiz, jstring full_url) { JNIEnv *env, jobject thiz, jstring full_url) {
auto bytes = env->GetStringUTFChars(full_url, nullptr); auto bytes = env->GetStringUTFChars(full_url, nullptr);
auto [base, room, pk] = session::config::convo::open_group::parse_full_url(bytes); auto [base, room, pk] = session::config::convo::community::parse_full_url(bytes);
env->ReleaseStringUTFChars(full_url, bytes); env->ReleaseStringUTFChars(full_url, bytes);
jclass clazz = env->FindClass("kotlin/Triple"); jclass clazz = env->FindClass("kotlin/Triple");
@ -74,13 +74,13 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseAll
jmethodID predicate_call = env->GetMethodID(predicate_class, "invoke", "(Ljava/lang/Object;)Ljava/lang/Object;"); jmethodID predicate_call = env->GetMethodID(predicate_class, "invoke", "(Ljava/lang/Object;)Ljava/lang/Object;");
jclass bool_class = env->FindClass("java/lang/Boolean"); jclass bool_class = env->FindClass("java/lang/Boolean");
jfieldID bool_value = env->GetFieldID(bool_class, "value", "Z"); jmethodID bool_get = env->GetMethodID(bool_class, "booleanValue", "()Z");
int removed = 0; int removed = 0;
for (auto it = conversations->begin(); it != conversations->end(); ) { for (auto it = conversations->begin(); it != conversations->end(); ) {
auto result = env->CallObjectMethod(predicate, predicate_call, serialize_any(env, *it)); auto result = env->CallObjectMethod(predicate, predicate_call, serialize_any(env, *it));
bool bool_result = env->GetBooleanField(result, bool_value); bool bool_result = env->CallBooleanMethod(result, bool_get);
if (bool_result) { if (bool_result) {
it = conversations->erase(it); it = conversations->erase(it);
removed++; removed++;
@ -115,8 +115,8 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_set(JNIE
auto convos = ptrToConvoInfo(env, thiz); auto convos = ptrToConvoInfo(env, thiz);
jclass one_to_one = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$OneToOne"); jclass one_to_one = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$OneToOne");
jclass open_group = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$OpenGroup"); jclass open_group = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$Community");
jclass legacy_closed_group = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$LegacyClosedGroup"); jclass legacy_closed_group = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$LegacyGroup");
jclass to_store_class = env->GetObjectClass(to_store); jclass to_store_class = env->GetObjectClass(to_store);
if (env->IsSameObject(to_store_class, one_to_one)) { if (env->IsSameObject(to_store_class, one_to_one)) {
@ -165,18 +165,15 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseOne
env->ReleaseStringUTFChars(pub_key_hex, param); env->ReleaseStringUTFChars(pub_key_hex, param);
return result; return result;
} }
extern "C" extern "C"
JNIEXPORT jobject JNICALL JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getOpenGroup__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2( Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getCommunity__Ljava_lang_String_2Ljava_lang_String_2(
JNIEnv *env, jobject thiz, jstring base_url, jstring room, jstring pub_key_hex) { JNIEnv *env, jobject thiz, jstring base_url, jstring room) {
auto convos = ptrToConvoInfo(env, thiz); auto convos = ptrToConvoInfo(env, thiz);
auto base_url_chars = env->GetStringUTFChars(base_url, nullptr); auto base_url_chars = env->GetStringUTFChars(base_url, nullptr);
auto room_chars = env->GetStringUTFChars(room, nullptr); auto room_chars = env->GetStringUTFChars(room, nullptr);
auto hex_chars = env->GetStringUTFChars(pub_key_hex, nullptr); auto open = convos->get_community(base_url_chars, room_chars);
auto open = convos->get_open(base_url_chars, room_chars, hex_chars);
env->ReleaseStringUTFChars(base_url, base_url_chars);
env->ReleaseStringUTFChars(room, room_chars);
env->ReleaseStringUTFChars(pub_key_hex, hex_chars);
if (open) { if (open) {
auto serialized = serialize_open_group(env, *open); auto serialized = serialize_open_group(env, *open);
return serialized; return serialized;
@ -185,40 +182,25 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getOpenG
} }
extern "C" extern "C"
JNIEXPORT jobject JNICALL JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getOpenGroup__Ljava_lang_String_2Ljava_lang_String_2_3B( Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getOrConstructCommunity__Ljava_lang_String_2Ljava_lang_String_2_3B(
JNIEnv *env, jobject thiz, jstring base_url, jstring room, jbyteArray pub_key) { JNIEnv *env, jobject thiz, jstring base_url, jstring room, jbyteArray pub_key) {
auto convos = ptrToConvoInfo(env, thiz); auto convos = ptrToConvoInfo(env, thiz);
auto base_url_chars = env->GetStringUTFChars(base_url, nullptr); auto base_url_chars = env->GetStringUTFChars(base_url, nullptr);
auto room_chars = env->GetStringUTFChars(room, nullptr); auto room_chars = env->GetStringUTFChars(room, nullptr);
auto pub_key_ustring = util::ustring_from_bytes(env, pub_key); auto pub_key_ustring = util::ustring_from_bytes(env, pub_key);
auto open = convos->get_open(base_url_chars, room_chars, pub_key_ustring); auto open = convos->get_or_construct_community(base_url_chars, room_chars, pub_key_ustring);
if (open) {
auto serialized = serialize_open_group(env, *open);
return serialized;
}
return nullptr;
}
extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getOrConstructOpenGroup__Ljava_lang_String_2Ljava_lang_String_2_3B(
JNIEnv *env, jobject thiz, jstring base_url, jstring room, jbyteArray pub_key) {
auto convos = ptrToConvoInfo(env, thiz);
auto base_url_chars = env->GetStringUTFChars(base_url, nullptr);
auto room_chars = env->GetStringUTFChars(room, nullptr);
auto pub_key_ustring = util::ustring_from_bytes(env, pub_key);
auto open = convos->get_or_construct_open(base_url_chars, room_chars, pub_key_ustring);
auto serialized = serialize_open_group(env, open); auto serialized = serialize_open_group(env, open);
return serialized; return serialized;
} }
extern "C" extern "C"
JNIEXPORT jobject JNICALL JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getOrConstructOpenGroup__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2( Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getOrConstructCommunity__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2(
JNIEnv *env, jobject thiz, jstring base_url, jstring room, jstring pub_key_hex) { JNIEnv *env, jobject thiz, jstring base_url, jstring room, jstring pub_key_hex) {
auto convos = ptrToConvoInfo(env, thiz); auto convos = ptrToConvoInfo(env, thiz);
auto base_url_chars = env->GetStringUTFChars(base_url, nullptr); auto base_url_chars = env->GetStringUTFChars(base_url, nullptr);
auto room_chars = env->GetStringUTFChars(room, nullptr); auto room_chars = env->GetStringUTFChars(room, nullptr);
auto hex_chars = env->GetStringUTFChars(pub_key_hex, nullptr); auto hex_chars = env->GetStringUTFChars(pub_key_hex, nullptr);
auto open = convos->get_or_construct_open(base_url_chars, room_chars, hex_chars); auto open = convos->get_or_construct_community(base_url_chars, room_chars, hex_chars);
env->ReleaseStringUTFChars(base_url, base_url_chars); env->ReleaseStringUTFChars(base_url, base_url_chars);
env->ReleaseStringUTFChars(room, room_chars); env->ReleaseStringUTFChars(room, room_chars);
env->ReleaseStringUTFChars(pub_key_hex, hex_chars); env->ReleaseStringUTFChars(pub_key_hex, hex_chars);
@ -227,7 +209,7 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getOrCon
} }
extern "C" extern "C"
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseOpenGroup__Lnetwork_loki_messenger_libsession_1util_util_Conversation_OpenGroup_2(JNIEnv *env, Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseCommunity__Lnetwork_loki_messenger_libsession_1util_util_Conversation_Community_2(JNIEnv *env,
jobject thiz, jobject thiz,
jobject open_group) { jobject open_group) {
auto convos = ptrToConvoInfo(env, thiz); auto convos = ptrToConvoInfo(env, thiz);
@ -236,27 +218,12 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseOpe
} }
extern "C" extern "C"
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseOpenGroup__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2( Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseCommunity__Ljava_lang_String_2Ljava_lang_String_2(
JNIEnv *env, jobject thiz, jstring base_url, jstring room, jstring pub_key_hex) { JNIEnv *env, jobject thiz, jstring base_url, jstring room) {
auto convos = ptrToConvoInfo(env, thiz); auto convos = ptrToConvoInfo(env, thiz);
auto base_url_chars = env->GetStringUTFChars(base_url, nullptr); auto base_url_chars = env->GetStringUTFChars(base_url, nullptr);
auto room_chars = env->GetStringUTFChars(room, nullptr); auto room_chars = env->GetStringUTFChars(room, nullptr);
auto hex_chars = env->GetStringUTFChars(pub_key_hex, nullptr); auto result = convos->erase_community(base_url_chars, room_chars);
auto result = convos->erase_open(base_url_chars, room_chars, hex_chars);
env->ReleaseStringUTFChars(base_url, base_url_chars);
env->ReleaseStringUTFChars(room, room_chars);
env->ReleaseStringUTFChars(pub_key_hex, hex_chars);
return result;
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseOpenGroup__Ljava_lang_String_2Ljava_lang_String_2_3B(
JNIEnv *env, jobject thiz, jstring base_url, jstring room, jbyteArray pub_key) {
auto convos = ptrToConvoInfo(env, thiz);
auto base_url_chars = env->GetStringUTFChars(base_url, nullptr);
auto room_chars = env->GetStringUTFChars(room, nullptr);
auto pub_key_bytes = util::ustring_from_bytes(env, pub_key);
auto result = convos->erase_open(base_url_chars, room_chars, pub_key_bytes);
env->ReleaseStringUTFChars(base_url, base_url_chars); env->ReleaseStringUTFChars(base_url, base_url_chars);
env->ReleaseStringUTFChars(room, room_chars); env->ReleaseStringUTFChars(room, room_chars);
return result; return result;
@ -267,7 +234,7 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getLegac
JNIEnv *env, jobject thiz, jstring group_id) { JNIEnv *env, jobject thiz, jstring group_id) {
auto convos = ptrToConvoInfo(env, thiz); auto convos = ptrToConvoInfo(env, thiz);
auto id_chars = env->GetStringUTFChars(group_id, nullptr); auto id_chars = env->GetStringUTFChars(group_id, nullptr);
auto lgc = convos->get_legacy_closed(id_chars); auto lgc = convos->get_legacy_group(id_chars);
env->ReleaseStringUTFChars(group_id, id_chars); env->ReleaseStringUTFChars(group_id, id_chars);
if (lgc) { if (lgc) {
auto serialized = serialize_legacy_group(env, *lgc); auto serialized = serialize_legacy_group(env, *lgc);
@ -281,7 +248,7 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getOrCon
JNIEnv *env, jobject thiz, jstring group_id) { JNIEnv *env, jobject thiz, jstring group_id) {
auto convos = ptrToConvoInfo(env, thiz); auto convos = ptrToConvoInfo(env, thiz);
auto id_chars = env->GetStringUTFChars(group_id, nullptr); auto id_chars = env->GetStringUTFChars(group_id, nullptr);
auto lgc = convos->get_or_construct_legacy_closed(id_chars); auto lgc = convos->get_or_construct_legacy_group(id_chars);
env->ReleaseStringUTFChars(group_id, id_chars); env->ReleaseStringUTFChars(group_id, id_chars);
return serialize_legacy_group(env, lgc); return serialize_legacy_group(env, lgc);
} }
@ -291,7 +258,7 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseLeg
JNIEnv *env, jobject thiz, jstring group_id) { JNIEnv *env, jobject thiz, jstring group_id) {
auto convos = ptrToConvoInfo(env, thiz); auto convos = ptrToConvoInfo(env, thiz);
auto id_chars = env->GetStringUTFChars(group_id, nullptr); auto id_chars = env->GetStringUTFChars(group_id, nullptr);
auto result = convos->erase_legacy_closed(id_chars); auto result = convos->erase_legacy_group(id_chars);
env->ReleaseStringUTFChars(group_id, id_chars); env->ReleaseStringUTFChars(group_id, id_chars);
return result; return result;
} }
@ -307,17 +274,17 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_erase(JN
} }
extern "C" extern "C"
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_sizeOpenGroups(JNIEnv *env, Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_sizeCommunities(JNIEnv *env,
jobject thiz) { jobject thiz) {
auto convos = ptrToConvoInfo(env, thiz); auto convos = ptrToConvoInfo(env, thiz);
return convos->size_open(); return convos->size_communities();
} }
extern "C" extern "C"
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_sizeLegacyClosedGroups( Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_sizeLegacyClosedGroups(
JNIEnv *env, jobject thiz) { JNIEnv *env, jobject thiz) {
auto convos = ptrToConvoInfo(env, thiz); auto convos = ptrToConvoInfo(env, thiz);
return convos->size_open(); return convos->size_legacy_groups();
} }
extern "C" extern "C"
JNIEXPORT jobject JNICALL JNIEXPORT jobject JNICALL
@ -349,14 +316,14 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_allOneTo
} }
extern "C" extern "C"
JNIEXPORT jobject JNICALL JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_allOpenGroups(JNIEnv *env, Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_allCommunities(JNIEnv *env,
jobject thiz) { jobject thiz) {
auto convos = ptrToConvoInfo(env, thiz); auto convos = ptrToConvoInfo(env, thiz);
jclass stack = env->FindClass("java/util/Stack"); jclass stack = env->FindClass("java/util/Stack");
jmethodID init = env->GetMethodID(stack, "<init>", "()V"); jmethodID init = env->GetMethodID(stack, "<init>", "()V");
jobject our_stack = env->NewObject(stack, init); jobject our_stack = env->NewObject(stack, init);
jmethodID push = env->GetMethodID(stack, "push", "(Ljava/lang/Object;)Ljava/lang/Object;"); jmethodID push = env->GetMethodID(stack, "push", "(Ljava/lang/Object;)Ljava/lang/Object;");
for (auto contact = convos->begin_open(); contact != convos->end(); ++contact) for (auto contact = convos->begin_communities(); contact != convos->end(); ++contact)
env->CallObjectMethod(our_stack, push, serialize_open_group(env, *contact)); env->CallObjectMethod(our_stack, push, serialize_open_group(env, *contact));
return our_stack; return our_stack;
} }
@ -369,7 +336,7 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_allLegac
jmethodID init = env->GetMethodID(stack, "<init>", "()V"); jmethodID init = env->GetMethodID(stack, "<init>", "()V");
jobject our_stack = env->NewObject(stack, init); jobject our_stack = env->NewObject(stack, init);
jmethodID push = env->GetMethodID(stack, "push", "(Ljava/lang/Object;)Ljava/lang/Object;"); jmethodID push = env->GetMethodID(stack, "push", "(Ljava/lang/Object;)Ljava/lang/Object;");
for (auto contact = convos->begin_legacy_closed(); contact != convos->end(); ++contact) for (auto contact = convos->begin_legacy_groups(); contact != convos->end(); ++contact)
env->CallObjectMethod(our_stack, push, serialize_legacy_group(env, *contact)); env->CallObjectMethod(our_stack, push, serialize_legacy_group(env, *contact));
return our_stack; return our_stack;
} }

View File

@ -21,25 +21,25 @@ inline jobject serialize_one_to_one(JNIEnv *env, session::config::convo::one_to_
return serialized; return serialized;
} }
inline jobject serialize_open_group(JNIEnv *env, session::config::convo::open_group open_group) { inline jobject serialize_open_group(JNIEnv *env, session::config::convo::community community) {
jclass clazz = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$OpenGroup"); jclass clazz = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$Community");
jmethodID constructor = env->GetMethodID(clazz, "<init>", "(Ljava/lang/String;Ljava/lang/String;[BJZ)V"); jmethodID constructor = env->GetMethodID(clazz, "<init>", "(Ljava/lang/String;Ljava/lang/String;[BJZ)V");
auto base_url = env->NewStringUTF(open_group.base_url().data()); auto base_url = env->NewStringUTF(community.base_url().data());
auto room = env->NewStringUTF(open_group.room().data()); auto room = env->NewStringUTF(community.room().data());
auto pubkey_ustring = open_group.pubkey(); auto pubkey_ustring = community.pubkey();
auto pubkey_jarray = util::bytes_from_ustring(env, session::ustring_view {pubkey_ustring.data(), pubkey_ustring.size()}); auto pubkey_jarray = util::bytes_from_ustring(env, session::ustring_view {pubkey_ustring.data(), pubkey_ustring.size()});
auto last_read = open_group.last_read; auto last_read = community.last_read;
auto unread = open_group.unread; auto unread = community.unread;
jobject serialized = env->NewObject(clazz, constructor, base_url, room, pubkey_jarray, last_read, unread); jobject serialized = env->NewObject(clazz, constructor, base_url, room, pubkey_jarray, last_read, unread);
return serialized; return serialized;
} }
inline jobject serialize_legacy_group(JNIEnv *env, session::config::convo::legacy_closed_group legacy_group) { inline jobject serialize_legacy_group(JNIEnv *env, session::config::convo::legacy_group group) {
jclass clazz = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$LegacyClosedGroup"); jclass clazz = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$LegacyGroup");
jmethodID constructor = env->GetMethodID(clazz, "<init>", "(Ljava/lang/String;JZ)V"); jmethodID constructor = env->GetMethodID(clazz, "<init>", "(Ljava/lang/String;JZ)V");
auto group_id = env->NewStringUTF(legacy_group.id.data()); auto group_id = env->NewStringUTF(group.id.data());
auto last_read = legacy_group.last_read; auto last_read = group.last_read;
auto unread = legacy_group.unread; auto unread = group.unread;
jobject serialized = env->NewObject(clazz, constructor, group_id, last_read, unread); jobject serialized = env->NewObject(clazz, constructor, group_id, last_read, unread);
return serialized; return serialized;
} }
@ -47,9 +47,9 @@ inline jobject serialize_legacy_group(JNIEnv *env, session::config::convo::legac
inline jobject serialize_any(JNIEnv *env, session::config::convo::any any) { inline jobject serialize_any(JNIEnv *env, session::config::convo::any any) {
if (auto* dm = std::get_if<session::config::convo::one_to_one>(&any)) { if (auto* dm = std::get_if<session::config::convo::one_to_one>(&any)) {
return serialize_one_to_one(env, *dm); return serialize_one_to_one(env, *dm);
} else if (auto* og = std::get_if<session::config::convo::open_group>(&any)) { } else if (auto* og = std::get_if<session::config::convo::community>(&any)) {
return serialize_open_group(env, *og); return serialize_open_group(env, *og);
} else if (auto* lgc = std::get_if<session::config::convo::legacy_closed_group>(&any)) { } else if (auto* lgc = std::get_if<session::config::convo::legacy_group>(&any)) {
return serialize_legacy_group(env, *lgc); return serialize_legacy_group(env, *lgc);
} }
return nullptr; return nullptr;
@ -70,8 +70,8 @@ inline session::config::convo::one_to_one* deserialize_one_to_one(JNIEnv *env, j
return deserialized; return deserialized;
} }
inline session::config::convo::open_group* deserialize_open_group(JNIEnv *env, jobject info) { inline session::config::convo::community* deserialize_open_group(JNIEnv *env, jobject info) {
auto clazz = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$OpenGroup"); auto clazz = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$Community");
auto url_getter = env->GetFieldID(clazz, "baseUrl", "Ljava/lang/String;"); auto url_getter = env->GetFieldID(clazz, "baseUrl", "Ljava/lang/String;");
auto room_getter = env->GetFieldID(clazz, "room", "Ljava/lang/String;"); auto room_getter = env->GetFieldID(clazz, "room", "Ljava/lang/String;");
auto pub_key_getter = env->GetFieldID(clazz, "pubKey", "[B"); auto pub_key_getter = env->GetFieldID(clazz, "pubKey", "[B");
@ -86,7 +86,7 @@ inline session::config::convo::open_group* deserialize_open_group(JNIEnv *env, j
auto room_string = std::string {room_bytes}; auto room_string = std::string {room_bytes};
auto pub_key_ustring = util::ustring_from_bytes(env, pub_key); auto pub_key_ustring = util::ustring_from_bytes(env, pub_key);
auto deserialized = new session::config::convo::open_group(base_string, room_string,pub_key_ustring); auto deserialized = new session::config::convo::community(base_string, room_string,pub_key_ustring);
deserialized->last_read = env->GetLongField(info, last_read_getter); deserialized->last_read = env->GetLongField(info, last_read_getter);
deserialized->unread = env->GetBooleanField(info, unread_getter); deserialized->unread = env->GetBooleanField(info, unread_getter);
env->ReleaseStringUTFChars(base_url, base_bytes); env->ReleaseStringUTFChars(base_url, base_bytes);
@ -94,15 +94,15 @@ inline session::config::convo::open_group* deserialize_open_group(JNIEnv *env, j
return deserialized; return deserialized;
} }
inline session::config::convo::legacy_closed_group* deserialize_legacy_closed_group(JNIEnv *env, jobject info) { inline session::config::convo::legacy_group* deserialize_legacy_closed_group(JNIEnv *env, jobject info) {
auto clazz = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$LegacyClosedGroup"); auto clazz = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$LegacyGroup");
auto group_id_getter = env->GetFieldID(clazz, "groupId", "Ljava/lang/String;"); auto group_id_getter = env->GetFieldID(clazz, "groupId", "Ljava/lang/String;");
auto last_read_getter = env->GetFieldID(clazz, "lastRead", "J"); auto last_read_getter = env->GetFieldID(clazz, "lastRead", "J");
auto unread_getter = env->GetFieldID(clazz, "unread", "Z"); auto unread_getter = env->GetFieldID(clazz, "unread", "Z");
auto group_id = static_cast<jstring>(env->GetObjectField(info, group_id_getter)); auto group_id = static_cast<jstring>(env->GetObjectField(info, group_id_getter));
auto group_id_bytes = env->GetStringUTFChars(group_id, nullptr); auto group_id_bytes = env->GetStringUTFChars(group_id, nullptr);
auto group_id_string = std::string{group_id_bytes}; auto group_id_string = std::string{group_id_bytes};
auto deserialized = new session::config::convo::legacy_closed_group(group_id_string); auto deserialized = new session::config::convo::legacy_group(group_id_string);
deserialized->last_read = env->GetLongField(info, last_read_getter); deserialized->last_read = env->GetLongField(info, last_read_getter);
deserialized->unread = env->GetBooleanField(info, unread_getter); deserialized->unread = env->GetBooleanField(info, unread_getter);
env->ReleaseStringUTFChars(group_id, group_id_bytes); env->ReleaseStringUTFChars(group_id, group_id_bytes);
@ -111,8 +111,8 @@ inline session::config::convo::legacy_closed_group* deserialize_legacy_closed_gr
inline session::config::convo::any* deserialize_any(JNIEnv *env, jobject convo) { inline session::config::convo::any* deserialize_any(JNIEnv *env, jobject convo) {
auto oto_class = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$OneToOne"); auto oto_class = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$OneToOne");
auto og_class = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$OpenGroup"); auto og_class = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$Community");
auto lgc_class = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$LegacyClosedGroup"); auto lgc_class = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$LegacyGroup");
auto object_class = env->GetObjectClass(convo); auto object_class = env->GetObjectClass(convo);
if (env->IsSameObject(object_class, oto_class)) { if (env->IsSameObject(object_class, oto_class)) {
return new session::config::convo::any{*deserialize_one_to_one(env, convo)}; return new session::config::convo::any{*deserialize_one_to_one(env, convo)};

View File

@ -91,16 +91,14 @@ class ConversationVolatileConfig(pointer: Long): ConfigBase(pointer) {
external fun getOrConstructOneToOne(pubKeyHex: String): Conversation.OneToOne external fun getOrConstructOneToOne(pubKeyHex: String): Conversation.OneToOne
external fun eraseOneToOne(pubKeyHex: String): Boolean external fun eraseOneToOne(pubKeyHex: String): Boolean
external fun getOpenGroup(baseUrl: String, room: String, pubKeyHex: String): Conversation.OpenGroup? external fun getCommunity(baseUrl: String, room: String): Conversation.Community?
external fun getOpenGroup(baseUrl: String, room: String, pubKey: ByteArray): Conversation.OpenGroup? external fun getOrConstructCommunity(baseUrl: String, room: String, pubKeyHex: String): Conversation.Community
external fun getOrConstructOpenGroup(baseUrl: String, room: String, pubKeyHex: String): Conversation.OpenGroup external fun getOrConstructCommunity(baseUrl: String, room: String, pubKey: ByteArray): Conversation.Community
external fun getOrConstructOpenGroup(baseUrl: String, room: String, pubKey: ByteArray): Conversation.OpenGroup external fun eraseCommunity(community: Conversation.Community): Boolean
external fun eraseOpenGroup(openGroup: Conversation.OpenGroup): Boolean external fun eraseCommunity(baseUrl: String, room: String): Boolean
external fun eraseOpenGroup(baseUrl: String, room: String, pubKeyHex: String): Boolean
external fun eraseOpenGroup(baseUrl: String, room: String, pubKey: ByteArray): Boolean
external fun getLegacyClosedGroup(groupId: String): Conversation.LegacyClosedGroup? external fun getLegacyClosedGroup(groupId: String): Conversation.LegacyGroup?
external fun getOrConstructLegacyClosedGroup(groupId: String): Conversation.LegacyClosedGroup external fun getOrConstructLegacyClosedGroup(groupId: String): Conversation.LegacyGroup
external fun eraseLegacyClosedGroup(groupId: String): Boolean external fun eraseLegacyClosedGroup(groupId: String): Boolean
external fun erase(conversation: Conversation): Boolean external fun erase(conversation: Conversation): Boolean
@ -112,15 +110,15 @@ class ConversationVolatileConfig(pointer: Long): ConfigBase(pointer) {
external fun eraseAll(predicate: (Conversation) -> Boolean): Int external fun eraseAll(predicate: (Conversation) -> Boolean): Int
external fun sizeOneToOnes(): Int external fun sizeOneToOnes(): Int
external fun sizeOpenGroups(): Int external fun sizeCommunities(): Int
external fun sizeLegacyClosedGroups(): Int external fun sizeLegacyClosedGroups(): Int
external fun size(): Int external fun size(): Int
external fun empty(): Boolean external fun empty(): Boolean
external fun allOneToOnes(): List<Conversation.OneToOne> external fun allOneToOnes(): List<Conversation.OneToOne>
external fun allOpenGroups(): List<Conversation.OpenGroup> external fun allCommunities(): List<Conversation.Community>
external fun allLegacyClosedGroups(): List<Conversation.LegacyClosedGroup> external fun allLegacyClosedGroups(): List<Conversation.LegacyGroup>
external fun all(): List<Conversation> external fun all(): List<Conversation>
} }

View File

@ -13,7 +13,7 @@ sealed class Conversation {
override var unread: Boolean override var unread: Boolean
): Conversation() ): Conversation()
data class OpenGroup( data class Community(
val baseUrl: String, val baseUrl: String,
val room: String, // lowercase val room: String, // lowercase
val pubKey: ByteArray, val pubKey: ByteArray,
@ -34,7 +34,7 @@ sealed class Conversation {
if (this === other) return true if (this === other) return true
if (javaClass != other?.javaClass) return false if (javaClass != other?.javaClass) return false
other as OpenGroup other as Community
if (baseUrl != other.baseUrl) return false if (baseUrl != other.baseUrl) return false
if (room != other.room) return false if (room != other.room) return false
@ -53,7 +53,7 @@ sealed class Conversation {
} }
} }
data class LegacyClosedGroup( data class LegacyGroup(
val groupId: String, val groupId: String,
override var lastRead: Long, override var lastRead: Long,
override var unread: Boolean override var unread: Boolean

View File

@ -1,9 +1,9 @@
package org.session.libsession.utilities package org.session.libsession.utilities
import org.junit.Assert.assertEquals
import org.junit.Test import org.junit.Test
import org.junit.Assert.*
class OpenGroupUrlParserTest { class CommunityUrlParserTest {
@Test @Test
fun parseUrlTest() { fun parseUrlTest() {