Skip to content

Commit

Permalink
Merge pull request #6972 from gitstart/K9-OSS-3
Browse files Browse the repository at this point in the history
Inconsistent recipient names when composing a message
  • Loading branch information
cketti committed Jun 16, 2023
2 parents bf73b0a + ff79ee7 commit fb457bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@ public class RecipientLoader extends AsyncTaskLoader<List<Recipient>> {

private static final String[] PROJECTION_NICKNAME = {
ContactsContract.Data.CONTACT_ID,
ContactsContract.CommonDataKinds.Nickname.NAME
};

private static final int INDEX_CONTACT_ID_FOR_NICKNAME = 0;
private static final int INDEX_NICKNAME = 1;

private static final String[] PROJECTION_CRYPTO_ADDRESSES = {
"address",
Expand Down Expand Up @@ -377,8 +375,7 @@ private boolean fillContactDataFromNickname(String nickname, List<Recipient> rec
Cursor cursor = contentResolver
.query(queryUri, PROJECTION, selection, new String[] { id }, SORT_ORDER);

String contactNickname = nicknameCursor.getString(INDEX_NICKNAME);
fillContactDataFromCursor(cursor, recipients, recipientMap, contactNickname, null);
fillContactDataFromCursor(cursor, recipients, recipientMap, null);

hasContact = true;
}
Expand All @@ -403,7 +400,7 @@ private List<Recipient> fillContactDataBySortOrder(int maxRecipients) {
return recipients;
}

fillContactDataFromCursor(cursor, recipients, new HashMap<>(), null, maxRecipients);
fillContactDataFromCursor(cursor, recipients, new HashMap<>(), maxRecipients);

return recipients;
}
Expand Down Expand Up @@ -437,15 +434,14 @@ private boolean fillContactDataFromNameAndEmail(String query, List<Recipient> re

private void fillContactDataFromCursor(Cursor cursor, List<Recipient> recipients,
Map<String, Recipient> recipientMap) {
fillContactDataFromCursor(cursor, recipients, recipientMap, null, null);
fillContactDataFromCursor(cursor, recipients, recipientMap, null);
}

private void fillContactDataFromCursor(Cursor cursor, List<Recipient> recipients,
Map<String, Recipient> recipientMap, @Nullable String prefilledName, @Nullable Integer maxRecipients) {
Map<String, Recipient> recipientMap, @Nullable Integer maxRecipients) {

while (cursor.moveToNext() && (maxRecipients == null || recipients.size() < maxRecipients)) {
String name = prefilledName != null ? prefilledName : cursor.getString(INDEX_NAME);

String name = cursor.getString(INDEX_NAME);
String email = cursor.getString(INDEX_EMAIL);

// already exists? just skip then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public class RecipientLoaderTest extends RobolectricTest {
ContactsContract.Contacts.STARRED
};
static final String[] PROJECTION_NICKNAME = {
ContactsContract.Data.CONTACT_ID,
ContactsContract.CommonDataKinds.Nickname.NAME
ContactsContract.Data.CONTACT_ID
};
static final String[] PROJECTION_CRYPTO_ADDRESSES = { "address", "uid_address" };
static final String[] PROJECTION_CRYPTO_STATUS = { "address", "uid_key_status", "autocrypt_key_status" };
Expand All @@ -66,7 +65,7 @@ public class RecipientLoaderTest extends RobolectricTest {
static final String[] CONTACT_WITH_NICKNAME_NOT_CONTACTED =
new String[] { "0", "Eve_notContacted", "eve_notContacted", "eve_notContacted@host.com", TYPE, null, "2",
null, "0", "Eve", "0" };
static final String[] NICKNAME_NOT_CONTACTED = new String[] { "2", "Eves_Nickname_Bob" };
static final String[] NICKNAME_NOT_CONTACTED = new String[] { "2" };

static final String QUERYSTRING = "querystring";

Expand Down

0 comments on commit fb457bc

Please sign in to comment.