mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
parent
d1e760f447
commit
87406e2cdb
6 changed files with 82 additions and 32 deletions
|
@ -1,5 +1,6 @@
|
|||
package org.asamk.signal.commands;
|
||||
|
||||
import net.sourceforge.argparse4j.impl.Arguments;
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
|
@ -14,6 +15,8 @@ import org.asamk.signal.manager.groups.GroupNotFoundException;
|
|||
import org.asamk.signal.manager.groups.LastGroupAdminException;
|
||||
import org.asamk.signal.manager.groups.NotAGroupMemberException;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -24,10 +27,15 @@ import static org.asamk.signal.util.ErrorUtils.handleTimestampAndSendMessageResu
|
|||
|
||||
public class QuitGroupCommand implements LocalCommand {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(QuitGroupCommand.class);
|
||||
|
||||
@Override
|
||||
public void attachToSubparser(final Subparser subparser) {
|
||||
subparser.help("Send a quit group message to all group members and remove self from member list.");
|
||||
subparser.addArgument("-g", "--group").required(true).help("Specify the recipient group ID.");
|
||||
subparser.addArgument("--delete")
|
||||
.action(Arguments.storeTrue())
|
||||
.help("Delete local group data completely after quitting group.");
|
||||
subparser.addArgument("--admin")
|
||||
.nargs("*")
|
||||
.help("Specify one or more members to make a group admin, required if you're currently the only admin.");
|
||||
|
@ -47,12 +55,20 @@ public class QuitGroupCommand implements LocalCommand {
|
|||
var groupAdmins = ns.<String>getList("admin");
|
||||
|
||||
try {
|
||||
final var results = m.sendQuitGroupMessage(groupId,
|
||||
groupAdmins == null ? Set.of() : new HashSet<>(groupAdmins));
|
||||
handleTimestampAndSendMessageResults(writer, results.first(), results.second());
|
||||
try {
|
||||
final var results = m.sendQuitGroupMessage(groupId,
|
||||
groupAdmins == null ? Set.of() : new HashSet<>(groupAdmins));
|
||||
handleTimestampAndSendMessageResults(writer, results.first(), results.second());
|
||||
} catch (NotAGroupMemberException e) {
|
||||
logger.info("User is not a group member");
|
||||
}
|
||||
if (ns.getBoolean("delete")) {
|
||||
logger.debug("Deleting group {}", groupId);
|
||||
m.deleteGroup(groupId);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IOErrorException("Failed to send message: " + e.getMessage());
|
||||
} catch (GroupNotFoundException | NotAGroupMemberException e) {
|
||||
} catch (GroupNotFoundException e) {
|
||||
throw new UserErrorException("Failed to send to group: " + e.getMessage());
|
||||
} catch (InvalidNumberException e) {
|
||||
throw new UserErrorException("Failed to parse admin number: " + e.getMessage());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue