]> nmode's Git Repositories - signal-cli/blobdiff - client/src/main.rs
Add support for sending view once messages
[signal-cli] / client / src / main.rs
index 61cbabf2cb66b415f6a2a9ef3e90f43bdcac80d9..ac12331df672891a7f62ce06348207080848679f 100644 (file)
@@ -2,7 +2,7 @@ use std::{path::PathBuf, time::Duration};
 
 use clap::Parser;
 use jsonrpsee::core::client::{Error as RpcError, Subscription, SubscriptionClientT};
-use serde_json::Value;
+use serde_json::{Error, Value};
 use tokio::{select, time::sleep};
 
 use cli::Cli;
@@ -60,8 +60,13 @@ async fn handle_command(
                 .delete_local_account_data(cli.account, ignore_registered)
                 .await
         }
-        CliCommands::GetUserStatus { recipient } => {
-            client.get_user_status(cli.account, recipient).await
+        CliCommands::GetUserStatus {
+            recipient,
+            username,
+        } => {
+            client
+                .get_user_status(cli.account, recipient, username)
+                .await
         }
         CliCommands::JoinGroup { uri } => client.join_group(cli.account, uri).await,
         CliCommands::Link { name } => {
@@ -70,7 +75,7 @@ async fn handle_command(
                 .await
                 .map_err(|e| RpcError::Custom(format!("JSON-RPC command startLink failed: {e:?}")))?
                 .device_link_uri;
-            println!("{}", url);
+            println!("{url}");
             client.finish_link(url, name).await
         }
         CliCommands::ListAccounts => client.list_accounts().await,
@@ -139,6 +144,7 @@ async fn handle_command(
             end_session,
             message,
             attachment,
+            view_once,
             mention,
             text_style,
             quote_timestamp,
@@ -165,6 +171,7 @@ async fn handle_command(
                     end_session,
                     message.unwrap_or_default(),
                     attachment,
+                    view_once,
                     mention,
                     text_style,
                     quote_timestamp,
@@ -275,9 +282,17 @@ async fn handle_command(
         CliCommands::UpdateAccount {
             device_name,
             unrestricted_unidentified_sender,
+            discoverable_by_number,
+            number_sharing,
         } => {
             client
-                .update_account(cli.account, device_name, unrestricted_unidentified_sender)
+                .update_account(
+                    cli.account,
+                    device_name,
+                    unrestricted_unidentified_sender,
+                    discoverable_by_number,
+                    number_sharing,
+                )
                 .await
         }
         CliCommands::UpdateConfiguration {
@@ -429,6 +444,23 @@ async fn handle_command(
                 .start_change_number(cli.account, number, voice, captcha)
                 .await
         }
+        CliCommands::SendMessageRequestResponse {
+            recipient,
+            group_id,
+            r#type,
+        } => {
+            client
+                .send_message_request_response(
+                    cli.account,
+                    recipient,
+                    group_id,
+                    match r#type {
+                        cli::MessageRequestResponseType::Accept => "accept".to_owned(),
+                        cli::MessageRequestResponseType::Delete => "delete".to_owned(),
+                    },
+                )
+                .await
+        }
     }
 }
 
@@ -452,30 +484,37 @@ async fn connect(cli: Cli) -> Result<Value, RpcError> {
 
         handle_command(cli, client).await
     } else {
-        let socket_path = cli
-            .json_rpc_socket
-            .clone()
-            .unwrap_or(None)
-            .or_else(|| {
-                std::env::var_os("XDG_RUNTIME_DIR").map(|runtime_dir| {
-                    PathBuf::from(runtime_dir)
-                        .join(DEFAULT_SOCKET_SUFFIX)
-                        .into()
+        #[cfg(windows)]
+        {
+            Err(RpcError::Custom("Invalid socket".into()))
+        }
+        #[cfg(unix)]
+        {
+            let socket_path = cli
+                .json_rpc_socket
+                .clone()
+                .unwrap_or(None)
+                .or_else(|| {
+                    std::env::var_os("XDG_RUNTIME_DIR").map(|runtime_dir| {
+                        PathBuf::from(runtime_dir)
+                            .join(DEFAULT_SOCKET_SUFFIX)
+                            .into()
+                    })
                 })
-            })
-            .unwrap_or_else(|| ("/run".to_owned() + DEFAULT_SOCKET_SUFFIX).into());
-        let client = jsonrpc::connect_unix(socket_path)
-            .await
-            .map_err(|e| RpcError::Custom(format!("Failed to connect to socket: {e}")))?;
+                .unwrap_or_else(|| ("/run".to_owned() + DEFAULT_SOCKET_SUFFIX).into());
+            let client = jsonrpc::connect_unix(socket_path)
+                .await
+                .map_err(|e| RpcError::Custom(format!("Failed to connect to socket: {e}")))?;
 
-        handle_command(cli, client).await
+            handle_command(cli, client).await
+        }
     }
 }
 
 async fn stream_next(
     timeout: f64,
     stream: &mut Subscription<Value>,
-) -> Option<Result<Value, RpcError>> {
+) -> Option<Result<Value, Error>> {
     if timeout < 0.0 {
         stream.next().await
     } else {