mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-26 22:08:41 +00:00
feat: adding more serialization changes for community base info and user groups LGC
This commit is contained in:
parent
858893a0e9
commit
1e43ef7318
@ -366,7 +366,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper, private val configF
|
|||||||
is Conversation.LegacyGroup -> conversation.groupId.let {
|
is Conversation.LegacyGroup -> conversation.groupId.let {
|
||||||
getOrCreateThreadIdFor("", it,null)
|
getOrCreateThreadIdFor("", it,null)
|
||||||
}
|
}
|
||||||
is Conversation.Community -> conversation.baseUrl.let {
|
is Conversation.Community -> conversation.baseCommunityInfo.baseUrl.let {
|
||||||
getOrCreateThreadIdFor("",null, it)
|
getOrCreateThreadIdFor("",null, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,8 @@ object ConfigurationMessageUtilities {
|
|||||||
blocked = settings.isBlocked,
|
blocked = settings.isBlocked,
|
||||||
approved = settings.isApproved,
|
approved = settings.isApproved,
|
||||||
approvedMe = settings.hasApprovedMe(),
|
approvedMe = settings.hasApprovedMe(),
|
||||||
profilePicture = userPic ?: UserPic.DEFAULT
|
profilePicture = userPic ?: UserPic.DEFAULT,
|
||||||
|
priority = 0 // TODO: read this in from a pinned priority
|
||||||
)
|
)
|
||||||
contactConfig.set(contactInfo)
|
contactConfig.set(contactInfo)
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,12 @@ inline jobject serialize_one_to_one(JNIEnv *env, session::config::convo::one_to_
|
|||||||
|
|
||||||
inline jobject serialize_open_group(JNIEnv *env, session::config::convo::community community) {
|
inline jobject serialize_open_group(JNIEnv *env, session::config::convo::community community) {
|
||||||
jclass clazz = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$Community");
|
jclass clazz = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$Community");
|
||||||
jmethodID constructor = env->GetMethodID(clazz, "<init>", "(Ljava/lang/String;Ljava/lang/String;[BJZ)V");
|
auto base_community = util::serialize_base_community(env, community);
|
||||||
auto base_url = env->NewStringUTF(community.base_url().data());
|
jmethodID constructor = env->GetMethodID(clazz, "<init>",
|
||||||
auto room = env->NewStringUTF(community.room().data());
|
"(Lnetwork/loki/messenger/libsession_util/util/BaseCommunityInfo;JZ)V");
|
||||||
auto pubkey_ustring = community.pubkey();
|
|
||||||
auto pubkey_jarray = util::bytes_from_ustring(env, session::ustring_view {pubkey_ustring.data(), pubkey_ustring.size()});
|
|
||||||
auto last_read = community.last_read;
|
auto last_read = community.last_read;
|
||||||
auto unread = community.unread;
|
auto unread = community.unread;
|
||||||
jobject serialized = env->NewObject(clazz, constructor, base_url, room, pubkey_jarray, last_read, unread);
|
jobject serialized = env->NewObject(clazz, constructor, base_community, last_read, unread);
|
||||||
return serialized;
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,25 +70,23 @@ inline session::config::convo::one_to_one* deserialize_one_to_one(JNIEnv *env, j
|
|||||||
|
|
||||||
inline session::config::convo::community* deserialize_open_group(JNIEnv *env, jobject info) {
|
inline session::config::convo::community* deserialize_open_group(JNIEnv *env, jobject info) {
|
||||||
auto clazz = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$Community");
|
auto clazz = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$Community");
|
||||||
auto url_getter = env->GetFieldID(clazz, "baseUrl", "Ljava/lang/String;");
|
|
||||||
auto room_getter = env->GetFieldID(clazz, "room", "Ljava/lang/String;");
|
auto base_community_getter = env->GetFieldID(clazz, "baseCommunityInfo", "Lnetwork/loki/messenger/libsession_util/util/BaseCommunityInfo;");
|
||||||
auto pub_key_getter = env->GetFieldID(clazz, "pubKey", "[B");
|
|
||||||
auto last_read_getter = env->GetFieldID(clazz, "lastRead", "J");
|
auto last_read_getter = env->GetFieldID(clazz, "lastRead", "J");
|
||||||
auto unread_getter = env->GetFieldID(clazz, "unread", "Z");
|
auto unread_getter = env->GetFieldID(clazz, "unread", "Z");
|
||||||
jstring base_url = static_cast<jstring>(env->GetObjectField(info, url_getter));
|
|
||||||
jstring room = static_cast<jstring>(env->GetObjectField(info, room_getter));
|
|
||||||
jbyteArray pub_key = (jbyteArray)env->GetObjectField(info, pub_key_getter);
|
|
||||||
auto base_bytes = env->GetStringUTFChars(base_url, nullptr);
|
|
||||||
auto base_string = std::string {base_bytes};
|
|
||||||
auto room_bytes = env->GetStringUTFChars(room, nullptr);
|
|
||||||
auto room_string = std::string {room_bytes};
|
|
||||||
auto pub_key_ustring = util::ustring_from_bytes(env, pub_key);
|
|
||||||
|
|
||||||
auto deserialized = new session::config::convo::community(base_string, room_string,pub_key_ustring);
|
auto base_community_info = env->GetObjectField(info, base_community_getter);
|
||||||
|
|
||||||
|
auto base_community_deserialized = util::deserialize_base_community(env, base_community_info);
|
||||||
|
|
||||||
|
auto deserialized = new session::config::convo::community{
|
||||||
|
base_community_deserialized.base_url(),
|
||||||
|
base_community_deserialized.room(),
|
||||||
|
base_community_deserialized.pubkey()
|
||||||
|
};
|
||||||
deserialized->last_read = env->GetLongField(info, last_read_getter);
|
deserialized->last_read = env->GetLongField(info, last_read_getter);
|
||||||
deserialized->unread = env->GetBooleanField(info, unread_getter);
|
deserialized->unread = env->GetBooleanField(info, unread_getter);
|
||||||
env->ReleaseStringUTFChars(base_url, base_bytes);
|
|
||||||
env->ReleaseStringUTFChars(room, room_bytes);
|
|
||||||
return deserialized;
|
return deserialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ Java_network_loki_messenger_libsession_1util_UserGroupsConfig_getCommunityInfo(J
|
|||||||
jobject community_info = nullptr;
|
jobject community_info = nullptr;
|
||||||
|
|
||||||
if (community) {
|
if (community) {
|
||||||
serialize_legacy_group_info()
|
community_info = serialize_community_info(env, *community);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implement getCommunityInfo()
|
// TODO: implement getCommunityInfo()
|
||||||
@ -89,7 +89,7 @@ Java_network_loki_messenger_libsession_1util_UserGroupsConfig_getOrConstructLega
|
|||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_set__Lnetwork_loki_messenger_libsession_1util_util_GroupInfo_CommunityInfo_2(
|
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_set__Lnetwork_loki_messenger_libsession_1util_util_GroupInfo_CommunityGroupInfo_2(
|
||||||
JNIEnv *env, jobject thiz, jobject community_info) {
|
JNIEnv *env, jobject thiz, jobject community_info) {
|
||||||
// TODO: implement set()
|
// TODO: implement set()
|
||||||
}
|
}
|
||||||
|
@ -21,23 +21,37 @@ val encPubKey: String,
|
|||||||
val encSecKey: String,
|
val encSecKey: String,
|
||||||
val priority: Int
|
val priority: Int
|
||||||
*/
|
*/
|
||||||
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;");
|
||||||
auto name_field = env->GetFieldID(clazz, "name", "Ljava/lang/String;");
|
auto name_field = env->GetFieldID(clazz, "name", "Ljava/lang/String;");
|
||||||
auto members_field = env->GetFieldID(clazz, "members", "Ljava/util/Map;");
|
auto members_field = env->GetFieldID(clazz, "members", "Ljava/util/Map;");
|
||||||
auto hidden_field = env->GetFieldID(clazz, "hidden", "Z");
|
auto hidden_field = env->GetFieldID(clazz, "hidden", "Z");
|
||||||
auto enc_pub_key_field = env->GetFieldID(clazz, "encPubKey", "Ljava/lang/String;");
|
auto enc_pub_key_field = env->GetFieldID(clazz, "encPubKey", "[B");
|
||||||
auto enc_sec_key_field = env->GetFieldID(clazz, "encSecKey", "Ljava/lang/String;");
|
auto enc_sec_key_field = env->GetFieldID(clazz, "encSecKey", "[B");
|
||||||
auto priority_field = env->GetFieldID(clazz, "priority", "I");
|
auto priority_field = env->GetFieldID(clazz, "priority", "I");
|
||||||
jstring id = static_cast<jstring>(env->GetObjectField(info, id_field));
|
jstring id = static_cast<jstring>(env->GetObjectField(info, id_field));
|
||||||
jstring name = static_cast<jstring>(env->GetObjectField(info, name_field));
|
jstring name = static_cast<jstring>(env->GetObjectField(info, name_field));
|
||||||
jobject members_map = env->GetObjectField(info, members_field);
|
jobject members_map = env->GetObjectField(info, members_field);
|
||||||
bool hidden = env->GetBooleanField(info, hidden_field);
|
bool hidden = env->GetBooleanField(info, hidden_field);
|
||||||
jstring enc_pub_key = static_cast<jstring>(env->GetObjectField(info, enc_pub_key_field));
|
jbyteArray enc_pub_key = static_cast<jbyteArray>(env->GetObjectField(info, enc_pub_key_field));
|
||||||
jstring enc_sec_key = static_cast<jstring>(env->GetObjectField(info, enc_sec_key_field));
|
jbyteArray enc_sec_key = static_cast<jbyteArray>(env->GetObjectField(info, enc_sec_key_field));
|
||||||
int priority = env->GetIntField(info, priority_field);
|
int priority = env->GetIntField(info, priority_field);
|
||||||
|
|
||||||
|
auto id_bytes = env->GetStringUTFChars(id, nullptr);
|
||||||
|
auto name_bytes = env->GetStringUTFChars(name, nullptr);
|
||||||
|
auto enc_pub_key_bytes = util::ustring_from_bytes(env, enc_pub_key);
|
||||||
|
auto enc_sec_key_bytes = util::ustring_from_bytes(env, enc_sec_key);
|
||||||
|
|
||||||
|
auto info_deserialized = new session::config::legacy_group_info(id_bytes);
|
||||||
|
|
||||||
|
info_deserialized->priority = priority;
|
||||||
|
// TODO: iterate over map and insert as admins
|
||||||
|
info_deserialized->enc_pubkey = enc_pub_key_bytes;
|
||||||
|
info_deserialized->enc_seckey = enc_sec_key_bytes;
|
||||||
|
env->ReleaseStringUTFChars(id, id_bytes);
|
||||||
|
env->ReleaseStringUTFChars(name, name_bytes);
|
||||||
|
return info_deserialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::map<std::string, bool> deserialize_members(JNIEnv *env, jobject members_map) {
|
inline std::map<std::string, bool> deserialize_members(JNIEnv *env, jobject members_map) {
|
||||||
@ -54,9 +68,10 @@ inline jobject serialize_members(JNIEnv *env, std::map<std::string, bool> member
|
|||||||
|
|
||||||
inline jobject serialize_community_info(JNIEnv *env, session::config::community_info info) {
|
inline jobject serialize_community_info(JNIEnv *env, session::config::community_info info) {
|
||||||
auto priority = info.priority;
|
auto priority = info.priority;
|
||||||
auto open_group = session::config::community::parse_full_url(info.full_url());
|
auto serialized_community = util::serialize_base_community(env, info);
|
||||||
auto serialized_community = serialize_open_group(env, (session::config::community) info);
|
auto clazz = env->FindClass("network/loki/messenger/libsession_util/util/GroupInfo$CommunityGroupInfo");
|
||||||
return nullptr;
|
|
||||||
|
return serialized_community;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //SESSION_ANDROID_USER_GROUPS_H
|
#endif //SESSION_ANDROID_USER_GROUPS_H
|
||||||
|
@ -37,6 +37,20 @@ namespace util {
|
|||||||
return {pic, key};
|
return {pic, key};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jobject serialize_base_community(JNIEnv *env, const session::config::community& community) {
|
||||||
|
jclass base_community_clazz = env->FindClass("network/loki/messenger/libsession_util/util/BaseCommunityInfo");
|
||||||
|
jmethodID base_community_constructor = env->GetMethodID(base_community_clazz, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||||
|
auto base_url = env->NewStringUTF(community.base_url().data());
|
||||||
|
auto room = env->NewStringUTF(community.room().data());
|
||||||
|
auto pubkey_jstring = env->NewStringUTF(community.pubkey_hex().data());
|
||||||
|
jobject ret = env->NewObject(base_community_clazz, base_community_constructor, base_url, room, pubkey_jstring);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
session::config::community deserialize_base_community(JNIEnv *env, jobject base_community) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
|
@ -6,12 +6,15 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include "session/types.hpp"
|
#include "session/types.hpp"
|
||||||
#include "session/config/profile_pic.hpp"
|
#include "session/config/profile_pic.hpp"
|
||||||
|
#include "session/config/user_groups.hpp"
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
jbyteArray bytes_from_ustring(JNIEnv* env, session::ustring_view from_str);
|
jbyteArray bytes_from_ustring(JNIEnv* env, session::ustring_view from_str);
|
||||||
session::ustring ustring_from_bytes(JNIEnv* env, jbyteArray byteArray);
|
session::ustring ustring_from_bytes(JNIEnv* env, jbyteArray byteArray);
|
||||||
jobject serialize_user_pic(JNIEnv *env, session::config::profile_pic pic);
|
jobject serialize_user_pic(JNIEnv *env, session::config::profile_pic pic);
|
||||||
std::pair<jstring, jbyteArray> deserialize_user_pic(JNIEnv *env, jobject user_pic);
|
std::pair<jstring, jbyteArray> deserialize_user_pic(JNIEnv *env, jobject user_pic);
|
||||||
|
jobject serialize_base_community(JNIEnv *env, const session::config::community& base_community);
|
||||||
|
session::config::community deserialize_base_community(JNIEnv *env, jobject base_community);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -154,11 +154,11 @@ class UserGroupsConfig(pointer: Long): ConfigBase(pointer) {
|
|||||||
external fun newInstance(ed25519SecretKey: ByteArray, initialDump: ByteArray): UserGroupsConfig
|
external fun newInstance(ed25519SecretKey: ByteArray, initialDump: ByteArray): UserGroupsConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
external fun getCommunityInfo(baseUrl: String, room: String): GroupInfo.CommunityInfo?
|
external fun getCommunityInfo(baseUrl: String, room: String): GroupInfo.CommunityGroupInfo?
|
||||||
external fun getLegacyGroupInfo(sessionId: String): GroupInfo.LegacyGroupInfo?
|
external fun getLegacyGroupInfo(sessionId: String): GroupInfo.LegacyGroupInfo?
|
||||||
external fun getOrConstructCommunityInfo(baseUrl: String, room: String, pubKeyHex: String): GroupInfo.CommunityInfo
|
external fun getOrConstructCommunityInfo(baseUrl: String, room: String, pubKeyHex: String): GroupInfo.CommunityGroupInfo
|
||||||
external fun getOrConstructLegacyGroupInfo(sessionId: String): GroupInfo.LegacyGroupInfo
|
external fun getOrConstructLegacyGroupInfo(sessionId: String): GroupInfo.LegacyGroupInfo
|
||||||
external fun set(communityInfo: GroupInfo.CommunityInfo)
|
external fun set(communityInfo: GroupInfo.CommunityGroupInfo)
|
||||||
external fun set(legacyGroupInfo: GroupInfo.LegacyGroupInfo)
|
external fun set(legacyGroupInfo: GroupInfo.LegacyGroupInfo)
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
package network.loki.messenger.libsession_util.util
|
||||||
|
|
||||||
|
data class BaseCommunityInfo(val baseUrl: String, val room: String, val pubKeyHex: String)
|
@ -8,5 +8,5 @@ data class Contact(
|
|||||||
var approvedMe: Boolean = false,
|
var approvedMe: Boolean = false,
|
||||||
var blocked: Boolean = false,
|
var blocked: Boolean = false,
|
||||||
var profilePicture: UserPic = UserPic.DEFAULT,
|
var profilePicture: UserPic = UserPic.DEFAULT,
|
||||||
var priority: Int
|
var priority: Int = 0
|
||||||
)
|
)
|
@ -1,7 +1,5 @@
|
|||||||
package network.loki.messenger.libsession_util.util
|
package network.loki.messenger.libsession_util.util
|
||||||
|
|
||||||
import org.session.libsignal.utilities.Hex
|
|
||||||
|
|
||||||
sealed class Conversation {
|
sealed class Conversation {
|
||||||
|
|
||||||
abstract var lastRead: Long
|
abstract var lastRead: Long
|
||||||
@ -14,43 +12,16 @@ sealed class Conversation {
|
|||||||
): Conversation()
|
): Conversation()
|
||||||
|
|
||||||
data class Community(
|
data class Community(
|
||||||
val baseUrl: String,
|
val baseCommunityInfo: BaseCommunityInfo,
|
||||||
val room: String, // lowercase
|
|
||||||
val pubKey: ByteArray,
|
|
||||||
override var lastRead: Long,
|
override var lastRead: Long,
|
||||||
override var unread: Boolean
|
override var unread: Boolean
|
||||||
) : Conversation() {
|
) : Conversation() {
|
||||||
|
|
||||||
val pubKeyHex: String
|
|
||||||
get() = Hex.toStringCondensed(pubKey)
|
|
||||||
companion object {
|
companion object {
|
||||||
init {
|
init {
|
||||||
System.loadLibrary("session_util")
|
System.loadLibrary("session_util")
|
||||||
}
|
}
|
||||||
external fun parseFullUrl(fullUrl: String): Triple<String, String, ByteArray>?
|
external fun parseFullUrl(fullUrl: String): Triple<String, String, ByteArray>?
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as Community
|
|
||||||
|
|
||||||
if (baseUrl != other.baseUrl) return false
|
|
||||||
if (room != other.room) return false
|
|
||||||
if (!pubKey.contentEquals(other.pubKey)) return false
|
|
||||||
if (lastRead != other.lastRead) return false
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = baseUrl.hashCode()
|
|
||||||
result = 31 * result + room.hashCode()
|
|
||||||
result = 31 * result + pubKey.contentHashCode()
|
|
||||||
result = 31 * result + lastRead.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data class LegacyGroup(
|
data class LegacyGroup(
|
||||||
|
@ -2,15 +2,15 @@ package network.loki.messenger.libsession_util.util
|
|||||||
|
|
||||||
sealed class GroupInfo {
|
sealed class GroupInfo {
|
||||||
|
|
||||||
data class CommunityInfo(val community: Conversation.Community, val priority: Int) : GroupInfo()
|
data class CommunityGroupInfo(val community: BaseCommunityInfo, val priority: Int) : GroupInfo()
|
||||||
|
|
||||||
data class LegacyGroupInfo(
|
data class LegacyGroupInfo(
|
||||||
val sessionId: String,
|
val sessionId: String,
|
||||||
val name: String,
|
val name: String,
|
||||||
val members: Map<String, Boolean>,
|
val members: Map<String, Boolean>,
|
||||||
val hidden: Boolean,
|
val hidden: Boolean,
|
||||||
val encPubKey: String,
|
val encPubKey: ByteArray,
|
||||||
val encSecKey: String,
|
val encSecKey: ByteArray,
|
||||||
val priority: Int
|
val priority: Int
|
||||||
): GroupInfo() {
|
): GroupInfo() {
|
||||||
companion object {
|
companion object {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user