feat(ap): ActivityPub spec compliance and profile completeness
Phase 1 — spec compliance: - Add AS_PUBLIC constant; add to/cc fields to CreateActivity, DeleteActivity, UpdateActivity, AddActivity; populate on all broadcast call sites - Add @context to outbox CreateActivity items - Set manuallyApprovesFollowers: true to match actual Pending follow flow - Gate PermissiveVerifier behind FEDERATION_DEBUG env var - Add updated timestamp to Person actor JSON - Improve actor update delivery logging Phase 2a Batch 1 — AP layer: - Add /inbox shared inbox route; add endpoints.sharedInbox to Person - Paginate followers and following collections (20/page, OrderedCollectionPage) Phase 2a Batch 2 — profile completeness: - DB migrations: banner_path, also_known_as columns; user_profile_fields table - ProfileField value object; UserProfileFieldsRepository port - Banner image upload (stored via image-converter, surfaced as image in Person) - alsoKnownAs field in Person (account migration support) - Custom profile fields (up to 4 PropertyValue attachments in Person) - Profile settings UI: banner preview/upload, alsoKnownAs input, fields form - PUT /api/v1/profile/fields API endpoint
This commit is contained in:
@@ -31,6 +31,7 @@ pub async fn wire(
|
||||
review_store: std::sync::Arc<dyn RemoteReviewRepository>,
|
||||
remote_watchlist_repo: std::sync::Arc<dyn domain::ports::RemoteWatchlistRepository>,
|
||||
user_repo: std::sync::Arc<dyn domain::ports::UserRepository>,
|
||||
profile_fields_repo: std::sync::Arc<dyn domain::ports::UserProfileFieldsRepository>,
|
||||
movie_repo: std::sync::Arc<dyn domain::ports::MovieRepository>,
|
||||
review_repo: std::sync::Arc<dyn domain::ports::ReviewRepository>,
|
||||
diary_repo: std::sync::Arc<dyn domain::ports::DiaryRepository>,
|
||||
@@ -52,15 +53,26 @@ pub async fn wire(
|
||||
watchlist: watchlist_handler,
|
||||
});
|
||||
|
||||
let federation_debug = std::env::var("FEDERATION_DEBUG")
|
||||
.map(|v| v == "true" || v == "1")
|
||||
.unwrap_or(false);
|
||||
|
||||
if federation_debug {
|
||||
tracing::warn!(
|
||||
"federation running in DEBUG mode — PermissiveVerifier active, \
|
||||
no URL/signature validation. Do NOT use in production."
|
||||
);
|
||||
}
|
||||
|
||||
let concrete = std::sync::Arc::new(
|
||||
ActivityPubService::new(
|
||||
federation_repo,
|
||||
std::sync::Arc::new(DomainUserRepoAdapter::new(user_repo, base_url.clone())),
|
||||
std::sync::Arc::new(DomainUserRepoAdapter::new(user_repo, profile_fields_repo, base_url.clone())),
|
||||
composite,
|
||||
base_url.clone(),
|
||||
allow_registration,
|
||||
"movies-diary".to_string(),
|
||||
cfg!(debug_assertions),
|
||||
federation_debug,
|
||||
Some(event_publisher),
|
||||
)
|
||||
.await?,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use activitypub_base::AS_PUBLIC;
|
||||
use activitypub_federation::kinds::object::NoteType;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -36,6 +37,10 @@ pub struct ReviewObject {
|
||||
pub(crate) watched_at: DateTime<Utc>,
|
||||
#[serde(default)]
|
||||
pub(crate) tag: Vec<ApHashtag>,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty", default)]
|
||||
pub(crate) to: Vec<String>,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty", default)]
|
||||
pub(crate) cc: Vec<String>,
|
||||
}
|
||||
|
||||
/// Serialize a local Review into a ReviewObject for AP delivery.
|
||||
@@ -84,7 +89,7 @@ pub fn review_to_ap_object(
|
||||
ReviewObject {
|
||||
kind: NoteType::default(),
|
||||
id: ap_id,
|
||||
attributed_to: actor_url,
|
||||
attributed_to: actor_url.clone(),
|
||||
content,
|
||||
published: DateTime::from_naive_utc_and_offset(*review.created_at(), Utc),
|
||||
movie_title,
|
||||
@@ -94,6 +99,8 @@ pub fn review_to_ap_object(
|
||||
comment: comment_text,
|
||||
watched_at: DateTime::from_naive_utc_and_offset(*review.watched_at(), Utc),
|
||||
tag,
|
||||
to: vec![AS_PUBLIC.to_string()],
|
||||
cc: vec![format!("{}/followers", actor_url)],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,6 +126,10 @@ pub struct WatchlistObject {
|
||||
/// Non-Movies-Diary apps ignore unknown fields.
|
||||
#[serde(default)]
|
||||
pub(crate) watchlist_entry: bool,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty", default)]
|
||||
pub(crate) to: Vec<String>,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty", default)]
|
||||
pub(crate) cc: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn watchlist_to_ap_object(
|
||||
@@ -156,7 +167,7 @@ pub fn watchlist_to_ap_object(
|
||||
WatchlistObject {
|
||||
kind: NoteType::default(),
|
||||
id: ap_id,
|
||||
attributed_to: actor_url,
|
||||
attributed_to: actor_url.clone(),
|
||||
content,
|
||||
published: added_at,
|
||||
movie_title,
|
||||
@@ -165,6 +176,8 @@ pub fn watchlist_to_ap_object(
|
||||
poster_url,
|
||||
tag,
|
||||
watchlist_entry: true,
|
||||
to: vec![AS_PUBLIC.to_string()],
|
||||
cc: vec![format!("{}/followers", actor_url)],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,3 +39,52 @@ fn review_to_ap_object_includes_two_hashtags() {
|
||||
assert!(names.contains(&"#MoviesDiary"));
|
||||
assert!(names.contains(&"#Dune"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn review_to_ap_object_has_public_addressing() {
|
||||
use chrono::NaiveDateTime;
|
||||
use domain::{
|
||||
models::{Review, ReviewSource},
|
||||
value_objects::{MovieId, Rating, ReviewId, UserId},
|
||||
};
|
||||
|
||||
let review = Review::from_persistence(
|
||||
ReviewId::generate(),
|
||||
MovieId::from_uuid(uuid::Uuid::new_v4()),
|
||||
UserId::from_uuid(uuid::Uuid::new_v4()),
|
||||
Rating::new(3).unwrap(),
|
||||
None,
|
||||
NaiveDateTime::parse_from_str("2024-06-01 00:00:00", "%Y-%m-%d %H:%M:%S").unwrap(),
|
||||
NaiveDateTime::parse_from_str("2024-06-01 00:00:00", "%Y-%m-%d %H:%M:%S").unwrap(),
|
||||
ReviewSource::Local,
|
||||
);
|
||||
let actor_url: url::Url = "https://example.com/users/abc".parse().unwrap();
|
||||
let obj = review_to_ap_object(
|
||||
&review,
|
||||
"https://example.com/reviews/1".parse().unwrap(),
|
||||
actor_url.clone(),
|
||||
"Dune".to_string(),
|
||||
2021,
|
||||
None,
|
||||
"https://example.com",
|
||||
);
|
||||
assert_eq!(obj.to, vec!["https://www.w3.org/ns/activitystreams#Public"]);
|
||||
assert_eq!(obj.cc, vec!["https://example.com/users/abc/followers"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn watchlist_to_ap_object_has_public_addressing() {
|
||||
let actor_url: url::Url = "https://example.com/users/abc".parse().unwrap();
|
||||
let obj = watchlist_to_ap_object(
|
||||
"https://example.com/watchlist/1".parse().unwrap(),
|
||||
actor_url.clone(),
|
||||
"Alien".to_string(),
|
||||
1979,
|
||||
None,
|
||||
None,
|
||||
chrono::Utc::now(),
|
||||
"https://example.com",
|
||||
);
|
||||
assert_eq!(obj.to, vec!["https://www.w3.org/ns/activitystreams#Public"]);
|
||||
assert_eq!(obj.cc, vec!["https://example.com/users/abc/followers"]);
|
||||
}
|
||||
|
||||
@@ -2,30 +2,45 @@ use std::sync::Arc;
|
||||
|
||||
use activitypub_base::{ApUser, ApUserRepository};
|
||||
use async_trait::async_trait;
|
||||
use domain::{ports::UserRepository, value_objects::UserId};
|
||||
use domain::{
|
||||
models::ProfileField,
|
||||
ports::{UserProfileFieldsRepository, UserRepository},
|
||||
value_objects::UserId,
|
||||
};
|
||||
use url::Url;
|
||||
|
||||
pub struct DomainUserRepoAdapter {
|
||||
pub repo: Arc<dyn UserRepository>,
|
||||
pub fields_repo: Arc<dyn UserProfileFieldsRepository>,
|
||||
pub base_url: String,
|
||||
}
|
||||
|
||||
impl DomainUserRepoAdapter {
|
||||
pub fn new(repo: Arc<dyn UserRepository>, base_url: String) -> Self {
|
||||
Self { repo, base_url }
|
||||
pub fn new(
|
||||
repo: Arc<dyn UserRepository>,
|
||||
fields_repo: Arc<dyn UserProfileFieldsRepository>,
|
||||
base_url: String,
|
||||
) -> Self {
|
||||
Self { repo, fields_repo, base_url }
|
||||
}
|
||||
|
||||
fn build_user(&self, u: &domain::models::User) -> ApUser {
|
||||
fn build_user(&self, u: &domain::models::User, fields: Vec<ProfileField>) -> ApUser {
|
||||
let avatar_url = u.avatar_path().and_then(|p| {
|
||||
Url::parse(&format!("{}/images/{}", self.base_url, p)).ok()
|
||||
});
|
||||
let banner_url = u.banner_path().and_then(|p| {
|
||||
Url::parse(&format!("{}/images/{}", self.base_url, p)).ok()
|
||||
});
|
||||
let profile_url = Url::parse(&format!("{}/u/{}", self.base_url, u.username().value())).ok();
|
||||
ApUser {
|
||||
id: u.id().value(),
|
||||
username: u.username().value().to_string(),
|
||||
bio: u.bio().map(|s| s.to_string()),
|
||||
avatar_url,
|
||||
banner_url,
|
||||
also_known_as: u.also_known_as().map(|s| s.to_string()),
|
||||
profile_url,
|
||||
attachment: fields,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,13 +49,23 @@ impl DomainUserRepoAdapter {
|
||||
impl ApUserRepository for DomainUserRepoAdapter {
|
||||
async fn find_by_id(&self, id: uuid::Uuid) -> anyhow::Result<Option<ApUser>> {
|
||||
let user_id = UserId::from_uuid(id);
|
||||
Ok(self.repo.find_by_id(&user_id).await?.as_ref().map(|u| self.build_user(u)))
|
||||
let user = match self.repo.find_by_id(&user_id).await? {
|
||||
Some(u) => u,
|
||||
None => return Ok(None),
|
||||
};
|
||||
let fields = self.fields_repo.get_fields(&user_id).await.unwrap_or_default();
|
||||
Ok(Some(self.build_user(&user, fields)))
|
||||
}
|
||||
|
||||
async fn find_by_username(&self, username: &str) -> anyhow::Result<Option<ApUser>> {
|
||||
use domain::value_objects::Username;
|
||||
let uname = Username::new(username.to_string()).map_err(|e| anyhow::anyhow!(e.to_string()))?;
|
||||
Ok(self.repo.find_by_username(&uname).await?.as_ref().map(|u| self.build_user(u)))
|
||||
let user = match self.repo.find_by_username(&uname).await? {
|
||||
Some(u) => u,
|
||||
None => return Ok(None),
|
||||
};
|
||||
let fields = self.fields_repo.get_fields(user.id()).await.unwrap_or_default();
|
||||
Ok(Some(self.build_user(&user, fields)))
|
||||
}
|
||||
|
||||
async fn count_users(&self) -> anyhow::Result<usize> {
|
||||
|
||||
Reference in New Issue
Block a user