Search in sources :

Example 6 with DecryptedPendingMember

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

the class PendingMemberInvitesRepository method getInvitees.

public void getInvitees(@NonNull Consumer<InviteeResult> onInviteesLoaded) {
    executor.execute(() -> {
        GroupDatabase groupDatabase = SignalDatabase.groups();
        GroupDatabase.V2GroupProperties v2GroupProperties = groupDatabase.getGroup(groupId).get().requireV2GroupProperties();
        DecryptedGroup decryptedGroup = v2GroupProperties.getDecryptedGroup();
        List<DecryptedPendingMember> pendingMembersList = decryptedGroup.getPendingMembersList();
        List<SinglePendingMemberInvitedByYou> byMe = new ArrayList<>(pendingMembersList.size());
        List<MultiplePendingMembersInvitedByAnother> byOthers = new ArrayList<>(pendingMembersList.size());
        ByteString self = Recipient.self().requireServiceId().toByteString();
        boolean selfIsAdmin = v2GroupProperties.isAdmin(Recipient.self());
        Stream.of(pendingMembersList).groupBy(DecryptedPendingMember::getAddedByUuid).forEach(g -> {
            ByteString inviterUuid = g.getKey();
            List<DecryptedPendingMember> invitedMembers = g.getValue();
            if (self.equals(inviterUuid)) {
                for (DecryptedPendingMember pendingMember : invitedMembers) {
                    try {
                        Recipient invitee = GroupProtoUtil.pendingMemberToRecipient(context, pendingMember);
                        UuidCiphertext uuidCipherText = new UuidCiphertext(pendingMember.getUuidCipherText().toByteArray());
                        byMe.add(new SinglePendingMemberInvitedByYou(invitee, uuidCipherText));
                    } catch (InvalidInputException e) {
                        Log.w(TAG, e);
                    }
                }
            } else {
                Recipient inviter = GroupProtoUtil.uuidByteStringToRecipient(context, inviterUuid);
                ArrayList<UuidCiphertext> uuidCipherTexts = new ArrayList<>(invitedMembers.size());
                for (DecryptedPendingMember pendingMember : invitedMembers) {
                    try {
                        uuidCipherTexts.add(new UuidCiphertext(pendingMember.getUuidCipherText().toByteArray()));
                    } catch (InvalidInputException e) {
                        Log.w(TAG, e);
                    }
                }
                byOthers.add(new MultiplePendingMembersInvitedByAnother(inviter, uuidCipherTexts));
            }
        });
        onInviteesLoaded.accept(new InviteeResult(byMe, byOthers, selfIsAdmin));
    });
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) Recipient(org.thoughtcrime.securesms.recipients.Recipient) UuidCiphertext(org.signal.zkgroup.groups.UuidCiphertext) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup)

Example 7 with DecryptedPendingMember

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

the class DecryptedGroupUtil_apply_Test method apply_new_pending_member_already_in_group.

@Test(expected = NotAbleToApplyGroupV2ChangeException.class)
public void apply_new_pending_member_already_in_group() throws NotAbleToApplyGroupV2ChangeException {
    DecryptedMember member1 = member(UUID.randomUUID());
    UUID uuid2 = UUID.randomUUID();
    DecryptedMember member2 = member(uuid2);
    DecryptedPendingMember pending2 = pendingMember(uuid2);
    DecryptedGroupUtil.apply(DecryptedGroup.newBuilder().setRevision(10).addMembers(member1).addMembers(member2).build(), DecryptedGroupChange.newBuilder().setRevision(11).addNewPendingMembers(pending2).build());
}
Also used : DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember) UUID(java.util.UUID) DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember) Test(org.junit.Test)

Example 8 with DecryptedPendingMember

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

the class DecryptedGroupUtil_apply_Test method apply_new_pending_member.

@Test
public void apply_new_pending_member() throws NotAbleToApplyGroupV2ChangeException {
    DecryptedMember member1 = member(UUID.randomUUID());
    DecryptedPendingMember pending = pendingMember(UUID.randomUUID());
    DecryptedGroup newGroup = DecryptedGroupUtil.apply(DecryptedGroup.newBuilder().setRevision(10).addMembers(member1).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 9 with DecryptedPendingMember

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

the class DecryptedGroupUtil_apply_Test method skip_promote_pending_member_by_direct_add.

@Test
public void skip_promote_pending_member_by_direct_add() throws NotAbleToApplyGroupV2ChangeException {
    ProfileKey profileKey2 = randomProfileKey();
    ProfileKey profileKey3 = randomProfileKey();
    DecryptedMember member1 = member(UUID.randomUUID());
    UUID pending2Uuid = UUID.randomUUID();
    UUID pending3Uuid = UUID.randomUUID();
    UUID pending4Uuid = UUID.randomUUID();
    DecryptedPendingMember pending2 = pendingMember(pending2Uuid);
    DecryptedPendingMember pending3 = pendingMember(pending3Uuid);
    DecryptedPendingMember pending4 = pendingMember(pending4Uuid);
    DecryptedMember member2 = member(pending2Uuid, profileKey2);
    DecryptedMember member3 = member(pending3Uuid, profileKey3);
    DecryptedGroup newGroup = DecryptedGroupUtil.apply(DecryptedGroup.newBuilder().setRevision(10).addMembers(member1).addPendingMembers(pending2).addPendingMembers(pending3).addPendingMembers(pending4).build(), DecryptedGroupChange.newBuilder().setRevision(11).addNewMembers(member2).addNewMembers(member3).build());
    assertEquals(DecryptedGroup.newBuilder().setRevision(11).addMembers(member1).addMembers(member2).addMembers(member3).addPendingMembers(pending4).build(), newGroup);
}
Also used : DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember) UUID(java.util.UUID) ProtoTestUtils.withProfileKey(org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.withProfileKey) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) ProtoTestUtils.randomProfileKey(org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.randomProfileKey) ProtoTestUtils.newProfileKey(org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.newProfileKey) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember) Test(org.junit.Test)

Example 10 with DecryptedPendingMember

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

the class DecryptedGroupUtil method applyAddPendingMemberActions.

private static void applyAddPendingMemberActions(DecryptedGroup.Builder builder, List<DecryptedPendingMember> newPendingMembersList) throws NotAbleToApplyGroupV2ChangeException {
    Set<ByteString> fullMemberSet = getMemberUuidSet(builder.getMembersList());
    Set<ByteString> pendingMemberCipherTexts = getPendingMemberCipherTextSet(builder.getPendingMembersList());
    for (DecryptedPendingMember pendingMember : newPendingMembersList) {
        if (fullMemberSet.contains(pendingMember.getUuid())) {
            throw new NotAbleToApplyGroupV2ChangeException();
        }
        if (!pendingMemberCipherTexts.contains(pendingMember.getUuidCipherText())) {
            builder.addPendingMembers(pendingMember);
        }
    }
}
Also used : ByteString(com.google.protobuf.ByteString) DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember)

Aggregations

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