From d7ef6a62e00eeeca3bfbf078a2c678d23b8d653a Mon Sep 17 00:00:00 2001 From: glyph Date: Thu, 10 Mar 2022 09:47:46 +0200 Subject: [PATCH 1/3] add private message publishing rpc --- Cargo.lock | 1 - Cargo.toml | 3 +- src/api/mod.rs | 1 + src/api/private.rs | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 src/api/private.rs diff --git a/Cargo.lock b/Cargo.lock index ac07f0f..59aa7c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -640,7 +640,6 @@ dependencies = [ [[package]] name = "kuska-ssb" version = "0.4.0" -source = "git+https://github.com/Kuska-ssb/ssb#87e3ea58ba00cc9dfe21e0122231768d90f89000" dependencies = [ "async-std", "async-stream 0.2.1", diff --git a/Cargo.toml b/Cargo.toml index 6340cf9..54b523f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,8 @@ 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" } +#kuska-ssb = { git = "https://github.com/Kuska-ssb/ssb" } +kuska-ssb = { path = "../ssb" } serde = { version = "1", features = ["derive"] } serde_json = "1" sha2 = "0.10.2" 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..3491a41 --- /dev/null +++ b/src/api/private.rs @@ -0,0 +1,68 @@ +//! Publish and read Scuttlebutt private messages. +//! +//! Implements the following methods: +//! +//! - [`Sbot::publish_private`] +//! - [`Sbot::read_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, msg: PrivateMessage) -> Result { + 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 + } +} From ab4077b1158e93759da69be2477dbd31f3e605fe Mon Sep 17 00:00:00 2001 From: glyph Date: Thu, 10 Mar 2022 11:11:15 +0200 Subject: [PATCH 2/3] temporarily point to kuska-ssb branch --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 54b523f..3c2079d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ 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" } -kuska-ssb = { path = "../ssb" } +kuska-ssb = { git = "https://github.com/mycognosist/ssb.git", branch = "private_messages" } serde = { version = "1", features = ["derive"] } serde_json = "1" sha2 = "0.10.2" From 1d0e31541d34b61118bf34126755d379f5777fe7 Mon Sep 17 00:00:00 2001 From: glyph Date: Sun, 13 Mar 2022 10:50:16 +0200 Subject: [PATCH 3/3] update kuska dependency path and fix private msg docs --- Cargo.lock | 1 + Cargo.toml | 4 +--- src/api/private.rs | 6 ++---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 59aa7c6..2801b0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -640,6 +640,7 @@ dependencies = [ [[package]] name = "kuska-ssb" version = "0.4.0" +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 3c2079d..460122c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,9 +19,7 @@ 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" } -kuska-ssb = { git = "https://github.com/mycognosist/ssb.git", branch = "private_messages" } +kuska-ssb = { git = "https://github.com/Kuska-ssb/ssb" } serde = { version = "1", features = ["derive"] } serde_json = "1" sha2 = "0.10.2" diff --git a/src/api/private.rs b/src/api/private.rs index 3491a41..f341135 100644 --- a/src/api/private.rs +++ b/src/api/private.rs @@ -1,9 +1,8 @@ -//! Publish and read Scuttlebutt private messages. +//! Publish Scuttlebutt private messages. //! -//! Implements the following methods: +//! Implements the following method: //! //! - [`Sbot::publish_private`] -//! - [`Sbot::read_private`] use crate::{error::GolgiError, messages::SsbMessageContent, sbot::Sbot, utils}; @@ -41,7 +40,6 @@ impl Sbot { /// Ok(()) /// } /// ``` - //pub async fn publish_private(&mut self, msg: PrivateMessage) -> Result { pub async fn publish_private( &mut self, text: String,