From e6be1cde2d5d91fa7f353106091df56f36733c9e Mon Sep 17 00:00:00 2001 From: silverpill Date: Thu, 8 Dec 2022 22:47:56 +0000 Subject: [PATCH] Refactor handle_undo_follow() function --- src/activitypub/handlers/undo.rs | 2 ++ src/activitypub/handlers/undo_follow.rs | 9 +++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/activitypub/handlers/undo.rs b/src/activitypub/handlers/undo.rs index 7c03bc8..3ec6e02 100644 --- a/src/activitypub/handlers/undo.rs +++ b/src/activitypub/handlers/undo.rs @@ -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 }; diff --git a/src/activitypub/handlers/undo_follow.rs b/src/activitypub/handlers/undo_follow.rs index b19eb6a..ca8c3bd 100644 --- a/src/activitypub/handlers/undo_follow.rs +++ b/src/activitypub/handlers/undo_follow.rs @@ -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,