X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/7b809c6547b0d473c1d03e9fac0fd501cde45a5b..6f5e72119e0c996f1efefecda11e33422d44a171:/src/main/java/org/asamk/signal/commands/JoinGroupCommand.java diff --git a/src/main/java/org/asamk/signal/commands/JoinGroupCommand.java b/src/main/java/org/asamk/signal/commands/JoinGroupCommand.java index e5a872e0..1e06ea9c 100644 --- a/src/main/java/org/asamk/signal/commands/JoinGroupCommand.java +++ b/src/main/java/org/asamk/signal/commands/JoinGroupCommand.java @@ -23,19 +23,21 @@ import static org.asamk.signal.util.ErrorUtils.handleSendMessageResults; public class JoinGroupCommand implements JsonRpcLocalCommand { - private final OutputWriter outputWriter; - - public JoinGroupCommand(final OutputWriter outputWriter) { - this.outputWriter = outputWriter; + @Override + public String getName() { + return "joinGroup"; } - public static void attachToSubparser(final Subparser subparser) { + @Override + public void attachToSubparser(final Subparser subparser) { subparser.help("Join a group via an invitation link."); subparser.addArgument("--uri").required(true).help("Specify the uri with the group invitation link."); } @Override - public void handleCommand(final Namespace ns, final Manager m) throws CommandException { + public void handleCommand( + final Namespace ns, final Manager m, final OutputWriter outputWriter + ) throws CommandException { final GroupInviteLinkUrl linkUrl; var uri = ns.getString("uri"); try { @@ -55,26 +57,31 @@ public class JoinGroupCommand implements JsonRpcLocalCommand { var newGroupId = results.first(); if (outputWriter instanceof JsonWriter) { final var writer = (JsonWriter) outputWriter; - if (!m.getGroup(newGroupId).isMember(m.getSelfRecipientId())) { + if (!m.getGroup(newGroupId).isMember()) { writer.write(Map.of("groupId", newGroupId.toBase64(), "onlyRequested", true)); } else { writer.write(Map.of("groupId", newGroupId.toBase64())); } } else { final var writer = (PlainTextWriter) outputWriter; - if (!m.getGroup(newGroupId).isMember(m.getSelfRecipientId())) { + if (!m.getGroup(newGroupId).isMember()) { writer.println("Requested to join group \"{}\"", newGroupId.toBase64()); } else { writer.println("Joined group \"{}\"", newGroupId.toBase64()); } } - handleSendMessageResults(results.second()); + handleSendMessageResults(results.second().getResults()); } catch (GroupPatchNotAcceptedException e) { throw new UserErrorException("Failed to join group, maybe already a member"); } catch (IOException e) { - throw new IOErrorException("Failed to send message: " + e.getMessage()); + throw new IOErrorException("Failed to send message: " + + e.getMessage() + + " (" + + e.getClass().getSimpleName() + + ")", e); } catch (DBusExecutionException e) { - throw new UnexpectedErrorException("Failed to send message: " + e.getMessage()); + throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass() + .getSimpleName() + ")", e); } catch (GroupLinkNotActiveException e) { throw new UserErrorException("Group link is not valid: " + e.getMessage()); }