Removing linked devices only works on the primary device

This commit is contained in:
AsamK 2024-02-25 18:12:36 +01:00
parent b76964f219
commit 22ac3cb50f
4 changed files with 11 additions and 2 deletions

View file

@ -140,7 +140,7 @@ public interface Manager extends Closeable {
List<Device> getLinkedDevices() throws IOException; List<Device> getLinkedDevices() throws IOException;
void removeLinkedDevices(int deviceId) throws IOException; void removeLinkedDevices(int deviceId) throws IOException, NotPrimaryDeviceException;
void addDeviceLink(DeviceLinkUrl linkUri) throws IOException, InvalidDeviceLinkException, NotPrimaryDeviceException; void addDeviceLink(DeviceLinkUrl linkUri) throws IOException, InvalidDeviceLinkException, NotPrimaryDeviceException;

View file

@ -436,7 +436,10 @@ public class ManagerImpl implements Manager {
} }
@Override @Override
public void removeLinkedDevices(int deviceId) throws IOException { public void removeLinkedDevices(int deviceId) throws IOException, NotPrimaryDeviceException {
if (!account.isPrimaryDevice()) {
throw new NotPrimaryDeviceException();
}
context.getAccountHelper().removeLinkedDevices(deviceId); context.getAccountHelper().removeLinkedDevices(deviceId);
} }

View file

@ -5,7 +5,9 @@ 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.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.NotPrimaryDeviceException;
import org.asamk.signal.output.OutputWriter; import org.asamk.signal.output.OutputWriter;
import java.io.IOException; import java.io.IOException;
@ -33,6 +35,8 @@ public class RemoveDeviceCommand implements JsonRpcLocalCommand {
try { try {
final var deviceId = ns.getInt("device-id"); final var deviceId = ns.getInt("device-id");
m.removeLinkedDevices(deviceId); m.removeLinkedDevices(deviceId);
} catch (NotPrimaryDeviceException e) {
throw new UserErrorException("This command doesn't work on linked devices.");
} catch (IOException e) { } catch (IOException e) {
throw new IOErrorException("Error while removing device: " + e.getMessage(), e); throw new IOErrorException("Error while removing device: " + e.getMessage(), e);
} }

View file

@ -1177,6 +1177,8 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
try { try {
m.removeLinkedDevices(device.id()); m.removeLinkedDevices(device.id());
updateDevices(); updateDevices();
} catch (NotPrimaryDeviceException e) {
throw new Error.Failure("This command doesn't work on linked devices.");
} catch (IOException e) { } catch (IOException e) {
throw new Error.Failure(e.getMessage()); throw new Error.Failure(e.getMessage());
} }