mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-03 15:05:24 +00:00
closed group control message updated
This commit is contained in:
parent
2d80f38e61
commit
19d48f5b06
@ -12,7 +12,9 @@ abstract class Message {
|
|||||||
var sender: String? = null
|
var sender: String? = null
|
||||||
var groupPublicKey: String? = null
|
var groupPublicKey: String? = null
|
||||||
var openGroupServerMessageID: Long? = null
|
var openGroupServerMessageID: Long? = null
|
||||||
|
|
||||||
open val ttl: Long = 2 * 24 * 60 * 60 * 1000
|
open val ttl: Long = 2 * 24 * 60 * 60 * 1000
|
||||||
|
open val isSelfSendValid: Boolean = false
|
||||||
|
|
||||||
// validation
|
// validation
|
||||||
open fun isValid(): Boolean {
|
open fun isValid(): Boolean {
|
||||||
|
@ -7,7 +7,7 @@ import org.session.libsignal.libsignal.ecc.ECKeyPair
|
|||||||
import org.session.libsignal.libsignal.logging.Log
|
import org.session.libsignal.libsignal.logging.Log
|
||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
||||||
|
|
||||||
class ClosedGroupUpdateV2() : ControlMessage() {
|
class ClosedGroupControlMessage() : ControlMessage() {
|
||||||
|
|
||||||
override val ttl: Long = run {
|
override val ttl: Long = run {
|
||||||
when (kind) {
|
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
|
var kind: Kind? = null
|
||||||
|
|
||||||
// Kind enum
|
// Kind enum
|
||||||
sealed class Kind {
|
sealed class Kind {
|
||||||
class New(val publicKey: ByteString, val name: String, val encryptionKeyPair: ECKeyPair, val members: List<ByteString>, val admins: List<ByteString>) : Kind()
|
class New(val publicKey: ByteString, val name: String, val encryptionKeyPair: ECKeyPair, val members: List<ByteString>, val admins: List<ByteString>) : Kind()
|
||||||
class Update(val name: String, val members: List<ByteString>) : Kind()
|
class Update(val name: String, val members: List<ByteString>) : Kind() //deprecated
|
||||||
class EncryptionKeyPair(val wrappers: Collection<KeyPairWrapper>) : Kind()
|
class EncryptionKeyPair(val wrappers: Collection<KeyPairWrapper>) : Kind()
|
||||||
|
class NameChange(val name: String) : Kind()
|
||||||
|
class MembersAdded(val members: List<ByteString>) : Kind()
|
||||||
|
class MembersRemoved( val members: List<ByteString>) : Kind()
|
||||||
|
class MemberLeft() : Kind()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "ClosedGroupUpdateV2"
|
const val TAG = "ClosedGroupUpdateV2"
|
||||||
|
|
||||||
fun fromProto(proto: SignalServiceProtos.Content): ClosedGroupUpdateV2? {
|
fun fromProto(proto: SignalServiceProtos.Content): ClosedGroupControlMessage? {
|
||||||
val closedGroupUpdateProto = proto.dataMessage?.closedGroupUpdateV2 ?: return null
|
val closedGroupUpdateProto = proto.dataMessage?.closedGroupUpdateV2 ?: return null
|
||||||
val kind: Kind
|
val kind: Kind
|
||||||
when(closedGroupUpdateProto.type) {
|
when(closedGroupUpdateProto.type) {
|
||||||
@ -53,8 +64,21 @@ class ClosedGroupUpdateV2() : ControlMessage() {
|
|||||||
val wrappers = closedGroupUpdateProto.wrappersList.mapNotNull { KeyPairWrapper.fromProto(it) }
|
val wrappers = closedGroupUpdateProto.wrappersList.mapNotNull { KeyPairWrapper.fromProto(it) }
|
||||||
kind = Kind.EncryptionKeyPair(wrappers)
|
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
|
val kind = kind ?: return false
|
||||||
return when(kind) {
|
return when(kind) {
|
||||||
is Kind.New -> {
|
is Kind.New -> {
|
||||||
!kind.publicKey.isEmpty && kind.name.isNotEmpty() && kind.encryptionKeyPair.publicKey != null && kind.encryptionKeyPair.privateKey != null && kind.members.isNotEmpty() && kind.admins.isNotEmpty()
|
!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.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.type = SignalServiceProtos.ClosedGroupUpdateV2.Type.ENCRYPTION_KEY_PAIR
|
||||||
closedGroupUpdate.addAllWrappers(kind.wrappers.map { it.toProto() })
|
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 contentProto = SignalServiceProtos.Content.newBuilder()
|
||||||
val dataMessageProto = SignalServiceProtos.DataMessage.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 {
|
companion object {
|
||||||
fun fromProto(proto: SignalServiceProtos.ClosedGroupUpdateV2.KeyPairWrapper): KeyPairWrapper {
|
fun fromProto(proto: SignalServiceProtos.ClosedGroupUpdateV2.KeyPairWrapper): KeyPairWrapper {
|
||||||
return KeyPairWrapper(proto.publicKey.toString(), proto.encryptedKeyPair)
|
return KeyPairWrapper(proto.publicKey.toString(), proto.encryptedKeyPair)
|
@ -24685,6 +24685,37 @@ public final class SignalServiceProtos {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
ENCRYPTION_KEY_PAIR(2, 3),
|
ENCRYPTION_KEY_PAIR(2, 3),
|
||||||
|
/**
|
||||||
|
* <code>NAME_CHANGE = 4;</code>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* name
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
NAME_CHANGE(3, 4),
|
||||||
|
/**
|
||||||
|
* <code>MEMBERS_ADDED = 5;</code>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* members
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
MEMBERS_ADDED(4, 5),
|
||||||
|
/**
|
||||||
|
* <code>MEMBERS_REMOVED = 6;</code>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* members
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
MEMBERS_REMOVED(5, 6),
|
||||||
|
/**
|
||||||
|
* <code>MEMBER_LEFT = 7;</code>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
MEMBER_LEFT(6, 7),
|
||||||
;
|
;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24711,6 +24742,38 @@ public final class SignalServiceProtos {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public static final int ENCRYPTION_KEY_PAIR_VALUE = 3;
|
public static final int ENCRYPTION_KEY_PAIR_VALUE = 3;
|
||||||
|
/**
|
||||||
|
* <code>NAME_CHANGE = 4;</code>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* name
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public static final int NAME_CHANGE_VALUE = 4;
|
||||||
|
/**
|
||||||
|
* <code>MEMBERS_ADDED = 5;</code>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* members
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public static final int MEMBERS_ADDED_VALUE = 5;
|
||||||
|
/**
|
||||||
|
* <code>MEMBERS_REMOVED = 6;</code>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* members
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public static final int MEMBERS_REMOVED_VALUE = 6;
|
||||||
|
/**
|
||||||
|
* <code>MEMBER_LEFT = 7;</code>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public static final int MEMBER_LEFT_VALUE = 7;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public final int getNumber() { return value; }
|
public final int getNumber() { return value; }
|
||||||
@ -24720,6 +24783,10 @@ public final class SignalServiceProtos {
|
|||||||
case 1: return NEW;
|
case 1: return NEW;
|
||||||
case 2: return UPDATE;
|
case 2: return UPDATE;
|
||||||
case 3: return ENCRYPTION_KEY_PAIR;
|
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;
|
default: return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user