Fix several issues with contact name syncing.
This commit is contained in:
parent
d83c3d35eb
commit
9e56441d4a
7 changed files with 37 additions and 16 deletions
|
@ -42,6 +42,7 @@ final class ContactHolder {
|
||||||
for (PhoneNumberRecord phoneNumberRecord : phoneNumberRecords) {
|
for (PhoneNumberRecord phoneNumberRecord : phoneNumberRecords) {
|
||||||
handle.setSystemContactInfo(phoneNumberRecord.getRecipientId(),
|
handle.setSystemContactInfo(phoneNumberRecord.getRecipientId(),
|
||||||
getProfileName(phoneNumberRecord.getDisplayName()),
|
getProfileName(phoneNumberRecord.getDisplayName()),
|
||||||
|
phoneNumberRecord.getDisplayName(),
|
||||||
phoneNumberRecord.getContactPhotoUri(),
|
phoneNumberRecord.getContactPhotoUri(),
|
||||||
phoneNumberRecord.getContactLabel(),
|
phoneNumberRecord.getContactLabel(),
|
||||||
phoneNumberRecord.getPhoneType(),
|
phoneNumberRecord.getPhoneType(),
|
||||||
|
|
|
@ -323,17 +323,18 @@ public class DirectoryHelper {
|
||||||
|
|
||||||
BulkOperationsHandle handle = recipientDatabase.beginBulkSystemContactUpdate();
|
BulkOperationsHandle handle = recipientDatabase.beginBulkSystemContactUpdate();
|
||||||
|
|
||||||
ContactHolder old = null;
|
|
||||||
try (Cursor cursor = ContactAccessor.getInstance().getAllSystemContacts(context)) {
|
try (Cursor cursor = ContactAccessor.getInstance().getAllSystemContacts(context)) {
|
||||||
while (cursor != null && cursor.moveToNext()) {
|
while (cursor != null && cursor.moveToNext()) {
|
||||||
String lookupKey = getLookupKey(cursor);
|
|
||||||
String mimeType = getMimeType(cursor);
|
String mimeType = getMimeType(cursor);
|
||||||
ContactHolder contactHolder = new ContactHolder(lookupKey);
|
|
||||||
|
|
||||||
if (!isPhoneMimeType(mimeType)) {
|
if (!isPhoneMimeType(mimeType)) {
|
||||||
Log.w(TAG, "Ignoring unexpected mime type: " + mimeType);
|
Log.w(TAG, "Ignoring unwanted mime type: " + mimeType);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String lookupKey = getLookupKey(cursor);
|
||||||
|
ContactHolder contactHolder = new ContactHolder(lookupKey);
|
||||||
|
|
||||||
while (!cursor.isAfterLast() && getLookupKey(cursor).equals(lookupKey) && isPhoneMimeType(getMimeType(cursor))) {
|
while (!cursor.isAfterLast() && getLookupKey(cursor).equals(lookupKey) && isPhoneMimeType(getMimeType(cursor))) {
|
||||||
String number = CursorUtil.requireString(cursor, ContactsContract.CommonDataKinds.Phone.NUMBER);
|
String number = CursorUtil.requireString(cursor, ContactsContract.CommonDataKinds.Phone.NUMBER);
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,7 @@ public class RecipientDatabase extends Database {
|
||||||
ID, UUID, USERNAME, PHONE, EMAIL, GROUP_ID, GROUP_TYPE,
|
ID, UUID, USERNAME, PHONE, EMAIL, GROUP_ID, GROUP_TYPE,
|
||||||
BLOCKED, MESSAGE_RINGTONE, CALL_RINGTONE, MESSAGE_VIBRATE, CALL_VIBRATE, MUTE_UNTIL, COLOR, SEEN_INVITE_REMINDER, DEFAULT_SUBSCRIPTION_ID, MESSAGE_EXPIRATION_TIME, REGISTERED,
|
BLOCKED, MESSAGE_RINGTONE, CALL_RINGTONE, MESSAGE_VIBRATE, CALL_VIBRATE, MUTE_UNTIL, COLOR, SEEN_INVITE_REMINDER, DEFAULT_SUBSCRIPTION_ID, MESSAGE_EXPIRATION_TIME, REGISTERED,
|
||||||
PROFILE_KEY, PROFILE_KEY_CREDENTIAL,
|
PROFILE_KEY, PROFILE_KEY_CREDENTIAL,
|
||||||
SYSTEM_GIVEN_NAME, SYSTEM_FAMILY_NAME, SYSTEM_PHOTO_URI, SYSTEM_PHONE_LABEL, SYSTEM_PHONE_TYPE, SYSTEM_CONTACT_URI,
|
SYSTEM_JOINED_NAME, SYSTEM_GIVEN_NAME, SYSTEM_FAMILY_NAME, SYSTEM_PHOTO_URI, SYSTEM_PHONE_LABEL, SYSTEM_PHONE_TYPE, SYSTEM_CONTACT_URI,
|
||||||
PROFILE_GIVEN_NAME, PROFILE_FAMILY_NAME, SIGNAL_PROFILE_AVATAR, PROFILE_SHARING, LAST_PROFILE_FETCH,
|
PROFILE_GIVEN_NAME, PROFILE_FAMILY_NAME, SIGNAL_PROFILE_AVATAR, PROFILE_SHARING, LAST_PROFILE_FETCH,
|
||||||
NOTIFICATION_CHANNEL,
|
NOTIFICATION_CHANNEL,
|
||||||
UNIDENTIFIED_ACCESS_MODE,
|
UNIDENTIFIED_ACCESS_MODE,
|
||||||
|
@ -1271,6 +1271,7 @@ public class RecipientDatabase extends Database {
|
||||||
String profileKeyCredentialString = CursorUtil.requireString(cursor, PROFILE_KEY_CREDENTIAL);
|
String profileKeyCredentialString = CursorUtil.requireString(cursor, PROFILE_KEY_CREDENTIAL);
|
||||||
String systemGivenName = CursorUtil.requireString(cursor, SYSTEM_GIVEN_NAME);
|
String systemGivenName = CursorUtil.requireString(cursor, SYSTEM_GIVEN_NAME);
|
||||||
String systemFamilyName = CursorUtil.requireString(cursor, SYSTEM_FAMILY_NAME);
|
String systemFamilyName = CursorUtil.requireString(cursor, SYSTEM_FAMILY_NAME);
|
||||||
|
String systemDisplayName = CursorUtil.requireString(cursor, SYSTEM_JOINED_NAME);
|
||||||
String systemContactPhoto = CursorUtil.requireString(cursor, SYSTEM_PHOTO_URI);
|
String systemContactPhoto = CursorUtil.requireString(cursor, SYSTEM_PHOTO_URI);
|
||||||
String systemPhoneLabel = CursorUtil.requireString(cursor, SYSTEM_PHONE_LABEL);
|
String systemPhoneLabel = CursorUtil.requireString(cursor, SYSTEM_PHONE_LABEL);
|
||||||
String systemContactUri = CursorUtil.requireString(cursor, SYSTEM_CONTACT_URI);
|
String systemContactUri = CursorUtil.requireString(cursor, SYSTEM_CONTACT_URI);
|
||||||
|
@ -1357,6 +1358,7 @@ public class RecipientDatabase extends Database {
|
||||||
profileKey,
|
profileKey,
|
||||||
profileKeyCredential,
|
profileKeyCredential,
|
||||||
ProfileName.fromParts(systemGivenName, systemFamilyName),
|
ProfileName.fromParts(systemGivenName, systemFamilyName),
|
||||||
|
systemDisplayName,
|
||||||
systemContactPhoto,
|
systemContactPhoto,
|
||||||
systemPhoneLabel,
|
systemPhoneLabel,
|
||||||
systemContactUri,
|
systemContactUri,
|
||||||
|
@ -2849,15 +2851,18 @@ public class RecipientDatabase extends Database {
|
||||||
|
|
||||||
public void setSystemContactInfo(@NonNull RecipientId id,
|
public void setSystemContactInfo(@NonNull RecipientId id,
|
||||||
@NonNull ProfileName systemProfileName,
|
@NonNull ProfileName systemProfileName,
|
||||||
|
@Nullable String systemDisplayName,
|
||||||
@Nullable String photoUri,
|
@Nullable String photoUri,
|
||||||
@Nullable String systemPhoneLabel,
|
@Nullable String systemPhoneLabel,
|
||||||
int systemPhoneType,
|
int systemPhoneType,
|
||||||
@Nullable String systemContactUri)
|
@Nullable String systemContactUri)
|
||||||
{
|
{
|
||||||
ContentValues dirtyQualifyingValues = new ContentValues();
|
ContentValues dirtyQualifyingValues = new ContentValues();
|
||||||
|
String joinedName = Util.firstNonNull(systemDisplayName, systemProfileName.toString());
|
||||||
|
|
||||||
dirtyQualifyingValues.put(SYSTEM_GIVEN_NAME, systemProfileName.getGivenName());
|
dirtyQualifyingValues.put(SYSTEM_GIVEN_NAME, systemProfileName.getGivenName());
|
||||||
dirtyQualifyingValues.put(SYSTEM_FAMILY_NAME, systemProfileName.getFamilyName());
|
dirtyQualifyingValues.put(SYSTEM_FAMILY_NAME, systemProfileName.getFamilyName());
|
||||||
dirtyQualifyingValues.put(SYSTEM_JOINED_NAME, systemProfileName.toString());
|
dirtyQualifyingValues.put(SYSTEM_JOINED_NAME, joinedName);
|
||||||
|
|
||||||
if (update(id, dirtyQualifyingValues)) {
|
if (update(id, dirtyQualifyingValues)) {
|
||||||
markDirty(id, DirtyState.UPDATE);
|
markDirty(id, DirtyState.UPDATE);
|
||||||
|
@ -2869,7 +2874,6 @@ public class RecipientDatabase extends Database {
|
||||||
refreshQualifyingValues.put(SYSTEM_PHONE_TYPE, systemPhoneType);
|
refreshQualifyingValues.put(SYSTEM_PHONE_TYPE, systemPhoneType);
|
||||||
refreshQualifyingValues.put(SYSTEM_CONTACT_URI, systemContactUri);
|
refreshQualifyingValues.put(SYSTEM_CONTACT_URI, systemContactUri);
|
||||||
|
|
||||||
String joinedName = systemProfileName.toString();
|
|
||||||
boolean updatedValues = update(id, refreshQualifyingValues);
|
boolean updatedValues = update(id, refreshQualifyingValues);
|
||||||
boolean updatedColor = !TextUtils.isEmpty(joinedName) && setColorIfNotSetInternal(id, ContactColors.generateFor(joinedName));
|
boolean updatedColor = !TextUtils.isEmpty(joinedName) && setColorIfNotSetInternal(id, ContactColors.generateFor(joinedName));
|
||||||
|
|
||||||
|
@ -2953,6 +2957,7 @@ public class RecipientDatabase extends Database {
|
||||||
private final byte[] profileKey;
|
private final byte[] profileKey;
|
||||||
private final ProfileKeyCredential profileKeyCredential;
|
private final ProfileKeyCredential profileKeyCredential;
|
||||||
private final ProfileName systemProfileName;
|
private final ProfileName systemProfileName;
|
||||||
|
private final String systemDisplayName;
|
||||||
private final String systemContactPhoto;
|
private final String systemContactPhoto;
|
||||||
private final String systemPhoneLabel;
|
private final String systemPhoneLabel;
|
||||||
private final String systemContactUri;
|
private final String systemContactUri;
|
||||||
|
@ -2995,6 +3000,7 @@ public class RecipientDatabase extends Database {
|
||||||
@Nullable byte[] profileKey,
|
@Nullable byte[] profileKey,
|
||||||
@Nullable ProfileKeyCredential profileKeyCredential,
|
@Nullable ProfileKeyCredential profileKeyCredential,
|
||||||
@NonNull ProfileName systemProfileName,
|
@NonNull ProfileName systemProfileName,
|
||||||
|
@Nullable String systemDisplayName,
|
||||||
@Nullable String systemContactPhoto,
|
@Nullable String systemContactPhoto,
|
||||||
@Nullable String systemPhoneLabel,
|
@Nullable String systemPhoneLabel,
|
||||||
@Nullable String systemContactUri,
|
@Nullable String systemContactUri,
|
||||||
|
@ -3035,6 +3041,7 @@ public class RecipientDatabase extends Database {
|
||||||
this.profileKey = profileKey;
|
this.profileKey = profileKey;
|
||||||
this.profileKeyCredential = profileKeyCredential;
|
this.profileKeyCredential = profileKeyCredential;
|
||||||
this.systemProfileName = systemProfileName;
|
this.systemProfileName = systemProfileName;
|
||||||
|
this.systemDisplayName = systemDisplayName;
|
||||||
this.systemContactPhoto = systemContactPhoto;
|
this.systemContactPhoto = systemContactPhoto;
|
||||||
this.systemPhoneLabel = systemPhoneLabel;
|
this.systemPhoneLabel = systemPhoneLabel;
|
||||||
this.systemContactUri = systemContactUri;
|
this.systemContactUri = systemContactUri;
|
||||||
|
@ -3142,6 +3149,10 @@ public class RecipientDatabase extends Database {
|
||||||
return systemProfileName;
|
return systemProfileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NonNull String getSystemDisplayName() {
|
||||||
|
return systemDisplayName;
|
||||||
|
}
|
||||||
|
|
||||||
public @Nullable String getSystemContactPhotoUri() {
|
public @Nullable String getSystemContactPhotoUri() {
|
||||||
return systemContactPhoto;
|
return systemContactPhoto;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1538,6 +1538,7 @@ public class ThreadDatabase extends Database {
|
||||||
|
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
RecipientDetails details = new RecipientDetails(group.getTitle(),
|
RecipientDetails details = new RecipientDetails(group.getTitle(),
|
||||||
|
null,
|
||||||
group.hasAvatar() ? Optional.of(group.getAvatarId()) : Optional.absent(),
|
group.hasAvatar() ? Optional.of(group.getAvatarId()) : Optional.absent(),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
|
|
@ -212,10 +212,10 @@ public final class LiveRecipient {
|
||||||
avatarId = Optional.of(groupRecord.get().getAvatarId());
|
avatarId = Optional.of(groupRecord.get().getAvatarId());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RecipientDetails(title, avatarId, false, false, settings, members);
|
return new RecipientDetails(title, null, avatarId, false, false, settings, members);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RecipientDetails(null, Optional.absent(), false, false, settings, null);
|
return new RecipientDetails(null, null, Optional.absent(), false, false, settings, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void set(@NonNull Recipient recipient) {
|
synchronized void set(@NonNull Recipient recipient) {
|
||||||
|
|
|
@ -110,6 +110,7 @@ public class Recipient {
|
||||||
private final String about;
|
private final String about;
|
||||||
private final String aboutEmoji;
|
private final String aboutEmoji;
|
||||||
private final ProfileName systemProfileName;
|
private final ProfileName systemProfileName;
|
||||||
|
private final String systemContactName;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -347,6 +348,7 @@ public class Recipient {
|
||||||
this.about = null;
|
this.about = null;
|
||||||
this.aboutEmoji = null;
|
this.aboutEmoji = null;
|
||||||
this.systemProfileName = ProfileName.EMPTY;
|
this.systemProfileName = ProfileName.EMPTY;
|
||||||
|
this.systemContactName = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Recipient(@NonNull RecipientId id, @NonNull RecipientDetails details, boolean resolved) {
|
public Recipient(@NonNull RecipientId id, @NonNull RecipientDetails details, boolean resolved) {
|
||||||
|
@ -393,6 +395,7 @@ public class Recipient {
|
||||||
this.about = details.about;
|
this.about = details.about;
|
||||||
this.aboutEmoji = details.aboutEmoji;
|
this.aboutEmoji = details.aboutEmoji;
|
||||||
this.systemProfileName = details.systemProfileName;
|
this.systemProfileName = details.systemProfileName;
|
||||||
|
this.systemContactName = details.systemContactName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NonNull RecipientId getId() {
|
public @NonNull RecipientId getId() {
|
||||||
|
@ -432,7 +435,7 @@ public class Recipient {
|
||||||
*/
|
*/
|
||||||
public boolean hasAUserSetDisplayName(@NonNull Context context) {
|
public boolean hasAUserSetDisplayName(@NonNull Context context) {
|
||||||
return !TextUtils.isEmpty(getGroupName(context)) ||
|
return !TextUtils.isEmpty(getGroupName(context)) ||
|
||||||
!TextUtils.isEmpty(getSystemProfileName().toString()) ||
|
!TextUtils.isEmpty(systemContactName) ||
|
||||||
!TextUtils.isEmpty(getProfileName().toString());
|
!TextUtils.isEmpty(getProfileName().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,7 +443,7 @@ public class Recipient {
|
||||||
String name = getGroupName(context);
|
String name = getGroupName(context);
|
||||||
|
|
||||||
if (Util.isEmpty(name)) {
|
if (Util.isEmpty(name)) {
|
||||||
name = getSystemProfileName().toString();
|
name = systemContactName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Util.isEmpty(name)) {
|
if (Util.isEmpty(name)) {
|
||||||
|
@ -466,7 +469,7 @@ public class Recipient {
|
||||||
String name = getGroupName(context);
|
String name = getGroupName(context);
|
||||||
|
|
||||||
if (Util.isEmpty(name)) {
|
if (Util.isEmpty(name)) {
|
||||||
name = getSystemProfileName().toString();
|
name = systemContactName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Util.isEmpty(name)) {
|
if (Util.isEmpty(name)) {
|
||||||
|
@ -497,7 +500,7 @@ public class Recipient {
|
||||||
name = StringUtil.isolateBidi(name);
|
name = StringUtil.isolateBidi(name);
|
||||||
|
|
||||||
if (Util.isEmpty(name)) {
|
if (Util.isEmpty(name)) {
|
||||||
name = isSelf ? getGroupName(context) : getSystemProfileName().toString();
|
name = isSelf ? getGroupName(context) : systemContactName;
|
||||||
name = StringUtil.isolateBidi(name);
|
name = StringUtil.isolateBidi(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ public class RecipientDetails {
|
||||||
final String email;
|
final String email;
|
||||||
final GroupId groupId;
|
final GroupId groupId;
|
||||||
final String groupName;
|
final String groupName;
|
||||||
|
final String systemContactName;
|
||||||
final String customLabel;
|
final String customLabel;
|
||||||
final Uri systemContactPhoto;
|
final Uri systemContactPhoto;
|
||||||
final Uri contactUri;
|
final Uri contactUri;
|
||||||
|
@ -71,6 +72,7 @@ public class RecipientDetails {
|
||||||
final ProfileName systemProfileName;
|
final ProfileName systemProfileName;
|
||||||
|
|
||||||
public RecipientDetails(@Nullable String groupName,
|
public RecipientDetails(@Nullable String groupName,
|
||||||
|
@Nullable String systemContactName,
|
||||||
@NonNull Optional<Long> groupAvatarId,
|
@NonNull Optional<Long> groupAvatarId,
|
||||||
boolean systemContact,
|
boolean systemContact,
|
||||||
boolean isSelf,
|
boolean isSelf,
|
||||||
|
@ -119,6 +121,7 @@ public class RecipientDetails {
|
||||||
this.aboutEmoji = settings.getAboutEmoji();
|
this.aboutEmoji = settings.getAboutEmoji();
|
||||||
this.systemProfileName = settings.getSystemProfileName();
|
this.systemProfileName = settings.getSystemProfileName();
|
||||||
this.groupName = groupName;
|
this.groupName = groupName;
|
||||||
|
this.systemContactName = systemContactName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -167,6 +170,7 @@ public class RecipientDetails {
|
||||||
this.about = null;
|
this.about = null;
|
||||||
this.aboutEmoji = null;
|
this.aboutEmoji = null;
|
||||||
this.systemProfileName = ProfileName.EMPTY;
|
this.systemProfileName = ProfileName.EMPTY;
|
||||||
|
this.systemContactName = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NonNull RecipientDetails forIndividual(@NonNull Context context, @NonNull RecipientSettings settings) {
|
public static @NonNull RecipientDetails forIndividual(@NonNull Context context, @NonNull RecipientSettings settings) {
|
||||||
|
@ -174,6 +178,6 @@ public class RecipientDetails {
|
||||||
boolean isSelf = (settings.getE164() != null && settings.getE164().equals(TextSecurePreferences.getLocalNumber(context))) ||
|
boolean isSelf = (settings.getE164() != null && settings.getE164().equals(TextSecurePreferences.getLocalNumber(context))) ||
|
||||||
(settings.getUuid() != null && settings.getUuid().equals(TextSecurePreferences.getLocalUuid(context)));
|
(settings.getUuid() != null && settings.getUuid().equals(TextSecurePreferences.getLocalUuid(context)));
|
||||||
|
|
||||||
return new RecipientDetails(null, Optional.absent(), systemContact, isSelf, settings, null);
|
return new RecipientDetails(null, settings.getSystemDisplayName(), Optional.absent(), systemContact, isSelf, settings, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue