Add backup subscriber fields to account record.

This commit is contained in:
Alex Hart 2024-10-10 16:18:29 -03:00 committed by Greyson Parrelli
parent 497cec4c17
commit 340bb93653
4 changed files with 41 additions and 5 deletions

View file

@ -94,6 +94,14 @@ public class AccountRecordProcessor extends DefaultStorageRecordProcessor<Signal
subscriber = local.getSubscriber();
}
SignalAccountRecord.Subscriber backupsSubscriber;
if (remote.getSubscriber().getId().isPresent()) {
backupsSubscriber = remote.getSubscriber();
} else {
backupsSubscriber = local.getSubscriber();
}
OptionalBool storyViewReceiptsState;
if (remote.getStoryViewReceiptsState() == OptionalBool.UNSET) {
storyViewReceiptsState = local.getStoryViewReceiptsState();
@ -128,8 +136,8 @@ public class AccountRecordProcessor extends DefaultStorageRecordProcessor<Signal
boolean hasSeenUsernameOnboarding = remote.hasCompletedUsernameOnboarding() || local.hasCompletedUsernameOnboarding();
String username = remote.getUsername();
AccountRecord.UsernameLink usernameLink = remote.getUsernameLink();
boolean matchesRemote = doParamsMatch(remote, unknownFields, givenName, familyName, avatarUrlPath, profileKey, noteToSelfArchived, noteToSelfForcedUnread, readReceipts, typingIndicators, sealedSenderIndicators, linkPreviews, phoneNumberSharingMode, unlisted, pinnedConversations, preferContactAvatars, payments, universalExpireTimer, primarySendsSms, e164, defaultReactions, subscriber, displayBadgesOnProfile, subscriptionManuallyCancelled, keepMutedChatsArchived, hasSetMyStoriesPrivacy, hasViewedOnboardingStory, hasSeenUsernameOnboarding, storiesDisabled, storyViewReceiptsState, username, usernameLink);
boolean matchesLocal = doParamsMatch(local, unknownFields, givenName, familyName, avatarUrlPath, profileKey, noteToSelfArchived, noteToSelfForcedUnread, readReceipts, typingIndicators, sealedSenderIndicators, linkPreviews, phoneNumberSharingMode, unlisted, pinnedConversations, preferContactAvatars, payments, universalExpireTimer, primarySendsSms, e164, defaultReactions, subscriber, displayBadgesOnProfile, subscriptionManuallyCancelled, keepMutedChatsArchived, hasSetMyStoriesPrivacy, hasViewedOnboardingStory, hasSeenUsernameOnboarding, storiesDisabled, storyViewReceiptsState, username, usernameLink);
boolean matchesRemote = doParamsMatch(remote, unknownFields, givenName, familyName, avatarUrlPath, profileKey, noteToSelfArchived, noteToSelfForcedUnread, readReceipts, typingIndicators, sealedSenderIndicators, linkPreviews, phoneNumberSharingMode, unlisted, pinnedConversations, preferContactAvatars, payments, universalExpireTimer, primarySendsSms, e164, defaultReactions, subscriber, displayBadgesOnProfile, subscriptionManuallyCancelled, keepMutedChatsArchived, hasSetMyStoriesPrivacy, hasViewedOnboardingStory, hasSeenUsernameOnboarding, storiesDisabled, storyViewReceiptsState, username, usernameLink, backupsSubscriber);
boolean matchesLocal = doParamsMatch(local, unknownFields, givenName, familyName, avatarUrlPath, profileKey, noteToSelfArchived, noteToSelfForcedUnread, readReceipts, typingIndicators, sealedSenderIndicators, linkPreviews, phoneNumberSharingMode, unlisted, pinnedConversations, preferContactAvatars, payments, universalExpireTimer, primarySendsSms, e164, defaultReactions, subscriber, displayBadgesOnProfile, subscriptionManuallyCancelled, keepMutedChatsArchived, hasSetMyStoriesPrivacy, hasViewedOnboardingStory, hasSeenUsernameOnboarding, storiesDisabled, storyViewReceiptsState, username, usernameLink, backupsSubscriber);
if (matchesRemote) {
return remote;
@ -167,7 +175,8 @@ public class AccountRecordProcessor extends DefaultStorageRecordProcessor<Signal
.setHasSeenGroupStoryEducationSheet(hasSeenGroupStoryEducation)
.setHasCompletedUsernameOnboarding(hasSeenUsernameOnboarding)
.setUsername(username)
.setUsernameLink(usernameLink);
.setUsernameLink(usernameLink)
.setBackupsSubscriber(backupsSubscriber);
return builder.build();
}
@ -219,7 +228,8 @@ public class AccountRecordProcessor extends DefaultStorageRecordProcessor<Signal
boolean storiesDisabled,
@NonNull OptionalBool storyViewReceiptsState,
@Nullable String username,
@Nullable AccountRecord.UsernameLink usernameLink)
@Nullable AccountRecord.UsernameLink usernameLink,
@NonNull SignalAccountRecord.Subscriber backupsSubscriber)
{
return Arrays.equals(contact.serializeUnknownFields(), unknownFields) &&
Objects.equals(contact.getGivenName().orElse(""), givenName) &&
@ -251,6 +261,7 @@ public class AccountRecordProcessor extends DefaultStorageRecordProcessor<Signal
contact.isStoriesDisabled() == storiesDisabled &&
contact.getStoryViewReceiptsState().equals(storyViewReceiptsState) &&
Objects.equals(contact.getUsername(), username) &&
Objects.equals(contact.getUsernameLink(), usernameLink);
Objects.equals(contact.getUsernameLink(), usernameLink) &&
Objects.equals(contact.getBackupsSubscriber(), backupsSubscriber);
}
}

View file

@ -157,6 +157,7 @@ public final class StorageSyncHelper {
.setUniversalExpireTimer(SignalStore.settings().getUniversalExpireTimer())
.setDefaultReactions(SignalStore.emoji().getReactions())
.setSubscriber(StorageSyncModels.localToRemoteSubscriber(InAppPaymentsRepository.getSubscriber(InAppPaymentSubscriberRecord.Type.DONATION)))
.setBackupsSubscriber(StorageSyncModels.localToRemoteSubscriber(InAppPaymentsRepository.getSubscriber(InAppPaymentSubscriberRecord.Type.BACKUP)))
.setDisplayBadgesOnProfile(SignalStore.inAppPayments().getDisplayBadgesOnProfile())
.setSubscriptionManuallyCancelled(InAppPaymentsRepository.isUserManuallyCancelled(InAppPaymentSubscriberRecord.Type.DONATION))
.setKeepMutedChatsArchived(SignalStore.settings().shouldKeepMutedChatsArchived())

View file

@ -38,6 +38,7 @@ public final class SignalAccountRecord implements SignalRecord {
private final Payments payments;
private final List<String> defaultReactions;
private final Subscriber subscriber;
private final Subscriber backupsSubscriber;
public SignalAccountRecord(StorageId id, AccountRecord proto) {
this.id = id;
@ -51,6 +52,7 @@ public final class SignalAccountRecord implements SignalRecord {
this.pinnedConversations = new ArrayList<>(proto.pinnedConversations.size());
this.defaultReactions = new ArrayList<>(proto.preferredReactionEmoji);
this.subscriber = new Subscriber(proto.subscriberCurrencyCode, proto.subscriberId.toByteArray());
this.backupsSubscriber = new Subscriber(proto.backupsSubscriberCurrencyCode, proto.backupsSubscriberId.toByteArray());
if (proto.payments != null) {
this.payments = new Payments(proto.payments.enabled, OptionalUtil.absentIfEmpty(proto.payments.entropy));
@ -207,6 +209,10 @@ public final class SignalAccountRecord implements SignalRecord {
diff.add("HasCompletedUsernameOnboarding");
}
if (!Objects.equals(this.getBackupsSubscriber(), that.getBackupsSubscriber())) {
diff.add("BackupsSubscriber");
}
return diff.toString();
} else {
return "Different class. " + getClass().getSimpleName() + " | " + other.getClass().getSimpleName();
@ -301,6 +307,10 @@ public final class SignalAccountRecord implements SignalRecord {
return subscriber;
}
public Subscriber getBackupsSubscriber() {
return backupsSubscriber;
}
public boolean isDisplayBadgesOnProfile() {
return proto.displayBadgesOnProfile;
}
@ -666,6 +676,18 @@ public final class SignalAccountRecord implements SignalRecord {
return this;
}
public Builder setBackupsSubscriber(Subscriber subscriber) {
if (subscriber.id.isPresent() && subscriber.currencyCode.isPresent()) {
builder.backupsSubscriberId(ByteString.of(subscriber.id.get()));
builder.backupsSubscriberCurrencyCode(subscriber.currencyCode.get());
} else {
builder.backupsSubscriberId(StorageRecordProtoUtil.getDefaultAccountRecord().subscriberId);
builder.backupsSubscriberCurrencyCode(StorageRecordProtoUtil.getDefaultAccountRecord().subscriberCurrencyCode);
}
return this;
}
public Builder setDisplayBadgesOnProfile(boolean displayBadgesOnProfile) {
builder.displayBadgesOnProfile(displayBadgesOnProfile);
return this;

View file

@ -219,6 +219,8 @@ message AccountRecord {
string username = 33;
bool hasCompletedUsernameOnboarding = 34;
UsernameLink usernameLink = 35;
bytes backupsSubscriberId = 36;
string backupsSubscriberCurrencyCode = 37;
}
message StoryDistributionListRecord {