Search in sources :

Example 76 with DecryptedMember

use of org.signal.storageservice.protos.groups.local.DecryptedMember in project Signal-Android by signalapp.

the class DecryptedGroupUtil_apply_Test method apply_new_pending_member_already_pending.

@Test
public void apply_new_pending_member_already_pending() throws NotAbleToApplyGroupV2ChangeException {
    DecryptedMember member1 = member(UUID.randomUUID());
    DecryptedPendingMember pending = pendingMember(UUID.randomUUID());
    DecryptedGroup newGroup = DecryptedGroupUtil.apply(DecryptedGroup.newBuilder().setRevision(10).addMembers(member1).addPendingMembers(pending).build(), DecryptedGroupChange.newBuilder().setRevision(11).addNewPendingMembers(pending).build());
    assertEquals(DecryptedGroup.newBuilder().setRevision(11).addMembers(member1).addPendingMembers(pending).build(), newGroup);
}
Also used : DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember) Test(org.junit.Test)

Example 77 with DecryptedMember

use of org.signal.storageservice.protos.groups.local.DecryptedMember in project Signal-Android by signalapp.

the class DecryptedGroupUtil method removeMember.

/**
 * Removes the uuid from the full members of a group.
 * <p>
 * Generally not expected to have to do this, just in the case of leaving a group where you cannot
 * get the new group state as you are not in the group any longer.
 */
public static DecryptedGroup removeMember(DecryptedGroup group, UUID uuid, int revision) {
    DecryptedGroup.Builder builder = DecryptedGroup.newBuilder(group);
    ByteString uuidString = UuidUtil.toByteString(uuid);
    boolean removed = false;
    ArrayList<DecryptedMember> decryptedMembers = new ArrayList<>(builder.getMembersList());
    Iterator<DecryptedMember> membersList = decryptedMembers.iterator();
    while (membersList.hasNext()) {
        if (uuidString.equals(membersList.next().getUuid())) {
            membersList.remove();
            removed = true;
        }
    }
    if (removed) {
        return builder.clearMembers().addAllMembers(decryptedMembers).setRevision(revision).build();
    } else {
        return group;
    }
}
Also used : ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember)

Example 78 with DecryptedMember

use of org.signal.storageservice.protos.groups.local.DecryptedMember in project Signal-Android by signalapp.

the class GroupChangeUtil method resolveField5ModifyMemberRoles.

private static void resolveField5ModifyMemberRoles(DecryptedGroupChange conflictingChange, ChangeSetModifier result, HashMap<ByteString, DecryptedMember> fullMembersByUuid) {
    List<DecryptedModifyMemberRole> modifyRolesList = conflictingChange.getModifyMemberRolesList();
    for (int i = modifyRolesList.size() - 1; i >= 0; i--) {
        DecryptedModifyMemberRole modifyRoleAction = modifyRolesList.get(i);
        DecryptedMember memberInGroup = fullMembersByUuid.get(modifyRoleAction.getUuid());
        if (memberInGroup == null || memberInGroup.getRole() == modifyRoleAction.getRole()) {
            result.removeModifyMemberRoles(i);
        }
    }
}
Also used : DecryptedModifyMemberRole(org.signal.storageservice.protos.groups.local.DecryptedModifyMemberRole) DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember)

Example 79 with DecryptedMember

use of org.signal.storageservice.protos.groups.local.DecryptedMember in project Signal-Android by signalapp.

the class DecryptedGroupChangeActionsBuilderChangeSetModifier method moveAddToPromote.

@Override
public void moveAddToPromote(int i) {
    DecryptedMember addMemberAction = result.getNewMembersList().get(i);
    result.removeNewMembers(i);
    result.addPromotePendingMembers(addMemberAction);
}
Also used : DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember)

Example 80 with DecryptedMember

use of org.signal.storageservice.protos.groups.local.DecryptedMember in project Signal-Android by signalapp.

the class DecryptedGroupChangeActionsBuilderChangeSetModifier method moveAddRequestingMembersToPromote.

@Override
public void moveAddRequestingMembersToPromote(int i) {
    DecryptedRequestingMember addMemberAction = result.getNewRequestingMembersList().get(i);
    result.removeNewRequestingMembers(i);
    DecryptedMember build = DecryptedMember.newBuilder().setUuid(addMemberAction.getUuid()).setProfileKey(addMemberAction.getProfileKey()).setRole(Member.Role.DEFAULT).build();
    result.addPromotePendingMembers(0, build);
}
Also used : DecryptedRequestingMember(org.signal.storageservice.protos.groups.local.DecryptedRequestingMember) DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember)

Aggregations

DecryptedMember (org.signal.storageservice.protos.groups.local.DecryptedMember)80 Test (org.junit.Test)54 DecryptedGroup (org.signal.storageservice.protos.groups.local.DecryptedGroup)48 UUID (java.util.UUID)32 DecryptedPendingMember (org.signal.storageservice.protos.groups.local.DecryptedPendingMember)20 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)14 ProtoTestUtils.newProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.newProfileKey)14 ProtoTestUtils.randomProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.randomProfileKey)14 ProtoTestUtils.withProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.withProfileKey)14 ByteString (com.google.protobuf.ByteString)12 DecryptedRequestingMember (org.signal.storageservice.protos.groups.local.DecryptedRequestingMember)12 DecryptedGroupChange (org.signal.storageservice.protos.groups.local.DecryptedGroupChange)10 NonNull (androidx.annotation.NonNull)6 WorkerThread (androidx.annotation.WorkerThread)6 DecryptedModifyMemberRole (org.signal.storageservice.protos.groups.local.DecryptedModifyMemberRole)6 Context (android.content.Context)4 DrawableRes (androidx.annotation.DrawableRes)4 Nullable (androidx.annotation.Nullable)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4