Update example
This commit is contained in:
parent
c406bb4870
commit
f54e4c47b0
|
@ -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)
|
||||
|
|
35
src/sbot.rs
35
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<String, GolgiError> {
|
||||
pub async fn follow(&mut self, contact: &str) -> Result<String, GolgiError> {
|
||||
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<String, GolgiError> {
|
||||
pub async fn block(&mut self, contact: &str) -> Result<String, GolgiError> {
|
||||
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<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
|
||||
}
|
||||
|
@ -267,7 +272,7 @@ impl Sbot {
|
|||
req_id,
|
||||
utils::string_res_parse,
|
||||
)
|
||||
.await
|
||||
.await
|
||||
}
|
||||
|
||||
// Gets a Vec<String> 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<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,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<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,
|
||||
utils::string_res_parse,
|
||||
)
|
||||
.await
|
||||
.await
|
||||
}
|
||||
|
||||
/// Wrapper for publish which constructs and publishes a post message appropriately from a string.
|
||||
|
|
Loading…
Reference in New Issue