Search in sources :

Example 21 with DecryptedPendingMember

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

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 22 with DecryptedPendingMember

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

the class DecryptedGroupUtil_apply_Test method promote_pending_member.

@Test
public void promote_pending_member() throws NotAbleToApplyGroupV2ChangeException {
    ProfileKey profileKey2 = randomProfileKey();
    DecryptedMember member1 = member(UUID.randomUUID());
    UUID pending2Uuid = UUID.randomUUID();
    DecryptedPendingMember pending2 = pendingMember(pending2Uuid);
    DecryptedMember member2 = member(pending2Uuid, profileKey2);
    DecryptedGroup newGroup = DecryptedGroupUtil.apply(DecryptedGroup.newBuilder().setRevision(10).addMembers(member1).addPendingMembers(pending2).build(), DecryptedGroupChange.newBuilder().setRevision(11).addPromotePendingMembers(member2).build());
    assertEquals(DecryptedGroup.newBuilder().setRevision(11).addMembers(member1).addMembers(member2).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 23 with DecryptedPendingMember

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

the class DecryptedGroupUtilTest method can_extract_uuid_from_bad_decrypted_pending_member.

@Test
public void can_extract_uuid_from_bad_decrypted_pending_member() {
    DecryptedPendingMember decryptedMember = DecryptedPendingMember.newBuilder().setUuid(ByteString.copyFrom(Util.getSecretBytes(17))).build();
    UUID parsed = DecryptedGroupUtil.toUuid(decryptedMember);
    assertEquals(UuidUtil.UNKNOWN_UUID, parsed);
}
Also used : DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember) UUID(java.util.UUID) Test(org.junit.Test)

Example 24 with DecryptedPendingMember

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

the class DecryptedGroupUtilTest method can_extract_uuids_for_all_pending_including_bad_entries.

@Test
public void can_extract_uuids_for_all_pending_including_bad_entries() {
    UUID uuid1 = UUID.randomUUID();
    UUID uuid2 = UUID.randomUUID();
    DecryptedPendingMember decryptedMember1 = DecryptedPendingMember.newBuilder().setUuid(UuidUtil.toByteString(uuid1)).build();
    DecryptedPendingMember decryptedMember2 = DecryptedPendingMember.newBuilder().setUuid(UuidUtil.toByteString(uuid2)).build();
    DecryptedPendingMember decryptedMember3 = DecryptedPendingMember.newBuilder().setUuid(ByteString.copyFrom(Util.getSecretBytes(17))).build();
    DecryptedGroupChange groupChange = DecryptedGroupChange.newBuilder().addNewPendingMembers(decryptedMember1).addNewPendingMembers(decryptedMember2).addNewPendingMembers(decryptedMember3).build();
    List<UUID> pendingUuids = DecryptedGroupUtil.pendingToUuidList(groupChange.getNewPendingMembersList());
    assertThat(pendingUuids, is(asList(uuid1, uuid2, UuidUtil.UNKNOWN_UUID)));
}
Also used : DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember) DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) UUID(java.util.UUID) Test(org.junit.Test)

Example 25 with DecryptedPendingMember

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

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)

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