- @Override
- public void handleCommand(
- final Namespace ns, final Signal signal, final OutputWriter outputWriter
- ) throws CommandException {
- final var recipients = ns.<String>getList("recipient");
- final var groupIdStrings = ns.<String>getList("group-id");
-
- final var noRecipients = recipients == null || recipients.isEmpty();
- final var noGroups = groupIdStrings == null || groupIdStrings.isEmpty();
- if (noRecipients && noGroups) {
- 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");
- }
-
- final var emoji = ns.getString("emoji");
- final var isRemove = ns.getBoolean("remove");
- final var targetAuthor = ns.getString("target-author");
- final var targetTimestamp = ns.getLong("target-timestamp");
-
- try {
- long timestamp = 0;
- if (!noGroups) {
- final var groupIds = CommandUtil.getGroupIds(groupIdStrings);
- for (final var groupId : groupIds) {
- timestamp = signal.sendGroupMessageReaction(emoji,
- isRemove,
- targetAuthor,
- targetTimestamp,
- groupId.serialize());
- }
- } else {
- timestamp = signal.sendMessageReaction(emoji, isRemove, targetAuthor, targetTimestamp, 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.InvalidNumber e) {
- throw new UserErrorException("Invalid number: " + e.getMessage());
- } catch (Signal.Error.GroupNotFound e) {
- throw new UserErrorException("Failed to send to group: " + e.getMessage());
- } catch (DBusExecutionException e) {
- throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
- .getSimpleName() + ")", e);
- }
- }
-