mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 17:29:32 +01:00
Improve and centralize e164 utils.
This commit is contained in:
@@ -16,7 +16,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.signal.libsignal.protocol.IdentityKey;
|
||||
import org.signal.libsignal.protocol.InvalidKeyException;
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.signal.core.util.Base64;
|
||||
@@ -53,7 +52,12 @@ public class IdentityKeyMismatch {
|
||||
if (!TextUtils.isEmpty(recipientId)) {
|
||||
return RecipientId.from(recipientId);
|
||||
} else {
|
||||
return Recipient.external(AppDependencies.getApplication(), address).getId();
|
||||
Recipient recipient = Recipient.external(address);
|
||||
if (recipient != null) {
|
||||
return recipient.getId();
|
||||
} else {
|
||||
return RecipientId.UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import androidx.annotation.NonNull;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
|
||||
@@ -34,7 +33,12 @@ public class NetworkFailure {
|
||||
if (!TextUtils.isEmpty(recipientId)) {
|
||||
return RecipientId.from(recipientId);
|
||||
} else {
|
||||
return Recipient.external(AppDependencies.getApplication(), address).getId();
|
||||
Recipient recipient = Recipient.external(address);
|
||||
if (recipient != null) {
|
||||
return recipient.getId();
|
||||
} else {
|
||||
return RecipientId.UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,11 +39,11 @@ import org.thoughtcrime.securesms.groups.GroupId
|
||||
import org.thoughtcrime.securesms.jobs.PreKeysSyncJob
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels
|
||||
import org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter
|
||||
import org.thoughtcrime.securesms.profiles.ProfileName
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper
|
||||
import org.thoughtcrime.securesms.util.FileUtils
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil
|
||||
import org.thoughtcrime.securesms.util.SignalE164Util
|
||||
import org.thoughtcrime.securesms.util.Triple
|
||||
import org.thoughtcrime.securesms.util.Util
|
||||
import org.whispersystems.signalservice.api.push.DistributionId
|
||||
@@ -379,7 +379,7 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
||||
db.rawQuery("SELECT recipient_ids, system_display_name, signal_profile_name, notification, vibrate FROM recipient_preferences WHERE notification NOT NULL OR vibrate != 0", null).use { cursor ->
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
val rawAddress: String = cursor.getString(cursor.getColumnIndexOrThrow("recipient_ids"))
|
||||
val address: String = PhoneNumberFormatter.get(context).format(rawAddress)
|
||||
val address: String = SignalE164Util.formatAsE164(rawAddress) ?: ""
|
||||
val systemName: String = cursor.getString(cursor.getColumnIndexOrThrow("system_display_name"))
|
||||
val profileName: String = cursor.getString(cursor.getColumnIndexOrThrow("signal_profile_name"))
|
||||
val messageSound: String? = cursor.getString(cursor.getColumnIndexOrThrow("notification"))
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package org.thoughtcrime.securesms.database.loaders;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.loader.content.AsyncTaskLoader;
|
||||
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
|
||||
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public final class CountryListLoader extends AsyncTaskLoader<ArrayList<Map<String, String>>> {
|
||||
|
||||
public CountryListLoader(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Map<String, String>> loadInBackground() {
|
||||
Set<String> regions = PhoneNumberUtil.getInstance().getSupportedRegions();
|
||||
ArrayList<Map<String, String>> results = new ArrayList<>(regions.size());
|
||||
|
||||
for (String region : regions) {
|
||||
Map<String, String> data = new HashMap<>(2);
|
||||
data.put("country_name", PhoneNumberFormatter.getRegionDisplayNameLegacy(region));
|
||||
data.put("country_code", "+" +PhoneNumberUtil.getInstance().getCountryCodeForRegion(region));
|
||||
results.add(data);
|
||||
}
|
||||
|
||||
Collections.sort(results, new RegionComparator());
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private static class RegionComparator implements Comparator<Map<String, String>> {
|
||||
|
||||
private final Collator collator;
|
||||
|
||||
RegionComparator() {
|
||||
collator = Collator.getInstance();
|
||||
collator.setStrength(Collator.PRIMARY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(Map<String, String> lhs, Map<String, String> rhs) {
|
||||
String a = lhs.get("country_name");
|
||||
String b = rhs.get("country_name");
|
||||
return collator.compare(a, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ import androidx.annotation.VisibleForTesting;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import org.signal.core.util.BidiUtil;
|
||||
import org.signal.core.util.StringUtil;
|
||||
import org.signal.storageservice.protos.groups.AccessControl;
|
||||
import org.signal.storageservice.protos.groups.Member;
|
||||
import org.signal.storageservice.protos.groups.local.DecryptedApproveMember;
|
||||
@@ -61,22 +60,16 @@ import org.thoughtcrime.securesms.backup.v2.proto.GroupV2MigrationSelfInvitedUpd
|
||||
import org.thoughtcrime.securesms.backup.v2.proto.GroupV2MigrationUpdate;
|
||||
import org.thoughtcrime.securesms.backup.v2.proto.SelfInvitedOtherUserToGroupUpdate;
|
||||
import org.thoughtcrime.securesms.backup.v2.proto.SelfInvitedToGroupUpdate;
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context;
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.GV2UpdateDescription;
|
||||
import org.thoughtcrime.securesms.groups.GV2AccessLevelUtil;
|
||||
import org.thoughtcrime.securesms.groups.GroupMigrationMembershipChange;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.thoughtcrime.securesms.util.ExpirationUtil;
|
||||
import org.thoughtcrime.securesms.util.SpanUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.signalservice.api.groupsv2.DecryptedGroupUtil;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
|
||||
import org.whispersystems.signalservice.api.push.ServiceIds;
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -35,7 +35,6 @@ import com.annimon.stream.Stream;
|
||||
|
||||
import org.signal.core.util.Base64;
|
||||
import org.signal.core.util.BidiUtil;
|
||||
import org.signal.core.util.StringUtil;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.signal.storageservice.protos.groups.local.DecryptedGroup;
|
||||
import org.signal.storageservice.protos.groups.local.DecryptedGroupChange;
|
||||
@@ -56,13 +55,13 @@ import org.thoughtcrime.securesms.emoji.EmojiSource;
|
||||
import org.thoughtcrime.securesms.emoji.JumboEmoji;
|
||||
import org.thoughtcrime.securesms.groups.GroupMigrationMembershipChange;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
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.DateUtils;
|
||||
import org.thoughtcrime.securesms.util.ExpirationUtil;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.SignalE164Util;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.signalservice.api.groupsv2.DecryptedGroupUtil;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
@@ -254,7 +253,7 @@ public abstract class MessageRecord extends DisplayRecord {
|
||||
if (event.previousE164.isEmpty()) {
|
||||
return fromRecipient(getFromRecipient(), r -> context.getString(R.string.MessageRecord_your_message_history_with_s_and_another_chat_has_been_merged, r.getDisplayName(context)), R.drawable.ic_thread_merge_16);
|
||||
} else {
|
||||
return fromRecipient(getFromRecipient(), r -> context.getString(R.string.MessageRecord_your_message_history_with_s_and_their_number_s_has_been_merged, r.getDisplayName(context), PhoneNumberFormatter.prettyPrint(event.previousE164)), R.drawable.ic_thread_merge_16);
|
||||
return fromRecipient(getFromRecipient(), r -> context.getString(R.string.MessageRecord_your_message_history_with_s_and_their_number_s_has_been_merged, r.getDisplayName(context), SignalE164Util.prettyPrint(event.previousE164)), R.drawable.ic_thread_merge_16);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
@@ -266,7 +265,7 @@ public abstract class MessageRecord extends DisplayRecord {
|
||||
if (event.e164.isEmpty()) {
|
||||
return fromRecipient(getFromRecipient(), r -> context.getString(R.string.MessageRecord_your_safety_number_with_s_has_changed, r.getDisplayName(context)), R.drawable.ic_update_safety_number_16);
|
||||
} else {
|
||||
return fromRecipient(getFromRecipient(), r -> context.getString(R.string.MessageRecord_s_belongs_to_s, PhoneNumberFormatter.prettyPrint(event.e164), r.getDisplayName(context)), R.drawable.ic_update_info_16);
|
||||
return fromRecipient(getFromRecipient(), r -> context.getString(R.string.MessageRecord_s_belongs_to_s, SignalE164Util.prettyPrint(event.e164), r.getDisplayName(context)), R.drawable.ic_update_info_16);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
@@ -487,7 +486,7 @@ public abstract class MessageRecord extends DisplayRecord {
|
||||
} else if (profileChangeDetails.learnedProfileName != null) {
|
||||
String previouslyKnownAs;
|
||||
if (!Util.isEmpty(profileChangeDetails.learnedProfileName.e164)) {
|
||||
previouslyKnownAs = PhoneNumberFormatter.prettyPrint(profileChangeDetails.learnedProfileName.e164);
|
||||
previouslyKnownAs = SignalE164Util.prettyPrint(profileChangeDetails.learnedProfileName.e164);
|
||||
} else {
|
||||
previouslyKnownAs = profileChangeDetails.learnedProfileName.username;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user