Ignore Accept(Follow) if follow request is already accepted

This commit is contained in:
silverpill 2022-09-12 23:36:35 +00:00
parent d0f97a33b3
commit 9aafe0eaf4
2 changed files with 10 additions and 0 deletions

View file

@ -13,6 +13,7 @@ use crate::models::relationships::queries::{
follow_request_accepted,
get_follow_request_by_id,
};
use crate::models::relationships::types::FollowRequestStatus;
use super::HandlerResult;
pub async fn handle_accept_follow(
@ -30,6 +31,10 @@ pub async fn handle_accept_follow(
if follow_request.target_id != actor_profile.id {
return Err(ValidationError("actor is not a target").into());
};
if matches!(follow_request.request_status, FollowRequestStatus::Accepted) {
// Ignore Accept if follow request already accepted
return Ok(None);
};
follow_request_accepted(db_client, &follow_request_id).await?;
Ok(Some(FOLLOW))
}

View file

@ -13,6 +13,7 @@ use crate::models::relationships::queries::{
follow_request_rejected,
get_follow_request_by_id,
};
use crate::models::relationships::types::FollowRequestStatus;
use super::HandlerResult;
pub async fn handle_reject_follow(
@ -30,6 +31,10 @@ pub async fn handle_reject_follow(
if follow_request.target_id != actor_profile.id {
return Err(ValidationError("actor is not a target").into());
};
if matches!(follow_request.request_status, FollowRequestStatus::Rejected) {
// Ignore Reject if follow request already rejected
return Ok(None);
};
follow_request_rejected(db_client, &follow_request_id).await?;
Ok(Some(FOLLOW))
}