Extend updateContact command with nick given/family name and note

This commit is contained in:
AsamK 2025-01-23 17:11:33 +01:00
parent d57442bd2a
commit 5e16123632
7 changed files with 66 additions and 17 deletions

View file

@ -237,9 +237,12 @@ public interface Manager extends Closeable {
void deleteContact(RecipientIdentifier.Single recipient); void deleteContact(RecipientIdentifier.Single recipient);
void setContactName( void setContactName(
RecipientIdentifier.Single recipient, final RecipientIdentifier.Single recipient,
String givenName, final String givenName,
final String familyName final String familyName,
final String nickGivenName,
final String nickFamilyName,
final String note
) throws NotPrimaryDeviceException, UnregisteredRecipientException; ) throws NotPrimaryDeviceException, UnregisteredRecipientException;
void setContactsBlocked( void setContactsBlocked(

View file

@ -17,7 +17,14 @@ public class ContactHelper {
return sourceContact != null && sourceContact.isBlocked(); return sourceContact != null && sourceContact.isBlocked();
} }
public void setContactName(final RecipientId recipientId, final String givenName, final String familyName) { public void setContactName(
final RecipientId recipientId,
final String givenName,
final String familyName,
final String nickGivenName,
final String nickFamilyName,
final String note
) {
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);
builder.withIsHidden(false); builder.withIsHidden(false);
@ -27,6 +34,15 @@ public class ContactHelper {
if (familyName != null) { if (familyName != null) {
builder.withFamilyName(familyName); builder.withFamilyName(familyName);
} }
if (nickGivenName != null) {
builder.withNickNameGivenName(nickGivenName);
}
if (nickFamilyName != null) {
builder.withNickNameFamilyName(nickFamilyName);
}
if (note != null) {
builder.withNote(note);
}
account.getContactStore().storeContact(recipientId, builder.build()); account.getContactStore().storeContact(recipientId, builder.build());
} }

View file

@ -1049,15 +1049,23 @@ public class ManagerImpl implements Manager {
@Override @Override
public void setContactName( public void setContactName(
RecipientIdentifier.Single recipient, final RecipientIdentifier.Single recipient,
String givenName, final String givenName,
final String familyName final String familyName,
final String nickGivenName,
final String nickFamilyName,
final String note
) throws NotPrimaryDeviceException, UnregisteredRecipientException { ) throws NotPrimaryDeviceException, UnregisteredRecipientException {
if (!account.isPrimaryDevice()) { if (!account.isPrimaryDevice()) {
throw new NotPrimaryDeviceException(); throw new NotPrimaryDeviceException();
} }
context.getContactHelper() context.getContactHelper()
.setContactName(context.getRecipientHelper().resolveRecipient(recipient), givenName, familyName); .setContactName(context.getRecipientHelper().resolveRecipient(recipient),
givenName,
familyName,
nickGivenName,
nickFamilyName,
note);
syncRemoteStorage(); syncRemoteStorage();
} }

View file

@ -669,11 +669,20 @@ If the contact doesn't exist yet, it will be added.
RECIPIENT:: RECIPIENT::
Specify the recipient. Specify the recipient.
*--given-name* NAME, *--name* NAME:: *--given-name* GIVEN_NAME, *--name* NAME::
New (given) name. New system given name.
*--family-name* FAMILY_NAME:: *--family-name* FAMILY_NAME::
New family name. New system family name.
*--nick-given-name* NICK_GIVEN_NAME::
New nick given name.
*--nick-family-name* NICK_FAMILY_NAME::
New nick family name.
*--note* NOTE::
New note.
*-e*, *--expiration* EXPIRATION_SECONDS:: *-e*, *--expiration* EXPIRATION_SECONDS::
Set expiration time of messages (seconds). Set expiration time of messages (seconds).

View file

@ -26,8 +26,11 @@ 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("--given-name").help("New system given name");
subparser.addArgument("--family-name").help("New contact family name"); subparser.addArgument("--family-name").help("New system family name");
subparser.addArgument("--nick-given-name").help("New nick given name");
subparser.addArgument("--nick-family-name").help("New nick family name");
subparser.addArgument("--note").help("New note");
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)");
} }
@ -54,8 +57,15 @@ public class UpdateContactCommand implements JsonRpcLocalCommand {
familyName = ""; familyName = "";
} }
} }
if (givenName != null || familyName != null) { var nickGivenName = ns.getString("nick-given-name");
m.setContactName(recipient, givenName, familyName); var nickFamilyName = ns.getString("nick-family-name");
var note = ns.getString("note");
if (givenName != null
|| familyName != null
|| nickGivenName != null
|| nickFamilyName != null
|| note != null) {
m.setContactName(recipient, givenName, familyName, nickGivenName, nickFamilyName, note);
} }
} catch (IOException e) { } catch (IOException e) {
throw new IOErrorException("Update contact error: " + e.getMessage(), e); throw new IOErrorException("Update contact error: " + e.getMessage(), e);

View file

@ -516,7 +516,10 @@ public class DbusManagerImpl implements Manager {
public void setContactName( public void setContactName(
final RecipientIdentifier.Single recipient, final RecipientIdentifier.Single recipient,
final String givenName, final String givenName,
final String familyName final String familyName,
final String nickGivenName,
final String nickFamilyName,
final String note
) throws NotPrimaryDeviceException { ) throws NotPrimaryDeviceException {
signal.setContactName(recipient.getIdentifier(), givenName); signal.setContactName(recipient.getIdentifier(), givenName);
} }

View file

@ -531,7 +531,7 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
@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, "", null, null, null);
} 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 (UnregisteredRecipientException e) { } catch (UnregisteredRecipientException e) {