- if (isNoteToSelf) {
- try {
- var timestamp = signal.sendNoteToSelfMessage(messageText, attachments);
- System.out.println(timestamp);
- return 0;
- } catch (AssertionError e) {
- handleAssertionError(e);
- return 1;
- } catch (Signal.Error.UntrustedIdentity e) {
- System.err.println("Failed to send message: " + e.getMessage());
- return 4;
- } catch (DBusExecutionException e) {
- System.err.println("Failed to send note to self message: " + e.getMessage());
- return 2;
+ try {
+ 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'");