Add support for banning/unbanning group members

This commit is contained in:
AsamK 2022-04-09 19:01:37 +02:00
parent 69f1d0c213
commit 2a20e70aab
17 changed files with 246 additions and 16 deletions

View file

@ -523,6 +523,7 @@ public interface Signal extends DBusInterface {
@DBusProperty(name = "PendingMembers", type = String[].class, access = DBusProperty.Access.READ)
@DBusProperty(name = "RequestingMembers", type = String[].class, access = DBusProperty.Access.READ)
@DBusProperty(name = "Admins", type = String[].class, access = DBusProperty.Access.READ)
@DBusProperty(name = "Banned", type = String[].class, access = DBusProperty.Access.READ)
@DBusProperty(name = "PermissionAddMember", type = String.class)
@DBusProperty(name = "PermissionEditDetails", type = String.class)
@DBusProperty(name = "PermissionSendMessage", type = String.class)

View file

@ -53,7 +53,7 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
final var groupInviteLink = group.groupInviteLinkUrl();
writer.println(
"Id: {} Name: {} Description: {} Active: {} Blocked: {} Members: {} Pending members: {} Requesting members: {} Admins: {} Message expiration: {} Link: {}",
"Id: {} Name: {} Description: {} Active: {} Blocked: {} Members: {} Pending members: {} Requesting members: {} Admins: {} Banned: {} Message expiration: {} Link: {}",
group.groupId().toBase64(),
group.title(),
group.description(),
@ -63,6 +63,7 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
resolveMembers(group.pendingMembers()),
resolveMembers(group.requestingMembers()),
resolveMembers(group.adminMembers()),
resolveMembers(group.bannedMembers()),
group.messageExpirationTimer() == 0 ? "disabled" : group.messageExpirationTimer() + "s",
groupInviteLink == null ? '-' : groupInviteLink.getUrl());
} else {
@ -95,6 +96,7 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
resolveJsonMembers(group.pendingMembers()),
resolveJsonMembers(group.requestingMembers()),
resolveJsonMembers(group.adminMembers()),
resolveJsonMembers(group.bannedMembers()),
group.permissionAddMember().name(),
group.permissionEditDetails().name(),
group.permissionSendMessage().name(),
@ -122,6 +124,7 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
Set<JsonGroupMember> pendingMembers,
Set<JsonGroupMember> requestingMembers,
Set<JsonGroupMember> admins,
Set<JsonGroupMember> banned,
String permissionAddMember,
String permissionEditDetails,
String permissionSendMessage,

View file

@ -55,6 +55,8 @@ public class UpdateGroupCommand implements JsonRpcLocalCommand {
subparser.addArgument("--remove-admin")
.nargs("*")
.help("Specify one or more members to remove group admin privileges");
subparser.addArgument("--ban").nargs("*").help("Specify one or more members to ban from joining the group");
subparser.addArgument("--unban").nargs("*").help("Specify one or more members to remove from the ban list");
subparser.addArgument("--reset-link")
.action(Arguments.storeTrue())
@ -114,6 +116,8 @@ public class UpdateGroupCommand implements JsonRpcLocalCommand {
var groupRemoveMembers = CommandUtil.getSingleRecipientIdentifiers(ns.getList("remove-member"), localNumber);
var groupAdmins = CommandUtil.getSingleRecipientIdentifiers(ns.getList("admin"), localNumber);
var groupRemoveAdmins = CommandUtil.getSingleRecipientIdentifiers(ns.getList("remove-admin"), localNumber);
var groupBan = CommandUtil.getSingleRecipientIdentifiers(ns.getList("ban"), localNumber);
var groupUnban = CommandUtil.getSingleRecipientIdentifiers(ns.getList("unban"), localNumber);
var groupAvatar = ns.getString("avatar");
var groupResetLink = Boolean.TRUE.equals(ns.getBoolean("reset-link"));
var groupLinkState = getGroupLinkState(ns.getString("link"));
@ -145,6 +149,8 @@ public class UpdateGroupCommand implements JsonRpcLocalCommand {
.withRemoveMembers(groupRemoveMembers)
.withAdmins(groupAdmins)
.withRemoveAdmins(groupRemoveAdmins)
.withBanMembers(groupBan)
.withUnbanMembers(groupUnban)
.withResetGroupLink(groupResetLink)
.withGroupLinkState(groupLinkState)
.withAddMemberPermission(groupAddMemberPermission)

View file

@ -583,6 +583,9 @@ public class DbusManagerImpl implements Manager {
((List<String>) group.get("Admins").getValue()).stream()
.map(m -> new RecipientAddress(null, m))
.collect(Collectors.toSet()),
((List<String>) group.get("Banned").getValue()).stream()
.map(m -> new RecipientAddress(null, m))
.collect(Collectors.toSet()),
(boolean) group.get("IsBlocked").getValue(),
(int) group.get("MessageExpirationTimer").getValue(),
GroupPermission.valueOf((String) group.get("PermissionAddMember").getValue()),

View file

@ -1162,6 +1162,8 @@ public class DbusSignalImpl implements Signal {
() -> new Variant<>(getRecipientStrings(getGroup().requestingMembers()), "as")),
new DbusProperty<>("Admins",
() -> new Variant<>(getRecipientStrings(getGroup().adminMembers()), "as")),
new DbusProperty<>("Banned",
() -> new Variant<>(getRecipientStrings(getGroup().bannedMembers()), "as")),
new DbusProperty<>("PermissionAddMember",
() -> getGroup().permissionAddMember().name(),
this::setGroupPermissionAddMember),