From 5b72de0b2b90df1ad72f16d16002e3bfae31bac1 Mon Sep 17 00:00:00 2001 From: notplants Date: Wed, 22 Dec 2021 14:42:01 -0500 Subject: [PATCH 1/4] Add publish_post method --- src/lib.rs | 2 ++ src/sbot.rs | 10 ++++++++++ src/utils.rs | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6fd638d..2dbc4cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,6 +24,8 @@ //! } //! ``` +extern crate kuska_ssb; + pub mod error; pub mod sbot; mod utils; diff --git a/src/sbot.rs b/src/sbot.rs index 151071d..557faed 100644 --- a/src/sbot.rs +++ b/src/sbot.rs @@ -113,6 +113,16 @@ impl Sbot { utils::get_async(&mut self.rpc_reader, req_id, utils::publish_res_parse).await } + /// Wrapper for publish which constructs and publish a post message appropriately from a string. + /// + /// # Arguments + /// + /// * `text` - A &str which represents the text to be published in the post + pub async fn publish_post(&mut self, text: &str) -> Result { + let msg = TypedMessage::Post{ text: text.to_string(), mentions: None}; + self.publish(msg).await + } + /* pub async fn publish_post(&mut self, post: Post) -> Result { let req_id = self.client.publish_req_send(post).await?; diff --git a/src/utils.rs b/src/utils.rs index ba3d65b..70c75e6 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -10,7 +10,7 @@ use std::fmt::Debug; use async_std::io::Read; -use kuska_ssb::api::dto::{PublishOut, WhoAmIOut}; +use kuska_ssb::api::dto::{WhoAmIOut}; use kuska_ssb::feed::Feed; use kuska_ssb::rpc::{RecvMsg, RequestNo, RpcReader}; From 4701c72f6a2ca11e603a24e2e56ddf189589747d Mon Sep 17 00:00:00 2001 From: notplants Date: Wed, 22 Dec 2021 14:47:41 -0500 Subject: [PATCH 2/4] Fix clippy warning --- src/sbot.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/sbot.rs b/src/sbot.rs index 557faed..aaf4788 100644 --- a/src/sbot.rs +++ b/src/sbot.rs @@ -39,19 +39,18 @@ impl Sbot { /// for the sbot, then retrieve the public key, private key (secret) and identity from the /// `.ssb-go/secret` file. Open a TCP stream to the sbot and perform the secret handshake. If successful, create a box stream and split it into a writer and reader. Return RPC handles to the sbot as part of the `struct` output. pub async fn init(ip_port: Option, net_id: Option) -> Result { - let address; - if ip_port.is_none() { - address = "127.0.0.1:8008".to_string(); - } else { - address = ip_port.unwrap(); - } - let network_id; - if net_id.is_none() { - network_id = discovery::ssb_net_id(); + let address = if ip_port.is_none() { + "127.0.0.1:8008".to_string() } else { - network_id = auth::Key::from_slice(&hex::decode(net_id.unwrap()).unwrap()).unwrap(); - } + ip_port.unwrap() + }; + + let network_id = if net_id.is_none() { + discovery::ssb_net_id() + } else { + auth::Key::from_slice(&hex::decode(net_id.unwrap()).unwrap()).unwrap() + }; let OwnedIdentity { pk, sk, id } = keystore::from_gosbot_local() .await @@ -113,7 +112,7 @@ impl Sbot { utils::get_async(&mut self.rpc_reader, req_id, utils::publish_res_parse).await } - /// Wrapper for publish which constructs and publish a post message appropriately from a string. + /// Wrapper for publish which constructs and publishes a post message appropriately from a string. /// /// # Arguments /// From c12ea2c8c1e0e3a98050d93f7171df432b8144f0 Mon Sep 17 00:00:00 2001 From: notplants Date: Wed, 22 Dec 2021 16:19:52 -0500 Subject: [PATCH 3/4] Working on publish_description --- examples/ssb-client.rs | 3 +++ src/sbot.rs | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/examples/ssb-client.rs b/examples/ssb-client.rs index 3c832e4..9df337f 100644 --- a/examples/ssb-client.rs +++ b/examples/ssb-client.rs @@ -33,6 +33,9 @@ async fn run() -> Result<(), GolgiError> { let post_msg_ref = sbot_client.publish(post).await?; println!("{}", post_msg_ref); + let post_msg_ref = sbot_client.publish_description("this is a description").await?; + println!("description: {}", post_msg_ref); + Ok(()) } diff --git a/src/sbot.rs b/src/sbot.rs index aaf4788..ddfc3f7 100644 --- a/src/sbot.rs +++ b/src/sbot.rs @@ -122,6 +122,26 @@ impl Sbot { self.publish(msg).await } + + /// Wrapper for publish which constructs and publishes an about description message appropriately from a string. + /// + /// # Arguments + /// + /// * `description` - A &str which represents the text to be published as an about description. + pub async fn publish_description(&mut self, description: &str) -> Result { + let msg = TypedMessage::About { + about: self.id.to_string(), + name: None, + title: None, + branch: None, + image: None, + description: Some(description.to_string()), + location: None, + start_datetime: None, + }; + self.publish(msg).await + } + /* pub async fn publish_post(&mut self, post: Post) -> Result { let req_id = self.client.publish_req_send(post).await?; From dbd880c9634c586d1605baf3741510b8ccecf702 Mon Sep 17 00:00:00 2001 From: notplants Date: Fri, 24 Dec 2021 10:34:07 -0500 Subject: [PATCH 4/4] Response to code review --- src/lib.rs | 2 -- src/sbot.rs | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2dbc4cb..6fd638d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,8 +24,6 @@ //! } //! ``` -extern crate kuska_ssb; - pub mod error; pub mod sbot; mod utils; diff --git a/src/sbot.rs b/src/sbot.rs index ddfc3f7..738fc7b 100644 --- a/src/sbot.rs +++ b/src/sbot.rs @@ -116,7 +116,7 @@ impl Sbot { /// /// # Arguments /// - /// * `text` - A &str which represents the text to be published in the post + /// * `text` - A reference to a string slice which represents the text to be published in the post pub async fn publish_post(&mut self, text: &str) -> Result { let msg = TypedMessage::Post{ text: text.to_string(), mentions: None}; self.publish(msg).await @@ -127,7 +127,7 @@ impl Sbot { /// /// # Arguments /// - /// * `description` - A &str which represents the text to be published as an about description. + /// * `description` - A reference to a string slice which represents the text to be published as an about description. pub async fn publish_description(&mut self, description: &str) -> Result { let msg = TypedMessage::About { about: self.id.to_string(),