feat: v2 rewrite — hexagonal arch, ActivityPub federation, NATS, deployment-ready #1

Merged
GKaszewski merged 334 commits from v2 into master 2026-05-16 09:42:43 +00:00
7 changed files with 45 additions and 1 deletions
Showing only changes of commit ca1ebc4b68 - Show all commits

View File

@@ -1561,6 +1561,15 @@ impl domain::ports::OutboundFederationPort for ActivityPubService {
.await .await
.map_err(|e| domain::errors::DomainError::Internal(e.to_string())) .map_err(|e| domain::errors::DomainError::Internal(e.to_string()))
} }
async fn broadcast_actor_update(
&self,
user_id: &domain::value_objects::UserId,
) -> Result<(), domain::errors::DomainError> {
self.broadcast_actor_update(user_id.as_uuid())
.await
.map_err(|e| domain::errors::DomainError::Internal(e.to_string()))
}
} }
#[async_trait::async_trait] #[async_trait::async_trait]

View File

@@ -68,6 +68,9 @@ pub enum EventPayload {
UserRegistered { UserRegistered {
user_id: String, user_id: String,
}, },
ProfileUpdated {
user_id: String,
},
FetchRemoteActorPosts { FetchRemoteActorPosts {
actor_ap_url: String, actor_ap_url: String,
outbox_url: String, outbox_url: String,
@@ -98,6 +101,7 @@ impl EventPayload {
Self::UserBlocked { .. } => "users.blocked", Self::UserBlocked { .. } => "users.blocked",
Self::UserUnblocked { .. } => "users.unblocked", Self::UserUnblocked { .. } => "users.unblocked",
Self::UserRegistered { .. } => "users.registered", Self::UserRegistered { .. } => "users.registered",
Self::ProfileUpdated { .. } => "users.profile_updated",
Self::FetchRemoteActorPosts { .. } => "federation.fetch_outbox", Self::FetchRemoteActorPosts { .. } => "federation.fetch_outbox",
Self::FetchActorConnections { .. } => "federation.fetch_connections", Self::FetchActorConnections { .. } => "federation.fetch_connections",
} }
@@ -209,6 +213,9 @@ impl From<&DomainEvent> for EventPayload {
DomainEvent::UserRegistered { user_id } => Self::UserRegistered { DomainEvent::UserRegistered { user_id } => Self::UserRegistered {
user_id: user_id.to_string(), user_id: user_id.to_string(),
}, },
DomainEvent::ProfileUpdated { user_id } => Self::ProfileUpdated {
user_id: user_id.to_string(),
},
DomainEvent::FetchRemoteActorPosts { DomainEvent::FetchRemoteActorPosts {
actor_ap_url, actor_ap_url,
outbox_url, outbox_url,
@@ -345,6 +352,9 @@ impl TryFrom<EventPayload> for DomainEvent {
EventPayload::UserRegistered { user_id } => DomainEvent::UserRegistered { EventPayload::UserRegistered { user_id } => DomainEvent::UserRegistered {
user_id: UserId::from_uuid(parse_uuid(&user_id, "user_id")?), user_id: UserId::from_uuid(parse_uuid(&user_id, "user_id")?),
}, },
EventPayload::ProfileUpdated { user_id } => DomainEvent::ProfileUpdated {
user_id: UserId::from_uuid(parse_uuid(&user_id, "user_id")?),
},
EventPayload::FetchRemoteActorPosts { EventPayload::FetchRemoteActorPosts {
actor_ap_url, actor_ap_url,
outbox_url, outbox_url,

View File

@@ -277,6 +277,10 @@ impl FederationEventService {
.await .await
} }
DomainEvent::ProfileUpdated { user_id } => {
self.ap.broadcast_actor_update(user_id).await
}
_ => Ok(()), _ => Ok(()),
} }
} }
@@ -308,6 +312,7 @@ mod tests {
undo_announced: Mutex<Vec<String>>, undo_announced: Mutex<Vec<String>>,
liked: Mutex<Vec<String>>, liked: Mutex<Vec<String>>,
undo_liked: Mutex<Vec<String>>, undo_liked: Mutex<Vec<String>>,
actor_updated: Mutex<Vec<UserId>>,
} }
#[async_trait] #[async_trait]
@@ -366,6 +371,11 @@ mod tests {
self.undo_liked.lock().unwrap().push(ap_id.to_string()); self.undo_liked.lock().unwrap().push(ap_id.to_string());
Ok(()) Ok(())
} }
async fn broadcast_actor_update(&self, user_id: &UserId) -> Result<(), DomainError> {
self.actor_updated.lock().unwrap().push(user_id.clone());
Ok(())
}
} }
fn alice() -> User { fn alice() -> User {

View File

@@ -1,7 +1,8 @@
use domain::{ use domain::{
errors::DomainError, errors::DomainError,
events::DomainEvent,
models::{top_friend::TopFriend, user::User}, models::{top_friend::TopFriend, user::User},
ports::{TopFriendRepository, UserRepository}, ports::{EventPublisher, TopFriendRepository, UserRepository},
value_objects::{UserId, Username}, value_objects::{UserId, Username},
}; };
@@ -38,8 +39,10 @@ pub async fn get_user_by_id_or_username(
} }
} }
#[allow(clippy::too_many_arguments)]
pub async fn update_profile( pub async fn update_profile(
users: &dyn UserRepository, users: &dyn UserRepository,
events: &dyn EventPublisher,
user_id: &UserId, user_id: &UserId,
display_name: Option<String>, display_name: Option<String>,
bio: Option<String>, bio: Option<String>,
@@ -56,6 +59,11 @@ pub async fn update_profile(
header_url, header_url,
custom_css, custom_css,
) )
.await?;
events
.publish(&DomainEvent::ProfileUpdated {
user_id: user_id.clone(),
})
.await .await
} }

View File

@@ -60,6 +60,9 @@ pub enum DomainEvent {
UserRegistered { UserRegistered {
user_id: UserId, user_id: UserId,
}, },
ProfileUpdated {
user_id: UserId,
},
FetchRemoteActorPosts { FetchRemoteActorPosts {
actor_ap_url: String, actor_ap_url: String,
outbox_url: String, outbox_url: String,

View File

@@ -471,4 +471,7 @@ pub trait OutboundFederationPort: Send + Sync {
object_ap_id: &str, object_ap_id: &str,
author_inbox_url: &str, author_inbox_url: &str,
) -> Result<(), DomainError>; ) -> Result<(), DomainError>;
/// Fan out an Update(Actor) to all accepted followers after a profile change.
async fn broadcast_actor_update(&self, user_id: &UserId) -> Result<(), DomainError>;
} }

View File

@@ -72,6 +72,7 @@ pub async fn patch_profile(
) -> Result<Json<UserResponse>, ApiError> { ) -> Result<Json<UserResponse>, ApiError> {
update_profile( update_profile(
&*s.users, &*s.users,
&*s.events,
&uid, &uid,
body.display_name, body.display_name,
body.bio, body.bio,