]> nmode's Git Repositories - signal-cli/commitdiff
Refactor selfNumber in send command
authorAsamK <asamk@gmx.de>
Sat, 20 May 2023 11:01:54 +0000 (13:01 +0200)
committerAsamK <asamk@gmx.de>
Sat, 20 May 2023 11:01:54 +0000 (13:01 +0200)
CHANGELOG.md
src/main/java/org/asamk/signal/commands/SendCommand.java

index 6419350ee1c12c3212e38c989ec83d1af7c7165d..df52b7ef94a691140626d42fcb96860557b544dd 100644 (file)
@@ -6,6 +6,9 @@
 ### Added
 - New `--text-style` and `--quote-text-style` flags for `send` command
 
+### Fixed
+- Fixed migration of older account files
+
 ## [0.11.10] - 2023-05-11
 **Attention**: Now requires native libsignal-client version 0.23.1
 
index c10817172e23ee5623de8e7bfb6b010ec63328a7..33777167189c3d8a97879ca29a3794cadba20912 100644 (file)
@@ -150,8 +150,12 @@ public class SendCommand implements JsonRpcLocalCommand {
             attachments = List.of();
         }
 
+        final var selfNumber = m.getSelfNumber();
+
         List<String> mentionStrings = ns.getList("mention");
-        final var mentions = mentionStrings == null ? List.<Message.Mention>of() : parseMentions(m, mentionStrings);
+        final var mentions = mentionStrings == null
+                ? List.<Message.Mention>of()
+                : parseMentions(selfNumber, mentionStrings);
 
         List<String> textStyleStrings = ns.getList("text-style");
         final var textStyles = textStyleStrings == null ? List.<TextStyle>of() : parseTextStyles(textStyleStrings);
@@ -164,13 +168,13 @@ public class SendCommand implements JsonRpcLocalCommand {
             List<String> quoteMentionStrings = ns.getList("quote-mention");
             final var quoteMentions = quoteMentionStrings == null
                     ? List.<Message.Mention>of()
-                    : parseMentions(m, quoteMentionStrings);
+                    : parseMentions(selfNumber, quoteMentionStrings);
             List<String> quoteTextStyleStrings = ns.getList("quote-text-style");
             final var quoteTextStyles = quoteTextStyleStrings == null
                     ? List.<TextStyle>of()
                     : parseTextStyles(quoteTextStyleStrings);
             quote = new Message.Quote(quoteTimestamp,
-                    CommandUtil.getSingleRecipientIdentifier(quoteAuthor, m.getSelfNumber()),
+                    CommandUtil.getSingleRecipientIdentifier(quoteAuthor, selfNumber),
                     quoteMessage == null ? "" : quoteMessage,
                     quoteMentions,
                     quoteTextStyles);
@@ -197,7 +201,7 @@ public class SendCommand implements JsonRpcLocalCommand {
         if (storyReplyTimestamp != null) {
             final var storyAuthor = ns.getString("story-author");
             storyReply = new Message.StoryReply(storyReplyTimestamp,
-                    CommandUtil.getSingleRecipientIdentifier(storyAuthor, m.getSelfNumber()));
+                    CommandUtil.getSingleRecipientIdentifier(storyAuthor, selfNumber));
         } else {
             storyReply = null;
         }
@@ -235,7 +239,7 @@ public class SendCommand implements JsonRpcLocalCommand {
     }
 
     private List<Message.Mention> parseMentions(
-            final Manager m, final List<String> mentionStrings
+            final String selfNumber, final List<String> mentionStrings
     ) throws UserErrorException {
         List<Message.Mention> mentions;
         final Pattern mentionPattern = Pattern.compile("(\\d+):(\\d+):(.+)");
@@ -245,10 +249,11 @@ public class SendCommand implements JsonRpcLocalCommand {
             if (!matcher.matches()) {
                 throw new UserErrorException("Invalid mention syntax ("
                         + mention
-                        + ") expected 'start:end:recipientNumber'");
+                        + ") expected 'start:length:recipientNumber'");
             }
-            mentions.add(new Message.Mention(CommandUtil.getSingleRecipientIdentifier(matcher.group(3),
-                    m.getSelfNumber()), Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))));
+            mentions.add(new Message.Mention(CommandUtil.getSingleRecipientIdentifier(matcher.group(3), selfNumber),
+                    Integer.parseInt(matcher.group(1)),
+                    Integer.parseInt(matcher.group(2))));
         }
         return mentions;
     }