Compare commits
2 Commits
fcce647711
...
d7c654fcb4
Author | SHA1 | Date |
---|---|---|
glyph | d7c654fcb4 | |
glyph | 21d0c4b6ab |
34
src/sbot.rs
34
src/sbot.rs
|
@ -13,26 +13,24 @@ use golgi::{
|
||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
use serde_json::value::Value;
|
use serde_json::value::Value;
|
||||||
|
|
||||||
use crate::{db::Post, sbot};
|
use crate::db::Post;
|
||||||
|
|
||||||
/// Check the follow status of a remote peer and follow them if not already
|
/// Check the follow status of a remote peer and follow them if not already
|
||||||
/// following.
|
/// following.
|
||||||
pub async fn follow_if_not_following(remote_peer: &str) -> Result<(), String> {
|
pub async fn follow_if_not_following(remote_peer: &str) -> Result<(), String> {
|
||||||
if let Ok(whoami) = sbot::whoami().await {
|
if let Ok(whoami) = whoami().await {
|
||||||
match sbot::is_following(&whoami, remote_peer).await {
|
match is_following(&whoami, remote_peer).await {
|
||||||
Ok(status) if status.as_str() == "false" => {
|
Ok(status) if status.as_str() == "false" => match follow_peer(remote_peer).await {
|
||||||
match sbot::follow_peer(remote_peer).await {
|
Ok(_) => {
|
||||||
Ok(_) => {
|
info!("Followed peer {}", &remote_peer);
|
||||||
info!("Followed peer {}", &remote_peer);
|
Ok(())
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
let err_msg = format!("Failed to follow peer {}: {}", &remote_peer, e);
|
|
||||||
warn!("{}", err_msg);
|
|
||||||
Err(err_msg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
Err(e) => {
|
||||||
|
let err_msg = format!("Failed to follow peer {}: {}", &remote_peer, e);
|
||||||
|
warn!("{}", err_msg);
|
||||||
|
Err(err_msg)
|
||||||
|
}
|
||||||
|
},
|
||||||
Ok(status) if status.as_str() == "true" => {
|
Ok(status) if status.as_str() == "true" => {
|
||||||
info!(
|
info!(
|
||||||
"Already following peer {}. No further action taken",
|
"Already following peer {}. No further action taken",
|
||||||
|
@ -55,11 +53,11 @@ pub async fn follow_if_not_following(remote_peer: &str) -> Result<(), String> {
|
||||||
/// Check the follow status of a remote peer and unfollow them if already
|
/// Check the follow status of a remote peer and unfollow them if already
|
||||||
/// following.
|
/// following.
|
||||||
pub async fn unfollow_if_following(remote_peer: &str) -> Result<(), String> {
|
pub async fn unfollow_if_following(remote_peer: &str) -> Result<(), String> {
|
||||||
if let Ok(whoami) = sbot::whoami().await {
|
if let Ok(whoami) = whoami().await {
|
||||||
match sbot::is_following(&whoami, remote_peer).await {
|
match is_following(&whoami, remote_peer).await {
|
||||||
Ok(status) if status.as_str() == "true" => {
|
Ok(status) if status.as_str() == "true" => {
|
||||||
info!("Unfollowing peer {}", &remote_peer);
|
info!("Unfollowing peer {}", &remote_peer);
|
||||||
match sbot::unfollow_peer(remote_peer).await {
|
match unfollow_peer(remote_peer).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!("Unfollowed peer {}", &remote_peer);
|
info!("Unfollowed peer {}", &remote_peer);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue