use relationship query struct and latest kuska api
This commit is contained in:
parent
79630703c2
commit
08cdc5bede
|
@ -5,29 +5,31 @@ use std::process;
|
||||||
use golgi::error::GolgiError;
|
use golgi::error::GolgiError;
|
||||||
use golgi::messages::SsbMessageContent;
|
use golgi::messages::SsbMessageContent;
|
||||||
use golgi::sbot::Sbot;
|
use golgi::sbot::Sbot;
|
||||||
use golgi::sbot::{FriendsHopsOpts, SubsetQuery, SubsetQueryOptions};
|
use golgi::sbot::{FriendsHops, RelationshipQuery, SubsetQuery, SubsetQueryOptions};
|
||||||
|
|
||||||
async fn run() -> Result<(), GolgiError> {
|
async fn run() -> Result<(), GolgiError> {
|
||||||
let mut sbot_client = Sbot::init(None, None).await?;
|
let mut sbot_client = Sbot::init(Some("127.0.0.1:8009".to_string()), None).await?;
|
||||||
|
|
||||||
let id = sbot_client.whoami().await?;
|
let id = sbot_client.whoami().await?;
|
||||||
println!("whoami: {}", id);
|
println!("whoami: {}", id);
|
||||||
|
|
||||||
// test ids to follow and block
|
// test ids to follow and block
|
||||||
let to_follow = "@5Pt3dKy2HTJ0mWuS78oIiklIX0gBz6BTfEnXsbvke9c=.ed25519";
|
let to_follow = String::from("@5Pt3dKy2HTJ0mWuS78oIiklIX0gBz6BTfEnXsbvke9c=.ed25519");
|
||||||
let to_block = "@7Y4nwfQmVtAilEzi5knXdS2gilW7cGKSHXdXoT086LM=.ed25519";
|
let to_block = String::from("@7Y4nwfQmVtAilEzi5knXdS2gilW7cGKSHXdXoT086LM=.ed25519");
|
||||||
|
|
||||||
// follow to_follow
|
// follow to_follow
|
||||||
let response = sbot_client.set_relationship(to_follow, true, false).await?;
|
let response = sbot_client
|
||||||
|
.set_relationship(&to_follow, true, false)
|
||||||
|
.await?;
|
||||||
println!("follow_response: {:?}", response);
|
println!("follow_response: {:?}", response);
|
||||||
|
|
||||||
// block to_block
|
// block to_block
|
||||||
let response = sbot_client.set_relationship(to_block, false, true).await?;
|
let response = sbot_client.set_relationship(&to_block, false, true).await?;
|
||||||
println!("follow_response: {:?}", response);
|
println!("follow_response: {:?}", response);
|
||||||
|
|
||||||
// print all users you are following
|
// print all users you are following
|
||||||
let follows = sbot_client
|
let follows = sbot_client
|
||||||
.friends_hops(FriendsHopsOpts {
|
.friends_hops(FriendsHops {
|
||||||
max: 1,
|
max: 1,
|
||||||
start: None,
|
start: None,
|
||||||
// doesnt seem like reverse does anything, currently
|
// doesnt seem like reverse does anything, currently
|
||||||
|
@ -37,19 +39,39 @@ async fn run() -> Result<(), GolgiError> {
|
||||||
println!("follows: {:?}", follows);
|
println!("follows: {:?}", follows);
|
||||||
|
|
||||||
// print if you are following to_follow (should be true)
|
// print if you are following to_follow (should be true)
|
||||||
let mref = sbot_client.friends_is_following(&id, to_follow).await?;
|
let mref = sbot_client
|
||||||
|
.friends_is_following(RelationshipQuery {
|
||||||
|
source: id.clone(),
|
||||||
|
dest: to_follow.clone(),
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
println!("isfollowingmref: {}", mref);
|
println!("isfollowingmref: {}", mref);
|
||||||
|
|
||||||
// print if you are blocking to_block (should be true)
|
// print if you are blocking to_block (should be true)
|
||||||
let mref = sbot_client.friends_is_blocking(&id, to_block).await?;
|
let mref = sbot_client
|
||||||
|
.friends_is_blocking(RelationshipQuery {
|
||||||
|
source: id.clone(),
|
||||||
|
dest: to_block.clone(),
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
println!("isblockingmref: {}", mref);
|
println!("isblockingmref: {}", mref);
|
||||||
|
|
||||||
// print if you are blocking to_follow (should be false)
|
// print if you are blocking to_follow (should be false)
|
||||||
let mref = sbot_client.friends_is_blocking(&id, to_follow).await?;
|
let mref = sbot_client
|
||||||
|
.friends_is_blocking(RelationshipQuery {
|
||||||
|
source: id.clone(),
|
||||||
|
dest: to_follow,
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
println!("isblockingmref(should be false): {}", mref);
|
println!("isblockingmref(should be false): {}", mref);
|
||||||
|
|
||||||
// print if you are following to_block (should be false)
|
// print if you are following to_block (should be false)
|
||||||
let mref = sbot_client.friends_is_following(&id, to_block).await?;
|
let mref = sbot_client
|
||||||
|
.friends_is_following(RelationshipQuery {
|
||||||
|
source: id,
|
||||||
|
dest: to_block.clone(),
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
println!("isfollowingmref(should be false): {}", mref);
|
println!("isfollowingmref(should be false): {}", mref);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
28
src/sbot.rs
28
src/sbot.rs
|
@ -21,7 +21,9 @@ use crate::utils;
|
||||||
use crate::utils::get_source_stream;
|
use crate::utils::get_source_stream;
|
||||||
|
|
||||||
// re-export types from kuska
|
// re-export types from kuska
|
||||||
pub use kuska_ssb::api::dto::content::{FriendsHopsOpts, SubsetQuery, SubsetQueryOptions};
|
pub use kuska_ssb::api::dto::content::{
|
||||||
|
FriendsHops, RelationshipQuery, SubsetQuery, SubsetQueryOptions,
|
||||||
|
};
|
||||||
|
|
||||||
/// A struct representing a connection with a running sbot.
|
/// 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
|
/// A client and an rpc_reader can together be used to make requests to the sbot
|
||||||
|
@ -210,17 +212,16 @@ impl Sbot {
|
||||||
self.publish(msg).await
|
self.publish(msg).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call the `friends isfollowing` RPC method and return a message reference.
|
/// Call the `friends isFollowing` RPC method and return a message reference.
|
||||||
/// returns true if src_id is following dest_id and false otherwise
|
/// Returns true if src_id is following dest_id and false otherwise.
|
||||||
pub async fn friends_is_following(
|
pub async fn friends_is_following(
|
||||||
&mut self,
|
&mut self,
|
||||||
src_id: &str,
|
args: RelationshipQuery,
|
||||||
dest_id: &str,
|
|
||||||
) -> Result<String, GolgiError> {
|
) -> Result<String, GolgiError> {
|
||||||
let mut sbot_connection = self.get_sbot_connection().await?;
|
let mut sbot_connection = self.get_sbot_connection().await?;
|
||||||
let req_id = sbot_connection
|
let req_id = sbot_connection
|
||||||
.client
|
.client
|
||||||
.friends_isfollowing_req_send(src_id, dest_id)
|
.friends_is_following_req_send(args)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
utils::get_async(
|
utils::get_async(
|
||||||
|
@ -232,16 +233,15 @@ impl Sbot {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call the `friends isblocking` RPC method and return a message reference.
|
/// Call the `friends isblocking` RPC method and return a message reference.
|
||||||
/// returns true if src_id is blocking dest_id and false otherwise
|
/// Returns true if src_id is blocking dest_id and false otherwise.
|
||||||
pub async fn friends_is_blocking(
|
pub async fn friends_is_blocking(
|
||||||
&mut self,
|
&mut self,
|
||||||
src_id: &str,
|
args: RelationshipQuery,
|
||||||
dest_id: &str,
|
|
||||||
) -> Result<String, GolgiError> {
|
) -> Result<String, GolgiError> {
|
||||||
let mut sbot_connection = self.get_sbot_connection().await?;
|
let mut sbot_connection = self.get_sbot_connection().await?;
|
||||||
let req_id = sbot_connection
|
let req_id = sbot_connection
|
||||||
.client
|
.client
|
||||||
.friends_isblocking_req_send(src_id, dest_id)
|
.friends_is_blocking_req_send(args)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
utils::get_async(
|
utils::get_async(
|
||||||
|
@ -254,7 +254,7 @@ impl Sbot {
|
||||||
|
|
||||||
// Gets a Vec<String> where each element is a peer you are following
|
// Gets a Vec<String> where each element is a peer you are following
|
||||||
pub async fn get_follows(&mut self) -> Result<Vec<String>, GolgiError> {
|
pub async fn get_follows(&mut self) -> Result<Vec<String>, GolgiError> {
|
||||||
self.friends_hops(FriendsHopsOpts {
|
self.friends_hops(FriendsHops {
|
||||||
max: 1,
|
max: 1,
|
||||||
start: None,
|
start: None,
|
||||||
reverse: Some(false),
|
reverse: Some(false),
|
||||||
|
@ -267,7 +267,7 @@ impl Sbot {
|
||||||
/// go-sbot does not seem to listen to the reverse=True parameter
|
/// go-sbot does not seem to listen to the reverse=True parameter
|
||||||
/// and just returns follows
|
/// and just returns follows
|
||||||
async fn get_followers(&mut self) -> Result<Vec<String>, GolgiError> {
|
async fn get_followers(&mut self) -> Result<Vec<String>, GolgiError> {
|
||||||
self.friends_hops(FriendsHopsOpts {
|
self.friends_hops(FriendsHops {
|
||||||
max: 1,
|
max: 1,
|
||||||
start: None,
|
start: None,
|
||||||
reverse: Some(true),
|
reverse: Some(true),
|
||||||
|
@ -280,9 +280,9 @@ impl Sbot {
|
||||||
///
|
///
|
||||||
/// When opts.reverse = True, it should return peers who are following you
|
/// When opts.reverse = True, it should return peers who are following you
|
||||||
/// (but this is currently not working)
|
/// (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, args: FriendsHops) -> Result<Vec<String>, GolgiError> {
|
||||||
let mut sbot_connection = self.get_sbot_connection().await?;
|
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(args).await?;
|
||||||
utils::get_source_until_eof(
|
utils::get_source_until_eof(
|
||||||
&mut sbot_connection.rpc_reader,
|
&mut sbot_connection.rpc_reader,
|
||||||
req_id,
|
req_id,
|
||||||
|
|
Loading…
Reference in New Issue