mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 20:45:17 +00:00
feat: adding more serialize deserialize to legacy closed groups
This commit is contained in:
parent
1e43ef7318
commit
4adf251c45
@ -12,15 +12,35 @@ inline session::config::UserGroups* ptrToUserGroups(JNIEnv *env, jobject obj) {
|
|||||||
return (session::config::UserGroups*) env->GetLongField(obj, pointerField);
|
return (session::config::UserGroups*) env->GetLongField(obj, pointerField);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
inline void deserialize_members_into(JNIEnv *env, jobject members_map, session::config::legacy_group_info *to_append_group) {
|
||||||
val sessionId: String,
|
jclass map_class = env->FindClass("java/util/Map");
|
||||||
val name: String,
|
jclass map_entry_class = env->FindClass("java/util/Map$Entry");
|
||||||
val members: Map<String, Boolean>,
|
jclass set_class = env->FindClass("java/util/Set");
|
||||||
val hidden: Boolean,
|
jclass iterator_class = env->FindClass("java/util/Iterator");
|
||||||
val encPubKey: String,
|
jclass boxed_bool = env->FindClass("java/lang/Boolean");
|
||||||
val encSecKey: String,
|
|
||||||
val priority: Int
|
jmethodID get_entry_set = env->GetMethodID(map_class, "entrySet", "()Ljava/util/Set;");
|
||||||
*/
|
jmethodID get_at = env->GetMethodID(set_class, "iterator", "()Ljava/util/Iterator;");
|
||||||
|
jmethodID has_next = env->GetMethodID(iterator_class, "hasNext", "()Z");
|
||||||
|
jmethodID next = env->GetMethodID(iterator_class, "next", "()Ljava/lang/Object;");
|
||||||
|
jmethodID get_key = env->GetMethodID(map_entry_class, "getKey", "()Ljava/lang/Object;");
|
||||||
|
jmethodID get_value = env->GetMethodID(map_entry_class, "getValue", "()Ljava/lang/Object;");
|
||||||
|
jmethodID get_bool_value = env->GetMethodID(boxed_bool, "booleanValue", "()Z");
|
||||||
|
|
||||||
|
jobject entry_set = env->CallObjectMethod(members_map, get_entry_set);
|
||||||
|
jobject iterator = env->CallObjectMethod(entry_set, get_at);
|
||||||
|
|
||||||
|
while (env->CallBooleanMethod(iterator, has_next)) {
|
||||||
|
jobject entry = env->CallObjectMethod(iterator, next);
|
||||||
|
jstring key = static_cast<jstring>(env->CallObjectMethod(entry, get_key));
|
||||||
|
jobject boxed = env->CallObjectMethod(entry, get_value);
|
||||||
|
bool is_admin = env->CallBooleanMethod(boxed, get_bool_value);
|
||||||
|
auto member_string = env->GetStringUTFChars(key, nullptr);
|
||||||
|
to_append_group->insert(member_string, is_admin);
|
||||||
|
env->ReleaseStringUTFChars(key, member_string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline session::config::legacy_group_info* deserialize_legacy_group_info(JNIEnv *env, jobject info) {
|
inline session::config::legacy_group_info* deserialize_legacy_group_info(JNIEnv *env, jobject info) {
|
||||||
auto clazz = env->FindClass("network/loki/messenger/libsession_util/util/GroupInfo$LegacyGroupInfo");
|
auto clazz = env->FindClass("network/loki/messenger/libsession_util/util/GroupInfo$LegacyGroupInfo");
|
||||||
auto id_field = env->GetFieldID(clazz, "sessionId", "Ljava/lang/String;");
|
auto id_field = env->GetFieldID(clazz, "sessionId", "Ljava/lang/String;");
|
||||||
@ -46,7 +66,9 @@ inline session::config::legacy_group_info* deserialize_legacy_group_info(JNIEnv
|
|||||||
auto info_deserialized = new session::config::legacy_group_info(id_bytes);
|
auto info_deserialized = new session::config::legacy_group_info(id_bytes);
|
||||||
|
|
||||||
info_deserialized->priority = priority;
|
info_deserialized->priority = priority;
|
||||||
// TODO: iterate over map and insert as admins
|
deserialize_members_into(env, members_map, info_deserialized);
|
||||||
|
info_deserialized->name = name_bytes;
|
||||||
|
info_deserialized->hidden = hidden;
|
||||||
info_deserialized->enc_pubkey = enc_pub_key_bytes;
|
info_deserialized->enc_pubkey = enc_pub_key_bytes;
|
||||||
info_deserialized->enc_seckey = enc_sec_key_bytes;
|
info_deserialized->enc_seckey = enc_sec_key_bytes;
|
||||||
env->ReleaseStringUTFChars(id, id_bytes);
|
env->ReleaseStringUTFChars(id, id_bytes);
|
||||||
@ -54,15 +76,26 @@ inline session::config::legacy_group_info* deserialize_legacy_group_info(JNIEnv
|
|||||||
return info_deserialized;
|
return info_deserialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::map<std::string, bool> deserialize_members(JNIEnv *env, jobject members_map) {
|
inline jobject serialize_members(JNIEnv *env, std::map<std::string, bool> members_map) {
|
||||||
|
jclass map_class = env->FindClass("java/util/HashMap");
|
||||||
|
jclass boxed_bool = env->FindClass("java/lang/Boolean");
|
||||||
|
jmethodID map_constructor = env->GetMethodID(map_class, "<init>", "()V");
|
||||||
|
jmethodID insert = env->GetMethodID(map_class, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
|
||||||
|
jmethodID new_bool = env->GetMethodID(boxed_bool, "<init>", "(Z)V");
|
||||||
|
|
||||||
}
|
jobject new_map = env->NewObject(map_class, map_constructor);
|
||||||
|
for (auto it = members_map.begin(); it != members_map.end(); it++) {
|
||||||
inline jobject serialize_legacy_group_info(JNIEnv *env, session::config::legacy_group_info info) {
|
auto session_id = env->NewStringUTF(it->first.data());
|
||||||
|
bool is_admin = it->second;
|
||||||
|
auto jbool = env->NewObject(boxed_bool, new_bool, is_admin);
|
||||||
|
env->CallObjectMethod(new_map, insert, session_id, jbool);
|
||||||
|
++it;
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline jobject serialize_members(JNIEnv *env, std::map<std::string, bool> members_map) {
|
inline jobject serialize_legacy_group_info(JNIEnv *env, session::config::legacy_group_info info) {
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,12 +11,40 @@ sealed class GroupInfo {
|
|||||||
val hidden: Boolean,
|
val hidden: Boolean,
|
||||||
val encPubKey: ByteArray,
|
val encPubKey: ByteArray,
|
||||||
val encSecKey: ByteArray,
|
val encSecKey: ByteArray,
|
||||||
val priority: Int
|
val priority: Int = 0
|
||||||
): GroupInfo() {
|
): GroupInfo() {
|
||||||
companion object {
|
companion object {
|
||||||
@Suppress("FunctionName")
|
@Suppress("FunctionName")
|
||||||
external fun NAME_MAX_LENGTH(): Int
|
external fun NAME_MAX_LENGTH(): Int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as LegacyGroupInfo
|
||||||
|
|
||||||
|
if (sessionId != other.sessionId) return false
|
||||||
|
if (name != other.name) return false
|
||||||
|
if (members != other.members) return false
|
||||||
|
if (hidden != other.hidden) return false
|
||||||
|
if (!encPubKey.contentEquals(other.encPubKey)) return false
|
||||||
|
if (!encSecKey.contentEquals(other.encSecKey)) return false
|
||||||
|
if (priority != other.priority) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = sessionId.hashCode()
|
||||||
|
result = 31 * result + name.hashCode()
|
||||||
|
result = 31 * result + members.hashCode()
|
||||||
|
result = 31 * result + hidden.hashCode()
|
||||||
|
result = 31 * result + encPubKey.contentHashCode()
|
||||||
|
result = 31 * result + encSecKey.contentHashCode()
|
||||||
|
result = 31 * result + priority
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user