]> nmode's Git Repositories - signal-cli/commitdiff
Reduce direct use of recipient store
authorAsamK <asamk@gmx.de>
Mon, 23 May 2022 11:18:33 +0000 (13:18 +0200)
committerAsamK <asamk@gmx.de>
Mon, 23 May 2022 11:21:28 +0000 (13:21 +0200)
13 files changed:
lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java
lib/src/main/java/org/asamk/signal/manager/helper/AccountHelper.java
lib/src/main/java/org/asamk/signal/manager/helper/GroupHelper.java
lib/src/main/java/org/asamk/signal/manager/helper/IncomingMessageHandler.java
lib/src/main/java/org/asamk/signal/manager/helper/ProfileHelper.java
lib/src/main/java/org/asamk/signal/manager/helper/ReceiveHelper.java
lib/src/main/java/org/asamk/signal/manager/helper/RecipientHelper.java
lib/src/main/java/org/asamk/signal/manager/helper/SendHelper.java
lib/src/main/java/org/asamk/signal/manager/helper/StorageHelper.java
lib/src/main/java/org/asamk/signal/manager/helper/SyncHelper.java
lib/src/main/java/org/asamk/signal/manager/storage/SignalAccount.java
lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java
lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientTrustedResolver.java [new file with mode: 0644]

