Do not show profile name changes if names are visually identical.

Fixes #9860
master
Greyson Parrelli 2020-07-24 14:20:52 -04:00
parent bccc58d693
commit 5cd4726e23
2 changed files with 32 additions and 8 deletions

View File

@ -376,19 +376,27 @@ public class RetrieveProfileJob extends BaseJob {
String plaintextProfileName = Util.emptyIfNull(ProfileUtil.decryptName(profileKey, profileName));
if (!Objects.equals(plaintextProfileName, recipient.getProfileName().serialize())) {
String newProfileName = TextUtils.isEmpty(plaintextProfileName) ? ProfileName.EMPTY.serialize() : plaintextProfileName;
String previousProfileName = recipient.getProfileName().serialize();
ProfileName remoteProfileName = ProfileName.fromSerialized(plaintextProfileName);
ProfileName localProfileName = recipient.getProfileName();
if (!remoteProfileName.equals(localProfileName)) {
Log.i(TAG, "Profile name updated. Writing new value.");
DatabaseFactory.getRecipientDatabase(context).setProfileName(recipient.getId(), ProfileName.fromSerialized(plaintextProfileName));
DatabaseFactory.getRecipientDatabase(context).setProfileName(recipient.getId(), remoteProfileName);
if (!recipient.isBlocked() && !recipient.isGroup() && !recipient.isLocalNumber() && !TextUtils.isEmpty(previousProfileName)) {
String remoteDisplayName = remoteProfileName.toString();
String localDisplayName = localProfileName.toString();
if (!recipient.isBlocked() &&
!recipient.isGroup() &&
!recipient.isLocalNumber() &&
!localDisplayName.isEmpty() &&
!remoteDisplayName.equals(localDisplayName))
{
Log.i(TAG, "Writing a profile name change event.");
DatabaseFactory.getSmsDatabase(context).insertProfileNameChangeMessages(recipient, newProfileName, previousProfileName);
DatabaseFactory.getSmsDatabase(context).insertProfileNameChangeMessages(recipient, remoteDisplayName, localDisplayName);
} else {
Log.i(TAG, String.format(Locale.US, "Name changed, but wasn't relevant to write an event. blocked: %b, group: %b, self: %b, firstSet: %b",
recipient.isBlocked(), recipient.isGroup(), recipient.isLocalNumber(), TextUtils.isEmpty(previousProfileName)));
Log.i(TAG, String.format(Locale.US, "Name changed, but wasn't relevant to write an event. blocked: %s, group: %s, self: %s, firstSet: %s, displayChange: %s",
recipient.isBlocked(), recipient.isGroup(), recipient.isLocalNumber(), localDisplayName.isEmpty(), !remoteDisplayName.equals(localDisplayName)));
}
}

View File

@ -13,6 +13,8 @@ import org.thoughtcrime.securesms.util.StringUtil;
import org.thoughtcrime.securesms.util.cjkv.CJKVUtil;
import org.whispersystems.signalservice.api.crypto.ProfileCipher;
import java.util.Objects;
public final class ProfileName implements Parcelable {
public static final ProfileName EMPTY = new ProfileName("", "");
@ -133,6 +135,20 @@ public final class ProfileName implements Parcelable {
dest.writeString(familyName);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ProfileName that = (ProfileName) o;
return Objects.equals(givenName, that.givenName) &&
Objects.equals(familyName, that.familyName);
}
@Override
public int hashCode() {
return Objects.hash(givenName, familyName);
}
public static final Creator<ProfileName> CREATOR = new Creator<ProfileName>() {
@Override
public ProfileName createFromParcel(Parcel in) {