diff --git a/src/activitypub/fetcher/helpers.rs b/src/activitypub/fetcher/helpers.rs index bba6b7b..824f70e 100644 --- a/src/activitypub/fetcher/helpers.rs +++ b/src/activitypub/fetcher/helpers.rs @@ -165,6 +165,25 @@ pub async fn get_or_import_profile_by_actor_address( Ok(profile) } +pub async fn get_post_by_object_id( + db_client: &impl DatabaseClient, + instance_url: &str, + object_id: &str, +) -> Result { + match parse_local_object_id(instance_url, object_id) { + Ok(post_id) => { + // Local post + let post = get_local_post_by_id(db_client, &post_id).await?; + Ok(post) + }, + Err(_) => { + // Remote post + let post = get_post_by_remote_object_id(db_client, object_id).await?; + Ok(post) + }, + } +} + const RECURSION_DEPTH_MAX: usize = 50; pub async fn import_post( diff --git a/src/activitypub/handlers/create.rs b/src/activitypub/handlers/create.rs index 2b4acd3..5e1f1a1 100644 --- a/src/activitypub/handlers/create.rs +++ b/src/activitypub/handlers/create.rs @@ -17,6 +17,7 @@ use crate::activitypub::{ fetcher::helpers::{ get_or_import_profile_by_actor_address, get_or_import_profile_by_actor_id, + get_post_by_object_id, import_post, }, identifiers::{parse_local_actor_id, profile_actor_id}, @@ -41,7 +42,6 @@ use crate::models::{ }, posts::{ hashtags::normalize_hashtag, - helpers::get_post_by_object_id, mentions::mention_to_address, queries::create_post, types::{Post, PostCreateData, Visibility}, diff --git a/src/activitypub/handlers/like.rs b/src/activitypub/handlers/like.rs index 0fc6212..deadc0b 100644 --- a/src/activitypub/handlers/like.rs +++ b/src/activitypub/handlers/like.rs @@ -4,7 +4,10 @@ use serde_json::Value; use mitra_config::Config; use crate::activitypub::{ - fetcher::helpers::get_or_import_profile_by_actor_id, + fetcher::helpers::{ + get_or_import_profile_by_actor_id, + get_post_by_object_id, + }, receiver::deserialize_into_object_id, vocabulary::NOTE, }; @@ -12,7 +15,6 @@ use crate::database::{DatabaseClient, DatabaseError}; use crate::errors::ValidationError; use crate::models::{ reactions::queries::create_reaction, - posts::helpers::get_post_by_object_id, }; use super::HandlerResult; diff --git a/src/models/posts/helpers.rs b/src/models/posts/helpers.rs index 73bee0a..f4a87d1 100644 --- a/src/models/posts/helpers.rs +++ b/src/models/posts/helpers.rs @@ -1,6 +1,5 @@ use uuid::Uuid; -use crate::activitypub::identifiers::parse_local_object_id; use crate::database::{DatabaseClient, DatabaseError}; use crate::models::{ reactions::queries::find_favourited_by_user, @@ -10,7 +9,6 @@ use crate::models::{ }; use super::queries::{ get_post_by_id, - get_post_by_remote_object_id, get_related_posts, find_reposted_by_user, }; @@ -142,25 +140,6 @@ pub async fn get_local_post_by_id( Ok(post) } -pub async fn get_post_by_object_id( - db_client: &impl DatabaseClient, - instance_url: &str, - object_id: &str, -) -> Result { - match parse_local_object_id(instance_url, object_id) { - Ok(post_id) => { - // Local post - let post = get_local_post_by_id(db_client, &post_id).await?; - Ok(post) - }, - Err(_) => { - // Remote post - let post = get_post_by_remote_object_id(db_client, object_id).await?; - Ok(post) - }, - } -} - #[cfg(test)] mod tests { use serial_test::serial; diff --git a/src/models/posts/links.rs b/src/models/posts/links.rs index cbc0444..3e3ca19 100644 --- a/src/models/posts/links.rs +++ b/src/models/posts/links.rs @@ -2,8 +2,8 @@ use std::collections::HashMap; use regex::{Captures, Match, Regex}; +use crate::activitypub::fetcher::helpers::get_post_by_object_id; use crate::database::{DatabaseClient, DatabaseError}; -use super::helpers::get_post_by_object_id; use super::types::{Post, Visibility}; // MediaWiki-like syntax: [[url|text]]