diff --git a/Cargo.lock b/Cargo.lock index ac07f0f..2801b0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -640,7 +640,7 @@ dependencies = [ [[package]] name = "kuska-ssb" version = "0.4.0" -source = "git+https://github.com/Kuska-ssb/ssb#87e3ea58ba00cc9dfe21e0122231768d90f89000" +source = "git+https://github.com/Kuska-ssb/ssb#fb7062de606e7c9cae8dd4df402a122db46c1b77" dependencies = [ "async-std", "async-stream 0.2.1", diff --git a/Cargo.toml b/Cargo.toml index 6340cf9..460122c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,6 @@ futures = "0.3.21" hex = "0.4.3" kuska-handshake = { version = "0.2.0", features = ["async_std"] } kuska-sodiumoxide = "0.2.5-0" -#kuska-ssb = "0.4.0" kuska-ssb = { git = "https://github.com/Kuska-ssb/ssb" } serde = { version = "1", features = ["derive"] } serde_json = "1" diff --git a/src/api/mod.rs b/src/api/mod.rs index ef9ba50..9cbb18c 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -4,6 +4,7 @@ pub mod friends; pub mod get_subset; pub mod history_stream; pub mod invite; +pub mod private; pub mod publish; pub mod whoami; diff --git a/src/api/private.rs b/src/api/private.rs new file mode 100644 index 0000000..f341135 --- /dev/null +++ b/src/api/private.rs @@ -0,0 +1,66 @@ +//! Publish Scuttlebutt private messages. +//! +//! Implements the following method: +//! +//! - [`Sbot::publish_private`] + +use crate::{error::GolgiError, messages::SsbMessageContent, sbot::Sbot, utils}; + +impl Sbot { + /// Publish a private message. + /// + /// # Arguments + /// + /// * `msg` - A `PrivateMessage` `struct` whose fields include `text` and + /// `recipients`. + /// + /// # Example + /// + /// ```rust + /// use golgi::{Sbot, GolgiError, messages::SsbMessageContent}; + /// + /// async fn publish_a_private_msg() -> Result<(), GolgiError> { + /// let mut sbot_client = Sbot::init(None, None).await?; + /// + /// let text = String::new("Hi friends, I have a super secrect message to share with you about the wonders of intra-cellular transport mechanics."); + /// + /// // We must also include the local identity (public key) here if we wish + /// // to be able to read the message. Ie. the sender must be included in + /// // the list of recipients. + /// let recipients = Vec::new( + /// String::new("@OKRij/n7Uu42A0Z75ty0JI0cZxcieD2NyjXrRdYKNOQ=.ed25519"), + /// String::new("@Sih4JGgs5oQPXehRyHS5qrYbx/0hQVUqChojX0LNtcQ=.ed25519"), + /// String::new("@BVA85B7a/a17v2ZVcLkMgPE+v7X5rQVAHEgQBbCaKMs=.ed25519"), + /// ); + /// + /// let msg_ref = sbot_client.publish_private(text, recipients).await?; + /// + /// println!("msg reference for the private msg: {}", msg_ref); + /// + /// Ok(()) + /// } + /// ``` + pub async fn publish_private( + &mut self, + text: String, + recipients: Vec, + ) -> Result { + let msg = SsbMessageContent::Post { + text: text.to_string(), + mentions: None, + }; + + let mut sbot_connection = self.get_sbot_connection().await?; + let req_id = sbot_connection + .client + .private_publish_req_send(msg, recipients) + .await?; + + utils::get_async( + &mut sbot_connection.rpc_reader, + req_id, + utils::string_res_parse, + ) + .await + } +}