Skip to content
Snippets Groups Projects
Unverified Commit 010eadcd authored by Jonathan Klabunde Tomer's avatar Jonathan Klabunde Tomer Committed by GitHub
Browse files

UnlinkDeviceCommand improvements

parent c43e0b54
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,10 @@ import com.fasterxml.jackson.databind.DeserializationFeature; ...@@ -9,7 +9,10 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import io.dropwizard.Application; import io.dropwizard.Application;
import io.dropwizard.cli.EnvironmentCommand; import io.dropwizard.cli.EnvironmentCommand;
import io.dropwizard.setup.Environment; import io.dropwizard.setup.Environment;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.whispersystems.textsecuregcm.WhisperServerConfiguration; import org.whispersystems.textsecuregcm.WhisperServerConfiguration;
...@@ -32,8 +35,9 @@ public class UnlinkDeviceCommand extends EnvironmentCommand<WhisperServerConfigu ...@@ -32,8 +35,9 @@ public class UnlinkDeviceCommand extends EnvironmentCommand<WhisperServerConfigu
super.configure(subparser); super.configure(subparser);
subparser.addArgument("-d", "--deviceId") subparser.addArgument("-d", "--deviceId")
.dest("deviceId") .dest("deviceIds")
.type(Long.class) .type(Long.class)
.action(Arguments.append())
.required(true); .required(true);
subparser.addArgument("-u", "--uuid") subparser.addArgument("-u", "--uuid")
...@@ -48,18 +52,23 @@ public class UnlinkDeviceCommand extends EnvironmentCommand<WhisperServerConfigu ...@@ -48,18 +52,23 @@ public class UnlinkDeviceCommand extends EnvironmentCommand<WhisperServerConfigu
final WhisperServerConfiguration configuration) throws Exception { final WhisperServerConfiguration configuration) throws Exception {
environment.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); environment.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
final CommandStopListener commandStopListener = new CommandStopListener(configuration.getCommandStopListener());
try {
commandStopListener.start();
final UUID aci = UUID.fromString(namespace.getString("uuid").trim()); final UUID aci = UUID.fromString(namespace.getString("uuid").trim());
final long deviceId = namespace.getLong("deviceId"); final List<Long> deviceIds = namespace.getList("deviceIds");
final CommandDependencies deps = CommandDependencies.build("unlink-device", environment, configuration); final CommandDependencies deps = CommandDependencies.build("unlink-device", environment, configuration);
Account account = deps.accountsManager().getByAccountIdentifier(aci) Account account = deps.accountsManager().getByAccountIdentifier(aci)
.orElseThrow(() -> new IllegalArgumentException("account id " + aci + " does not exist")); .orElseThrow(() -> new IllegalArgumentException("account id " + aci + " does not exist"));
if (deviceId == Device.MASTER_ID) { if (deviceIds.contains(Device.MASTER_ID)) {
throw new IllegalArgumentException("cannot delete primary device"); throw new IllegalArgumentException("cannot delete primary device");
} }
for (long deviceId : deviceIds) {
/** see {@link org.whispersystems.textsecuregcm.controllers.DeviceController#removeDevice} */ /** see {@link org.whispersystems.textsecuregcm.controllers.DeviceController#removeDevice} */
System.out.format("Removing device %s::%d\n", aci, deviceId); System.out.format("Removing device %s::%d\n", aci, deviceId);
account = deps.accountsManager().update(account, a -> a.removeDevice(deviceId)); account = deps.accountsManager().update(account, a -> a.removeDevice(deviceId));
...@@ -74,7 +83,9 @@ public class UnlinkDeviceCommand extends EnvironmentCommand<WhisperServerConfigu ...@@ -74,7 +83,9 @@ public class UnlinkDeviceCommand extends EnvironmentCommand<WhisperServerConfigu
deps.clientPresenceManager().disconnectPresence(aci, deviceId); deps.clientPresenceManager().disconnectPresence(aci, deviceId);
System.out.format("Device %s::%d successfully removed\n", aci, deviceId); System.out.format("Device %s::%d successfully removed\n", aci, deviceId);
}
} finally {
commandStopListener.stop();
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment