]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/helper/ProfileHelper.java
Update libsignal-service
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / helper / ProfileHelper.java
index 184eac6b26711af917ea941092e478d6d04fbe33..af16ed1d92b38b192f8984c6c7d41c5ea90e922c 100644 (file)
@@ -23,6 +23,7 @@ import org.signal.libsignal.zkgroup.profiles.ExpiringProfileKeyCredential;
 import org.signal.libsignal.zkgroup.profiles.ProfileKey;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.whispersystems.signalservice.api.NetworkResultUtil;
 import org.whispersystems.signalservice.api.crypto.SealedSenderAccess;
 import org.whispersystems.signalservice.api.profiles.AvatarUploadParams;
 import org.whispersystems.signalservice.api.profiles.ProfileAndCredential;
@@ -196,9 +197,10 @@ public final class ProfileHelper {
                         : avatar == null ? AvatarUploadParams.unchanged(true) : AvatarUploadParams.unchanged(false);
                 final var paymentsAddress = Optional.ofNullable(newProfile.getMobileCoinAddress())
                         .map(address -> PaymentUtils.signPaymentsAddress(address,
-                                account.getAciIdentityKeyPair().getPrivateKey()));
+                                account.getAciIdentityKeyPair().getPrivateKey()))
+                        .orElse(null);
                 logger.debug("Uploading new profile");
-                final var avatarPath = dependencies.getAccountManager()
+                final var avatarPath = NetworkResultUtil.toSetProfileLegacy(dependencies.getProfileApi()
                         .setVersionedProfile(account.getAci(),
                                 account.getProfileKey(),
                                 newProfile.getInternalServiceName(),
@@ -208,9 +210,9 @@ public final class ProfileHelper {
                                 avatarUploadParams,
                                 List.of(/* TODO implement support for badges */),
                                 account.getConfigurationStore().getPhoneNumberSharingMode()
-                                        == PhoneNumberSharingMode.EVERYBODY);
+                                        == PhoneNumberSharingMode.EVERYBODY));
                 if (!avatarUploadParams.keepTheSame) {
-                    builder.withAvatarUrlPath(avatarPath.orElse(null));
+                    builder.withAvatarUrlPath(avatarPath);
                 }
                 newProfile = builder.build();
             }
@@ -336,13 +338,6 @@ public final class ProfileHelper {
 
             final var profile = account.getProfileStore().getProfile(recipientId);
 
-            if (recipientId.equals(account.getSelfRecipientId())) {
-                final var isUnrestricted = encryptedProfile.isUnrestrictedUnidentifiedAccess();
-                if (account.isUnrestrictedUnidentifiedAccess() != isUnrestricted) {
-                    account.setUnrestrictedUnidentifiedAccess(isUnrestricted);
-                }
-            }
-
             Profile newProfile = null;
             if (profileKey.isPresent()) {
                 logger.trace("Decrypting profile");
@@ -358,6 +353,18 @@ public final class ProfileHelper {
                         .build();
             }
 
+            if (recipientId.equals(account.getSelfRecipientId())) {
+                final var isUnrestricted = encryptedProfile.isUnrestrictedUnidentifiedAccess();
+                if (account.isUnrestrictedUnidentifiedAccess() != isUnrestricted) {
+                    account.setUnrestrictedUnidentifiedAccess(isUnrestricted);
+                }
+                if (account.isPrimaryDevice() && profile != null && newProfile.getCapabilities()
+                        .contains(Profile.Capability.storageServiceEncryptionV2Capability) && !profile.getCapabilities()
+                        .contains(Profile.Capability.storageServiceEncryptionV2Capability)) {
+                    context.getJobExecutor().enqueueJob(new SyncStorageJob(true));
+                }
+            }
+
             try {
                 logger.trace("Storing identity");
                 final var identityKey = new IdentityKey(Base64.getDecoder().decode(encryptedProfile.getIdentityKey()));