Move AP ID helpers to activitypub::identifiers module

This commit is contained in:
silverpill 2022-07-15 17:31:02 +00:00
parent 34ecf56ccd
commit d2ba86315c
28 changed files with 147 additions and 137 deletions

View file

@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use super::constants::AP_CONTEXT;
use super::views::get_actor_url;
use super::identifiers::local_actor_id;
use super::vocabulary::*;
#[derive(Deserialize, Serialize)]
@ -108,10 +108,7 @@ pub fn create_activity(
primary_audience: Vec<String>,
secondary_audience: Vec<String>,
) -> Activity {
let actor_id = get_actor_url(
instance_url,
actor_name,
);
let actor_id = local_actor_id(instance_url, actor_name);
Activity {
context: json!(AP_CONTEXT),
id: activity_id,

View file

@ -13,15 +13,7 @@ use crate::models::users::types::User;
use crate::utils::crypto::{deserialize_private_key, get_public_key_pem};
use crate::utils::files::get_file_url;
use super::constants::{ACTOR_KEY_SUFFIX, AP_CONTEXT};
use super::identifiers::LocalActorCollection;
use super::views::{
get_actor_url,
get_inbox_url,
get_outbox_url,
get_followers_url,
get_following_url,
get_subscribers_url,
};
use super::identifiers::{local_actor_id, LocalActorCollection};
use super::vocabulary::{IDENTITY_PROOF, IMAGE, PERSON, PROPERTY_VALUE, SERVICE};
const W3ID_CONTEXT: &str = "https://w3id.org/security/v1";
@ -253,12 +245,12 @@ pub fn get_local_actor(
instance_url: &str,
) -> Result<Actor, ActorKeyError> {
let username = &user.profile.username;
let actor_id = get_actor_url(instance_url, username);
let inbox = get_inbox_url(instance_url, username);
let outbox = get_outbox_url(instance_url, username);
let followers = get_followers_url(instance_url, username);
let following = get_following_url(instance_url, username);
let subscribers = get_subscribers_url(instance_url, username);
let actor_id = local_actor_id(instance_url, username);
let inbox = LocalActorCollection::Inbox.of(&actor_id);
let outbox = LocalActorCollection::Outbox.of(&actor_id);
let followers = LocalActorCollection::Followers.of(&actor_id);
let following = LocalActorCollection::Following.of(&actor_id);
let subscribers = LocalActorCollection::Subscribers.of(&actor_id);
let private_key = deserialize_private_key(&user.private_key)?;
let public_key_pem = get_public_key_pem(&private_key)?;

View file

@ -5,7 +5,7 @@ use crate::activitypub::{
actor::Actor,
constants::AP_CONTEXT,
deliverer::OutgoingActivity,
views::get_object_url,
identifiers::local_object_id,
vocabulary::{ACCEPT, FOLLOW},
};
use crate::config::Instance;
@ -26,7 +26,7 @@ fn build_accept_follow(
..Default::default()
};
// Accept(Follow) is idempotent so its ID can be random
let activity_id = get_object_url(instance_url, &new_uuid());
let activity_id = local_object_id(instance_url, &new_uuid());
let activity = create_activity(
instance_url,
&actor_profile.username,

View file

@ -6,7 +6,7 @@ use crate::activitypub::{
actor::Actor,
constants::AP_PUBLIC,
deliverer::OutgoingActivity,
views::{get_followers_url, get_object_url},
identifiers::{local_actor_followers, local_object_id},
vocabulary::ANNOUNCE,
};
use crate::config::Instance;
@ -23,8 +23,9 @@ fn build_announce_note(
repost_id: &Uuid,
) -> Activity {
let object_id = post.get_object_id(instance_url);
let activity_id = get_object_url(instance_url, repost_id);
let activity_id = local_object_id(instance_url, repost_id);
let recipient_id = post.author.actor_id(instance_url);
let followers = local_actor_followers(instance_url, &actor_profile.username);
let activity = create_activity(
instance_url,
&actor_profile.username,
@ -32,7 +33,7 @@ fn build_announce_note(
activity_id,
object_id,
vec![AP_PUBLIC.to_string(), recipient_id],
vec![get_followers_url(instance_url, &actor_profile.username)],
vec![followers],
);
activity
}

View file

@ -7,7 +7,12 @@ use crate::activitypub::{
actor::Actor,
constants::{AP_CONTEXT, AP_PUBLIC},
deliverer::OutgoingActivity,
views::{get_actor_url, get_followers_url, get_object_url, get_subscribers_url},
identifiers::{
local_actor_id,
local_actor_followers,
local_actor_subscribers,
local_object_id,
},
vocabulary::{CREATE, DOCUMENT, HASHTAG, MENTION, NOTE},
};
use crate::config::Instance;
@ -56,14 +61,8 @@ pub fn build_note(
post: &Post,
subscribers: Vec<DbActorProfile>,
) -> Note {
let object_id = get_object_url(
instance_url,
&post.id,
);
let actor_id = get_actor_url(
instance_url,
&post.author.username,
);
let object_id = local_object_id(instance_url, &post.id);
let actor_id = local_actor_id(instance_url, &post.author.username);
let attachments: Vec<Attachment> = post.attachments.iter().map(|db_item| {
let url = get_file_url(instance_url, &db_item.file_name);
let media_type = db_item.media_type.clone();
@ -76,20 +75,20 @@ pub fn build_note(
}).collect();
let mut primary_audience = vec![];
let mut secondary_audience = vec![];
let followers_collection_url =
get_followers_url(instance_url, &post.author.username);
let subscribers_collection_url =
get_subscribers_url(instance_url, &post.author.username);
let followers_collection_id =
local_actor_followers(instance_url, &post.author.username);
let subscribers_collection_id =
local_actor_subscribers(instance_url, &post.author.username);
match post.visibility {
Visibility::Public => {
primary_audience.push(AP_PUBLIC.to_string());
secondary_audience.push(followers_collection_url);
secondary_audience.push(followers_collection_id);
},
Visibility::Followers => {
primary_audience.push(followers_collection_url);
primary_audience.push(followers_collection_id);
},
Visibility::Subscribers => {
primary_audience.push(subscribers_collection_url);
primary_audience.push(subscribers_collection_id);
},
Visibility::Direct => (),
};
@ -268,7 +267,7 @@ mod tests {
assert_eq!(note.content, post.content);
assert_eq!(note.to, vec![AP_PUBLIC]);
assert_eq!(note.cc, vec![
get_followers_url(INSTANCE_URL, "author"),
local_actor_followers(INSTANCE_URL, "author"),
]);
}
@ -281,7 +280,7 @@ mod tests {
let note = build_note(INSTANCE_HOST, INSTANCE_URL, &post, vec![]);
assert_eq!(note.to, vec![
get_followers_url(INSTANCE_URL, &post.author.username),
local_actor_followers(INSTANCE_URL, &post.author.username),
]);
assert_eq!(note.cc.is_empty(), true);
}
@ -302,7 +301,7 @@ mod tests {
);
assert_eq!(note.to, vec![
AP_PUBLIC.to_string(),
get_actor_url(INSTANCE_URL, &parent.author.username),
local_actor_id(INSTANCE_URL, &parent.author.username),
]);
}

View file

@ -6,7 +6,7 @@ use crate::activitypub::{
actor::Actor,
constants::AP_CONTEXT,
deliverer::OutgoingActivity,
views::get_object_url,
identifiers::local_object_id,
vocabulary::{FOLLOW, PERSON},
};
use crate::config::Instance;
@ -25,7 +25,7 @@ fn build_follow(
object_type: PERSON.to_string(),
..Default::default()
};
let activity_id = get_object_url(instance_url, follow_request_id);
let activity_id = local_object_id(instance_url, follow_request_id);
let activity = create_activity(
instance_url,
&actor_profile.username,

View file

@ -6,7 +6,7 @@ use crate::activitypub::{
actor::Actor,
constants::AP_PUBLIC,
deliverer::OutgoingActivity,
views::get_object_url,
identifiers::local_object_id,
vocabulary::LIKE,
};
use crate::config::Instance;
@ -22,7 +22,7 @@ fn build_like_note(
reaction_id: &Uuid,
recipient_id: &str,
) -> Activity {
let activity_id = get_object_url(instance_url, reaction_id);
let activity_id = local_object_id(instance_url, reaction_id);
let activity = create_activity(
instance_url,
&actor_profile.username,

View file

@ -5,7 +5,7 @@ use crate::activitypub::{
activity::{create_activity, Activity},
constants::AP_PUBLIC,
deliverer::OutgoingActivity,
views::{get_followers_url, get_object_url},
identifiers::{local_actor_followers, local_object_id},
vocabulary::UNDO,
};
use crate::config::Instance;
@ -21,15 +21,15 @@ fn build_undo_announce(
repost_id: &Uuid,
recipient_id: &str,
) -> Activity {
let object_id = get_object_url(
instance_url,
repost_id,
);
let object_id = local_object_id(instance_url, repost_id);
let activity_id = format!("{}/undo", object_id);
let primary_audience = vec![
AP_PUBLIC.to_string(),
recipient_id.to_string(),
];
let secondary_audience = vec![
local_actor_followers(instance_url, &actor_profile.username),
];
create_activity(
instance_url,
&actor_profile.username,
@ -37,7 +37,7 @@ fn build_undo_announce(
activity_id,
object_id,
primary_audience,
vec![get_followers_url(instance_url, &actor_profile.username)],
secondary_audience,
)
}

View file

@ -6,7 +6,7 @@ use crate::activitypub::{
actor::Actor,
constants::AP_CONTEXT,
deliverer::OutgoingActivity,
views::{get_actor_url, get_object_url},
identifiers::{local_actor_id, local_object_id},
vocabulary::{FOLLOW, UNDO},
};
use crate::config::Instance;
@ -19,11 +19,11 @@ fn build_undo_follow(
target_actor_id: &str,
follow_request_id: &Uuid,
) -> Activity {
let follow_activity_id = get_object_url(
let follow_activity_id = local_object_id(
instance_url,
follow_request_id,
);
let follow_actor_id = get_actor_url(
let follow_actor_id = local_actor_id(
instance_url,
&actor_profile.username,
);

View file

@ -5,7 +5,7 @@ use crate::activitypub::{
activity::{create_activity, Activity},
constants::AP_PUBLIC,
deliverer::OutgoingActivity,
views::get_object_url,
identifiers::local_object_id,
vocabulary::UNDO,
};
use crate::config::Instance;
@ -21,10 +21,7 @@ fn build_undo_like(
reaction_id: &Uuid,
recipient_id: &str,
) -> Activity {
let object_id = get_object_url(
instance_url,
reaction_id,
);
let object_id = local_object_id(instance_url, reaction_id);
let activity_id = format!("{}/undo", object_id);
create_activity(
instance_url,

View file

@ -6,7 +6,7 @@ use crate::activitypub::{
actor::{get_local_actor, Actor, ActorKeyError},
constants::AP_PUBLIC,
deliverer::OutgoingActivity,
views::{get_followers_url, get_object_url},
identifiers::{local_actor_followers, local_object_id},
vocabulary::UPDATE,
};
use crate::config::Instance;
@ -21,7 +21,7 @@ fn build_update_person(
) -> Result<Activity, ActorKeyError> {
let actor = get_local_actor(user, instance_url)?;
// Update(Person) is idempotent so its ID can be random
let activity_id = get_object_url(instance_url, &new_uuid());
let activity_id = local_object_id(instance_url, &new_uuid());
let activity = create_activity(
instance_url,
&user.profile.username,
@ -30,7 +30,7 @@ fn build_update_person(
actor,
vec![
AP_PUBLIC.to_string(),
get_followers_url(instance_url, &user.profile.username),
local_actor_followers(instance_url, &user.profile.username),
],
vec![],
);

View file

@ -8,7 +8,7 @@ use crate::utils::crypto::deserialize_private_key;
use super::activity::Activity;
use super::actor::Actor;
use super::constants::{ACTIVITY_CONTENT_TYPE, ACTOR_KEY_SUFFIX};
use super::views::get_actor_url;
use super::identifiers::local_actor_id;
#[derive(thiserror::Error, Debug)]
pub enum DelivererError {
@ -83,7 +83,7 @@ async fn deliver_activity_worker(
let actor_key = deserialize_private_key(&sender.private_key)?;
let actor_key_id = format!(
"{}{}",
get_actor_url(
local_actor_id(
&instance.url(),
&sender.profile.username,
),

View file

@ -2,7 +2,7 @@ use tokio_postgres::GenericClient;
use crate::activitypub::{
activity::Activity,
receiver::{get_object_id, parse_object_id},
receiver::{find_object_id, parse_object_id},
vocabulary::FOLLOW,
};
use crate::config::Config;
@ -20,7 +20,7 @@ pub async fn handle_accept_follow(
activity: Activity,
) -> HandlerResult {
let actor_profile = get_profile_by_actor_id(db_client, &activity.actor).await?;
let object_id = get_object_id(&activity.object)?;
let object_id = find_object_id(&activity.object)?;
let follow_request_id = parse_object_id(&config.instance_url(), &object_id)?;
let follow_request = get_follow_request_by_id(db_client, &follow_request_id).await?;
if follow_request.target_id != actor_profile.id {

View file

@ -3,7 +3,7 @@ use tokio_postgres::GenericClient;
use crate::activitypub::{
activity::Activity,
fetcher::helpers::{get_or_import_profile_by_actor_id, import_post},
receiver::{get_object_id, parse_object_id},
receiver::{find_object_id, parse_object_id},
vocabulary::NOTE,
};
use crate::config::Config;
@ -29,7 +29,7 @@ pub async fn handle_announce(
&config.media_dir(),
&activity.actor,
).await?;
let object_id = get_object_id(&activity.object)?;
let object_id = find_object_id(&activity.object)?;
let post_id = match parse_object_id(&config.instance_url(), &object_id) {
Ok(post_id) => post_id,
Err(_) => {

View file

@ -2,7 +2,7 @@ use tokio_postgres::GenericClient;
use crate::activitypub::{
activity::Activity,
receiver::get_object_id,
receiver::find_object_id,
vocabulary::{NOTE, PERSON},
};
use crate::config::Config;
@ -19,7 +19,7 @@ pub async fn handle_delete(
db_client: &mut impl GenericClient,
activity: Activity,
) -> HandlerResult {
let object_id = get_object_id(&activity.object)?;
let object_id = find_object_id(&activity.object)?;
if object_id == activity.actor {
// Self-delete
let profile = match get_profile_by_actor_id(db_client, &object_id).await {

View file

@ -4,7 +4,7 @@ use crate::activitypub::{
activity::Activity,
builders::accept_follow::prepare_accept_follow,
fetcher::helpers::{get_or_import_profile_by_actor_id, ImportError},
receiver::{get_object_id, parse_actor_id},
receiver::{find_object_id, parse_actor_id},
vocabulary::PERSON,
};
use crate::config::Config;
@ -26,7 +26,7 @@ pub async fn handle_follow(
).await?;
let source_actor = source_profile.actor_json
.ok_or(ImportError::LocalObject)?;
let target_actor_id = get_object_id(&activity.object)?;
let target_actor_id = find_object_id(&activity.object)?;
let target_username = parse_actor_id(&config.instance_url(), &target_actor_id)?;
let target_user = get_user_by_name(db_client, &target_username).await?;
match follow(db_client, &source_profile.id, &target_user.profile.id).await {

View file

@ -3,7 +3,7 @@ use tokio_postgres::GenericClient;
use crate::activitypub::{
activity::Activity,
fetcher::helpers::get_or_import_profile_by_actor_id,
receiver::{get_object_id, parse_object_id},
receiver::{find_object_id, parse_object_id},
vocabulary::NOTE,
};
use crate::config::Config;
@ -23,7 +23,7 @@ pub async fn handle_like(
&config.media_dir(),
&activity.actor,
).await?;
let object_id = get_object_id(&activity.object)?;
let object_id = find_object_id(&activity.object)?;
let post_id = match parse_object_id(&config.instance_url(), &object_id) {
Ok(post_id) => post_id,
Err(_) => {

View file

@ -2,7 +2,7 @@ use tokio_postgres::GenericClient;
use crate::activitypub::{
activity::Activity,
receiver::{get_object_id, parse_object_id},
receiver::{find_object_id, parse_object_id},
vocabulary::FOLLOW,
};
use crate::config::Config;
@ -20,7 +20,7 @@ pub async fn handle_reject_follow(
activity: Activity,
) -> HandlerResult {
let actor_profile = get_profile_by_actor_id(db_client, &activity.actor).await?;
let object_id = get_object_id(&activity.object)?;
let object_id = find_object_id(&activity.object)?;
let follow_request_id = parse_object_id(&config.instance_url(), &object_id)?;
let follow_request = get_follow_request_by_id(db_client, &follow_request_id).await?;
if follow_request.target_id != actor_profile.id {

View file

@ -2,7 +2,7 @@ use tokio_postgres::GenericClient;
use crate::activitypub::{
activity::Activity,
receiver::get_object_id,
receiver::find_object_id,
vocabulary::{ANNOUNCE, LIKE},
};
use crate::errors::{DatabaseError, ValidationError};
@ -22,7 +22,7 @@ pub async fn handle_undo(
activity: Activity,
) -> HandlerResult {
let actor_profile = get_profile_by_actor_id(db_client, &activity.actor).await?;
let object_id = get_object_id(&activity.object)?;
let object_id = find_object_id(&activity.object)?;
match get_reaction_by_activity_id(db_client, &object_id).await {
Ok(reaction) => {
// Undo(Like)

View file

@ -1,4 +1,5 @@
#[allow(dead_code)]
use uuid::Uuid;
pub enum LocalActorCollection {
Inbox,
Outbox,
@ -19,3 +20,40 @@ impl LocalActorCollection {
format!("{}/{}", actor_id, name)
}
}
pub fn local_actor_id(instance_url: &str, username: &str) -> String {
format!("{}/users/{}", instance_url, username)
}
pub fn local_actor_inbox(instance_url: &str, username: &str) -> String {
let actor_id = local_actor_id(instance_url, username);
LocalActorCollection::Inbox.of(&actor_id)
}
pub fn local_actor_outbox(instance_url: &str, username: &str) -> String {
let actor_id = local_actor_id(instance_url, username);
LocalActorCollection::Outbox.of(&actor_id)
}
pub fn local_actor_followers(instance_url: &str, username: &str) -> String {
let actor_id = local_actor_id(instance_url, username);
LocalActorCollection::Followers.of(&actor_id)
}
pub fn local_actor_following(instance_url: &str, username: &str) -> String {
let actor_id = local_actor_id(instance_url, username);
LocalActorCollection::Following.of(&actor_id)
}
pub fn local_actor_subscribers(instance_url: &str, username: &str) -> String {
let actor_id = local_actor_id(instance_url, username);
LocalActorCollection::Subscribers.of(&actor_id)
}
pub fn local_instance_actor_id(instance_url: &str) -> String {
format!("{}/actor", instance_url)
}
pub fn local_object_id(instance_url: &str, internal_object_id: &Uuid) -> String {
format!("{}/objects/{}", instance_url, internal_object_id)
}

View file

@ -6,7 +6,7 @@ pub mod constants;
mod deliverer;
pub mod fetcher;
pub mod handlers;
mod identifiers;
pub mod identifiers;
mod receiver;
pub mod views;
mod vocabulary;

View file

@ -109,7 +109,7 @@ pub fn parse_property_value<T: DeserializeOwned>(value: &Value) -> Result<Vec<T>
}
/// Parses object json value and returns its ID as string
pub fn get_object_id(object: &Value) -> Result<String, ValidationError> {
pub fn find_object_id(object: &Value) -> Result<String, ValidationError> {
let object_id = match object.as_str() {
Some(object_id) => object_id.to_owned(),
None => {
@ -152,7 +152,7 @@ pub async fn receive_activity(
.unwrap_or("Unknown");
let is_self_delete = if activity_type == DELETE {
let object_id = get_object_id(&activity.object)?;
let object_id = find_object_id(&activity.object)?;
activity.actor == object_id
} else { false };
// Don't fetch signer if this is Delete(Person) activity
@ -327,14 +327,14 @@ mod tests {
}
#[test]
fn test_get_object_id_from_string() {
fn test_find_object_id_from_string() {
let value = json!("test_id");
assert_eq!(get_object_id(&value).unwrap(), "test_id");
assert_eq!(find_object_id(&value).unwrap(), "test_id");
}
#[test]
fn test_get_object_id_from_object() {
fn test_find_object_id_from_object() {
let value = json!({"id": "test_id", "type": "Note"});
assert_eq!(get_object_id(&value).unwrap(), "test_id");
assert_eq!(find_object_id(&value).unwrap(), "test_id");
}
}

View file

@ -23,40 +23,14 @@ use super::collections::{
OrderedCollectionPage,
};
use super::constants::ACTIVITY_CONTENT_TYPE;
use super::identifiers::{
local_actor_followers,
local_actor_following,
local_actor_subscribers,
local_actor_outbox,
};
use super::receiver::receive_activity;
pub fn get_actor_url(instance_url: &str, username: &str) -> String {
format!("{}/users/{}", instance_url, username)
}
pub fn get_inbox_url(instance_url: &str, username: &str) -> String {
format!("{}/users/{}/inbox", instance_url, username)
}
pub fn get_outbox_url(instance_url: &str, username: &str) -> String {
format!("{}/users/{}/outbox", instance_url, username)
}
pub fn get_followers_url(instance_url: &str, username: &str) -> String {
format!("{}/users/{}/followers", instance_url, username)
}
pub fn get_following_url(instance_url: &str, username: &str) -> String {
format!("{}/users/{}/following", instance_url, username)
}
pub fn get_subscribers_url(instance_url: &str, username: &str) -> String {
format!("{}/users/{}/subscribers", instance_url, username)
}
pub fn get_instance_actor_url(instance_url: &str) -> String {
format!("{}/actor", instance_url)
}
pub fn get_object_url(instance_url: &str, internal_object_id: &Uuid) -> String {
format!("{}/objects/{}", instance_url, internal_object_id)
}
fn is_activitypub_request(headers: &HeaderMap) -> bool {
const CONTENT_TYPES: [&str; 4] = [
ACTIVITY_CONTENT_TYPE,
@ -139,7 +113,7 @@ async fn outbox(
query_params: web::Query<CollectionQueryParams>,
) -> Result<HttpResponse, HttpError> {
let instance = config.instance();
let collection_id = get_outbox_url(&instance.url(), &username);
let collection_id = local_actor_outbox(&instance.url(), &username);
let first_page_id = format!("{}?page=true", collection_id);
if query_params.page.is_none() {
let collection = OrderedCollection::new(
@ -196,7 +170,10 @@ async fn followers_collection(
// Social graph is not available
return Err(HttpError::PermissionError);
}
let collection_id = get_followers_url(&config.instance_url(), &username);
let collection_id = local_actor_followers(
&config.instance_url(),
&username,
);
let collection = OrderedCollection::new(collection_id, None);
let response = HttpResponse::Ok()
.content_type(ACTIVITY_CONTENT_TYPE)
@ -214,7 +191,10 @@ async fn following_collection(
// Social graph is not available
return Err(HttpError::PermissionError);
}
let collection_id = get_following_url(&config.instance_url(), &username);
let collection_id = local_actor_following(
&config.instance_url(),
&username,
);
let collection = OrderedCollection::new(collection_id, None);
let response = HttpResponse::Ok()
.content_type(ACTIVITY_CONTENT_TYPE)
@ -232,7 +212,10 @@ async fn subscribers_collection(
// Subscriber list is hidden
return Err(HttpError::PermissionError);
}
let collection_id = get_subscribers_url(&config.instance_url(), &username);
let collection_id = local_actor_subscribers(
&config.instance_url(),
&username,
);
let collection = OrderedCollection::new(collection_id, None);
let response = HttpResponse::Ok()
.content_type(ACTIVITY_CONTENT_TYPE)

View file

@ -1,7 +1,7 @@
use ammonia::clean_text;
use chrono::{DateTime, NaiveDateTime, Utc};
use crate::activitypub::views::{get_actor_url, get_object_url};
use crate::activitypub::identifiers::{local_actor_id, local_object_id};
use crate::config::Instance;
use crate::models::posts::types::Post;
use crate::models::profiles::types::DbActorProfile;
@ -17,7 +17,7 @@ fn make_entry(
instance_url: &str,
post: &Post,
) -> String {
let object_id = get_object_url(instance_url, &post.id);
let object_id = local_object_id(instance_url, &post.id);
let content_escaped = clean_text(&post.content);
let content_cleaned = clean_html_all(&post.content);
// Use trimmed content for title
@ -49,7 +49,7 @@ pub fn make_feed(
profile: &DbActorProfile,
posts: Vec<Post>,
) -> String {
let actor_url = get_actor_url(&instance.url(), &profile.username);
let actor_url = local_actor_id(&instance.url(), &profile.username);
let actor_name = profile.display_name.as_ref()
.unwrap_or(&profile.username);
let actor_address = profile.actor_address(&instance.host());

View file

@ -9,7 +9,7 @@ use serde::Deserialize;
use url::Url;
use crate::activitypub::constants::ACTOR_KEY_SUFFIX;
use crate::activitypub::views::get_instance_actor_url;
use crate::activitypub::identifiers::local_instance_actor_id;
use crate::errors::ConversionError;
use crate::ethereum::utils::{parse_caip2_chain_id, ChainIdError};
use crate::models::profiles::currencies::Currency;
@ -223,7 +223,7 @@ impl Instance {
}
pub fn actor_id(&self) -> String {
get_instance_actor_url(&self.url())
local_instance_actor_id(&self.url())
}
pub fn actor_key_id(&self) -> String {

View file

@ -5,7 +5,7 @@ use postgres_types::FromSql;
use tokio_postgres::Row;
use uuid::Uuid;
use crate::activitypub::views::get_object_url;
use crate::activitypub::identifiers::local_object_id;
use crate::database::int_enum::{int_enum_from_sql, int_enum_to_sql};
use crate::errors::{ConversionError, DatabaseError, ValidationError};
use crate::models::attachments::types::DbMediaAttachment;
@ -156,7 +156,7 @@ impl Post {
pub fn get_object_id(&self, instance_url: &str) -> String {
match &self.object_id {
Some(object_id) => object_id.to_string(),
None => get_object_url(instance_url, &self.id),
None => local_object_id(instance_url, &self.id),
}
}
}

View file

@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::activitypub::actor::Actor;
use crate::activitypub::views::get_actor_url;
use crate::activitypub::identifiers::local_actor_id;
use crate::database::json_macro::{json_from_sql, json_to_sql};
use crate::errors::ValidationError;
use crate::ethereum::identity::DidPkh;
@ -98,7 +98,7 @@ impl DbActorProfile {
// TODO: use actor_id field
match self.actor_json {
Some(ref actor) => actor.id.clone(),
None => get_actor_url(instance_url, &self.username),
None => local_actor_id(instance_url, &self.username),
}
}

View file

@ -2,8 +2,11 @@ use actix_web::{get, web, HttpResponse};
use regex::Regex;
use tokio_postgres::GenericClient;
use crate::activitypub::views::{get_actor_url, get_instance_actor_url};
use crate::activitypub::constants::ACTIVITY_CONTENT_TYPE;
use crate::activitypub::identifiers::{
local_actor_id,
local_instance_actor_id,
};
use crate::config::{Config, Instance};
use crate::database::{Pool, get_database_client};
use crate::errors::{HttpError, ValidationError};
@ -38,12 +41,12 @@ async fn get_user_info(
return Err(HttpError::NotFoundError("user"));
}
let actor_url = if username == instance.host() {
get_instance_actor_url(&instance.url())
local_instance_actor_id(&instance.url())
} else {
if !is_registered_user(db_client, username).await? {
return Err(HttpError::NotFoundError("user"));
};
get_actor_url(&instance.url(), username)
local_actor_id(&instance.url(), username)
};
let link = Link {
rel: "self".to_string(),