Fix matches logic in contact selection.
This commit is contained in:
parent
fe25d941bb
commit
c5e7300df2
2 changed files with 13 additions and 7 deletions
|
@ -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.
|
||||
* <p>
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue