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
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Base64
;
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 byte[] groupId
= null;
31 if (ns
.getString("group") != null) {
33 groupId
= Util
.decodeGroupId(ns
.getString("group")).serialize();
34 } catch (GroupIdFormatException e
) {
35 handleGroupIdFormatException(e
);
39 if (groupId
== null) {
40 groupId
= new byte[0];
43 String groupName
= ns
.getString("name");
44 if (groupName
== null) {
48 List
<String
> groupMembers
= ns
.getList("member");
49 if (groupMembers
== null) {
50 groupMembers
= new ArrayList
<>();
53 String groupAvatar
= ns
.getString("avatar");
54 if (groupAvatar
== null) {
59 byte[] newGroupId
= signal
.updateGroup(groupId
, groupName
, groupMembers
, groupAvatar
);
60 if (groupId
.length
!= newGroupId
.length
) {
61 System
.out
.println("Creating new group \"" + Base64
.getEncoder().encodeToString(newGroupId
) + "\" …");
64 } catch (AssertionError e
) {
65 handleAssertionError(e
);
67 } catch (Signal
.Error
.AttachmentInvalid e
) {
68 System
.err
.println("Failed to add avatar attachment for group\": " + e
.getMessage());
70 } catch (DBusExecutionException e
) {
71 System
.err
.println("Failed to send message: " + e
.getMessage());