]> nmode's Git Repositories - signal-cli/commitdiff
Add --unrestricted-unidentified-sender to updateAccount command
authorAsamK <asamk@gmx.de>
Sat, 13 Jan 2024 15:00:55 +0000 (16:00 +0100)
committerAsamK <asamk@gmx.de>
Sat, 13 Jan 2024 15:00:55 +0000 (16:00 +0100)
CHANGELOG.md
lib/src/main/java/org/asamk/signal/manager/Manager.java
lib/src/main/java/org/asamk/signal/manager/helper/ProfileHelper.java
lib/src/main/java/org/asamk/signal/manager/internal/ManagerImpl.java
lib/src/main/java/org/asamk/signal/manager/storage/SignalAccount.java
man/signal-cli.1.adoc
src/main/java/org/asamk/signal/commands/UpdateAccountCommand.java
src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java
src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java

index 40bb6d37ffd42dda2680fb9d024e7cbaf821137e..4abfc1082f3369c4fdd9d99f72b9cf462030dfc0 100644 (file)
@@ -8,6 +8,7 @@
 - New --hidden parameter for removeContact command
 - New --notify-self parameter for send command, for sending a non-sync message when self is part of the recipients or groups.
   With this parameter sending to the self number (+XXXX) now behaves the same as the --note-to-self parameter.
+- New --unrestricted-unidentified-sender parameter for updateAccount command
 
 ### Improved
 - Better shutdown handling after Ctrl+C and SIGTERM
