mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Implement setting group permissions
This commit is contained in:
parent
7170a68571
commit
78f22c7020
7 changed files with 104 additions and 13 deletions
27
src/main/java/org/asamk/signal/GroupPermission.java
Normal file
27
src/main/java/org/asamk/signal/GroupPermission.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package org.asamk.signal;
|
||||
|
||||
public enum GroupPermission {
|
||||
EVERY_MEMBER {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "every-member";
|
||||
}
|
||||
},
|
||||
ONLY_ADMINS {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "only-admins";
|
||||
}
|
||||
};
|
||||
|
||||
public org.asamk.signal.manager.groups.GroupPermission toManager() {
|
||||
switch (this) {
|
||||
case EVERY_MEMBER:
|
||||
return org.asamk.signal.manager.groups.GroupPermission.EVERY_MEMBER;
|
||||
case ONLY_ADMINS:
|
||||
return org.asamk.signal.manager.groups.GroupPermission.ONLY_ADMINS;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ public class QuitGroupCommand implements LocalCommand {
|
|||
try {
|
||||
groupId = Util.decodeGroupId(ns.getString("group"));
|
||||
} catch (GroupIdFormatException e) {
|
||||
throw new UserErrorException("Invalid group id:" + e.getMessage());
|
||||
throw new UserErrorException("Invalid group id: " + e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -6,6 +6,7 @@ import net.sourceforge.argparse4j.inf.Subparser;
|
|||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.GroupLinkState;
|
||||
import org.asamk.signal.GroupPermission;
|
||||
import org.asamk.signal.PlainTextWriterImpl;
|
||||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
||||
|
@ -55,6 +56,13 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
|||
.help("Set group link state, with or without admin approval")
|
||||
.type(Arguments.enumStringType(GroupLinkState.class));
|
||||
|
||||
subparser.addArgument("--set-permission-add-member")
|
||||
.help("Set permission to add new group members")
|
||||
.type(Arguments.enumStringType(GroupPermission.class));
|
||||
subparser.addArgument("--set-permission-edit-details")
|
||||
.help("Set permission to edit group details")
|
||||
.type(Arguments.enumStringType(GroupPermission.class));
|
||||
|
||||
subparser.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
|
||||
}
|
||||
|
||||
|
@ -67,29 +75,22 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
|||
try {
|
||||
groupId = Util.decodeGroupId(groupIdString);
|
||||
} catch (GroupIdFormatException e) {
|
||||
throw new UserErrorException("Invalid group id:" + e.getMessage());
|
||||
throw new UserErrorException("Invalid group id: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
var groupName = ns.getString("name");
|
||||
|
||||
var groupDescription = ns.getString("description");
|
||||
|
||||
var groupMembers = ns.<String>getList("member");
|
||||
|
||||
var groupRemoveMembers = ns.<String>getList("remove-member");
|
||||
|
||||
var groupAdmins = ns.<String>getList("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");
|
||||
|
||||
var groupExpiration = ns.getInt("expiration");
|
||||
var groupAddMemberPermission = ns.<GroupPermission>get("set-permission-add-member");
|
||||
var groupEditDetailsPermission = ns.<GroupPermission>get("set-permission-edit-details");
|
||||
|
||||
try {
|
||||
if (groupId == null) {
|
||||
|
@ -109,6 +110,8 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
|||
groupRemoveAdmins,
|
||||
groupResetLink,
|
||||
groupLinkState != null ? groupLinkState.toLinkState() : null,
|
||||
groupAddMemberPermission != null ? groupAddMemberPermission.toManager() : null,
|
||||
groupEditDetailsPermission != null ? groupEditDetailsPermission.toManager() : null,
|
||||
groupAvatar == null ? null : new File(groupAvatar),
|
||||
groupExpiration);
|
||||
ErrorUtils.handleTimestampAndSendMessageResults(writer, results.first(), results.second());
|
||||
|
@ -134,7 +137,7 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
|||
try {
|
||||
groupId = Util.decodeGroupId(ns.getString("group")).serialize();
|
||||
} catch (GroupIdFormatException e) {
|
||||
throw new UserErrorException("Invalid group id:" + e.getMessage());
|
||||
throw new UserErrorException("Invalid group id: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
if (groupId == null) {
|
||||
|
|
|
@ -349,6 +349,8 @@ public class DbusSignalImpl implements Signal {
|
|||
null,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
avatar == null ? null : new File(avatar),
|
||||
null);
|
||||
checkSendMessageResults(results.first(), results.second());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue