]> nmode's Git Repositories - signal-cli/commitdiff
Add -u flag to send to username
authorAsamK <asamk@gmx.de>
Thu, 16 Nov 2023 19:36:46 +0000 (20:36 +0100)
committerAsamK <asamk@gmx.de>
Tue, 21 Nov 2023 16:09:21 +0000 (17:09 +0100)
src/main/java/org/asamk/signal/commands/RemoteDeleteCommand.java
src/main/java/org/asamk/signal/commands/SendCommand.java
src/main/java/org/asamk/signal/commands/SendReactionCommand.java
src/main/java/org/asamk/signal/util/CommandUtil.java

index 294fd7c5cd0f4e24cdeb06de61e836c108790e35..1b26396dd88a10f3331f1c647a41e62810eec8d5 100644 (file)
@@ -34,6 +34,7 @@ public class RemoteDeleteCommand implements JsonRpcLocalCommand {
                 .help("Specify the timestamp of the message to delete.");
         subparser.addArgument("-g", "--group-id", "--group").help("Specify the recipient group ID.").nargs("*");
         subparser.addArgument("recipient").help("Specify the recipients' phone number.").nargs("*");
+        subparser.addArgument("-u", "--username").help("Specify the recipient username or username link.").nargs("*");
         subparser.addArgument("--note-to-self").action(Arguments.storeTrue());
     }
 
@@ -43,12 +44,14 @@ public class RemoteDeleteCommand implements JsonRpcLocalCommand {
     ) throws CommandException {
         final var isNoteToSelf = Boolean.TRUE.equals(ns.getBoolean("note-to-self"));
         final var recipientStrings = ns.<String>getList("recipient");
+        final var usernameStrings = ns.<String>getList("username");
         final var groupIdStrings = ns.<String>getList("group-id");
 
         final var recipientIdentifiers = CommandUtil.getRecipientIdentifiers(m,
                 isNoteToSelf,
                 recipientStrings,
-                groupIdStrings);
+                groupIdStrings,
+                usernameStrings);
 
         final long targetTimestamp = ns.getLong("target-timestamp");
 
index 7d9fe78812cc282e91a98987307757f5d1e56302..1d0b46e4a5e8eabc08a5e80b131e347082fa5b0b 100644 (file)
@@ -47,6 +47,7 @@ public class SendCommand implements JsonRpcLocalCommand {
         subparser.help("Send a message to another user or group.");
         subparser.addArgument("recipient").help("Specify the recipients' phone number.").nargs("*");
         subparser.addArgument("-g", "--group-id", "--group").help("Specify the recipient group ID.").nargs("*");
+        subparser.addArgument("-u", "--username").help("Specify the recipient username or username link.").nargs("*");
         subparser.addArgument("--note-to-self")
                 .help("Send the message to self without notification.")
                 .action(Arguments.storeTrue());
@@ -56,6 +57,7 @@ public class SendCommand implements JsonRpcLocalCommand {
         mut.addArgument("--message-from-stdin")
                 .action(Arguments.storeTrue())
                 .help("Read the message from standard input.");
+
         subparser.addArgument("-a", "--attachment")
                 .nargs("*")
                 .help("Add an attachment. "
@@ -106,11 +108,13 @@ public class SendCommand implements JsonRpcLocalCommand {
         final var isNoteToSelf = Boolean.TRUE.equals(ns.getBoolean("note-to-self"));
         final var recipientStrings = ns.<String>getList("recipient");
         final var groupIdStrings = ns.<String>getList("group-id");
+        final var usernameStrings = ns.<String>getList("username");
 
         final var recipientIdentifiers = CommandUtil.getRecipientIdentifiers(m,
                 isNoteToSelf,
                 recipientStrings,
-                groupIdStrings);
+                groupIdStrings,
+                usernameStrings);
 
         final var isEndSession = Boolean.TRUE.equals(ns.getBoolean("end-session"));
         if (isEndSession) {
index 0eafc2fd4768a1b0da76afa21c106bddf33a1e47..56fa81f2b83ff75b2dafe237f9d7aa5705f8a140 100644 (file)
@@ -31,6 +31,7 @@ public class SendReactionCommand implements JsonRpcLocalCommand {
         subparser.help("Send reaction to a previously received or sent message.");
         subparser.addArgument("-g", "--group-id", "--group").help("Specify the recipient group ID.").nargs("*");
         subparser.addArgument("recipient").help("Specify the recipients' phone number.").nargs("*");
+        subparser.addArgument("-u", "--username").help("Specify the recipient username or username link.").nargs("*");
         subparser.addArgument("--note-to-self")
                 .help("Send the reaction to self without notification.")
                 .action(Arguments.storeTrue());
@@ -57,11 +58,13 @@ public class SendReactionCommand implements JsonRpcLocalCommand {
         final var isNoteToSelf = Boolean.TRUE.equals(ns.getBoolean("note-to-self"));
         final var recipientStrings = ns.<String>getList("recipient");
         final var groupIdStrings = ns.<String>getList("group-id");
+        final var usernameStrings = ns.<String>getList("username");
 
         final var recipientIdentifiers = CommandUtil.getRecipientIdentifiers(m,
                 isNoteToSelf,
                 recipientStrings,
-                groupIdStrings);
+                groupIdStrings,
+                usernameStrings);
 
         final var emoji = ns.getString("emoji");
         final var isRemove = Boolean.TRUE.equals(ns.getBoolean("remove"));
index 48decc7a0c68323b83be4fbb2e8f67ac6997df81..039ac2a7f4d06edd36e2a17aacfab4769cfe41d4 100644 (file)
@@ -26,7 +26,8 @@ public class CommandUtil {
             final Manager m,
             final boolean isNoteToSelf,
             final List<String> recipientStrings,
-            final List<String> groupIdStrings
+            final List<String> groupIdStrings,
+            final List<String> usernameStrings
     ) throws UserErrorException {
         final var recipientIdentifiers = new HashSet<RecipientIdentifier>();
         if (isNoteToSelf) {
@@ -39,6 +40,9 @@ public class CommandUtil {
         if (groupIdStrings != null) {
             recipientIdentifiers.addAll(CommandUtil.getGroupIdentifiers(groupIdStrings));
         }
+        if (usernameStrings != null) {
+            recipientIdentifiers.addAll(CommandUtil.getUsernameIdentifiers(usernameStrings));
+        }
 
         if (recipientIdentifiers.isEmpty()) {
             throw new UserErrorException("No recipients given");
@@ -102,6 +106,17 @@ public class CommandUtil {
         }
     }
 
+    public static Set<RecipientIdentifier.Username> getUsernameIdentifiers(Collection<String> usernameIdStrings) {
+        if (usernameIdStrings == null) {
+            return Set.of();
+        }
+        final var usernameIds = new HashSet<RecipientIdentifier.Username>();
+        for (final var usernameIdString : usernameIdStrings) {
+            usernameIds.add(new RecipientIdentifier.Username(usernameIdString));
+        }
+        return usernameIds;
+    }
+
     public static String getCaptchaRequiredMessage(final CaptchaRequiredException e, final boolean captchaProvided) {
         String message;
         if (!captchaProvided) {