mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-01 22:25:46 +01:00
Rewrite storage service change processing.
This commit is contained in:
@@ -12,6 +12,7 @@ import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||
import org.whispersystems.signalservice.internal.storage.protos.AccountRecord;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -52,6 +53,87 @@ public final class SignalAccountRecord implements SignalRecord {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignalStorageRecord asStorageRecord() {
|
||||
return SignalStorageRecord.forAccount(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeDiff(SignalRecord other) {
|
||||
if (other instanceof SignalAccountRecord) {
|
||||
SignalAccountRecord that = (SignalAccountRecord) other;
|
||||
List<String> diff = new LinkedList<>();
|
||||
|
||||
if (!Objects.equals(this.givenName, that.givenName)) {
|
||||
diff.add("GivenName");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.familyName, that.familyName)) {
|
||||
diff.add("FamilyName");
|
||||
}
|
||||
|
||||
if (!OptionalUtil.byteArrayEquals(this.profileKey, that.profileKey)) {
|
||||
diff.add("ProfileKey");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.avatarUrlPath, that.avatarUrlPath)) {
|
||||
diff.add("AvatarUrlPath");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isNoteToSelfArchived(), that.isNoteToSelfArchived())) {
|
||||
diff.add("NoteToSelfArchived");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isNoteToSelfForcedUnread(), that.isNoteToSelfForcedUnread())) {
|
||||
diff.add("NoteToSelfForcedUnread");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isReadReceiptsEnabled(), that.isReadReceiptsEnabled())) {
|
||||
diff.add("ReadReceipts");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isTypingIndicatorsEnabled(), that.isTypingIndicatorsEnabled())) {
|
||||
diff.add("TypingIndicators");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isSealedSenderIndicatorsEnabled(), that.isSealedSenderIndicatorsEnabled())) {
|
||||
diff.add("SealedSenderIndicators");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isLinkPreviewsEnabled(), that.isLinkPreviewsEnabled())) {
|
||||
diff.add("LinkPreviews");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.getPhoneNumberSharingMode(), that.getPhoneNumberSharingMode())) {
|
||||
diff.add("PhoneNumberSharingMode");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isPhoneNumberUnlisted(), that.isPhoneNumberUnlisted())) {
|
||||
diff.add("PhoneNumberUnlisted");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.pinnedConversations, that.pinnedConversations)) {
|
||||
diff.add("PinnedConversations");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.preferContactAvatars, that.preferContactAvatars)) {
|
||||
diff.add("PreferContactAvatars");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.payments, that.payments)) {
|
||||
diff.add("PreferContactAvatars");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.hasUnknownFields(), that.hasUnknownFields())) {
|
||||
diff.add("UnknownFields");
|
||||
}
|
||||
|
||||
return diff.toString();
|
||||
} else {
|
||||
return "Different class. " + getClass().getSimpleName() + " | " + other.getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasUnknownFields() {
|
||||
return hasUnknownFields;
|
||||
}
|
||||
@@ -251,6 +333,20 @@ public final class SignalAccountRecord implements SignalRecord {
|
||||
public Optional<byte[]> getEntropy() {
|
||||
return entropy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Payments payments = (Payments) o;
|
||||
return enabled == payments.enabled &&
|
||||
OptionalUtil.byteArrayEquals(entropy, payments.entropy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(enabled, entropy);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
|
||||
@@ -10,6 +10,8 @@ import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||
import org.whispersystems.signalservice.internal.storage.protos.ContactRecord;
|
||||
import org.whispersystems.signalservice.internal.storage.protos.ContactRecord.IdentityState;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class SignalContactRecord implements SignalRecord {
|
||||
@@ -43,6 +45,75 @@ public final class SignalContactRecord implements SignalRecord {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignalStorageRecord asStorageRecord() {
|
||||
return SignalStorageRecord.forContact(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeDiff(SignalRecord other) {
|
||||
if (other instanceof SignalContactRecord) {
|
||||
SignalContactRecord that = (SignalContactRecord) other;
|
||||
List<String> diff = new LinkedList<>();
|
||||
|
||||
if (!Objects.equals(this.getAddress().getNumber(), that.getAddress().getNumber())) {
|
||||
diff.add("E164");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.getAddress().getUuid(), that.getAddress().getUuid())) {
|
||||
diff.add("UUID");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.givenName, that.givenName)) {
|
||||
diff.add("GivenName");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.familyName, that.familyName)) {
|
||||
diff.add("FamilyName");
|
||||
}
|
||||
|
||||
if (!OptionalUtil.byteArrayEquals(this.profileKey, that.profileKey)) {
|
||||
diff.add("ProfileKey");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.username, that.username)) {
|
||||
diff.add("Username");
|
||||
}
|
||||
|
||||
if (!OptionalUtil.byteArrayEquals(this.identityKey, that.identityKey)) {
|
||||
diff.add("IdentityKey");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.getIdentityState(), that.getIdentityState())) {
|
||||
diff.add("IdentityState");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isBlocked(), that.isBlocked())) {
|
||||
diff.add("Blocked");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isProfileSharingEnabled(), that.isProfileSharingEnabled())) {
|
||||
diff.add("ProfileSharing");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isArchived(), that.isArchived())) {
|
||||
diff.add("Archived");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isForcedUnread(), that.isForcedUnread())) {
|
||||
diff.add("ForcedUnread");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.hasUnknownFields(), that.hasUnknownFields())) {
|
||||
diff.add("UnknownFields");
|
||||
}
|
||||
|
||||
return diff.toString();
|
||||
} else {
|
||||
return "Different class. " + getClass().getSimpleName() + " | " + other.getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasUnknownFields() {
|
||||
return hasUnknownFields;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import com.google.protobuf.ByteString;
|
||||
import org.whispersystems.signalservice.api.util.ProtoUtil;
|
||||
import org.whispersystems.signalservice.internal.storage.protos.GroupV1Record;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class SignalGroupV1Record implements SignalRecord {
|
||||
@@ -26,6 +29,47 @@ public final class SignalGroupV1Record implements SignalRecord {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignalStorageRecord asStorageRecord() {
|
||||
return SignalStorageRecord.forGroupV1(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeDiff(SignalRecord other) {
|
||||
if (other instanceof SignalGroupV1Record) {
|
||||
SignalGroupV1Record that = (SignalGroupV1Record) other;
|
||||
List<String> diff = new LinkedList<>();
|
||||
|
||||
if (!Arrays.equals(this.groupId, that.groupId)) {
|
||||
diff.add("MasterKey");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isBlocked(), that.isBlocked())) {
|
||||
diff.add("Blocked");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isProfileSharingEnabled(), that.isProfileSharingEnabled())) {
|
||||
diff.add("ProfileSharing");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isArchived(), that.isArchived())) {
|
||||
diff.add("Archived");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isForcedUnread(), that.isForcedUnread())) {
|
||||
diff.add("ForcedUnread");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.hasUnknownFields(), that.hasUnknownFields())) {
|
||||
diff.add("UnknownFields");
|
||||
}
|
||||
|
||||
return diff.toString();
|
||||
} else {
|
||||
return "Different class. " + getClass().getSimpleName() + " | " + other.getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasUnknownFields() {
|
||||
return hasUnknownFields;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ import org.signal.zkgroup.groups.GroupMasterKey;
|
||||
import org.whispersystems.signalservice.api.util.ProtoUtil;
|
||||
import org.whispersystems.signalservice.internal.storage.protos.GroupV2Record;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class SignalGroupV2Record implements SignalRecord {
|
||||
@@ -28,6 +31,47 @@ public final class SignalGroupV2Record implements SignalRecord {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignalStorageRecord asStorageRecord() {
|
||||
return SignalStorageRecord.forGroupV2(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeDiff(SignalRecord other) {
|
||||
if (other instanceof SignalGroupV2Record) {
|
||||
SignalGroupV2Record that = (SignalGroupV2Record) other;
|
||||
List<String> diff = new LinkedList<>();
|
||||
|
||||
if (!Arrays.equals(this.getMasterKeyBytes(), that.getMasterKeyBytes())) {
|
||||
diff.add("MasterKey");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isBlocked(), that.isBlocked())) {
|
||||
diff.add("Blocked");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isProfileSharingEnabled(), that.isProfileSharingEnabled())) {
|
||||
diff.add("ProfileSharing");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isArchived(), that.isArchived())) {
|
||||
diff.add("Archived");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.isForcedUnread(), that.isForcedUnread())) {
|
||||
diff.add("ForcedUnread");
|
||||
}
|
||||
|
||||
if (!Objects.equals(this.hasUnknownFields(), that.hasUnknownFields())) {
|
||||
diff.add("UnknownFields");
|
||||
}
|
||||
|
||||
return diff.toString();
|
||||
} else {
|
||||
return "Different class. " + getClass().getSimpleName() + " | " + other.getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasUnknownFields() {
|
||||
return hasUnknownFields;
|
||||
}
|
||||
|
||||
@@ -2,4 +2,6 @@ package org.whispersystems.signalservice.api.storage;
|
||||
|
||||
public interface SignalRecord {
|
||||
StorageId getId();
|
||||
SignalStorageRecord asStorageRecord();
|
||||
String describeDiff(SignalRecord other);
|
||||
}
|
||||
|
||||
@@ -67,6 +67,16 @@ public class SignalStorageRecord implements SignalRecord {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignalStorageRecord asStorageRecord() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeDiff(SignalRecord other) {
|
||||
return "Diffs not supported.";
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return id.getType();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,10 @@ public class StorageId {
|
||||
return new StorageId(type, raw);
|
||||
}
|
||||
|
||||
public boolean isUnknown() {
|
||||
return !isKnownType(type);
|
||||
}
|
||||
|
||||
private StorageId(int type, byte[] raw) {
|
||||
this.type = type;
|
||||
this.raw = raw;
|
||||
|
||||
Reference in New Issue
Block a user