mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
parent
89f568dd1f
commit
53b84bad02
5 changed files with 47 additions and 5 deletions
|
@ -683,6 +683,16 @@ public class ManagerImpl implements Manager {
|
||||||
if (attachments != null) {
|
if (attachments != null) {
|
||||||
messageBuilder.withAttachments(attachmentHelper.uploadAttachments(attachments));
|
messageBuilder.withAttachments(attachmentHelper.uploadAttachments(attachments));
|
||||||
}
|
}
|
||||||
|
if (message.mentions().size() > 0) {
|
||||||
|
final var mentions = new ArrayList<SignalServiceDataMessage.Mention>();
|
||||||
|
for (final var m : message.mentions()) {
|
||||||
|
final var recipientId = resolveRecipient(m.recipient());
|
||||||
|
mentions.add(new SignalServiceDataMessage.Mention(resolveSignalServiceAddress(recipientId).getAci(),
|
||||||
|
m.start(),
|
||||||
|
m.length()));
|
||||||
|
}
|
||||||
|
messageBuilder.withMentions(mentions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,4 +2,7 @@ package org.asamk.signal.manager.api;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record Message(String messageText, List<String> attachments) {}
|
public record Message(String messageText, List<String> attachments, List<Mention> mentions) {
|
||||||
|
|
||||||
|
public record Mention(RecipientIdentifier.Single recipient, int start, int length) {}
|
||||||
|
}
|
||||||
|
|
|
@ -205,6 +205,11 @@ Send the message to self without notification.
|
||||||
*-e*, *--end-session*::
|
*-e*, *--end-session*::
|
||||||
Clear session state and send end session message.
|
Clear session state and send end session message.
|
||||||
|
|
||||||
|
*--mention*::
|
||||||
|
Mention another group member (syntax: start:length:recipientNumber)
|
||||||
|
In the apps the mention replaces part of the message text, which is specified by the start and length values.
|
||||||
|
e.g.: `-m "Hi X!" --mention "3:1:+123456789"`
|
||||||
|
|
||||||
=== sendReaction
|
=== sendReaction
|
||||||
|
|
||||||
Send reaction to a previously received or sent message.
|
Send reaction to a previously received or sent message.
|
||||||
|
|
|
@ -25,8 +25,10 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SendCommand implements JsonRpcLocalCommand {
|
public class SendCommand implements JsonRpcLocalCommand {
|
||||||
|
@ -52,6 +54,9 @@ public class SendCommand implements JsonRpcLocalCommand {
|
||||||
subparser.addArgument("-e", "--end-session", "--endsession")
|
subparser.addArgument("-e", "--end-session", "--endsession")
|
||||||
.help("Clear session state and send end session message.")
|
.help("Clear session state and send end session message.")
|
||||||
.action(Arguments.storeTrue());
|
.action(Arguments.storeTrue());
|
||||||
|
subparser.addArgument("--mention")
|
||||||
|
.nargs("*")
|
||||||
|
.help("Mention another group member (syntax: start:length:recipientNumber)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -100,8 +105,27 @@ public class SendCommand implements JsonRpcLocalCommand {
|
||||||
attachments = List.of();
|
attachments = List.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<String> mentionStrings = ns.getList("mention");
|
||||||
|
List<Message.Mention> mentions;
|
||||||
|
if (mentionStrings == null) {
|
||||||
|
mentions = List.of();
|
||||||
|
} else {
|
||||||
|
final Pattern mentionPattern = Pattern.compile("([0-9]+):([0-9]+):(.+)");
|
||||||
|
mentions = new ArrayList<>();
|
||||||
|
for (final var mention : mentionStrings) {
|
||||||
|
final var matcher = mentionPattern.matcher(mention);
|
||||||
|
if (!matcher.matches()) {
|
||||||
|
throw new UserErrorException("Invalid mention syntax ("
|
||||||
|
+ mention
|
||||||
|
+ ") expected 'start:end:recipientNumber'");
|
||||||
|
}
|
||||||
|
mentions.add(new Message.Mention(CommandUtil.getSingleRecipientIdentifier(matcher.group(3),
|
||||||
|
m.getSelfNumber()), Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var results = m.sendMessage(new Message(messageText, attachments), recipientIdentifiers);
|
var results = m.sendMessage(new Message(messageText, attachments, mentions), recipientIdentifiers);
|
||||||
outputResult(outputWriter, results.timestamp());
|
outputResult(outputWriter, results.timestamp());
|
||||||
ErrorUtils.handleSendMessageResults(results.results());
|
ErrorUtils.handleSendMessageResults(results.results());
|
||||||
} catch (AttachmentInvalidException | IOException e) {
|
} catch (AttachmentInvalidException | IOException e) {
|
||||||
|
|
|
@ -201,7 +201,7 @@ public class DbusSignalImpl implements Signal {
|
||||||
@Override
|
@Override
|
||||||
public long sendMessage(final String message, final List<String> attachments, final List<String> recipients) {
|
public long sendMessage(final String message, final List<String> attachments, final List<String> recipients) {
|
||||||
try {
|
try {
|
||||||
final var results = m.sendMessage(new Message(message, attachments),
|
final var results = m.sendMessage(new Message(message, attachments, List.of()),
|
||||||
getSingleRecipientIdentifiers(recipients, m.getSelfNumber()).stream()
|
getSingleRecipientIdentifiers(recipients, m.getSelfNumber()).stream()
|
||||||
.map(RecipientIdentifier.class::cast)
|
.map(RecipientIdentifier.class::cast)
|
||||||
.collect(Collectors.toSet()));
|
.collect(Collectors.toSet()));
|
||||||
|
@ -367,7 +367,7 @@ public class DbusSignalImpl implements Signal {
|
||||||
final String message, final List<String> attachments
|
final String message, final List<String> attachments
|
||||||
) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity {
|
) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity {
|
||||||
try {
|
try {
|
||||||
final var results = m.sendMessage(new Message(message, attachments),
|
final var results = m.sendMessage(new Message(message, attachments, List.of()),
|
||||||
Set.of(RecipientIdentifier.NoteToSelf.INSTANCE));
|
Set.of(RecipientIdentifier.NoteToSelf.INSTANCE));
|
||||||
checkSendMessageResults(results.timestamp(), results.results());
|
checkSendMessageResults(results.timestamp(), results.results());
|
||||||
return results.timestamp();
|
return results.timestamp();
|
||||||
|
@ -393,7 +393,7 @@ public class DbusSignalImpl implements Signal {
|
||||||
@Override
|
@Override
|
||||||
public long sendGroupMessage(final String message, final List<String> attachments, final byte[] groupId) {
|
public long sendGroupMessage(final String message, final List<String> attachments, final byte[] groupId) {
|
||||||
try {
|
try {
|
||||||
var results = m.sendMessage(new Message(message, attachments),
|
var results = m.sendMessage(new Message(message, attachments, List.of()),
|
||||||
Set.of(new RecipientIdentifier.Group(getGroupId(groupId))));
|
Set.of(new RecipientIdentifier.Group(getGroupId(groupId))));
|
||||||
checkSendMessageResults(results.timestamp(), results.results());
|
checkSendMessageResults(results.timestamp(), results.results());
|
||||||
return results.timestamp();
|
return results.timestamp();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue