Merge pull request 'Remove `sbot` module prefix from functions within the module' (#3) from sbot_module_cleanup into main
Reviewed-on: #3
This commit is contained in:
commit
d7c654fcb4
34
src/sbot.rs
34
src/sbot.rs
|
@ -13,26 +13,24 @@ use golgi::{
|
|||
use log::{debug, info, warn};
|
||||
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
|
||||
/// following.
|
||||
pub async fn follow_if_not_following(remote_peer: &str) -> Result<(), String> {
|
||||
if let Ok(whoami) = sbot::whoami().await {
|
||||
match sbot::is_following(&whoami, remote_peer).await {
|
||||
Ok(status) if status.as_str() == "false" => {
|
||||
match sbot::follow_peer(remote_peer).await {
|
||||
Ok(_) => {
|
||||
info!("Followed peer {}", &remote_peer);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
let err_msg = format!("Failed to follow peer {}: {}", &remote_peer, e);
|
||||
warn!("{}", err_msg);
|
||||
Err(err_msg)
|
||||
}
|
||||
if let Ok(whoami) = whoami().await {
|
||||
match is_following(&whoami, remote_peer).await {
|
||||
Ok(status) if status.as_str() == "false" => match follow_peer(remote_peer).await {
|
||||
Ok(_) => {
|
||||
info!("Followed peer {}", &remote_peer);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
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" => {
|
||||
info!(
|
||||
"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
|
||||
/// following.
|
||||
pub async fn unfollow_if_following(remote_peer: &str) -> Result<(), String> {
|
||||
if let Ok(whoami) = sbot::whoami().await {
|
||||
match sbot::is_following(&whoami, remote_peer).await {
|
||||
if let Ok(whoami) = whoami().await {
|
||||
match is_following(&whoami, remote_peer).await {
|
||||
Ok(status) if status.as_str() == "true" => {
|
||||
info!("Unfollowing peer {}", &remote_peer);
|
||||
match sbot::unfollow_peer(remote_peer).await {
|
||||
match unfollow_peer(remote_peer).await {
|
||||
Ok(_) => {
|
||||
info!("Unfollowed peer {}", &remote_peer);
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue