mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 11:00:38 +00:00
Refactor register and verify
This commit is contained in:
parent
6c8a1ff3d3
commit
e74be0c345
33 changed files with 405 additions and 362 deletions
|
@ -23,10 +23,6 @@ public class AddDeviceCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
try {
|
||||
m.addDeviceLink(new URI(ns.getString("uri")));
|
||||
return 0;
|
||||
|
|
|
@ -21,11 +21,6 @@ public class BlockCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (String contact_number : ns.<String>getList("contact")) {
|
||||
try {
|
||||
m.setContactBlocked(contact_number, true);
|
||||
|
|
|
@ -35,10 +35,6 @@ public class DaemonCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
DBusConnection conn = null;
|
||||
try {
|
||||
try {
|
||||
|
|
|
@ -28,11 +28,6 @@ public class GetUserStatusCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Setup the json object mapper
|
||||
ObjectMapper jsonProcessor = new ObjectMapper();
|
||||
jsonProcessor.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
|
||||
|
|
|
@ -29,11 +29,6 @@ public class JoinGroupCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
final GroupInviteLinkUrl linkUrl;
|
||||
String uri = ns.getString("uri");
|
||||
try {
|
||||
|
|
|
@ -16,10 +16,6 @@ public class ListContactsCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
List<ContactInfo> contacts = m.getContacts();
|
||||
for (ContactInfo c : contacts) {
|
||||
System.out.println(String.format("Number: %s Name: %s Blocked: %b", c.number, c.name, c.blocked));
|
||||
|
|
|
@ -18,10 +18,6 @@ public class ListDevicesCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
try {
|
||||
List<DeviceInfo> devices = m.getLinkedDevices();
|
||||
for (DeviceInfo d : devices) {
|
||||
|
|
|
@ -64,11 +64,6 @@ public class ListGroupsCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
List<GroupInfo> groups = m.getGroups();
|
||||
boolean detailed = ns.getBoolean("detailed");
|
||||
|
||||
|
|
|
@ -30,10 +30,6 @@ public class ListIdentitiesCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
if (ns.get("number") == null) {
|
||||
for (IdentityInfo identity : m.getIdentities()) {
|
||||
printIdentityFingerprint(m, identity);
|
||||
|
|
|
@ -31,11 +31,6 @@ public class QuitGroupCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
final GroupId groupId = Util.decodeGroupId(ns.getString("group"));
|
||||
final Pair<Long, List<SendMessageResult>> results = m.sendQuitGroupMessage(groupId);
|
||||
|
|
|
@ -146,10 +146,6 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
double timeout = 5;
|
||||
if (ns.getDouble("timeout") != null) {
|
||||
timeout = ns.getDouble("timeout");
|
||||
|
|
|
@ -4,12 +4,12 @@ import net.sourceforge.argparse4j.impl.Arguments;
|
|||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.RegistrationManager;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class RegisterCommand implements LocalCommand {
|
||||
public class RegisterCommand implements RegistrationCommand {
|
||||
|
||||
@Override
|
||||
public void attachToSubparser(final Subparser subparser) {
|
||||
|
@ -21,7 +21,7 @@ public class RegisterCommand implements LocalCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
public int handleCommand(final Namespace ns, final RegistrationManager m) {
|
||||
try {
|
||||
final boolean voiceVerification = ns.getBoolean("voice");
|
||||
final String captcha = ns.getString("captcha");
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package org.asamk.signal.commands;
|
||||
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
|
||||
import org.asamk.signal.manager.RegistrationManager;
|
||||
|
||||
public interface RegistrationCommand extends Command {
|
||||
|
||||
int handleCommand(Namespace ns, RegistrationManager m);
|
||||
}
|
|
@ -19,10 +19,6 @@ public class RemoveDeviceCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
try {
|
||||
int deviceId = ns.getInt("deviceId");
|
||||
m.removeLinkedDevices(deviceId);
|
||||
|
|
|
@ -17,10 +17,6 @@ public class RemovePinCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
try {
|
||||
m.setRegistrationLockPin(Optional.absent());
|
||||
return 0;
|
||||
|
|
|
@ -17,10 +17,6 @@ public class SendContactsCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
try {
|
||||
m.sendContacts();
|
||||
return 0;
|
||||
|
|
|
@ -47,11 +47,6 @@ public class SendReactionCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((ns.getList("recipient") == null || ns.getList("recipient").size() == 0) && ns.getString("group") == null) {
|
||||
System.err.println("No recipients given");
|
||||
System.err.println("Aborting sending.");
|
||||
|
|
|
@ -19,10 +19,6 @@ public class SetPinCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
try {
|
||||
String registrationLockPin = ns.getString("registrationLockPin");
|
||||
m.setRegistrationLockPin(Optional.of(registrationLockPin));
|
||||
|
|
|
@ -27,10 +27,6 @@ public class TrustCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
String number = ns.getString("number");
|
||||
if (ns.getBoolean("trust_all_known_keys")) {
|
||||
boolean res = m.trustIdentityAllKeys(number);
|
||||
|
|
|
@ -21,11 +21,6 @@ public class UnblockCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (String contact_number : ns.<String>getList("contact")) {
|
||||
try {
|
||||
m.setContactBlocked(contact_number, false);
|
||||
|
|
|
@ -16,10 +16,6 @@ public class UnregisterCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
try {
|
||||
m.unregister();
|
||||
return 0;
|
||||
|
|
|
@ -16,10 +16,6 @@ public class UpdateAccountCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
try {
|
||||
m.updateAccountAttributes();
|
||||
return 0;
|
||||
|
|
|
@ -23,11 +23,6 @@ public class UpdateContactCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
String number = ns.getString("number");
|
||||
String name = ns.getString("name");
|
||||
|
||||
|
|
|
@ -25,11 +25,6 @@ public class UpdateProfileCommand implements LocalCommand {
|
|||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
String name = ns.getString("name");
|
||||
String avatarPath = ns.getString("avatar");
|
||||
boolean removeAvatar = ns.getBoolean("remove_avatar");
|
||||
|
|
|
@ -3,14 +3,14 @@ package org.asamk.signal.commands;
|
|||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.RegistrationManager;
|
||||
import org.whispersystems.signalservice.api.KeyBackupServicePinException;
|
||||
import org.whispersystems.signalservice.api.KeyBackupSystemNoDataException;
|
||||
import org.whispersystems.signalservice.internal.push.LockedException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class VerifyCommand implements LocalCommand {
|
||||
public class VerifyCommand implements RegistrationCommand {
|
||||
|
||||
@Override
|
||||
public void attachToSubparser(final Subparser subparser) {
|
||||
|
@ -19,11 +19,7 @@ public class VerifyCommand implements LocalCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (m.isRegistered()) {
|
||||
System.err.println("User registration is already verified");
|
||||
return 1;
|
||||
}
|
||||
public int handleCommand(final Namespace ns, final RegistrationManager m) {
|
||||
try {
|
||||
String verificationCode = ns.getString("verificationCode");
|
||||
String pin = ns.getString("pin");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue