From a05f74d3023320ef1d1cc796928a5e0aacc96c92 Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Tue, 22 Sep 2020 14:09:48 -0300 Subject: [PATCH] Do not set color before profile name is known. --- .../securesms/database/RecipientDatabase.java | 2 +- .../thoughtcrime/securesms/profiles/ProfileName.java | 4 ++++ .../securesms/profiles/ProfileNameTest.java | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java index 7fe882dee2..2be09836f5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java @@ -999,7 +999,7 @@ public class RecipientDatabase extends Database { values.put(STORAGE_SERVICE_ID, Base64.encodeBytes(contact.getId().getRaw())); values.put(DIRTY, DirtyState.CLEAN.getId()); - if (contact.isProfileSharingEnabled() && isInsert) { + if (contact.isProfileSharingEnabled() && isInsert && !profileName.isEmpty()) { values.put(COLOR, ContactColors.generateFor(profileName.toString()).serialize()); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/profiles/ProfileName.java b/app/src/main/java/org/thoughtcrime/securesms/profiles/ProfileName.java index eb393dab74..193f17e6fa 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/profiles/ProfileName.java +++ b/app/src/main/java/org/thoughtcrime/securesms/profiles/ProfileName.java @@ -99,6 +99,10 @@ public final class ProfileName implements Parcelable { givenName = StringUtil.trimToFit(givenName.trim(), ProfileName.MAX_PART_LENGTH); familyName = StringUtil.trimToFit(familyName.trim(), ProfileName.MAX_PART_LENGTH); + if (givenName.isEmpty() && familyName.isEmpty()) { + return EMPTY; + } + return new ProfileName(givenName, familyName); } diff --git a/app/src/test/java/org/thoughtcrime/securesms/profiles/ProfileNameTest.java b/app/src/test/java/org/thoughtcrime/securesms/profiles/ProfileNameTest.java index c76b397366..577b867c89 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/profiles/ProfileNameTest.java +++ b/app/src/test/java/org/thoughtcrime/securesms/profiles/ProfileNameTest.java @@ -20,6 +20,7 @@ public final class ProfileNameTest { assertFalse("ProfileName should not be CJKV", profileName.isProfileNameCJKV()); assertEquals("ProfileName should have empty given name", "", profileName.getGivenName()); assertEquals("ProfileName should have empty family name", "", profileName.getFamilyName()); + assertTrue(profileName.isEmpty()); } @Test @@ -31,6 +32,15 @@ public final class ProfileNameTest { assertSame(ProfileName.EMPTY, profileName); } + @Test + public void givenProfileNameWithNulls_thenIExpectExactlyEmpty() { + // GIVEN + ProfileName profileName = ProfileName.fromParts(null, null); + + // THEN + assertSame(ProfileName.EMPTY, profileName); + } + @Test public void givenProfileNameWithGivenNameOnly_whenIFromDataString_thenIExpectValidProfileName() { // GIVEN