Add listContacts subcommand (#248)

This commit is contained in:
VisibleCode 2019-12-03 12:57:27 -08:00 committed by AsamK
parent b402b65066
commit e508fc50e9
3 changed files with 32 additions and 0 deletions

View file

@ -11,6 +11,7 @@ public class Commands {
addCommand("addDevice", new AddDeviceCommand());
addCommand("daemon", new DaemonCommand());
addCommand("link", new LinkCommand());
addCommand("listContacts", new ListContactsCommand());
addCommand("listDevices", new ListDevicesCommand());
addCommand("listGroups", new ListGroupsCommand());
addCommand("listIdentities", new ListIdentitiesCommand());

View file

@ -0,0 +1,27 @@
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.storage.contacts.ContactInfo;
import java.util.List;
public class ListContactsCommand implements LocalCommand {
@Override
public void attachToSubparser(final Subparser subparser) {
}
@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", c.number, c.name));
}
return 0;
}
}

View file

@ -1484,6 +1484,10 @@ public class Manager implements Signal {
sendSyncMessage(SignalServiceSyncMessage.forVerified(verifiedMessage));
}
public List<ContactInfo> getContacts() {
return account.getContactStore().getContacts();
}
public ContactInfo getContact(String number) {
return account.getContactStore().getContact(number);
}