mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-02 12:30:39 +00:00
Add commands to update contact names on Signal servers
As Signal Desktop does not allow its users to update the contact names, it would be nice to be able to update contact names from signal-cli when the latter is the master device. The command `setContactName` allow to set the name for the given contact in the local store. `sendContacts` can then be used to push the updated contact list on Signal servers.
This commit is contained in:
parent
9aa13e92fe
commit
fa1769f324
5 changed files with 81 additions and 1 deletions
|
@ -208,6 +208,19 @@ number::
|
||||||
Specify the safety number or fingerprint of the key, only use this option if you have verified
|
Specify the safety number or fingerprint of the key, only use this option if you have verified
|
||||||
the fingerprint.
|
the fingerprint.
|
||||||
|
|
||||||
|
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
|
daemon
|
||||||
~~~~~~
|
~~~~~~
|
||||||
|
|
|
@ -20,6 +20,8 @@ public class Commands {
|
||||||
addCommand("removeDevice", new RemoveDeviceCommand());
|
addCommand("removeDevice", new RemoveDeviceCommand());
|
||||||
addCommand("removePin", new RemovePinCommand());
|
addCommand("removePin", new RemovePinCommand());
|
||||||
addCommand("send", new SendCommand());
|
addCommand("send", new SendCommand());
|
||||||
|
addCommand("sendContacts", new SendContactsCommand());
|
||||||
|
addCommand("setContactName", new SetContactNameCommand());
|
||||||
addCommand("setPin", new SetPinCommand());
|
addCommand("setPin", new SetPinCommand());
|
||||||
addCommand("trust", new TrustCommand());
|
addCommand("trust", new TrustCommand());
|
||||||
addCommand("unregister", new UnregisterCommand());
|
addCommand("unregister", new UnregisterCommand());
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1347,7 +1347,7 @@ public class Manager implements Signal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendContacts() throws IOException, UntrustedIdentityException {
|
public void sendContacts() throws IOException, UntrustedIdentityException {
|
||||||
File contactsFile = IOUtils.createTempFile();
|
File contactsFile = IOUtils.createTempFile();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue