Ignore Update(Note) if it tries to update local post

This commit is contained in:
silverpill 2022-10-15 14:12:26 +00:00
parent 0ce634564b
commit a74736d29f
2 changed files with 9 additions and 17 deletions

View file

@ -2,7 +2,6 @@ use chrono::Utc;
use tokio_postgres::GenericClient; use tokio_postgres::GenericClient;
use crate::activitypub::activity::Object; use crate::activitypub::activity::Object;
use crate::activitypub::identifiers::parse_local_object_id;
use crate::activitypub::vocabulary::NOTE; use crate::activitypub::vocabulary::NOTE;
use crate::errors::DatabaseError; use crate::errors::DatabaseError;
use crate::models::posts::queries::{ use crate::models::posts::queries::{
@ -15,23 +14,16 @@ use super::create_note::get_note_content;
pub async fn handle_update_note( pub async fn handle_update_note(
db_client: &mut impl GenericClient, db_client: &mut impl GenericClient,
instance_url: &str,
object: Object, object: Object,
) -> HandlerResult { ) -> HandlerResult {
let post_id = match parse_local_object_id(instance_url, &object.id) { let post_id = match get_post_by_remote_object_id(
Ok(post_id) => post_id, db_client,
Err(_) => { &object.id,
let post = match get_post_by_remote_object_id( ).await {
db_client, Ok(post) => post.id,
&object.id, // Ignore Update if post is not found locally
).await { Err(DatabaseError::NotFound(_)) => return Ok(None),
Ok(post) => post, Err(other_error) => return Err(other_error.into()),
// 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 content = get_note_content(&object)?; let content = get_note_content(&object)?;
let updated_at = object.updated.unwrap_or(Utc::now()); let updated_at = object.updated.unwrap_or(Utc::now());

View file

@ -191,7 +191,7 @@ pub async fn receive_activity(
require_actor_signature(&activity.actor, &signer_id)?; require_actor_signature(&activity.actor, &signer_id)?;
let object: Object = serde_json::from_value(activity.object) let object: Object = serde_json::from_value(activity.object)
.map_err(|_| ValidationError("invalid 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) => { (UPDATE, PERSON) => {
require_actor_signature(&activity.actor, &signer_id)?; require_actor_signature(&activity.actor, &signer_id)?;