Add sendMessageRequestResponse command

This commit is contained in:
AsamK 2024-02-18 20:37:20 +01:00
parent 2c0ad7feb7
commit d84362eb0f
11 changed files with 210 additions and 0 deletions

View file

@ -39,6 +39,7 @@ public class Commands {
addCommand(new RemoteDeleteCommand());
addCommand(new SendCommand());
addCommand(new SendContactsCommand());
addCommand(new SendMessageRequestResponseCommand());
addCommand(new SendPaymentNotificationCommand());
addCommand(new SendReactionCommand());
addCommand(new SendReceiptCommand());

View file

@ -0,0 +1,16 @@
package org.asamk.signal.commands;
enum MessageRequestResponseType {
ACCEPT {
@Override
public String toString() {
return "accept";
}
},
DELETE {
@Override
public String toString() {
return "delete";
}
}
}

View file

@ -0,0 +1,49 @@
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.commands.exceptions.CommandException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.MessageEnvelope.Sync.MessageRequestResponse.Type;
import org.asamk.signal.output.OutputWriter;
import org.asamk.signal.util.CommandUtil;
public class SendMessageRequestResponseCommand implements JsonRpcLocalCommand {
@Override
public String getName() {
return "sendMessageRequestResponse";
}
@Override
public void attachToSubparser(final Subparser subparser) {
subparser.help("Send response to a message request to linked devices.");
subparser.addArgument("-g", "--group-id", "--group").help("Specify the recipient group ID.").nargs("*");
subparser.addArgument("recipient").help("Specify the recipients' phone number.").nargs("*");
subparser.addArgument("-u", "--username").help("Specify the recipient username or username link.").nargs("*");
subparser.addArgument("--type")
.help("Type of message request response")
.type(Arguments.enumStringType(MessageRequestResponseType.class))
.required(true);
}
@Override
public void handleCommand(
final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException {
final var recipientStrings = ns.<String>getList("recipient");
final var groupIdStrings = ns.<String>getList("group-id");
final var usernameStrings = ns.<String>getList("username");
final var type = ns.<MessageRequestResponseType>get("type");
final var recipientIdentifiers = CommandUtil.getRecipientIdentifiers(m,
false,
recipientStrings,
groupIdStrings,
usernameStrings);
m.sendMessageRequestResponse(type == MessageRequestResponseType.ACCEPT ? Type.ACCEPT : Type.DELETE,
recipientIdentifiers);
}
}

View file

@ -472,6 +472,14 @@ public class DbusManagerImpl implements Manager {
return new SendMessageResults(0, Map.of());
}
@Override
public SendMessageResults sendMessageRequestResponse(
final MessageEnvelope.Sync.MessageRequestResponse.Type type,
final Set<RecipientIdentifier> recipientIdentifiers
) {
throw new UnsupportedOperationException();
}
public void hideRecipient(final RecipientIdentifier.Single recipient) {
throw new UnsupportedOperationException();
}