Rename process_note() to import_post() and change its error type to ImportError
This commit is contained in:
parent
ec44fce526
commit
2fda205dbf
2 changed files with 8 additions and 8 deletions
|
@ -144,12 +144,12 @@ fn clean_note_content(content: &str) -> Result<String, ValidationError> {
|
||||||
Ok(content_safe)
|
Ok(content_safe)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn process_note(
|
pub async fn import_post(
|
||||||
config: &Config,
|
config: &Config,
|
||||||
db_client: &mut impl GenericClient,
|
db_client: &mut impl GenericClient,
|
||||||
object_id: String,
|
object_id: String,
|
||||||
object_received: Option<Object>,
|
object_received: Option<Object>,
|
||||||
) -> Result<Post, HttpError> {
|
) -> Result<Post, ImportError> {
|
||||||
let instance = config.instance();
|
let instance = config.instance();
|
||||||
let mut maybe_object_id_to_fetch = Some(object_id);
|
let mut maybe_object_id_to_fetch = Some(object_id);
|
||||||
let mut maybe_object = object_received;
|
let mut maybe_object = object_received;
|
||||||
|
@ -487,7 +487,7 @@ pub async fn receive_activity(
|
||||||
// Fetch forwarded note, don't trust the sender
|
// Fetch forwarded note, don't trust the sender
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
process_note(config, db_client, object_id, object_received).await?;
|
import_post(config, db_client, object_id, object_received).await?;
|
||||||
NOTE
|
NOTE
|
||||||
},
|
},
|
||||||
(ANNOUNCE, _) => {
|
(ANNOUNCE, _) => {
|
||||||
|
@ -509,7 +509,7 @@ pub async fn receive_activity(
|
||||||
Ok(post_id) => post_id,
|
Ok(post_id) => post_id,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// Try to get remote post
|
// Try to get remote post
|
||||||
let post = process_note(config, db_client, object_id, None).await?;
|
let post = import_post(config, db_client, object_id, None).await?;
|
||||||
post.id
|
post.id
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ use tokio_postgres::GenericClient;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::activitypub::actor::ActorAddress;
|
use crate::activitypub::actor::ActorAddress;
|
||||||
use crate::activitypub::receiver::process_note;
|
use crate::activitypub::receiver::import_post;
|
||||||
use crate::activitypub::fetcher::helpers::import_profile_by_actor_address;
|
use crate::activitypub::fetcher::helpers::import_profile_by_actor_address;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::errors::{ValidationError, HttpError};
|
use crate::errors::{ValidationError, HttpError};
|
||||||
|
@ -99,12 +99,12 @@ async fn search_profiles(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds public post by its object ID
|
/// Finds public post by its object ID
|
||||||
async fn search_note(
|
async fn search_post(
|
||||||
config: &Config,
|
config: &Config,
|
||||||
db_client: &mut impl GenericClient,
|
db_client: &mut impl GenericClient,
|
||||||
url: String,
|
url: String,
|
||||||
) -> Result<Option<Post>, HttpError> {
|
) -> Result<Option<Post>, HttpError> {
|
||||||
let maybe_post = match process_note(
|
let maybe_post = match import_post(
|
||||||
config, db_client,
|
config, db_client,
|
||||||
url,
|
url,
|
||||||
None,
|
None,
|
||||||
|
@ -131,7 +131,7 @@ pub async fn search(
|
||||||
profiles = search_profiles(config, db_client, username, instance).await?;
|
profiles = search_profiles(config, db_client, username, instance).await?;
|
||||||
},
|
},
|
||||||
SearchQuery::Url(url) => {
|
SearchQuery::Url(url) => {
|
||||||
let maybe_post = search_note(config, db_client, url).await?;
|
let maybe_post = search_post(config, db_client, url).await?;
|
||||||
if let Some(post) = maybe_post {
|
if let Some(post) = maybe_post {
|
||||||
if can_view_post(db_client, Some(current_user), &post).await? {
|
if can_view_post(db_client, Some(current_user), &post).await? {
|
||||||
posts = vec![post];
|
posts = vec![post];
|
||||||
|
|
Loading…
Reference in a new issue