diff --git a/man/signal-cli.1.adoc b/man/signal-cli.1.adoc index c338bb63..2d91826b 100644 --- a/man/signal-cli.1.adoc +++ b/man/signal-cli.1.adoc @@ -223,6 +223,16 @@ with every outgoing messages (excluding group messages). *--remove-avatar*:: Remove the avatar visible by message recipients. +setContactName +-------------- +Update name associated to a number on our contact list. This change is only local but can be synchronized to other devices by using `sendContacts` (see below). +number:: + Specify the contact phone number. +name:: + Specify the new name for this contact. +sendContacts +------------ +Update contact list on Signal servers. daemon ~~~~~~ signal-cli can run in daemon mode and provides an experimental dbus interface. For diff --git a/src/main/java/org/asamk/signal/commands/Commands.java b/src/main/java/org/asamk/signal/commands/Commands.java index 75efaef2..ed2796b8 100644 --- a/src/main/java/org/asamk/signal/commands/Commands.java +++ b/src/main/java/org/asamk/signal/commands/Commands.java @@ -20,6 +20,8 @@ public class Commands { addCommand("removeDevice", new RemoveDeviceCommand()); addCommand("removePin", new RemovePinCommand()); addCommand("send", new SendCommand()); + addCommand("sendContacts", new SendContactsCommand()); + addCommand("setContactName", new SetContactNameCommand()); addCommand("setPin", new SetPinCommand()); addCommand("trust", new TrustCommand()); addCommand("unregister", new UnregisterCommand()); diff --git a/src/main/java/org/asamk/signal/commands/SendContactsCommand.java b/src/main/java/org/asamk/signal/commands/SendContactsCommand.java new file mode 100644 index 00000000..15241a34 --- /dev/null +++ b/src/main/java/org/asamk/signal/commands/SendContactsCommand.java @@ -0,0 +1,31 @@ +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.whispersystems.signalservice.api.crypto.UntrustedIdentityException; + +import java.io.IOException; + +public class SendContactsCommand implements LocalCommand { + + @Override + public void attachToSubparser(final Subparser subparser) { + subparser.help("Send contacts to the signal server."); + } + + @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; + } catch (IOException | UntrustedIdentityException e) { + System.err.println("SendContacts error: " + e.getMessage()); + return 3; + } + } +} diff --git a/src/main/java/org/asamk/signal/commands/SetContactNameCommand.java b/src/main/java/org/asamk/signal/commands/SetContactNameCommand.java new file mode 100644 index 00000000..d7cbedc6 --- /dev/null +++ b/src/main/java/org/asamk/signal/commands/SetContactNameCommand.java @@ -0,0 +1,34 @@ +package org.asamk.signal.commands; + +import net.sourceforge.argparse4j.impl.Arguments; +import net.sourceforge.argparse4j.inf.Namespace; +import net.sourceforge.argparse4j.inf.Subparser; +import org.asamk.signal.manager.Manager; + +public class SetContactNameCommand implements LocalCommand { + + @Override + public void attachToSubparser(final Subparser subparser) { + subparser.addArgument("number") + .help("Contact number"); + subparser.addArgument("name") + .help("New contact name"); + subparser.help("Set the name of a given contact"); + } + + @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"); + + m.setContactName(number, name); + + return 0; + } + +} diff --git a/src/main/java/org/asamk/signal/manager/Manager.java b/src/main/java/org/asamk/signal/manager/Manager.java index 5aaf14e3..a1458019 100644 --- a/src/main/java/org/asamk/signal/manager/Manager.java +++ b/src/main/java/org/asamk/signal/manager/Manager.java @@ -1416,7 +1416,7 @@ public class Manager implements Signal { } } - private void sendContacts() throws IOException, UntrustedIdentityException { + public void sendContacts() throws IOException, UntrustedIdentityException { File contactsFile = IOUtils.createTempFile(); try {