mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-18 07:14:01 +00:00
feat: incorporate hashes from library, more wrapper for user groups and serialization from c++
This commit is contained in:
Submodule libsession-util/libsession-util updated: c76d7e06f6...5a7569861d
@@ -120,29 +120,18 @@ Java_network_loki_messenger_libsession_1util_ConfigBase_00024Companion_kindFor(J
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_ConfigBase_removeObsoleteHashes(JNIEnv *env,
|
||||
jobject thiz,
|
||||
jobjectArray to_remove) {
|
||||
auto conf = ptrToConfigBase(env, thiz);
|
||||
size_t number = env->GetArrayLength(to_remove);
|
||||
for (int i = 0; i < number; i++) {
|
||||
auto jElement = (jstring) env->GetObjectArrayElement(to_remove, i);
|
||||
auto element_as_string = env->GetStringUTFChars(jElement, nullptr);
|
||||
// TODO: uncomment when this is re-implemented
|
||||
// conf->confirm_removed(element_as_string);
|
||||
env->ReleaseStringUTFChars(jElement, element_as_string);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_ConfigBase_obsoleteHashes(JNIEnv *env, jobject thiz) {
|
||||
Java_network_loki_messenger_libsession_1util_ConfigBase_currentHashes(JNIEnv *env, jobject thiz) {
|
||||
auto conf = ptrToConfigBase(env, thiz);
|
||||
jclass stack = env->FindClass("java/util/Stack");
|
||||
jmethodID init = env->GetMethodID(stack, "<init>", "()V");
|
||||
jobject our_stack = env->NewObject(stack, init);
|
||||
jmethodID push = env->GetMethodID(stack, "push", "(Ljava/lang/Object;)Ljava/lang/Object;");
|
||||
// TODO: implement obsoleteHashes()
|
||||
auto vec = conf->current_hashes();
|
||||
for (std::string element: vec) {
|
||||
env->CallObjectMethod(our_stack, push, env->NewStringUTF(element.data()));
|
||||
}
|
||||
return our_stack;
|
||||
}
|
@@ -14,7 +14,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;)V");
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZLnetwork/loki/messenger/libsession_util/util/UserPic;I)V");
|
||||
jstring id = env->NewStringUTF(info.session_id.data());
|
||||
jstring name = env->NewStringUTF(info.name.data());
|
||||
jstring nickname = env->NewStringUTF(info.nickname.data());
|
||||
@@ -23,14 +23,14 @@ 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);
|
||||
jobject returnObj = env->NewObject(contactClass, constructor, id, name, nickname, approved, approvedMe, blocked, profilePic, info.priority);
|
||||
return returnObj;
|
||||
}
|
||||
|
||||
inline session::config::contact_info* deserialize_contact(JNIEnv *env, jobject info) {
|
||||
jclass contactClass = env->FindClass("network/loki/messenger/libsession_util/util/Contact");
|
||||
|
||||
jfieldID getId, getName, getNick, getApproved, getApprovedMe, getBlocked, getUserPic;
|
||||
jfieldID getId, getName, getNick, getApproved, getApprovedMe, getBlocked, getUserPic, getPriority;
|
||||
getId = env->GetFieldID(contactClass, "id", "Ljava/lang/String;");
|
||||
getName = env->GetFieldID(contactClass, "name", "Ljava/lang/String;");
|
||||
getNick = env->GetFieldID(contactClass, "nickname", "Ljava/lang/String;");
|
||||
@@ -38,11 +38,13 @@ inline session::config::contact_info* deserialize_contact(JNIEnv *env, jobject i
|
||||
getApprovedMe = env->GetFieldID(contactClass, "approvedMe", "Z");
|
||||
getBlocked = env->GetFieldID(contactClass, "blocked", "Z");
|
||||
getUserPic = env->GetFieldID(contactClass, "profilePicture", "Lnetwork/loki/messenger/libsession_util/util/UserPic;");
|
||||
getPriority = env->GetFieldID(contactClass, "priority", "I");
|
||||
jstring name, nickname, session_id;
|
||||
session_id = static_cast<jstring>(env->GetObjectField(info, getId));
|
||||
name = static_cast<jstring>(env->GetObjectField(info, getName));
|
||||
nickname = static_cast<jstring>(env->GetObjectField(info, getNick));
|
||||
bool approved, approvedMe, blocked;
|
||||
int priority = env->GetIntField(info, getPriority);
|
||||
approved = env->GetBooleanField(info, getApproved);
|
||||
approvedMe = env->GetBooleanField(info, getApprovedMe);
|
||||
blocked = env->GetBooleanField(info, getBlocked);
|
||||
@@ -86,6 +88,8 @@ inline session::config::contact_info* deserialize_contact(JNIEnv *env, jobject i
|
||||
env->ReleaseStringUTFChars(nickname, nickname_bytes);
|
||||
}
|
||||
|
||||
contact_info->priority = priority;
|
||||
|
||||
return contact_info;
|
||||
}
|
||||
|
||||
|
@@ -31,8 +31,6 @@ Java_network_loki_messenger_libsession_1util_UserGroupsConfig_00024Companion_new
|
||||
jmethodID constructor = env->GetMethodID(contactsClass, "<init>", "(J)V");
|
||||
jobject newConfig = env->NewObject(contactsClass, constructor, reinterpret_cast<jlong>(user_groups));
|
||||
|
||||
user_groups->get_or_construct_legacy_group()
|
||||
|
||||
return newConfig;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
@@ -50,7 +48,21 @@ Java_network_loki_messenger_libsession_1util_UserGroupsConfig_getCommunityInfo(J
|
||||
jobject thiz,
|
||||
jstring base_url,
|
||||
jstring room) {
|
||||
auto conf = ptrToUserGroups(env, thiz);
|
||||
auto base_url_bytes = env->GetStringUTFChars(base_url, nullptr);
|
||||
auto room_bytes = env->GetStringUTFChars(room, nullptr);
|
||||
|
||||
auto community = conf->get_community(base_url_bytes, room_bytes);
|
||||
|
||||
jobject community_info = nullptr;
|
||||
|
||||
if (community) {
|
||||
serialize_legacy_group_info()
|
||||
}
|
||||
|
||||
// TODO: implement getCommunityInfo()
|
||||
env->ReleaseStringUTFChars(base_url, base_url_bytes);
|
||||
env->ReleaseStringUTFChars(room, room_bytes);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
|
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "jni.h"
|
||||
#include "util.h"
|
||||
#include "conversation.h"
|
||||
#include "session/config/user_groups.hpp"
|
||||
|
||||
inline session::config::UserGroups* ptrToUserGroups(JNIEnv *env, jobject obj) {
|
||||
@@ -51,4 +52,11 @@ inline jobject serialize_members(JNIEnv *env, std::map<std::string, bool> member
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline jobject serialize_community_info(JNIEnv *env, session::config::community_info info) {
|
||||
auto priority = info.priority;
|
||||
auto open_group = session::config::community::parse_full_url(info.full_url());
|
||||
auto serialized_community = serialize_open_group(env, (session::config::community) info);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#endif //SESSION_ANDROID_USER_GROUPS_H
|
||||
|
@@ -34,8 +34,7 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
|
||||
external fun encryptionDomain(): String
|
||||
external fun confirmPushed(seqNo: Long, newHash: String)
|
||||
external fun merge(toMerge: Array<Pair<String,ByteArray>>): Int
|
||||
external fun obsoleteHashes(): List<String>
|
||||
external fun removeObsoleteHashes(toRemove: Array<String>)
|
||||
external fun currentHashes(): List<String>
|
||||
|
||||
external fun configNamespace(): Int
|
||||
|
||||
|
@@ -7,5 +7,6 @@ data class Contact(
|
||||
var approved: Boolean = false,
|
||||
var approvedMe: Boolean = false,
|
||||
var blocked: Boolean = false,
|
||||
var profilePicture: UserPic = UserPic.DEFAULT
|
||||
var profilePicture: UserPic = UserPic.DEFAULT,
|
||||
var priority: Int
|
||||
)
|
Reference in New Issue
Block a user