mirror of
https://github.com/AsamK/signal-cli.git
synced 2026-08-12 03:16:22 +00:00
Add terminateGroup command to terminate a group for everyone
Let a group admin permanently terminate a GroupV2 group via the TerminateGroupAction (Groups.proto field 28, change epoch 7) the pinned library already exposes as GroupsV2Operations.createTerminateGroup(). - GroupV2Helper.terminateGroup builds and commits the change - GroupHelper.terminateGroup resolves/refreshes the group (v2 only), sends the update to members and syncs storage, with the same conflict-retry as updateGroup - exposed through Manager.terminateGroup, the terminateGroup CLI/JSON-RPC command and the DBus Group.terminateGroup method
This commit is contained in:
parent
4dfdcf5214
commit
1ba6595a8b
@ -184,6 +184,10 @@ public interface Manager extends Closeable {
|
||||
|
||||
void deleteGroup(GroupId groupId) throws IOException;
|
||||
|
||||
SendGroupMessageResults terminateGroup(
|
||||
GroupId groupId
|
||||
) throws IOException, GroupNotFoundException, NotAGroupMemberException;
|
||||
|
||||
Pair<GroupId, SendGroupMessageResults> createGroup(
|
||||
String name,
|
||||
Set<RecipientIdentifier.Single> members,
|
||||
|
||||
@ -363,6 +363,28 @@ public class GroupHelper {
|
||||
return results;
|
||||
}
|
||||
|
||||
public SendGroupMessageResults terminateGroup(final GroupId groupId) throws IOException, GroupNotFoundException, NotAGroupMemberException {
|
||||
final var group = getGroupForUpdating(groupId);
|
||||
if (!(group instanceof GroupInfoV2)) {
|
||||
throw new IOException("Terminating a group is only supported for Signal group v2 groups.");
|
||||
}
|
||||
|
||||
SendGroupMessageResults results;
|
||||
try {
|
||||
results = terminateGroupV2((GroupInfoV2) group);
|
||||
} catch (ConflictException e) {
|
||||
// Detected conflicting update, refreshing group and trying again
|
||||
results = terminateGroupV2((GroupInfoV2) getGroup(groupId, true));
|
||||
}
|
||||
context.getJobExecutor().enqueueJob(new SyncStorageJob());
|
||||
return results;
|
||||
}
|
||||
|
||||
private SendGroupMessageResults terminateGroupV2(final GroupInfoV2 group) throws IOException {
|
||||
final var groupGroupChangePair = context.getGroupV2Helper().terminateGroup(group);
|
||||
return sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
|
||||
}
|
||||
|
||||
public void updateGroupProfileKey(GroupIdV2 groupId) throws GroupNotFoundException, NotAGroupMemberException, IOException {
|
||||
var group = getGroupForUpdating(groupId);
|
||||
|
||||
|
||||
@ -543,6 +543,14 @@ class GroupV2Helper {
|
||||
return commitChange(groupInfoV2, change);
|
||||
}
|
||||
|
||||
Pair<DecryptedGroup, GroupChangeResponse> terminateGroup(
|
||||
GroupInfoV2 groupInfoV2
|
||||
) throws IOException {
|
||||
final GroupsV2Operations.GroupOperations groupOperations = getGroupOperations(groupInfoV2);
|
||||
final var change = groupOperations.createTerminateGroup();
|
||||
return commitChange(groupInfoV2, change);
|
||||
}
|
||||
|
||||
Pair<DecryptedGroup, GroupChangeResponse> setMemberLabels(
|
||||
GroupInfoV2 groupInfoV2,
|
||||
String labelEmoji,
|
||||
|
||||
@ -610,6 +610,11 @@ public class ManagerImpl implements Manager {
|
||||
context.getGroupHelper().deleteGroup(groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SendGroupMessageResults terminateGroup(GroupId groupId) throws IOException, GroupNotFoundException, NotAGroupMemberException {
|
||||
return context.getGroupHelper().terminateGroup(groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<GroupId, SendGroupMessageResults> createGroup(
|
||||
String name,
|
||||
|
||||
@ -503,6 +503,11 @@ Exceptions: Failure
|
||||
quitGroup() -> <>::
|
||||
Exceptions: Failure, LastGroupAdmin
|
||||
|
||||
terminateGroup() -> <>::
|
||||
Permanently terminate the group for all members (requires admin privileges). Afterwards nobody can send messages or start calls; members keep access to the existing history.
|
||||
|
||||
Exceptions: Failure
|
||||
|
||||
removeAdmins(recipients<as>) -> <>::
|
||||
* recipients : String array of phone numbers
|
||||
|
||||
|
||||
@ -786,6 +786,16 @@ Specify the recipient group ID in base64 encoding.
|
||||
*--delete*::
|
||||
Delete local group data completely after quitting group.
|
||||
|
||||
=== terminateGroup
|
||||
|
||||
Permanently terminate a group for all members.
|
||||
This requires admin privileges.
|
||||
Afterwards no member (not even an admin) can send messages or start calls in the group; members keep access to the existing message history.
|
||||
Only supported for Signal group v2 groups.
|
||||
|
||||
*-g* GROUP, *--group-id* GROUP::
|
||||
Specify the group ID in base64 encoding.
|
||||
|
||||
=== listGroups
|
||||
|
||||
Show a list of known groups and related information.
|
||||
|
||||
@ -612,6 +612,8 @@ public interface Signal extends DBusInterface {
|
||||
|
||||
void deleteGroup() throws Error.Failure;
|
||||
|
||||
void terminateGroup() throws Error.Failure;
|
||||
|
||||
void addMembers(List<String> recipients) throws Error.Failure;
|
||||
|
||||
void removeMembers(List<String> recipients) throws Error.Failure;
|
||||
|
||||
@ -61,6 +61,7 @@ public class Commands {
|
||||
addCommand(new SubmitRateLimitChallengeCommand());
|
||||
addCommand(new StartChangeNumberCommand());
|
||||
addCommand(new StartLinkCommand());
|
||||
addCommand(new TerminateGroupCommand());
|
||||
addCommand(new TrustCommand());
|
||||
addCommand(new UnblockCommand());
|
||||
addCommand(new UnregisterCommand());
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
package org.asamk.signal.commands;
|
||||
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
import org.asamk.signal.commands.exceptions.IOErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.api.GroupNotFoundException;
|
||||
import org.asamk.signal.manager.api.NotAGroupMemberException;
|
||||
import org.asamk.signal.output.OutputWriter;
|
||||
import org.asamk.signal.util.CommandUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.asamk.signal.util.SendMessageResultUtils.outputResult;
|
||||
|
||||
public class TerminateGroupCommand implements JsonRpcLocalCommand {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "terminateGroup";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachToSubparser(final Subparser subparser) {
|
||||
subparser.help(
|
||||
"Permanently terminate a group for all members. Requires admin privileges; afterwards nobody can send messages or start calls.");
|
||||
subparser.addArgument("-g", "--group-id", "--group").required(true).help("Specify the group ID.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCommand(
|
||||
final Namespace ns,
|
||||
final Manager m,
|
||||
final OutputWriter outputWriter
|
||||
) throws CommandException {
|
||||
final var groupId = CommandUtil.getGroupId(ns.getString("group-id"));
|
||||
|
||||
try {
|
||||
final var results = m.terminateGroup(groupId);
|
||||
outputResult(outputWriter, results);
|
||||
} catch (IOException e) {
|
||||
throw new IOErrorException("Failed to send message: "
|
||||
+ e.getMessage()
|
||||
+ " ("
|
||||
+ e.getClass().getSimpleName()
|
||||
+ ")", e);
|
||||
} catch (GroupNotFoundException | NotAGroupMemberException e) {
|
||||
throw new UserErrorException("Failed to terminate group: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -327,6 +327,21 @@ public class DbusManagerImpl implements Manager {
|
||||
group.deleteGroup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SendGroupMessageResults terminateGroup(
|
||||
final GroupId groupId
|
||||
) throws IOException, GroupNotFoundException, NotAGroupMemberException {
|
||||
final var group = getRemoteObject(signal.getGroup(groupId.serialize()), Signal.Group.class);
|
||||
try {
|
||||
group.terminateGroup();
|
||||
} catch (Signal.Error.GroupNotFound e) {
|
||||
throw new GroupNotFoundException(groupId);
|
||||
} catch (Signal.Error.NotAGroupMember e) {
|
||||
throw new NotAGroupMemberException(groupId, group.Get("org.asamk.Signal.Group", "Name"));
|
||||
}
|
||||
return new SendGroupMessageResults(0, List.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<GroupId, SendGroupMessageResults> createGroup(
|
||||
final String name,
|
||||
|
||||
@ -1376,6 +1376,19 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
|
||||
updateGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void terminateGroup() throws Error.Failure {
|
||||
try {
|
||||
m.terminateGroup(groupId);
|
||||
} catch (GroupNotFoundException e) {
|
||||
throw new Error.GroupNotFound(e.getMessage());
|
||||
} catch (NotAGroupMemberException e) {
|
||||
throw new Error.NotAGroupMember(e.getMessage());
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMembers(final List<String> recipients) throws Error.Failure {
|
||||
final var memberIdentifiers = getSingleRecipientIdentifiers(recipients, m.getSelfNumber());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user