diff --git a/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupActivity.kt b/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupActivity.kt index cb6e80f5ea..dfa13e8003 100644 --- a/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupActivity.kt @@ -247,7 +247,8 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() { if (isSSKBasedClosedGroup) { //TODO AC: Should it use "groupPublicKey" or "groupID"? - ClosedGroupsProtocol.updateGroup(this, groupPublicKey!!, finalGroupMembers, null, groupDisplayName, finalGroupAdmins) + ClosedGroupsProtocol.update(this, groupPublicKey!!, finalGroupMembers.map { it.address.serialize() }, + groupDisplayName, finalGroupAdmins.map { it.address.serialize() }) } else { GroupManager.updateGroup(this, groupID, finalGroupMembers, null, groupDisplayName, finalGroupAdmins) } diff --git a/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt b/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt index 13c416fe55..9ec9fe5563 100644 --- a/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt +++ b/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt @@ -184,15 +184,23 @@ object ClosedGroupsProtocol { insertOutgoingInfoMessage(context, groupID, GroupContext.Type.QUIT, name, members, admins, threadID) } - //TODO AC: This is a reflection of GroupManager's update API. - // It needs a valid implementation and probably the signature should be refactored a bit. - public fun updateGroup(context: Context, - groupPublicKey: String, - members: Collection, - avatar: Bitmap?, - name: String, - admins: Collection) { - // STUB + public fun update(context: Context, groupPublicKey: String, members: Collection, name: String, admins: Collection) { + val groupDB = DatabaseFactory.getGroupDatabase(context) + val groupID = doubleEncodeGroupID(groupPublicKey) + if (groupDB.getGroup(groupID).orNull() == null) { + Log.d("Loki", "Can't update nonexistent closed group.") + return + } + // Send the update to the group + val closedGroupUpdateKind = ClosedGroupUpdateMessageSendJob.Kind.Info(Hex.fromStringCondensed(groupPublicKey), + name, setOf(), members.map { Hex.fromStringCondensed(it) }, admins.map { Hex.fromStringCondensed(it) }) + val job = ClosedGroupUpdateMessageSendJob(groupPublicKey, closedGroupUpdateKind) + ApplicationContext.getInstance(context).jobManager.add(job) + // Update the group + groupDB.updateMembers(groupID, members.map { Address.fromSerialized(it) }) + // Notify the user + val threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(Recipient.from(context, Address.fromSerialized(groupID), false)) + insertOutgoingInfoMessage(context, groupID, GroupContext.Type.UPDATE, name, members, admins, threadID) } @JvmStatic