diff --git a/src/api/friends.rs b/src/api/friends.rs index b681b01..8975133 100644 --- a/src/api/friends.rs +++ b/src/api/friends.rs @@ -3,7 +3,9 @@ //! Implements the following methods: //! //! - [`Sbot::block`] +//! - [`Sbot::unblock`] //! - [`Sbot::follow`] +//! - [`Sbot::unfollow`] //! - [`Sbot::friends_hops`] //! - [`Sbot::friends_is_blocking`] //! - [`Sbot::friends_is_following`] @@ -20,7 +22,7 @@ impl Sbot { /// Follow a peer. /// /// This is a convenience method to publish a contact message with - /// following: `true` and blocking: `false`. + /// following: `true`. /// /// # Example /// @@ -43,7 +45,36 @@ impl Sbot { /// } /// ``` pub async fn follow(&mut self, contact: &str) -> Result { - self.set_relationship(contact, true, false).await + self.set_relationship(contact, Some(true), None).await + } + + /// Unfollow a peer. + /// + /// This is a convenience method to publish a contact message with + /// following: `false`. + /// + /// # Example + /// + /// ```rust + /// use golgi::{Sbot, GolgiError}; + /// + /// async fn unfollow_peer() -> Result<(), GolgiError> { + /// let mut sbot_client = Sbot::init(None, None).await?; + /// + /// let ssb_id = "@zqshk7o2Rpd/OaZ/MxH6xXONgonP1jH+edK9+GZb/NY=.ed25519"; + /// + /// match sbot_client.unfollow(ssb_id).await { + /// Ok(msg_ref) => { + /// println!("unfollow msg reference is: {}", msg_ref) + /// }, + /// Err(e) => eprintln!("failed to unfollow {}: {}", ssb_id, e) + /// } + /// + /// Ok(()) + /// } + /// ``` + pub async fn unfollow(&mut self, contact: &str) -> Result { + self.set_relationship(contact, Some(false), None).await } /// Block a peer. @@ -72,7 +103,38 @@ impl Sbot { /// } /// ``` pub async fn block(&mut self, contact: &str) -> Result { - self.set_relationship(contact, false, true).await + // we want to unfollow and block + self.set_relationship(contact, Some(false), Some(true)) + .await + } + + /// Unblock a peer. + /// + /// This is a convenience method to publish a contact message with + /// blocking: `false`. + /// + /// # Example + /// + /// ```rust + /// use golgi::{Sbot, GolgiError}; + /// + /// async fn unblock_peer() -> Result<(), GolgiError> { + /// let mut sbot_client = Sbot::init(None, None).await?; + /// + /// let ssb_id = "@zqshk7o2Rpd/OaZ/MxH6xXONgonP1jH+edK9+GZb/NY=.ed25519"; + /// + /// match sbot_client.unblock(ssb_id).await { + /// Ok(msg_ref) => { + /// println!("unblock msg reference is: {}", msg_ref) + /// }, + /// Err(e) => eprintln!("failed to unblock {}: {}", ssb_id, e) + /// } + /// + /// Ok(()) + /// } + /// ``` + pub async fn unblock(&mut self, contact: &str) -> Result { + self.set_relationship(contact, None, Some(false)).await } /// Publish a contact message defining the relationship for a peer. @@ -86,8 +148,9 @@ impl Sbot { /// let mut sbot_client = Sbot::init(None, None).await?; /// /// let ssb_id = "@zqshk7o2Rpd/OaZ/MxH6xXONgonP1jH+edK9+GZb/NY=.ed25519"; - /// let following = true; - /// let blocking = false; + /// let following = Some(true); + /// // Could also be `None` to only publish the following relationship. + /// let blocking = Some(false); /// /// match sbot_client.set_relationship(ssb_id, following, blocking).await { /// Ok(msg_ref) => { @@ -102,13 +165,13 @@ impl Sbot { pub async fn set_relationship( &mut self, contact: &str, - following: bool, - blocking: bool, + following: Option, + blocking: Option, ) -> Result { let msg = SsbMessageContent::Contact { contact: Some(contact.to_string()), - following: Some(following), - blocking: Some(blocking), + following, + blocking, autofollow: None, }; self.publish(msg).await