mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Prevent updateContact and block commands on linked devices
The changes would be overwritten with the next sync anyway Fixes #600
This commit is contained in:
parent
312c6c8bb2
commit
36475bb632
6 changed files with 38 additions and 5 deletions
|
@ -1088,14 +1088,22 @@ public class Manager implements Closeable {
|
||||||
return contact == null || contact.getName() == null ? "" : contact.getName();
|
return contact == null || contact.getName() == null ? "" : contact.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContactName(String number, String name) throws InvalidNumberException {
|
public void setContactName(String number, String name) throws InvalidNumberException, NotMasterDeviceException {
|
||||||
|
if (!account.isMasterDevice()) {
|
||||||
|
throw new NotMasterDeviceException();
|
||||||
|
}
|
||||||
final var recipientId = canonicalizeAndResolveRecipient(number);
|
final var recipientId = canonicalizeAndResolveRecipient(number);
|
||||||
var contact = account.getContactStore().getContact(recipientId);
|
var contact = account.getContactStore().getContact(recipientId);
|
||||||
final var builder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
|
final var builder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
|
||||||
account.getContactStore().storeContact(recipientId, builder.withName(name).build());
|
account.getContactStore().storeContact(recipientId, builder.withName(name).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContactBlocked(String number, boolean blocked) throws InvalidNumberException {
|
public void setContactBlocked(
|
||||||
|
String number, boolean blocked
|
||||||
|
) throws InvalidNumberException, NotMasterDeviceException {
|
||||||
|
if (!account.isMasterDevice()) {
|
||||||
|
throw new NotMasterDeviceException();
|
||||||
|
}
|
||||||
setContactBlocked(canonicalizeAndResolveRecipient(number), blocked);
|
setContactBlocked(canonicalizeAndResolveRecipient(number), blocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package org.asamk.signal.manager;
|
||||||
|
|
||||||
|
public class NotMasterDeviceException extends Exception {
|
||||||
|
|
||||||
|
public NotMasterDeviceException() {
|
||||||
|
super("This function is not supported for linked devices.");
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,10 @@ package org.asamk.signal.commands;
|
||||||
import net.sourceforge.argparse4j.inf.Namespace;
|
import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
import net.sourceforge.argparse4j.inf.Subparser;
|
import net.sourceforge.argparse4j.inf.Subparser;
|
||||||
|
|
||||||
|
import org.asamk.signal.commands.exceptions.CommandException;
|
||||||
|
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
|
import org.asamk.signal.manager.NotMasterDeviceException;
|
||||||
import org.asamk.signal.manager.groups.GroupIdFormatException;
|
import org.asamk.signal.manager.groups.GroupIdFormatException;
|
||||||
import org.asamk.signal.manager.groups.GroupNotFoundException;
|
import org.asamk.signal.manager.groups.GroupNotFoundException;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
|
@ -23,12 +26,14 @@ public class BlockCommand implements LocalCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(final Namespace ns, final Manager m) {
|
public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
|
||||||
for (var contact_number : ns.<String>getList("contact")) {
|
for (var contact_number : ns.<String>getList("contact")) {
|
||||||
try {
|
try {
|
||||||
m.setContactBlocked(contact_number, true);
|
m.setContactBlocked(contact_number, true);
|
||||||
} catch (InvalidNumberException e) {
|
} catch (InvalidNumberException e) {
|
||||||
logger.warn("Invalid number {}: {}", contact_number, e.getMessage());
|
logger.warn("Invalid number {}: {}", contact_number, e.getMessage());
|
||||||
|
} catch (NotMasterDeviceException e) {
|
||||||
|
throw new UserErrorException("This command doesn't work on linked devices.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,9 @@ import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
import net.sourceforge.argparse4j.inf.Subparser;
|
import net.sourceforge.argparse4j.inf.Subparser;
|
||||||
|
|
||||||
import org.asamk.signal.commands.exceptions.CommandException;
|
import org.asamk.signal.commands.exceptions.CommandException;
|
||||||
|
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
|
import org.asamk.signal.manager.NotMasterDeviceException;
|
||||||
import org.asamk.signal.manager.groups.GroupIdFormatException;
|
import org.asamk.signal.manager.groups.GroupIdFormatException;
|
||||||
import org.asamk.signal.manager.groups.GroupNotFoundException;
|
import org.asamk.signal.manager.groups.GroupNotFoundException;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
|
@ -30,6 +32,8 @@ public class UnblockCommand implements LocalCommand {
|
||||||
m.setContactBlocked(contactNumber, false);
|
m.setContactBlocked(contactNumber, false);
|
||||||
} catch (InvalidNumberException e) {
|
} catch (InvalidNumberException e) {
|
||||||
logger.warn("Invalid number: {}", contactNumber);
|
logger.warn("Invalid number: {}", contactNumber);
|
||||||
|
} catch (NotMasterDeviceException e) {
|
||||||
|
throw new UserErrorException("This command doesn't work on linked devices.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import org.asamk.signal.commands.exceptions.CommandException;
|
||||||
import org.asamk.signal.commands.exceptions.IOErrorException;
|
import org.asamk.signal.commands.exceptions.IOErrorException;
|
||||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
|
import org.asamk.signal.manager.NotMasterDeviceException;
|
||||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -30,16 +31,18 @@ public class UpdateContactCommand implements LocalCommand {
|
||||||
var name = ns.getString("name");
|
var name = ns.getString("name");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
m.setContactName(number, name);
|
|
||||||
|
|
||||||
var expiration = ns.getInt("expiration");
|
var expiration = ns.getInt("expiration");
|
||||||
if (expiration != null) {
|
if (expiration != null) {
|
||||||
m.setExpirationTimer(number, expiration);
|
m.setExpirationTimer(number, expiration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.setContactName(number, name);
|
||||||
} catch (InvalidNumberException e) {
|
} catch (InvalidNumberException e) {
|
||||||
throw new UserErrorException("Invalid contact number: " + e.getMessage());
|
throw new UserErrorException("Invalid contact number: " + e.getMessage());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IOErrorException("Update contact error: " + e.getMessage());
|
throw new IOErrorException("Update contact error: " + e.getMessage());
|
||||||
|
} catch (NotMasterDeviceException e) {
|
||||||
|
throw new UserErrorException("This command doesn't work on linked devices.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.asamk.Signal;
|
||||||
import org.asamk.signal.BaseConfig;
|
import org.asamk.signal.BaseConfig;
|
||||||
import org.asamk.signal.manager.AttachmentInvalidException;
|
import org.asamk.signal.manager.AttachmentInvalidException;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
|
import org.asamk.signal.manager.NotMasterDeviceException;
|
||||||
import org.asamk.signal.manager.groups.GroupId;
|
import org.asamk.signal.manager.groups.GroupId;
|
||||||
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
|
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
|
||||||
import org.asamk.signal.manager.groups.GroupNotFoundException;
|
import org.asamk.signal.manager.groups.GroupNotFoundException;
|
||||||
|
@ -260,6 +261,8 @@ public class DbusSignalImpl implements Signal {
|
||||||
m.setContactName(number, name);
|
m.setContactName(number, name);
|
||||||
} catch (InvalidNumberException e) {
|
} catch (InvalidNumberException e) {
|
||||||
throw new Error.InvalidNumber(e.getMessage());
|
throw new Error.InvalidNumber(e.getMessage());
|
||||||
|
} catch (NotMasterDeviceException e) {
|
||||||
|
throw new Error.Failure("This command doesn't work on linked devices.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,6 +272,8 @@ public class DbusSignalImpl implements Signal {
|
||||||
m.setContactBlocked(number, blocked);
|
m.setContactBlocked(number, blocked);
|
||||||
} catch (InvalidNumberException e) {
|
} catch (InvalidNumberException e) {
|
||||||
throw new Error.InvalidNumber(e.getMessage());
|
throw new Error.InvalidNumber(e.getMessage());
|
||||||
|
} catch (NotMasterDeviceException e) {
|
||||||
|
throw new Error.Failure("This command doesn't work on linked devices.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue