]> nmode's Git Repositories - signal-cli/commitdiff
Use RecipientAddress in AvatarStore
authorAsamK <asamk@gmx.de>
Sun, 6 Feb 2022 10:13:01 +0000 (11:13 +0100)
committerAsamK <asamk@gmx.de>
Sun, 6 Feb 2022 11:29:47 +0000 (12:29 +0100)
graalvm-config-dir/reflect-config.json
lib/src/main/java/org/asamk/signal/manager/AvatarStore.java
lib/src/main/java/org/asamk/signal/manager/helper/ProfileHelper.java
lib/src/main/java/org/asamk/signal/manager/helper/SyncHelper.java
lib/src/main/java/org/asamk/signal/manager/storage/SignalAccount.java

index 50d3c5d1f6a48384bd08bedc701cfea854d1bf0f..56351226109a0d6352820316f18fe30578c69a7f 100644 (file)
   "name":"sun.security.x509.CRLDistributionPointsExtension",
   "methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
 },
   "name":"sun.security.x509.CRLDistributionPointsExtension",
   "methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
 },
+{
+  "name":"sun.security.x509.ExtendedKeyUsageExtension",
+  "methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
+},
 {
   "name":"sun.security.x509.KeyUsageExtension",
   "methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
 {
   "name":"sun.security.x509.KeyUsageExtension",
   "methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
index bfeef7259708551c13e37143c1c138c33f404514..b4bd188c04e919a5afd3bef44584c075f285edcc 100644 (file)
@@ -1,9 +1,9 @@
 package org.asamk.signal.manager;
 
 import org.asamk.signal.manager.groups.GroupId;
 package org.asamk.signal.manager;
 
 import org.asamk.signal.manager.groups.GroupId;
+import org.asamk.signal.manager.storage.recipients.RecipientAddress;
 import org.asamk.signal.manager.util.IOUtils;
 import org.asamk.signal.manager.util.Utils;
 import org.asamk.signal.manager.util.IOUtils;
 import org.asamk.signal.manager.util.Utils;
-import org.whispersystems.signalservice.api.push.SignalServiceAddress;
 import org.whispersystems.signalservice.api.util.StreamDetails;
 
 import java.io.File;
 import org.whispersystems.signalservice.api.util.StreamDetails;
 
 import java.io.File;
@@ -20,11 +20,11 @@ public class AvatarStore {
         this.avatarsPath = avatarsPath;
     }
 
         this.avatarsPath = avatarsPath;
     }
 
-    public StreamDetails retrieveContactAvatar(SignalServiceAddress address) throws IOException {
+    public StreamDetails retrieveContactAvatar(RecipientAddress address) throws IOException {
         return retrieveAvatar(getContactAvatarFile(address));
     }
 
         return retrieveAvatar(getContactAvatarFile(address));
     }
 
-    public StreamDetails retrieveProfileAvatar(SignalServiceAddress address) throws IOException {
+    public StreamDetails retrieveProfileAvatar(RecipientAddress address) throws IOException {
         return retrieveAvatar(getProfileAvatarFile(address));
     }
 
         return retrieveAvatar(getProfileAvatarFile(address));
     }
 
@@ -33,11 +33,11 @@ public class AvatarStore {
         return retrieveAvatar(groupAvatarFile);
     }
 
         return retrieveAvatar(groupAvatarFile);
     }
 
-    public void storeContactAvatar(SignalServiceAddress address, AvatarStorer storer) throws IOException {
+    public void storeContactAvatar(RecipientAddress address, AvatarStorer storer) throws IOException {
         storeAvatar(getContactAvatarFile(address), storer);
     }
 
         storeAvatar(getContactAvatarFile(address), storer);
     }
 
-    public void storeProfileAvatar(SignalServiceAddress address, AvatarStorer storer) throws IOException {
+    public void storeProfileAvatar(RecipientAddress address, AvatarStorer storer) throws IOException {
         storeAvatar(getProfileAvatarFile(address), storer);
     }
 
         storeAvatar(getProfileAvatarFile(address), storer);
     }
 
@@ -45,7 +45,7 @@ public class AvatarStore {
         storeAvatar(getGroupAvatarFile(groupId), storer);
     }
 
         storeAvatar(getGroupAvatarFile(groupId), storer);
     }
 
-    public void deleteProfileAvatar(SignalServiceAddress address) throws IOException {
+    public void deleteProfileAvatar(RecipientAddress address) throws IOException {
         deleteAvatar(getProfileAvatarFile(address));
     }
 
         deleteAvatar(getProfileAvatarFile(address));
     }
 
@@ -77,16 +77,12 @@ public class AvatarStore {
         return new File(avatarsPath, "group-" + groupId.toBase64().replace("/", "_"));
     }
 
         return new File(avatarsPath, "group-" + groupId.toBase64().replace("/", "_"));
     }
 
