mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-25 02:46:20 +00:00
feat: add contacts expiry serialization/deserialization, more LGC, timestamps to add closed group encryption info (for latest tracking)
This commit is contained in:
@@ -13,8 +13,7 @@ inline session::config::Contacts *ptrToContacts(JNIEnv *env, jobject obj) {
|
||||
|
||||
inline jobject serialize_contact(JNIEnv *env, session::config::contact_info info) {
|
||||
jclass contactClass = env->FindClass("network/loki/messenger/libsession_util/util/Contact");
|
||||
jmethodID constructor = env->GetMethodID(contactClass, "<init>",
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZLnetwork/loki/messenger/libsession_util/util/UserPic;I)V");
|
||||
jmethodID constructor = env->GetMethodID(contactClass, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZLnetwork/loki/messenger/libsession_util/util/UserPic;ILnetwork/loki/messenger/libsession_util/util/ExpiryMode;)V");
|
||||
jstring id = env->NewStringUTF(info.session_id.data());
|
||||
jstring name = env->NewStringUTF(info.name.data());
|
||||
jstring nickname = env->NewStringUTF(info.nickname.data());
|
||||
@@ -23,22 +22,27 @@ inline jobject serialize_contact(JNIEnv *env, session::config::contact_info info
|
||||
approvedMe = info.approved_me;
|
||||
blocked = info.blocked;
|
||||
jobject profilePic = util::serialize_user_pic(env, info.profile_picture);
|
||||
jobject returnObj = env->NewObject(contactClass, constructor, id, name, nickname, approved, approvedMe, blocked, profilePic, info.priority);
|
||||
jobject returnObj = env->NewObject(contactClass, constructor, id, name, nickname, approved,
|
||||
approvedMe, blocked, profilePic, info.priority,
|
||||
util::serialize_expiry(env, info.exp_mode, info.exp_timer));
|
||||
return returnObj;
|
||||
}
|
||||
|
||||
inline session::config::contact_info deserialize_contact(JNIEnv *env, jobject info, session::config::Contacts *conf) {
|
||||
inline session::config::contact_info
|
||||
deserialize_contact(JNIEnv *env, jobject info, session::config::Contacts *conf) {
|
||||
jclass contactClass = env->FindClass("network/loki/messenger/libsession_util/util/Contact");
|
||||
|
||||
jfieldID getId, getName, getNick, getApproved, getApprovedMe, getBlocked, getUserPic, getPriority;
|
||||
jfieldID getId, getName, getNick, getApproved, getApprovedMe, getBlocked, getUserPic, getPriority, getExpiry;
|
||||
getId = env->GetFieldID(contactClass, "id", "Ljava/lang/String;");
|
||||
getName = env->GetFieldID(contactClass, "name", "Ljava/lang/String;");
|
||||
getNick = env->GetFieldID(contactClass, "nickname", "Ljava/lang/String;");
|
||||
getApproved = env->GetFieldID(contactClass, "approved", "Z");
|
||||
getApprovedMe = env->GetFieldID(contactClass, "approvedMe", "Z");
|
||||
getBlocked = env->GetFieldID(contactClass, "blocked", "Z");
|
||||
getUserPic = env->GetFieldID(contactClass, "profilePicture", "Lnetwork/loki/messenger/libsession_util/util/UserPic;");
|
||||
getUserPic = env->GetFieldID(contactClass, "profilePicture",
|
||||
"Lnetwork/loki/messenger/libsession_util/util/UserPic;");
|
||||
getPriority = env->GetFieldID(contactClass, "priority", "I");
|
||||
getExpiry = env->GetFieldID(contactClass, "expiryMode", "Lnetwork/loki/messenger/libsession_util/util/ExpiryMode;");
|
||||
jstring name, nickname, session_id;
|
||||
session_id = static_cast<jstring>(env->GetObjectField(info, getId));
|
||||
name = static_cast<jstring>(env->GetObjectField(info, getName));
|
||||
@@ -49,6 +53,9 @@ inline session::config::contact_info deserialize_contact(JNIEnv *env, jobject in
|
||||
approvedMe = env->GetBooleanField(info, getApprovedMe);
|
||||
blocked = env->GetBooleanField(info, getBlocked);
|
||||
jobject user_pic = env->GetObjectField(info, getUserPic);
|
||||
jobject expiry_mode = env->GetObjectField(info, getExpiry);
|
||||
|
||||
auto expiry_pair = util::deserialize_expiry(env, expiry_mode);
|
||||
|
||||
std::string url;
|
||||
session::ustring key;
|
||||
@@ -91,6 +98,8 @@ inline session::config::contact_info deserialize_contact(JNIEnv *env, jobject in
|
||||
}
|
||||
|
||||
contact_info.priority = priority;
|
||||
contact_info.exp_mode = expiry_pair.first;
|
||||
contact_info.exp_timer = std::chrono::seconds(expiry_pair.second);
|
||||
|
||||
return contact_info;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ inline session::config::legacy_group_info deserialize_legacy_group_info(JNIEnv *
|
||||
auto enc_pub_key_field = env->GetFieldID(clazz, "encPubKey", "[B");
|
||||
auto enc_sec_key_field = env->GetFieldID(clazz, "encSecKey", "[B");
|
||||
auto priority_field = env->GetFieldID(clazz, "priority", "I");
|
||||
auto disappearing_timer_field = env->GetFieldID(clazz, "disappearingTimer", "J");
|
||||
jstring id = static_cast<jstring>(env->GetObjectField(info, id_field));
|
||||
jstring name = static_cast<jstring>(env->GetObjectField(info, name_field));
|
||||
jobject members_map = env->GetObjectField(info, members_field);
|
||||
@@ -72,8 +73,7 @@ inline session::config::legacy_group_info deserialize_legacy_group_info(JNIEnv *
|
||||
info_deserialized.hidden = hidden;
|
||||
info_deserialized.enc_pubkey = enc_pub_key_bytes;
|
||||
info_deserialized.enc_seckey = enc_sec_key_bytes;
|
||||
// TODO: this
|
||||
// info_deserialized.disappearing_timer
|
||||
info_deserialized.disappearing_timer = std::chrono::seconds(env->GetLongField(info, disappearing_timer_field));
|
||||
env->ReleaseStringUTFChars(id, id_bytes);
|
||||
env->ReleaseStringUTFChars(name, name_bytes);
|
||||
return info_deserialized;
|
||||
@@ -119,8 +119,8 @@ inline jobject serialize_legacy_group_info(JNIEnv *env, session::config::legacy_
|
||||
bool hidden = info.hidden;
|
||||
|
||||
jclass legacy_group_class = env->FindClass("network/loki/messenger/libsession_util/util/GroupInfo$LegacyGroupInfo");
|
||||
jmethodID constructor = env->GetMethodID(legacy_group_class, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Z[B[BI)V");
|
||||
jobject serialized = env->NewObject(legacy_group_class, constructor, session_id, name, members, hidden, enc_pubkey, enc_seckey, priority);
|
||||
jmethodID constructor = env->GetMethodID(legacy_group_class, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Z[B[BIJ)V");
|
||||
jobject serialized = env->NewObject(legacy_group_class, constructor, session_id, name, members, hidden, enc_pubkey, enc_seckey, priority, (jlong) info.disappearing_timer.count());
|
||||
return serialized;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,40 @@ namespace util {
|
||||
return community;
|
||||
}
|
||||
|
||||
jobject serialize_expiry(JNIEnv *env, const session::config::expiration_mode& mode, const std::chrono::seconds& time_seconds) {
|
||||
jclass none = env->FindClass("network/loki/messenger/libsession_util/util/ExpiryMode$NONE");
|
||||
jfieldID none_instance = env->GetStaticFieldID(none, "INSTANCE", "Lnetwork/loki/messenger/libsession_util/util/ExpiryMode$NONE;");
|
||||
jclass after_send = env->FindClass("network/loki/messenger/libsession_util/util/ExpiryMode$AfterSend");
|
||||
jmethodID send_init = env->GetMethodID(after_send, "<init>", "(J)V");
|
||||
jclass after_read = env->FindClass("network/loki/messenger/libsession_util/util/ExpiryMode$AfterRead");
|
||||
jmethodID read_init = env->GetMethodID(after_read, "<init>", "(J)V");
|
||||
|
||||
if (mode == session::config::expiration_mode::none) {
|
||||
return env->GetStaticObjectField(none, none_instance);
|
||||
} else if (mode == session::config::expiration_mode::after_send) {
|
||||
return env->NewObject(after_send, send_init, time_seconds.count());
|
||||
} else if (mode == session::config::expiration_mode::after_read) {
|
||||
return env->NewObject(after_read, read_init, time_seconds.count());
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::pair<session::config::expiration_mode, long> deserialize_expiry(JNIEnv *env, jobject expiry_mode) {
|
||||
jclass parent = env->FindClass("network/loki/messenger/libsession_util/util/ExpiryMode");
|
||||
jclass after_read = env->FindClass("network/loki/messenger/libsession_util/util/ExpiryMode$AfterRead");
|
||||
jclass after_send = env->FindClass("network/loki/messenger/libsession_util/util/ExpiryMode$AfterSend");
|
||||
jfieldID duration_seconds = env->GetFieldID(parent, "expirySeconds", "J");
|
||||
|
||||
jclass object_class = env->GetObjectClass(expiry_mode);
|
||||
|
||||
if (object_class == after_read) {
|
||||
return std::pair(session::config::expiration_mode::after_read, env->GetLongField(expiry_mode, duration_seconds));
|
||||
} else if (object_class == after_send) {
|
||||
return std::pair(session::config::expiration_mode::after_send, env->GetLongField(expiry_mode, duration_seconds));
|
||||
}
|
||||
return std::pair(session::config::expiration_mode::none, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern "C"
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "session/types.hpp"
|
||||
#include "session/config/profile_pic.hpp"
|
||||
#include "session/config/user_groups.hpp"
|
||||
#include "session/config/expiring.hpp"
|
||||
|
||||
namespace util {
|
||||
jbyteArray bytes_from_ustring(JNIEnv* env, session::ustring_view from_str);
|
||||
@@ -15,6 +16,8 @@ namespace util {
|
||||
std::pair<jstring, jbyteArray> deserialize_user_pic(JNIEnv *env, jobject user_pic);
|
||||
jobject serialize_base_community(JNIEnv *env, const session::config::community& base_community);
|
||||
session::config::community deserialize_base_community(JNIEnv *env, jobject base_community);
|
||||
jobject serialize_expiry(JNIEnv *env, const session::config::expiration_mode& mode, const std::chrono::seconds& time_seconds);
|
||||
std::pair<session::config::expiration_mode, long> deserialize_expiry(JNIEnv *env, jobject expiry_mode);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -2,11 +2,12 @@ package network.loki.messenger.libsession_util.util
|
||||
|
||||
data class Contact(
|
||||
val id: String,
|
||||
var name: String = "",
|
||||
var nickname: String = "",
|
||||
var approved: Boolean = false,
|
||||
var approvedMe: Boolean = false,
|
||||
var blocked: Boolean = false,
|
||||
var profilePicture: UserPic = UserPic.DEFAULT,
|
||||
var priority: Int = 0
|
||||
val name: String = "",
|
||||
val nickname: String = "",
|
||||
val approved: Boolean = false,
|
||||
val approvedMe: Boolean = false,
|
||||
val blocked: Boolean = false,
|
||||
val profilePicture: UserPic = UserPic.DEFAULT,
|
||||
val priority: Int = 0,
|
||||
val expiryMode: ExpiryMode
|
||||
)
|
||||
@@ -1,7 +1,7 @@
|
||||
package network.loki.messenger.libsession_util.util
|
||||
|
||||
sealed class ExpiryMode(val expiryMinutes: Long) {
|
||||
sealed class ExpiryMode(val expirySeconds: Long) {
|
||||
object NONE: ExpiryMode(0)
|
||||
class AfterSend(minutes: Long): ExpiryMode(minutes)
|
||||
class AfterRead(minutes: Long): ExpiryMode(minutes)
|
||||
class AfterSend(seconds: Long): ExpiryMode(seconds)
|
||||
class AfterRead(seconds: Long): ExpiryMode(seconds)
|
||||
}
|
||||
@@ -11,7 +11,8 @@ sealed class GroupInfo {
|
||||
val hidden: Boolean,
|
||||
val encPubKey: ByteArray,
|
||||
val encSecKey: ByteArray,
|
||||
val priority: Int = 0
|
||||
val priority: Int = 0,
|
||||
val disappearingTimer: Long
|
||||
): GroupInfo() {
|
||||
companion object {
|
||||
@Suppress("FunctionName")
|
||||
|
||||
Reference in New Issue
Block a user