Skip to content

Commit

Permalink
Do a better job at filtering duplicate numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
moezbhatti committed Feb 6, 2020
1 parent bf808a8 commit e47bfb5
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,16 @@ class SyncRepositoryImpl @Inject constructor(
val uniqueNumbers = mutableListOf<PhoneNumber>()
contacts.value
.flatMap { it.numbers }
.sortedBy { it.accountType }
.forEach { number ->
number.isDefault = defaultNumberIds.any { id -> id == number.id }
val duplicate = uniqueNumbers.any { other ->
number.accountType != other.accountType
&& phoneNumberUtils.compare(number.address, other.address)
val duplicate = uniqueNumbers.find { other ->
phoneNumberUtils.compare(number.address, other.address)
}

if (!duplicate) {
if (duplicate == null) {
uniqueNumbers += number
} else if (!duplicate.isDefault && number.isDefault) {
duplicate.isDefault = true
}
}

Expand Down

0 comments on commit e47bfb5

Please sign in to comment.