-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sendMessageRequestResponse command
- Loading branch information
Showing
11 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/org/asamk/signal/commands/MessageRequestResponseType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/org/asamk/signal/commands/SendMessageRequestResponseCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters