]> nmode's Git Repositories - signal-cli/commitdiff
Add parameter to configure phone number privacy
authorAsamK <asamk@gmx.de>
Sun, 18 Feb 2024 18:24:23 +0000 (19:24 +0100)
committerAsamK <asamk@gmx.de>
Sun, 18 Feb 2024 19:42:41 +0000 (20:42 +0100)
client/src/cli.rs
client/src/jsonrpc.rs
client/src/main.rs
lib/src/main/java/org/asamk/signal/manager/Manager.java
lib/src/main/java/org/asamk/signal/manager/internal/ManagerImpl.java
lib/src/main/java/org/asamk/signal/manager/syncStorage/AccountRecordProcessor.java
lib/src/main/java/org/asamk/signal/manager/syncStorage/StorageSyncModels.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 33403890821716278606cb66ed1087e39777b9dd..e5a5a8782156242311e18be1afd2e3a79cfc4fe8 100644 (file)
@@ -316,6 +316,10 @@ pub enum CliCommands {
         device_name: Option<String>,
         #[arg(long = "unrestricted-unidentified-sender")]
         unrestricted_unidentified_sender: Option<bool>,
+        #[arg(long = "discoverable-by-number")]
+        discoverable_by_number: Option<bool>,
+        #[arg(long = "number-sharing")]
+        number_sharing: Option<bool>,
     },
     UpdateConfiguration {
         #[arg(long = "read-receipts")]
index 211eaad820266645a794090b1e4ae36fbb1f39f6..266047c2d8972a357b5e6cdfb3a42cec04972694 100644 (file)
@@ -301,6 +301,8 @@ pub trait Rpc {
         account: Option<String>,
         deviceName: Option<String>,
         unrestrictedUnidentifiedSender: Option<bool>,
+        discoverableByNumber: Option<bool>,
+        numberSharing: Option<bool>,
     ) -> Result<Value, ErrorObjectOwned>;
 
     #[method(name = "updateConfiguration", param_kind = map)]
index 61cbabf2cb66b415f6a2a9ef3e90f43bdcac80d9..d934f800f376256be42cb820156119d912e46055 100644 (file)
@@ -275,9 +275,17 @@ async fn handle_command(
         CliCommands::UpdateAccount {
             device_name,
             unrestricted_unidentified_sender,
+            discoverable_by_number,
+            number_sharing,
         } => {
             client
-                .update_account(cli.account, device_name, unrestricted_unidentified_sender)
+                .update_account(
+                    cli.account,
+                    device_name,
+                    unrestricted_unidentified_sender,
+                    discoverable_by_number,
+                    number_sharing,
+                )
                 .await
         }
         CliCommands::UpdateConfiguration {
index e9eeb7c4c08acbe2f68ad4584e80458e69f52232..52d0aaffb6f08178fcc0e8c164803a80b49123d2 100644 (file)
@@ -90,7 +90,12 @@ public interface Manager extends Closeable {
      */
     Map<String, UserStatus> getUserStatus(Set<String> numbers) throws IOException, RateLimitException;
 
-    void updateAccountAttributes(String deviceName, Boolean unrestrictedUnidentifiedSender) throws IOException;
+    void updateAccountAttributes(
+            String deviceName,
+            Boolean unrestrictedUnidentifiedSender,
+            final Boolean discoverableByNumber,
+            final Boolean numberSharing
+    ) throws IOException;
 
     Configuration getConfiguration();
 
index b059e821ae066313a7483d162f47222808655570..bd484bb7978a1ce087a65e5acbaf6ce3c03b3561 100644 (file)
@@ -43,6 +43,7 @@ import org.asamk.signal.manager.api.NotAGroupMemberException;
 import org.asamk.signal.manager.api.NotPrimaryDeviceException;
 import org.asamk.signal.manager.api.Pair;
 import org.asamk.signal.manager.api.PendingAdminApprovalException;
+import org.asamk.signal.manager.api.PhoneNumberSharingMode;
 import org.asamk.signal.manager.api.PinLockedException;
 import org.asamk.signal.manager.api.Profile;
 import org.asamk.signal.manager.api.RateLimitException;
@@ -277,13 +278,27 @@ public class ManagerImpl implements Manager {
     }
 
     @Override
-    public void updateAccountAttributes(String deviceName, Boolean unrestrictedUnidentifiedSender) throws IOException {
+    public void updateAccountAttributes(
+            String deviceName,
+            Boolean unrestrictedUnidentifiedSender,
+            final Boolean discoverableByNumber,
+            final Boolean numberSharing
+    ) throws IOException {
         if (deviceName != null) {
             context.getAccountHelper().setDeviceName(deviceName);
         }
         if (unrestrictedUnidentifiedSender != null) {
             account.setUnrestrictedUnidentifiedAccess(unrestrictedUnidentifiedSender);
         }
+        if (discoverableByNumber != null) {
+            account.getConfigurationStore().setPhoneNumberUnlisted(!discoverableByNumber);
+        }
+        if (numberSharing != null) {
+            account.getConfigurationStore()
+                    .setPhoneNumberSharingMode(numberSharing
+                            ? PhoneNumberSharingMode.EVERYBODY
+                            : PhoneNumberSharingMode.NOBODY);
+        }
         context.getAccountHelper().updateAccountAttributes();
         context.getAccountHelper().checkWhoAmiI();
     }
index e9cd1fa627e0aa3f2d7bd7d94c6202ff6ba684c1..acce82e6ce27be614e59cf2105edc70faa360590 100644 (file)
@@ -118,7 +118,6 @@ public class AccountRecordProcessor extends DefaultStorageRecordProcessor<Signal
                 .setLinkPreviewsEnabled(linkPreviews)
                 .setUnlistedPhoneNumber(unlisted)
                 .setPhoneNumberSharingMode(phoneNumberSharingMode)
-                .setUnlistedPhoneNumber(unlisted)
                 .setPinnedConversations(pinnedConversations)
                 .setPreferContactAvatars(preferContactAvatars)
                 .setPayments(payments.isEnabled(), payments.getEntropy().orElse(null))
index a8d10142e6ed62e5b074674b2cbe7ff83e70eb8b..8cf0604833dcebc7640b35011045d0f0f25778bd 100644 (file)
@@ -62,7 +62,7 @@ public final class StorageSyncModels {
                 .setSealedSenderIndicatorsEnabled(Optional.ofNullable(configStore.getUnidentifiedDeliveryIndicators())
                         .orElse(true))
                 .setLinkPreviewsEnabled(Optional.ofNullable(configStore.getLinkPreviews()).orElse(true))
-                .setUnlistedPhoneNumber(Optional.ofNullable(configStore.getPhoneNumberUnlisted()).orElse(true))
+                .setUnlistedPhoneNumber(Optional.ofNullable(configStore.getPhoneNumberUnlisted()).orElse(false))
                 .setPhoneNumberSharingMode(localToRemote(Optional.ofNullable(configStore.getPhoneNumberSharingMode())
                         .orElse(PhoneNumberSharingMode.EVERYBODY)))
                 .setE164(self.getAddress().number().orElse(""))
index c629d55022a2ef02a4deea7a6a4711aced29ddfc..d718571c9b5b5c58a834939e5b386d78515b22d4 100644 (file)
@@ -154,6 +154,12 @@ 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.
 
+*--discoverable-by-number* {true,false}::
+Enable/disable if the account should be discoverable by phone number
+
+*--number-sharing* {true,false}::
+Indicates if Signal should share its phone number when sending a message.
+
 === startChangeNumber
 
 Change an account to a new phone number with SMS or voice verification.
index 95c0f4a4be04ceccec16f2d4cd489144478e7e52..a750bc88fe62b105c646d7a5bd5893c82bcd7ba9 100644 (file)
@@ -31,6 +31,12 @@ public class UpdateAccountCommand implements JsonRpcLocalCommand {
         subparser.addArgument("--unrestricted-unidentified-sender")
                 .type(Boolean.class)
                 .help("Enable if anyone should be able to send you unidentified sender messages.");
+        subparser.addArgument("--discoverable-by-number")
+                .type(Boolean.class)
+                .help("Enable/disable if the account should be discoverable by phone number");
+        subparser.addArgument("--number-sharing")
+                .type(Boolean.class)
+                .help("Indicates if Signal should share its phone number when sending a message.");
 
         var mut = subparser.addMutuallyExclusiveGroup();
         mut.addArgument("-u", "--username").help("Specify a username that can then be used to contact this account.");
@@ -45,8 +51,10 @@ public class UpdateAccountCommand implements JsonRpcLocalCommand {
     ) throws CommandException {
         final var deviceName = ns.getString("device-name");
         final var unrestrictedUnidentifiedSender = ns.getBoolean("unrestricted-unidentified-sender");
+        final var discoverableByNumber = ns.getBoolean("discoverable-by-number");
+        final var numberSharing = ns.getBoolean("number-sharing");
         try {
-            m.updateAccountAttributes(deviceName, unrestrictedUnidentifiedSender);
+            m.updateAccountAttributes(deviceName, unrestrictedUnidentifiedSender, discoverableByNumber, numberSharing);
         } catch (IOException e) {
             throw new IOErrorException("UpdateAccount error: " + e.getMessage(), e);
         }
index a37fa3e3b526fbf40ad9edc948192c9b08505d2b..f684871abdc7bde96c230db95145b0045ff29f7b 100644 (file)
@@ -124,11 +124,16 @@ public class DbusManagerImpl implements Manager {
 
     @Override
     public void updateAccountAttributes(
-            final String deviceName, final Boolean unrestrictedUnidentifiedSender
+            final String deviceName,
+            final Boolean unrestrictedUnidentifiedSender,
+            final Boolean discoverableByNumber,
+            final Boolean numberSharing
     ) throws IOException {
         if (deviceName != null) {
             final var devicePath = signal.getThisDevice();
             getRemoteObject(devicePath, Signal.Device.class).Set("org.asamk.Signal.Device", "Name", deviceName);
+        } else {
+            throw new UnsupportedOperationException();
         }
     }
 
index 80132f09e8d39d30df834a07a48f0a096fbee07b..6db2ef63a56aaaee2065dc2a687fa83d9cb5707b 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, null);
+                m.updateAccountAttributes(name, null, null, null);
                 // update device list
                 updateDevices();
             } catch (IOException e) {