feat: adding support for new closed groups, moving closed groups to be legacy throughout app

This commit is contained in:
0x330a
2023-08-24 17:38:14 +10:00
parent 4e0d043a8c
commit eaddc44de1
26 changed files with 150 additions and 112 deletions

View File

@@ -157,14 +157,14 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
fun Destination.destinationPublicKey(): String = when (this) {
is Destination.Contact -> publicKey
is Destination.ClosedGroup -> groupPublicKey
is Destination.ClosedGroup -> publicKey
else -> throw NullPointerException("Not public key for this destination")
}
override fun serialize(): Data {
val (type, address) = when (destination) {
is Destination.Contact -> CONTACT_TYPE to destination.publicKey
is Destination.ClosedGroup -> GROUP_TYPE to destination.groupPublicKey
is Destination.ClosedGroup -> GROUP_TYPE to destination.publicKey
else -> return Data.EMPTY
}
return Data.Builder()

View File

@@ -10,12 +10,15 @@ sealed class Destination {
data class Contact(var publicKey: String) : Destination() {
internal constructor(): this("")
}
data class ClosedGroup(var groupPublicKey: String) : Destination() {
data class LegacyClosedGroup(var groupPublicKey: String) : Destination() {
internal constructor(): this("")
}
data class LegacyOpenGroup(var roomToken: String, var server: String) : Destination() {
internal constructor(): this("", "")
}
data class ClosedGroup(var publicKey: String): Destination() {
internal constructor(): this("")
}
class OpenGroup(
var roomToken: String = "",
@@ -38,10 +41,10 @@ sealed class Destination {
address.isContact -> {
Contact(address.contactIdentifier())
}
address.isClosedGroup -> {
address.isLegacyClosedGroup -> {
val groupID = address.toGroupString()
val groupPublicKey = GroupUtil.doubleDecodeGroupID(groupID).toHexString()
ClosedGroup(groupPublicKey)
LegacyClosedGroup(groupPublicKey)
}
address.isOpenGroup -> {
val storage = MessagingModuleConfiguration.shared.storage

View File

@@ -124,7 +124,7 @@ class ConfigurationMessage(var closedGroups: List<ClosedGroup>, var openGroups:
val profileKey = ProfileKeyUtil.getProfileKey(context)
val groups = storage.getAllGroups(includeInactive = false)
for (group in groups) {
if (group.isClosedGroup && group.isActive) {
if (group.isLegacyClosedGroup && group.isActive) {
if (!group.members.contains(Address.fromSerialized(storage.getUserPublicKey()!!))) continue
val groupPublicKey = GroupUtil.doubleDecodeGroupID(group.encodedId).toHexString()
val encryptionKeyPair = storage.getLatestClosedGroupEncryptionKeyPair(groupPublicKey) ?: continue

View File

@@ -87,7 +87,7 @@ object MessageSender {
when (destination) {
is Destination.Contact -> message.recipient = destination.publicKey
is Destination.ClosedGroup -> message.recipient = destination.groupPublicKey
is Destination.LegacyClosedGroup -> message.recipient = destination.groupPublicKey
else -> throw IllegalStateException("Destination should not be an open group.")
}
@@ -126,7 +126,7 @@ object MessageSender {
// Encrypt the serialized protobuf
val ciphertext = when (destination) {
is Destination.Contact -> MessageEncrypter.encrypt(plaintext, destination.publicKey)
is Destination.ClosedGroup -> {
is Destination.LegacyClosedGroup -> {
val encryptionKeyPair =
MessagingModuleConfiguration.shared.storage.getLatestClosedGroupEncryptionKeyPair(
destination.groupPublicKey
@@ -143,7 +143,7 @@ object MessageSender {
kind = SignalServiceProtos.Envelope.Type.SESSION_MESSAGE
senderPublicKey = ""
}
is Destination.ClosedGroup -> {
is Destination.LegacyClosedGroup -> {
kind = SignalServiceProtos.Envelope.Type.CLOSED_GROUP_MESSAGE
senderPublicKey = destination.groupPublicKey
}
@@ -183,9 +183,9 @@ object MessageSender {
// TODO: this might change in future for config messages
val forkInfo = SnodeAPI.forkInfo
val namespaces: List<Int> = when {
destination is Destination.ClosedGroup
destination is Destination.LegacyClosedGroup
&& forkInfo.defaultRequiresAuth() -> listOf(Namespace.UNAUTHENTICATED_CLOSED_GROUP)
destination is Destination.ClosedGroup
destination is Destination.LegacyClosedGroup
&& forkInfo.hasNamespaces() -> listOf(Namespace.UNAUTHENTICATED_CLOSED_GROUP, Namespace.DEFAULT)
else -> listOf(Namespace.DEFAULT)
}

View File

@@ -20,9 +20,9 @@ class Address private constructor(address: String) : Parcelable, Comparable<Addr
constructor(`in`: Parcel) : this(`in`.readString()!!) {}
val isGroup: Boolean
get() = GroupUtil.isEncodedGroup(address)
val isClosedGroup: Boolean
get() = GroupUtil.isClosedGroup(address)
get() = GroupUtil.isEncodedGroup(address) || address.startsWith(IdPrefix.GROUP.value)
val isLegacyClosedGroup: Boolean
get() = GroupUtil.isLegacyClosedGroup(address)
val isOpenGroup: Boolean
get() = GroupUtil.isOpenGroup(address)
val isOpenGroupInbox: Boolean

View File

@@ -23,8 +23,8 @@ class GroupRecord(
val isOpenGroup: Boolean
get() = Address.fromSerialized(encodedId).isOpenGroup
val isClosedGroup: Boolean
get() = Address.fromSerialized(encodedId).isClosedGroup
val isLegacyClosedGroup: Boolean
get() = Address.fromSerialized(encodedId).isLegacyClosedGroup
init {
if (!TextUtils.isEmpty(members)) {

View File

@@ -1,12 +1,11 @@
package org.session.libsession.utilities
import network.loki.messenger.libsession_util.util.GroupInfo
import org.session.libsignal.messages.SignalServiceGroup
import org.session.libsignal.utilities.Hex
import java.io.IOException
object GroupUtil {
const val CLOSED_GROUP_PREFIX = "__textsecure_group__!"
const val LEGACY_CLOSED_GROUP_PREFIX = "__textsecure_group__!"
const val OPEN_GROUP_PREFIX = "__loki_public_chat_group__!"
const val OPEN_GROUP_INBOX_PREFIX = "__open_group_inbox__!"
@@ -22,7 +21,7 @@ object GroupUtil {
@JvmStatic
fun getEncodedClosedGroupID(groupID: ByteArray): String {
return CLOSED_GROUP_PREFIX + Hex.toStringCondensed(groupID)
return LEGACY_CLOSED_GROUP_PREFIX + Hex.toStringCondensed(groupID)
}
@JvmStatic
@@ -61,7 +60,7 @@ object GroupUtil {
}
fun isEncodedGroup(groupId: String): Boolean {
return groupId.startsWith(CLOSED_GROUP_PREFIX) || groupId.startsWith(OPEN_GROUP_PREFIX)
return groupId.startsWith(LEGACY_CLOSED_GROUP_PREFIX) || groupId.startsWith(OPEN_GROUP_PREFIX)
}
@JvmStatic
@@ -75,8 +74,8 @@ object GroupUtil {
}
@JvmStatic
fun isClosedGroup(groupId: String): Boolean {
return groupId.startsWith(CLOSED_GROUP_PREFIX)
fun isLegacyClosedGroup(groupId: String): Boolean {
return groupId.startsWith(LEGACY_CLOSED_GROUP_PREFIX)
}
// NOTE: Signal group ID handling is weird. The ID is double encoded in the database, but not in a `GroupContext`.

View File

@@ -455,10 +455,11 @@ public class Recipient implements RecipientModifiedListener {
return address.isOpenGroupInbox();
}
public boolean isClosedGroupRecipient() {
return address.isClosedGroup();
public boolean isLegacyClosedGroupRecipient() {
return address.isLegacyClosedGroup();
}
@Deprecated
public boolean isPushGroupRecipient() {
return address.isGroup();