1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
4 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
6 import org
.asamk
.signal
.PlainTextWriterImpl
;
7 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
8 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
9 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
10 import org
.asamk
.signal
.manager
.Manager
;
11 import org
.asamk
.signal
.manager
.groups
.GroupId
;
12 import org
.asamk
.signal
.manager
.groups
.GroupIdFormatException
;
13 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
14 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
15 import org
.asamk
.signal
.util
.Util
;
17 import java
.io
.IOException
;
19 import static org
.asamk
.signal
.util
.ErrorUtils
.handleAssertionError
;
20 import static org
.asamk
.signal
.util
.ErrorUtils
.handleTimestampAndSendMessageResults
;
22 public class QuitGroupCommand
implements LocalCommand
{
25 public void attachToSubparser(final Subparser subparser
) {
26 subparser
.addArgument("-g", "--group").required(true).help("Specify the recipient group ID.");
30 public void handleCommand(final Namespace ns
, final Manager m
) throws CommandException
{
31 final var writer
= new PlainTextWriterImpl(System
.out
);
33 final GroupId groupId
;
35 groupId
= Util
.decodeGroupId(ns
.getString("group"));
36 } catch (GroupIdFormatException e
) {
37 throw new UserErrorException("Invalid group id:" + e
.getMessage());
41 final var results
= m
.sendQuitGroupMessage(groupId
);
42 handleTimestampAndSendMessageResults(writer
, results
.first(), results
.second());
43 } catch (IOException e
) {
44 throw new IOErrorException("Failed to send message: " + e
.getMessage());
45 } catch (AssertionError e
) {
46 handleAssertionError(e
);
48 } catch (GroupNotFoundException e
) {
49 throw new UserErrorException("Failed to send to group: " + e
.getMessage());
50 } catch (NotAGroupMemberException e
) {
51 throw new UserErrorException("Failed to send to group: " + e
.getMessage());