Search in sources :

Example 1 with IdentityState

use of org.whispersystems.signalservice.internal.storage.protos.ContactRecord.IdentityState in project Signal-Android by WhisperSystems.

the class ContactRecordProcessor method merge.

@NonNull
SignalContactRecord merge(@NonNull SignalContactRecord remote, @NonNull SignalContactRecord local, @NonNull StorageKeyGenerator keyGenerator) {
    String givenName;
    String familyName;
    if (remote.getGivenName().isPresent() || remote.getFamilyName().isPresent()) {
        givenName = remote.getGivenName().or("");
        familyName = remote.getFamilyName().or("");
    } else {
        givenName = local.getGivenName().or("");
        familyName = local.getFamilyName().or("");
    }
    byte[] unknownFields = remote.serializeUnknownFields();
    ServiceId serviceId = local.getAddress().getServiceId() == ServiceId.UNKNOWN ? remote.getAddress().getServiceId() : local.getAddress().getServiceId();
    String e164 = remote.getAddress().getNumber().or(local.getAddress().getNumber()).orNull();
    SignalServiceAddress address = new SignalServiceAddress(serviceId, e164);
    byte[] profileKey = remote.getProfileKey().or(local.getProfileKey()).orNull();
    String username = remote.getUsername().or(local.getUsername()).or("");
    IdentityState identityState = remote.getIdentityState();
    byte[] identityKey = remote.getIdentityKey().or(local.getIdentityKey()).orNull();
    boolean blocked = remote.isBlocked();
    boolean profileSharing = remote.isProfileSharingEnabled();
    boolean archived = remote.isArchived();
    boolean forcedUnread = remote.isForcedUnread();
    long muteUntil = remote.getMuteUntil();
    boolean matchesRemote = doParamsMatch(remote, unknownFields, address, givenName, familyName, profileKey, username, identityState, identityKey, blocked, profileSharing, archived, forcedUnread, muteUntil);
    boolean matchesLocal = doParamsMatch(local, unknownFields, address, givenName, familyName, profileKey, username, identityState, identityKey, blocked, profileSharing, archived, forcedUnread, muteUntil);
    if (matchesRemote) {
        return remote;
    } else if (matchesLocal) {
        return local;
    } else {
        return new SignalContactRecord.Builder(keyGenerator.generate(), address, unknownFields).setGivenName(givenName).setFamilyName(familyName).setProfileKey(profileKey).setUsername(username).setIdentityState(identityState).setIdentityKey(identityKey).setBlocked(blocked).setProfileSharingEnabled(profileSharing).setArchived(archived).setForcedUnread(forcedUnread).setMuteUntil(muteUntil).build();
    }
}
Also used : SignalContactRecord(org.whispersystems.signalservice.api.storage.SignalContactRecord) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) IdentityState(org.whispersystems.signalservice.internal.storage.protos.ContactRecord.IdentityState) ServiceId(org.whispersystems.signalservice.api.push.ServiceId) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)1 ServiceId (org.whispersystems.signalservice.api.push.ServiceId)1 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)1 SignalContactRecord (org.whispersystems.signalservice.api.storage.SignalContactRecord)1 IdentityState (org.whispersystems.signalservice.internal.storage.protos.ContactRecord.IdentityState)1