From 323a4050040423a9eb7dd44c074e068c559145fe Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Fri, 4 Dec 2020 09:42:10 -0500 Subject: [PATCH] Don't format numbers unnecessarily. Util.getFirstNonEmpty() requires calculating all input strings first, but that's unnecessary and could result in lots of warning logs in the case of calling PhoneNumberFormatter#prettyPrint with nulls or other stuff. Fixes #10246 --- .../securesms/recipients/Recipient.java | 71 ++++++++++++++----- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/Recipient.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/Recipient.java index add06ca6bb..1274ef8d82 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/Recipient.java +++ b/app/src/main/java/org/thoughtcrime/securesms/recipients/Recipient.java @@ -416,32 +416,71 @@ public class Recipient { } public @NonNull String getDisplayName(@NonNull Context context) { - String name = Util.getFirstNonEmpty(getName(context), - getProfileName().toString(), - PhoneNumberFormatter.prettyPrint(e164), - email, - context.getString(R.string.Recipient_unknown)); + String name = getName(context); + + if (Util.isEmpty(name)) { + name = getProfileName().toString(); + } + + if (Util.isEmpty(name) && !Util.isEmpty(e164)) { + name = PhoneNumberFormatter.prettyPrint(e164); + } + + if (Util.isEmpty(name)) { + name = email; + } + + if (Util.isEmpty(name)) { + name = context.getString(R.string.Recipient_unknown); + } return StringUtil.isolateBidi(name); } public @NonNull String getDisplayNameOrUsername(@NonNull Context context) { - String name = Util.getFirstNonEmpty(getName(context), - getProfileName().toString(), - PhoneNumberFormatter.prettyPrint(e164), - email, - username, - context.getString(R.string.Recipient_unknown)); + String name = getName(context); + + if (Util.isEmpty(name)) { + name = getProfileName().toString(); + } + + if (Util.isEmpty(name) && !Util.isEmpty(e164)) { + name = PhoneNumberFormatter.prettyPrint(e164); + } + + if (Util.isEmpty(name)) { + name = email; + } + + if (Util.isEmpty(name)) { + name = username; + } + + if (Util.isEmpty(name)) { + name = context.getString(R.string.Recipient_unknown); + } return StringUtil.isolateBidi(name); } public @NonNull String getMentionDisplayName(@NonNull Context context) { - String name = Util.getFirstNonEmpty(isSelf ? getProfileName().toString() : getName(context), - isSelf ? getName(context) : getProfileName().toString(), - PhoneNumberFormatter.prettyPrint(e164), - email, - context.getString(R.string.Recipient_unknown)); + String name = isSelf ? getProfileName().toString() : getName(context); + + if (Util.isEmpty(name)) { + name = isSelf ? getName(context) : getProfileName().toString(); + } + + if (Util.isEmpty(name) && !Util.isEmpty(e164)) { + name = PhoneNumberFormatter.prettyPrint(e164); + } + + if (Util.isEmpty(name)) { + name = email; + } + + if (Util.isEmpty(name)) { + name = context.getString(R.string.Recipient_unknown); + } return StringUtil.isolateBidi(name); }