From 2248acb9f272be811347841fbdf4b6bc5615afd0 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Tue, 8 Oct 2019 14:08:25 -0700 Subject: [PATCH] Remove unnecessary resolves. --- .../securesms/recipients/Recipient.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/org/thoughtcrime/securesms/recipients/Recipient.java b/src/org/thoughtcrime/securesms/recipients/Recipient.java index 0ee318f91c..2ed4d2ede6 100644 --- a/src/org/thoughtcrime/securesms/recipients/Recipient.java +++ b/src/org/thoughtcrime/securesms/recipients/Recipient.java @@ -197,7 +197,7 @@ public class Recipient { } public @Nullable String getName() { - if (this.name == null && isMmsGroup()) { + if (this.name == null && address != null && address.isMmsGroup()) { List names = new LinkedList<>(); for (Recipient recipient : participants) { @@ -225,10 +225,10 @@ public class Recipient { } public @NonNull MaterialColor getColor() { - if (isGroup()) return MaterialColor.GROUP; - else if (color != null) return color; - else if (name != null) return ContactColors.generateFor(name); - else return ContactColors.UNKNOWN_COLOR; + if (isGroupInternal()) return MaterialColor.GROUP; + else if (color != null) return color; + else if (name != null) return ContactColors.generateFor(name); + else return ContactColors.UNKNOWN_COLOR; } public @NonNull Address requireAddress() { @@ -263,6 +263,10 @@ public class Recipient { return requireAddress().isGroup(); } + private boolean isGroupInternal() { + return address != null && address.isGroup(); + } + public boolean isMmsGroup() { return requireAddress().isMmsGroup(); } @@ -277,7 +281,7 @@ public class Recipient { } public @NonNull String toShortString() { - return Optional.fromNullable(getName()).or(Optional.of(requireAddress().serialize())).get(); + return Optional.fromNullable(getName()).or(Optional.fromNullable(address != null ? address.serialize() : null)).or(""); } public @NonNull Drawable getFallbackContactPhotoDrawable(Context context, boolean inverted) { @@ -287,17 +291,17 @@ public class Recipient { public @NonNull FallbackContactPhoto getFallbackContactPhoto() { if (localNumber) return new ResourceContactPhoto(R.drawable.ic_note_to_self); if (isResolving()) return new TransparentContactPhoto(); - else if (isGroup()) return new ResourceContactPhoto(R.drawable.ic_group_white_24dp, R.drawable.ic_group_large); + else if (isGroupInternal()) return new ResourceContactPhoto(R.drawable.ic_group_white_24dp, R.drawable.ic_group_large); else if (!TextUtils.isEmpty(name)) return new GeneratedContactPhoto(name, R.drawable.ic_profile_default); else return new ResourceContactPhoto(R.drawable.ic_profile_default, R.drawable.ic_person_large); } public @Nullable ContactPhoto getContactPhoto() { - if (localNumber) return null; - else if (isGroup() && groupAvatarId.isPresent()) return new GroupRecordContactPhoto(address, groupAvatarId.get()); - else if (systemContactPhoto != null) return new SystemContactPhoto(address, systemContactPhoto, 0); - else if (profileAvatar != null) return new ProfileContactPhoto(address, profileAvatar); - else return null; + if (localNumber) return null; + else if (isGroupInternal() && groupAvatarId.isPresent()) return new GroupRecordContactPhoto(address, groupAvatarId.get()); + else if (systemContactPhoto != null) return new SystemContactPhoto(address, systemContactPhoto, 0); + else if (profileAvatar != null) return new ProfileContactPhoto(address, profileAvatar); + else return null; } public @Nullable Uri getMessageRingtone() {