Detect if group v2 is active from membership.

This commit is contained in:
Alan Evans 2020-05-26 16:05:18 -03:00 committed by Greyson Parrelli
parent befb4939d5
commit 56551025e9
3 changed files with 8 additions and 10 deletions

View File

@ -391,11 +391,14 @@ public final class GroupDatabase extends Database {
RecipientId groupRecipientId = recipientDatabase.getOrInsertFromGroupId(groupId); RecipientId groupRecipientId = recipientDatabase.getOrInsertFromGroupId(groupId);
String title = decryptedGroup.getTitle(); String title = decryptedGroup.getTitle();
ContentValues contentValues = new ContentValues(); ContentValues contentValues = new ContentValues();
UUID uuid = Recipient.self().getUuid().get();
contentValues.put(TITLE, title); contentValues.put(TITLE, title);
contentValues.put(V2_REVISION, decryptedGroup.getVersion()); contentValues.put(V2_REVISION, decryptedGroup.getVersion());
contentValues.put(V2_DECRYPTED_GROUP, decryptedGroup.toByteArray()); contentValues.put(V2_DECRYPTED_GROUP, decryptedGroup.toByteArray());
contentValues.put(MEMBERS, serializeV2GroupMembers(decryptedGroup)); contentValues.put(MEMBERS, serializeV2GroupMembers(decryptedGroup));
contentValues.put(ACTIVE, DecryptedGroupUtil.findMemberByUuid(decryptedGroup.getMembersList(), uuid).isPresent() ||
DecryptedGroupUtil.findPendingByUuid(decryptedGroup.getPendingMembersList(), uuid).isPresent() ? 1 : 0);
databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues, databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues,
GROUP_ID + " = ?", GROUP_ID + " = ?",

View File

@ -140,16 +140,16 @@ final class GroupsV2UpdateMessageProducer {
boolean editorIsYou = change.getEditor().equals(selfUuidBytes); boolean editorIsYou = change.getEditor().equals(selfUuidBytes);
for (ByteString member : change.getDeleteMembersList()) { for (ByteString member : change.getDeleteMembersList()) {
boolean newMemberIsYou = member.equals(selfUuidBytes); boolean removedMemberIsYou = member.equals(selfUuidBytes);
if (editorIsYou) { if (editorIsYou) {
if (newMemberIsYou) { if (removedMemberIsYou) {
updates.add(context.getString(R.string.MessageRecord_you_left_the_group)); updates.add(context.getString(R.string.MessageRecord_you_left_the_group));
} else { } else {
updates.add(context.getString(R.string.MessageRecord_you_removed_s, describe(member))); updates.add(context.getString(R.string.MessageRecord_you_removed_s, describe(member)));
} }
} else { } else {
if (newMemberIsYou) { if (removedMemberIsYou) {
updates.add(context.getString(R.string.MessageRecord_s_removed_you_from_the_group, describe(change.getEditor()))); updates.add(context.getString(R.string.MessageRecord_s_removed_you_from_the_group, describe(change.getEditor())));
} else { } else {
if (member.equals(change.getEditor())) { if (member.equals(change.getEditor())) {

View File

@ -264,14 +264,9 @@ final class GroupManagerV2 {
@NonNull GroupManager.GroupActionResult ejectMember(@NonNull RecipientId recipientId) @NonNull GroupManager.GroupActionResult ejectMember(@NonNull RecipientId recipientId)
throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException
{ {
Recipient recipient = Recipient.resolved(recipientId); Recipient recipient = Recipient.resolved(recipientId);
GroupManager.GroupActionResult result = commitChangeWithConflictResolution(groupOperations.createRemoveMembersChange(Collections.singleton(recipient.getUuid().get())));
if (recipient.isLocalNumber()) { return commitChangeWithConflictResolution(groupOperations.createRemoveMembersChange(Collections.singleton(recipient.getUuid().get())));
groupDatabase.setActive(groupId, false);
}
return result;
} }
@WorkerThread @WorkerThread