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
;
7 import org
.asamk
.signal
.util
.GroupIdFormatException
;
8 import org
.asamk
.signal
.util
.Util
;
9 import org
.freedesktop
.dbus
.exceptions
.DBusExecutionException
;
10 import org
.whispersystems
.util
.Base64
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
15 import static org
.asamk
.signal
.util
.ErrorUtils
.handleAssertionError
;
16 import static org
.asamk
.signal
.util
.ErrorUtils
.handleGroupIdFormatException
;
18 public class UpdateGroupCommand
implements DbusCommand
{
21 public void attachToSubparser(final Subparser subparser
) {
22 subparser
.addArgument("-g", "--group")
23 .help("Specify the recipient group ID.");
24 subparser
.addArgument("-n", "--name")
25 .help("Specify the new group name.");
26 subparser
.addArgument("-a", "--avatar")
27 .help("Specify a new group avatar image file");
28 subparser
.addArgument("-m", "--member")
30 .help("Specify one or more members to add to the group");
34 public int handleCommand(final Namespace ns
, final Signal signal
) {
35 if (!signal
.isRegistered()) {
36 System
.err
.println("User is not registered.");
40 byte[] groupId
= null;
41 if (ns
.getString("group") != null) {
43 groupId
= Util
.decodeGroupId(ns
.getString("group"));
44 } catch (GroupIdFormatException e
) {
45 handleGroupIdFormatException(e
);
49 if (groupId
== null) {
50 groupId
= new byte[0];
53 String groupName
= ns
.getString("name");
54 if (groupName
== null) {
58 List
<String
> groupMembers
= ns
.getList("member");
59 if (groupMembers
== null) {
60 groupMembers
= new ArrayList
<>();
63 String groupAvatar
= ns
.getString("avatar");
64 if (groupAvatar
== null) {
69 byte[] newGroupId
= signal
.updateGroup(groupId
, groupName
, groupMembers
, groupAvatar
);
70 if (groupId
.length
!= newGroupId
.length
) {
71 System
.out
.println("Creating new group \"" + Base64
.encodeBytes(newGroupId
) + "\" …");
74 } catch (AssertionError e
) {
75 handleAssertionError(e
);
77 } catch (Signal
.Error
.AttachmentInvalid e
) {
78 System
.err
.println("Failed to add avatar attachment for group\": " + e
.getMessage());
80 } catch (DBusExecutionException e
) {
81 System
.err
.println("Failed to send message: " + e
.getMessage());