- return 0;
- } catch (IOException e) {
- handleIOException(e);
- return 3;
- } catch (EncapsulatedExceptions e) {
- handleEncapsulatedExceptions(e);
- return 3;
- } catch (AssertionError e) {
- handleAssertionError(e);
- return 1;
- } catch (GroupNotFoundException e) {
- handleGroupNotFoundException(e);
- return 1;
- } catch (NotAGroupMemberException e) {
- handleNotAGroupMemberException(e);
- return 1;
- } catch (AttachmentInvalidException e) {
- System.err.println("Failed to add attachment: " + e.getMessage());
- System.err.println("Aborting sending.");
- return 1;
- } catch (DBusExecutionException e) {
- handleDBusExecutionException(e);
- return 1;
- } catch (GroupIdFormatException e) {
- handleGroupIdFormatException(e);
- return 1;
+ }
+
+ try {
+ var results = m.sendMessage(new Message(messageText, attachments, mentions), 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 void outputResult(final OutputWriter outputWriter, final long timestamp) {
+ if (outputWriter instanceof PlainTextWriter writer) {
+ writer.println("{}", timestamp);
+ } else {
+ final var writer = (JsonWriter) outputWriter;
+ writer.write(Map.of("timestamp", timestamp));