update set_relationship parameter types

This commit is contained in:
glyph 2022-03-01 15:42:40 +02:00
parent 6508aeb3ea
commit e8294241ec
1 changed files with 16 additions and 13 deletions

View File

@ -22,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
///
@ -45,13 +45,13 @@ impl Sbot {
/// }
/// ```
pub async fn follow(&mut self, contact: &str) -> Result<String, GolgiError> {
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` and blocking: `false`.
/// following: `false`.
///
/// # Example
///
@ -74,7 +74,7 @@ impl Sbot {
/// }
/// ```
pub async fn unfollow(&mut self, contact: &str) -> Result<String, GolgiError> {
self.set_relationship(contact, false, false).await
self.set_relationship(contact, Some(false), None).await
}
/// Block a peer.
@ -103,13 +103,15 @@ impl Sbot {
/// }
/// ```
pub async fn block(&mut self, contact: &str) -> Result<String, GolgiError> {
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
/// following: `false` and blocking: `false`.
/// blocking: `false`.
///
/// # Example
///
@ -132,7 +134,7 @@ impl Sbot {
/// }
/// ```
pub async fn unblock(&mut self, contact: &str) -> Result<String, GolgiError> {
self.set_relationship(contact, false, false).await
self.set_relationship(contact, None, Some(false)).await
}
/// Publish a contact message defining the relationship for a peer.
@ -146,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) => {
@ -162,13 +165,13 @@ impl Sbot {
pub async fn set_relationship(
&mut self,
contact: &str,
following: bool,
blocking: bool,
following: Option<bool>,
blocking: Option<bool>,
) -> Result<String, GolgiError> {
let msg = SsbMessageContent::Contact {
contact: Some(contact.to_string()),
following: Some(following),
blocking: Some(blocking),
following,
blocking,
autofollow: None,
};
self.publish(msg).await