refactor(domain): remove ap_id/inbox_url from User and Thought; use ActivityPubRepository lookups
This commit is contained in:
@@ -15,8 +15,6 @@ pub struct Thought {
|
||||
pub user_id: UserId,
|
||||
pub content: Content,
|
||||
pub in_reply_to_id: Option<ThoughtId>,
|
||||
pub in_reply_to_url: Option<String>,
|
||||
pub ap_id: Option<String>,
|
||||
pub visibility: Visibility,
|
||||
pub content_warning: Option<String>,
|
||||
pub sensitive: bool,
|
||||
@@ -60,8 +58,6 @@ impl Thought {
|
||||
user_id,
|
||||
content,
|
||||
in_reply_to_id,
|
||||
in_reply_to_url: None,
|
||||
ap_id: None,
|
||||
visibility,
|
||||
content_warning,
|
||||
sensitive,
|
||||
|
||||
@@ -13,8 +13,6 @@ pub struct User {
|
||||
pub header_url: Option<String>,
|
||||
pub custom_css: Option<String>,
|
||||
pub local: bool,
|
||||
pub ap_id: Option<String>,
|
||||
pub inbox_url: Option<String>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -38,8 +36,6 @@ impl User {
|
||||
header_url: None,
|
||||
custom_css: None,
|
||||
local: true,
|
||||
ap_id: None,
|
||||
inbox_url: None,
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
}
|
||||
|
||||
@@ -442,6 +442,7 @@ pub trait OutboundFederationPort: Send + Sync {
|
||||
author_user_id: &UserId,
|
||||
thought: &Thought,
|
||||
author_username: &str,
|
||||
in_reply_to_url: Option<&str>,
|
||||
) -> Result<(), DomainError>;
|
||||
|
||||
/// Fan out a Delete tombstone for a now-deleted local Note.
|
||||
@@ -459,6 +460,7 @@ pub trait OutboundFederationPort: Send + Sync {
|
||||
author_user_id: &UserId,
|
||||
thought: &Thought,
|
||||
author_username: &str,
|
||||
in_reply_to_url: Option<&str>,
|
||||
) -> Result<(), DomainError>;
|
||||
|
||||
/// Fan out an Announce(object_ap_id) for a boost.
|
||||
|
||||
@@ -19,6 +19,7 @@ use crate::{
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use chrono::Utc;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use url;
|
||||
|
||||
@@ -35,6 +36,12 @@ pub struct TestStore {
|
||||
pub top_friends: Arc<Mutex<Vec<TopFriend>>>,
|
||||
pub notifications: Arc<Mutex<Vec<Notification>>>,
|
||||
pub events: Arc<Mutex<Vec<DomainEvent>>>,
|
||||
/// AP URL → UserId for remote actors (used by find_remote_actor_id / intern_remote_actor)
|
||||
pub actor_ap_ids: Arc<Mutex<HashMap<String, UserId>>>,
|
||||
/// ThoughtId → AP object URL (used by get_thought_ap_id)
|
||||
pub thought_ap_ids: Arc<Mutex<HashMap<ThoughtId, String>>>,
|
||||
/// UserId → ActorApUrls (used by get_actor_ap_urls)
|
||||
pub actor_ap_urls: Arc<Mutex<HashMap<UserId, ActorApUrls>>>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -802,14 +809,12 @@ impl ActivityPubRepository for TestStore {
|
||||
&self,
|
||||
actor_ap_url: &url::Url,
|
||||
) -> Result<Option<UserId>, DomainError> {
|
||||
let url = actor_ap_url.to_string();
|
||||
Ok(self
|
||||
.users
|
||||
.actor_ap_ids
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|u| u.ap_id.as_deref() == Some(&url))
|
||||
.map(|u| u.id.clone()))
|
||||
.get(actor_ap_url.as_str())
|
||||
.cloned())
|
||||
}
|
||||
async fn intern_remote_actor(&self, actor_ap_url: &url::Url) -> Result<UserId, DomainError> {
|
||||
if let Some(uid) = self.find_remote_actor_id(actor_ap_url).await? {
|
||||
@@ -831,12 +836,14 @@ impl ActivityPubRepository for TestStore {
|
||||
header_url: None,
|
||||
custom_css: None,
|
||||
local: false,
|
||||
ap_id: Some(actor_ap_url.to_string()),
|
||||
inbox_url: None,
|
||||
created_at: chrono::Utc::now(),
|
||||
updated_at: chrono::Utc::now(),
|
||||
};
|
||||
self.users.lock().unwrap().push(user);
|
||||
self.actor_ap_ids
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(actor_ap_url.to_string(), uid.clone());
|
||||
Ok(uid)
|
||||
}
|
||||
async fn update_remote_actor_display(
|
||||
@@ -884,15 +891,15 @@ impl ActivityPubRepository for TestStore {
|
||||
}
|
||||
async fn get_thought_ap_id(
|
||||
&self,
|
||||
_thought_id: &ThoughtId,
|
||||
thought_id: &ThoughtId,
|
||||
) -> Result<Option<String>, DomainError> {
|
||||
Ok(None)
|
||||
Ok(self.thought_ap_ids.lock().unwrap().get(thought_id).cloned())
|
||||
}
|
||||
async fn get_actor_ap_urls(
|
||||
&self,
|
||||
_user_id: &UserId,
|
||||
user_id: &UserId,
|
||||
) -> Result<Option<ActorApUrls>, DomainError> {
|
||||
Ok(None)
|
||||
Ok(self.actor_ap_urls.lock().unwrap().get(user_id).cloned())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user