Split createGroup out of updateGroup method

This commit is contained in:
AsamK 2021-05-14 21:21:09 +02:00
parent dd0effc10c
commit 4ebacd0e1f
3 changed files with 133 additions and 108 deletions

View file

@ -62,15 +62,20 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
var groupAvatar = ns.getString("avatar");
try {
var results = m.updateGroup(groupId,
groupName,
groupDescription,
groupMembers,
groupAvatar == null ? null : new File(groupAvatar));
ErrorUtils.handleTimestampAndSendMessageResults(writer, 0, results.second());
final var newGroupId = results.first();
if (groupId == null) {
var results = m.createGroup(groupName,
groupMembers,
groupAvatar == null ? null : new File(groupAvatar));
ErrorUtils.handleTimestampAndSendMessageResults(writer, 0, results.second());
final var newGroupId = results.first();
writer.println("Created new group: \"{}\"", newGroupId.toBase64());
} else {
var results = m.updateGroup(groupId,
groupName,
groupDescription,
groupMembers,
groupAvatar == null ? null : new File(groupAvatar));
ErrorUtils.handleTimestampAndSendMessageResults(writer, results.first(), results.second());
}
} catch (AttachmentInvalidException e) {
throw new UserErrorException("Failed to add avatar attachment for group\": " + e.getMessage());

View file

@ -335,13 +335,19 @@ public class DbusSignalImpl implements Signal {
if (avatar.isEmpty()) {
avatar = null;
}
final var results = m.updateGroup(groupId == null ? null : GroupId.unknownVersion(groupId),
name,
null,
members,
avatar == null ? null : new File(avatar));
checkSendMessageResults(0, results.second());
return results.first().serialize();
if (groupId == null) {
final var results = m.createGroup(name, members, avatar == null ? null : new File(avatar));
checkSendMessageResults(0, results.second());
return results.first().serialize();
} else {
final var results = m.updateGroup(GroupId.unknownVersion(groupId),
name,
null,
members,
avatar == null ? null : new File(avatar));
checkSendMessageResults(results.first(), results.second());
return groupId;
}
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
} catch (GroupNotFoundException | NotAGroupMemberException e) {