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.
- 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

View file

@ -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,24 +36,16 @@ 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,
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()),
};
post.id
},
};
match create_reaction(
db_client,
&author.id,