Respect the phoneNumberSharing setting on the profile.

This commit is contained in:
Greyson Parrelli
2023-12-20 11:48:02 -05:00
committed by Clark Chen
parent 624f863da4
commit bb30535afb
24 changed files with 257 additions and 44 deletions

View File

@@ -146,7 +146,8 @@ object RecipientDatabaseTestUtils {
badges = badges,
needsPniSignature = false,
hiddenState = Recipient.HiddenState.NOT_HIDDEN,
callLinkRoomId = null
callLinkRoomId = null,
phoneNumberSharing = RecipientTable.PhoneNumberSharingState.UNKNOWN
),
participantIds = participants,
isReleaseChannel = isReleaseChannel,

View File

@@ -37,6 +37,19 @@ public final class RecipientExporterTest {
assertNull(intent.getStringExtra(EMAIL));
}
@Test
public void asAddContactIntent_with_phone_number_should_not_show_number() {
Recipient recipient = givenPhoneRecipient(ProfileName.fromParts("Alice", null), "+1555123456", false);
Intent intent = RecipientExporter.export(recipient).asAddContactIntent();
assertEquals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction());
assertEquals(ContactsContract.Contacts.CONTENT_ITEM_TYPE, intent.getType());
assertEquals("Alice", intent.getStringExtra(NAME));
assertNull(intent.getStringExtra(PHONE));
assertNull(intent.getStringExtra(EMAIL));
}
@Test
public void asAddContactIntent_with_email() {
Recipient recipient = givenEmailRecipient(ProfileName.fromParts("Bob", null), "bob@signal.org");
@@ -50,13 +63,19 @@ public final class RecipientExporterTest {
assertNull(intent.getStringExtra(PHONE));
}
private Recipient givenPhoneRecipient(ProfileName profileName, String phone) {
return givenPhoneRecipient(profileName, phone, true);
}
private Recipient givenPhoneRecipient(ProfileName profileName, String phone, boolean shouldShowPhoneNumber) {
Recipient recipient = mock(Recipient.class);
when(recipient.getProfileName()).thenReturn(profileName);
when(recipient.requireE164()).thenReturn(phone);
when(recipient.getE164()).thenAnswer(i -> Optional.of(phone));
when(recipient.getEmail()).thenAnswer(i -> Optional.empty());
when(recipient.shouldShowE164()).thenAnswer(i -> shouldShowPhoneNumber);
return recipient;
}