Skip to content

Commit b32447a

Browse files
SessionHero01SessionHero01
authored andcommitted
Pro features in config
1 parent e5105d0 commit b32447a

File tree

3 files changed

+76
-36
lines changed

3 files changed

+76
-36
lines changed

library/src/main/cpp/contacts.cpp

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ static session::config::Contacts *ptrToContacts(JNIEnv *env, jobject obj) {
1212
return (session::config::Contacts *) env->GetLongField(obj, pointerField);
1313
}
1414

15-
static JavaLocalRef<jobject> serialize_contact(JNIEnv *env, session::config::contact_info info) {
15+
static JavaLocalRef<jobject> serialize_contact(JNIEnv *env, const session::config::contact_info &info) {
1616
static BasicJavaClassInfo class_info(
1717
env, "network/loki/messenger/libsession_util/util/Contact",
18-
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZLnetwork/loki/messenger/libsession_util/util/UserPic;JJJLnetwork/loki/messenger/libsession_util/util/ExpiryMode;)V");
18+
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZLnetwork/loki/messenger/libsession_util/util/UserPic;JJJLnetwork/loki/messenger/libsession_util/util/ExpiryMode;J)V");
1919

2020
jobject returnObj = env->NewObject(class_info.java_class,
2121
class_info.constructor,
@@ -29,13 +29,13 @@ static JavaLocalRef<jobject> serialize_contact(JNIEnv *env, session::config::con
2929
(jlong) info.created,
3030
(jlong) (info.profile_updated.time_since_epoch().count()),
3131
(jlong) info.priority,
32-
util::serialize_expiry(env, info.exp_mode, info.exp_timer).get());
32+
util::serialize_expiry(env, info.exp_mode, info.exp_timer).get(),
33+
(jlong) info.pro_features);
3334
return {env, returnObj};
3435
}
3536

