Rewrite fetch_profile to accept ActorAddress object

This commit is contained in:
silverpill 2022-05-02 22:50:07 +00:00
parent b05a8b2757
commit 5c0e6b0b0c
3 changed files with 15 additions and 9 deletions

View file

@ -208,13 +208,19 @@ pub struct ActorAddress {
pub is_local: bool,
}
impl ToString for ActorAddress {
fn to_string(&self) -> String {
format!("{}@{}", self.username, self.instance)
}
}
impl ActorAddress {
/// Returns acct string, as used in Mastodon
pub fn acct(&self) -> String {
if self.is_local {
self.username.clone()
} else {
format!("{}@{}", self.username, self.instance)
self.to_string()
}
}
}

View file

@ -4,7 +4,7 @@ use reqwest::Method;
use serde_json::Value;
use crate::activitypub::activity::Object;
use crate::activitypub::actor::Actor;
use crate::activitypub::actor::{Actor, ActorAddress};
use crate::activitypub::constants::ACTIVITY_CONTENT_TYPE;
use crate::config::Instance;
use crate::http_signatures::create::{create_http_signature, SignatureError};
@ -112,14 +112,15 @@ pub async fn fetch_avatar_and_banner(
pub async fn fetch_profile(
instance: &Instance,
username: &str,
actor_host: &str,
actor_address: &ActorAddress,
media_dir: &Path,
) -> Result<ProfileCreateData, FetchError> {
let actor_address = format!("{}@{}", &username, &actor_host);
let webfinger_account_uri = format!("acct:{}", actor_address);
let webfinger_account_uri = format!("acct:{}", actor_address.to_string());
// TOOD: support http
let webfinger_url = format!("https://{}/.well-known/webfinger", actor_host);
let webfinger_url = format!(
"https://{}/.well-known/webfinger",
actor_address.instance,
);
let client = reqwest::Client::new();
let mut request_builder = client.get(&webfinger_url);
if !instance.is_private {

View file

@ -94,8 +94,7 @@ pub async fn import_profile_by_actor_address(
};
let mut profile_data = fetch_profile(
instance,
&actor_address.username,
&actor_address.instance,
actor_address,
media_dir,
).await?;
if profile_data.acct != actor_address.acct() {