-    private File getContactAvatarFile(SignalServiceAddress address) {
-        return new File(avatarsPath, "contact-" + getLegacyIdentifier(address));
+    private File getContactAvatarFile(RecipientAddress address) {
+        return new File(avatarsPath, "contact-" + address.getLegacyIdentifier());
     }
 
     }
 
-    private String getLegacyIdentifier(final SignalServiceAddress address) {
-        return address.getNumber().or(() -> address.getAci().toString());
-    }
-
-    private File getProfileAvatarFile(SignalServiceAddress address) {
-        return new File(avatarsPath, "profile-" + getLegacyIdentifier(address));
+    private File getProfileAvatarFile(RecipientAddress address) {
+        return new File(avatarsPath, "profile-" + address.getLegacyIdentifier());
     }
 
     private void createAvatarsDir() throws IOException {
     }
 
     private void createAvatarsDir() throws IOException {
index f1f5d1de875e99b1aae99dd6351dfe4807c85a12..ec4d385e1e9effd65403c380cba77dcec1042b42 100644 (file)
@@ -4,6 +4,7 @@ import org.asamk.signal.manager.SignalDependencies;
 import org.asamk.signal.manager.config.ServiceConfig;
 import org.asamk.signal.manager.storage.SignalAccount;
 import org.asamk.signal.manager.storage.recipients.Profile;
 import org.asamk.signal.manager.config.ServiceConfig;
 import org.asamk.signal.manager.storage.SignalAccount;
 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.util.IOUtils;
 import org.asamk.signal.manager.util.ProfileUtils;
 import org.asamk.signal.manager.storage.recipients.RecipientId;
 import org.asamk.signal.manager.util.IOUtils;
 import org.asamk.signal.manager.util.ProfileUtils;
@@ -131,7 +132,7 @@ public final class ProfileHelper {
         if (uploadProfile) {
             try (final var streamDetails = avatar == null
                     ? context.getAvatarStore()
         if (uploadProfile) {
             try (final var streamDetails = avatar == null
                     ? context.getAvatarStore()
-                    .retrieveProfileAvatar(account.getSelfAddress())
+                    .retrieveProfileAvatar(account.getSelfRecipientAddress())
                     : avatar.isPresent() ? Utils.createStreamDetailsFromFile(avatar.get()) : null) {
                 final var avatarPath = dependencies.getAccountManager()
                         .setVersionedProfile(account.getAci(),
                     : avatar.isPresent() ? Utils.createStreamDetailsFromFile(avatar.get()) : null) {
                 final var avatarPath = dependencies.getAccountManager()
                         .setVersionedProfile(account.getAci(),
@@ -150,10 +151,10 @@ public final class ProfileHelper {
         if (avatar != null) {
             if (avatar.isPresent()) {
                 context.getAvatarStore()
         if (avatar != null) {
             if (avatar.isPresent()) {
                 context.getAvatarStore()
-                        .storeProfileAvatar(account.getSelfAddress(),
+                        .storeProfileAvatar(account.getSelfRecipientAddress(),
                                 outputStream -> IOUtils.copyFileToStream(avatar.get(), outputStream));
             } else {
                                 outputStream -> IOUtils.copyFileToStream(avatar.get(), outputStream));
             } else {
-                context.getAvatarStore().deleteProfileAvatar(account.getSelfAddress());
+                context.getAvatarStore().deleteProfileAvatar(account.getSelfRecipientAddress());
             }
         }
         account.getProfileStore().storeProfile(account.getSelfRecipientId(), newProfile);
             }
         }
         account.getProfileStore().storeProfile(account.getSelfRecipientId(), newProfile);
@@ -219,7 +220,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);
         var profile = account.getProfileStore().getProfile(recipientId);
         if (profile == null || !Objects.equals(avatarPath, profile.getAvatarUrlPath())) {
             logger.trace("Downloading profile avatar for {}", recipientId);
-            downloadProfileAvatar(context.getRecipientHelper().resolveSignalServiceAddress(recipientId),
+            downloadProfileAvatar(account.getRecipientStore().resolveRecipientAddress(recipientId),
                     avatarPath,
                     profileKey);
             var builder = profile == null ? Profile.newBuilder() : Profile.newBuilder(profile);
                     avatarPath,
                     profileKey);
             var builder = profile == null ? Profile.newBuilder() : Profile.newBuilder(profile);
@@ -330,7 +331,7 @@ public final class ProfileHelper {
     }
 
     private void downloadProfileAvatar(
     }
 
     private void downloadProfileAvatar(
-            SignalServiceAddress address, String avatarPath, ProfileKey profileKey
+            RecipientAddress address, String avatarPath, ProfileKey profileKey
     ) {
         if (avatarPath == null) {
             try {
     ) {
         if (avatarPath == null) {
             try {
index 01726cb0036f7851eee68855c5eaf601a35dc345..75bd296d24713eed640025ccb85e7cba810e2b4f 100644 (file)
@@ -4,6 +4,7 @@ import org.asamk.signal.manager.TrustLevel;
 import org.asamk.signal.manager.storage.SignalAccount;
 import org.asamk.signal.manager.storage.groups.GroupInfoV1;
 import org.asamk.signal.manager.storage.recipients.Contact;
 import org.asamk.signal.manager.storage.SignalAccount;
 import org.asamk.signal.manager.storage.groups.GroupInfoV1;
 import org.asamk.signal.manager.storage.recipients.Contact;
+import org.asamk.signal.manager.storage.recipients.RecipientAddress;
 import org.asamk.signal.manager.util.AttachmentUtils;
 import org.asamk.signal.manager.util.IOUtils;
 import org.slf4j.Logger;
 import org.asamk.signal.manager.util.AttachmentUtils;
 import org.asamk.signal.manager.util.IOUtils;
 import org.slf4j.Logger;
@@ -128,7 +129,7 @@ public class SyncHelper {
                     var profileKey = account.getProfileStore().getProfileKey(recipientId);
                     out.write(new DeviceContact(address,
                             Optional.fromNullable(contact.getName()),
                     var profileKey = account.getProfileStore().getProfileKey(recipientId);
                     out.write(new DeviceContact(address,
                             Optional.fromNullable(contact.getName()),
-                            createContactAvatarAttachment(address),
+                            createContactAvatarAttachment(new RecipientAddress(address)),
                             Optional.fromNullable(contact.getColor()),
                             Optional.fromNullable(verifiedMessage),
                             Optional.fromNullable(profileKey),
                             Optional.fromNullable(contact.getColor()),
                             Optional.fromNullable(verifiedMessage),
                             Optional.fromNullable(profileKey),
@@ -264,7 +265,7 @@ public class SyncHelper {
             account.getContactStore().storeContact(recipientId, builder.build());
 
             if (c.getAvatar().isPresent()) {
             account.getContactStore().storeContact(recipientId, builder.build());
 
             if (c.getAvatar().isPresent()) {
-                downloadContactAvatar(c.getAvatar().get(), c.getAddress());
+                downloadContactAvatar(c.getAvatar().get(), new RecipientAddress(c.getAddress()));
             }
         }
     }
             }
         }
     }
@@ -309,7 +310,7 @@ public class SyncHelper {
         context.getSendHelper().sendSyncMessage(message);
     }
 
         context.getSendHelper().sendSyncMessage(message);
     }
 
-    private Optional<SignalServiceAttachmentStream> createContactAvatarAttachment(SignalServiceAddress address) throws IOException {
+    private Optional<SignalServiceAttachmentStream> createContactAvatarAttachment(RecipientAddress address) throws IOException {
         final var streamDetails = context.getAvatarStore().retrieveContactAvatar(address);
         if (streamDetails == null) {
             return Optional.absent();
         final var streamDetails = context.getAvatarStore().retrieveContactAvatar(address);
         if (streamDetails == null) {
             return Optional.absent();
@@ -318,7 +319,7 @@ public class SyncHelper {
         return Optional.of(AttachmentUtils.createAttachment(streamDetails, Optional.absent()));
     }
 
         return Optional.of(AttachmentUtils.createAttachment(streamDetails, Optional.absent()));
     }
 
-    private void downloadContactAvatar(SignalServiceAttachment avatar, SignalServiceAddress address) {
+    private void downloadContactAvatar(SignalServiceAttachment avatar, RecipientAddress address) {
         try {
             context.getAvatarStore()
                     .storeContactAvatar(address,
         try {
             context.getAvatarStore()
                     .storeContactAvatar(address,
index f0cdba2b8424bdd0818a2c2b85e5558da6b72c29..250bd36c58437357d666d5e0fb73496a1b59dc75 100644 (file)
@@ -554,7 +554,7 @@ public class SignalAccount implements Closeable {
             if (legacyRecipientStore != null) {
                 getRecipientStore().resolveRecipientsTrusted(legacyRecipientStore.getAddresses());
             }
             if (legacyRecipientStore != null) {
                 getRecipientStore().resolveRecipientsTrusted(legacyRecipientStore.getAddresses());
             }
-            getSelfRecipientId();
+            getRecipientStore().resolveRecipientTrusted(getSelfRecipientAddress());
             migrated = true;
         }
 
             migrated = true;
         }
 
@@ -914,9 +914,12 @@ public class SignalAccount implements Closeable {
         return new SignalServiceAddress(aci, account);
     }
 
         return new SignalServiceAddress(aci, account);
     }
 
+    public RecipientAddress getSelfRecipientAddress() {
+        return new RecipientAddress(aci == null ? null : aci.uuid(), account);
+    }
+
     public RecipientId getSelfRecipientId() {
     public RecipientId getSelfRecipientId() {
-        return getRecipientStore().resolveRecipientTrusted(new RecipientAddress(aci == null ? null : aci.uuid(),
-                account));
+        return getRecipientStore().resolveRecipient(getSelfRecipientAddress());
     }
 
     public String getEncryptedDeviceName() {
     }
 
     public String getEncryptedDeviceName() {