mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Refactor addDeviceLink method
This commit is contained in:
parent
e5a67d6ce1
commit
ff162cb44d
9 changed files with 24 additions and 19 deletions
|
@ -2747,7 +2747,8 @@
|
|||
"name":"org.whispersystems.signalservice.internal.push.DeviceCode",
|
||||
"allDeclaredFields":true,
|
||||
"allDeclaredMethods":true,
|
||||
"allDeclaredConstructors":true
|
||||
"allDeclaredConstructors":true,
|
||||
"methods":[{"name":"<init>","parameterTypes":[] }]
|
||||
},
|
||||
{
|
||||
"name":"org.whispersystems.signalservice.internal.push.DeviceId",
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.asamk.signal.manager.api.AlreadyReceivingException;
|
|||
import org.asamk.signal.manager.api.AttachmentInvalidException;
|
||||
import org.asamk.signal.manager.api.Configuration;
|
||||
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;
|
||||
|
@ -42,7 +43,6 @@ import java.io.Closeable;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -116,7 +116,7 @@ public interface Manager extends Closeable {
|
|||
|
||||
void removeLinkedDevices(int deviceId) throws IOException;
|
||||
|
||||
void addDeviceLink(URI linkUri) throws IOException, InvalidDeviceLinkException;
|
||||
void addDeviceLink(DeviceLinkUrl linkUri) throws IOException, InvalidDeviceLinkException;
|
||||
|
||||
void setRegistrationLockPin(Optional<String> pin) throws IOException, NotPrimaryDeviceException;
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.asamk.signal.manager.internal;
|
||||
package org.asamk.signal.manager.api;
|
||||
|
||||
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
|
||||
import org.asamk.signal.manager.util.Utils;
|
||||
import org.signal.libsignal.protocol.InvalidKeyException;
|
||||
import org.signal.libsignal.protocol.ecc.Curve;
|
||||
|
@ -14,9 +13,9 @@ import java.util.Base64;
|
|||
|
||||
import static org.whispersystems.signalservice.internal.util.Util.isEmpty;
|
||||
|
||||
public record DeviceLinkInfo(String deviceIdentifier, ECPublicKey deviceKey) {
|
||||
public record DeviceLinkUrl(String deviceIdentifier, ECPublicKey deviceKey) {
|
||||
|
||||
public static DeviceLinkInfo parseDeviceLinkUri(URI linkUri) throws InvalidDeviceLinkException {
|
||||
public static DeviceLinkUrl parseDeviceLinkUri(URI linkUri) throws InvalidDeviceLinkException {
|
||||
final var rawQuery = linkUri.getRawQuery();
|
||||
if (isEmpty(rawQuery)) {
|
||||
throw new RuntimeException("Invalid device link uri");
|
||||
|
@ -43,7 +42,7 @@ public record DeviceLinkInfo(String deviceIdentifier, ECPublicKey deviceKey) {
|
|||
throw new InvalidDeviceLinkException("Invalid device link", e);
|
||||
}
|
||||
|
||||
return new DeviceLinkInfo(deviceIdentifier, deviceKey);
|
||||
return new DeviceLinkUrl(deviceIdentifier, deviceKey);
|
||||
}
|
||||
|
||||
public URI createDeviceLinkUri() {
|
|
@ -1,12 +1,12 @@
|
|||
package org.asamk.signal.manager.helper;
|
||||
|
||||
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
||||
import org.asamk.signal.manager.api.DeviceLinkUrl;
|
||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
|
||||
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
||||
import org.asamk.signal.manager.api.PinLockedException;
|
||||
import org.asamk.signal.manager.api.RateLimitException;
|
||||
import org.asamk.signal.manager.internal.DeviceLinkInfo;
|
||||
import org.asamk.signal.manager.internal.SignalDependencies;
|
||||
import org.asamk.signal.manager.storage.SignalAccount;
|
||||
import org.asamk.signal.manager.util.KeyUtils;
|
||||
|
@ -267,7 +267,7 @@ public class AccountHelper {
|
|||
dependencies.getAccountManager().setAccountAttributes(account.getAccountAttributes(null));
|
||||
}
|
||||
|
||||
public void addDevice(DeviceLinkInfo deviceLinkInfo) throws IOException, InvalidDeviceLinkException {
|
||||
public void addDevice(DeviceLinkUrl deviceLinkInfo) throws IOException, InvalidDeviceLinkException {
|
||||
var verificationCode = dependencies.getAccountManager().getNewDeviceVerificationCode();
|
||||
|
||||
try {
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.asamk.signal.manager.api.AlreadyReceivingException;
|
|||
import org.asamk.signal.manager.api.AttachmentInvalidException;
|
||||
import org.asamk.signal.manager.api.Configuration;
|
||||
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;
|
||||
|
@ -91,7 +92,6 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
|
@ -359,9 +359,8 @@ public class ManagerImpl implements Manager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceLink(URI linkUri) throws IOException, InvalidDeviceLinkException {
|
||||
var deviceLinkInfo = DeviceLinkInfo.parseDeviceLinkUri(linkUri);
|
||||
context.getAccountHelper().addDevice(deviceLinkInfo);
|
||||
public void addDeviceLink(DeviceLinkUrl linkUrl) throws IOException, InvalidDeviceLinkException {
|
||||
context.getAccountHelper().addDevice(linkUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.asamk.signal.manager.internal;
|
|||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.ProvisioningManager;
|
||||
import org.asamk.signal.manager.Settings;
|
||||
import org.asamk.signal.manager.api.DeviceLinkUrl;
|
||||
import org.asamk.signal.manager.api.UserAlreadyExistsException;
|
||||
import org.asamk.signal.manager.config.ServiceConfig;
|
||||
import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
|
||||
|
@ -97,7 +98,7 @@ public class ProvisioningManagerImpl implements ProvisioningManager {
|
|||
public URI getDeviceLinkUri() throws TimeoutException, IOException {
|
||||
var deviceUuid = accountManager.getNewDeviceUuid();
|
||||
|
||||
return new DeviceLinkInfo(deviceUuid, tempIdentityKey.getPublicKey().getPublicKey()).createDeviceLinkUri();
|
||||
return new DeviceLinkUrl(deviceUuid, tempIdentityKey.getPublicKey().getPublicKey()).createDeviceLinkUri();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue