2022-12-13 17:40:09 +11:00
|
|
|
#include "user_profile.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
extern "C" {
|
2022-12-14 11:37:43 +11:00
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma ide diagnostic ignored "bugprone-reserved-identifier"
|
2022-12-13 17:40:09 +11:00
|
|
|
JNIEXPORT jobject JNICALL
|
|
|
|
Java_network_loki_messenger_libsession_1util_UserProfile_00024Companion_newInstance___3B_3B(
|
|
|
|
JNIEnv *env, jobject thiz, jbyteArray ed25519_secret_key, jbyteArray initial_dump) {
|
|
|
|
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
|
|
|
|
auto initial = util::ustring_from_bytes(env, initial_dump);
|
|
|
|
auto* profile = new session::config::UserProfile(secret_key, std::optional(initial));
|
|
|
|
|
|
|
|
jclass userClass = env->FindClass("network/loki/messenger/libsession_util/UserProfile");
|
|
|
|
jmethodID constructor = env->GetMethodID(userClass, "<init>", "(J)V");
|
|
|
|
jobject newConfig = env->NewObject(userClass, constructor, reinterpret_cast<jlong>(profile));
|
|
|
|
|
|
|
|
return newConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jobject JNICALL
|
|
|
|
Java_network_loki_messenger_libsession_1util_UserProfile_00024Companion_newInstance___3B(
|
|
|
|
JNIEnv* env,
|
|
|
|
jobject,
|
|
|
|
jbyteArray secretKey) {
|
|
|
|
|
|
|
|
auto* profile = new session::config::UserProfile(util::ustring_from_bytes(env, secretKey), std::nullopt);
|
|
|
|
|
|
|
|
jclass userClass = env->FindClass("network/loki/messenger/libsession_util/UserProfile");
|
|
|
|
jmethodID constructor = env->GetMethodID(userClass, "<init>", "(J)V");
|
|
|
|
jobject newConfig = env->NewObject(userClass, constructor, reinterpret_cast<jlong>(profile));
|
|
|
|
|
|
|
|
return newConfig;
|
|
|
|
}
|
2022-12-14 11:37:43 +11:00
|
|
|
#pragma clang diagnostic pop
|
2022-12-13 17:40:09 +11:00
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_network_loki_messenger_libsession_1util_UserProfile_setName(
|
|
|
|
JNIEnv* env,
|
|
|
|
jobject thiz,
|
|
|
|
jstring newName) {
|
|
|
|
auto profile = ptrToProfile(env, thiz);
|
2022-12-16 16:00:38 +11:00
|
|
|
auto name_chars = env->GetStringUTFChars(newName, nullptr);
|
|
|
|
profile->set_name(name_chars);
|
|
|
|
env->ReleaseStringUTFChars(newName, name_chars);
|
2022-12-13 17:40:09 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
Java_network_loki_messenger_libsession_1util_UserProfile_getName(JNIEnv *env, jobject thiz) {
|
|
|
|
auto profile = ptrToProfile(env, thiz);
|
|
|
|
auto name = profile->get_name();
|
|
|
|
if (name == std::nullopt) return nullptr;
|
|
|
|
jstring returnString = env->NewStringUTF(name->data());
|
|
|
|
return returnString;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jobject JNICALL
|
|
|
|
Java_network_loki_messenger_libsession_1util_UserProfile_getPic(JNIEnv *env, jobject thiz) {
|
|
|
|
auto profile = ptrToProfile(env, thiz);
|
|
|
|
auto pic = profile->get_profile_pic();
|
|
|
|
|
|
|
|
jobject returnObject = util::serialize_user_pic(env, pic);
|
|
|
|
|
|
|
|
return returnObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_network_loki_messenger_libsession_1util_UserProfile_setPic(JNIEnv *env, jobject thiz,
|
|
|
|
jobject user_pic) {
|
|
|
|
auto profile = ptrToProfile(env, thiz);
|
|
|
|
auto pic = util::deserialize_user_pic(env, user_pic);
|
|
|
|
auto url = env->GetStringUTFChars(pic.first, nullptr);
|
|
|
|
auto key = util::ustring_from_bytes(env, pic.second);
|
|
|
|
profile->set_profile_pic(url, key);
|
2022-12-16 16:00:38 +11:00
|
|
|
env->ReleaseStringUTFChars(pic.first, url);
|
2022-12-13 17:40:09 +11:00
|
|
|
}
|
|
|
|
|
2023-03-03 16:41:57 +11:00
|
|
|
}
|
|
|
|
extern "C"
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_network_loki_messenger_libsession_1util_UserProfile_setNtsPriority(JNIEnv *env, jobject thiz,
|
|
|
|
jint priority) {
|
|
|
|
auto profile = ptrToProfile(env, thiz);
|
|
|
|
profile->set_nts_priority(priority);
|
|
|
|
}
|
|
|
|
extern "C"
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_network_loki_messenger_libsession_1util_UserProfile_setNtsHidden(JNIEnv *env, jobject thiz,
|
|
|
|
jboolean is_hidden) {
|
|
|
|
auto profile = ptrToProfile(env, thiz);
|
|
|
|
profile->set_nts_hidden(is_hidden);
|
2023-03-31 09:01:52 +11:00
|
|
|
}
|
|
|
|
extern "C"
|
|
|
|
JNIEXPORT jint JNICALL
|
|
|
|
Java_network_loki_messenger_libsession_1util_UserProfile_getNtsPriority(JNIEnv *env, jobject thiz) {
|
|
|
|
auto profile = ptrToProfile(env, thiz);
|
|
|
|
return profile->get_nts_priority();
|
|
|
|
}
|
|
|
|
extern "C"
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_network_loki_messenger_libsession_1util_UserProfile_getNtsHidden(JNIEnv *env, jobject thiz) {
|
|
|
|
auto profile = ptrToProfile(env, thiz);
|
|
|
|
return profile->get_nts_hidden();
|
2022-12-13 17:40:09 +11:00
|
|
|
}
|