From 5356b15a5001923760cf0b1bf34295b0dde95ac6 Mon Sep 17 00:00:00 2001 From: SessionHero01 Date: Tue, 2 Dec 2025 15:04:16 +1100 Subject: [PATCH 1/3] Update libsession-util and adjust APIs --- library/src/main/cpp/protocol.cpp | 39 +------------------ .../protocol/ProFeaturesForMsg.kt | 24 ------------ .../protocol/SessionProtocol.kt | 16 +------- libsession-util | 2 +- 4 files changed, 4 insertions(+), 77 deletions(-) delete mode 100644 library/src/main/java/network/loki/messenger/libsession_util/protocol/ProFeaturesForMsg.kt diff --git a/library/src/main/cpp/protocol.cpp b/library/src/main/cpp/protocol.cpp index 0472b22..af595d6 100644 --- a/library/src/main/cpp/protocol.cpp +++ b/library/src/main/cpp/protocol.cpp @@ -142,7 +142,7 @@ Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_encodeForG extern "C" JNIEXPORT jobject JNICALL Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_decodeForCommunity( - JNIEnv *env, jobject thiz, jbyteArray payload, jlong now_epoch_ms, + JNIEnv *env, jobject thiz, jbyteArray payload, jlong timestamp_ms, jbyteArray pro_backend_pub_key) { return run_catching_cxx_exception_or_throws(env, [=] { jni_utils::JavaByteArrayRef payload_ref(env, payload); @@ -150,7 +150,7 @@ Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_decodeForC auto decoded = session::decode_for_community( payload_ref.get(), std::chrono::sys_time{ - std::chrono::milliseconds{now_epoch_ms}}, + std::chrono::milliseconds{timestamp_ms}}, *java_to_cpp_array<32>(env, pro_backend_pub_key) ); @@ -194,7 +194,6 @@ Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_decodeFor1 jobject thiz, jbyteArray key, jbyteArray payload, - jlong now_epoch_ms, jbyteArray pro_backend_pub_key) { return run_catching_cxx_exception_or_throws(env, [=] { JavaByteArrayRef key_ref(env, key); @@ -208,8 +207,6 @@ Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_decodeFor1 return serializeDecodedEnvelope(env, session::decode_envelope( decode_key, JavaByteArrayRef(env, payload).get(), - std::chrono::sys_time{ - std::chrono::milliseconds{now_epoch_ms}}, *java_to_cpp_array<32>(env, pro_backend_pub_key) )).release(); }); @@ -222,7 +219,6 @@ Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_decodeForG jobject thiz, jbyteArray payload, jbyteArray my_ed25519_priv_key, - jlong now_epoch_ms, jbyteArray group_ed25519_public_key, jobjectArray group_ed25519_private_keys, jbyteArray pro_backend_pub_key) { @@ -245,38 +241,7 @@ Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_decodeForG return serializeDecodedEnvelope(env, session::decode_envelope( decode_key, JavaByteArrayRef(env, payload).get(), - std::chrono::sys_time{ - std::chrono::milliseconds{now_epoch_ms}}, *java_to_cpp_array<32>(env, pro_backend_pub_key) )).release(); }); } - -extern "C" -JNIEXPORT jobject JNICALL -Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_proFeaturesForMessage( - JNIEnv *env, jobject thiz, jstring message_body) { - return run_catching_cxx_exception_or_throws(env, [=] { - JavaCharsRef message_ref(env, message_body); - - auto features = session::pro_features_for_utf16( - reinterpret_cast(message_ref.chars()), - message_ref.size() - ); - - static BasicJavaClassInfo class_info( - env, - "network/loki/messenger/libsession_util/protocol/ProFeaturesForMsg", - "(ILjava/lang/String;JI)V" - ); - - return env->NewObject( - class_info.java_class, - class_info.constructor, - static_cast(features.status), - features.error.empty() ? nullptr : env->NewStringUTF(std::string(features.error).c_str()), - static_cast(features.bitset.data), - static_cast(features.codepoint_count) - ); - }); -} \ No newline at end of file diff --git a/library/src/main/java/network/loki/messenger/libsession_util/protocol/ProFeaturesForMsg.kt b/library/src/main/java/network/loki/messenger/libsession_util/protocol/ProFeaturesForMsg.kt deleted file mode 100644 index f73488e..0000000 --- a/library/src/main/java/network/loki/messenger/libsession_util/protocol/ProFeaturesForMsg.kt +++ /dev/null @@ -1,24 +0,0 @@ -package network.loki.messenger.libsession_util.protocol - -typealias ProFeaturesForMsgStatus = Int - -/** - * Represents the result of trying to augment a message with Pro features. - * - * @param status The status of the augmentation attempt. - * @param error An optional error message if the augmentation failed. - * @param features The Pro features that were successfully applied. - * @param codepointCount The number of codepoints in the message - */ -data class ProFeaturesForMsg( - val status: ProFeaturesForMsgStatus, - val error: String?, - val features: ProMessageFeatures, - val codepointCount: Int, -) { - companion object { - const val SUCCESS: ProFeaturesForMsgStatus = 0 - const val UTF_DECODING_ERROR: ProFeaturesForMsgStatus = 1 - const val EXCEEDS_CHARACTER_LIMIT: ProFeaturesForMsgStatus = 2 - } -} diff --git a/library/src/main/java/network/loki/messenger/libsession_util/protocol/SessionProtocol.kt b/library/src/main/java/network/loki/messenger/libsession_util/protocol/SessionProtocol.kt index 667b459..d329749 100644 --- a/library/src/main/java/network/loki/messenger/libsession_util/protocol/SessionProtocol.kt +++ b/library/src/main/java/network/loki/messenger/libsession_util/protocol/SessionProtocol.kt @@ -14,7 +14,6 @@ object SessionProtocol : LibSessionUtilCApi() { external fun decodeFor1o1( myEd25519PrivKey: ByteArray, payload: ByteArray, - nowEpochMs: Long, proBackendPubKey: ByteArray, // 32 bytes backend key ): DecodedEnvelope @@ -34,7 +33,7 @@ object SessionProtocol : LibSessionUtilCApi() { external fun decodeForCommunity( payload: ByteArray, - nowEpochMs: Long, + timestampMs: Long, proBackendPubKey: ByteArray, // 32 bytes backend key ): DecodedCommunityMessage @@ -50,21 +49,8 @@ object SessionProtocol : LibSessionUtilCApi() { external fun decodeForGroup( payload: ByteArray, myEd25519PrivKey: ByteArray, - nowEpochMs: Long, groupEd25519PublicKey: ByteArray, // 33 bytes 03 prefixed key groupEd25519PrivateKeys: Array, // all available group private keys proBackendPubKey: ByteArray, // 32 bytes backend key ): DecodedEnvelope - - private external fun proFeaturesForMessage( - messageBody: String, - proposedFeatures: Long - ): ProFeaturesForMsg - - /** - * Determines which Pro features shall be applied to a message based on its content and the proposed features. - */ - fun proFeaturesForMessage( - messageBody: String, - ): ProFeaturesForMsg = proFeaturesForMessage(messageBody) } \ No newline at end of file diff --git a/libsession-util b/libsession-util index dc3fc6b..d509d1d 160000 --- a/libsession-util +++ b/libsession-util @@ -1 +1 @@ -Subproject commit dc3fc6b9c1a734afd0c81b8cd177f2673e3632c6 +Subproject commit d509d1deb7b9d3948e916e2c8625fef523465dd6 From 9ba5089073a260c2451edcfe06479fcaeb64ccfc Mon Sep 17 00:00:00 2001 From: SessionHero01 Date: Tue, 2 Dec 2025 16:32:49 +1100 Subject: [PATCH 2/3] Bytes toString --- .../java/network/loki/messenger/libsession_util/util/Bytes.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/src/main/java/network/loki/messenger/libsession_util/util/Bytes.kt b/library/src/main/java/network/loki/messenger/libsession_util/util/Bytes.kt index 052597e..368ec66 100644 --- a/library/src/main/java/network/loki/messenger/libsession_util/util/Bytes.kt +++ b/library/src/main/java/network/loki/messenger/libsession_util/util/Bytes.kt @@ -18,6 +18,10 @@ class Bytes(val data: ByteArray) { return data.contentHashCode() } + override fun toString(): String { + return "Bytes(${data.size} bytes)" + } + companion object { fun ByteArray.toBytes(): Bytes { return Bytes(this) From 9fbc75fc1314a6c599a20d4b2c78e58d2a3a1c40 Mon Sep 17 00:00:00 2001 From: SessionHero01 Date: Wed, 3 Dec 2025 09:05:53 +1100 Subject: [PATCH 3/3] Not use gradle version catalog to integrate better --- build.gradle.kts | 8 +++++--- gradle/libs.versions.toml | 20 -------------------- library/build.gradle.kts | 29 +++++++++++++++-------------- settings.gradle.kts | 1 - 4 files changed, 20 insertions(+), 38 deletions(-) delete mode 100644 gradle/libs.versions.toml diff --git a/build.gradle.kts b/build.gradle.kts index eb3bad5..9d573f3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,8 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - alias(libs.plugins.android.library) apply false - alias(libs.plugins.kotlin.android) apply false - alias(libs.plugins.kotlinx.serialization) apply false + val kotlinVersion = "2.2.21" + + id("com.android.library") version "8.13.1" apply false + id("org.jetbrains.kotlin.android") version kotlinVersion apply false + id("org.jetbrains.kotlin.plugin.serialization") version kotlinVersion apply false } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml deleted file mode 100644 index cdbf11b..0000000 --- a/gradle/libs.versions.toml +++ /dev/null @@ -1,20 +0,0 @@ -[versions] -agp = "8.13.1" -kotlin = "2.2.21" -protobufVersion = "4.33.1" - -[libraries] -junit = { module = "junit:junit", version = "4.13.2" } -androidx-test-runner = { module = "androidx.test:runner", version = "1.7.0" } -androidx-test-rules = { module = "androidx.test:rules", version = "1.7.0" } -androidx-test-ext = { module = "androidx.test.ext:junit", version = "1.3.0" } -androidx-annotations = { module = "androidx.annotation:annotation", version = "1.9.1" } -kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version = "1.9.0" } -protoc = { module = "com.google.protobuf:protoc", version.ref = "protobufVersion" } -protobuf-java = { module = "com.google.protobuf:protobuf-java", version.ref = "protobufVersion" } - -[plugins] -android-library = { id = "com.android.library", version.ref = "agp" } -kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } -kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } -protobuf-compiler = { id = "com.google.protobuf", version = "0.9.5" } \ No newline at end of file diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 42eb3bb..a57535c 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -1,18 +1,18 @@ -import com.google.protobuf.gradle.id import org.jetbrains.kotlin.gradle.dsl.JvmTarget plugins { - alias(libs.plugins.android.library) - alias(libs.plugins.kotlin.android) - alias(libs.plugins.kotlinx.serialization) + id("com.android.library") + id("org.jetbrains.kotlin.android") + id("org.jetbrains.kotlin.plugin.serialization") id("maven-publish") - - alias(libs.plugins.protobuf.compiler) + id("com.google.protobuf") version "0.9.5" } group = "org.sessionfoundation" version = System.getenv("VERSION") ?: "dev-snapshot" +val protobufVersion = "4.33.1" + android { namespace = "org.sessionfoundation.libsession_util" compileSdk = 35 @@ -81,7 +81,7 @@ kotlin { protobuf { protoc { - artifact = libs.protoc.get().toString() + artifact = "com.google.protobuf:protoc:$protobufVersion" } plugins { @@ -133,15 +133,16 @@ publishing { } dependencies { - androidTestImplementation(libs.junit) - androidTestImplementation(libs.androidx.test.runner) - androidTestImplementation(libs.androidx.test.rules) - androidTestImplementation(libs.androidx.test.ext) - implementation(libs.androidx.annotations) - implementation(libs.kotlinx.serialization.core) + androidTestImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test:runner:1.7.0") + androidTestImplementation("androidx.test:rules:1.7.0") + androidTestImplementation("androidx.test.ext:junit:1.3.0") + + implementation("androidx.annotation:annotation:1.9.1") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.9.0") - api(libs.protobuf.java) + api("com.google.protobuf:protobuf-java:$protobufVersion") protobuf(files("../libsession-util/proto/SessionProtos.proto")) } diff --git a/settings.gradle.kts b/settings.gradle.kts index 801b4a5..f26c1a1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -19,7 +19,6 @@ dependencyResolutionManagement { } } -rootProject.name = "libsession-util-android" include(":library") project(":library").name = "libsession-util-android" \ No newline at end of file