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
.addArgument("-g", "--group").required(true).help("Specify the recipient group ID.");
30 subparser
.addArgument("--admin")
32 .help("Specify one or more members to make a group admin, required if you're currently the only admin.");
36 public void handleCommand(final Namespace ns
, final Manager m
) throws CommandException
{
37 final var writer
= new PlainTextWriterImpl(System
.out
);
39 final GroupId groupId
;
41 groupId
= Util
.decodeGroupId(ns
.getString("group"));
42 } catch (GroupIdFormatException e
) {
43 throw new UserErrorException("Invalid group id: " + e
.getMessage());
46 var groupAdmins
= ns
.<String
>getList("admin");
49 final var results
= m
.sendQuitGroupMessage(groupId
,
50 groupAdmins
== null ? Set
.of() : new HashSet
<>(groupAdmins
));
51 handleTimestampAndSendMessageResults(writer
, results
.first(), results
.second());
52 } catch (IOException e
) {
53 throw new IOErrorException("Failed to send message: " + e
.getMessage());
54 } catch (GroupNotFoundException
| NotAGroupMemberException e
) {
55 throw new UserErrorException("Failed to send to group: " + e
.getMessage());
56 } catch (InvalidNumberException e
) {
57 throw new UserErrorException("Failed to parse admin number: " + e
.getMessage());
58 } catch (LastGroupAdminException e
) {
59 throw new UserErrorException("You need to specify a new admin with --admin: " + e
.getMessage());