]> nmode's Git Repositories - signal-cli/commitdiff
Split given/family name in updateContact command
authorAsamK <asamk@gmx.de>
Sun, 29 May 2022 20:21:24 +0000 (22:21 +0200)
committerAsamK <asamk@gmx.de>
Sun, 29 May 2022 20:21:24 +0000 (22:21 +0200)
lib/src/main/java/org/asamk/signal/manager/Manager.java
lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java
lib/src/main/java/org/asamk/signal/manager/helper/ContactHelper.java
man/signal-cli.1.adoc
src/main/java/org/asamk/signal/commands/UpdateContactCommand.java
src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java
src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java

index e69826aaccda292a2e01ea53a9de2b314087192f..4bc4019ca20dbadb2cac1aa1bf0f8fb1890b85d1 100644 (file)
@@ -149,7 +149,7 @@ public interface Manager extends Closeable {
     void deleteContact(RecipientIdentifier.Single recipient);
 
     void setContactName(
-            RecipientIdentifier.Single recipient, String name
+            RecipientIdentifier.Single recipient, String givenName, final String familyName
     ) throws NotPrimaryDeviceException, IOException, UnregisteredRecipientException;
 
     void setContactsBlocked(
index daff69e026973b2f71b93b22ea2a92e9555f0dc1..dc7e743ec6221e0355636434a71c0396327aa3bf 100644 (file)
@@ -705,12 +705,13 @@ class ManagerImpl implements Manager {
 
     @Override
     public void setContactName(
-            RecipientIdentifier.Single recipient, String name
+            RecipientIdentifier.Single recipient, String givenName, final String familyName
     ) throws NotPrimaryDeviceException, UnregisteredRecipientException {
         if (!account.isPrimaryDevice()) {
             throw new NotPrimaryDeviceException();
         }
-        context.getContactHelper().setContactName(context.getRecipientHelper().resolveRecipient(recipient), name);
+        context.getContactHelper()
+                .setContactName(context.getRecipientHelper().resolveRecipient(recipient), givenName, familyName);
     }
 
     @Override
index a10436e8708596b80670e0df09636bb679982d1d..f43d083c2be891cf884c111a566f0b23769d77a6 100644 (file)
@@ -17,10 +17,16 @@ public class ContactHelper {
         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);
         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) {
index 4d32ea5f3b664dd24ff326d61f7830758be25f73..6258243a5a6387177216556775f8e065a0e6b8db 100644 (file)
@@ -522,8 +522,11 @@ If the contact doesn't exist yet, it will be added.
 NUMBER::
 Specify the contact phone number.
 
-*-n*, *--name*::
-Specify the new name for this contact.
+*--given-name* NAME, *--name* NAME::
+New (given) name.
+
+*--family-name* FAMILY_NAME::
+New family name.
 
 *-e*, *--expiration* EXPIRATION_SECONDS::
 Set expiration time of messages (seconds).
index c5305f306a57dfb207565748d42769867534368e..7ff91e9be25e1f5e1a43ddc3b4d2b37513ecebdd 100644 (file)
@@ -26,6 +26,8 @@ public class UpdateContactCommand implements JsonRpcLocalCommand {
         subparser.help("Update the details of a given contact");
         subparser.addArgument("recipient").help("Contact number");
         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)");
     }
 
@@ -42,9 +44,16 @@ public class UpdateContactCommand implements JsonRpcLocalCommand {
                 m.setExpirationTimer(recipient, expiration);
             }
 
-            var name = ns.getString("name");
-            if (name != null) {
-                m.setContactName(recipient, name);
+            var givenName = ns.getString("given-name");
+            var familyName = ns.getString("family-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) {
             throw new IOErrorException("Update contact error: " + e.getMessage(), e);
index 822bb14bf6d008510a02731d2bacaa37fa9f0c6f..9ffb0795343bca9e8a38120cfa25984ae0aee64e 100644 (file)
@@ -409,9 +409,9 @@ public class DbusManagerImpl implements Manager {
 
     @Override
     public void setContactName(
-            final RecipientIdentifier.Single recipient, final String name
+            final RecipientIdentifier.Single recipient, final String givenName, final String familyName
     ) throws NotPrimaryDeviceException {
-        signal.setContactName(recipient.getIdentifier(), name);
+        signal.setContactName(recipient.getIdentifier(), givenName);
     }
 
     @Override
index ce35ef1442f8006c125d25acab6d9f7d113c06d8..d2ac27a987254b699703028489e0ee70af1412cc 100644 (file)
@@ -492,7 +492,7 @@ public class DbusSignalImpl implements Signal {
     @Override
     public void setContactName(final String number, final String name) {
         try {
-            m.setContactName(getSingleRecipientIdentifier(number, m.getSelfNumber()), name);
+            m.setContactName(getSingleRecipientIdentifier(number, m.getSelfNumber()), name, "");
         } catch (NotPrimaryDeviceException e) {
             throw new Error.Failure("This command doesn't work on linked devices.");
         } catch (IOException e) {