- handleNotAGroupMemberException(e);
- return 1;
- } catch (EncapsulatedExceptions e) {
- handleEncapsulatedExceptions(e);
- return 3;
- } catch (GroupIdFormatException e) {
- handleGroupIdFormatException(e);
- return 1;
+ logger.warn("You're not a group member");
+ } catch (InvalidNumberException e) {
+ throw new UserErrorException("Failed to parse member number: " + e.getMessage());
+ } catch (IOException e) {
+ throw new UnexpectedErrorException("Failed to send message: " + e.getMessage());
+ }
+ }
+
+ @Override
+ public void handleCommand(final Namespace ns, final Signal signal) throws CommandException {
+ final var writer = new PlainTextWriterImpl(System.out);
+ byte[] groupId = null;
+ if (ns.getString("group") != null) {
+ try {
+ groupId = Util.decodeGroupId(ns.getString("group")).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) {
+ writer.println("Created new group: \"{}\"", Base64.getEncoder().encodeToString(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());