-
- var messageText = ns.getString("message");
- if (messageText == null) {
- try {
- messageText = IOUtils.readAll(System.in, Charset.defaultCharset());
- } catch (IOException e) {
- throw new UserErrorException("Failed to read message from stdin: " + e.getMessage());
- }
- }
-
- List<String> attachments = ns.getList("attachment");
- if (attachments == null) {
- attachments = List.of();
- }
-
- if (!noGroups) {
- final var groupIds = CommandUtil.getGroupIds(groupIdStrings);
-
- try {
- long timestamp = 0;
- for (final var groupId : groupIds) {
- timestamp = signal.sendGroupMessage(messageText, attachments, groupId.serialize());
- }
- outputResult(outputWriter, timestamp);
- return;
- } catch (DBusExecutionException e) {
- throw new UnexpectedErrorException("Failed to send group message: " + e.getMessage(), e);
- }
- }
-
- if (isNoteToSelf) {
- try {
- var timestamp = signal.sendNoteToSelfMessage(messageText, attachments);
- outputResult(outputWriter, timestamp);
- 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 note to self message: " + e.getMessage(), e);
- }
- }
-
- try {
- var timestamp = signal.sendMessage(messageText, attachments, recipients);
- outputResult(outputWriter, timestamp);
- } catch (UnknownObject e) {
- throw new UserErrorException("Failed to find dbus object, maybe missing the -u flag: " + e.getMessage());
- } 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);
- }