Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent recipient names when composing a message #6972

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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