diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/Message.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/Message.kt index 87dd17bf9f..2cf27ed8ed 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/Message.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/Message.kt @@ -12,7 +12,9 @@ abstract class Message { var sender: String? = null var groupPublicKey: String? = null var openGroupServerMessageID: Long? = null + open val ttl: Long = 2 * 24 * 60 * 60 * 1000 + open val isSelfSendValid: Boolean = false // validation open fun isValid(): Boolean { diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupUpdateV2.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupControlMessage.kt similarity index 71% rename from libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupUpdateV2.kt rename to libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupControlMessage.kt index 1f345d9124..3ed8b71e59 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupUpdateV2.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/ClosedGroupControlMessage.kt @@ -7,7 +7,7 @@ import org.session.libsignal.libsignal.ecc.ECKeyPair import org.session.libsignal.libsignal.logging.Log import org.session.libsignal.service.internal.push.SignalServiceProtos -class ClosedGroupUpdateV2() : ControlMessage() { +class ClosedGroupControlMessage() : ControlMessage() { override val ttl: Long = run { when (kind) { @@ -16,19 +16,30 @@ class ClosedGroupUpdateV2() : ControlMessage() { } } + override val isSelfSendValid: Boolean = run { + when(kind) { + is Kind.New -> false + else -> true + } + } + var kind: Kind? = null // Kind enum sealed class Kind { class New(val publicKey: ByteString, val name: String, val encryptionKeyPair: ECKeyPair, val members: List, val admins: List) : Kind() - class Update(val name: String, val members: List) : Kind() + class Update(val name: String, val members: List) : Kind() //deprecated class EncryptionKeyPair(val wrappers: Collection) : Kind() + class NameChange(val name: String) : Kind() + class MembersAdded(val members: List) : Kind() + class MembersRemoved( val members: List) : Kind() + class MemberLeft() : Kind() } companion object { const val TAG = "ClosedGroupUpdateV2" - fun fromProto(proto: SignalServiceProtos.Content): ClosedGroupUpdateV2? { + fun fromProto(proto: SignalServiceProtos.Content): ClosedGroupControlMessage? { val closedGroupUpdateProto = proto.dataMessage?.closedGroupUpdateV2 ?: return null val kind: Kind when(closedGroupUpdateProto.type) { @@ -53,8 +64,21 @@ class ClosedGroupUpdateV2() : ControlMessage() { val wrappers = closedGroupUpdateProto.wrappersList.mapNotNull { KeyPairWrapper.fromProto(it) } kind = Kind.EncryptionKeyPair(wrappers) } + SignalServiceProtos.ClosedGroupUpdateV2.Type.NAME_CHANGE -> { + val name = closedGroupUpdateProto.name ?: return null + kind = Kind.NameChange(name) + } + SignalServiceProtos.ClosedGroupUpdateV2.Type.MEMBERS_ADDED -> { + kind = Kind.MembersAdded(closedGroupUpdateProto.membersList) + } + SignalServiceProtos.ClosedGroupUpdateV2.Type.MEMBERS_REMOVED -> { + kind = Kind.MembersRemoved(closedGroupUpdateProto.membersList) + } + SignalServiceProtos.ClosedGroupUpdateV2.Type.MEMBER_LEFT -> { + kind = Kind.MemberLeft() + } } - return ClosedGroupUpdateV2(kind) + return ClosedGroupControlMessage(kind) } } @@ -69,14 +93,15 @@ class ClosedGroupUpdateV2() : ControlMessage() { val kind = kind ?: return false return when(kind) { is Kind.New -> { - !kind.publicKey.isEmpty && kind.name.isNotEmpty() && kind.encryptionKeyPair.publicKey != null && kind.encryptionKeyPair.privateKey != null && kind.members.isNotEmpty() && kind.admins.isNotEmpty() - } - is Kind.Update -> { - kind.name.isNotEmpty() - } - is Kind.EncryptionKeyPair -> { - true + !kind.publicKey.isEmpty && kind.name.isNotEmpty() && kind.encryptionKeyPair.publicKey != null + && kind.encryptionKeyPair.privateKey != null && kind.members.isNotEmpty() && kind.admins.isNotEmpty() } + is Kind.Update -> kind.name.isNotEmpty() + is Kind.EncryptionKeyPair -> true + is Kind.NameChange -> kind.name.isNotEmpty() + is Kind.MembersAdded -> kind.members.isNotEmpty() + is Kind.MembersRemoved -> kind.members.isNotEmpty() + is Kind.MemberLeft -> true } } @@ -115,6 +140,21 @@ class ClosedGroupUpdateV2() : ControlMessage() { closedGroupUpdate.type = SignalServiceProtos.ClosedGroupUpdateV2.Type.ENCRYPTION_KEY_PAIR closedGroupUpdate.addAllWrappers(kind.wrappers.map { it.toProto() }) } + is Kind.NameChange -> { + closedGroupUpdate.type = SignalServiceProtos.ClosedGroupUpdateV2.Type.NAME_CHANGE + closedGroupUpdate.name = kind.name + } + is Kind.MembersAdded -> { + closedGroupUpdate.type = SignalServiceProtos.ClosedGroupUpdateV2.Type.MEMBERS_ADDED + closedGroupUpdate.addAllMembers(kind.members) + } + is Kind.MembersRemoved -> { + closedGroupUpdate.type = SignalServiceProtos.ClosedGroupUpdateV2.Type.MEMBERS_REMOVED + closedGroupUpdate.addAllMembers(kind.members) + } + is Kind.MemberLeft -> { + closedGroupUpdate.type = SignalServiceProtos.ClosedGroupUpdateV2.Type.MEMBER_LEFT + } } val contentProto = SignalServiceProtos.Content.newBuilder() val dataMessageProto = SignalServiceProtos.DataMessage.newBuilder() @@ -128,7 +168,7 @@ class ClosedGroupUpdateV2() : ControlMessage() { } } - class KeyPairWrapper(val publicKey: String?, private val encryptedKeyPair: ByteString?) { + final class KeyPairWrapper(val publicKey: String?, private val encryptedKeyPair: ByteString?) { companion object { fun fromProto(proto: SignalServiceProtos.ClosedGroupUpdateV2.KeyPairWrapper): KeyPairWrapper { return KeyPairWrapper(proto.publicKey.toString(), proto.encryptedKeyPair) diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/SignalServiceProtos.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/SignalServiceProtos.java index 64f8415f2e..a4acbeaffa 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/SignalServiceProtos.java +++ b/libsignal/src/main/java/org/session/libsignal/service/internal/push/SignalServiceProtos.java @@ -24685,6 +24685,37 @@ public final class SignalServiceProtos { * */ ENCRYPTION_KEY_PAIR(2, 3), + /** + * NAME_CHANGE = 4; + * + *
+         * name
+         * 
+ */ + NAME_CHANGE(3, 4), + /** + * MEMBERS_ADDED = 5; + * + *
+         * members
+         * 
+ */ + MEMBERS_ADDED(4, 5), + /** + * MEMBERS_REMOVED = 6; + * + *
+         * members
+         * 
+ */ + MEMBERS_REMOVED(5, 6), + /** + * MEMBER_LEFT = 7; + * + *
+         * 
+ */ + MEMBER_LEFT(6, 7), ; /** @@ -24711,6 +24742,38 @@ public final class SignalServiceProtos { * */ public static final int ENCRYPTION_KEY_PAIR_VALUE = 3; + /** + * NAME_CHANGE = 4; + * + *
+         * name
+         * 
+ */ + public static final int NAME_CHANGE_VALUE = 4; + /** + * MEMBERS_ADDED = 5; + * + *
+         * members
+         * 
+ */ + public static final int MEMBERS_ADDED_VALUE = 5; + /** + * MEMBERS_REMOVED = 6; + * + *
+         * members
+         * 
+ */ + public static final int MEMBERS_REMOVED_VALUE = 6; + /** + * MEMBER_LEFT = 7; + * + *
+         * 
+ */ + public static final int MEMBER_LEFT_VALUE = 7; + public final int getNumber() { return value; } @@ -24720,6 +24783,10 @@ public final class SignalServiceProtos { case 1: return NEW; case 2: return UPDATE; case 3: return ENCRYPTION_KEY_PAIR; + case 4: return NAME_CHANGE; + case 5: return MEMBERS_ADDED; + case 6: return MEMBERS_REMOVED; + case 7: return MEMBER_LEFT; default: return null; } }