Refactor handle_undo_follow() function

This commit is contained in:
silverpill 2022-12-08 22:47:56 +00:00
parent 84c93fecf1
commit e6be1cde2d
2 changed files with 5 additions and 6 deletions

View file

@ -26,6 +26,8 @@ pub async fn handle_undo(
activity: Activity,
) -> HandlerResult {
if let Some(FOLLOW) = activity.object["type"].as_str() {
// Object type is currently required for processing Undo(Follow)
// because activity IDs of remote follow requests are not stored.
return handle_undo_follow(config, db_client, activity).await
};

View file

@ -1,13 +1,13 @@
use tokio_postgres::GenericClient;
use crate::activitypub::{
activity::{Activity, Object},
activity::Activity,
identifiers::parse_local_actor_id,
receiver::find_object_id,
vocabulary::FOLLOW,
};
use crate::config::Config;
use crate::database::DatabaseError;
use crate::errors::ValidationError;
use crate::models::profiles::queries::{
get_profile_by_acct,
get_profile_by_remote_actor_id,
@ -20,14 +20,11 @@ pub async fn handle_undo_follow(
db_client: &mut impl GenericClient,
activity: Activity,
) -> HandlerResult {
let object: Object = serde_json::from_value(activity.object)
.map_err(|_| ValidationError("invalid object"))?;
let source_profile = get_profile_by_remote_actor_id(
db_client,
&activity.actor,
).await?;
let target_actor_id = object.object
.ok_or(ValidationError("invalid object"))?;
let target_actor_id = find_object_id(&activity.object["object"])?;
let target_username = parse_local_actor_id(
&config.instance_url(),
&target_actor_id,