mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
parent
c07ba14fc6
commit
3290a5bf4d
8 changed files with 66 additions and 42 deletions
|
@ -51,6 +51,9 @@ public class SendCommand implements JsonRpcLocalCommand {
|
|||
subparser.addArgument("--note-to-self")
|
||||
.help("Send the message to self without notification.")
|
||||
.action(Arguments.storeTrue());
|
||||
subparser.addArgument("--notify-self")
|
||||
.help("If self is part of recipients/groups send a normal message, not a sync message.")
|
||||
.action(Arguments.storeTrue());
|
||||
|
||||
var mut = subparser.addMutuallyExclusiveGroup();
|
||||
mut.addArgument("-m", "--message").help("Specify the message to be sent.");
|
||||
|
@ -105,6 +108,7 @@ public class SendCommand implements JsonRpcLocalCommand {
|
|||
public void handleCommand(
|
||||
final Namespace ns, final Manager m, final OutputWriter outputWriter
|
||||
) throws CommandException {
|
||||
final var notifySelf = Boolean.TRUE.equals(ns.getBoolean("notify-self"));
|
||||
final var isNoteToSelf = Boolean.TRUE.equals(ns.getBoolean("note-to-self"));
|
||||
final var recipientStrings = ns.<String>getList("recipient");
|
||||
final var groupIdStrings = ns.<String>getList("group-id");
|
||||
|
@ -236,7 +240,7 @@ public class SendCommand implements JsonRpcLocalCommand {
|
|||
textStyles);
|
||||
var results = editTimestamp != null
|
||||
? m.sendEditMessage(message, recipientIdentifiers, editTimestamp)
|
||||
: m.sendMessage(message, recipientIdentifiers);
|
||||
: m.sendMessage(message, recipientIdentifiers, notifySelf);
|
||||
outputResult(outputWriter, results);
|
||||
} catch (AttachmentInvalidException | IOException e) {
|
||||
throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
|
||||
|
|
|
@ -397,7 +397,7 @@ public class DbusManagerImpl implements Manager {
|
|||
|
||||
@Override
|
||||
public SendMessageResults sendMessage(
|
||||
final Message message, final Set<RecipientIdentifier> recipients
|
||||
final Message message, final Set<RecipientIdentifier> recipients, final boolean notifySelf
|
||||
) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException {
|
||||
return handleMessage(recipients,
|
||||
numbers -> signal.sendMessage(message.messageText(), message.attachments(), numbers),
|
||||
|
|
|
@ -225,19 +225,20 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public long sendMessage(final String message, final List<String> attachments, final List<String> recipients) {
|
||||
public long sendMessage(final String messageText, final List<String> attachments, final List<String> recipients) {
|
||||
try {
|
||||
final var results = m.sendMessage(new Message(message,
|
||||
attachments,
|
||||
List.of(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
List.of(),
|
||||
Optional.empty(),
|
||||
List.of()),
|
||||
getSingleRecipientIdentifiers(recipients, m.getSelfNumber()).stream()
|
||||
.map(RecipientIdentifier.class::cast)
|
||||
.collect(Collectors.toSet()));
|
||||
final var message = new Message(messageText,
|
||||
attachments,
|
||||
List.of(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
List.of(),
|
||||
Optional.empty(),
|
||||
List.of());
|
||||
final var recipientIdentifiers = getSingleRecipientIdentifiers(recipients, m.getSelfNumber()).stream()
|
||||
.map(RecipientIdentifier.class::cast)
|
||||
.collect(Collectors.toSet());
|
||||
final var results = m.sendMessage(message, recipientIdentifiers, false);
|
||||
|
||||
checkSendMessageResults(results);
|
||||
return results.timestamp();
|
||||
|
@ -384,17 +385,18 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
|
|||
|
||||
@Override
|
||||
public long sendNoteToSelfMessage(
|
||||
final String message, final List<String> attachments
|
||||
final String messageText, final List<String> attachments
|
||||
) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity {
|
||||
try {
|
||||
final var results = m.sendMessage(new Message(message,
|
||||
final var message = new Message(messageText,
|
||||
attachments,
|
||||
List.of(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
List.of(),
|
||||
Optional.empty(),
|
||||
List.of()), Set.of(RecipientIdentifier.NoteToSelf.INSTANCE));
|
||||
List.of());
|
||||
final var results = m.sendMessage(message, Set.of(RecipientIdentifier.NoteToSelf.INSTANCE), false);
|
||||
checkSendMessageResults(results);
|
||||
return results.timestamp();
|
||||
} catch (AttachmentInvalidException e) {
|
||||
|
@ -429,16 +431,17 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public long sendGroupMessage(final String message, final List<String> attachments, final byte[] groupId) {
|
||||
public long sendGroupMessage(final String messageText, final List<String> attachments, final byte[] groupId) {
|
||||
try {
|
||||
var results = m.sendMessage(new Message(message,
|
||||
final var message = new Message(messageText,
|
||||
attachments,
|
||||
List.of(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
List.of(),
|
||||
Optional.empty(),
|
||||
List.of()), Set.of(getGroupRecipientIdentifier(groupId)));
|
||||
List.of());
|
||||
var results = m.sendMessage(message, Set.of(getGroupRecipientIdentifier(groupId)), false);
|
||||
checkSendMessageResults(results);
|
||||
return results.timestamp();
|
||||
} catch (IOException | InvalidStickerException e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue