diff --git a/CHANGELOG.md b/CHANGELOG.md index 7be3c7b..211c8d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Don't stop activity processing on invalid local mentions. - Accept actor objects where `attachment` property value is not an array. - Don't download HTML pages attached by GNU Social. +- Ignore `Like()` activity if local post doesn't exist. ## [1.9.0] - 2023-01-08 diff --git a/src/activitypub/handlers/like.rs b/src/activitypub/handlers/like.rs index d6e22b0..aa7bf6d 100644 --- a/src/activitypub/handlers/like.rs +++ b/src/activitypub/handlers/like.rs @@ -3,15 +3,16 @@ use serde_json::Value; use crate::activitypub::{ fetcher::helpers::get_or_import_profile_by_actor_id, - identifiers::parse_local_object_id, receiver::deserialize_into_object_id, vocabulary::NOTE, }; use crate::config::Config; use crate::database::{DatabaseClient, DatabaseError}; use crate::errors::ValidationError; -use crate::models::reactions::queries::create_reaction; -use crate::models::posts::queries::get_post_by_remote_object_id; +use crate::models::{ + reactions::queries::create_reaction, + posts::helpers::get_post_by_object_id, +}; use super::HandlerResult; #[derive(Deserialize)] @@ -35,23 +36,15 @@ pub async fn handle_like( &config.media_dir(), &activity.actor, ).await?; - let post_id = match parse_local_object_id( + let post_id = match get_post_by_object_id( + db_client, &config.instance_url(), &activity.object, - ) { - Ok(post_id) => post_id, - Err(_) => { - let post = match get_post_by_remote_object_id( - db_client, - &activity.object, - ).await { - Ok(post) => post, - // Ignore like if post is not found locally - Err(DatabaseError::NotFound(_)) => return Ok(None), - Err(other_error) => return Err(other_error.into()), - }; - post.id - }, + ).await { + Ok(post) => post.id, + // Ignore like if post is not found locally + Err(DatabaseError::NotFound(_)) => return Ok(None), + Err(other_error) => return Err(other_error.into()), }; match create_reaction( db_client,