index 4104a8fb32d147ce50d50172352a14c3b086c26c..6fe1a67f8cbca13a7492cb4bbfa85a03ba5ddefe 100644 (file)
@@ -89,7 +89,7 @@ public interface Manager extends Closeable {
      */
     Map<String, UserStatus> getUserStatus(Set<String> numbers) throws IOException, RateLimitException;
 
-    void updateAccountAttributes(String deviceName) throws IOException;
+    void updateAccountAttributes(String deviceName, Boolean unrestrictedUnidentifiedSender) throws IOException;
 
     Configuration getConfiguration();
 
index d427d0d096e41bf227cbf2eadbe9bf69e0b66f85..ec3ae020ccafc115ee2c9ea7723badebf9262877 100644 (file)
@@ -328,6 +328,13 @@ 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");
index bc801a28d4a1d6a5c44c73996684b6955abddfe4..29f3d2abd79765fb2eff663b8f05d3cb32da6be4 100644 (file)
@@ -277,10 +277,13 @@ public class ManagerImpl implements Manager {
     }
 
     @Override
-    public void updateAccountAttributes(String deviceName) throws IOException {
+    public void updateAccountAttributes(String deviceName, Boolean unrestrictedUnidentifiedSender) throws IOException {
         if (deviceName != null) {
             context.getAccountHelper().setDeviceName(deviceName);
         }
+        if (unrestrictedUnidentifiedSender != null) {
+            account.setUnrestrictedUnidentifiedAccess(unrestrictedUnidentifiedSender);
+        }
         context.getAccountHelper().updateAccountAttributes();
         context.getAccountHelper().checkWhoAmiI();
     }
index b95b86e5bbb59e7992981e3a85a1a67f6a012621..6860e239cd4573a40bd858772aba5c6685c06bf4 100644 (file)
@@ -154,6 +154,10 @@ public class SignalAccount implements Closeable {
     private final KeyValueEntry<Long> storageManifestVersion = new KeyValueEntry<>("storage-manifest-version",
             long.class,
             -1L);
+    private final KeyValueEntry<Boolean> unrestrictedUnidentifiedAccess = new KeyValueEntry<>(
+            "unrestricted-unidentified-access",
+            Boolean.class,
+            false);
     private boolean isMultiDevice = false;
     private boolean registered = false;
 
@@ -1594,8 +1598,11 @@ public class SignalAccount implements Closeable {
     }
 
     public boolean isUnrestrictedUnidentifiedAccess() {
-        final var profile = getProfileStore().getProfile(getSelfRecipientId());
-        return profile != null && profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.UNRESTRICTED;
+        return Boolean.TRUE.equals(getKeyValueStore().getEntry(unrestrictedUnidentifiedAccess));
+    }
+
+    public void setUnrestrictedUnidentifiedAccess(boolean value) {
+        getKeyValueStore().storeEntry(unrestrictedUnidentifiedAccess, value);
     }
 
     public boolean isDiscoverableByPhoneNumber() {
index 4814d28a88f60868edad778d8d9291e63f034010..bd855ab43d19c90f8abcb5f6f6790fb1321d813d 100644 (file)
@@ -147,6 +147,9 @@ Can fix problems with receiving messages.
 *-n* NAME, *--device-name* NAME::
 Set a new device name for the primary or linked device
 
+*--unrestricted-unidentified-sender* {true,false}::
+Enable if anyone should be able to send you unidentified sender messages.
+
 === startChangeNumber
 
 Change an account to a new phone number with SMS or voice verification.
index c729a39a81471c5c2f732eedfcf567055e8e40c5..95c0f4a4be04ceccec16f2d4cd489144478e7e52 100644 (file)
@@ -28,6 +28,10 @@ public class UpdateAccountCommand implements JsonRpcLocalCommand {
     public void attachToSubparser(final Subparser subparser) {
         subparser.help("Update the account attributes on the signal server.");
         subparser.addArgument("-n", "--device-name").help("Specify a name to describe this device.");
+        subparser.addArgument("--unrestricted-unidentified-sender")
+                .type(Boolean.class)
+                .help("Enable if anyone should be able to send you unidentified sender messages.");
+
         var mut = subparser.addMutuallyExclusiveGroup();
         mut.addArgument("-u", "--username").help("Specify a username that can then be used to contact this account.");
         mut.addArgument("--delete-username")
@@ -39,14 +43,15 @@ public class UpdateAccountCommand implements JsonRpcLocalCommand {
     public void handleCommand(
             final Namespace ns, final Manager m, final OutputWriter outputWriter
     ) throws CommandException {
-        var deviceName = ns.getString("device-name");
+        final var deviceName = ns.getString("device-name");
+        final var unrestrictedUnidentifiedSender = ns.getBoolean("unrestricted-unidentified-sender");
         try {
-            m.updateAccountAttributes(deviceName);
+            m.updateAccountAttributes(deviceName, unrestrictedUnidentifiedSender);
         } catch (IOException e) {
             throw new IOErrorException("UpdateAccount error: " + e.getMessage(), e);
         }
 
-        var username = ns.getString("username");
+        final var username = ns.getString("username");
         if (username != null) {
             try {
                 m.setUsername(username);
@@ -66,7 +71,7 @@ public class UpdateAccountCommand implements JsonRpcLocalCommand {
             }
         }
 
-        var deleteUsername = Boolean.TRUE.equals(ns.getBoolean("delete-username"));
+        final var deleteUsername = Boolean.TRUE.equals(ns.getBoolean("delete-username"));
         if (deleteUsername) {
             try {
                 m.deleteUsername();
index e149e58ce97f2f8d741e6e918c9b30aa6b135741..e6a18307f39c4d67d30a6d00a8d270f3dbec4794 100644 (file)
@@ -121,7 +121,9 @@ public class DbusManagerImpl implements Manager {
     }
 
     @Override
-    public void updateAccountAttributes(final String deviceName) throws IOException {
+    public void updateAccountAttributes(
+            final String deviceName, final Boolean unrestrictedUnidentifiedSender
+    ) throws IOException {
         if (deviceName != null) {
             final var devicePath = signal.getThisDevice();
             getRemoteObject(devicePath, Signal.Device.class).Set("org.asamk.Signal.Device", "Name", deviceName);
index 5ad145371eb3a29b1653ec49016d833ac1ea9af1..80132f09e8d39d30df834a07a48f0a096fbee07b 100644 (file)
@@ -1187,7 +1187,7 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
                 throw new Error.Failure("Only the name of this device can be changed");
             }
             try {
-                m.updateAccountAttributes(name);
+                m.updateAccountAttributes(name, null);
                 // update device list
                 updateDevices();
             } catch (IOException e) {