index 96196f8ff8e6f3fc89039f4ab6bb424fd2cc8173..19ff8b54c1990e60ecbc9b4a8543ce3a6f00d154 100644 (file)
@@ -168,9 +168,9 @@ class ManagerImpl implements Manager {
             logger.trace("Archiving old sessions for {}", recipientId);
             account.getSessionStore().archiveSessions(recipientId);
             account.getSenderKeyStore().deleteSharedWith(recipientId);
-            final var profile = account.getRecipientStore().getProfile(recipientId);
+            final var profile = account.getProfileStore().getProfile(recipientId);
             if (profile != null) {
-                account.getRecipientStore()
+                account.getProfileStore()
                         .storeProfile(recipientId,
                                 Profile.newBuilder(profile)
                                         .withUnidentifiedAccessMode(Profile.UnidentifiedAccessMode.UNKNOWN)
@@ -215,7 +215,8 @@ class ManagerImpl implements Manager {
             final var aci = registeredUsers.get(number);
             final var profile = aci == null
                     ? null
-                    : context.getProfileHelper().getRecipientProfile(account.getRecipientStore().resolveRecipient(aci));
+                    : context.getProfileHelper()
+                            .getRecipientProfile(account.getRecipientResolver().resolveRecipient(aci));
             return new UserStatus(number.isEmpty() ? null : number,
                     aci == null ? null : aci.uuid(),
                     profile != null
@@ -356,9 +357,7 @@ class ManagerImpl implements Manager {
             return null;
         }
 
-        return Group.from(groupInfo,
-                account.getRecipientStore()::resolveRecipientAddress,
-                account.getSelfRecipientId());
+        return Group.from(groupInfo, account.getRecipientAddressResolver(), account.getSelfRecipientId());
     }
 
     @Override
@@ -459,9 +458,7 @@ class ManagerImpl implements Manager {
     }
 
     private SendMessageResult toSendMessageResult(final org.whispersystems.signalservice.api.messages.SendMessageResult result) {
-        return SendMessageResult.from(result,
-                account.getRecipientStore(),
-                account.getRecipientStore()::resolveRecipientAddress);
+        return SendMessageResult.from(result, account.getRecipientResolver(), account.getRecipientAddressResolver());
     }
 
     private SendMessageResults sendTypingMessage(
@@ -683,13 +680,13 @@ class ManagerImpl implements Manager {
 
     @Override
     public void deleteRecipient(final RecipientIdentifier.Single recipient) {
-        account.removeRecipient(account.getRecipientStore().resolveRecipient(recipient.toPartialRecipientAddress()));
+        account.removeRecipient(account.getRecipientResolver().resolveRecipient(recipient.toPartialRecipientAddress()));
     }
 
     @Override
     public void deleteContact(final RecipientIdentifier.Single recipient) {
         account.getContactStore()
-                .deleteContact(account.getRecipientStore().resolveRecipient(recipient.toPartialRecipientAddress()));
+                .deleteContact(account.getRecipientResolver().resolveRecipient(recipient.toPartialRecipientAddress()));
     }
 
     @Override
@@ -1018,7 +1015,8 @@ class ManagerImpl implements Manager {
             return null;
         }
 
-        final var address = account.getRecipientStore().resolveRecipientAddress(identityInfo.getRecipientId());
+        final var address = account.getRecipientAddressResolver()
+                .resolveRecipientAddress(identityInfo.getRecipientId());
         final var scannableFingerprint = context.getIdentityHelper()
                 .computeSafetyNumberForScanning(identityInfo.getRecipientId(), identityInfo.getIdentityKey());
         return new Identity(address,
index b75cce525dbfa7e3c2587d92f74c83d29397c4da..224ac4da43e77fbba89bfac9b1c0be1f67d5b07f 100644 (file)
@@ -86,7 +86,7 @@ public class AccountHelper {
         account.setNumber(number);
         account.setAci(aci);
         account.setPni(pni);
-        account.getRecipientStore().resolveSelfRecipientTrusted(account.getSelfRecipientAddress());
+        account.getRecipientTrustedResolver().resolveSelfRecipientTrusted(account.getSelfRecipientAddress());
         // TODO check and update remote storage
         context.getUnidentifiedAccessHelper().rotateSenderCertificates();
         dependencies.resetAfterAddressChange();
index 9346372c1924aa80d52b271c6393f23dbbbd1977..f4e9232085194acf8efd5e98c1e0d803eea0abc4 100644 (file)
@@ -153,7 +153,7 @@ public class GroupHelper {
                     downloadGroupAvatar(groupId, groupSecretParams, avatar);
                 }
             }
-            groupInfoV2.setGroup(group, account.getRecipientStore());
+            groupInfoV2.setGroup(group, account.getRecipientResolver());
             account.getGroupStore().updateGroup(groupInfoV2);
         }
 
@@ -183,7 +183,7 @@ public class GroupHelper {
         final var gv2 = gv2Pair.first();
         final var decryptedGroup = gv2Pair.second();
 
-        gv2.setGroup(decryptedGroup, account.getRecipientStore());
+        gv2.setGroup(decryptedGroup, account.getRecipientResolver());
         if (avatarFile != null) {
             context.getAvatarStore()
                     .storeGroupAvatar(gv2.getGroupId(),
@@ -398,7 +398,7 @@ public class GroupHelper {
                         downloadGroupAvatar(groupInfoV2.getGroupId(), groupSecretParams, avatar);
                     }
                 }
-                groupInfoV2.setGroup(decryptedGroup, account.getRecipientStore());
+                groupInfoV2.setGroup(decryptedGroup, account.getRecipientResolver());
                 account.getGroupStore().updateGroup(group);
             }
         }
@@ -441,7 +441,7 @@ public class GroupHelper {
     private void storeProfileKeysFromMembers(final DecryptedGroup group) {
         for (var member : group.getMembersList()) {
             final var serviceId = ServiceId.fromByteString(member.getUuid());
-            final var recipientId = account.getRecipientStore().resolveRecipient(serviceId);
+            final var recipientId = account.getRecipientResolver().resolveRecipient(serviceId);
             final var profileStore = account.getProfileStore();
             if (profileStore.getProfileKey(recipientId) != null) {
                 // We already have a profile key, not updating it from a non-authoritative source
@@ -461,7 +461,7 @@ public class GroupHelper {
         if (profileKeyFromChange != null) {
             final var serviceId = profileKeyFromChange.first();
             final var profileKey = profileKeyFromChange.second();
-            final var recipientId = account.getRecipientStore().resolveRecipient(serviceId);
+            final var recipientId = account.getRecipientResolver().resolveRecipient(serviceId);
             account.getProfileStore().storeProfileKey(recipientId, profileKey);
         }
     }
@@ -487,7 +487,7 @@ public class GroupHelper {
                     .forEach(p -> {
                         final var serviceId = p.first();
                         final var profileKey = p.second();
-                        final var recipientId = account.getRecipientStore().resolveRecipient(serviceId);
+                        final var recipientId = account.getRecipientResolver().resolveRecipient(serviceId);
                         newProfileKeys.put(recipientId, profileKey);
                     });
             if (!page.getPagingData().hasMorePages()) {
@@ -729,7 +729,7 @@ public class GroupHelper {
             throw new LastGroupAdminException(groupInfoV2.getGroupId(), groupInfoV2.getTitle());
         }
         final var groupGroupChangePair = context.getGroupV2Helper().leaveGroup(groupInfoV2, newAdmins);
-        groupInfoV2.setGroup(groupGroupChangePair.first(), account.getRecipientStore());
+        groupInfoV2.setGroup(groupGroupChangePair.first(), account.getRecipientResolver());
         account.getGroupStore().updateGroup(groupInfoV2);
 
         var messageBuilder = getGroupUpdateMessageBuilder(groupInfoV2, groupGroupChangePair.second().toByteArray());
@@ -773,7 +773,7 @@ public class GroupHelper {
     ) throws IOException {
         final var selfRecipientId = account.getSelfRecipientId();
         final var members = group.getMembersIncludingPendingWithout(selfRecipientId);
-        group.setGroup(newDecryptedGroup, account.getRecipientStore());
+        group.setGroup(newDecryptedGroup, account.getRecipientResolver());
         members.addAll(group.getMembersIncludingPendingWithout(selfRecipientId));
         account.getGroupStore().updateGroup(group);
 
@@ -792,8 +792,8 @@ public class GroupHelper {
         return new SendGroupMessageResults(timestamp,
                 results.stream()
                         .map(sendMessageResult -> SendMessageResult.from(sendMessageResult,
-                                account.getRecipientStore(),
-                                account.getRecipientStore()::resolveRecipientAddress))
+                                account.getRecipientResolver(),
+                                account.getRecipientAddressResolver()))
                         .toList());
     }
 }
index 5e310a4844942dd0ba273cf37267d8f25f9da143..b28c21e67c398e8d29cb4d27c23cfd031eed5d80 100644 (file)
@@ -89,8 +89,8 @@ public final class IncomingMessageHandler {
             try {
                 content = dependencies.getCipher().decrypt(envelope);
             } catch (ProtocolUntrustedIdentityException e) {
-                final var recipientId = account.getRecipientStore().resolveRecipient(e.getSender());
-                final var exception = new UntrustedIdentityException(account.getRecipientStore()
+                final var recipientId = account.getRecipientResolver().resolveRecipient(e.getSender());
+                final var exception = new UntrustedIdentityException(account.getRecipientAddressResolver()
                         .resolveRecipientAddress(recipientId), e.getSenderDevice());
                 return new Pair<>(List.of(), exception);
             } catch (Exception e) {
@@ -112,7 +112,7 @@ public final class IncomingMessageHandler {
         if (envelope.hasSourceUuid()) {
             // Store uuid if we don't have it already
             // address/uuid in envelope is sent by server
-            account.getRecipientStore().resolveRecipientTrusted(envelope.getSourceAddress());
+            account.getRecipientTrustedResolver().resolveRecipientTrusted(envelope.getSourceAddress());
         }
         SignalServiceContent content = null;
         Exception exception = null;
@@ -120,14 +120,14 @@ public final class IncomingMessageHandler {
             try {
                 content = dependencies.getCipher().decrypt(envelope);
             } catch (ProtocolUntrustedIdentityException e) {
-                final var recipientId = account.getRecipientStore().resolveRecipient(e.getSender());
+                final var recipientId = account.getRecipientResolver().resolveRecipient(e.getSender());
                 actions.add(new RetrieveProfileAction(recipientId));
-                exception = new UntrustedIdentityException(account.getRecipientStore()
+                exception = new UntrustedIdentityException(account.getRecipientAddressResolver()
                         .resolveRecipientAddress(recipientId), e.getSenderDevice());
             } catch (ProtocolInvalidKeyIdException | ProtocolInvalidKeyException | ProtocolNoSessionException |
                      ProtocolInvalidMessageException e) {
                 logger.debug("Failed to decrypt incoming message", e);
-                final var sender = account.getRecipientStore().resolveRecipient(e.getSender());
+                final var sender = account.getRecipientResolver().resolveRecipient(e.getSender());
                 if (context.getContactHelper().isContactBlocked(sender)) {
                     logger.debug("Received invalid message from blocked contact, ignoring.");
                 } else {
@@ -169,7 +169,7 @@ public final class IncomingMessageHandler {
         if (!envelope.hasSourceUuid() && content != null) {
             // Store uuid if we don't have it already
             // address/uuid is validated by unidentified sender certificate
-            account.getRecipientStore().resolveRecipientTrusted(content.getSender());
+            account.getRecipientTrustedResolver().resolveRecipientTrusted(content.getSender());
         }
         if (envelope.isReceipt()) {
             final var senderPair = getSender(envelope, content);
@@ -195,8 +195,8 @@ public final class IncomingMessageHandler {
             }
             handler.handleMessage(MessageEnvelope.from(envelope,
                     content,
-                    account.getRecipientStore(),
-                    account.getRecipientStore()::resolveRecipientAddress,
+                    account.getRecipientResolver(),
+                    account.getRecipientAddressResolver(),
                     context.getAttachmentHelper()::getAttachmentFile,
                     exception), exception);
             return actions;
@@ -391,7 +391,7 @@ public final class IncomingMessageHandler {
         if (syncMessage.getVerified().isPresent()) {
             final var verifiedMessage = syncMessage.getVerified().get();
             account.getIdentityKeyStore()
-                    .setIdentityTrustLevel(account.getRecipientStore()
+                    .setIdentityTrustLevel(account.getRecipientTrustedResolver()
                                     .resolveRecipientTrusted(verifiedMessage.getDestination()),
                             verifiedMessage.getIdentityKey(),
                             TrustLevel.fromVerifiedState(verifiedMessage.getVerified()));
index cc01dc73bb822e2903ddc5d4a6c0a5f7798a0a05..387882780229b84cf4907a38f500f7471e0797be 100644 (file)
@@ -289,7 +289,7 @@ public final class ProfileHelper {
         var profile = account.getProfileStore().getProfile(recipientId);
         if (profile == null || !Objects.equals(avatarPath, profile.getAvatarUrlPath())) {
             logger.trace("Downloading profile avatar for {}", recipientId);
-            downloadProfileAvatar(account.getRecipientStore().resolveRecipientAddress(recipientId),
+            downloadProfileAvatar(account.getRecipientAddressResolver().resolveRecipientAddress(recipientId),
                     avatarPath,
                     profileKey);
             var builder = profile == null ? Profile.newBuilder() : Profile.newBuilder(profile);
index 7bc2c224052362d826438edd502d29dc44d79eea..7083caaeb73b4dbdbc8548eacce41376309a4866 100644 (file)
@@ -141,7 +141,7 @@ public class ReceiveHelper {
                 isWaitingForMessage = true;
                 var result = signalWebSocket.readOrEmpty(timeout.toMillis(), envelope1 -> {
                     isWaitingForMessage = false;
-                    final var recipientId = envelope1.hasSourceUuid() ? account.getRecipientStore()
+                    final var recipientId = envelope1.hasSourceUuid() ? account.getRecipientResolver()
                             .resolveRecipient(envelope1.getSourceAddress()) : null;
                     logger.trace("Storing new message from {}", recipientId);
                     // store message on disk, before acknowledging receipt to the server
@@ -211,7 +211,7 @@ public class ReceiveHelper {
                 if (exception instanceof UntrustedIdentityException) {
                     logger.debug("Keeping message with untrusted identity in message cache");
                     final var address = ((UntrustedIdentityException) exception).getSender();
-                    final var recipientId = account.getRecipientStore().resolveRecipient(address);
+                    final var recipientId = account.getRecipientResolver().resolveRecipient(address);
                     if (!envelope.hasSourceUuid()) {
                         try {
                             cachedMessage[0] = account.getMessageCache().replaceSender(cachedMessage[0], recipientId);
@@ -260,7 +260,7 @@ public class ReceiveHelper {
             }
             if (!envelope.hasSourceUuid()) {
                 final var identifier = ((UntrustedIdentityException) exception).getSender();
-                final var recipientId = account.getRecipientStore().resolveRecipient(identifier);
+                final var recipientId = account.getRecipientResolver().resolveRecipient(identifier);
                 try {
                     account.getMessageCache().replaceSender(cachedMessage, recipientId);
                 } catch (IOException ioException) {
index c253d602bd8a7d11503cf17ea31ef1a3df6b5e58..2f254b5dcf3bef08f3e587d5673c128bbb90b427 100644 (file)
@@ -40,7 +40,7 @@ public class RecipientHelper {
     }
 
     public SignalServiceAddress resolveSignalServiceAddress(RecipientId recipientId) {
-        final var address = account.getRecipientStore().resolveRecipientAddress(recipientId);
+        final var address = account.getRecipientAddressResolver().resolveRecipientAddress(recipientId);
         if (address.number().isEmpty() || address.uuid().isPresent()) {
             return address.toSignalServiceAddress();
         }
@@ -60,13 +60,13 @@ public class RecipientHelper {
             // Return SignalServiceAddress with unknown UUID
             return address.toSignalServiceAddress();
         }
-        return account.getRecipientStore()
-                .resolveRecipientAddress(account.getRecipientStore().resolveRecipient(aci))
+        return account.getRecipientAddressResolver()
+                .resolveRecipientAddress(account.getRecipientResolver().resolveRecipient(aci))
                 .toSignalServiceAddress();
     }
 
     public RecipientId resolveRecipient(final SignalServiceAddress address) {
-        return account.getRecipientStore().resolveRecipient(address);
+        return account.getRecipientResolver().resolveRecipient(address);
     }
 
     public Set<RecipientId> resolveRecipients(Collection<RecipientIdentifier.Single> recipients) throws UnregisteredRecipientException {
@@ -80,7 +80,7 @@ public class RecipientHelper {
 
     public RecipientId resolveRecipient(final RecipientIdentifier.Single recipient) throws UnregisteredRecipientException {
         if (recipient instanceof RecipientIdentifier.Uuid uuidRecipient) {
-            return account.getRecipientStore().resolveRecipient(ServiceId.from(uuidRecipient.uuid()));
+            return account.getRecipientResolver().resolveRecipient(ServiceId.from(uuidRecipient.uuid()));
         } else {
             final var number = ((RecipientIdentifier.Number) recipient).number();
             return account.getRecipientStore().resolveRecipient(number, () -> {
@@ -100,7 +100,7 @@ public class RecipientHelper {
         }
         final var number = address.getNumber().get();
         final var uuid = getRegisteredUser(number);
-        return account.getRecipientStore().resolveRecipientTrusted(new SignalServiceAddress(uuid, number));
+        return account.getRecipientTrustedResolver().resolveRecipientTrusted(new SignalServiceAddress(uuid, number));
     }
 
     public Map<String, ACI> getRegisteredUsers(final Set<String> numbers) throws IOException {
@@ -116,7 +116,7 @@ public class RecipientHelper {
         }
 
         // Store numbers as recipients, so we have the number/uuid association
-        registeredUsers.forEach((number, aci) -> account.getRecipientStore()
+        registeredUsers.forEach((number, aci) -> account.getRecipientTrustedResolver()
                 .resolveRecipientTrusted(new SignalServiceAddress(aci, number)));
 
         return registeredUsers;
index 8b2a054efbb1f8edab75cf914102a4788099c1a8..85d5cc32546883db6bd5019500c4630578d02293 100644 (file)
@@ -656,12 +656,12 @@ public class SendHelper {
     private void handleSendMessageResult(final SendMessageResult r) {
         if (r.isSuccess() && !r.getSuccess().isUnidentified()) {
             final var recipientId = context.getRecipientHelper().resolveRecipient(r.getAddress());
-            final var profile = account.getRecipientStore().getProfile(recipientId);
+            final var profile = account.getProfileStore().getProfile(recipientId);
             if (profile != null && (
                     profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.ENABLED
                             || profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.UNRESTRICTED
             )) {
-                account.getRecipientStore()
+                account.getProfileStore()
                         .storeProfile(recipientId,
                                 Profile.newBuilder(profile)
                                         .withUnidentifiedAccessMode(Profile.UnidentifiedAccessMode.UNKNOWN)
@@ -670,12 +670,12 @@ public class SendHelper {
         }
         if (r.isUnregisteredFailure()) {
             final var recipientId = context.getRecipientHelper().resolveRecipient(r.getAddress());
-            final var profile = account.getRecipientStore().getProfile(recipientId);
+            final var profile = account.getProfileStore().getProfile(recipientId);
             if (profile != null && (
                     profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.ENABLED
                             || profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.UNRESTRICTED
             )) {
-                account.getRecipientStore()
+                account.getProfileStore()
                         .storeProfile(recipientId,
                                 Profile.newBuilder(profile)
                                         .withUnidentifiedAccessMode(Profile.UnidentifiedAccessMode.UNKNOWN)
index 88fe84b90c72b654f5e0aadcf9d3f7dd02b13262..b1a653fd7aa5b19e9758355e712ab33a9a42ec37 100644 (file)
@@ -86,7 +86,7 @@ public class StorageHelper {
         final var contactRecord = record.getContact().get();
         final var address = contactRecord.getAddress();
 
-        final var recipientId = account.getRecipientStore().resolveRecipient(address);
+        final var recipientId = account.getRecipientResolver().resolveRecipient(address);
         final var contact = account.getContactStore().getContact(recipientId);
         final var blocked = contact != null && contact.isBlocked();
         final var profileShared = contact != null && contact.isProfileSharingEnabled();
index 86fb0e66a603aec711dc6da38c1d9a69b51c30f2..d98f9eef7006c12ea77f1c0bb5b8014430150261 100644 (file)
@@ -257,7 +257,7 @@ public class SyncHelper {
             if (c.getAddress().matches(account.getSelfAddress()) && c.getProfileKey().isPresent()) {
                 account.setProfileKey(c.getProfileKey().get());
             }
-            final var recipientId = account.getRecipientStore().resolveRecipientTrusted(c.getAddress());
+            final var recipientId = account.getRecipientTrustedResolver().resolveRecipientTrusted(c.getAddress());
             var contact = account.getContactStore().getContact(recipientId);
             final var builder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
             if (c.getName().isPresent()) {
@@ -272,7 +272,7 @@ public class SyncHelper {
             if (c.getVerified().isPresent()) {
                 final var verifiedMessage = c.getVerified().get();
                 account.getIdentityKeyStore()
-                        .setIdentityTrustLevel(account.getRecipientStore()
+                        .setIdentityTrustLevel(account.getRecipientTrustedResolver()
                                         .resolveRecipientTrusted(verifiedMessage.getDestination()),
                                 verifiedMessage.getIdentityKey(),
                                 TrustLevel.fromVerifiedState(verifiedMessage.getVerified()));
index ac41d791f11877fd8c731ee7582bc7d019ecee3a..521e21d9152ddae129b72020c1b965f42240dccc 100644 (file)
@@ -7,6 +7,7 @@ import org.asamk.signal.manager.api.Pair;
 import org.asamk.signal.manager.api.TrustLevel;
 import org.asamk.signal.manager.config.ServiceEnvironment;
 import org.asamk.signal.manager.groups.GroupId;
+import org.asamk.signal.manager.helper.RecipientAddressResolver;
 import org.asamk.signal.manager.storage.configuration.ConfigurationStore;
 import org.asamk.signal.manager.storage.contacts.ContactsStore;
 import org.asamk.signal.manager.storage.contacts.LegacyJsonContactsStore;
@@ -27,7 +28,9 @@ import org.asamk.signal.manager.storage.recipients.LegacyRecipientStore;
 import org.asamk.signal.manager.storage.recipients.Profile;
 import org.asamk.signal.manager.storage.recipients.RecipientAddress;
 import org.asamk.signal.manager.storage.recipients.RecipientId;
+import org.asamk.signal.manager.storage.recipients.RecipientResolver;
 import org.asamk.signal.manager.storage.recipients.RecipientStore;
+import org.asamk.signal.manager.storage.recipients.RecipientTrustedResolver;
 import org.asamk.signal.manager.storage.sendLog.MessageSendLogStore;
 import org.asamk.signal.manager.storage.senderKeys.SenderKeyStore;
 import org.asamk.signal.manager.storage.sessions.SessionStore;
@@ -201,7 +204,7 @@ public class SignalAccount implements Closeable {
         signalAccount.localRegistrationId = registrationId;
         signalAccount.trustNewIdentity = trustNewIdentity;
         signalAccount.groupStore = new GroupStore(getGroupCachePath(dataPath, accountPath),
-                signalAccount.getRecipientStore(),
+                signalAccount.getRecipientResolver(),
                 signalAccount::saveGroupStore);
         signalAccount.stickerStore = new StickerStore(signalAccount::saveStickerStore);
         signalAccount.configurationStore = new ConfigurationStore(signalAccount::saveConfigurationStore);
@@ -260,7 +263,8 @@ public class SignalAccount implements Closeable {
                 aciIdentityKey,
                 pniIdentityKey,
                 profileKey);
-        signalAccount.getRecipientStore().resolveSelfRecipientTrusted(signalAccount.getSelfRecipientAddress());
+        signalAccount.getRecipientTrustedResolver()
+                .resolveSelfRecipientTrusted(signalAccount.getSelfRecipientAddress());
         signalAccount.getSessionStore().archiveAllSessions();
         signalAccount.getSenderKeyStore().deleteAll();
         signalAccount.clearAllPreKeys();
@@ -321,12 +325,13 @@ public class SignalAccount implements Closeable {
         signalAccount.localRegistrationId = registrationId;
         signalAccount.trustNewIdentity = trustNewIdentity;
         signalAccount.groupStore = new GroupStore(getGroupCachePath(dataPath, accountPath),
-                signalAccount.getRecipientStore(),
+                signalAccount.getRecipientResolver(),
                 signalAccount::saveGroupStore);
         signalAccount.stickerStore = new StickerStore(signalAccount::saveStickerStore);
         signalAccount.configurationStore = new ConfigurationStore(signalAccount::saveConfigurationStore);
 
-        signalAccount.getRecipientStore().resolveSelfRecipientTrusted(signalAccount.getSelfRecipientAddress());
+        signalAccount.getRecipientTrustedResolver()
+                .resolveSelfRecipientTrusted(signalAccount.getSelfRecipientAddress());
         signalAccount.previousStorageVersion = CURRENT_STORAGE_VERSION;
         signalAccount.migrateLegacyConfigs();
         signalAccount.clearAllPreKeys();
@@ -608,11 +613,11 @@ public class SignalAccount implements Closeable {
             groupStoreStorage = jsonProcessor.convertValue(rootNode.get("groupStore"), GroupStore.Storage.class);
             groupStore = GroupStore.fromStorage(groupStoreStorage,
                     getGroupCachePath(dataPath, accountPath),
-                    getRecipientStore(),
+                    getRecipientResolver(),
                     this::saveGroupStore);
         } else {
             groupStore = new GroupStore(getGroupCachePath(dataPath, accountPath),
-                    getRecipientStore(),
+                    getRecipientResolver(),
                     this::saveGroupStore);
         }
 
@@ -650,7 +655,7 @@ public class SignalAccount implements Closeable {
             if (legacyRecipientStore != null) {
                 getRecipientStore().resolveRecipientsTrusted(legacyRecipientStore.getAddresses());
             }
-            getRecipientStore().resolveSelfRecipientTrusted(getSelfRecipientAddress());
+            getRecipientTrustedResolver().resolveSelfRecipientTrusted(getSelfRecipientAddress());
             migrated = true;
         }
 
@@ -710,7 +715,7 @@ public class SignalAccount implements Closeable {
             final var contactStore = jsonProcessor.convertValue(contactStoreNode, LegacyJsonContactsStore.class);
             for (var contact : contactStore.getContacts()) {
                 final var recipientId = getRecipientStore().resolveRecipientTrusted(contact.getAddress());
-                getRecipientStore().storeContact(recipientId,
+                getContactStore().storeContact(recipientId,
                         new Contact(contact.name,
                                 contact.color,
                                 contact.messageExpirationTime,
@@ -738,9 +743,9 @@ public class SignalAccount implements Closeable {
             var profileStoreNode = rootNode.get("profileStore");
             final var legacyProfileStore = jsonProcessor.convertValue(profileStoreNode, LegacyProfileStore.class);
             for (var profileEntry : legacyProfileStore.getProfileEntries()) {
-                var recipientId = getRecipientStore().resolveRecipient(profileEntry.getAddress());
-                getRecipientStore().storeProfileKeyCredential(recipientId, profileEntry.getProfileKeyCredential());
-                getRecipientStore().storeProfileKey(recipientId, profileEntry.getProfileKey());
+                var recipientId = getRecipientResolver().resolveRecipient(profileEntry.getAddress());
+                getProfileStore().storeProfileKeyCredential(recipientId, profileEntry.getProfileKeyCredential());
+                getProfileStore().storeProfileKey(recipientId, profileEntry.getProfileKey());
                 final var profile = profileEntry.getProfile();
                 if (profile != null) {
                     final var capabilities = new HashSet<Profile.Capability>();
@@ -765,7 +770,7 @@ public class SignalAccount implements Closeable {
                                             ? Profile.UnidentifiedAccessMode.ENABLED
                                             : Profile.UnidentifiedAccessMode.DISABLED,
                             capabilities);
-                    getRecipientStore().storeProfile(recipientId, newProfile);
+                    getProfileStore().storeProfile(recipientId, newProfile);
                 }
             }
         }
@@ -784,10 +789,10 @@ public class SignalAccount implements Closeable {
                 }
                 try {
                     if (UuidUtil.isUuid(thread.id) || thread.id.startsWith("+")) {
-                        final var recipientId = getRecipientStore().resolveRecipient(thread.id);
-                        var contact = getRecipientStore().getContact(recipientId);
+                        final var recipientId = getRecipientResolver().resolveRecipient(thread.id);
+                        var contact = getContactStore().getContact(recipientId);
                         if (contact != null) {
-                            getRecipientStore().storeContact(recipientId,
+                            getContactStore().storeContact(recipientId,
                                     Contact.newBuilder(contact)
                                             .withMessageExpirationTime(thread.messageExpirationTime)
                                             .build());
@@ -1028,13 +1033,13 @@ public class SignalAccount implements Closeable {
 
     public SessionStore getSessionStore() {
         return getOrCreate(() -> sessionStore,
-                () -> sessionStore = new SessionStore(getSessionsPath(dataPath, accountPath), getRecipientStore()));
+                () -> sessionStore = new SessionStore(getSessionsPath(dataPath, accountPath), getRecipientResolver()));
     }
 
     public IdentityKeyStore getIdentityKeyStore() {
         return getOrCreate(() -> identityKeyStore,
                 () -> identityKeyStore = new IdentityKeyStore(getIdentitiesPath(dataPath, accountPath),
-                        getRecipientStore(),
+                        getRecipientResolver(),
                         aciIdentityKeyPair,
                         localRegistrationId,
                         trustNewIdentity));
@@ -1048,6 +1053,18 @@ public class SignalAccount implements Closeable {
         return getRecipientStore();
     }
 
+    public RecipientResolver getRecipientResolver() {
+        return getRecipientStore();
+    }
+
+    public RecipientTrustedResolver getRecipientTrustedResolver() {
+        return getRecipientStore();
+    }
+
+    public RecipientAddressResolver getRecipientAddressResolver() {
+        return getRecipientStore()::resolveRecipientAddress;
+    }
+
     public RecipientStore getRecipientStore() {
         return getOrCreate(() -> recipientStore,
                 () -> recipientStore = RecipientStore.load(getRecipientsStoreFile(dataPath, accountPath),
@@ -1067,8 +1084,8 @@ public class SignalAccount implements Closeable {
         return getOrCreate(() -> senderKeyStore,
                 () -> senderKeyStore = new SenderKeyStore(getSharedSenderKeysFile(dataPath, accountPath),
                         getSenderKeysPath(dataPath, accountPath),
-                        getRecipientStore()::resolveRecipientAddress,
-                        getRecipientStore()));
+                        getRecipientAddressResolver(),
+                        getRecipientResolver()));
     }
 
     public ConfigurationStore getConfigurationStore() {
@@ -1092,7 +1109,7 @@ public class SignalAccount implements Closeable {
 
     public MessageSendLogStore getMessageSendLogStore() {
         return getOrCreate(() -> messageSendLogStore,
-                () -> messageSendLogStore = new MessageSendLogStore(getRecipientStore(), getAccountDatabase()));
+                () -> messageSendLogStore = new MessageSendLogStore(getRecipientResolver(), getAccountDatabase()));
     }
 
     public CredentialsProvider getCredentialsProvider() {
@@ -1169,7 +1186,7 @@ public class SignalAccount implements Closeable {
     }
 
     public RecipientId getSelfRecipientId() {
-        return getRecipientStore().resolveRecipient(getSelfRecipientAddress());
+        return getRecipientResolver().resolveRecipient(getSelfRecipientAddress());
     }
 
     public byte[] getEncryptedDeviceName() {
@@ -1337,7 +1354,7 @@ public class SignalAccount implements Closeable {
         clearAllPreKeys();
         getSessionStore().archiveAllSessions();
         getSenderKeyStore().deleteAll();
-        final var recipientId = getRecipientStore().resolveSelfRecipientTrusted(getSelfRecipientAddress());
+        final var recipientId = getRecipientTrustedResolver().resolveSelfRecipientTrusted(getSelfRecipientAddress());
         final var publicKey = getAciIdentityKeyPair().getPublicKey();
         getIdentityKeyStore().saveIdentity(recipientId, publicKey, new Date());
         getIdentityKeyStore().setIdentityTrustLevel(recipientId, publicKey, TrustLevel.TRUSTED_VERIFIED);
index 0297f6d7d290b93ae29529f14a0a1a95e1ee6c67..d2cc94d6a6a9a0a997c67c25d5cea7174f9a4e73 100644 (file)
@@ -37,7 +37,7 @@ import java.util.UUID;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
-public class RecipientStore implements RecipientResolver, ContactsStore, ProfileStore {
+public class RecipientStore implements RecipientResolver, RecipientTrustedResolver, ContactsStore, ProfileStore {
 
     private final static Logger logger = LoggerFactory.getLogger(RecipientStore.class);
 
@@ -224,6 +224,7 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
         return resolveRecipient(new RecipientAddress(address), false, false);
     }
 
+    @Override
     public RecipientId resolveSelfRecipientTrusted(RecipientAddress address) {
         return resolveRecipient(address, true, true);
     }
@@ -232,6 +233,7 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
         return resolveRecipient(address, true, false);
     }
 
+    @Override
     public RecipientId resolveRecipientTrusted(SignalServiceAddress address) {
         return resolveRecipient(new RecipientAddress(address), true, false);
     }
diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientTrustedResolver.java b/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientTrustedResolver.java
new file mode 100644 (file)
index 0000000..0bc522e
--- /dev/null
@@ -0,0 +1,10 @@
+package org.asamk.signal.manager.storage.recipients;
+
+import org.whispersystems.signalservice.api.push.SignalServiceAddress;
+
+public interface RecipientTrustedResolver {
+
+    RecipientId resolveSelfRecipientTrusted(RecipientAddress address);
+
+    RecipientId resolveRecipientTrusted(SignalServiceAddress address);
+}