Skip to content

Commit

Permalink
Removing linked devices only works on the primary device
Browse files Browse the repository at this point in the history
  • Loading branch information
AsamK committed Feb 25, 2024
1 parent b76964f commit 22ac3cb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/src/main/java/org/asamk/signal/manager/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void finishChangeNumber(

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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,10 @@ public List<Device> getLinkedDevices() throws IOException {
}

@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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import org.asamk.signal.commands.exceptions.CommandException;
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.api.NotPrimaryDeviceException;
import org.asamk.signal.output.OutputWriter;

import java.io.IOException;
Expand Down Expand Up @@ -33,6 +35,8 @@ public void handleCommand(
try {
final var deviceId = ns.getInt("device-id");
m.removeLinkedDevices(deviceId);
} catch (NotPrimaryDeviceException e) {
throw new UserErrorException("This command doesn't work on linked devices.");
} catch (IOException e) {
throw new IOErrorException("Error while removing device: " + e.getMessage(), e);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,8 @@ public void removeDevice() throws Error.Failure {
try {
m.removeLinkedDevices(device.id());
updateDevices();
} catch (NotPrimaryDeviceException e) {
throw new Error.Failure("This command doesn't work on linked devices.");
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
}
Expand Down

0 comments on commit 22ac3cb

Please sign in to comment.