Ignore Update(Note) if it tries to update local post
This commit is contained in:
parent
0ce634564b
commit
a74736d29f
2 changed files with 9 additions and 17 deletions
|
@ -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,24 +14,17 @@ 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(
|
||||
let post_id = match get_post_by_remote_object_id(
|
||||
db_client,
|
||||
&object.id,
|
||||
).await {
|
||||
Ok(post) => post,
|
||||
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()),
|
||||
};
|
||||
post.id
|
||||
},
|
||||
};
|
||||
let content = get_note_content(&object)?;
|
||||
let updated_at = object.updated.unwrap_or(Utc::now());
|
||||
let post_data = PostUpdateData { content, updated_at };
|
||||
|
|
|
@ -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)?;
|
||||
|
|
Loading…
Reference in a new issue