Refactor addDeviceLink method

This commit is contained in:
AsamK 2023-05-21 22:54:51 +02:00
parent e5a67d6ce1
commit ff162cb44d
9 changed files with 24 additions and 19 deletions

View file

@ -7,6 +7,7 @@ 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.DeviceLinkUrl;
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
import org.asamk.signal.output.OutputWriter;
import org.slf4j.Logger;
@ -45,7 +46,8 @@ public class AddDeviceCommand implements JsonRpcLocalCommand {
}
try {
m.addDeviceLink(linkUri);
var deviceLinkUrl = DeviceLinkUrl.parseDeviceLinkUri(linkUri);
m.addDeviceLink(deviceLinkUrl);
} catch (IOException e) {
logger.error("Add device link failed", e);
throw new IOErrorException("Add device link failed", e);

View file

@ -7,6 +7,7 @@ import org.asamk.signal.manager.api.AttachmentInvalidException;
import org.asamk.signal.manager.api.Configuration;
import org.asamk.signal.manager.api.Contact;
import org.asamk.signal.manager.api.Device;
import org.asamk.signal.manager.api.DeviceLinkUrl;
import org.asamk.signal.manager.api.Group;
import org.asamk.signal.manager.api.GroupId;
import org.asamk.signal.manager.api.GroupInviteLinkUrl;
@ -199,8 +200,8 @@ public class DbusManagerImpl implements Manager {
}
@Override
public void addDeviceLink(final URI linkUri) throws IOException, InvalidDeviceLinkException {
signal.addDevice(linkUri.toString());
public void addDeviceLink(final DeviceLinkUrl linkUri) throws IOException, InvalidDeviceLinkException {
signal.addDevice(linkUri.createDeviceLinkUri().toString());
}
@Override

View file

@ -4,6 +4,7 @@ import org.asamk.Signal;
import org.asamk.signal.BaseConfig;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.AttachmentInvalidException;
import org.asamk.signal.manager.api.DeviceLinkUrl;
import org.asamk.signal.manager.api.GroupId;
import org.asamk.signal.manager.api.GroupInviteLinkUrl;
import org.asamk.signal.manager.api.GroupLinkState;
@ -173,7 +174,8 @@ public class DbusSignalImpl implements Signal {
@Override
public void addDevice(String uri) {
try {
m.addDeviceLink(new URI(uri));
var deviceLinkUrl = DeviceLinkUrl.parseDeviceLinkUri(new URI(uri));
m.addDeviceLink(deviceLinkUrl);
} catch (IOException | InvalidDeviceLinkException e) {
throw new Error.Failure(e.getClass().getSimpleName() + " Add device link failed. " + e.getMessage());
} catch (URISyntaxException e) {