11#include " user_profile.h"
22#include " util.h"
3+ #include " pro_proof_util.h"
34
45extern " C" {
56JNIEXPORT void JNICALL
67Java_network_loki_messenger_libsession_1util_UserProfile_setName (
7- JNIEnv* env,
8+ JNIEnv * env,
89 jobject thiz,
910 jstring newName) {
1011 auto profile = ptrToProfile (env, thiz);
@@ -57,7 +58,7 @@ Java_network_loki_messenger_libsession_1util_UserProfile_setNtsExpiry(JNIEnv *en
5758 jobject expiry_mode) {
5859 auto profile = ptrToProfile (env, thiz);
5960 auto expiry = util::deserialize_expiry (env, expiry_mode);
60- profile->set_nts_expiry (std::chrono::seconds (expiry.second ));
61+ profile->set_nts_expiry (std::chrono::seconds (expiry.second ));
6162}
6263
6364extern " C"
@@ -66,10 +67,12 @@ Java_network_loki_messenger_libsession_1util_UserProfile_getNtsExpiry(JNIEnv *en
6667 auto profile = ptrToProfile (env, thiz);
6768 auto nts_expiry = profile->get_nts_expiry ();
6869 if (nts_expiry == std::nullopt ) {
69- auto expiry = util::serialize_expiry (env, session::config::expiration_mode::none, std::chrono::seconds (0 ));
70+ auto expiry = util::serialize_expiry (env, session::config::expiration_mode::none,
71+ std::chrono::seconds (0 ));
7072 return expiry;
7173 }
72- auto expiry = util::serialize_expiry (env, session::config::expiration_mode::after_send, std::chrono::seconds (*nts_expiry));
74+ auto expiry = util::serialize_expiry (env, session::config::expiration_mode::after_send,
75+ std::chrono::seconds (*nts_expiry));
7376 return expiry;
7477}
7578
@@ -90,7 +93,7 @@ JNIEXPORT void JNICALL
9093Java_network_loki_messenger_libsession_1util_UserProfile_setCommunityMessageRequests (
9194 JNIEnv *env, jobject thiz, jboolean blocks) {
9295 auto profile = ptrToProfile (env, thiz);
93- profile->set_blinded_msgreqs (std::optional{(bool )blocks});
96+ profile->set_blinded_msgreqs (std::optional{(bool ) blocks});
9497}
9598
9699extern " C"
@@ -113,4 +116,97 @@ JNIEXPORT void JNICALL
113116Java_network_loki_messenger_libsession_1util_UserProfile_setReuploadedPic (JNIEnv *env, jobject thiz,
114117 jobject user_pic) {
115118 ptrToProfile (env, thiz)->set_reupload_profile_pic (util::deserialize_user_pic (env, user_pic));
119+ }
120+
121+ extern " C"
122+ JNIEXPORT void JNICALL
123+ Java_network_loki_messenger_libsession_1util_UserProfile_removeProConfig (JNIEnv *env,
124+ jobject thiz) {
125+ ptrToProfile (env, thiz)->remove_pro_config ();
126+ }
127+
128+ extern " C"
129+ JNIEXPORT void JNICALL
130+ Java_network_loki_messenger_libsession_1util_UserProfile_setProConfig (JNIEnv *env, jobject thiz,
131+ jobject proof,
132+ jbyteArray rotating_private_key) {
133+ jni_utils::run_catching_cxx_exception_or_throws<void >(env, [=]() {
134+
135+ jni_utils::JavaByteArrayRef key_ref (env, rotating_private_key);
136+ auto r = key_ref.get ();
137+ session::cleared_uc64 rotating_privkey;
138+ std::copy (r.begin (), r.end (), rotating_privkey.begin ());
139+
140+ ptrToProfile (env, thiz)->set_pro_config (
141+ {
142+ .rotating_privkey = rotating_privkey,
143+ .proof = java_to_cpp_proof (env, proof),
144+ }
145+ );
146+ });
147+ }
148+
149+ extern " C"
150+ JNIEXPORT void JNICALL
151+ Java_network_loki_messenger_libsession_1util_UserProfile_setProBadge (JNIEnv *env, jobject thiz,
152+ jboolean pro_badge) {
153+ ptrToProfile (env, thiz)->set_pro_badge (pro_badge);
154+ }
155+
156+ extern " C"
157+ JNIEXPORT void JNICALL
158+ Java_network_loki_messenger_libsession_1util_UserProfile_setAnimatedAvatar (JNIEnv *env,
159+ jobject thiz,
160+ jboolean enabled) {
161+ ptrToProfile (env, thiz)->set_animated_avatar (enabled);
162+ }
163+
164+ extern " C"
165+ JNIEXPORT void JNICALL
166+ Java_network_loki_messenger_libsession_1util_UserProfile_setProAccessExpiryMs (JNIEnv *env,
167+ jobject thiz,
168+ jlong epoch_mills) {
169+ ptrToProfile (env, thiz)->set_pro_access_expiry (std::chrono::sys_time<std::chrono::milliseconds>{
170+ std::chrono::milliseconds{epoch_mills}
171+ });
172+ }
173+
174+ extern " C"
175+ JNIEXPORT void JNICALL
176+ Java_network_loki_messenger_libsession_1util_UserProfile_removeProAccessExpiry (JNIEnv *env,
177+ jobject thiz) {
178+ ptrToProfile (env, thiz)->set_pro_access_expiry (std::nullopt );
179+ }
180+
181+ extern " C"
182+ JNIEXPORT jlong JNICALL
183+ Java_network_loki_messenger_libsession_1util_UserProfile_getProFeaturesRaw (JNIEnv *env,
184+ jobject thiz) {
185+ return static_cast <jlong>(ptrToProfile (env, thiz)->get_pro_features ());
186+ }
187+
188+ extern " C"
189+ JNIEXPORT jobject JNICALL
190+ Java_network_loki_messenger_libsession_1util_UserProfile_getProConfig (JNIEnv *env, jobject thiz) {
191+ auto profile = ptrToProfile (env, thiz)->get_pro_config ();
192+ if (profile) {
193+ return nullptr ;
194+ }
195+
196+ auto clazz = env->FindClass (" network/loki/messenger/libsession_util/pro/ProConfig" );
197+ auto constructor = env->GetMethodID (clazz, " <init>" , " (Lnetwork/loki/messenger/libsession_util/pro/ProProof;[B)V" );
198+
199+ return env->NewObject (clazz,
200+ constructor,
201+ cpp_to_java_proof (env, profile->proof ),
202+ util::bytes_from_span (env, profile->rotating_privkey )
203+ );
204+ }
205+
206+ extern " C"
207+ JNIEXPORT jlong JNICALL
208+ Java_network_loki_messenger_libsession_1util_UserProfile_getProAccessExpiryMsOrZero (JNIEnv *env,
209+ jobject thiz) {
210+ auto expiry = ptrToProfile (env, thiz)->get_pro_access_expiry ();
211+ return expiry ? expiry->time_since_epoch ().count () : 0 ;
116212}
0 commit comments