- if (ns.getString("group") != null) {
- byte[] groupId;
- try {
- groupId = Util.decodeGroupId(ns.getString("group"));
- } catch (GroupIdFormatException e) {
- handleGroupIdFormatException(e);
- return 1;
- }
-
- long timestamp = signal.sendGroupMessage(messageText, attachments, groupId);
- System.out.println(timestamp);
- return 0;
+ var results = m.sendMessage(new Message(messageText, attachments, mentions, Optional.ofNullable(quote)),
+ recipientIdentifiers);
+ outputResult(outputWriter, results.timestamp());
+ ErrorUtils.handleSendMessageResults(results.results());
+ } catch (AttachmentInvalidException | IOException e) {
+ throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
+ .getSimpleName() + ")", e);
+ } catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
+ throw new UserErrorException(e.getMessage());
+ }
+ }
+
+ private List<Message.Mention> parseMentions(
+ final Manager m, final List<String> mentionStrings
+ ) throws UserErrorException {
+ List<Message.Mention> mentions;
+ 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'");