]> nmode's Git Repositories - signal-cli/commitdiff
Use existing connection to read configuration during storage sync
authorAsamK <asamk@gmx.de>
Tue, 14 Jan 2025 20:33:12 +0000 (21:33 +0100)
committerAsamK <asamk@gmx.de>
Tue, 14 Jan 2025 20:33:12 +0000 (21:33 +0100)
lib/src/main/java/org/asamk/signal/manager/helper/StorageHelper.java
lib/src/main/java/org/asamk/signal/manager/storage/configuration/ConfigurationStore.java
lib/src/main/java/org/asamk/signal/manager/storage/keyValue/KeyValueStore.java
lib/src/main/java/org/asamk/signal/manager/syncStorage/AccountRecordProcessor.java
lib/src/main/java/org/asamk/signal/manager/syncStorage/StorageSyncModels.java

index 5f52585e1e490e6611bbdb139ffd602193c115dd..bb53479b7e288e0b076923150f02a1edf8c79f58 100644 (file)
@@ -353,7 +353,8 @@ public class StorageHelper {
                 final var storageId = newContactStorageIds.get(recipientId);
                 if (storageId.getType() == ManifestRecord.Identifier.Type.ACCOUNT.getValue()) {
                     final var recipient = account.getRecipientStore().getRecipient(connection, recipientId);
-                    final var accountRecord = StorageSyncModels.localToRemoteRecord(account.getConfigurationStore(),
+                    final var accountRecord = StorageSyncModels.localToRemoteRecord(connection,
+                            account.getConfigurationStore(),
                             recipient,
                             account.getUsernameLink());
                     newStorageRecords.add(new SignalStorageRecord(storageId,
@@ -551,7 +552,8 @@ public class StorageHelper {
                 final var selfRecipient = account.getRecipientStore()
                         .getRecipient(connection, account.getSelfRecipientId());
 
-                final var record = StorageSyncModels.localToRemoteRecord(account.getConfigurationStore(),
+                final var record = StorageSyncModels.localToRemoteRecord(connection,
+                        account.getConfigurationStore(),
                         selfRecipient,
                         account.getUsernameLink());
                 yield new SignalStorageRecord(storageId, new StorageRecord.Builder().account(record).build());
index ef4a4545073cf634ef512a049df1cfe3d6230c62..88f057258f76db794edec919153b8162a3bb30ee 100644 (file)
@@ -36,6 +36,10 @@ public class ConfigurationStore {
         return keyValueStore.getEntry(readReceipts);
     }
 
+    public Boolean getReadReceipts(final Connection connection) throws SQLException {
+        return keyValueStore.getEntry(connection, readReceipts);
+    }
+
     public void setReadReceipts(final boolean value) {
         if (keyValueStore.storeEntry(readReceipts, value)) {
             recipientStore.rotateSelfStorageId();
@@ -52,6 +56,10 @@ public class ConfigurationStore {
         return keyValueStore.getEntry(unidentifiedDeliveryIndicators);
     }
 
+    public Boolean getUnidentifiedDeliveryIndicators(final Connection connection) throws SQLException {
+        return keyValueStore.getEntry(connection, unidentifiedDeliveryIndicators);
+    }
+
     public void setUnidentifiedDeliveryIndicators(final boolean value) {
         if (keyValueStore.storeEntry(unidentifiedDeliveryIndicators, value)) {
             recipientStore.rotateSelfStorageId();
@@ -71,6 +79,10 @@ public class ConfigurationStore {
         return keyValueStore.getEntry(typingIndicators);
     }
 
+    public Boolean getTypingIndicators(final Connection connection) throws SQLException {
+        return keyValueStore.getEntry(connection, typingIndicators);
+    }
+
     public void setTypingIndicators(final boolean value) {
         if (keyValueStore.storeEntry(typingIndicators, value)) {
             recipientStore.rotateSelfStorageId();
@@ -87,6 +99,10 @@ public class ConfigurationStore {
         return keyValueStore.getEntry(linkPreviews);
     }
 
+    public Boolean getLinkPreviews(final Connection connection) throws SQLException {
+        return keyValueStore.getEntry(connection, linkPreviews);
+    }
+
     public void setLinkPreviews(final boolean value) {
         if (keyValueStore.storeEntry(linkPreviews, value)) {
             recipientStore.rotateSelfStorageId();
@@ -103,6 +119,10 @@ public class ConfigurationStore {
         return keyValueStore.getEntry(phoneNumberUnlisted);
     }
 
+    public Boolean getPhoneNumberUnlisted(final Connection connection) throws SQLException {
+        return keyValueStore.getEntry(connection, phoneNumberUnlisted);
+    }
+
     public void setPhoneNumberUnlisted(final boolean value) {
         if (keyValueStore.storeEntry(phoneNumberUnlisted, value)) {
             recipientStore.rotateSelfStorageId();
@@ -119,6 +139,10 @@ public class ConfigurationStore {
         return keyValueStore.getEntry(phoneNumberSharingMode);
     }
 
+    public PhoneNumberSharingMode getPhoneNumberSharingMode(final Connection connection) throws SQLException {
+        return keyValueStore.getEntry(connection, phoneNumberSharingMode);
+    }
+
     public void setPhoneNumberSharingMode(final PhoneNumberSharingMode value) {
         if (keyValueStore.storeEntry(phoneNumberSharingMode, value)) {
             recipientStore.rotateSelfStorageId();
@@ -138,6 +162,10 @@ public class ConfigurationStore {
         return keyValueStore.getEntry(usernameLinkColor);
     }
 
+    public String getUsernameLinkColor(final Connection connection) throws SQLException {
+        return keyValueStore.getEntry(connection, usernameLinkColor);
+    }
+
     public void setUsernameLinkColor(final String color) {
         if (keyValueStore.storeEntry(usernameLinkColor, color)) {
             recipientStore.rotateSelfStorageId();
index ac43c9c5c3c831751edf7ee52f362a1fd18766ae..17135d1093daa0cebeca7e37bad32e4712113c10 100644 (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 = (
                 """
                 SELECT key, value
index 5b1efbd68e83064d67e76cfc38c1e873badcce09..656297bf7fe6653869d1298e6c9484ebd54d3db5 100644 (file)
@@ -53,7 +53,8 @@ public class AccountRecordProcessor extends DefaultStorageRecordProcessor<Signal
         final var recipient = account.getRecipientStore().getRecipient(connection, selfRecipientId);
         final var storageId = account.getRecipientStore().getSelfStorageId(connection);
         this.localAccountRecord = new SignalAccountRecord(storageId,
-                StorageSyncModels.localToRemoteRecord(account.getConfigurationStore(),
+                StorageSyncModels.localToRemoteRecord(connection,
+                        account.getConfigurationStore(),
                         recipient,
                         account.getUsernameLink()));
     }
index 9eeaf53a244768e4fdb61ebc0559e76305d69d23..b5d702b4264e96a4361c9bcbc654ffd1327a8198 100644 (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.GroupV2Record;
 
+import java.sql.Connection;
+import java.sql.SQLException;
 import java.util.Optional;
 
 import okio.ByteString;
@@ -49,10 +51,11 @@ public final class StorageSyncModels {
     }
 
     public static AccountRecord localToRemoteRecord(
+            final Connection connection,
             ConfigurationStore configStore,
             Recipient self,
             UsernameLinkComponents usernameLinkComponents
-    ) {
+    ) throws SQLException {
         final var builder = SignalAccountRecord.Companion.newBuilder(self.getStorageRecord());
         if (self.getProfileKey() != null) {
             builder.profileKey(ByteString.of(self.getProfileKey().serialize()));
@@ -62,19 +65,19 @@ public final class StorageSyncModels {
                     .familyName(emptyIfNull(self.getProfile().getFamilyName()))
                     .avatarUrlPath(emptyIfNull(self.getProfile().getAvatarUrlPath()));
         }
-        builder.typingIndicators(Optional.ofNullable(configStore.getTypingIndicators()).orElse(true))
-                .readReceipts(Optional.ofNullable(configStore.getReadReceipts()).orElse(true))
-                .sealedSenderIndicators(Optional.ofNullable(configStore.getUnidentifiedDeliveryIndicators())
+        builder.typingIndicators(Optional.ofNullable(configStore.getTypingIndicators(connection)).orElse(true))
+                .readReceipts(Optional.ofNullable(configStore.getReadReceipts(connection)).orElse(true))
+                .sealedSenderIndicators(Optional.ofNullable(configStore.getUnidentifiedDeliveryIndicators(connection))
                         .orElse(true))
-                .linkPreviews(Optional.ofNullable(configStore.getLinkPreviews()).orElse(true))
-                .unlistedPhoneNumber(Optional.ofNullable(configStore.getPhoneNumberUnlisted()).orElse(false))
-                .phoneNumberSharingMode(Optional.ofNullable(configStore.getPhoneNumberSharingMode())
+                .linkPreviews(Optional.ofNullable(configStore.getLinkPreviews(connection)).orElse(true))
+                .unlistedPhoneNumber(Optional.ofNullable(configStore.getPhoneNumberUnlisted(connection)).orElse(false))
+                .phoneNumberSharingMode(Optional.ofNullable(configStore.getPhoneNumberSharingMode(connection))
                         .map(StorageSyncModels::localToRemote)
                         .orElse(AccountRecord.PhoneNumberSharingMode.UNKNOWN))
                 .e164(self.getAddress().number().orElse(""))
                 .username(self.getAddress().username().orElse(""));
         if (usernameLinkComponents != null) {
-            final var linkColor = configStore.getUsernameLinkColor();
+            final var linkColor = configStore.getUsernameLinkColor(connection);
             builder.usernameLink(new UsernameLink.Builder().entropy(ByteString.of(usernameLinkComponents.getEntropy()))
                     .serverId(UuidUtil.toByteString(usernameLinkComponents.getServerId()))
                     .color(linkColor == null ? UsernameLink.Color.UNKNOWN : UsernameLink.Color.valueOf(linkColor))