Refactor Manager to always have a valid SignalAccount instance

Extract ProvisioningManager to link new devices
This commit is contained in:
AsamK 2020-05-11 18:07:37 +02:00
parent 8163a42d3a
commit a02031aa80
8 changed files with 239 additions and 149 deletions

View file

@ -4,7 +4,7 @@ import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.UserAlreadyExists;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.ProvisioningManager;
import org.whispersystems.libsignal.InvalidKeyException;
import java.io.IOException;
@ -12,7 +12,7 @@ import java.util.concurrent.TimeoutException;
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
public class LinkCommand implements LocalCommand {
public class LinkCommand implements ProvisioningCommand {
@Override
public void attachToSubparser(final Subparser subparser) {
@ -21,15 +21,15 @@ public class LinkCommand implements LocalCommand {
}
@Override
public int handleCommand(final Namespace ns, final Manager m) {
public int handleCommand(final Namespace ns, final ProvisioningManager m) {
String deviceName = ns.getString("name");
if (deviceName == null) {
deviceName = "cli";
}
try {
System.out.println(m.getDeviceLinkUri());
m.finishDeviceLink(deviceName);
System.out.println("Associated with: " + m.getUsername());
String username = m.finishDeviceLink(deviceName);
System.out.println("Associated with: " + username);
} catch (TimeoutException e) {
System.err.println("Link request timed out, please try again.");
return 3;

View file

@ -0,0 +1,10 @@
package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace;
import org.asamk.signal.manager.ProvisioningManager;
public interface ProvisioningCommand extends Command {
int handleCommand(Namespace ns, ProvisioningManager m);
}

View file

@ -20,10 +20,6 @@ public class VerifyCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.userHasKeys()) {
System.err.println("User has no keys, first call register.");
return 1;
}
if (m.isRegistered()) {
System.err.println("User registration is already verified");
return 1;