Update example

This commit is contained in:
notplants 2022-01-16 08:55:05 -05:00
parent c406bb4870
commit f54e4c47b0
2 changed files with 27 additions and 24 deletions

View File

@ -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 {
let follows = sbot_client
.friends_hops(FriendsHopsOpts {
max: 1,
start: None,
// doesnt seem like reverse does anything, currently
reverse: Some(false),
}).await?;
})
.await?;
println!("follows: {:?}", follows);
// print if you are following to_follow (should be true)

View File

@ -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
@ -195,12 +195,17 @@ impl Sbot {
}
/// 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<String, GolgiError> {
pub async fn set_relationship(
&mut self,
contact: &str,
following: bool,
blocking: bool,
) -> Result<String, GolgiError> {
let msg = SsbMessageContent::Contact {
contact: Some(contact.to_string()),
following: Some(following),
blocking: Some(blocking),
autofollow: None
autofollow: None,
};
self.publish(msg).await
}
@ -276,7 +281,8 @@ impl Sbot {
max: 1,
start: None,
reverse: Some(false),
}).await
})
.await
}
// Gets a Vec<String> 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<String>
@ -296,15 +303,9 @@ 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<Vec<String>, GolgiError> {
pub async fn friends_hops(&mut self, opts: FriendsHopsOpts) -> Result<Vec<String>, 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,