mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-28 18:10:38 +00:00
Use existing connection to read configuration during storage sync
This commit is contained in:
parent
5ac5938c8b
commit
e4af0be0ad
5 changed files with 46 additions and 12 deletions
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue