From f54e4c47b0a5be3beed40282a48ba3d405e4e590 Mon Sep 17 00:00:00 2001 From: notplants Date: Sun, 16 Jan 2022 08:55:05 -0500 Subject: [PATCH] Update example --- examples/ssb-friends.rs | 16 +++++++++------- src/sbot.rs | 35 ++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/examples/ssb-friends.rs b/examples/ssb-friends.rs index 0b65a78..22b33a3 100644 --- a/examples/ssb-friends.rs +++ b/examples/ssb-friends.rs @@ -2,10 +2,10 @@ use async_std::stream::StreamExt; use futures::pin_mut; use std::process; -use golgi::sbot::{SubsetQuery, SubsetQueryOptions, FriendsHopsOpts}; use golgi::error::GolgiError; use golgi::messages::SsbMessageContent; use golgi::sbot::Sbot; +use golgi::sbot::{FriendsHopsOpts, SubsetQuery, SubsetQueryOptions}; async fn run() -> Result<(), GolgiError> { let mut sbot_client = Sbot::init(None, None).await?; @@ -26,12 +26,14 @@ async fn run() -> Result<(), GolgiError> { println!("follow_response: {:?}", response); // print all users you are following - let follows = sbot_client.friends_hops(FriendsHopsOpts { - max: 1, - start: None, - // doesnt seem like reverse does anything, currently - reverse: Some(false), - }).await?; + let follows = sbot_client + .friends_hops(FriendsHopsOpts { + max: 1, + start: None, + // doesnt seem like reverse does anything, currently + reverse: Some(false), + }) + .await?; println!("follows: {:?}", follows); // print if you are following to_follow (should be true) diff --git a/src/sbot.rs b/src/sbot.rs index e4cd61f..52c2797 100644 --- a/src/sbot.rs +++ b/src/sbot.rs @@ -21,7 +21,7 @@ use crate::utils; use crate::utils::get_source_stream; // re-export types from kuska -pub use kuska_ssb::api::dto::content::{SubsetQuery, SubsetQueryOptions, FriendsHopsOpts}; +pub use kuska_ssb::api::dto::content::{FriendsHopsOpts, SubsetQuery, SubsetQueryOptions}; /// A struct representing a connection with a running sbot. /// A client and an rpc_reader can together be used to make requests to the sbot @@ -185,22 +185,27 @@ impl Sbot { } // Convenience method to set a relationship with following: true, blocking: false - pub async fn follow(&mut self, contact: &str) -> Result { + pub async fn follow(&mut self, contact: &str) -> Result { self.set_relationship(contact, true, false).await } // Convenience method to set a relationship with following: false, blocking: true - pub async fn block(&mut self, contact: &str) -> Result { + pub async fn block(&mut self, contact: &str) -> Result { self.set_relationship(contact, false, true).await } /// Publishes a contact relationship to the given user (with ssb_id) with the given state. - pub async fn set_relationship(&mut self, contact: &str, following: bool, blocking: bool) -> Result { + pub async fn set_relationship( + &mut self, + contact: &str, + following: bool, + blocking: bool, + ) -> Result { let msg = SsbMessageContent::Contact { contact: Some(contact.to_string()), following: Some(following), blocking: Some(blocking), - autofollow: None + autofollow: None, }; self.publish(msg).await } @@ -267,7 +272,7 @@ impl Sbot { req_id, utils::string_res_parse, ) - .await + .await } // Gets a Vec where each element is a peer you are following @@ -276,7 +281,8 @@ impl Sbot { max: 1, start: None, reverse: Some(false), - }).await + }) + .await } // Gets a Vec where each element is a peer who follows you @@ -288,7 +294,8 @@ impl Sbot { max: 1, start: None, reverse: Some(true), - }).await + }) + .await } /// Call the `friends hops` RPC method and return a Vector @@ -296,21 +303,15 @@ impl Sbot { /// /// When opts.reverse = True, it should return peers who are following you /// (but this is currently not working) - pub async fn friends_hops( - &mut self, - opts: FriendsHopsOpts, - ) -> Result, GolgiError> { + pub async fn friends_hops(&mut self, opts: FriendsHopsOpts) -> Result, GolgiError> { let mut sbot_connection = self.get_sbot_connection().await?; - let req_id = sbot_connection - .client - .friends_hops_req_send(opts) - .await?; + let req_id = sbot_connection.client.friends_hops_req_send(opts).await?; utils::get_source_until_eof( &mut sbot_connection.rpc_reader, req_id, utils::string_res_parse, ) - .await + .await } /// Wrapper for publish which constructs and publishes a post message appropriately from a string.