Add support for sending view once messages

Closes #1812
This commit is contained in:
AsamK 2025-07-14 16:42:06 +02:00
parent c924d5c03a
commit 7c7fc76a64
8 changed files with 21 additions and 0 deletions

View file

@ -179,6 +179,9 @@ pub enum CliCommands {
#[arg(short = 'a', long)] #[arg(short = 'a', long)]
attachment: Vec<String>, attachment: Vec<String>,
#[arg(long)]
view_once: bool,
#[arg(long)] #[arg(long)]
mention: Vec<String>, mention: Vec<String>,

View file

@ -183,6 +183,7 @@ pub trait Rpc {
endSession: bool, endSession: bool,
message: String, message: String,
attachments: Vec<String>, attachments: Vec<String>,
view_once: bool,
mentions: Vec<String>, mentions: Vec<String>,
textStyle: Vec<String>, textStyle: Vec<String>,
quoteTimestamp: Option<u64>, quoteTimestamp: Option<u64>,

View file

@ -144,6 +144,7 @@ async fn handle_command(
end_session, end_session,
message, message,
attachment, attachment,
view_once,
mention, mention,
text_style, text_style,
quote_timestamp, quote_timestamp,
@ -170,6 +171,7 @@ async fn handle_command(
end_session, end_session,
message.unwrap_or_default(), message.unwrap_or_default(),
attachment, attachment,
view_once,
mention, mention,
text_style, text_style,
quote_timestamp, quote_timestamp,

View file

@ -6,6 +6,7 @@ import java.util.Optional;
public record Message( public record Message(
String messageText, String messageText,
List<String> attachments, List<String> attachments,
boolean viewOnce,
List<Mention> mentions, List<Mention> mentions,
Optional<Quote> quote, Optional<Quote> quote,
Optional<Sticker> sticker, Optional<Sticker> sticker,

View file

@ -810,6 +810,7 @@ public class ManagerImpl implements Manager {
} else if (!additionalAttachments.isEmpty()) { } else if (!additionalAttachments.isEmpty()) {
messageBuilder.withAttachments(additionalAttachments); messageBuilder.withAttachments(additionalAttachments);
} }
messageBuilder.withViewOnce(message.viewOnce());
if (!message.mentions().isEmpty()) { if (!message.mentions().isEmpty()) {
messageBuilder.withMentions(resolveMentions(message.mentions())); messageBuilder.withMentions(resolveMentions(message.mentions()));
} }

View file

@ -316,6 +316,11 @@ Data URI encoded attachments must follow the RFC 2397.
Additionally a file name can be added: Additionally a file name can be added:
e.g.: `data:<MIME-TYPE>;filename=<FILENAME>;base64,<BASE64 ENCODED DATA>` e.g.: `data:<MIME-TYPE>;filename=<FILENAME>;base64,<BASE64 ENCODED DATA>`
*--view-once*::
Send the message as a view once message.
A conformant client will only allow the receiver to view the message once.
View Once is only supported for messages that include an image attachment.
*--sticker* STICKER:: *--sticker* STICKER::
Send a sticker of a locally known sticker pack (syntax: stickerPackId:stickerId). Send a sticker of a locally known sticker pack (syntax: stickerPackId:stickerId).
Shouldn't be used together with `-m` as the official clients don't support this. Shouldn't be used together with `-m` as the official clients don't support this.

View file

@ -66,6 +66,9 @@ public class SendCommand implements JsonRpcLocalCommand {
.help("Add an attachment. " .help("Add an attachment. "
+ "Can be either a file path or a data URI. Data URI encoded attachments must follow the RFC 2397. Additionally a file name can be added, e.g. " + "Can be either a file path or a data URI. Data URI encoded attachments must follow the RFC 2397. Additionally a file name can be added, e.g. "
+ "data:<MIME-TYPE>;filename=<FILENAME>;base64,<BASE64 ENCODED DATA>."); + "data:<MIME-TYPE>;filename=<FILENAME>;base64,<BASE64 ENCODED DATA>.");
subparser.addArgument("--view-once")
.action(Arguments.storeTrue())
.help("Send the message as a view once message");
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());
@ -164,6 +167,7 @@ public class SendCommand implements JsonRpcLocalCommand {
if (attachments == null) { if (attachments == null) {
attachments = List.of(); attachments = List.of();
} }
final var viewOnce = ns.getBoolean("view-once");
final var selfNumber = m.getSelfNumber(); final var selfNumber = m.getSelfNumber();
@ -239,6 +243,7 @@ public class SendCommand implements JsonRpcLocalCommand {
try { try {
final var message = new Message(messageText, final var message = new Message(messageText,
attachments, attachments,
viewOnce,
mentions, mentions,
Optional.ofNullable(quote), Optional.ofNullable(quote),
Optional.ofNullable(sticker), Optional.ofNullable(sticker),

View file

@ -236,6 +236,7 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
try { try {
final var message = new Message(messageText, final var message = new Message(messageText,
attachments, attachments,
false,
List.of(), List.of(),
Optional.empty(), Optional.empty(),
Optional.empty(), Optional.empty(),
@ -399,6 +400,7 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
try { try {
final var message = new Message(messageText, final var message = new Message(messageText,
attachments, attachments,
false,
List.of(), List.of(),
Optional.empty(), Optional.empty(),
Optional.empty(), Optional.empty(),
@ -444,6 +446,7 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
try { try {
final var message = new Message(messageText, final var message = new Message(messageText,
attachments, attachments,
false,
List.of(), List.of(),
Optional.empty(), Optional.empty(),
Optional.empty(), Optional.empty(),