From 3a035482e42900afe4767cf8374935e7ae894662 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Thu, 1 Jun 2023 15:25:58 +1000 Subject: [PATCH] Added the legacy group 'joined_at' value --- .../java/org/thoughtcrime/securesms/database/Storage.kt | 5 +++-- .../securesms/util/ConfigurationMessageUtilities.kt | 3 ++- libsession-util/src/main/cpp/user_groups.h | 8 ++++++-- .../loki/messenger/libsession_util/util/GroupInfo.kt | 7 ++++++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index d81796d85c..430d9cd63b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -564,7 +564,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co val admins = group.members.filter { it.value /*admin = true*/ }.keys.map { Address.fromSerialized(it) } val groupId = GroupUtil.doubleEncodeGroupID(group.sessionId) val title = group.name - val formationTimestamp = SnodeAPI.nowWithOffset // TODO: formation timestamp for legacy ? current time? + val formationTimestamp = group.joinedAt createGroup(groupId, title, members, null, null, admins, formationTimestamp) setProfileSharing(Address.fromSerialized(groupId), true) // Add the group to the user's set of public keys to poll for @@ -835,7 +835,8 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co priority = ConfigBase.PRIORITY_VISIBLE, encPubKey = encryptionKeyPair.publicKey.serialize(), encSecKey = encryptionKeyPair.privateKey.serialize(), - disappearingTimer = 0L + disappearingTimer = 0L, + joinedAt = formationTimestamp ) // shouldn't exist, don't use getOrConstruct + copy userGroups.set(groupInfo) diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt index 3644cdc127..1e5e9b475c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt @@ -256,7 +256,8 @@ object ConfigurationMessageUtilities { priority = if (isPinned) ConfigBase.PRIORITY_PINNED else ConfigBase.PRIORITY_VISIBLE, encPubKey = encryptionKeyPair.publicKey.serialize(), encSecKey = encryptionKeyPair.privateKey.serialize(), - disappearingTimer = recipient.expireMessages.toLong() + disappearingTimer = recipient.expireMessages.toLong(), + joinedAt = group.formationTimestamp ) } (allOpenGroups + allLgc).forEach { groupInfo -> diff --git a/libsession-util/src/main/cpp/user_groups.h b/libsession-util/src/main/cpp/user_groups.h index a79d01a0a7..1ec852340b 100644 --- a/libsession-util/src/main/cpp/user_groups.h +++ b/libsession-util/src/main/cpp/user_groups.h @@ -51,12 +51,14 @@ inline session::config::legacy_group_info deserialize_legacy_group_info(JNIEnv * auto enc_sec_key_field = env->GetFieldID(clazz, "encSecKey", "[B"); auto priority_field = env->GetFieldID(clazz, "priority", "I"); auto disappearing_timer_field = env->GetFieldID(clazz, "disappearingTimer", "J"); + auto joined_at_field = env->GetFieldID(clazz, "joinedAt", "L"); jstring id = static_cast(env->GetObjectField(info, id_field)); jstring name = static_cast(env->GetObjectField(info, name_field)); jobject members_map = env->GetObjectField(info, members_field); jbyteArray enc_pub_key = static_cast(env->GetObjectField(info, enc_pub_key_field)); jbyteArray enc_sec_key = static_cast(env->GetObjectField(info, enc_sec_key_field)); int priority = env->GetIntField(info, priority_field); + long joined_at = env->GetLongField(info, joined_at_field); auto id_bytes = env->GetStringUTFChars(id, nullptr); auto name_bytes = env->GetStringUTFChars(name, nullptr); @@ -75,6 +77,7 @@ inline session::config::legacy_group_info deserialize_legacy_group_info(JNIEnv * info_deserialized.enc_seckey = enc_sec_key_bytes; info_deserialized.priority = priority; info_deserialized.disappearing_timer = std::chrono::seconds(env->GetLongField(info, disappearing_timer_field)); + info_deserialized.joined_at = joined_at; env->ReleaseStringUTFChars(id, id_bytes); env->ReleaseStringUTFChars(name, name_bytes); return info_deserialized; @@ -116,10 +119,11 @@ inline jobject serialize_legacy_group_info(JNIEnv *env, session::config::legacy_ jbyteArray enc_pubkey = util::bytes_from_ustring(env, info.enc_pubkey); jbyteArray enc_seckey = util::bytes_from_ustring(env, info.enc_seckey); int priority = info.priority; + long joined_at = info.joined_at; jclass legacy_group_class = env->FindClass("network/loki/messenger/libsession_util/util/GroupInfo$LegacyGroupInfo"); - jmethodID constructor = env->GetMethodID(legacy_group_class, "", "(Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;[B[BIJ)V"); - jobject serialized = env->NewObject(legacy_group_class, constructor, session_id, name, members, enc_pubkey, enc_seckey, priority, (jlong) info.disappearing_timer.count()); + jmethodID constructor = env->GetMethodID(legacy_group_class, "", "(Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;[B[BIJL)V"); + jobject serialized = env->NewObject(legacy_group_class, constructor, session_id, name, members, enc_pubkey, enc_seckey, priority, joined_at, (jlong) info.disappearing_timer.count()); return serialized; } diff --git a/libsession-util/src/main/java/network/loki/messenger/libsession_util/util/GroupInfo.kt b/libsession-util/src/main/java/network/loki/messenger/libsession_util/util/GroupInfo.kt index 8201baf940..c8ace0a9a7 100644 --- a/libsession-util/src/main/java/network/loki/messenger/libsession_util/util/GroupInfo.kt +++ b/libsession-util/src/main/java/network/loki/messenger/libsession_util/util/GroupInfo.kt @@ -11,7 +11,8 @@ sealed class GroupInfo { val encPubKey: ByteArray, val encSecKey: ByteArray, val priority: Int, - val disappearingTimer: Long + val disappearingTimer: Long, + val joinedAt: Long ): GroupInfo() { companion object { @Suppress("FunctionName") @@ -30,6 +31,8 @@ sealed class GroupInfo { if (!encPubKey.contentEquals(other.encPubKey)) return false if (!encSecKey.contentEquals(other.encSecKey)) return false if (priority != other.priority) return false + if (disappearingTimer != other.disappearingTimer) return false + if (joinedAt != other.joinedAt) return false return true } @@ -41,6 +44,8 @@ sealed class GroupInfo { result = 31 * result + encPubKey.contentHashCode() result = 31 * result + encSecKey.contentHashCode() result = 31 * result + priority + result = 31 * result + disappearingTimer.hashCode() + result = 31 * result + joinedAt.hashCode() return result } }