Refactor selfNumber in send command

This commit is contained in:
AsamK 2023-05-20 13:01:54 +02:00
parent 91700ce995
commit 314b3cafbb
2 changed files with 16 additions and 8 deletions

View file

@ -6,6 +6,9 @@
### Added ### Added
- New `--text-style` and `--quote-text-style` flags for `send` command - New `--text-style` and `--quote-text-style` flags for `send` command
### Fixed
- Fixed migration of older account files
## [0.11.10] - 2023-05-11 ## [0.11.10] - 2023-05-11
**Attention**: Now requires native libsignal-client version 0.23.1 **Attention**: Now requires native libsignal-client version 0.23.1

View file

@ -150,8 +150,12 @@ public class SendCommand implements JsonRpcLocalCommand {
attachments = List.of(); attachments = List.of();
} }
final var selfNumber = m.getSelfNumber();
List<String> mentionStrings = ns.getList("mention"); 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"); List<String> textStyleStrings = ns.getList("text-style");
final var textStyles = textStyleStrings == null ? List.<TextStyle>of() : parseTextStyles(textStyleStrings); 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"); List<String> quoteMentionStrings = ns.getList("quote-mention");
final var quoteMentions = quoteMentionStrings == null final var quoteMentions = quoteMentionStrings == null
? List.<Message.Mention>of() ? List.<Message.Mention>of()
: parseMentions(m, quoteMentionStrings); : parseMentions(selfNumber, quoteMentionStrings);
List<String> quoteTextStyleStrings = ns.getList("quote-text-style"); List<String> quoteTextStyleStrings = ns.getList("quote-text-style");
final var quoteTextStyles = quoteTextStyleStrings == null final var quoteTextStyles = quoteTextStyleStrings == null
? List.<TextStyle>of() ? List.<TextStyle>of()
: parseTextStyles(quoteTextStyleStrings); : parseTextStyles(quoteTextStyleStrings);
quote = new Message.Quote(quoteTimestamp, quote = new Message.Quote(quoteTimestamp,
CommandUtil.getSingleRecipientIdentifier(quoteAuthor, m.getSelfNumber()), CommandUtil.getSingleRecipientIdentifier(quoteAuthor, selfNumber),
quoteMessage == null ? "" : quoteMessage, quoteMessage == null ? "" : quoteMessage,
quoteMentions, quoteMentions,
quoteTextStyles); quoteTextStyles);
@ -197,7 +201,7 @@ public class SendCommand implements JsonRpcLocalCommand {
if (storyReplyTimestamp != null) { if (storyReplyTimestamp != null) {
final var storyAuthor = ns.getString("story-author"); final var storyAuthor = ns.getString("story-author");
storyReply = new Message.StoryReply(storyReplyTimestamp, storyReply = new Message.StoryReply(storyReplyTimestamp,
CommandUtil.getSingleRecipientIdentifier(storyAuthor, m.getSelfNumber())); CommandUtil.getSingleRecipientIdentifier(storyAuthor, selfNumber));
} else { } else {
storyReply = null; storyReply = null;
} }
@ -235,7 +239,7 @@ public class SendCommand implements JsonRpcLocalCommand {
} }
private List<Message.Mention> parseMentions( private List<Message.Mention> parseMentions(
final Manager m, final List<String> mentionStrings final String selfNumber, final List<String> mentionStrings
) throws UserErrorException { ) throws UserErrorException {
List<Message.Mention> mentions; List<Message.Mention> mentions;
final Pattern mentionPattern = Pattern.compile("(\\d+):(\\d+):(.+)"); final Pattern mentionPattern = Pattern.compile("(\\d+):(\\d+):(.+)");
@ -245,10 +249,11 @@ public class SendCommand implements JsonRpcLocalCommand {
if (!matcher.matches()) { if (!matcher.matches()) {
throw new UserErrorException("Invalid mention syntax (" throw new UserErrorException("Invalid mention syntax ("
+ mention + mention
+ ") expected 'start:end:recipientNumber'"); + ") expected 'start:length:recipientNumber'");
} }
mentions.add(new Message.Mention(CommandUtil.getSingleRecipientIdentifier(matcher.group(3), mentions.add(new Message.Mention(CommandUtil.getSingleRecipientIdentifier(matcher.group(3), selfNumber),
m.getSelfNumber()), Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)))); Integer.parseInt(matcher.group(1)),
Integer.parseInt(matcher.group(2))));
} }
return mentions; return mentions;
} }