fix closed group updating

This commit is contained in:
Ryan ZHAO 2021-03-04 15:16:47 +11:00
parent 88ac390495
commit a1d1b864e6
3 changed files with 13 additions and 11 deletions

View File

@ -35,8 +35,8 @@ class ClosedGroupControlMessage() : ControlMessage() {
class NameChange(val name: String) : Kind()
class MembersAdded(val members: List<ByteString>) : Kind()
class MembersRemoved( val members: List<ByteString>) : Kind()
object MemberLeft : Kind()
object EncryptionKeyPairRequest: Kind()
class MemberLeft : Kind()
class EncryptionKeyPairRequest: Kind()
val description: String = run {
when(this) {
@ -46,8 +46,8 @@ class ClosedGroupControlMessage() : ControlMessage() {
is NameChange -> "nameChange"
is MembersAdded -> "membersAdded"
is MembersRemoved -> "membersRemoved"
MemberLeft -> "memberLeft"
EncryptionKeyPairRequest -> "encryptionKeyPairRequest"
is MemberLeft -> "memberLeft"
is EncryptionKeyPairRequest -> "encryptionKeyPairRequest"
}
}
}
@ -92,10 +92,10 @@ class ClosedGroupControlMessage() : ControlMessage() {
kind = Kind.MembersRemoved(closedGroupControlMessageProto.membersList)
}
DataMessage.ClosedGroupControlMessage.Type.MEMBER_LEFT -> {
kind = Kind.MemberLeft
kind = Kind.MemberLeft()
}
DataMessage.ClosedGroupControlMessage.Type.ENCRYPTION_KEY_PAIR_REQUEST -> {
kind = Kind.EncryptionKeyPairRequest
kind = Kind.EncryptionKeyPairRequest()
}
}
return ClosedGroupControlMessage(kind)

View File

@ -212,8 +212,8 @@ private fun MessageReceiver.handleClosedGroupControlMessage(message: ClosedGroup
is ClosedGroupControlMessage.Kind.NameChange -> handleClosedGroupNameChanged(message)
is ClosedGroupControlMessage.Kind.MembersAdded -> handleClosedGroupMembersAdded(message)
is ClosedGroupControlMessage.Kind.MembersRemoved -> handleClosedGroupMembersRemoved(message)
ClosedGroupControlMessage.Kind.MemberLeft -> handleClosedGroupMemberLeft(message)
ClosedGroupControlMessage.Kind.EncryptionKeyPairRequest -> handleClosedGroupEncryptionKeyPairRequest(message)
is ClosedGroupControlMessage.Kind.MemberLeft -> handleClosedGroupMemberLeft(message)
is ClosedGroupControlMessage.Kind.EncryptionKeyPairRequest -> handleClosedGroupEncryptionKeyPairRequest(message)
}
}

View File

@ -50,9 +50,11 @@ fun MessageSender.create(name: String, members: Collection<String>): Promise<Str
storage.setProfileSharing(Address.fromSerialized(groupID), true)
// Send a closed group update message to all members individually
val closedGroupUpdateKind = ClosedGroupControlMessage.Kind.New(ByteString.copyFrom(Hex.fromStringCondensed(groupPublicKey)), name, encryptionKeyPair, membersAsData, adminsAsData)
val sentTime = System.currentTimeMillis()
for (member in members) {
val closedGroupControlMessage = ClosedGroupControlMessage(closedGroupUpdateKind)
sendNonDurably(closedGroupControlMessage, Address.fromSerialized(groupID)).get()
closedGroupControlMessage.sentTimestamp = sentTime
sendNonDurably(closedGroupControlMessage, Address.fromSerialized(member)).get()
}
// Add the group to the user's set of public keys to poll for
storage.addClosedGroupPublicKey(groupPublicKey)
@ -199,7 +201,7 @@ fun MessageSender.leave(groupPublicKey: String, notifyUser: Boolean = true): Pro
val admins = group.admins.map { it.serialize() }
val name = group.title
// Send the update to the group
val closedGroupControlMessage = ClosedGroupControlMessage(ClosedGroupControlMessage.Kind.MemberLeft)
val closedGroupControlMessage = ClosedGroupControlMessage(ClosedGroupControlMessage.Kind.MemberLeft())
closedGroupControlMessage.sentTimestamp = System.currentTimeMillis()
sendNonDurably(closedGroupControlMessage, Address.fromSerialized(groupID)).success {
// Notify the user
@ -265,7 +267,7 @@ fun MessageSender.requestEncryptionKeyPair(groupPublicKey: String) {
val members = group.members.map { it.serialize() }.toSet()
if (!members.contains(storage.getUserPublicKey()!!)) return
// Send the request to the group
val closedGroupControlMessage = ClosedGroupControlMessage(ClosedGroupControlMessage.Kind.EncryptionKeyPairRequest)
val closedGroupControlMessage = ClosedGroupControlMessage(ClosedGroupControlMessage.Kind.EncryptionKeyPairRequest())
send(closedGroupControlMessage, Address.fromSerialized(groupID))
}