Add --unrestricted-unidentified-sender to updateAccount command

This commit is contained in:
AsamK 2024-01-13 16:00:55 +01:00
parent 3290a5bf4d
commit 30e8e36635
9 changed files with 38 additions and 10 deletions

View file

@ -8,6 +8,7 @@
- New --hidden parameter for removeContact command - 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. - 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. 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 ### Improved
- Better shutdown handling after Ctrl+C and SIGTERM - Better shutdown handling after Ctrl+C and SIGTERM

View file

@ -89,7 +89,7 @@ public interface Manager extends Closeable {
*/ */
Map<String, UserStatus> getUserStatus(Set<String> numbers) throws IOException, RateLimitException; 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(); Configuration getConfiguration();

View file

@ -328,6 +328,13 @@ public final class ProfileHelper {
final var profile = account.getProfileStore().getProfile(recipientId); 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; Profile newProfile = null;
if (profileKey.isPresent()) { if (profileKey.isPresent()) {
logger.trace("Decrypting profile"); logger.trace("Decrypting profile");

View file

@ -277,10 +277,13 @@ public class ManagerImpl implements Manager {
} }
@Override @Override
public void updateAccountAttributes(String deviceName) throws IOException { public void updateAccountAttributes(String deviceName, Boolean unrestrictedUnidentifiedSender) throws IOException {
if (deviceName != null) { if (deviceName != null) {
context.getAccountHelper().setDeviceName(deviceName); context.getAccountHelper().setDeviceName(deviceName);
} }
if (unrestrictedUnidentifiedSender != null) {
account.setUnrestrictedUnidentifiedAccess(unrestrictedUnidentifiedSender);
}
context.getAccountHelper().updateAccountAttributes(); context.getAccountHelper().updateAccountAttributes();
context.getAccountHelper().checkWhoAmiI(); context.getAccountHelper().checkWhoAmiI();
} }

View file

@ -154,6 +154,10 @@ public class SignalAccount implements Closeable {
private final KeyValueEntry<Long> storageManifestVersion = new KeyValueEntry<>("storage-manifest-version", private final KeyValueEntry<Long> storageManifestVersion = new KeyValueEntry<>("storage-manifest-version",
long.class, long.class,
-1L); -1L);
private final KeyValueEntry<Boolean> unrestrictedUnidentifiedAccess = new KeyValueEntry<>(
"unrestricted-unidentified-access",
Boolean.class,
false);
private boolean isMultiDevice = false; private boolean isMultiDevice = false;
private boolean registered = false; private boolean registered = false;
@ -1594,8 +1598,11 @@ public class SignalAccount implements Closeable {
} }
public boolean isUnrestrictedUnidentifiedAccess() { public boolean isUnrestrictedUnidentifiedAccess() {
final var profile = getProfileStore().getProfile(getSelfRecipientId()); return Boolean.TRUE.equals(getKeyValueStore().getEntry(unrestrictedUnidentifiedAccess));
return profile != null && profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.UNRESTRICTED; }
public void setUnrestrictedUnidentifiedAccess(boolean value) {
getKeyValueStore().storeEntry(unrestrictedUnidentifiedAccess, value);
} }
public boolean isDiscoverableByPhoneNumber() { public boolean isDiscoverableByPhoneNumber() {

View file

@ -147,6 +147,9 @@ Can fix problems with receiving messages.
*-n* NAME, *--device-name* NAME:: *-n* NAME, *--device-name* NAME::
Set a new device name for the primary or linked device 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 === startChangeNumber
Change an account to a new phone number with SMS or voice verification. Change an account to a new phone number with SMS or voice verification.

View file

@ -28,6 +28,10 @@ public class UpdateAccountCommand implements JsonRpcLocalCommand {
public void attachToSubparser(final Subparser subparser) { public void attachToSubparser(final Subparser subparser) {
subparser.help("Update the account attributes on the signal server."); 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("-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(); var mut = subparser.addMutuallyExclusiveGroup();
mut.addArgument("-u", "--username").help("Specify a username that can then be used to contact this account."); mut.addArgument("-u", "--username").help("Specify a username that can then be used to contact this account.");
mut.addArgument("--delete-username") mut.addArgument("--delete-username")
@ -39,14 +43,15 @@ public class UpdateAccountCommand implements JsonRpcLocalCommand {
public void handleCommand( public void handleCommand(
final Namespace ns, final Manager m, final OutputWriter outputWriter final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException { ) throws CommandException {
var deviceName = ns.getString("device-name"); final var deviceName = ns.getString("device-name");
final var unrestrictedUnidentifiedSender = ns.getBoolean("unrestricted-unidentified-sender");
try { try {
m.updateAccountAttributes(deviceName); m.updateAccountAttributes(deviceName, unrestrictedUnidentifiedSender);
} catch (IOException e) { } catch (IOException e) {
throw new IOErrorException("UpdateAccount error: " + e.getMessage(), e); throw new IOErrorException("UpdateAccount error: " + e.getMessage(), e);
} }
var username = ns.getString("username"); final var username = ns.getString("username");
if (username != null) { if (username != null) {
try { try {
m.setUsername(username); 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) { if (deleteUsername) {
try { try {
m.deleteUsername(); m.deleteUsername();

View file

@ -121,7 +121,9 @@ public class DbusManagerImpl implements Manager {
} }
@Override @Override
public void updateAccountAttributes(final String deviceName) throws IOException { public void updateAccountAttributes(
final String deviceName, final Boolean unrestrictedUnidentifiedSender
) throws IOException {
if (deviceName != null) { if (deviceName != null) {
final var devicePath = signal.getThisDevice(); final var devicePath = signal.getThisDevice();
getRemoteObject(devicePath, Signal.Device.class).Set("org.asamk.Signal.Device", "Name", deviceName); getRemoteObject(devicePath, Signal.Device.class).Set("org.asamk.Signal.Device", "Name", deviceName);

View file

@ -1187,7 +1187,7 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
throw new Error.Failure("Only the name of this device can be changed"); throw new Error.Failure("Only the name of this device can be changed");
} }
try { try {
m.updateAccountAttributes(name); m.updateAccountAttributes(name, null);
// update device list // update device list
updateDevices(); updateDevices();
} catch (IOException e) { } catch (IOException e) {