mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 18:00:02 +01:00
Split system names into first / last.
This commit is contained in:
@@ -89,11 +89,11 @@ public class Recipient {
|
||||
private final RegisteredState registered;
|
||||
private final byte[] profileKey;
|
||||
private final ProfileKeyCredential profileKeyCredential;
|
||||
private final String name;
|
||||
private final String groupName;
|
||||
private final Uri systemContactPhoto;
|
||||
private final String customLabel;
|
||||
private final Uri contactUri;
|
||||
private final ProfileName profileName;
|
||||
private final ProfileName signalProfileName;
|
||||
private final String profileAvatar;
|
||||
private final boolean hasProfileImage;
|
||||
private final boolean profileSharing;
|
||||
@@ -109,6 +109,7 @@ public class Recipient {
|
||||
private final ChatWallpaper wallpaper;
|
||||
private final String about;
|
||||
private final String aboutEmoji;
|
||||
private final ProfileName systemProfileName;
|
||||
|
||||
|
||||
/**
|
||||
@@ -326,11 +327,11 @@ public class Recipient {
|
||||
this.registered = RegisteredState.UNKNOWN;
|
||||
this.profileKey = null;
|
||||
this.profileKeyCredential = null;
|
||||
this.name = null;
|
||||
this.groupName = null;
|
||||
this.systemContactPhoto = null;
|
||||
this.customLabel = null;
|
||||
this.contactUri = null;
|
||||
this.profileName = ProfileName.EMPTY;
|
||||
this.signalProfileName = ProfileName.EMPTY;
|
||||
this.profileAvatar = null;
|
||||
this.hasProfileImage = false;
|
||||
this.profileSharing = false;
|
||||
@@ -345,6 +346,7 @@ public class Recipient {
|
||||
this.wallpaper = null;
|
||||
this.about = null;
|
||||
this.aboutEmoji = null;
|
||||
this.systemProfileName = ProfileName.EMPTY;
|
||||
}
|
||||
|
||||
public Recipient(@NonNull RecipientId id, @NonNull RecipientDetails details, boolean resolved) {
|
||||
@@ -371,11 +373,11 @@ public class Recipient {
|
||||
this.registered = details.registered;
|
||||
this.profileKey = details.profileKey;
|
||||
this.profileKeyCredential = details.profileKeyCredential;
|
||||
this.name = details.name;
|
||||
this.groupName = details.groupName;
|
||||
this.systemContactPhoto = details.systemContactPhoto;
|
||||
this.customLabel = details.customLabel;
|
||||
this.contactUri = details.contactUri;
|
||||
this.profileName = details.profileName;
|
||||
this.signalProfileName = details.profileName;
|
||||
this.profileAvatar = details.profileAvatar;
|
||||
this.hasProfileImage = details.hasProfileImage;
|
||||
this.profileSharing = details.profileSharing;
|
||||
@@ -390,6 +392,7 @@ public class Recipient {
|
||||
this.wallpaper = details.wallpaper;
|
||||
this.about = details.about;
|
||||
this.aboutEmoji = details.aboutEmoji;
|
||||
this.systemProfileName = details.systemProfileName;
|
||||
}
|
||||
|
||||
public @NonNull RecipientId getId() {
|
||||
@@ -404,8 +407,8 @@ public class Recipient {
|
||||
return contactUri;
|
||||
}
|
||||
|
||||
public @Nullable String getName(@NonNull Context context) {
|
||||
if (this.name == null && groupId != null && groupId.isMms()) {
|
||||
public @Nullable String getGroupName(@NonNull Context context) {
|
||||
if (this.groupName == null && groupId != null && groupId.isMms()) {
|
||||
List<String> names = new LinkedList<>();
|
||||
|
||||
for (Recipient recipient : participants) {
|
||||
@@ -413,27 +416,32 @@ public class Recipient {
|
||||
}
|
||||
|
||||
return Util.join(names, ", ");
|
||||
} else if (name == null && groupId != null && groupId.isPush()) {
|
||||
} else if (groupName == null && groupId != null && groupId.isPush()) {
|
||||
return context.getString(R.string.RecipientProvider_unnamed_group);
|
||||
} else {
|
||||
return this.name;
|
||||
return this.groupName;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasName() {
|
||||
return name != null;
|
||||
return groupName != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* False iff it {@link #getDisplayName} would fall back to e164, email or unknown.
|
||||
*/
|
||||
public boolean hasAUserSetDisplayName(@NonNull Context context) {
|
||||
return !TextUtils.isEmpty(getName(context)) ||
|
||||
return !TextUtils.isEmpty(getGroupName(context)) ||
|
||||
!TextUtils.isEmpty(getSystemProfileName().toString()) ||
|
||||
!TextUtils.isEmpty(getProfileName().toString());
|
||||
}
|
||||
|
||||
public @NonNull String getDisplayName(@NonNull Context context) {
|
||||
String name = getName(context);
|
||||
String name = getGroupName(context);
|
||||
|
||||
if (Util.isEmpty(name)) {
|
||||
name = getSystemProfileName().toString();
|
||||
}
|
||||
|
||||
if (Util.isEmpty(name)) {
|
||||
name = getProfileName().toString();
|
||||
@@ -455,7 +463,11 @@ public class Recipient {
|
||||
}
|
||||
|
||||
public @NonNull String getDisplayNameOrUsername(@NonNull Context context) {
|
||||
String name = getName(context);
|
||||
String name = getGroupName(context);
|
||||
|
||||
if (Util.isEmpty(name)) {
|
||||
name = getSystemProfileName().toString();
|
||||
}
|
||||
|
||||
if (Util.isEmpty(name)) {
|
||||
name = StringUtil.isolateBidi(getProfileName().toString());
|
||||
@@ -481,11 +493,16 @@ public class Recipient {
|
||||
}
|
||||
|
||||
public @NonNull String getMentionDisplayName(@NonNull Context context) {
|
||||
String name = isSelf ? getProfileName().toString() : getName(context);
|
||||
String name = isSelf ? getProfileName().toString() : getGroupName(context);
|
||||
name = StringUtil.isolateBidi(name);
|
||||
|
||||
if (Util.isEmpty(name)) {
|
||||
name = isSelf ? getName(context) : getProfileName().toString();
|
||||
name = isSelf ? getGroupName(context) : getSystemProfileName().toString();
|
||||
name = StringUtil.isolateBidi(name);
|
||||
}
|
||||
|
||||
if (Util.isEmpty(name)) {
|
||||
name = isSelf ? getGroupName(context) : getProfileName().toString();
|
||||
name = StringUtil.isolateBidi(name);
|
||||
}
|
||||
|
||||
@@ -505,7 +522,8 @@ public class Recipient {
|
||||
}
|
||||
|
||||
public @NonNull String getShortDisplayName(@NonNull Context context) {
|
||||
String name = Util.getFirstNonEmpty(getName(context),
|
||||
String name = Util.getFirstNonEmpty(getGroupName(context),
|
||||
getSystemProfileName().getGivenName(),
|
||||
getProfileName().getGivenName(),
|
||||
getDisplayName(context));
|
||||
|
||||
@@ -513,7 +531,8 @@ public class Recipient {
|
||||
}
|
||||
|
||||
public @NonNull String getShortDisplayNameIncludingUsername(@NonNull Context context) {
|
||||
String name = Util.getFirstNonEmpty(getName(context),
|
||||
String name = Util.getFirstNonEmpty(getGroupName(context),
|
||||
getSystemProfileName().getGivenName(),
|
||||
getProfileName().getGivenName(),
|
||||
getDisplayName(context),
|
||||
getUsername().orNull());
|
||||
@@ -526,7 +545,7 @@ public class Recipient {
|
||||
return MaterialColor.GROUP;
|
||||
} else if (color != null) {
|
||||
return color;
|
||||
} else if (name != null || profileSharing) {
|
||||
} else if (groupName != null || profileSharing) {
|
||||
Log.w(TAG, "Had no color for " + id + "! Saving a new one.");
|
||||
|
||||
Context context = ApplicationDependencies.getApplication();
|
||||
@@ -672,7 +691,11 @@ public class Recipient {
|
||||
}
|
||||
|
||||
public @NonNull ProfileName getProfileName() {
|
||||
return profileName;
|
||||
return signalProfileName;
|
||||
}
|
||||
|
||||
private @NonNull ProfileName getSystemProfileName() {
|
||||
return systemProfileName;
|
||||
}
|
||||
|
||||
public @Nullable String getProfileAvatar() {
|
||||
@@ -744,12 +767,12 @@ public class Recipient {
|
||||
}
|
||||
|
||||
public @NonNull FallbackContactPhoto getFallbackContactPhoto(@NonNull FallbackPhotoProvider fallbackPhotoProvider) {
|
||||
if (isSelf) return fallbackPhotoProvider.getPhotoForLocalNumber();
|
||||
else if (isResolving()) return fallbackPhotoProvider.getPhotoForResolvingRecipient();
|
||||
else if (isGroupInternal()) return fallbackPhotoProvider.getPhotoForGroup();
|
||||
else if (isGroup()) return fallbackPhotoProvider.getPhotoForGroup();
|
||||
else if (!TextUtils.isEmpty(name)) return fallbackPhotoProvider.getPhotoForRecipientWithName(name);
|
||||
else return fallbackPhotoProvider.getPhotoForRecipientWithoutName();
|
||||
if (isSelf) return fallbackPhotoProvider.getPhotoForLocalNumber();
|
||||
else if (isResolving()) return fallbackPhotoProvider.getPhotoForResolvingRecipient();
|
||||
else if (isGroupInternal()) return fallbackPhotoProvider.getPhotoForGroup();
|
||||
else if (isGroup()) return fallbackPhotoProvider.getPhotoForGroup();
|
||||
else if (!TextUtils.isEmpty(groupName)) return fallbackPhotoProvider.getPhotoForRecipientWithName(groupName);
|
||||
else return fallbackPhotoProvider.getPhotoForRecipientWithoutName();
|
||||
}
|
||||
|
||||
public @Nullable ContactPhoto getContactPhoto() {
|
||||
@@ -1003,11 +1026,12 @@ public class Recipient {
|
||||
registered == other.registered &&
|
||||
Arrays.equals(profileKey, other.profileKey) &&
|
||||
Objects.equals(profileKeyCredential, other.profileKeyCredential) &&
|
||||
Objects.equals(name, other.name) &&
|
||||
Objects.equals(groupName, other.groupName) &&
|
||||
Objects.equals(systemContactPhoto, other.systemContactPhoto) &&
|
||||
Objects.equals(customLabel, other.customLabel) &&
|
||||
Objects.equals(contactUri, other.contactUri) &&
|
||||
Objects.equals(profileName, other.profileName) &&
|
||||
Objects.equals(signalProfileName, other.signalProfileName) &&
|
||||
Objects.equals(systemProfileName, other.systemProfileName) &&
|
||||
Objects.equals(profileAvatar, other.profileAvatar) &&
|
||||
Objects.equals(notificationChannel, other.notificationChannel) &&
|
||||
unidentifiedAccessMode == other.unidentifiedAccessMode &&
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.recipients;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -33,7 +32,7 @@ public class RecipientDetails {
|
||||
final String e164;
|
||||
final String email;
|
||||
final GroupId groupId;
|
||||
final String name;
|
||||
final String groupName;
|
||||
final String customLabel;
|
||||
final Uri systemContactPhoto;
|
||||
final Uri contactUri;
|
||||
@@ -69,8 +68,9 @@ public class RecipientDetails {
|
||||
final ChatWallpaper wallpaper;
|
||||
final String about;
|
||||
final String aboutEmoji;
|
||||
final ProfileName systemProfileName;
|
||||
|
||||
public RecipientDetails(@Nullable String name,
|
||||
public RecipientDetails(@Nullable String groupName,
|
||||
@NonNull Optional<Long> groupAvatarId,
|
||||
boolean systemContact,
|
||||
boolean isSelf,
|
||||
@@ -117,9 +117,8 @@ public class RecipientDetails {
|
||||
this.wallpaper = settings.getWallpaper();
|
||||
this.about = settings.getAbout();
|
||||
this.aboutEmoji = settings.getAboutEmoji();
|
||||
|
||||
if (name == null) this.name = settings.getSystemDisplayName();
|
||||
else this.name = name;
|
||||
this.systemProfileName = settings.getSystemProfileName();
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,7 +158,7 @@ public class RecipientDetails {
|
||||
this.notificationChannel = null;
|
||||
this.unidentifiedAccessMode = UnidentifiedAccessMode.UNKNOWN;
|
||||
this.forceSmsSelection = false;
|
||||
this.name = null;
|
||||
this.groupName = null;
|
||||
this.groupsV2Capability = Recipient.Capability.UNKNOWN;
|
||||
this.groupsV1MigrationCapability = Recipient.Capability.UNKNOWN;
|
||||
this.storageId = null;
|
||||
@@ -167,10 +166,11 @@ public class RecipientDetails {
|
||||
this.wallpaper = null;
|
||||
this.about = null;
|
||||
this.aboutEmoji = null;
|
||||
this.systemProfileName = ProfileName.EMPTY;
|
||||
}
|
||||
|
||||
public static @NonNull RecipientDetails forIndividual(@NonNull Context context, @NonNull RecipientSettings settings) {
|
||||
boolean systemContact = !TextUtils.isEmpty(settings.getSystemDisplayName());
|
||||
boolean systemContact = !settings.getSystemProfileName().isEmpty();
|
||||
boolean isSelf = (settings.getE164() != null && settings.getE164().equals(TextSecurePreferences.getLocalNumber(context))) ||
|
||||
(settings.getUuid() != null && settings.getUuid().equals(TextSecurePreferences.getLocalUuid(context)));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user