Fix contact sync issues where structured names are absent.

This commit is contained in:
Greyson Parrelli 2021-03-13 11:29:57 -05:00
parent 07201203b2
commit b4266b8575

View file

@ -1,15 +1,22 @@
package org.thoughtcrime.securesms.contacts.sync; package org.thoughtcrime.securesms.contacts.sync;
import androidx.annotation.NonNull; import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.database.RecipientDatabase; import org.thoughtcrime.securesms.database.RecipientDatabase;
import org.thoughtcrime.securesms.profiles.ProfileName; import org.thoughtcrime.securesms.profiles.ProfileName;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
final class ContactHolder { final class ContactHolder {
private static final String TAG = Log.tag(ContactHolder.class);
private final String lookupKey; private final String lookupKey;
private final List<PhoneNumberRecord> phoneNumberRecords = new LinkedList<>(); private final List<PhoneNumberRecord> phoneNumberRecords = new LinkedList<>();
@ -38,16 +45,18 @@ final class ContactHolder {
phoneNumberRecord.getContactPhotoUri(), phoneNumberRecord.getContactPhotoUri(),
phoneNumberRecord.getContactLabel(), phoneNumberRecord.getContactLabel(),
phoneNumberRecord.getPhoneType(), phoneNumberRecord.getPhoneType(),
phoneNumberRecord.getContactUri().toString()); Optional.fromNullable(phoneNumberRecord.getContactUri()).transform(Uri::toString).orNull());
} }
} }
private @NonNull ProfileName getProfileName(@NonNull String displayName) { private @NonNull ProfileName getProfileName(@Nullable String displayName) {
if (structuredNameRecord.hasGivenName()) { if (structuredNameRecord != null && structuredNameRecord.hasGivenName()) {
return structuredNameRecord.asProfileName(); return structuredNameRecord.asProfileName();
} else { } else if (displayName != null) {
return ProfileName.asGiven(displayName); return ProfileName.asGiven(displayName);
} else {
Log.w(TAG, "Failed to find a suitable display name!");
return ProfileName.EMPTY;
} }
} }
} }