mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-12 17:13:38 +00:00
Merge pull request #525 from Brice-W/zombie-handling-update
Closed Group Fixes
This commit is contained in:
commit
7ea399b55d
@ -1029,6 +1029,7 @@ public class ConversationFragment extends Fragment
|
||||
|
||||
@Override
|
||||
public void onItemClick(MessageRecord messageRecord) {
|
||||
if (messageRecord.isUpdate()) return;
|
||||
if (actionMode != null) {
|
||||
((ConversationAdapter) list.getAdapter()).toggleSelection(messageRecord);
|
||||
list.getAdapter().notifyDataSetChanged();
|
||||
@ -1044,6 +1045,7 @@ public class ConversationFragment extends Fragment
|
||||
|
||||
@Override
|
||||
public void onItemLongClick(MessageRecord messageRecord) {
|
||||
if (messageRecord.isUpdate()) return;
|
||||
if (actionMode == null) {
|
||||
((ConversationAdapter) list.getAdapter()).toggleSelection(messageRecord);
|
||||
list.getAdapter().notifyDataSetChanged();
|
||||
|
@ -294,7 +294,6 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt
|
||||
|
||||
ContentValues contents = new ContentValues();
|
||||
contents.put(ZOMBIE_MEMBERS, Address.toSerializedList(members, ','));
|
||||
contents.put(ACTIVE, 1);
|
||||
databaseHelper.getWritableDatabase().update(TABLE_NAME, contents, GROUP_ID + " = ?",
|
||||
new String[] {groupId});
|
||||
}
|
||||
|
@ -317,9 +317,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), ConversationClickLis
|
||||
}
|
||||
if (isClosedGroup) {
|
||||
MessageSender.explicitLeave(groupPublicKey!!, false)
|
||||
} else {
|
||||
Toast.makeText(context, R.string.activity_home_leaving_group_failed_message, Toast.LENGTH_LONG).show()
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
// Delete the conversation
|
||||
|
@ -266,6 +266,9 @@ private fun handleNewClosedGroup(sender: String, sentTimestamp: Long, groupPubli
|
||||
val groupID = GroupUtil.doubleEncodeGroupID(groupPublicKey)
|
||||
if (storage.getGroup(groupID) != null) {
|
||||
// Update the group
|
||||
// clearing zombie list if the group was not active before the update is received
|
||||
if (!storage.isGroupActive(groupID))
|
||||
storage.setZombieMembers(groupID, listOf<String>().map { Address.fromSerialized(it) })
|
||||
storage.updateTitle(groupID, name)
|
||||
storage.updateMembers(groupID, members.map { Address.fromSerialized(it) })
|
||||
} else {
|
||||
@ -390,6 +393,12 @@ private fun MessageReceiver.handleClosedGroupMembersAdded(message: ClosedGroupCo
|
||||
val updateMembers = kind.members.map { it.toByteArray().toHexString() }
|
||||
val newMembers = members + updateMembers
|
||||
storage.updateMembers(groupID, newMembers.map { Address.fromSerialized(it) })
|
||||
|
||||
// update zombie members in case the added members are zombies
|
||||
val zombies = storage.getZombieMembers(groupID)
|
||||
if (zombies.intersect(updateMembers).isNotEmpty())
|
||||
storage.setZombieMembers(groupID, zombies.minus(updateMembers).map { Address.fromSerialized(it) })
|
||||
|
||||
// Notify the user
|
||||
if (userPublicKey == senderPublicKey) {
|
||||
val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))
|
||||
@ -448,6 +457,7 @@ private fun MessageReceiver.handleClosedGroupMembersRemoved(message: ClosedGroup
|
||||
val members = group.members.map { it.serialize() }
|
||||
val admins = group.admins.map { it.toString() }
|
||||
val removedMembers = kind.members.map { it.toByteArray().toHexString() }
|
||||
val zombies: Set<String> = storage.getZombieMembers(groupID)
|
||||
// Check that the admin wasn't removed
|
||||
if (removedMembers.contains(admins.first())) {
|
||||
Log.d("Loki", "Ignoring invalid closed group update.")
|
||||
@ -473,12 +483,12 @@ private fun MessageReceiver.handleClosedGroupMembersRemoved(message: ClosedGroup
|
||||
disableLocalGroupAndUnsubscribe(groupPublicKey, groupID, userPublicKey)
|
||||
} else {
|
||||
storage.updateMembers(groupID, newMembers.map { Address.fromSerialized(it) })
|
||||
// Update zombie members
|
||||
storage.setZombieMembers(groupID, zombies.minus(removedMembers).map { Address.fromSerialized(it) })
|
||||
}
|
||||
// Update zombie members
|
||||
val zombies = storage.getZombieMembers(groupID)
|
||||
storage.setZombieMembers(groupID, zombies.minus(removedMembers).map { Address.fromSerialized(it) })
|
||||
val type = if (senderLeft) SignalServiceGroup.Type.QUIT else SignalServiceGroup.Type.MEMBER_REMOVED
|
||||
|
||||
// Notify the user
|
||||
val type = if (senderLeft) SignalServiceGroup.Type.QUIT else SignalServiceGroup.Type.MEMBER_REMOVED
|
||||
// We don't display zombie members in the notification as users have already been notified when those members left
|
||||
val notificationMembers = removedMembers.minus(zombies)
|
||||
if (notificationMembers.isNotEmpty()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user