Update ContactRecord proto with new nickname fields.
This commit is contained in:
parent
5b10aa6fa7
commit
7a24554b68
4 changed files with 106 additions and 19 deletions
|
@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.storage;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.signal.core.util.StringUtil;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.database.RecipientTable;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
|
@ -152,6 +153,23 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
|
|||
profileFamilyName = local.getProfileFamilyName().orElse("");
|
||||
}
|
||||
|
||||
String nicknameGivenName;
|
||||
String nicknameFamilyName;
|
||||
if (remote.getNicknameGivenName().isPresent()) {
|
||||
nicknameGivenName = remote.getNicknameGivenName().orElse("");
|
||||
nicknameFamilyName = remote.getNicknameFamilyName().orElse("");
|
||||
} else {
|
||||
nicknameGivenName = local.getNicknameGivenName().orElse("");
|
||||
nicknameFamilyName = local.getNicknameFamilyName().orElse("");
|
||||
}
|
||||
|
||||
if (StringUtil.isVisuallyEmpty(nicknameGivenName) && !StringUtil.isVisuallyEmpty(nicknameFamilyName)) {
|
||||
Log.w(TAG, "Processed invalid nickname. Missing given name.");
|
||||
|
||||
nicknameGivenName = "";
|
||||
nicknameFamilyName = "";
|
||||
}
|
||||
|
||||
IdentityState identityState;
|
||||
byte[] identityKey;
|
||||
|
||||
|
@ -217,8 +235,9 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
|
|||
String systemFamilyName = SignalStore.account().isPrimaryDevice() ? local.getSystemFamilyName().orElse("") : remote.getSystemFamilyName().orElse("");
|
||||
String systemNickname = remote.getSystemNickname().orElse("");
|
||||
boolean pniSignatureVerified = remote.isPniSignatureVerified() || local.isPniSignatureVerified();
|
||||
boolean matchesRemote = doParamsMatch(remote, unknownFields, aci, pni, e164, profileGivenName, profileFamilyName, systemGivenName, systemFamilyName, systemNickname, profileKey, username, identityState, identityKey, blocked, profileSharing, archived, forcedUnread, muteUntil, hideStory, unregisteredTimestamp, hidden, pniSignatureVerified);
|
||||
boolean matchesLocal = doParamsMatch(local, unknownFields, aci, pni, e164, profileGivenName, profileFamilyName, systemGivenName, systemFamilyName, systemNickname, profileKey, username, identityState, identityKey, blocked, profileSharing, archived, forcedUnread, muteUntil, hideStory, unregisteredTimestamp, hidden, pniSignatureVerified);
|
||||
String note = remote.getNote().or(local::getNote).orElse("");
|
||||
boolean matchesRemote = doParamsMatch(remote, unknownFields, aci, pni, e164, profileGivenName, profileFamilyName, systemGivenName, systemFamilyName, systemNickname, profileKey, username, identityState, identityKey, blocked, profileSharing, archived, forcedUnread, muteUntil, hideStory, unregisteredTimestamp, hidden, pniSignatureVerified, nicknameGivenName, nicknameFamilyName, note);
|
||||
boolean matchesLocal = doParamsMatch(local, unknownFields, aci, pni, e164, profileGivenName, profileFamilyName, systemGivenName, systemFamilyName, systemNickname, profileKey, username, identityState, identityKey, blocked, profileSharing, archived, forcedUnread, muteUntil, hideStory, unregisteredTimestamp, hidden, pniSignatureVerified, nicknameGivenName, nicknameFamilyName, note);
|
||||
|
||||
if (matchesRemote) {
|
||||
return remote;
|
||||
|
@ -246,6 +265,9 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
|
|||
.setUnregisteredTimestamp(unregisteredTimestamp)
|
||||
.setHidden(hidden)
|
||||
.setPniSignatureVerified(pniSignatureVerified)
|
||||
.setNicknameGivenName(nicknameGivenName)
|
||||
.setNicknameFamilyName(nicknameFamilyName)
|
||||
.setNote(note)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
@ -298,7 +320,10 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
|
|||
boolean hideStory,
|
||||
long unregisteredTimestamp,
|
||||
boolean hidden,
|
||||
boolean pniSignatureVerified)
|
||||
boolean pniSignatureVerified,
|
||||
@NonNull String nicknameGivenName,
|
||||
@NonNull String nicknameFamilyName,
|
||||
@NonNull String note)
|
||||
{
|
||||
return Arrays.equals(contact.serializeUnknownFields(), unknownFields) &&
|
||||
Objects.equals(contact.getAci().orElse(null), aci) &&
|
||||
|
@ -321,6 +346,9 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
|
|||
contact.shouldHideStory() == hideStory &&
|
||||
contact.getUnregisteredTimestamp() == unregisteredTimestamp &&
|
||||
contact.isHidden() == hidden &&
|
||||
contact.isPniSignatureVerified() == pniSignatureVerified;
|
||||
contact.isPniSignatureVerified() == pniSignatureVerified &&
|
||||
Objects.equals(contact.getNicknameGivenName().orElse(""), nicknameGivenName) &&
|
||||
Objects.equals(contact.getNicknameFamilyName().orElse(""), nicknameFamilyName) &&
|
||||
Objects.equals(contact.getNote().orElse(""), note);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,6 +155,9 @@ public final class StorageSyncModels {
|
|||
.setHidden(recipient.getHiddenState() != Recipient.HiddenState.NOT_HIDDEN)
|
||||
.setUsername(recipient.getUsername())
|
||||
.setPniSignatureVerified(recipient.getSyncExtras().getPniSignatureVerified())
|
||||
.setNicknameGivenName(recipient.getNickname().getGivenName())
|
||||
.setNicknameFamilyName(recipient.getNickname().getFamilyName())
|
||||
.setNote(recipient.getNote())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -39,22 +39,28 @@ public final class SignalContactRecord implements SignalRecord {
|
|||
private final Optional<byte[]> profileKey;
|
||||
private final Optional<String> username;
|
||||
private final Optional<byte[]> identityKey;
|
||||
private final Optional<String> nicknameGivenName;
|
||||
private final Optional<String> nicknameFamilyName;
|
||||
private final Optional<String> note;
|
||||
|
||||
public SignalContactRecord(StorageId id, ContactRecord proto) {
|
||||
this.id = id;
|
||||
this.proto = proto;
|
||||
this.hasUnknownFields = ProtoUtil.hasUnknownFields(proto);
|
||||
this.aci = OptionalUtil.absentIfEmpty(proto.aci).map(ACI::parseOrNull).map(it -> it.isUnknown() ? null : it);
|
||||
this.pni = OptionalUtil.absentIfEmpty(proto.pni).map(PNI::parseOrNull).map(it -> it.isUnknown() ? null : it);
|
||||
this.e164 = OptionalUtil.absentIfEmpty(proto.e164);
|
||||
this.profileGivenName = OptionalUtil.absentIfEmpty(proto.givenName);
|
||||
this.profileFamilyName = OptionalUtil.absentIfEmpty(proto.familyName);
|
||||
this.systemGivenName = OptionalUtil.absentIfEmpty(proto.systemGivenName);
|
||||
this.systemFamilyName = OptionalUtil.absentIfEmpty(proto.systemFamilyName);
|
||||
this.systemNickname = OptionalUtil.absentIfEmpty(proto.systemNickname);
|
||||
this.profileKey = OptionalUtil.absentIfEmpty(proto.profileKey);
|
||||
this.username = OptionalUtil.absentIfEmpty(proto.username);
|
||||
this.identityKey = OptionalUtil.absentIfEmpty(proto.identityKey);
|
||||
this.id = id;
|
||||
this.proto = proto;
|
||||
this.hasUnknownFields = ProtoUtil.hasUnknownFields(proto);
|
||||
this.aci = OptionalUtil.absentIfEmpty(proto.aci).map(ACI::parseOrNull).map(it -> it.isUnknown() ? null : it);
|
||||
this.pni = OptionalUtil.absentIfEmpty(proto.pni).map(PNI::parseOrNull).map(it -> it.isUnknown() ? null : it);
|
||||
this.e164 = OptionalUtil.absentIfEmpty(proto.e164);
|
||||
this.profileGivenName = OptionalUtil.absentIfEmpty(proto.givenName);
|
||||
this.profileFamilyName = OptionalUtil.absentIfEmpty(proto.familyName);
|
||||
this.systemGivenName = OptionalUtil.absentIfEmpty(proto.systemGivenName);
|
||||
this.systemFamilyName = OptionalUtil.absentIfEmpty(proto.systemFamilyName);
|
||||
this.systemNickname = OptionalUtil.absentIfEmpty(proto.systemNickname);
|
||||
this.profileKey = OptionalUtil.absentIfEmpty(proto.profileKey);
|
||||
this.username = OptionalUtil.absentIfEmpty(proto.username);
|
||||
this.identityKey = OptionalUtil.absentIfEmpty(proto.identityKey);
|
||||
this.nicknameGivenName = Optional.ofNullable(proto.nickname).flatMap(n -> OptionalUtil.absentIfEmpty(n.given));
|
||||
this.nicknameFamilyName = Optional.ofNullable(proto.nickname).flatMap(n -> OptionalUtil.absentIfEmpty(n.family));
|
||||
this.note = OptionalUtil.absentIfEmpty(proto.note);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -165,6 +171,18 @@ public final class SignalContactRecord implements SignalRecord {
|
|||
diff.add("UnknownFields");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.nicknameGivenName, that.nicknameGivenName)) {
|
||||
diff.add("NicknameGivenName");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.nicknameFamilyName, that.nicknameFamilyName)) {
|
||||
diff.add("NicknameFamilyName");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.note, that.note)) {
|
||||
diff.add("Note");
|
||||
}
|
||||
|
||||
return diff.toString();
|
||||
} else {
|
||||
return "Different class. " + getClass().getSimpleName() + " | " + other.getClass().getSimpleName();
|
||||
|
@ -221,6 +239,18 @@ public final class SignalContactRecord implements SignalRecord {
|
|||
return systemNickname;
|
||||
}
|
||||
|
||||
public Optional<String> getNicknameGivenName() {
|
||||
return nicknameGivenName;
|
||||
}
|
||||
|
||||
public Optional<String> getNicknameFamilyName() {
|
||||
return nicknameFamilyName;
|
||||
}
|
||||
|
||||
public Optional<String> getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public Optional<byte[]> getProfileKey() {
|
||||
return profileKey;
|
||||
}
|
||||
|
@ -414,6 +444,25 @@ public final class SignalContactRecord implements SignalRecord {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setNicknameGivenName(String nicknameGivenName) {
|
||||
ContactRecord.Name.Builder name = builder.nickname == null ? new ContactRecord.Name.Builder() : builder.nickname.newBuilder();
|
||||
name.given(nicknameGivenName);
|
||||
builder.nickname(name.build());
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setNicknameFamilyName(String nicknameFamilyName) {
|
||||
ContactRecord.Name.Builder name = builder.nickname == null ? new ContactRecord.Name.Builder() : builder.nickname.newBuilder();
|
||||
name.family(nicknameFamilyName);
|
||||
builder.nickname(name.build());
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setNote(String note) {
|
||||
builder.note(note == null ? "" : note);
|
||||
return this;
|
||||
}
|
||||
|
||||
private static ContactRecord.Builder parseUnknowns(byte[] serializedUnknowns) {
|
||||
try {
|
||||
return ContactRecord.ADAPTER.decode(serializedUnknowns).newBuilder();
|
||||
|
|
|
@ -79,6 +79,11 @@ message ContactRecord {
|
|||
UNVERIFIED = 2;
|
||||
}
|
||||
|
||||
message Name {
|
||||
string given = 1;
|
||||
string family = 2;
|
||||
}
|
||||
|
||||
string aci = 1;
|
||||
string e164 = 2;
|
||||
string pni = 15;
|
||||
|
@ -100,7 +105,9 @@ message ContactRecord {
|
|||
string systemNickname = 19;
|
||||
bool hidden = 20;
|
||||
bool pniSignatureVerified = 21;
|
||||
// NEXT ID: 22
|
||||
Name nickname = 22;
|
||||
string note = 23;
|
||||
// NEXT ID: 24
|
||||
}
|
||||
|
||||
message GroupV1Record {
|
||||
|
|
Loading…
Add table
Reference in a new issue