mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
parent
76942ea458
commit
e3752e733a
5 changed files with 95 additions and 4 deletions
|
@ -4,6 +4,7 @@ import org.asamk.signal.manager.groups.GroupIdV1;
|
||||||
import org.asamk.signal.manager.storage.recipients.RecipientId;
|
import org.asamk.signal.manager.storage.recipients.RecipientId;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
interface HandleAction {
|
interface HandleAction {
|
||||||
|
@ -23,7 +24,7 @@ class SendReceiptAction implements HandleAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Manager m) throws Throwable {
|
public void execute(Manager m) throws Throwable {
|
||||||
m.sendReceipt(address, timestamp);
|
m.sendDeliveryReceipt(address, List.of(timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1191,11 +1191,31 @@ public class Manager implements Closeable {
|
||||||
return sendHelper.sendGroupMessage(messageBuilder.build(), Set.of(resolveRecipient(recipient)));
|
return sendHelper.sendGroupMessage(messageBuilder.build(), Set.of(resolveRecipient(recipient)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendReceipt(
|
public void sendReadReceipt(
|
||||||
SignalServiceAddress remoteAddress, long messageId
|
String sender, List<Long> messageIds
|
||||||
|
) throws IOException, UntrustedIdentityException, InvalidNumberException {
|
||||||
|
var receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.READ,
|
||||||
|
messageIds,
|
||||||
|
System.currentTimeMillis());
|
||||||
|
|
||||||
|
sendHelper.sendReceiptMessage(receiptMessage, canonicalizeAndResolveRecipient(sender));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendViewedReceipt(
|
||||||
|
String sender, List<Long> messageIds
|
||||||
|
) throws IOException, UntrustedIdentityException, InvalidNumberException {
|
||||||
|
var receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.VIEWED,
|
||||||
|
messageIds,
|
||||||
|
System.currentTimeMillis());
|
||||||
|
|
||||||
|
sendHelper.sendReceiptMessage(receiptMessage, canonicalizeAndResolveRecipient(sender));
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendDeliveryReceipt(
|
||||||
|
SignalServiceAddress remoteAddress, List<Long> messageIds
|
||||||
) throws IOException, UntrustedIdentityException {
|
) throws IOException, UntrustedIdentityException {
|
||||||
var receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.DELIVERY,
|
var receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.DELIVERY,
|
||||||
List.of(messageId),
|
messageIds,
|
||||||
System.currentTimeMillis());
|
System.currentTimeMillis());
|
||||||
|
|
||||||
sendHelper.sendReceiptMessage(receiptMessage, resolveRecipient(remoteAddress));
|
sendHelper.sendReceiptMessage(receiptMessage, resolveRecipient(remoteAddress));
|
||||||
|
|
|
@ -199,6 +199,19 @@ Specify the timestamp of the message to which to react.
|
||||||
*-r*, *--remove*::
|
*-r*, *--remove*::
|
||||||
Remove a reaction.
|
Remove a reaction.
|
||||||
|
|
||||||
|
=== sendReceipt
|
||||||
|
|
||||||
|
Send a read or viewed receipt to a previously received message.
|
||||||
|
|
||||||
|
RECIPIENT::
|
||||||
|
Specify the sender’s phone number.
|
||||||
|
|
||||||
|
*-t* TIMESTAMP, *--target-timestamp* TIMESTAMP::
|
||||||
|
Specify the timestamp of the message to which to react.
|
||||||
|
|
||||||
|
*--type* TYPE::
|
||||||
|
Specify the receipt type, either `read` (the default) or `viewed`.
|
||||||
|
|
||||||
=== sendTyping
|
=== sendTyping
|
||||||
|
|
||||||
Send typing message to trigger a typing indicator for the recipient.
|
Send typing message to trigger a typing indicator for the recipient.
|
||||||
|
|
|
@ -30,6 +30,7 @@ public class Commands {
|
||||||
addCommand(new SendCommand());
|
addCommand(new SendCommand());
|
||||||
addCommand(new SendContactsCommand());
|
addCommand(new SendContactsCommand());
|
||||||
addCommand(new SendReactionCommand());
|
addCommand(new SendReactionCommand());
|
||||||
|
addCommand(new SendReceiptCommand());
|
||||||
addCommand(new SendSyncRequestCommand());
|
addCommand(new SendSyncRequestCommand());
|
||||||
addCommand(new SendTypingCommand());
|
addCommand(new SendTypingCommand());
|
||||||
addCommand(new SetPinCommand());
|
addCommand(new SetPinCommand());
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
package org.asamk.signal.commands;
|
||||||
|
|
||||||
|
import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
|
import net.sourceforge.argparse4j.inf.Subparser;
|
||||||
|
|
||||||
|
import org.asamk.signal.OutputWriter;
|
||||||
|
import org.asamk.signal.commands.exceptions.CommandException;
|
||||||
|
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||||
|
import org.asamk.signal.manager.Manager;
|
||||||
|
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
||||||
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class SendReceiptCommand implements JsonRpcLocalCommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "sendReceipt";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attachToSubparser(final Subparser subparser) {
|
||||||
|
subparser.help("Send a read or viewed receipt to a previously received message.");
|
||||||
|
subparser.addArgument("recipient").help("Specify the sender's phone number.").required(true);
|
||||||
|
subparser.addArgument("-t", "--target-timestamp")
|
||||||
|
.type(long.class)
|
||||||
|
.nargs("+")
|
||||||
|
.help("Specify the timestamp of the messages for which a receipt should be sent.");
|
||||||
|
subparser.addArgument("--type").help("Specify the receipt type.").choices("read", "viewed").setDefault("read");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleCommand(
|
||||||
|
final Namespace ns, final Manager m, final OutputWriter outputWriter
|
||||||
|
) throws CommandException {
|
||||||
|
final var recipient = ns.getString("recipient");
|
||||||
|
|
||||||
|
final var targetTimestamps = ns.<Long>getList("target-timestamp");
|
||||||
|
final var type = ns.getString("type");
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ("read".equals(type)) {
|
||||||
|
m.sendReadReceipt(recipient, targetTimestamps);
|
||||||
|
} else if ("viewed".equals(type)) {
|
||||||
|
m.sendViewedReceipt(recipient, targetTimestamps);
|
||||||
|
} else {
|
||||||
|
throw new UserErrorException("Unknown receipt type: " + type);
|
||||||
|
}
|
||||||
|
} catch (IOException | UntrustedIdentityException e) {
|
||||||
|
throw new UserErrorException("Failed to send message: " + e.getMessage());
|
||||||
|
} catch (InvalidNumberException e) {
|
||||||
|
throw new UserErrorException("Invalid number: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue