Use existing connection to read configuration during storage sync

This commit is contained in:
AsamK 2025-01-14 21:33:12 +01:00
parent 5ac5938c8b
commit e4af0be0ad
5 changed files with 46 additions and 12 deletions

View file

@ -353,7 +353,8 @@ public class StorageHelper {
final var storageId = newContactStorageIds.get(recipientId); final var storageId = newContactStorageIds.get(recipientId);
if (storageId.getType() == ManifestRecord.Identifier.Type.ACCOUNT.getValue()) { if (storageId.getType() == ManifestRecord.Identifier.Type.ACCOUNT.getValue()) {
final var recipient = account.getRecipientStore().getRecipient(connection, recipientId); final var recipient = account.getRecipientStore().getRecipient(connection, recipientId);
final var accountRecord = StorageSyncModels.localToRemoteRecord(account.getConfigurationStore(), final var accountRecord = StorageSyncModels.localToRemoteRecord(connection,
account.getConfigurationStore(),
recipient, recipient,
account.getUsernameLink()); account.getUsernameLink());
newStorageRecords.add(new SignalStorageRecord(storageId, newStorageRecords.add(new SignalStorageRecord(storageId,
@ -551,7 +552,8 @@ public class StorageHelper {
final var selfRecipient = account.getRecipientStore() final var selfRecipient = account.getRecipientStore()
.getRecipient(connection, account.getSelfRecipientId()); .getRecipient(connection, account.getSelfRecipientId());
final var record = StorageSyncModels.localToRemoteRecord(account.getConfigurationStore(), final var record = StorageSyncModels.localToRemoteRecord(connection,
account.getConfigurationStore(),
selfRecipient, selfRecipient,
account.getUsernameLink()); account.getUsernameLink());
yield new SignalStorageRecord(storageId, new StorageRecord.Builder().account(record).build()); yield new SignalStorageRecord(storageId, new StorageRecord.Builder().account(record).build());

View file

@ -36,6 +36,10 @@ public class ConfigurationStore {
return keyValueStore.getEntry(readReceipts); return keyValueStore.getEntry(readReceipts);
} }
public Boolean getReadReceipts(final Connection connection) throws SQLException {
return keyValueStore.getEntry(connection, readReceipts);
}
public void setReadReceipts(final boolean value) { public void setReadReceipts(final boolean value) {
if (keyValueStore.storeEntry(readReceipts, value)) { if (keyValueStore.storeEntry(readReceipts, value)) {
recipientStore.rotateSelfStorageId(); recipientStore.rotateSelfStorageId();
@ -52,6 +56,10 @@ public class ConfigurationStore {
return keyValueStore.getEntry(unidentifiedDeliveryIndicators); return keyValueStore.getEntry(unidentifiedDeliveryIndicators);
} }
public Boolean getUnidentifiedDeliveryIndicators(final Connection connection) throws SQLException {
return keyValueStore.getEntry(connection, unidentifiedDeliveryIndicators);
}
public void setUnidentifiedDeliveryIndicators(final boolean value) { public void setUnidentifiedDeliveryIndicators(final boolean value) {
if (keyValueStore.storeEntry(unidentifiedDeliveryIndicators, value)) { if (keyValueStore.storeEntry(unidentifiedDeliveryIndicators, value)) {
recipientStore.rotateSelfStorageId(); recipientStore.rotateSelfStorageId();
@ -71,6 +79,10 @@ public class ConfigurationStore {
return keyValueStore.getEntry(typingIndicators); return keyValueStore.getEntry(typingIndicators);
} }
public Boolean getTypingIndicators(final Connection connection) throws SQLException {
return keyValueStore.getEntry(connection, typingIndicators);
}
public void setTypingIndicators(final boolean value) { public void setTypingIndicators(final boolean value) {
if (keyValueStore.storeEntry(typingIndicators, value)) { if (keyValueStore.storeEntry(typingIndicators, value)) {
recipientStore.rotateSelfStorageId(); recipientStore.rotateSelfStorageId();
@ -87,6 +99,10 @@ public class ConfigurationStore {
return keyValueStore.getEntry(linkPreviews); return keyValueStore.getEntry(linkPreviews);
} }
public Boolean getLinkPreviews(final Connection connection) throws SQLException {
return keyValueStore.getEntry(connection, linkPreviews);
}
public void setLinkPreviews(final boolean value) { public void setLinkPreviews(final boolean value) {
if (keyValueStore.storeEntry(linkPreviews, value)) { if (keyValueStore.storeEntry(linkPreviews, value)) {
recipientStore.rotateSelfStorageId(); recipientStore.rotateSelfStorageId();
@ -103,6 +119,10 @@ public class ConfigurationStore {
return keyValueStore.getEntry(phoneNumberUnlisted); return keyValueStore.getEntry(phoneNumberUnlisted);
} }
public Boolean getPhoneNumberUnlisted(final Connection connection) throws SQLException {
return keyValueStore.getEntry(connection, phoneNumberUnlisted);
}
public void setPhoneNumberUnlisted(final boolean value) { public void setPhoneNumberUnlisted(final boolean value) {
if (keyValueStore.storeEntry(phoneNumberUnlisted, value)) { if (keyValueStore.storeEntry(phoneNumberUnlisted, value)) {
recipientStore.rotateSelfStorageId(); recipientStore.rotateSelfStorageId();
@ -119,6 +139,10 @@ public class ConfigurationStore {
return keyValueStore.getEntry(phoneNumberSharingMode); return keyValueStore.getEntry(phoneNumberSharingMode);
} }
public PhoneNumberSharingMode getPhoneNumberSharingMode(final Connection connection) throws SQLException {
return keyValueStore.getEntry(connection, phoneNumberSharingMode);
}
public void setPhoneNumberSharingMode(final PhoneNumberSharingMode value) { public void setPhoneNumberSharingMode(final PhoneNumberSharingMode value) {
if (keyValueStore.storeEntry(phoneNumberSharingMode, value)) { if (keyValueStore.storeEntry(phoneNumberSharingMode, value)) {
recipientStore.rotateSelfStorageId(); recipientStore.rotateSelfStorageId();
@ -138,6 +162,10 @@ public class ConfigurationStore {
return keyValueStore.getEntry(usernameLinkColor); return keyValueStore.getEntry(usernameLinkColor);
} }
public String getUsernameLinkColor(final Connection connection) throws SQLException {
return keyValueStore.getEntry(connection, usernameLinkColor);
}
public void setUsernameLinkColor(final String color) { public void setUsernameLinkColor(final String color) {
if (keyValueStore.storeEntry(usernameLinkColor, color)) { if (keyValueStore.storeEntry(usernameLinkColor, color)) {
recipientStore.rotateSelfStorageId(); recipientStore.rotateSelfStorageId();

View file

@ -52,7 +52,7 @@ public class KeyValueStore {
} }
} }
private <T> T getEntry(final Connection connection, final KeyValueEntry<T> key) throws SQLException { public <T> T getEntry(final Connection connection, final KeyValueEntry<T> key) throws SQLException {
final var sql = ( final var sql = (
""" """
SELECT key, value SELECT key, value

View file

@ -53,7 +53,8 @@ public class AccountRecordProcessor extends DefaultStorageRecordProcessor<Signal
final var recipient = account.getRecipientStore().getRecipient(connection, selfRecipientId); final var recipient = account.getRecipientStore().getRecipient(connection, selfRecipientId);
final var storageId = account.getRecipientStore().getSelfStorageId(connection); final var storageId = account.getRecipientStore().getSelfStorageId(connection);
this.localAccountRecord = new SignalAccountRecord(storageId, this.localAccountRecord = new SignalAccountRecord(storageId,
StorageSyncModels.localToRemoteRecord(account.getConfigurationStore(), StorageSyncModels.localToRemoteRecord(connection,
account.getConfigurationStore(),
recipient, recipient,
account.getUsernameLink())); account.getUsernameLink()));
} }

View file

@ -22,6 +22,8 @@ import org.whispersystems.signalservice.internal.storage.protos.ContactRecord.Id
import org.whispersystems.signalservice.internal.storage.protos.GroupV1Record; import org.whispersystems.signalservice.internal.storage.protos.GroupV1Record;
import org.whispersystems.signalservice.internal.storage.protos.GroupV2Record; import org.whispersystems.signalservice.internal.storage.protos.GroupV2Record;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Optional; import java.util.Optional;
import okio.ByteString; import okio.ByteString;
@ -49,10 +51,11 @@ public final class StorageSyncModels {
} }
public static AccountRecord localToRemoteRecord( public static AccountRecord localToRemoteRecord(
final Connection connection,
ConfigurationStore configStore, ConfigurationStore configStore,
Recipient self, Recipient self,
UsernameLinkComponents usernameLinkComponents UsernameLinkComponents usernameLinkComponents
) { ) throws SQLException {
final var builder = SignalAccountRecord.Companion.newBuilder(self.getStorageRecord()); final var builder = SignalAccountRecord.Companion.newBuilder(self.getStorageRecord());
if (self.getProfileKey() != null) { if (self.getProfileKey() != null) {
builder.profileKey(ByteString.of(self.getProfileKey().serialize())); builder.profileKey(ByteString.of(self.getProfileKey().serialize()));
@ -62,19 +65,19 @@ public final class StorageSyncModels {
.familyName(emptyIfNull(self.getProfile().getFamilyName())) .familyName(emptyIfNull(self.getProfile().getFamilyName()))
.avatarUrlPath(emptyIfNull(self.getProfile().getAvatarUrlPath())); .avatarUrlPath(emptyIfNull(self.getProfile().getAvatarUrlPath()));
} }
builder.typingIndicators(Optional.ofNullable(configStore.getTypingIndicators()).orElse(true)) builder.typingIndicators(Optional.ofNullable(configStore.getTypingIndicators(connection)).orElse(true))
.readReceipts(Optional.ofNullable(configStore.getReadReceipts()).orElse(true)) .readReceipts(Optional.ofNullable(configStore.getReadReceipts(connection)).orElse(true))
.sealedSenderIndicators(Optional.ofNullable(configStore.getUnidentifiedDeliveryIndicators()) .sealedSenderIndicators(Optional.ofNullable(configStore.getUnidentifiedDeliveryIndicators(connection))
.orElse(true)) .orElse(true))
.linkPreviews(Optional.ofNullable(configStore.getLinkPreviews()).orElse(true)) .linkPreviews(Optional.ofNullable(configStore.getLinkPreviews(connection)).orElse(true))
.unlistedPhoneNumber(Optional.ofNullable(configStore.getPhoneNumberUnlisted()).orElse(false)) .unlistedPhoneNumber(Optional.ofNullable(configStore.getPhoneNumberUnlisted(connection)).orElse(false))
.phoneNumberSharingMode(Optional.ofNullable(configStore.getPhoneNumberSharingMode()) .phoneNumberSharingMode(Optional.ofNullable(configStore.getPhoneNumberSharingMode(connection))
.map(StorageSyncModels::localToRemote) .map(StorageSyncModels::localToRemote)
.orElse(AccountRecord.PhoneNumberSharingMode.UNKNOWN)) .orElse(AccountRecord.PhoneNumberSharingMode.UNKNOWN))
.e164(self.getAddress().number().orElse("")) .e164(self.getAddress().number().orElse(""))
.username(self.getAddress().username().orElse("")); .username(self.getAddress().username().orElse(""));
if (usernameLinkComponents != null) { if (usernameLinkComponents != null) {
final var linkColor = configStore.getUsernameLinkColor(); final var linkColor = configStore.getUsernameLinkColor(connection);
builder.usernameLink(new UsernameLink.Builder().entropy(ByteString.of(usernameLinkComponents.getEntropy())) builder.usernameLink(new UsernameLink.Builder().entropy(ByteString.of(usernameLinkComponents.getEntropy()))
.serverId(UuidUtil.toByteString(usernameLinkComponents.getServerId())) .serverId(UuidUtil.toByteString(usernameLinkComponents.getServerId()))
.color(linkColor == null ? UsernameLink.Color.UNKNOWN : UsernameLink.Color.valueOf(linkColor)) .color(linkColor == null ? UsernameLink.Color.UNKNOWN : UsernameLink.Color.valueOf(linkColor))