Skip to content

Commit

Permalink
Detect if group v2 is active from membership.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-signal authored and greyson-signal committed May 29, 2020
1 parent befb493 commit 5655102
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
Expand Up @@ -391,11 +391,14 @@ public void update(@NonNull GroupId.V2 groupId, @NonNull DecryptedGroup decrypte
RecipientId groupRecipientId = recipientDatabase.getOrInsertFromGroupId(groupId);
String title = decryptedGroup.getTitle();
ContentValues contentValues = new ContentValues();
UUID uuid = Recipient.self().getUuid().get();

contentValues.put(TITLE, title);
contentValues.put(V2_REVISION, decryptedGroup.getVersion());
contentValues.put(V2_DECRYPTED_GROUP, decryptedGroup.toByteArray());
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,
GROUP_ID + " = ?",
Expand Down
Expand Up @@ -140,16 +140,16 @@ private void describeMemberRemovals(@NonNull DecryptedGroupChange change, @NonNu
boolean editorIsYou = change.getEditor().equals(selfUuidBytes);

for (ByteString member : change.getDeleteMembersList()) {
boolean newMemberIsYou = member.equals(selfUuidBytes);
boolean removedMemberIsYou = member.equals(selfUuidBytes);

if (editorIsYou) {
if (newMemberIsYou) {
if (removedMemberIsYou) {
updates.add(context.getString(R.string.MessageRecord_you_left_the_group));
} else {
updates.add(context.getString(R.string.MessageRecord_you_removed_s, describe(member)));
}
} else {
if (newMemberIsYou) {
if (removedMemberIsYou) {
updates.add(context.getString(R.string.MessageRecord_s_removed_you_from_the_group, describe(change.getEditor())));
} else {
if (member.equals(change.getEditor())) {
Expand Down
Expand Up @@ -264,14 +264,9 @@ class GroupEditor implements Closeable {
@NonNull GroupManager.GroupActionResult ejectMember(@NonNull RecipientId recipientId)
throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException
{
Recipient recipient = Recipient.resolved(recipientId);
GroupManager.GroupActionResult result = commitChangeWithConflictResolution(groupOperations.createRemoveMembersChange(Collections.singleton(recipient.getUuid().get())));

if (recipient.isLocalNumber()) {
groupDatabase.setActive(groupId, false);
}
Recipient recipient = Recipient.resolved(recipientId);

return result;
return commitChangeWithConflictResolution(groupOperations.createRemoveMembersChange(Collections.singleton(recipient.getUuid().get())));
}

@WorkerThread
Expand Down

0 comments on commit 5655102

Please sign in to comment.