Skip to content

Commit

Permalink
Forward displayName and isStarred from contact instead of querying Data
Browse files Browse the repository at this point in the history
There is a case where the Data row queried might not have a display name (i.e in the case of a 3rd party mimetype). To be safe, we are using the information we need from the forwarding contact instead as it is guaranteed to be there.
  • Loading branch information
alexstyl committed Oct 24, 2021
1 parent 2432268 commit 386eddd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ class ContactStoreInsertContactTest : ContactStoreTestBase() {

val actual = store.fetchContacts(columnsToFetch = listOf(Events)).first()
val expected = contact(
displayName = "",
columns = listOf(Events),
events = listOf(
LabeledValue(
Expand Down Expand Up @@ -226,7 +225,6 @@ class ContactStoreInsertContactTest : ContactStoreTestBase() {

val actual = store.fetchContacts(columnsToFetch = listOf(WebAddresses)).first()
val expected = contact(
displayName = "",
columns = listOf(WebAddresses),
webAddresses = listOf(
LabeledValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ abstract class ContactStoreTestBase {
protected open val context: Application = ApplicationProvider.getApplicationContext()

protected fun contact(
displayName: String = "",
displayName: String? = null,
firstName: String? = null,
lastName: String? = null,
organization: String? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.alexstyl.contactstore

import com.alexstyl.contactstore.ContactColumn.Companion.standardColumns
import com.alexstyl.contactstore.ContactColumn.Events
import com.alexstyl.contactstore.ContactColumn.Image
import com.alexstyl.contactstore.ContactColumn.Mails
Expand Down
17 changes: 6 additions & 11 deletions library/src/main/java/com/alexstyl/contactstore/ContactQueries.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ internal class ContactQueries(
if (columnsToFetch.isEmpty()) {
contacts
} else {
// TODO forward contacts instead of just the ids and keep displayname + stars
val contactIds = contacts.map { it.contactId }
fetchAdditionalColumns(contactIds, columnsToFetch)
fetchAdditionalColumns(contacts, columnsToFetch)
}
}
}
Expand Down Expand Up @@ -198,10 +196,11 @@ internal class ContactQueries(
}

private fun fetchAdditionalColumns(
forContactIds: List<Long>,
forContacts: List<PartialContact>,
columnsToFetch: List<ContactColumn>
): List<Contact> {
return forContactIds.map { contactId ->
return forContacts.map { contact ->
val contactId = contact.contactId
var firstName: String? = null
var middleName: String? = null
var lastName: String? = null
Expand All @@ -222,8 +221,6 @@ internal class ContactQueries(
var organization: String? = null
var jobTitle: String? = null
var note: Note? = null
var displayName: String? = null
var isStarred = false
val groupIds = mutableListOf<GroupMembership>()
val linkedAccountValues = mutableListOf<LinkedAccountValue>()

Expand All @@ -232,8 +229,6 @@ internal class ContactQueries(
selection = buildColumnsToFetchSelection(contactId, columnsToFetch),
selectionArgs = buildSelectionArgs(columnsToFetch)
).iterate { row ->
displayName = row[Data.DISPLAY_NAME]
isStarred = row[Data.STARRED].toInt() == 1

when (row[Contacts.Data.MIMETYPE]) {
NicknameColumns.CONTENT_ITEM_TYPE -> {
Expand Down Expand Up @@ -372,8 +367,8 @@ internal class ContactQueries(
PartialContact(
contactId = contactId,
columns = columnsToFetch,
isStarred = isStarred,
displayName = displayName.orEmpty(),
isStarred = contact.isStarred,
displayName = contact.displayName,
firstName = firstName,
lastName = lastName,
imageData = imageData,
Expand Down

0 comments on commit 386eddd

Please sign in to comment.