Implement configuring of group link

This commit is contained in:
AsamK 2021-05-15 13:14:12 +02:00
parent 3de30e166f
commit 03589f858b
7 changed files with 121 additions and 5 deletions

View file

@ -0,0 +1,35 @@
package org.asamk.signal;
public enum GroupLinkState {
ENABLED {
@Override
public String toString() {
return "enabled";
}
},
ENABLED_WITH_APPROVAL {
@Override
public String toString() {
return "enabled-with-approval";
}
},
DISABLED {
@Override
public String toString() {
return "disabled";
}
};
public org.asamk.signal.manager.groups.GroupLinkState toLinkState() {
switch (this) {
case ENABLED:
return org.asamk.signal.manager.groups.GroupLinkState.ENABLED;
case ENABLED_WITH_APPROVAL:
return org.asamk.signal.manager.groups.GroupLinkState.ENABLED_WITH_APPROVAL;
case DISABLED:
return org.asamk.signal.manager.groups.GroupLinkState.DISABLED;
default:
throw new AssertionError();
}
}
}

View file

@ -1,9 +1,11 @@
package org.asamk.signal.commands;
import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.Signal;
import org.asamk.signal.GroupLinkState;
import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
@ -46,6 +48,12 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
.nargs("*")
.help("Specify one or more members to remove group admin privileges");
subparser.addArgument("--reset-link")
.action(Arguments.storeTrue())
.help("Reset group link and create new link password");
subparser.addArgument("--link")
.help("Set group link state, with or without admin approval")
.type(Arguments.enumStringType(GroupLinkState.class));
}
@Override
@ -65,16 +73,20 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
var groupDescription = ns.getString("description");
List<String> groupMembers = ns.getList("member");
var groupMembers = ns.<String>getList("member");
List<String> groupRemoveMembers = ns.getList("remove-member");
var groupRemoveMembers = ns.<String>getList("remove-member");
List<String> groupAdmins = ns.getList("admin");
var groupAdmins = ns.<String>getList("admin");
List<String> groupRemoveAdmins = ns.getList("remove-admin");
var groupRemoveAdmins = ns.<String>getList("remove-admin");
var groupAvatar = ns.getString("avatar");
var groupResetLink = ns.getBoolean("reset-link");
var groupLinkState = ns.<GroupLinkState>get("link");
try {
if (groupId == null) {
var results = m.createGroup(groupName,
@ -91,6 +103,8 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
groupRemoveMembers,
groupAdmins,
groupRemoveAdmins,
groupResetLink,
groupLinkState != null ? groupLinkState.toLinkState() : null,
groupAvatar == null ? null : new File(groupAvatar));
ErrorUtils.handleTimestampAndSendMessageResults(writer, results.first(), results.second());
}

View file

@ -347,6 +347,8 @@ public class DbusSignalImpl implements Signal {
null,
null,
null,
false,
null,
avatar == null ? null : new File(avatar));
checkSendMessageResults(results.first(), results.second());
return groupId;