Added methods + cli commands for `network.{get_followers,get_following,follow_peer,unfollow_peer}`
This commit is contained in:
parent
c95c71c1bd
commit
a038b6f7da
|
@ -145,6 +145,36 @@ async fn main() {
|
|||
Ok(response) => println!("{:#?}", response),
|
||||
Err(err) => println!("{}", MyFriendlyError::from(err)),
|
||||
},
|
||||
SocialVoidCommand::Followers { peer, page } => {
|
||||
match sv.network.get_followers(peer, page).await {
|
||||
Ok(peers) => {
|
||||
println!(
|
||||
"{}",
|
||||
peers
|
||||
.iter()
|
||||
.map(|peer| format!("{:?}", peer))
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n")
|
||||
)
|
||||
}
|
||||
Err(err) => println!("{}", MyFriendlyError::from(err)),
|
||||
}
|
||||
}
|
||||
SocialVoidCommand::Following { peer, page } => {
|
||||
match sv.network.get_following(peer, page).await {
|
||||
Ok(peers) => {
|
||||
println!(
|
||||
"{}",
|
||||
peers
|
||||
.iter()
|
||||
.map(|peer| format!("{:?}", peer))
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n")
|
||||
)
|
||||
}
|
||||
Err(err) => println!("{}", MyFriendlyError::from(err)),
|
||||
}
|
||||
}
|
||||
SocialVoidCommand::SetProfile { field, value } => match field {
|
||||
ProfileField::Pic => {
|
||||
if let Some(filepath) = value {
|
||||
|
@ -185,6 +215,28 @@ async fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
SocialVoidCommand::Follow { peer } => {
|
||||
match sv.network.follow_peer(peer.clone()).await {
|
||||
Ok(relationship) => {
|
||||
println!(
|
||||
"The relationship type with\n\t`{}`\nis now\n\t{:?}",
|
||||
peer, relationship
|
||||
)
|
||||
}
|
||||
Err(err) => println!("{}", MyFriendlyError::from(err)),
|
||||
}
|
||||
}
|
||||
SocialVoidCommand::Unfollow { peer } => {
|
||||
match sv.network.unfollow_peer(peer.clone()).await {
|
||||
Ok(relationship) => {
|
||||
println!(
|
||||
"The relationship type with\n\t`{}`\nis now\n\t{:?}",
|
||||
peer, relationship
|
||||
)
|
||||
}
|
||||
Err(err) => println!("{}", MyFriendlyError::from(err)),
|
||||
}
|
||||
}
|
||||
SocialVoidCommand::Sync {} => {}
|
||||
}
|
||||
}
|
||||
|
@ -213,6 +265,20 @@ enum SocialVoidCommand {
|
|||
value: Option<String>,
|
||||
},
|
||||
GetMe,
|
||||
Followers {
|
||||
peer: Option<String>,
|
||||
page: Option<u32>,
|
||||
},
|
||||
Following {
|
||||
peer: Option<String>,
|
||||
page: Option<u32>,
|
||||
},
|
||||
Follow {
|
||||
peer: String,
|
||||
},
|
||||
Unfollow {
|
||||
peer: String,
|
||||
},
|
||||
SetProfile {
|
||||
#[structopt(subcommand)]
|
||||
field: ProfileField,
|
||||
|
|
|
@ -88,6 +88,46 @@ impl SVNetworkMethods {
|
|||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Get the number of followers of a specific peer or get the number of followers of the authenticated peer if the peer is `None`
|
||||
/// `page` can be none to return the first page of the result.
|
||||
pub async fn get_followers(
|
||||
&self,
|
||||
peer: Option<String>,
|
||||
page: Option<u32>,
|
||||
) -> Result<Vec<Peer>, Error> {
|
||||
let session_identification = self.session.session_identification()?;
|
||||
self.client
|
||||
.send_request(
|
||||
"network.get_followers",
|
||||
json!({
|
||||
"session_identification": serde_json::to_value(session_identification)?,
|
||||
"peer":peer,
|
||||
"page": page,
|
||||
}),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Get the number of peers following a specific peer or get the number of peers following the authenticated peer if the peer is `None`
|
||||
/// `page` can be none to return the first page of the result.
|
||||
pub async fn get_following(
|
||||
&self,
|
||||
peer: Option<String>,
|
||||
page: Option<u32>,
|
||||
) -> Result<Vec<Peer>, Error> {
|
||||
let session_identification = self.session.session_identification()?;
|
||||
self.client
|
||||
.send_request(
|
||||
"network.get_following",
|
||||
json!({
|
||||
"session_identification": serde_json::to_value(session_identification)?,
|
||||
"peer":peer,
|
||||
"page": page,
|
||||
}),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Reference in New Issue