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);
}
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);
}
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);
}
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)));
}
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));
});
}
Aggregations