- @Override
- public void handleCommand(
- final Namespace ns, final Signal signal, final OutputWriter outputWriter
- ) throws CommandException {
- byte[] groupId = null;
- if (ns.getString("group-id") != null) {
- try {
- groupId = Util.decodeGroupId(ns.getString("group-id")).serialize();
- } catch (GroupIdFormatException e) {
- throw new UserErrorException("Invalid group id: " + e.getMessage());
- }
- }
- if (groupId == null) {
- groupId = new byte[0];
- }
-
- var groupName = ns.getString("name");
- if (groupName == null) {
- groupName = "";
- }
-
- List<String> groupMembers = ns.getList("member");
- if (groupMembers == null) {
- groupMembers = new ArrayList<>();
- }
-
- var groupAvatar = ns.getString("avatar");
- if (groupAvatar == null) {
- groupAvatar = "";
- }
-
- try {
- var newGroupId = signal.updateGroup(groupId, groupName, groupMembers, groupAvatar);
- if (groupId.length != newGroupId.length) {
- outputResult(outputWriter, null, GroupId.unknownVersion(newGroupId));
- }
- } catch (Signal.Error.AttachmentInvalid e) {
- throw new UserErrorException("Failed to add avatar attachment for group\": " + e.getMessage());
- } catch (DBusExecutionException e) {
- throw new UnexpectedErrorException("Failed to send message: " + e.getMessage());
- }
- }
-
- private void outputResult(final OutputWriter outputWriter, final Long timestamp, final GroupId groupId) {
- if (outputWriter instanceof PlainTextWriter) {
- final var writer = (PlainTextWriter) outputWriter;