Add handler for Reject(Follow) activity
This commit is contained in:
parent
d2adda2034
commit
602e4ec229
3 changed files with 33 additions and 3 deletions
|
@ -14,7 +14,11 @@ use crate::models::profiles::queries::{
|
||||||
update_profile,
|
update_profile,
|
||||||
};
|
};
|
||||||
use crate::models::profiles::types::ProfileUpdateData;
|
use crate::models::profiles::types::ProfileUpdateData;
|
||||||
use crate::models::relationships::queries::{accept_follow_request, follow, unfollow};
|
use crate::models::relationships::queries::{
|
||||||
|
follow_request_accepted,
|
||||||
|
follow_request_rejected,
|
||||||
|
follow, unfollow,
|
||||||
|
};
|
||||||
use crate::models::users::queries::get_user_by_id;
|
use crate::models::users::queries::get_user_by_id;
|
||||||
use super::activity::{Object, Activity, create_activity_accept_follow};
|
use super::activity::{Object, Activity, create_activity_accept_follow};
|
||||||
use super::actor::Actor;
|
use super::actor::Actor;
|
||||||
|
@ -64,7 +68,13 @@ pub async fn receive_activity(
|
||||||
.map_err(|_| ValidationError("invalid object"))?;
|
.map_err(|_| ValidationError("invalid object"))?;
|
||||||
// TODO: reject if object ID contains wrong instance URI
|
// TODO: reject if object ID contains wrong instance URI
|
||||||
let follow_request_id = parse_object_id(&object.id)?;
|
let follow_request_id = parse_object_id(&object.id)?;
|
||||||
accept_follow_request(db_client, &follow_request_id).await?;
|
follow_request_accepted(db_client, &follow_request_id).await?;
|
||||||
|
},
|
||||||
|
(REJECT, FOLLOW) => {
|
||||||
|
let object: Object = serde_json::from_value(activity.object)
|
||||||
|
.map_err(|_| ValidationError("invalid object"))?;
|
||||||
|
let follow_request_id = parse_object_id(&object.id)?;
|
||||||
|
follow_request_rejected(db_client, &follow_request_id).await?;
|
||||||
},
|
},
|
||||||
(CREATE, NOTE) => {
|
(CREATE, NOTE) => {
|
||||||
let object: Object = serde_json::from_value(activity.object)
|
let object: Object = serde_json::from_value(activity.object)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
pub const ACCEPT: &str = "Accept";
|
pub const ACCEPT: &str = "Accept";
|
||||||
pub const CREATE: &str = "Create";
|
pub const CREATE: &str = "Create";
|
||||||
pub const FOLLOW: &str = "Follow";
|
pub const FOLLOW: &str = "Follow";
|
||||||
|
pub const REJECT: &str = "Reject";
|
||||||
pub const UNDO: &str = "Undo";
|
pub const UNDO: &str = "Undo";
|
||||||
pub const UPDATE: &str = "Update";
|
pub const UPDATE: &str = "Update";
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ pub async fn create_follow_request(
|
||||||
Ok(request)
|
Ok(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn accept_follow_request(
|
pub async fn follow_request_accepted(
|
||||||
db_client: &mut impl GenericClient,
|
db_client: &mut impl GenericClient,
|
||||||
request_id: &Uuid,
|
request_id: &Uuid,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
|
@ -188,6 +188,25 @@ pub async fn accept_follow_request(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn follow_request_rejected(
|
||||||
|
db_client: &impl GenericClient,
|
||||||
|
request_id: &Uuid,
|
||||||
|
) -> Result<(), DatabaseError> {
|
||||||
|
let status_sql: i16 = FollowRequestStatus::Rejected.into();
|
||||||
|
let updated_count = db_client.execute(
|
||||||
|
"
|
||||||
|
UPDATE follow_request
|
||||||
|
SET request_status = $1
|
||||||
|
WHERE id = $2
|
||||||
|
",
|
||||||
|
&[&status_sql, &request_id],
|
||||||
|
).await?;
|
||||||
|
if updated_count == 0 {
|
||||||
|
return Err(DatabaseError::NotFound("follow request"));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn delete_follow_request(
|
pub async fn delete_follow_request(
|
||||||
db_client: &impl GenericClient,
|
db_client: &impl GenericClient,
|
||||||
source_id: &Uuid,
|
source_id: &Uuid,
|
||||||
|
|
Loading…
Reference in a new issue