mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Split given/family name in updateContact command
This commit is contained in:
parent
27dbc671e0
commit
badbb55ef2
7 changed files with 32 additions and 13 deletions
|
@ -149,7 +149,7 @@ public interface Manager extends Closeable {
|
||||||
void deleteContact(RecipientIdentifier.Single recipient);
|
void deleteContact(RecipientIdentifier.Single recipient);
|
||||||
|
|
||||||
void setContactName(
|
void setContactName(
|
||||||
RecipientIdentifier.Single recipient, String name
|
RecipientIdentifier.Single recipient, String givenName, final String familyName
|
||||||
) throws NotPrimaryDeviceException, IOException, UnregisteredRecipientException;
|
) throws NotPrimaryDeviceException, IOException, UnregisteredRecipientException;
|
||||||
|
|
||||||
void setContactsBlocked(
|
void setContactsBlocked(
|
||||||
|
|
|
@ -705,12 +705,13 @@ class ManagerImpl implements Manager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContactName(
|
public void setContactName(
|
||||||
RecipientIdentifier.Single recipient, String name
|
RecipientIdentifier.Single recipient, String givenName, final String familyName
|
||||||
) throws NotPrimaryDeviceException, UnregisteredRecipientException {
|
) throws NotPrimaryDeviceException, UnregisteredRecipientException {
|
||||||
if (!account.isPrimaryDevice()) {
|
if (!account.isPrimaryDevice()) {
|
||||||
throw new NotPrimaryDeviceException();
|
throw new NotPrimaryDeviceException();
|
||||||
}
|
}
|
||||||
context.getContactHelper().setContactName(context.getRecipientHelper().resolveRecipient(recipient), name);
|
context.getContactHelper()
|
||||||
|
.setContactName(context.getRecipientHelper().resolveRecipient(recipient), givenName, familyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,10 +17,16 @@ public class ContactHelper {
|
||||||
return sourceContact != null && sourceContact.isBlocked();
|
return sourceContact != null && sourceContact.isBlocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContactName(final RecipientId recipientId, final String name) {
|
public void setContactName(final RecipientId recipientId, final String givenName, final String familyName) {
|
||||||
var contact = account.getContactStore().getContact(recipientId);
|
var contact = account.getContactStore().getContact(recipientId);
|
||||||
final var builder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
|
final var builder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
|
||||||
account.getContactStore().storeContact(recipientId, builder.withGivenName(name).build());
|
if (givenName != null) {
|
||||||
|
builder.withGivenName(givenName);
|
||||||
|
}
|
||||||
|
if (familyName != null) {
|
||||||
|
builder.withFamilyName(familyName);
|
||||||
|
}
|
||||||
|
account.getContactStore().storeContact(recipientId, builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExpirationTimer(RecipientId recipientId, int messageExpirationTimer) {
|
public void setExpirationTimer(RecipientId recipientId, int messageExpirationTimer) {
|
||||||
|
|
|
@ -522,8 +522,11 @@ If the contact doesn't exist yet, it will be added.
|
||||||
NUMBER::
|
NUMBER::
|
||||||
Specify the contact phone number.
|
Specify the contact phone number.
|
||||||
|
|
||||||
*-n*, *--name*::
|
*--given-name* NAME, *--name* NAME::
|
||||||
Specify the new name for this contact.
|
New (given) name.
|
||||||
|
|
||||||
|
*--family-name* FAMILY_NAME::
|
||||||
|
New family name.
|
||||||
|
|
||||||
*-e*, *--expiration* EXPIRATION_SECONDS::
|
*-e*, *--expiration* EXPIRATION_SECONDS::
|
||||||
Set expiration time of messages (seconds).
|
Set expiration time of messages (seconds).
|
||||||
|
|
|
@ -26,6 +26,8 @@ public class UpdateContactCommand implements JsonRpcLocalCommand {
|
||||||
subparser.help("Update the details of a given contact");
|
subparser.help("Update the details of a given contact");
|
||||||
subparser.addArgument("recipient").help("Contact number");
|
subparser.addArgument("recipient").help("Contact number");
|
||||||
subparser.addArgument("-n", "--name").help("New contact name");
|
subparser.addArgument("-n", "--name").help("New contact name");
|
||||||
|
subparser.addArgument("--given-name").help("New contact given name");
|
||||||
|
subparser.addArgument("--family-name").help("New contact family name");
|
||||||
subparser.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
|
subparser.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,9 +44,16 @@ public class UpdateContactCommand implements JsonRpcLocalCommand {
|
||||||
m.setExpirationTimer(recipient, expiration);
|
m.setExpirationTimer(recipient, expiration);
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = ns.getString("name");
|
var givenName = ns.getString("given-name");
|
||||||
if (name != null) {
|
var familyName = ns.getString("family-name");
|
||||||
m.setContactName(recipient, name);
|
if (givenName == null) {
|
||||||
|
givenName = ns.getString("name");
|
||||||
|
if (givenName != null && familyName == null) {
|
||||||
|
familyName = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (givenName != null || familyName != null) {
|
||||||
|
m.setContactName(recipient, givenName, familyName);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IOErrorException("Update contact error: " + e.getMessage(), e);
|
throw new IOErrorException("Update contact error: " + e.getMessage(), e);
|
||||||
|
|
|
@ -409,9 +409,9 @@ public class DbusManagerImpl implements Manager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContactName(
|
public void setContactName(
|
||||||
final RecipientIdentifier.Single recipient, final String name
|
final RecipientIdentifier.Single recipient, final String givenName, final String familyName
|
||||||
) throws NotPrimaryDeviceException {
|
) throws NotPrimaryDeviceException {
|
||||||
signal.setContactName(recipient.getIdentifier(), name);
|
signal.setContactName(recipient.getIdentifier(), givenName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -492,7 +492,7 @@ public class DbusSignalImpl implements Signal {
|
||||||
@Override
|
@Override
|
||||||
public void setContactName(final String number, final String name) {
|
public void setContactName(final String number, final String name) {
|
||||||
try {
|
try {
|
||||||
m.setContactName(getSingleRecipientIdentifier(number, m.getSelfNumber()), name);
|
m.setContactName(getSingleRecipientIdentifier(number, m.getSelfNumber()), name, "");
|
||||||
} catch (NotPrimaryDeviceException e) {
|
} catch (NotPrimaryDeviceException e) {
|
||||||
throw new Error.Failure("This command doesn't work on linked devices.");
|
throw new Error.Failure("This command doesn't work on linked devices.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue