Fix parsing of mentions of local users
This commit is contained in:
parent
269318da76
commit
8e53214830
2 changed files with 20 additions and 0 deletions
|
@ -19,6 +19,9 @@ use super::fetchers::{
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum ImportError {
|
pub enum ImportError {
|
||||||
|
#[error("local object")]
|
||||||
|
LocalObject,
|
||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
FetchError(#[from] FetchError),
|
FetchError(#[from] FetchError),
|
||||||
|
|
||||||
|
@ -32,6 +35,7 @@ pub enum ImportError {
|
||||||
impl From<ImportError> for HttpError {
|
impl From<ImportError> for HttpError {
|
||||||
fn from(error: ImportError) -> Self {
|
fn from(error: ImportError) -> Self {
|
||||||
match error {
|
match error {
|
||||||
|
ImportError::LocalObject => HttpError::InternalError,
|
||||||
ImportError::FetchError(error) => {
|
ImportError::FetchError(error) => {
|
||||||
HttpError::ValidationError(error.to_string())
|
HttpError::ValidationError(error.to_string())
|
||||||
},
|
},
|
||||||
|
@ -47,6 +51,9 @@ pub async fn get_or_import_profile_by_actor_id(
|
||||||
media_dir: &Path,
|
media_dir: &Path,
|
||||||
actor_id: &str,
|
actor_id: &str,
|
||||||
) -> Result<DbActorProfile, ImportError> {
|
) -> Result<DbActorProfile, ImportError> {
|
||||||
|
if actor_id.starts_with(&instance.url()) {
|
||||||
|
return Err(ImportError::LocalObject);
|
||||||
|
};
|
||||||
let profile = match get_profile_by_actor_id(db_client, actor_id).await {
|
let profile = match get_profile_by_actor_id(db_client, actor_id).await {
|
||||||
Ok(profile) => profile,
|
Ok(profile) => profile,
|
||||||
Err(DatabaseError::NotFound(_)) => {
|
Err(DatabaseError::NotFound(_)) => {
|
||||||
|
@ -74,6 +81,9 @@ pub async fn import_profile_by_actor_address(
|
||||||
media_dir: &Path,
|
media_dir: &Path,
|
||||||
actor_address: &ActorAddress,
|
actor_address: &ActorAddress,
|
||||||
) -> Result<DbActorProfile, ImportError> {
|
) -> Result<DbActorProfile, ImportError> {
|
||||||
|
if actor_address.instance == instance.host() {
|
||||||
|
return Err(ImportError::LocalObject);
|
||||||
|
};
|
||||||
let profile_data = fetch_profile(
|
let profile_data = fetch_profile(
|
||||||
instance,
|
instance,
|
||||||
&actor_address.username,
|
&actor_address.username,
|
||||||
|
|
|
@ -268,6 +268,16 @@ pub async fn process_note(
|
||||||
// href attribute is not an actor ID but is a link to profile
|
// href attribute is not an actor ID but is a link to profile
|
||||||
if let Some(href) = tag.href {
|
if let Some(href) = tag.href {
|
||||||
// TODO: use actor_url
|
// TODO: use actor_url
|
||||||
|
match parse_actor_id(&config.instance_url(), &href) {
|
||||||
|
Ok(username) => {
|
||||||
|
let user = get_user_by_name(db_client, &username).await?;
|
||||||
|
if !mentions.contains(&user.id) {
|
||||||
|
mentions.push(user.id);
|
||||||
|
};
|
||||||
|
continue;
|
||||||
|
},
|
||||||
|
Err(_) => (), // remote profile
|
||||||
|
};
|
||||||
match get_or_import_profile_by_actor_id(
|
match get_or_import_profile_by_actor_id(
|
||||||
db_client,
|
db_client,
|
||||||
&instance,
|
&instance,
|
||||||
|
|
Loading…
Reference in a new issue