diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/SelectedContact.java b/app/src/main/java/org/thoughtcrime/securesms/contacts/SelectedContact.java index 407df2b89a..54d15c70b1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contacts/SelectedContact.java +++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/SelectedContact.java @@ -43,13 +43,19 @@ public final class SelectedContact { } /** - * Returns true iff any non-null property matches one on the other contact. + * Returns true when non-null recipient ids match, and false if not. + *
+ * If one or more recipient id is not set, then it returns true iff any other non-null property + * matches one on the other contact. */ public boolean matches(@Nullable SelectedContact other) { if (other == null) return false; - return recipientId != null && recipientId.equals(other.recipientId) || - number != null && number .equals(other.number) || - username != null && username .equals(other.username); + if (recipientId != null && other.recipientId != null) { + return recipientId.equals(other.recipientId); + } + + return number != null && number .equals(other.number) || + username != null && username.equals(other.username); } } diff --git a/app/src/test/java/org/thoughtcrime/securesms/contacts/SelectedContactSetTest.java b/app/src/test/java/org/thoughtcrime/securesms/contacts/SelectedContactSetTest.java index a95829b1c9..f32bef64f6 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/contacts/SelectedContactSetTest.java +++ b/app/src/test/java/org/thoughtcrime/securesms/contacts/SelectedContactSetTest.java @@ -3,8 +3,8 @@ package org.thoughtcrime.securesms.contacts; import org.junit.Test; import org.thoughtcrime.securesms.recipients.RecipientId; -import static edu.emory.mathcs.backport.java.util.Collections.singletonList; import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -92,13 +92,13 @@ public final class SelectedContactSetTest { SelectedContact contact1 = SelectedContact.forPhone(RecipientId.from(1), "+1-555-000-0000"); SelectedContact contact2 = SelectedContact.forUsername(RecipientId.from(2), "@alice"); SelectedContact contact3 = SelectedContact.forUsername(null, "@bob"); - SelectedContact contact2Remove = SelectedContact.forUsername(RecipientId.from(1), "@alice"); + SelectedContact contact2Remove = SelectedContact.forUsername(RecipientId.from(1), "@bob"); assertTrue(selectedContactSet.add(contact1)); assertTrue(selectedContactSet.add(contact2)); assertTrue(selectedContactSet.add(contact3)); assertEquals(2, selectedContactSet.remove(contact2Remove)); - assertThat(selectedContactSet.getContacts(), is(singletonList(contact3))); + assertThat(selectedContactSet.getContacts(), is(singletonList(contact2))); } }