3637
session::config::contact_info deserialize_contact(JNIEnv *env, jobject info, session::config::Contacts *conf) {
37-
struct ClassInfo {
38-
jclass java_class;
38+
struct ClassInfo : JavaClassInfo {
3939
jmethodID get_id;
4040
jmethodID get_name;
4141
jmethodID get_nick;
@@ -46,19 +46,21 @@ session::config::contact_info deserialize_contact(JNIEnv *env, jobject info, ses
4646
jmethodID get_priority;
4747
jmethodID get_expiry;
4848
jmethodID get_profile_updated;
49+
jmethodID get_pro_features;
4950

50-
ClassInfo(JNIEnv *env, jclass clazz):
51-
java_class((jclass) env->NewGlobalRef(clazz)),
52-
get_id(env->GetMethodID(clazz, "getId", "()Ljava/lang/String;")),
53-
get_name(env->GetMethodID(clazz, "getName", "()Ljava/lang/String;")),
54-
get_nick(env->GetMethodID(clazz, "getNickname", "()Ljava/lang/String;")),
55-
get_approved(env->GetMethodID(clazz, "getApproved", "()Z")),
56-
get_approved_me(env->GetMethodID(clazz, "getApprovedMe", "()Z")),
57-
get_blocked(env->GetMethodID(clazz, "getBlocked", "()Z")),
58-
get_user_pic(env->GetMethodID(clazz, "getProfilePicture", "()Lnetwork/loki/messenger/libsession_util/util/UserPic;")),
59-
get_priority(env->GetMethodID(clazz, "getPriority", "()J")),
60-
get_expiry(env->GetMethodID(clazz, "getExpiryMode", "()Lnetwork/loki/messenger/libsession_util/util/ExpiryMode;")),
61-
get_profile_updated(env->GetMethodID(clazz, "getProfileUpdatedEpochSeconds", "()J")) {}
51+
ClassInfo(JNIEnv *env, jobject obj):
52+
JavaClassInfo(env, obj),
53+
get_id(env->GetMethodID(java_class, "getId", "()Ljava/lang/String;")),
54+
get_name(env->GetMethodID(java_class, "getName", "()Ljava/lang/String;")),
55+
get_nick(env->GetMethodID(java_class, "getNickname", "()Ljava/lang/String;")),
56+
get_approved(env->GetMethodID(java_class, "getApproved", "()Z")),
57+
get_approved_me(env->GetMethodID(java_class, "getApprovedMe", "()Z")),
58+
get_blocked(env->GetMethodID(java_class, "getBlocked", "()Z")),
59+
get_user_pic(env->GetMethodID(java_class, "getProfilePicture", "()Lnetwork/loki/messenger/libsession_util/util/UserPic;")),
60+
get_priority(env->GetMethodID(java_class, "getPriority", "()J")),
61+
get_expiry(env->GetMethodID(java_class, "getExpiryMode", "()Lnetwork/loki/messenger/libsession_util/util/ExpiryMode;")),
62+
get_profile_updated(env->GetMethodID(java_class, "getProfileUpdatedEpochSeconds", "()J")),
63+
get_pro_features(env->GetMethodID(java_class, "getProFeaturesRaw", "()J")) {}
6264
};
6365

6466
static ClassInfo class_info(env, JavaLocalRef(env, env->GetObjectClass(info)).get());
@@ -90,6 +92,7 @@ session::config::contact_info deserialize_contact(JNIEnv *env, jobject info, ses
9092
contact_info.priority = env->CallLongMethod(info, class_info.get_priority);
9193
contact_info.exp_mode = expiry_pair.first;
9294
contact_info.exp_timer = std::chrono::seconds(expiry_pair.second);
95+
contact_info.pro_features = env->CallLongMethod(info, class_info.get_pro_features);
9396

9497
return contact_info;
9598
}
@@ -156,7 +159,7 @@ Java_network_loki_messenger_libsession_1util_Contacts_all(JNIEnv *env, jobject t
156159
JavaLocalRef<jobject> serialize_blinded_contact(JNIEnv *env, const session::config::blinded_contact_info &info) {
157160
static BasicJavaClassInfo class_info(
158161
env, "network/loki/messenger/libsession_util/util/BlindedContact",
159-
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JJLnetwork/loki/messenger/libsession_util/util/UserPic;J)V");
162+
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JJLnetwork/loki/messenger/libsession_util/util/UserPic;JJ)V");
160163

161164
return {env, env->NewObject(
162165
class_info.java_class,
@@ -168,31 +171,55 @@ JavaLocalRef<jobject> serialize_blinded_contact(JNIEnv *env, const session::conf
168171
(jlong) (info.created.time_since_epoch().count()),
169172
(jlong) (info.profile_updated.time_since_epoch().count()),
170173
util::serialize_user_pic(env, info.profile_picture).get(),
171-
(jlong) info.priority
174+
(jlong) info.priority,
175+
(jlong) info.pro_features
172176
)};
173177
}
174178

175179
session::config::blinded_contact_info deserialize_blinded_contact(JNIEnv *env, jobject jInfo) {
176-
JavaLocalRef<jclass> clazz(env, env->GetObjectClass(jInfo));
177-
auto idField = env->GetFieldID(clazz.get(), "id", "Ljava/lang/String;");
178-
auto communityServerField = env->GetFieldID(clazz.get(), "communityServer", "Ljava/lang/String;");
179-
auto getCommunityServerPubKey = env->GetMethodID(clazz.get(), "getCommunityServerPubKey", "()[B");
180-
auto nameField = env->GetFieldID(clazz.get(), "name", "Ljava/lang/String;");
181-
auto createdEpochSecondsField = env->GetFieldID(clazz.get(), "createdEpochSeconds", "J");
182-
auto profileUpdatedEpochSecondsField = env->GetFieldID(clazz.get(), "profileUpdatedEpochSeconds", "J");
183-
auto profilePicField = env->GetFieldID(clazz.get(), "profilePic", "Lnetwork/loki/messenger/libsession_util/util/UserPic;");
184-
auto priorityField = env->GetFieldID(clazz.get(), "priority", "J");
180+
struct ClassInfo : public JavaClassInfo {
181+
jmethodID id_getter;
182+
jmethodID community_server_getter;
183+
jmethodID community_server_pub_key_getter;
184+
jmethodID name_getter;
185+
jmethodID created_epoch_seconds_getter;
186+
jmethodID profile_updated_epoch_seconds_getter;
187+
jmethodID profile_pic_getter;
188+
jmethodID priority_getter;
189+
jmethodID pro_features_getter;
190+
191+
ClassInfo(JNIEnv *env, jobject obj)
192+
: JavaClassInfo(env, obj)
193+
, id_getter(env->GetMethodID(java_class, "getId", "()Ljava/lang/String;"))
194+
, community_server_getter(env->GetMethodID(java_class, "getCommunityServer", "()Ljava/lang/String;"))
195+
, community_server_pub_key_getter(env->GetMethodID(java_class, "getCommunityServerPubKey", "()[B"))
196+
, name_getter(env->GetMethodID(java_class, "getName", "()Ljava/lang/String;"))
197+
, created_epoch_seconds_getter(env->GetMethodID(java_class, "getCreatedEpochSeconds", "()J"))
198+
, profile_updated_epoch_seconds_getter(env->GetMethodID(java_class, "getProfileUpdatedEpochSeconds", "()J"))
199+
, profile_pic_getter(env->GetMethodID(java_class, "getProfilePicture", "()Lnetwork/loki/messenger/libsession_util/util/UserPic;"))
200+
, priority_getter(env->GetMethodID(java_class, "getPriority", "()J"))
201+
, pro_features_getter(env->GetMethodID(java_class, "getProFeaturesRaw", "()J")) {}
202+
};
203+
204+
static ClassInfo class_info(env, jInfo);
205+
206+
JavaLocalRef
207+
community_server(env, (jstring) env->CallObjectMethod(jInfo, class_info.community_server_getter)),
208+
id(env, (jstring) env->CallObjectMethod(jInfo, class_info.id_getter));
209+
210+
JavaLocalRef community_server_pub_key(env, (jbyteArray) env->CallObjectMethod(jInfo, class_info.community_server_pub_key_getter));
185211

186212
session::config::blinded_contact_info info(
187-
JavaStringRef(env, (jstring) env->GetObjectField(jInfo, communityServerField)).view(),
188-
JavaByteArrayRef(env, (jbyteArray) env->CallObjectMethod(jInfo, getCommunityServerPubKey)).get(),
189-
JavaStringRef(env, (jstring) env->GetObjectField(jInfo, idField)).view()
213+
JavaStringRef(env, community_server.get()).view(),
214+
JavaByteArrayRef(env, community_server_pub_key.get()).get(),
215+
JavaStringRef(env, id.get()).view()
190216
);
191-
info.created = std::chrono::sys_seconds{std::chrono::seconds{env->GetLongField(jInfo, createdEpochSecondsField)}};
192-
info.profile_picture = util::deserialize_user_pic(env, JavaLocalRef(env, env->GetObjectField(jInfo, profilePicField)).get());
193-
info.name = JavaStringRef(env, JavaLocalRef(env, (jstring) env->GetObjectField(jInfo, nameField)).get()).view();
194-
info.profile_updated = std::chrono::sys_seconds{std::chrono::seconds{env->GetLongField(jInfo, profileUpdatedEpochSecondsField)}};
195-
info.priority = env->GetLongField(jInfo, priorityField);
217+
info.created = std::chrono::sys_seconds{std::chrono::seconds{env->CallLongMethod(jInfo, class_info.created_epoch_seconds_getter)}};
218+
info.profile_picture = util::deserialize_user_pic(env, JavaLocalRef(env, env->CallObjectMethod(jInfo, class_info.profile_pic_getter)).get());
219+
info.name = JavaStringRef(env, JavaLocalRef(env, (jstring) env->CallObjectMethod(jInfo, class_info.name_getter)).get()).view();
220+
info.profile_updated = std::chrono::sys_seconds{std::chrono::seconds{env->CallLongMethod(jInfo, class_info.profile_updated_epoch_seconds_getter)}};
221+
info.priority = env->CallLongMethod(jInfo, class_info.priority_getter);
222+
info.pro_features = env->CallLongMethod(jInfo, class_info.pro_features_getter);
196223

197224
return info;
198225
}

library/src/main/java/network/loki/messenger/libsession_util/util/BlindedContact.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package network.loki.messenger.libsession_util.util
22

3+
import androidx.annotation.Keep
34
import network.loki.messenger.libsession_util.ConversationPriority
5+
import network.loki.messenger.libsession_util.protocol.ProFeatures
46

57
data class BlindedContact(
68
val id: String,
@@ -11,8 +13,12 @@ data class BlindedContact(
1113
var profileUpdatedEpochSeconds: Long,
1214
var profilePic: UserPic,
1315
var priority: ConversationPriority,
16+
val proFeatures: ProFeatures,
1417
) {
1518
@OptIn(ExperimentalStdlibApi::class)
1619
val communityServerPubKey: ByteArray
1720
get() = communityServerPubKeyHex.hexToByteArray()
21+
22+
@get:Keep
23+
private val proFeaturesRaw: Long get() = proFeatures.rawValue
1824
}

library/src/main/java/network/loki/messenger/libsession_util/util/Contact.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package network.loki.messenger.libsession_util.util
22

3+
import androidx.annotation.Keep
34
import network.loki.messenger.libsession_util.ConversationPriority
45
import network.loki.messenger.libsession_util.PRIORITY_VISIBLE
6+
import network.loki.messenger.libsession_util.protocol.ProFeatures
57

68
data class Contact(
79
val id: String,
@@ -15,7 +17,12 @@ data class Contact(
1517
var profileUpdatedEpochSeconds: Long = 0,
1618
var priority: ConversationPriority = PRIORITY_VISIBLE,
1719
var expiryMode: ExpiryMode = ExpiryMode.NONE,
20+
var proFeatures: ProFeatures = ProFeatures.NONE,
1821
) {
22+
1923
val displayName: String
2024
get() = nickname.ifEmpty { name }
25+
26+
@get:Keep
27+
private val proFeaturesRaw: Long get() = proFeatures.rawValue
2128
}

0 commit comments

Comments
 (0)