X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/6826e3cb49f42142d5d3201a7425a2180f496216..a7c9995655d712368cf1e523fab3feecef72d4e2:/src/main/java/org/asamk/signal/commands/UpdateGroupCommand.java diff --git a/src/main/java/org/asamk/signal/commands/UpdateGroupCommand.java b/src/main/java/org/asamk/signal/commands/UpdateGroupCommand.java index 0aa2cf1e..00da38d4 100644 --- a/src/main/java/org/asamk/signal/commands/UpdateGroupCommand.java +++ b/src/main/java/org/asamk/signal/commands/UpdateGroupCommand.java @@ -35,13 +35,14 @@ import java.util.List; public class UpdateGroupCommand implements DbusCommand, JsonRpcLocalCommand { private final static Logger logger = LoggerFactory.getLogger(UpdateGroupCommand.class); - private final OutputWriter outputWriter; - public UpdateGroupCommand(final OutputWriter outputWriter) { - this.outputWriter = outputWriter; + @Override + public String getName() { + return "updateGroup"; } - public static void attachToSubparser(final Subparser subparser) { + @Override + public void attachToSubparser(final Subparser subparser) { subparser.help("Create or update a group."); subparser.addArgument("-g", "--group-id", "--group").help("Specify the group ID."); subparser.addArgument("-n", "--name").help("Specify the new group name."); @@ -69,6 +70,9 @@ public class UpdateGroupCommand implements DbusCommand, JsonRpcLocalCommand { subparser.addArgument("--set-permission-edit-details") .help("Set permission to edit group details") .choices("every-member", "only-admins"); + subparser.addArgument("--set-permission-send-messages") + .help("Set permission to send messages") + .choices("every-member", "only-admins"); subparser.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)"); } @@ -107,7 +111,9 @@ public class UpdateGroupCommand implements DbusCommand, JsonRpcLocalCommand { } @Override - public void handleCommand(final Namespace ns, final Manager m) throws CommandException { + public void handleCommand( + final Namespace ns, final Manager m, final OutputWriter outputWriter + ) throws CommandException { GroupId groupId = null; final var groupIdString = ns.getString("group-id"); if (groupIdString != null) { @@ -130,6 +136,7 @@ public class UpdateGroupCommand implements DbusCommand, JsonRpcLocalCommand { var groupExpiration = ns.getInt("expiration"); var groupAddMemberPermission = getGroupPermission(ns.getString("set-permission-add-member")); var groupEditDetailsPermission = getGroupPermission(ns.getString("set-permission-edit-details")); + var groupSendMessagesPermission = getGroupPermission(ns.getString("set-permission-send-messages")); try { boolean isNewGroup = false; @@ -157,13 +164,16 @@ public class UpdateGroupCommand implements DbusCommand, JsonRpcLocalCommand { groupAddMemberPermission, groupEditDetailsPermission, groupAvatar == null ? null : new File(groupAvatar), - groupExpiration); + groupExpiration, + groupSendMessagesPermission == null + ? null + : groupSendMessagesPermission == GroupPermission.ONLY_ADMINS); Long timestamp = null; if (results != null) { timestamp = results.first(); ErrorUtils.handleSendMessageResults(results.second()); } - outputResult(timestamp, isNewGroup ? groupId : null); + outputResult(outputWriter, timestamp, isNewGroup ? groupId : null); } catch (AttachmentInvalidException e) { throw new UserErrorException("Failed to add avatar attachment for group\": " + e.getMessage()); } catch (GroupNotFoundException e) { @@ -178,7 +188,9 @@ public class UpdateGroupCommand implements DbusCommand, JsonRpcLocalCommand { } @Override - public void handleCommand(final Namespace ns, final Signal signal) throws CommandException { + public void handleCommand( + final Namespace ns, final Signal signal, final OutputWriter outputWriter + ) throws CommandException { byte[] groupId = null; if (ns.getString("group-id") != null) { try { @@ -209,7 +221,7 @@ public class UpdateGroupCommand implements DbusCommand, JsonRpcLocalCommand { try { var newGroupId = signal.updateGroup(groupId, groupName, groupMembers, groupAvatar); if (groupId.length != newGroupId.length) { - outputResult(null, GroupId.unknownVersion(newGroupId)); + outputResult(outputWriter, null, GroupId.unknownVersion(newGroupId)); } } catch (Signal.Error.AttachmentInvalid e) { throw new UserErrorException("Failed to add avatar attachment for group\": " + e.getMessage()); @@ -218,7 +230,7 @@ public class UpdateGroupCommand implements DbusCommand, JsonRpcLocalCommand { } } - private void outputResult(final Long timestamp, final GroupId groupId) { + private void outputResult(final OutputWriter outputWriter, final Long timestamp, final GroupId groupId) { if (outputWriter instanceof PlainTextWriter) { final var writer = (PlainTextWriter) outputWriter; if (groupId != null) {