- try {
- var results = m.sendMessage(new Message(messageText, attachments), recipientIdentifiers);
- outputResult(outputWriter, results.getTimestamp());
- ErrorUtils.handleSendMessageResults(results.getResults());
- } 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());
- }
- }
-
- @Override
- public void handleCommand(
- final Namespace ns, final Signal signal, final OutputWriter outputWriter
- ) throws CommandException {
- final var recipients = ns.<String>getList("recipient");
- final var isEndSession = ns.getBoolean("end-session");
- final var groupIdStrings = ns.<String>getList("group-id");
- final var isNoteToSelf = ns.getBoolean("note-to-self");
-
- final var noRecipients = recipients == null || recipients.isEmpty();
- final var noGroups = groupIdStrings == null || groupIdStrings.isEmpty();
- if ((noRecipients && isEndSession) || (noRecipients && noGroups && !isNoteToSelf)) {
- throw new UserErrorException("No recipients given");
- }
- if (!noRecipients && !noGroups) {
- throw new UserErrorException("You cannot specify recipients by phone number and groups at the same time");
- }
- if (!noRecipients && isNoteToSelf) {
- throw new UserErrorException(
- "You cannot specify recipients by phone number and note to self at the same time");
- }
-
- if (isEndSession) {
- try {
- signal.sendEndSessionMessage(recipients);
- return;
- } catch (Signal.Error.UntrustedIdentity e) {
- throw new UntrustedKeyErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
- .getSimpleName() + ")");
- } catch (DBusExecutionException e) {
- throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
- .getSimpleName() + ")", e);
- }
+ List<String> mentionStrings = ns.getList("mention");
+ final var mentions = mentionStrings == null ? List.<Message.Mention>of() : parseMentions(m, mentionStrings);
+
+ final Message.Quote quote;
+ final var quoteTimestamp = ns.getLong("quote-timestamp");
+ if (quoteTimestamp != null) {
+ final var quoteAuthor = ns.getString("quote-author");
+ final var quoteMessage = ns.getString("quote-message");
+ List<String> quoteMentionStrings = ns.getList("quote-mention");
+ final var quoteMentions = quoteMentionStrings == null
+ ? List.<Message.Mention>of()
+ : parseMentions(m, quoteMentionStrings);
+ quote = new Message.Quote(quoteTimestamp,
+ CommandUtil.getSingleRecipientIdentifier(quoteAuthor, m.getSelfNumber()),
+ quoteMessage == null ? "" : quoteMessage,
+ quoteMentions);
+ } else {
+ quote = null;