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
.LastGroupAdminException
;
15 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
16 import org
.asamk
.signal
.util
.Util
;
17 import org
.whispersystems
.signalservice
.api
.util
.InvalidNumberException
;
19 import java
.io
.IOException
;
20 import java
.util
.HashSet
;
23 import static org
.asamk
.signal
.util
.ErrorUtils
.handleTimestampAndSendMessageResults
;
25 public class QuitGroupCommand
implements LocalCommand
{
28 public void attachToSubparser(final Subparser subparser
) {
29 subparser
.help("Send a quit group message to all group members and remove self from member list.");
30 subparser
.addArgument("-g", "--group").required(true).help("Specify the recipient group ID.");
31 subparser
.addArgument("--admin")
33 .help("Specify one or more members to make a group admin, required if you're currently the only admin.");
37 public void handleCommand(final Namespace ns
, final Manager m
) throws CommandException
{
38 final var writer
= new PlainTextWriterImpl(System
.out
);
40 final GroupId groupId
;
42 groupId
= Util
.decodeGroupId(ns
.getString("group"));
43 } catch (GroupIdFormatException e
) {
44 throw new UserErrorException("Invalid group id: " + e
.getMessage());
47 var groupAdmins
= ns
.<String
>getList("admin");
50 final var results
= m
.sendQuitGroupMessage(groupId
,
51 groupAdmins
== null ? Set
.of() : new HashSet
<>(groupAdmins
));
52 handleTimestampAndSendMessageResults(writer
, results
.first(), results
.second());
53 } catch (IOException e
) {
54 throw new IOErrorException("Failed to send message: " + e
.getMessage());
55 } catch (GroupNotFoundException
| NotAGroupMemberException e
) {
56 throw new UserErrorException("Failed to send to group: " + e
.getMessage());
57 } catch (InvalidNumberException e
) {
58 throw new UserErrorException("Failed to parse admin number: " + e
.getMessage());
59 } catch (LastGroupAdminException e
) {
60 throw new UserErrorException("You need to specify a new admin with --admin: " + e
.getMessage());