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 151071d..738fc7b 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,6 +112,36 @@ impl Sbot { utils::get_async(&mut self.rpc_reader, req_id, utils::publish_res_parse).await } + /// Wrapper for publish which constructs and publishes a post message appropriately from a string. + /// + /// # Arguments + /// + /// * `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 + } + + + /// Wrapper for publish which constructs and publishes an about description message appropriately from a string. + /// + /// # Arguments + /// + /// * `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(), + 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?; 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};