- if (groupIdString != null) {
- byte[] groupId;
- try {
- groupId = Util.decodeGroupId(groupIdString).serialize();
- } catch (GroupIdFormatException e) {
- throw new UserErrorException("Invalid group id: " + e.getMessage());
- }
-
- try {
- var timestamp = signal.sendGroupMessage(messageText, attachments, groupId);
- outputResult(timestamp);
- return;
- } catch (DBusExecutionException e) {
- throw new UnexpectedErrorException("Failed to send group message: " + e.getMessage());
- }
- }
-
- if (isNoteToSelf) {
- try {
- var timestamp = signal.sendNoteToSelfMessage(messageText, attachments);
- outputResult(timestamp);
- return;
- } catch (Signal.Error.UntrustedIdentity e) {
- throw new UntrustedKeyErrorException("Failed to send message: " + e.getMessage());
- } catch (DBusExecutionException e) {
- throw new UnexpectedErrorException("Failed to send note to self message: " + e.getMessage());
+ List<String> mentionStrings = ns.getList("mention");
+ List<Message.Mention> mentions;
+ if (mentionStrings == null) {
+ mentions = List.of();
+ } else {
+ final Pattern mentionPattern = Pattern.compile("([0-9]+):([0-9]+):(.+)");
+ mentions = new ArrayList<>();
+ for (final var mention : mentionStrings) {
+ final var matcher = mentionPattern.matcher(mention);
+ if (!matcher.matches()) {
+ throw new UserErrorException("Invalid mention syntax ("
+ + mention
+ + ") expected 'start:end:recipientNumber'");
+ }
+ mentions.add(new Message.Mention(CommandUtil.getSingleRecipientIdentifier(matcher.group(3),
+ m.getSelfNumber()), Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))));