mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-11 12:07:26 +00:00
Rename remaining session id refs
This commit is contained in:
@@ -368,7 +368,7 @@ class InstrumentedTests {
|
||||
assertEquals(2, convos.sizeOneToOnes())
|
||||
|
||||
val numErased = convos.eraseAll { convo ->
|
||||
convo is Conversation.OneToOne && convo.sessionId == definitelyRealId
|
||||
convo is Conversation.OneToOne && convo.accountId == definitelyRealId
|
||||
}
|
||||
assertEquals(1, numErased)
|
||||
assertEquals(1, convos.sizeOneToOnes())
|
||||
@@ -453,7 +453,7 @@ class InstrumentedTests {
|
||||
|
||||
val c = convos.getOrConstructOneToOne(definitelyRealId)
|
||||
|
||||
assertEquals(definitelyRealId, c.sessionId)
|
||||
assertEquals(definitelyRealId, c.accountId)
|
||||
assertEquals(0, c.lastRead)
|
||||
|
||||
assertFalse(convos.needsPush())
|
||||
@@ -504,7 +504,7 @@ class InstrumentedTests {
|
||||
|
||||
val x1 = convos2.getOneToOne(definitelyRealId)!!
|
||||
assertEquals(nowMs, x1.lastRead)
|
||||
assertEquals(definitelyRealId, x1.sessionId)
|
||||
assertEquals(definitelyRealId, x1.accountId)
|
||||
assertEquals(false, x1.unread)
|
||||
|
||||
val x2 = convos2.getCommunity("http://EXAMPLE.org:5678", "sudokuRoom")!!
|
||||
@@ -548,7 +548,7 @@ class InstrumentedTests {
|
||||
val allConvos = conv.all()
|
||||
for (convo in allConvos) {
|
||||
when (convo) {
|
||||
is Conversation.OneToOne -> seen.add("1-to-1: ${convo.sessionId}")
|
||||
is Conversation.OneToOne -> seen.add("1-to-1: ${convo.accountId}")
|
||||
is Conversation.Community -> seen.add("og: ${convo.baseCommunityInfo.baseUrl}/r/${convo.baseCommunityInfo.room}")
|
||||
is Conversation.LegacyGroup -> seen.add("cl: ${convo.groupId}")
|
||||
}
|
||||
@@ -569,7 +569,7 @@ class InstrumentedTests {
|
||||
|
||||
assertEquals(1, convos.allOneToOnes().size)
|
||||
assertEquals("051111111111111111111111111111111111111111111111111111111111111111",
|
||||
convos.allOneToOnes().map(Conversation.OneToOne::sessionId).first()
|
||||
convos.allOneToOnes().map(Conversation.OneToOne::accountId).first()
|
||||
)
|
||||
assertEquals(1, convos.allCommunities().size)
|
||||
assertEquals("http://example.org:5678",
|
||||
|
@@ -5,15 +5,15 @@
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_Contacts_get(JNIEnv *env, jobject thiz,
|
||||
jstring session_id) {
|
||||
jstring account_id) {
|
||||
// If an exception is thrown, return nullptr
|
||||
return jni_utils::run_catching_cxx_exception_or<jobject>(
|
||||
[=]() -> jobject {
|
||||
std::lock_guard lock{util::util_mutex_};
|
||||
auto contacts = ptrToContacts(env, thiz);
|
||||
auto session_id_chars = env->GetStringUTFChars(session_id, nullptr);
|
||||
auto contact = contacts->get(session_id_chars);
|
||||
env->ReleaseStringUTFChars(session_id, session_id_chars);
|
||||
auto account_id_chars = env->GetStringUTFChars(account_id, nullptr);
|
||||
auto contact = contacts->get(account_id_chars);
|
||||
env->ReleaseStringUTFChars(account_id, account_id_chars);
|
||||
if (!contact) return nullptr;
|
||||
jobject j_contact = serialize_contact(env, contact.value());
|
||||
return j_contact;
|
||||
@@ -25,13 +25,13 @@ Java_network_loki_messenger_libsession_1util_Contacts_get(JNIEnv *env, jobject t
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_Contacts_getOrConstruct(JNIEnv *env, jobject thiz,
|
||||
jstring session_id) {
|
||||
jstring account_id) {
|
||||
return jni_utils::run_catching_cxx_exception_or_throws<jobject>(env, [=] {
|
||||
std::lock_guard lock{util::util_mutex_};
|
||||
auto contacts = ptrToContacts(env, thiz);
|
||||
auto session_id_chars = env->GetStringUTFChars(session_id, nullptr);
|
||||
auto contact = contacts->get_or_construct(session_id_chars);
|
||||
env->ReleaseStringUTFChars(session_id, session_id_chars);
|
||||
auto account_id_chars = env->GetStringUTFChars(account_id, nullptr);
|
||||
auto contact = contacts->get_or_construct(account_id_chars);
|
||||
env->ReleaseStringUTFChars(account_id, account_id_chars);
|
||||
return serialize_contact(env, contact);
|
||||
});
|
||||
}
|
||||
@@ -51,14 +51,14 @@ Java_network_loki_messenger_libsession_1util_Contacts_set(JNIEnv *env, jobject t
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_Contacts_erase(JNIEnv *env, jobject thiz,
|
||||
jstring session_id) {
|
||||
jstring account_id) {
|
||||
return jni_utils::run_catching_cxx_exception_or_throws<jboolean>(env, [=] {
|
||||
std::lock_guard lock{util::util_mutex_};
|
||||
auto contacts = ptrToContacts(env, thiz);
|
||||
auto session_id_chars = env->GetStringUTFChars(session_id, nullptr);
|
||||
auto account_id_chars = env->GetStringUTFChars(account_id, nullptr);
|
||||
|
||||
bool result = contacts->erase(session_id_chars);
|
||||
env->ReleaseStringUTFChars(session_id, session_id_chars);
|
||||
bool result = contacts->erase(account_id_chars);
|
||||
env->ReleaseStringUTFChars(account_id, account_id_chars);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
@@ -43,8 +43,8 @@ inline session::config::contact_info deserialize_contact(JNIEnv *env, jobject in
|
||||
"Lnetwork/loki/messenger/libsession_util/util/UserPic;");
|
||||
getPriority = env->GetFieldID(contactClass, "priority", "I");
|
||||
getExpiry = env->GetFieldID(contactClass, "expiryMode", "Lnetwork/loki/messenger/libsession_util/util/ExpiryMode;");
|
||||
jstring name, nickname, session_id;
|
||||
session_id = static_cast<jstring>(env->GetObjectField(info, getId));
|
||||
jstring name, nickname, account_id;
|
||||
account_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, hidden;
|
||||
@@ -69,11 +69,11 @@ inline session::config::contact_info deserialize_contact(JNIEnv *env, jobject in
|
||||
key = util::ustring_from_bytes(env, deserialized_pic.second);
|
||||
}
|
||||
|
||||
auto session_id_bytes = env->GetStringUTFChars(session_id, nullptr);
|
||||
auto account_id_bytes = env->GetStringUTFChars(account_id, nullptr);
|
||||
auto name_bytes = name ? env->GetStringUTFChars(name, nullptr) : nullptr;
|
||||
auto nickname_bytes = nickname ? env->GetStringUTFChars(nickname, nullptr) : nullptr;
|
||||
|
||||
auto contact_info = conf->get_or_construct(session_id_bytes);
|
||||
auto contact_info = conf->get_or_construct(account_id_bytes);
|
||||
if (name_bytes) {
|
||||
contact_info.name = name_bytes;
|
||||
}
|
||||
@@ -89,7 +89,7 @@ inline session::config::contact_info deserialize_contact(JNIEnv *env, jobject in
|
||||
contact_info.profile_picture = session::config::profile_pic();
|
||||
}
|
||||
|
||||
env->ReleaseStringUTFChars(session_id, session_id_bytes);
|
||||
env->ReleaseStringUTFChars(account_id, account_id_bytes);
|
||||
if (name_bytes) {
|
||||
env->ReleaseStringUTFChars(name, name_bytes);
|
||||
}
|
||||
|
@@ -14,10 +14,10 @@ inline session::config::ConvoInfoVolatile *ptrToConvoInfo(JNIEnv *env, jobject o
|
||||
inline jobject serialize_one_to_one(JNIEnv *env, session::config::convo::one_to_one one_to_one) {
|
||||
jclass clazz = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$OneToOne");
|
||||
jmethodID constructor = env->GetMethodID(clazz, "<init>", "(Ljava/lang/String;JZ)V");
|
||||
auto session_id = env->NewStringUTF(one_to_one.session_id.data());
|
||||
auto account_id = env->NewStringUTF(one_to_one.session_id.data());
|
||||
auto last_read = one_to_one.last_read;
|
||||
auto unread = one_to_one.unread;
|
||||
jobject serialized = env->NewObject(clazz, constructor, session_id, last_read, unread);
|
||||
jobject serialized = env->NewObject(clazz, constructor, account_id, last_read, unread);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ inline jobject serialize_any(JNIEnv *env, session::config::convo::any any) {
|
||||
|
||||
inline session::config::convo::one_to_one deserialize_one_to_one(JNIEnv *env, jobject info, session::config::ConvoInfoVolatile *conf) {
|
||||
auto clazz = env->FindClass("network/loki/messenger/libsession_util/util/Conversation$OneToOne");
|
||||
auto id_getter = env->GetFieldID(clazz, "sessionId", "Ljava/lang/String;");
|
||||
auto id_getter = env->GetFieldID(clazz, "accountId", "Ljava/lang/String;");
|
||||
auto last_read_getter = env->GetFieldID(clazz, "lastRead", "J");
|
||||
auto unread_getter = env->GetFieldID(clazz, "unread", "Z");
|
||||
jstring id = static_cast<jstring>(env->GetObjectField(info, id_getter));
|
||||
|
@@ -74,16 +74,16 @@ extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_getLegacyGroupInfo(JNIEnv *env,
|
||||
jobject thiz,
|
||||
jstring session_id) {
|
||||
jstring account_id) {
|
||||
std::lock_guard lock{util::util_mutex_};
|
||||
auto conf = ptrToUserGroups(env, thiz);
|
||||
auto id_bytes = env->GetStringUTFChars(session_id, nullptr);
|
||||
auto id_bytes = env->GetStringUTFChars(account_id, nullptr);
|
||||
auto legacy_group = conf->get_legacy_group(id_bytes);
|
||||
jobject return_group = nullptr;
|
||||
if (legacy_group) {
|
||||
return_group = serialize_legacy_group_info(env, *legacy_group);
|
||||
}
|
||||
env->ReleaseStringUTFChars(session_id, id_bytes);
|
||||
env->ReleaseStringUTFChars(account_id, id_bytes);
|
||||
return return_group;
|
||||
}
|
||||
|
||||
@@ -108,12 +108,12 @@ Java_network_loki_messenger_libsession_1util_UserGroupsConfig_getOrConstructComm
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_getOrConstructLegacyGroupInfo(
|
||||
JNIEnv *env, jobject thiz, jstring session_id) {
|
||||
JNIEnv *env, jobject thiz, jstring account_id) {
|
||||
std::lock_guard lock{util::util_mutex_};
|
||||
auto conf = ptrToUserGroups(env, thiz);
|
||||
auto id_bytes = env->GetStringUTFChars(session_id, nullptr);
|
||||
auto id_bytes = env->GetStringUTFChars(account_id, nullptr);
|
||||
auto group = conf->get_or_construct_legacy_group(id_bytes);
|
||||
env->ReleaseStringUTFChars(session_id, id_bytes);
|
||||
env->ReleaseStringUTFChars(account_id, id_bytes);
|
||||
return serialize_legacy_group_info(env, group);
|
||||
}
|
||||
|
||||
@@ -264,11 +264,11 @@ extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_eraseLegacyGroup(JNIEnv *env,
|
||||
jobject thiz,
|
||||
jstring session_id) {
|
||||
jstring account_id) {
|
||||
std::lock_guard lock{util::util_mutex_};
|
||||
auto conf = ptrToUserGroups(env, thiz);
|
||||
auto session_id_bytes = env->GetStringUTFChars(session_id, nullptr);
|
||||
bool return_bool = conf->erase_legacy_group(session_id_bytes);
|
||||
env->ReleaseStringUTFChars(session_id, session_id_bytes);
|
||||
auto account_id_bytes = env->GetStringUTFChars(account_id, nullptr);
|
||||
bool return_bool = conf->erase_legacy_group(account_id_bytes);
|
||||
env->ReleaseStringUTFChars(account_id, account_id_bytes);
|
||||
return return_bool;
|
||||
}
|
@@ -44,7 +44,7 @@ inline void deserialize_members_into(JNIEnv *env, jobject members_map, session::
|
||||
|
||||
inline session::config::legacy_group_info deserialize_legacy_group_info(JNIEnv *env, jobject info, session::config::UserGroups* conf) {
|
||||
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, "accountId", "Ljava/lang/String;");
|
||||
auto name_field = env->GetFieldID(clazz, "name", "Ljava/lang/String;");
|
||||
auto members_field = env->GetFieldID(clazz, "members", "Ljava/util/Map;");
|
||||
auto enc_pub_key_field = env->GetFieldID(clazz, "encPubKey", "[B");
|
||||
@@ -104,16 +104,16 @@ inline jobject serialize_members(JNIEnv *env, std::map<std::string, bool> member
|
||||
|
||||
jobject new_map = env->NewObject(map_class, map_constructor);
|
||||
for (auto it = members_map.begin(); it != members_map.end(); it++) {
|
||||
auto session_id = env->NewStringUTF(it->first.data());
|
||||
auto account_id = env->NewStringUTF(it->first.data());
|
||||
bool is_admin = it->second;
|
||||
auto jbool = env->NewObject(boxed_bool, new_bool, is_admin);
|
||||
env->CallObjectMethod(new_map, insert, session_id, jbool);
|
||||
env->CallObjectMethod(new_map, insert, account_id, jbool);
|
||||
}
|
||||
return new_map;
|
||||
}
|
||||
|
||||
inline jobject serialize_legacy_group_info(JNIEnv *env, session::config::legacy_group_info info) {
|
||||
jstring session_id = env->NewStringUTF(info.session_id.data());
|
||||
jstring account_id = env->NewStringUTF(info.session_id.data());
|
||||
jstring name = env->NewStringUTF(info.name.data());
|
||||
jobject members = serialize_members(env, info.members());
|
||||
jbyteArray enc_pubkey = util::bytes_from_ustring(env, info.enc_pubkey);
|
||||
@@ -123,7 +123,7 @@ inline jobject serialize_legacy_group_info(JNIEnv *env, session::config::legacy_
|
||||
|
||||
jclass legacy_group_class = env->FindClass("network/loki/messenger/libsession_util/util/GroupInfo$LegacyGroupInfo");
|
||||
jmethodID constructor = env->GetMethodID(legacy_group_class, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;[B[BIJJ)V");
|
||||
jobject serialized = env->NewObject(legacy_group_class, constructor, session_id, name, members, enc_pubkey, enc_seckey, priority, (jlong) info.disappearing_timer.count(), joined_at);
|
||||
jobject serialized = env->NewObject(legacy_group_class, constructor, account_id, name, members, enc_pubkey, enc_seckey, priority, (jlong) info.disappearing_timer.count(), joined_at);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
|
@@ -61,49 +61,41 @@ class Contacts(pointer: Long) : ConfigBase(pointer) {
|
||||
external fun newInstance(ed25519SecretKey: ByteArray, initialDump: ByteArray): Contacts
|
||||
}
|
||||
|
||||
external fun get(sessionId: String): Contact?
|
||||
external fun getOrConstruct(sessionId: String): Contact
|
||||
external fun get(accountId: String): Contact?
|
||||
external fun getOrConstruct(accountId: String): Contact
|
||||
external fun all(): List<Contact>
|
||||
external fun set(contact: Contact)
|
||||
external fun erase(sessionId: String): Boolean
|
||||
external fun erase(accountId: String): Boolean
|
||||
|
||||
/**
|
||||
* Similar to [updateIfExists], but will create the underlying contact if it doesn't exist before passing to [updateFunction]
|
||||
*/
|
||||
fun upsertContact(sessionId: String, updateFunction: Contact.()->Unit = {}) {
|
||||
if (sessionId.startsWith(IdPrefix.BLINDED.value)) {
|
||||
Log.w("Loki", "Trying to create a contact with a blinded ID prefix")
|
||||
return
|
||||
} else if (sessionId.startsWith(IdPrefix.UN_BLINDED.value)) {
|
||||
Log.w("Loki", "Trying to create a contact with an un-blinded ID prefix")
|
||||
return
|
||||
} else if (sessionId.startsWith(IdPrefix.BLINDEDV2.value)) {
|
||||
Log.w("Loki", "Trying to create a contact with a blindedv2 ID prefix")
|
||||
return
|
||||
fun upsertContact(accountId: String, updateFunction: Contact.()->Unit = {}) {
|
||||
when {
|
||||
accountId.startsWith(IdPrefix.BLINDED.value) -> Log.w("Loki", "Trying to create a contact with a blinded ID prefix")
|
||||
accountId.startsWith(IdPrefix.UN_BLINDED.value) -> Log.w("Loki", "Trying to create a contact with an un-blinded ID prefix")
|
||||
accountId.startsWith(IdPrefix.BLINDEDV2.value) -> Log.w("Loki", "Trying to create a contact with a blindedv2 ID prefix")
|
||||
else -> getOrConstruct(accountId).let {
|
||||
updateFunction(it)
|
||||
set(it)
|
||||
}
|
||||
}
|
||||
val contact = getOrConstruct(sessionId)
|
||||
updateFunction(contact)
|
||||
set(contact)
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the contact by sessionId with a given [updateFunction], and applies to the underlying config.
|
||||
* Updates the contact by accountId with a given [updateFunction], and applies to the underlying config.
|
||||
* the [updateFunction] doesn't run if there is no contact
|
||||
*/
|
||||
fun updateIfExists(sessionId: String, updateFunction: Contact.()->Unit) {
|
||||
if (sessionId.startsWith(IdPrefix.BLINDED.value)) {
|
||||
Log.w("Loki", "Trying to create a contact with a blinded ID prefix")
|
||||
return
|
||||
} else if (sessionId.startsWith(IdPrefix.UN_BLINDED.value)) {
|
||||
Log.w("Loki", "Trying to create a contact with an un-blinded ID prefix")
|
||||
return
|
||||
} else if (sessionId.startsWith(IdPrefix.BLINDEDV2.value)) {
|
||||
Log.w("Loki", "Trying to create a contact with a blindedv2 ID prefix")
|
||||
return
|
||||
private fun updateIfExists(accountId: String, updateFunction: Contact.()->Unit) {
|
||||
when {
|
||||
accountId.startsWith(IdPrefix.BLINDED.value) -> Log.w("Loki", "Trying to create a contact with a blinded ID prefix")
|
||||
accountId.startsWith(IdPrefix.UN_BLINDED.value) -> Log.w("Loki", "Trying to create a contact with an un-blinded ID prefix")
|
||||
accountId.startsWith(IdPrefix.BLINDEDV2.value) -> Log.w("Loki", "Trying to create a contact with a blindedv2 ID prefix")
|
||||
else -> get(accountId)?.let {
|
||||
updateFunction(it)
|
||||
set(it)
|
||||
}
|
||||
}
|
||||
val contact = get(sessionId) ?: return
|
||||
updateFunction(contact)
|
||||
set(contact)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,14 +176,14 @@ class UserGroupsConfig(pointer: Long): ConfigBase(pointer) {
|
||||
}
|
||||
|
||||
external fun getCommunityInfo(baseUrl: String, room: String): GroupInfo.CommunityGroupInfo?
|
||||
external fun getLegacyGroupInfo(sessionId: String): GroupInfo.LegacyGroupInfo?
|
||||
external fun getLegacyGroupInfo(accountId: String): GroupInfo.LegacyGroupInfo?
|
||||
external fun getOrConstructCommunityInfo(baseUrl: String, room: String, pubKeyHex: String): GroupInfo.CommunityGroupInfo
|
||||
external fun getOrConstructLegacyGroupInfo(sessionId: String): GroupInfo.LegacyGroupInfo
|
||||
external fun getOrConstructLegacyGroupInfo(accountId: String): GroupInfo.LegacyGroupInfo
|
||||
external fun set(groupInfo: GroupInfo)
|
||||
external fun erase(communityInfo: GroupInfo)
|
||||
external fun eraseCommunity(baseCommunityInfo: BaseCommunityInfo): Boolean
|
||||
external fun eraseCommunity(server: String, room: String): Boolean
|
||||
external fun eraseLegacyGroup(sessionId: String): Boolean
|
||||
external fun eraseLegacyGroup(accountId: String): Boolean
|
||||
external fun sizeCommunityInfo(): Int
|
||||
external fun sizeLegacyGroupInfo(): Int
|
||||
external fun size(): Int
|
||||
|
@@ -6,7 +6,7 @@ sealed class Conversation {
|
||||
abstract var unread: Boolean
|
||||
|
||||
data class OneToOne(
|
||||
val sessionId: String,
|
||||
val accountId: String,
|
||||
override var lastRead: Long,
|
||||
override var unread: Boolean
|
||||
): Conversation()
|
||||
|
@@ -5,7 +5,7 @@ sealed class GroupInfo {
|
||||
data class CommunityGroupInfo(val community: BaseCommunityInfo, val priority: Int) : GroupInfo()
|
||||
|
||||
data class LegacyGroupInfo(
|
||||
val sessionId: String,
|
||||
val accountId: String,
|
||||
val name: String,
|
||||
val members: Map<String, Boolean>,
|
||||
val encPubKey: ByteArray,
|
||||
@@ -25,7 +25,7 @@ sealed class GroupInfo {
|
||||
|
||||
other as LegacyGroupInfo
|
||||
|
||||
if (sessionId != other.sessionId) return false
|
||||
if (accountId != other.accountId) return false
|
||||
if (name != other.name) return false
|
||||
if (members != other.members) return false
|
||||
if (!encPubKey.contentEquals(other.encPubKey)) return false
|
||||
@@ -38,7 +38,7 @@ sealed class GroupInfo {
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = sessionId.hashCode()
|
||||
var result = accountId.hashCode()
|
||||
result = 31 * result + name.hashCode()
|
||||
result = 31 * result + members.hashCode()
|
||||
result = 31 * result + encPubKey.contentHashCode()
|
||||
|
Reference in New Issue
Block a user