mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 09:49:30 +01:00
Improve and centralize e164 utils.
This commit is contained in:
@@ -27,10 +27,10 @@ import org.thoughtcrime.securesms.contactshare.Contact.Phone;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact.PostalAddress;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
import org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter;
|
||||
import org.thoughtcrime.securesms.profiles.ProfileName;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.thoughtcrime.securesms.util.SignalE164Util;
|
||||
import org.thoughtcrime.securesms.util.SpanUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -120,8 +120,8 @@ public final class ContactUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static @NonNull String getNormalizedPhoneNumber(@NonNull Context context, @Nullable String number) {
|
||||
return PhoneNumberFormatter.get(context).format(number);
|
||||
public static @Nullable String getNormalizedPhoneNumber(@Nullable String number) {
|
||||
return SignalE164Util.formatAsE164(number != null ? number : "");
|
||||
}
|
||||
|
||||
@MainThread
|
||||
@@ -142,11 +142,11 @@ public final class ContactUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<RecipientId> getRecipients(@NonNull Context context, @NonNull Contact contact) {
|
||||
public static List<RecipientId> getRecipients(@NonNull Contact contact) {
|
||||
return contact
|
||||
.getPhoneNumbers()
|
||||
.stream()
|
||||
.map(phone -> PhoneNumberFormatter.get(context).formatOrNull(phone.getNumber()))
|
||||
.map(phone -> SignalE164Util.formatAsE164(phone.getNumber()))
|
||||
.filter(number -> number != null)
|
||||
.map(phone -> SignalDatabase.recipients().getOrInsertFromE164(phone))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -97,7 +97,7 @@ public class SharedContactDetailsActivity extends PassphraseRequiredActivity {
|
||||
initViews();
|
||||
|
||||
presentContact(contact);
|
||||
presentActionButtons(ContactUtil.getRecipients(this, contact));
|
||||
presentActionButtons(ContactUtil.getRecipients(contact));
|
||||
presentAvatar(contact.getAvatarAttachment() != null ? contact.getAvatarAttachment().getUri() : null);
|
||||
|
||||
for (LiveRecipient recipient : activeRecipients.values()) {
|
||||
|
||||
@@ -19,9 +19,9 @@ import org.thoughtcrime.securesms.contactshare.Contact.Name;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact.Phone;
|
||||
import org.thoughtcrime.securesms.contactshare.Contact.PostalAddress;
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
import org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter;
|
||||
import org.thoughtcrime.securesms.providers.BlobProvider;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.SignalE164Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -130,7 +130,11 @@ public class SharedContactRepository {
|
||||
List<PhoneDetails> phoneDetails = SystemContactsRepository.getPhoneDetails(context, contactId);
|
||||
|
||||
for (PhoneDetails phone : phoneDetails) {
|
||||
String number = ContactUtil.getNormalizedPhoneNumber(context, phone.getNumber());
|
||||
String number = ContactUtil.getNormalizedPhoneNumber(phone.getNumber());
|
||||
if (number == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Phone existing = numberMap.get(number);
|
||||
Phone candidate = new Phone(number, VCardUtil.phoneTypeFromContactType(phone.getType()), phone.getLabel());
|
||||
|
||||
@@ -182,7 +186,12 @@ public class SharedContactRepository {
|
||||
}
|
||||
|
||||
for (Phone phoneNumber : phoneNumbers) {
|
||||
AvatarInfo recipientAvatar = getRecipientAvatarInfo(PhoneNumberFormatter.get(context).format(phoneNumber.getNumber()));
|
||||
String formattedNumber = SignalE164Util.formatAsE164(phoneNumber.getNumber());
|
||||
if (formattedNumber == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
AvatarInfo recipientAvatar = getRecipientAvatarInfo(formattedNumber);
|
||||
if (recipientAvatar != null) {
|
||||
return recipientAvatar;
|
||||
}
|
||||
@@ -202,7 +211,11 @@ public class SharedContactRepository {
|
||||
|
||||
@WorkerThread
|
||||
private @Nullable AvatarInfo getRecipientAvatarInfo(String address) {
|
||||
Recipient recipient = Recipient.external(context, address);
|
||||
Recipient recipient = Recipient.external(address);
|
||||
if (recipient == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ContactPhoto contactPhoto = recipient.getContactPhoto();
|
||||
|
||||
if (contactPhoto != null) {
|
||||
|
||||
Reference in New Issue
Block a user