mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
Add support for PNIs in storage service.
This commit is contained in:
committed by
Cody Henthorne
parent
cb057968ee
commit
95fc9d6c3c
@@ -78,6 +78,10 @@ public class ServiceId {
|
||||
return uuid.equals(UNKNOWN.uuid);
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return !isUnknown();
|
||||
}
|
||||
|
||||
public SignalProtocolAddress toProtocolAddress(int deviceId) {
|
||||
return new SignalProtocolAddress(uuid.toString(), deviceId);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import org.signal.libsignal.protocol.logging.Log;
|
||||
import org.whispersystems.signalservice.api.push.PNI;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.api.util.OptionalUtil;
|
||||
@@ -25,19 +26,23 @@ public final class SignalContactRecord implements SignalRecord {
|
||||
private final ContactRecord proto;
|
||||
private final boolean hasUnknownFields;
|
||||
|
||||
private final SignalServiceAddress address;
|
||||
private final Optional<String> givenName;
|
||||
private final Optional<String> familyName;
|
||||
private final Optional<byte[]> profileKey;
|
||||
private final Optional<String> username;
|
||||
private final Optional<byte[]> identityKey;
|
||||
private final ServiceId serviceId;
|
||||
private final Optional<PNI> pni;
|
||||
private final Optional<String> e164;
|
||||
private final Optional<String> givenName;
|
||||
private final Optional<String> familyName;
|
||||
private final Optional<byte[]> profileKey;
|
||||
private final Optional<String> username;
|
||||
private final Optional<byte[]> identityKey;
|
||||
|
||||
public SignalContactRecord(StorageId id, ContactRecord proto) {
|
||||
this.id = id;
|
||||
this.proto = proto;
|
||||
this.hasUnknownFields = ProtoUtil.hasUnknownFields(proto);
|
||||
|
||||
this.address = new SignalServiceAddress(ServiceId.parseOrUnknown(proto.getServiceUuid()), proto.getServiceE164());
|
||||
this.serviceId = ServiceId.parseOrUnknown(proto.getServiceId());
|
||||
this.pni = OptionalUtil.absentIfEmpty(proto.getServicePni()).map(PNI::parseOrNull);
|
||||
this.e164 = OptionalUtil.absentIfEmpty(proto.getServiceE164());
|
||||
this.givenName = OptionalUtil.absentIfEmpty(proto.getGivenName());
|
||||
this.familyName = OptionalUtil.absentIfEmpty(proto.getFamilyName());
|
||||
this.profileKey = OptionalUtil.absentIfEmpty(proto.getProfileKey());
|
||||
@@ -65,12 +70,16 @@ public final class SignalContactRecord implements SignalRecord {
|
||||
diff.add("ID");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.getAddress().getNumber(), that.getAddress().getNumber())) {
|
||||
diff.add("E164");
|
||||
if (!Objects.equals(this.getServiceId(), that.getServiceId())) {
|
||||
diff.add("ServiceId");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.getAddress().getServiceId(), that.getAddress().getServiceId())) {
|
||||
diff.add("UUID");
|
||||
if (!Objects.equals(this.getPni(), that.getPni())) {
|
||||
diff.add("PNI");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.getNumber(), that.getNumber())) {
|
||||
diff.add("E164");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.givenName, that.givenName)) {
|
||||
@@ -139,8 +148,16 @@ public final class SignalContactRecord implements SignalRecord {
|
||||
return hasUnknownFields ? proto.toByteArray() : null;
|
||||
}
|
||||
|
||||
public SignalServiceAddress getAddress() {
|
||||
return address;
|
||||
public ServiceId getServiceId() {
|
||||
return serviceId;
|
||||
}
|
||||
|
||||
public Optional<PNI> getPni() {
|
||||
return pni;
|
||||
}
|
||||
|
||||
public Optional<String> getNumber() {
|
||||
return e164;
|
||||
}
|
||||
|
||||
public Optional<String> getGivenName() {
|
||||
@@ -191,6 +208,13 @@ public final class SignalContactRecord implements SignalRecord {
|
||||
return proto.getHideStory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the same record, but stripped of the PNI field. Only used while PNP is in development.
|
||||
*/
|
||||
public SignalContactRecord withoutPni() {
|
||||
return new SignalContactRecord(id, proto.toBuilder().clearServicePni().build());
|
||||
}
|
||||
|
||||
public ContactRecord toProto() {
|
||||
return proto;
|
||||
}
|
||||
@@ -213,7 +237,7 @@ public final class SignalContactRecord implements SignalRecord {
|
||||
private final StorageId id;
|
||||
private final ContactRecord.Builder builder;
|
||||
|
||||
public Builder(byte[] rawId, SignalServiceAddress address, byte[] serializedUnknowns) {
|
||||
public Builder(byte[] rawId, ServiceId serviceId, byte[] serializedUnknowns) {
|
||||
this.id = StorageId.forContact(rawId);
|
||||
|
||||
if (serializedUnknowns != null) {
|
||||
@@ -222,8 +246,17 @@ public final class SignalContactRecord implements SignalRecord {
|
||||
this.builder = ContactRecord.newBuilder();
|
||||
}
|
||||
|
||||
builder.setServiceUuid(address.getServiceId().toString());
|
||||
builder.setServiceE164(address.getNumber().orElse(""));
|
||||
builder.setServiceId(serviceId.toString());
|
||||
}
|
||||
|
||||
public Builder setE164(String e164) {
|
||||
builder.setServiceE164(e164 == null ? "" : e164);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPni(PNI pni) {
|
||||
builder.setServicePni(pni == null ? "" : pni.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setGivenName(String givenName) {
|
||||
|
||||
@@ -71,8 +71,9 @@ message ContactRecord {
|
||||
UNVERIFIED = 2;
|
||||
}
|
||||
|
||||
string serviceUuid = 1;
|
||||
string serviceId = 1;
|
||||
string serviceE164 = 2;
|
||||
string servicePni = 15;
|
||||
bytes profileKey = 3;
|
||||
bytes identityKey = 4;
|
||||
IdentityState identityState = 5;
|
||||
|
||||
@@ -51,7 +51,8 @@ public class SignalContactRecordTest {
|
||||
String e164,
|
||||
String givenName)
|
||||
{
|
||||
return new SignalContactRecord.Builder(byteArray(key), new SignalServiceAddress(serviceId, e164), null)
|
||||
return new SignalContactRecord.Builder(byteArray(key), serviceId, null)
|
||||
.setE164(e164)
|
||||
.setGivenName(givenName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user