Ignore Like() activity if local post doesn't exist

This commit is contained in:
silverpill 2023-01-18 01:12:49 +00:00
parent 01f56d9ef7
commit 6af5b8c24d
2 changed files with 12 additions and 18 deletions

View file

@ -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. - Don't stop activity processing on invalid local mentions.
- Accept actor objects where `attachment` property value is not an array. - Accept actor objects where `attachment` property value is not an array.
- Don't download HTML pages attached by GNU Social. - Don't download HTML pages attached by GNU Social.
- Ignore `Like()` activity if local post doesn't exist.
## [1.9.0] - 2023-01-08 ## [1.9.0] - 2023-01-08

View file

@ -3,15 +3,16 @@ use serde_json::Value;
use crate::activitypub::{ use crate::activitypub::{
fetcher::helpers::get_or_import_profile_by_actor_id, fetcher::helpers::get_or_import_profile_by_actor_id,
identifiers::parse_local_object_id,
receiver::deserialize_into_object_id, receiver::deserialize_into_object_id,
vocabulary::NOTE, vocabulary::NOTE,
}; };
use crate::config::Config; use crate::config::Config;
use crate::database::{DatabaseClient, DatabaseError}; use crate::database::{DatabaseClient, DatabaseError};
use crate::errors::ValidationError; use crate::errors::ValidationError;
use crate::models::reactions::queries::create_reaction; use crate::models::{
use crate::models::posts::queries::get_post_by_remote_object_id; reactions::queries::create_reaction,
posts::helpers::get_post_by_object_id,
};
use super::HandlerResult; use super::HandlerResult;
#[derive(Deserialize)] #[derive(Deserialize)]
@ -35,23 +36,15 @@ pub async fn handle_like(
&config.media_dir(), &config.media_dir(),
&activity.actor, &activity.actor,
).await?; ).await?;
let post_id = match parse_local_object_id( let post_id = match get_post_by_object_id(
db_client,
&config.instance_url(), &config.instance_url(),
&activity.object, &activity.object,
) { ).await {
Ok(post_id) => post_id, Ok(post) => post.id,
Err(_) => { // Ignore like if post is not found locally
let post = match get_post_by_remote_object_id( Err(DatabaseError::NotFound(_)) => return Ok(None),
db_client, Err(other_error) => return Err(other_error.into()),
&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
},
}; };
match create_reaction( match create_reaction(
db_client, db_client,