From a74736d29fafc06a707d914722ae98406f7c570c Mon Sep 17 00:00:00 2001 From: silverpill Date: Sat, 15 Oct 2022 14:12:26 +0000 Subject: [PATCH] Ignore Update(Note) if it tries to update local post --- src/activitypub/handlers/update_note.rs | 24 ++++++++---------------- src/activitypub/receiver.rs | 2 +- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/activitypub/handlers/update_note.rs b/src/activitypub/handlers/update_note.rs index 8367d4e..92f1b4d 100644 --- a/src/activitypub/handlers/update_note.rs +++ b/src/activitypub/handlers/update_note.rs @@ -2,7 +2,6 @@ use chrono::Utc; use tokio_postgres::GenericClient; use crate::activitypub::activity::Object; -use crate::activitypub::identifiers::parse_local_object_id; use crate::activitypub::vocabulary::NOTE; use crate::errors::DatabaseError; use crate::models::posts::queries::{ @@ -15,23 +14,16 @@ use super::create_note::get_note_content; pub async fn handle_update_note( db_client: &mut impl GenericClient, - instance_url: &str, object: Object, ) -> HandlerResult { - let post_id = match parse_local_object_id(instance_url, &object.id) { - Ok(post_id) => post_id, - Err(_) => { - let post = match get_post_by_remote_object_id( - db_client, - &object.id, - ).await { - Ok(post) => post, - // Ignore Update if post is not found locally - Err(DatabaseError::NotFound(_)) => return Ok(None), - Err(other_error) => return Err(other_error.into()), - }; - post.id - }, + let post_id = match get_post_by_remote_object_id( + db_client, + &object.id, + ).await { + Ok(post) => post.id, + // Ignore Update if post is not found locally + Err(DatabaseError::NotFound(_)) => return Ok(None), + Err(other_error) => return Err(other_error.into()), }; let content = get_note_content(&object)?; let updated_at = object.updated.unwrap_or(Utc::now()); diff --git a/src/activitypub/receiver.rs b/src/activitypub/receiver.rs index 33e3bac..af8b54a 100644 --- a/src/activitypub/receiver.rs +++ b/src/activitypub/receiver.rs @@ -191,7 +191,7 @@ pub async fn receive_activity( require_actor_signature(&activity.actor, &signer_id)?; let object: Object = serde_json::from_value(activity.object) .map_err(|_| ValidationError("invalid object"))?; - handle_update_note(db_client, &config.instance_url(), object).await? + handle_update_note(db_client, object).await? }, (UPDATE, PERSON) => { require_actor_signature(&activity.actor, &signer_id)?;