diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java
index de34abb650..340506ac30 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java
@@ -308,6 +308,13 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt
databaseHelper.getWritableDatabase().update(TABLE_NAME, contents, GROUP_ID + " = ?", new String[] {groupId});
}
+ public void updateFormationTimestamp(String groupId, Long formationTimestamp) {
+ ContentValues contents = new ContentValues();
+ contents.put(TIMESTAMP, formationTimestamp);
+
+ databaseHelper.getWritableDatabase().update(TABLE_NAME, contents, GROUP_ID + " = ?", new String[] {groupId});
+ }
+
public void removeMember(String groupId, Address source) {
List
currentMembers = getCurrentMembers(groupId, false);
currentMembers.remove(source);
diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt
index a09866b265..1c67eac4e3 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt
@@ -428,6 +428,11 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
DatabaseFactory.getLokiAPIDatabase(context).removeAllClosedGroupEncryptionKeyPairs(groupPublicKey)
}
+ override fun updateFormationTimestamp(groupID: String, formationTimestamp: Long) {
+ DatabaseFactory.getGroupDatabase(context)
+ .updateFormationTimestamp(groupID, formationTimestamp)
+ }
+
override fun setExpirationTimer(groupID: String, duration: Int) {
val recipient = Recipient.from(context, fromSerialized(groupID), false)
DatabaseFactory.getRecipientDatabase(context).setExpireMessages(recipient, duration);
diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/EditClosedGroupMembersAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/EditClosedGroupMembersAdapter.kt
index ab5e79d105..4a451ba222 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/EditClosedGroupMembersAdapter.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/EditClosedGroupMembersAdapter.kt
@@ -56,6 +56,8 @@ class EditClosedGroupMembersAdapter(
if (unlocked) {
viewHolder.view.setOnClickListener { this.memberClickListener?.invoke(member) }
+ } else {
+ viewHolder.view.setOnClickListener(null)
}
}
diff --git a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt
index dc557d337d..94a19ff072 100644
--- a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt
+++ b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt
@@ -115,6 +115,7 @@ interface StorageProtocol {
fun isClosedGroup(publicKey: String): Boolean
fun getClosedGroupEncryptionKeyPairs(groupPublicKey: String): MutableList
fun getLatestClosedGroupEncryptionKeyPair(groupPublicKey: String): ECKeyPair?
+ fun updateFormationTimestamp(groupID: String, formationTimestamp: Long)
fun setExpirationTimer(groupID: String, duration: Int)
// Groups
diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt
index 521d043170..dfd63b2090 100644
--- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt
+++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt
@@ -161,7 +161,13 @@ fun MessageSender.addMembers(groupPublicKey: String, membersToAdd: List)
for (member in membersToAdd) {
val closedGroupNewKind = ClosedGroupControlMessage.Kind.New(ByteString.copyFrom(Hex.fromStringCondensed(groupPublicKey)), name, encryptionKeyPair, membersAsData, adminsAsData, expireTimer)
val closedGroupControlMessage = ClosedGroupControlMessage(closedGroupNewKind)
- closedGroupControlMessage.sentTimestamp = sentTime
+ // It's important that the sent timestamp of this message is greater than the sent timestamp
+ // of the `MembersAdded` message above. The reason is that upon receiving this `New` message,
+ // the recipient will update the closed group formation timestamp and ignore any closed group
+ // updates from before that timestamp. By setting the timestamp of the message below to a value
+ // greater than that of the `MembersAdded` message, we ensure that newly added members ignore
+ // the `MembersAdded` message.
+ closedGroupControlMessage.sentTimestamp = System.currentTimeMillis()
send(closedGroupControlMessage, Address.fromSerialized(member))
}
// Notify the user
diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt
index bb6b5ada67..27bd608f3c 100644
--- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt
+++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt
@@ -263,27 +263,22 @@ private fun MessageReceiver.handleNewClosedGroup(message: ClosedGroupControlMess
private fun handleNewClosedGroup(sender: String, sentTimestamp: Long, groupPublicKey: String, name: String, encryptionKeyPair: ECKeyPair, members: List, admins: List, formationTimestamp: Long, expireTimer: Int) {
val context = MessagingModuleConfiguration.shared.context
val storage = MessagingModuleConfiguration.shared.storage
+ val userPublicKey = TextSecurePreferences.getLocalNumber(context)
// Create the group
val groupID = GroupUtil.doubleEncodeGroupID(groupPublicKey)
if (storage.getGroup(groupID) != null) {
// Update the group
- // Clear zombie list if the group wasn't active
if (!storage.isGroupActive(groupPublicKey)) {
+ // Clear zombie list if the group wasn't active
storage.setZombieMembers(groupID, listOf())
+ // Update the formation timestamp
+ storage.updateFormationTimestamp(groupID, formationTimestamp)
}
storage.updateTitle(groupID, name)
storage.updateMembers(groupID, members.map { Address.fromSerialized(it) })
} else {
storage.createGroup(groupID, name, LinkedList(members.map { Address.fromSerialized(it) }),
null, null, LinkedList(admins.map { Address.fromSerialized(it) }), formationTimestamp)
- val userPublicKey = TextSecurePreferences.getLocalNumber(context)
- // Notify the user
- if (userPublicKey == sender) {
- val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))
- storage.insertOutgoingInfoMessage(context, groupID, SignalServiceGroup.Type.CREATION, name, members, admins, threadID, sentTimestamp)
- } else {
- storage.insertIncomingInfoMessage(context, sender, groupID, SignalServiceGroup.Type.CREATION, name, members, admins, sentTimestamp)
- }
}
storage.setProfileSharing(Address.fromSerialized(groupID), true)
// Add the group to the user's set of public keys to poll for
@@ -294,6 +289,13 @@ private fun handleNewClosedGroup(sender: String, sentTimestamp: Long, groupPubli
storage.setExpirationTimer(groupID, expireTimer)
// Notify the PN server
PushNotificationAPI.performOperation(PushNotificationAPI.ClosedGroupOperation.Subscribe, groupPublicKey, storage.getUserPublicKey()!!)
+ // Notify the user
+ if (userPublicKey == sender) {
+ val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))
+ storage.insertOutgoingInfoMessage(context, groupID, SignalServiceGroup.Type.CREATION, name, members, admins, threadID, sentTimestamp)
+ } else {
+ storage.insertIncomingInfoMessage(context, sender, groupID, SignalServiceGroup.Type.CREATION, name, members, admins, sentTimestamp)
+ }
// Start polling
ClosedGroupPollerV2.shared.startPolling(groupPublicKey)
}
@@ -427,7 +429,7 @@ private fun MessageReceiver.handleClosedGroupMembersAdded(message: ClosedGroupCo
val encryptionKeyPair = pendingKeyPairs[groupPublicKey]?.orNull()
?: storage.getLatestClosedGroupEncryptionKeyPair(groupPublicKey)
if (encryptionKeyPair == null) {
- android.util.Log.d("Loki", "Couldn't get encryption key pair for closed group.")
+ Log.d("Loki", "Couldn't get encryption key pair for closed group.")
} else {
for (user in updateMembers) {
MessageSender.sendEncryptionKeyPair(groupPublicKey, encryptionKeyPair, setOf(user), targetUser = user, force = false)
@@ -559,12 +561,12 @@ private fun isValidGroupUpdate(group: GroupRecord, sentTimestamp: Long, senderPu
val oldMembers = group.members.map { it.serialize() }
// Check that the message isn't from before the group was created
if (group.formationTimestamp > sentTimestamp) {
- android.util.Log.d("Loki", "Ignoring closed group update from before thread was created.")
+ Log.d("Loki", "Ignoring closed group update from before thread was created.")
return false
}
// Check that the sender is a member of the group (before the update)
if (senderPublicKey !in oldMembers) {
- android.util.Log.d("Loki", "Ignoring closed group info message from non-member.")
+ Log.d("Loki", "Ignoring closed group info message from non-member.")
return false
}
return true