add get_blocks method

This commit is contained in:
glyph 2022-03-01 13:54:52 +02:00
parent 34531400f0
commit 19b1813685
3 changed files with 37 additions and 4 deletions

5
Cargo.lock generated
View File

@ -543,7 +543,7 @@ dependencies = [
[[package]]
name = "golgi"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"async-std",
"async-stream 0.3.2",
@ -640,8 +640,7 @@ dependencies = [
[[package]]
name = "kuska-ssb"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cef1d6e08b984bc040c5c11ee3104e626640466978b6977a2d842e4a72595311"
source = "git+https://github.com/Kuska-ssb/ssb#87e3ea58ba00cc9dfe21e0122231768d90f89000"
dependencies = [
"async-std",
"async-stream 0.2.1",

View File

@ -19,7 +19,8 @@ futures = "0.3.21"
hex = "0.4.3"
kuska-handshake = { version = "0.2.0", features = ["async_std"] }
kuska-sodiumoxide = "0.2.5-0"
kuska-ssb = "0.4.0"
#kuska-ssb = "0.4.0"
kuska-ssb = { git = "https://github.com/Kuska-ssb/ssb" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha2 = "0.10.2"

View File

@ -7,6 +7,7 @@
//! - [`Sbot::friends_hops`]
//! - [`Sbot::friends_is_blocking`]
//! - [`Sbot::friends_is_following`]
//! - [`Sbot::get_blocks`]
//! - [`Sbot::get_follows`]
//! - [`Sbot::set_relationship`]
@ -213,6 +214,38 @@ impl Sbot {
.await
}
/// Get a list of peers blocked by the local peer.
///
/// # Example
///
/// ```rust
/// use golgi::{Sbot, GolgiError};
///
/// async fn follows() -> Result<(), GolgiError> {
/// let mut sbot_client = Sbot::init(None, None).await?;
///
/// let follows = sbot_client.get_blocks().await?;
///
/// if follows.is_empty() {
/// println!("we do not block any peers")
/// } else {
/// follows.iter().for_each(|peer| println!("we block {}", peer))
/// }
///
/// Ok(())
/// }
/// ```
pub async fn get_blocks(&mut self) -> Result<Vec<String>, GolgiError> {
let mut sbot_connection = self.get_sbot_connection().await?;
let req_id = sbot_connection.client.friends_blocks_req_send().await?;
utils::get_source_until_eof(
&mut sbot_connection.rpc_reader,
req_id,
utils::string_res_parse,
)
.await
}
/// Get a list of peers followed by the local peer.
///
/// # Example