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
.manager
.groups
.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").help("Specify the recipient group ID.");
23 subparser
.addArgument("-n", "--name").help("Specify the new group name.");
24 subparser
.addArgument("-a", "--avatar").help("Specify a new group avatar image file");
25 subparser
.addArgument("-m", "--member").nargs("*").help("Specify one or more members to add to the group");
29 public int handleCommand(final Namespace ns
, final Signal signal
) {
30 if (!signal
.isRegistered()) {
31 System
.err
.println("User is not registered.");
35 byte[] groupId
= null;
36 if (ns
.getString("group") != null) {
38 groupId
= Util
.decodeGroupId(ns
.getString("group")).serialize();
39 } catch (GroupIdFormatException e
) {
40 handleGroupIdFormatException(e
);
44 if (groupId
== null) {
45 groupId
= new byte[0];
48 String groupName
= ns
.getString("name");
49 if (groupName
== null) {
53 List
<String
> groupMembers
= ns
.getList("member");
54 if (groupMembers
== null) {
55 groupMembers
= new ArrayList
<>();
58 String groupAvatar
= ns
.getString("avatar");
59 if (groupAvatar
== null) {
64 byte[] newGroupId
= signal
.updateGroup(groupId
, groupName
, groupMembers
, groupAvatar
);
65 if (groupId
.length
!= newGroupId
.length
) {
66 System
.out
.println("Creating new group \"" + Base64
.encodeBytes(newGroupId
) + "\" …");
69 } catch (AssertionError e
) {
70 handleAssertionError(e
);
72 } catch (Signal
.Error
.AttachmentInvalid e
) {
73 System
.err
.println("Failed to add avatar attachment for group\": " + e
.getMessage());
75 } catch (DBusExecutionException e
) {
76 System
.err
.println("Failed to send message: " + e
.getMessage());