Compare commits
9 Commits
v0.1.3
...
432f39cbb4
| Author | SHA1 | Date | |
|---|---|---|---|
| 432f39cbb4 | |||
| 2c509cbf88 | |||
| 52614d406a | |||
| 1949fce620 | |||
| 699258f830 | |||
| 9412a9739a | |||
| 13111c10b9 | |||
| 2e3b6d5cd4 | |||
| bc857b2c08 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1368,7 +1368,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "k-ap"
|
name = "k-ap"
|
||||||
version = "0.1.0"
|
version = "0.1.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activitypub_federation",
|
"activitypub_federation",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "k-ap"
|
name = "k-ap"
|
||||||
version = "0.1.0"
|
version = "0.1.9"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "Generic ActivityPub protocol layer"
|
description = "Generic ActivityPub protocol layer"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@@ -65,12 +65,20 @@ impl Activity for FollowActivity {
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if target_domain != data.domain {
|
if target_domain == data.domain {
|
||||||
return Err(Error::bad_request(anyhow::anyhow!(
|
return Ok(());
|
||||||
"follow target is not a local actor"
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
Ok(())
|
// Domain mismatch — still accept if the UUID resolves to a local user.
|
||||||
|
// This handles domain migrations where remote servers have cached the old actor URL.
|
||||||
|
if let Some(uuid) = crate::urls::extract_user_id_from_url(target_url) {
|
||||||
|
if data.user_repo.find_by_id(uuid).await.ok().flatten().is_some() {
|
||||||
|
tracing::debug!(target = %target_url, local_domain = %data.domain, "accepting follow for migrated actor URL");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(Error::bad_request(anyhow::anyhow!(
|
||||||
|
"follow target is not a local actor"
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn receive(self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
async fn receive(self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
||||||
@@ -829,10 +837,86 @@ impl Activity for MoveActivity {
|
|||||||
if data.federation_repo.is_domain_blocked(domain).await? {
|
if data.federation_repo.is_domain_blocked(domain).await? {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch the target actor via signed request.
|
||||||
|
let target = ObjectId::<DbActor>::from(self.target.clone())
|
||||||
|
.dereference(data)
|
||||||
|
.await
|
||||||
|
.map_err(|e| Error::from(anyhow::anyhow!("{e}")))?;
|
||||||
|
|
||||||
|
// Verify the new actor claims the old identity via alsoKnownAs.
|
||||||
|
let old_url = self.object.as_str();
|
||||||
|
if target.also_known_as.as_deref() != Some(old_url) {
|
||||||
|
return Err(Error::bad_request(anyhow::anyhow!(
|
||||||
|
"Move target alsoKnownAs does not reference old actor"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Migrate DB records; get user IDs that need a re-follow.
|
||||||
|
let affected = data
|
||||||
|
.federation_repo
|
||||||
|
.migrate_follower_actor(old_url, self.target.as_str())
|
||||||
|
.await
|
||||||
|
.map_err(|e| Error::from(anyhow::anyhow!("{e}")))?;
|
||||||
|
|
||||||
|
let affected_count = affected.len();
|
||||||
|
|
||||||
|
// Re-follow on behalf of each affected local user.
|
||||||
|
for local_user_id in &affected {
|
||||||
|
let local_actor = match crate::actors::get_local_actor(*local_user_id, data).await {
|
||||||
|
Ok(a) => a,
|
||||||
|
Err(e) => {
|
||||||
|
tracing::warn!(error = %e, %local_user_id, "Move: failed to load local actor for re-follow");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let follow_id = match crate::urls::activity_url(&data.base_url) {
|
||||||
|
Ok(u) => u,
|
||||||
|
Err(e) => {
|
||||||
|
tracing::warn!(error = %e, "Move: failed to generate follow activity URL");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let follow = FollowActivity {
|
||||||
|
id: follow_id,
|
||||||
|
kind: Default::default(),
|
||||||
|
actor: activitypub_federation::fetch::object_id::ObjectId::from(
|
||||||
|
local_actor.ap_id.clone(),
|
||||||
|
),
|
||||||
|
object: activitypub_federation::fetch::object_id::ObjectId::from(
|
||||||
|
self.target.clone(),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
let sends = match activitypub_federation::activity_sending::SendActivityTask::prepare(
|
||||||
|
&activitypub_federation::protocol::context::WithContext::new_default(follow),
|
||||||
|
&local_actor,
|
||||||
|
vec![target.inbox_url.clone()],
|
||||||
|
data,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(e) => {
|
||||||
|
tracing::warn!(error = %e, "Move: failed to prepare re-follow");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for send in sends {
|
||||||
|
if let Err(e) = send.sign_and_send(data).await {
|
||||||
|
tracing::warn!(error = %e, %local_user_id, "Move: re-follow delivery failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
actor = %self.actor.inner(),
|
actor = %self.actor.inner(),
|
||||||
target = %self.target,
|
target = %self.target,
|
||||||
"received Move (account migration) — target noted"
|
affected = affected_count,
|
||||||
|
"received Move — migrated follower relationships"
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use activitypub_federation::{
|
|||||||
config::Data,
|
config::Data,
|
||||||
fetch::object_id::ObjectId,
|
fetch::object_id::ObjectId,
|
||||||
http_signatures::generate_actor_keypair,
|
http_signatures::generate_actor_keypair,
|
||||||
kinds::actor::PersonType,
|
|
||||||
protocol::{public_key::PublicKey, verification::verify_domains_match},
|
protocol::{public_key::PublicKey, verification::verify_domains_match},
|
||||||
traits::{Actor, Object},
|
traits::{Actor, Object},
|
||||||
};
|
};
|
||||||
@@ -19,6 +18,7 @@ use crate::user::ApProfileField;
|
|||||||
pub struct DbActor {
|
pub struct DbActor {
|
||||||
pub user_id: uuid::Uuid,
|
pub user_id: uuid::Uuid,
|
||||||
pub username: String,
|
pub username: String,
|
||||||
|
pub display_name: Option<String>,
|
||||||
pub public_key_pem: String,
|
pub public_key_pem: String,
|
||||||
pub private_key_pem: Option<String>,
|
pub private_key_pem: Option<String>,
|
||||||
pub inbox_url: Url,
|
pub inbox_url: Url,
|
||||||
@@ -57,18 +57,39 @@ pub struct ProfileFieldObject {
|
|||||||
pub value: String,
|
pub value: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Accepts any AP actor type on inbound JSON; always serializes as "Person" for local actors.
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub enum ApActorType {
|
||||||
|
Person,
|
||||||
|
Service,
|
||||||
|
Application,
|
||||||
|
Organization,
|
||||||
|
Group,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ApActorType {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Person
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Person {
|
pub struct Person {
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
kind: PersonType,
|
kind: ApActorType,
|
||||||
id: ObjectId<DbActor>,
|
id: ObjectId<DbActor>,
|
||||||
|
#[serde(default)]
|
||||||
preferred_username: String,
|
preferred_username: String,
|
||||||
inbox: Url,
|
inbox: Url,
|
||||||
outbox: Url,
|
#[serde(default)]
|
||||||
followers: Url,
|
outbox: Option<Url>,
|
||||||
following: Url,
|
#[serde(default)]
|
||||||
public_key: PublicKey,
|
followers: Option<Url>,
|
||||||
|
#[serde(default)]
|
||||||
|
following: Option<Url>,
|
||||||
|
pub public_key: PublicKey,
|
||||||
|
#[serde(default)]
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
summary: Option<String>,
|
summary: Option<String>,
|
||||||
@@ -78,6 +99,7 @@ pub struct Person {
|
|||||||
url: Option<Url>,
|
url: Option<Url>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
discoverable: Option<bool>,
|
discoverable: Option<bool>,
|
||||||
|
#[serde(default)]
|
||||||
manually_approves_followers: bool,
|
manually_approves_followers: bool,
|
||||||
#[serde(skip_serializing_if = "Option::is_none", default)]
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
updated: Option<DateTime<Utc>>,
|
updated: Option<DateTime<Utc>>,
|
||||||
@@ -152,6 +174,7 @@ pub async fn get_local_actor(
|
|||||||
Ok(DbActor {
|
Ok(DbActor {
|
||||||
user_id,
|
user_id,
|
||||||
username: user.username,
|
username: user.username,
|
||||||
|
display_name: None,
|
||||||
public_key_pem: public_key,
|
public_key_pem: public_key,
|
||||||
private_key_pem: Some(private_key),
|
private_key_pem: Some(private_key),
|
||||||
inbox_url,
|
inbox_url,
|
||||||
@@ -170,6 +193,11 @@ pub async fn get_local_actor(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn apex_domain(url: &Url) -> String {
|
||||||
|
let host = url.host_str().unwrap_or("");
|
||||||
|
host.strip_prefix("www.").unwrap_or(host).to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl Object for DbActor {
|
impl Object for DbActor {
|
||||||
type DataType = FederationData;
|
type DataType = FederationData;
|
||||||
@@ -219,6 +247,7 @@ impl Object for DbActor {
|
|||||||
Ok(Some(DbActor {
|
Ok(Some(DbActor {
|
||||||
user_id,
|
user_id,
|
||||||
username: user.username,
|
username: user.username,
|
||||||
|
display_name: None,
|
||||||
public_key_pem: public_key,
|
public_key_pem: public_key,
|
||||||
private_key_pem: private_key,
|
private_key_pem: private_key,
|
||||||
inbox_url,
|
inbox_url,
|
||||||
@@ -272,9 +301,9 @@ impl Object for DbActor {
|
|||||||
id: self.ap_id.clone().into(),
|
id: self.ap_id.clone().into(),
|
||||||
preferred_username: self.username.clone(),
|
preferred_username: self.username.clone(),
|
||||||
inbox: self.inbox_url.clone(),
|
inbox: self.inbox_url.clone(),
|
||||||
outbox: self.outbox_url.clone(),
|
outbox: Some(self.outbox_url.clone()),
|
||||||
followers: self.followers_url.clone(),
|
followers: Some(self.followers_url.clone()),
|
||||||
following: self.following_url.clone(),
|
following: Some(self.following_url.clone()),
|
||||||
public_key,
|
public_key,
|
||||||
name: Some(self.username.clone()),
|
name: Some(self.username.clone()),
|
||||||
summary: self.bio.clone(),
|
summary: self.bio.clone(),
|
||||||
@@ -295,11 +324,26 @@ impl Object for DbActor {
|
|||||||
expected_domain: &Url,
|
expected_domain: &Url,
|
||||||
_data: &Data<Self::DataType>,
|
_data: &Data<Self::DataType>,
|
||||||
) -> Result<(), Self::Error> {
|
) -> Result<(), Self::Error> {
|
||||||
verify_domains_match(json.id.inner(), expected_domain)?;
|
if verify_domains_match(json.id.inner(), expected_domain).is_ok() {
|
||||||
Ok(())
|
return Ok(());
|
||||||
|
}
|
||||||
|
if apex_domain(json.id.inner()) == apex_domain(expected_domain) {
|
||||||
|
tracing::debug!(
|
||||||
|
actor_id = %json.id.inner(),
|
||||||
|
expected = %expected_domain,
|
||||||
|
"domain verified via www-apex equivalence"
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
verify_domains_match(json.id.inner(), expected_domain).map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn from_json(json: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, Self::Error> {
|
async fn from_json(json: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, Self::Error> {
|
||||||
|
tracing::debug!(
|
||||||
|
actor_id = %json.id.inner(),
|
||||||
|
username = %json.preferred_username,
|
||||||
|
"ingesting remote actor"
|
||||||
|
);
|
||||||
let shared_inbox_url = json.endpoints.as_ref().map(|e| e.shared_inbox.to_string());
|
let shared_inbox_url = json.endpoints.as_ref().map(|e| e.shared_inbox.to_string());
|
||||||
let actor = RemoteActor {
|
let actor = RemoteActor {
|
||||||
url: json.id.inner().to_string(),
|
url: json.id.inner().to_string(),
|
||||||
@@ -308,7 +352,7 @@ impl Object for DbActor {
|
|||||||
shared_inbox_url,
|
shared_inbox_url,
|
||||||
display_name: json.name.clone(),
|
display_name: json.name.clone(),
|
||||||
avatar_url: json.icon.as_ref().map(|i| i.url.to_string()),
|
avatar_url: json.icon.as_ref().map(|i| i.url.to_string()),
|
||||||
outbox_url: Some(json.outbox.to_string()),
|
outbox_url: json.outbox.as_ref().map(|u| u.to_string()),
|
||||||
};
|
};
|
||||||
data.federation_repo.upsert_remote_actor(actor).await?;
|
data.federation_repo.upsert_remote_actor(actor).await?;
|
||||||
|
|
||||||
@@ -320,13 +364,17 @@ impl Object for DbActor {
|
|||||||
.endpoints
|
.endpoints
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|e| Url::parse(e.shared_inbox.as_str()).ok());
|
.and_then(|e| Url::parse(e.shared_inbox.as_str()).ok());
|
||||||
let outbox_url = json.outbox.clone();
|
let fallback = |suffix: &str| {
|
||||||
let followers_url = json.followers.clone();
|
Url::parse(&format!("{}{}", ap_id, suffix)).unwrap_or_else(|_| ap_id.clone())
|
||||||
let following_url = json.following.clone();
|
};
|
||||||
|
let outbox_url = json.outbox.clone().unwrap_or_else(|| fallback("/outbox"));
|
||||||
|
let followers_url = json.followers.clone().unwrap_or_else(|| fallback("/followers"));
|
||||||
|
let following_url = json.following.clone().unwrap_or_else(|| fallback("/following"));
|
||||||
|
|
||||||
Ok(DbActor {
|
Ok(DbActor {
|
||||||
user_id,
|
user_id,
|
||||||
username: json.preferred_username.clone(),
|
username: json.preferred_username.clone(),
|
||||||
|
display_name: json.name.clone(),
|
||||||
public_key_pem: json.public_key.public_key_pem,
|
public_key_pem: json.public_key.public_key_pem,
|
||||||
private_key_pem: None,
|
private_key_pem: None,
|
||||||
inbox_url,
|
inbox_url,
|
||||||
|
|||||||
@@ -25,4 +25,4 @@ pub use repository::{
|
|||||||
BlockedDomain, FederationRepository, Follower, FollowerStatus, FollowingStatus, RemoteActor,
|
BlockedDomain, FederationRepository, Follower, FollowerStatus, FollowingStatus, RemoteActor,
|
||||||
};
|
};
|
||||||
pub use service::ActivityPubService;
|
pub use service::ActivityPubService;
|
||||||
pub use user::{ApProfileField, ApUser, ApUserRepository};
|
pub use user::{ApProfileField, ApUser, ApUserRepository, LookedUpActor};
|
||||||
|
|||||||
@@ -131,4 +131,12 @@ pub trait FederationRepository: Send + Sync {
|
|||||||
async fn remove_blocked_actor(&self, local_user_id: uuid::Uuid, actor_url: &str) -> Result<()>;
|
async fn remove_blocked_actor(&self, local_user_id: uuid::Uuid, actor_url: &str) -> Result<()>;
|
||||||
async fn get_blocked_actors(&self, local_user_id: uuid::Uuid) -> Result<Vec<String>>;
|
async fn get_blocked_actors(&self, local_user_id: uuid::Uuid) -> Result<Vec<String>>;
|
||||||
async fn is_actor_blocked(&self, local_user_id: uuid::Uuid, actor_url: &str) -> Result<bool>;
|
async fn is_actor_blocked(&self, local_user_id: uuid::Uuid, actor_url: &str) -> Result<bool>;
|
||||||
|
/// Migrate all local following records from old_actor_url to new_actor_url.
|
||||||
|
/// Returns the local user IDs whose records were migrated (excludes users
|
||||||
|
/// already following the new actor — they need no re-follow).
|
||||||
|
async fn migrate_follower_actor(
|
||||||
|
&self,
|
||||||
|
old_actor_url: &str,
|
||||||
|
new_actor_url: &str,
|
||||||
|
) -> Result<Vec<uuid::Uuid>>;
|
||||||
}
|
}
|
||||||
|
|||||||
100
src/service.rs
100
src/service.rs
@@ -330,6 +330,36 @@ impl ActivityPubService {
|
|||||||
Ok(serde_json::to_string(&WithContext::new_default(person))?)
|
Ok(serde_json::to_string(&WithContext::new_default(person))?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resolve a `@user@domain` handle to actor data using a signed HTTP request.
|
||||||
|
/// Unlike a plain unauthenticated fetch, this works with instances (e.g. Threads)
|
||||||
|
/// that require HTTP signatures before returning full actor JSON.
|
||||||
|
pub async fn lookup_actor_by_handle(
|
||||||
|
&self,
|
||||||
|
handle: &str,
|
||||||
|
) -> anyhow::Result<crate::user::LookedUpActor> {
|
||||||
|
tracing::info!(handle, "looking up remote actor");
|
||||||
|
let data = self.federation_config.to_request_data();
|
||||||
|
let actor = Self::webfinger_https(handle, &data).await
|
||||||
|
.inspect_err(|e| tracing::warn!(handle, error = %e, "actor lookup failed"))?;
|
||||||
|
let domain = actor.ap_id.host_str().unwrap_or("").to_string();
|
||||||
|
let handle = format!("{}@{}", actor.username, domain);
|
||||||
|
tracing::info!(handle, ap_url = %actor.ap_id, "remote actor resolved");
|
||||||
|
Ok(crate::user::LookedUpActor {
|
||||||
|
handle,
|
||||||
|
display_name: actor.display_name,
|
||||||
|
bio: actor.bio,
|
||||||
|
avatar_url: actor.avatar_url,
|
||||||
|
banner_url: actor.banner_url,
|
||||||
|
ap_url: actor.ap_id,
|
||||||
|
outbox_url: Some(actor.outbox_url),
|
||||||
|
followers_url: Some(actor.followers_url),
|
||||||
|
following_url: Some(actor.following_url),
|
||||||
|
also_known_as: actor.also_known_as,
|
||||||
|
profile_url: actor.profile_url,
|
||||||
|
attachment: actor.attachment,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the ActivityPub router compatible with any outer state `S`.
|
/// Returns the ActivityPub router compatible with any outer state `S`.
|
||||||
/// Handlers only use `Data<FederationData>` injected by the middleware layer,
|
/// Handlers only use `Data<FederationData>` injected by the middleware layer,
|
||||||
/// so the router is independent of the application state type.
|
/// so the router is independent of the application state type.
|
||||||
@@ -570,6 +600,7 @@ impl ActivityPubService {
|
|||||||
"https://{}/.well-known/webfinger?resource=acct:{}@{}",
|
"https://{}/.well-known/webfinger?resource=acct:{}@{}",
|
||||||
domain_str, user, domain_str
|
domain_str, user, domain_str
|
||||||
);
|
);
|
||||||
|
tracing::debug!(handle, wf_url, "resolving webfinger");
|
||||||
let wf: serde_json::Value = reqwest::Client::new()
|
let wf: serde_json::Value = reqwest::Client::new()
|
||||||
.get(&wf_url)
|
.get(&wf_url)
|
||||||
.header("Accept", "application/jrd+json, application/json")
|
.header("Accept", "application/jrd+json, application/json")
|
||||||
@@ -588,6 +619,7 @@ impl ActivityPubService {
|
|||||||
.and_then(|l| l["href"].as_str())
|
.and_then(|l| l["href"].as_str())
|
||||||
.ok_or_else(|| anyhow::anyhow!("no self link in WebFinger response"))?
|
.ok_or_else(|| anyhow::anyhow!("no self link in WebFinger response"))?
|
||||||
.to_owned();
|
.to_owned();
|
||||||
|
tracing::debug!(handle, self_href, "webfinger resolved, fetching actor with signature");
|
||||||
let self_url = url::Url::parse(&self_href)?;
|
let self_url = url::Url::parse(&self_href)?;
|
||||||
let actor: DbActor = ObjectId::from(self_url)
|
let actor: DbActor = ObjectId::from(self_url)
|
||||||
.dereference(data)
|
.dereference(data)
|
||||||
@@ -1171,6 +1203,74 @@ impl ActivityPubService {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Broadcast a Move activity to all accepted followers, signalling that this
|
||||||
|
/// actor is migrating to `new_actor_url`.
|
||||||
|
///
|
||||||
|
/// **Pre-condition (caller's responsibility):**
|
||||||
|
/// Before calling this, the application must persist `also_known_as = [new_actor_url]`
|
||||||
|
/// in the local actor's row so the old actor JSON already advertises the new URL
|
||||||
|
/// when remote servers fetch it to verify the cross-reference.
|
||||||
|
pub async fn broadcast_move(
|
||||||
|
&self,
|
||||||
|
user_id: uuid::Uuid,
|
||||||
|
new_actor_url: url::Url,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
let data = self.federation_config.to_request_data();
|
||||||
|
let local_actor = get_local_actor(user_id, &data)
|
||||||
|
.await
|
||||||
|
.map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
|
|
||||||
|
let followers = data.federation_repo.get_followers(user_id).await?;
|
||||||
|
let accepted: Vec<_> = followers
|
||||||
|
.into_iter()
|
||||||
|
.filter(|f| f.status == FollowerStatus::Accepted)
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if accepted.is_empty() {
|
||||||
|
tracing::info!(
|
||||||
|
%user_id,
|
||||||
|
"broadcast_move: no accepted followers, nothing to send"
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let inboxes = collect_inboxes(&accepted);
|
||||||
|
|
||||||
|
let move_id =
|
||||||
|
crate::urls::activity_url(&self.base_url).map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
|
|
||||||
|
let move_activity = crate::activities::MoveActivity {
|
||||||
|
id: move_id,
|
||||||
|
kind: Default::default(),
|
||||||
|
actor: ObjectId::from(local_actor.ap_id.clone()),
|
||||||
|
object: local_actor.ap_id.clone(),
|
||||||
|
target: new_actor_url.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let sends = SendActivityTask::prepare(
|
||||||
|
&WithContext::new_default(move_activity),
|
||||||
|
&local_actor,
|
||||||
|
inboxes,
|
||||||
|
&data,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let failures = send_with_retry(sends, &data).await;
|
||||||
|
if !failures.is_empty() {
|
||||||
|
tracing::warn!(
|
||||||
|
count = failures.len(),
|
||||||
|
"some Move deliveries failed permanently"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
tracing::info!(
|
||||||
|
%user_id,
|
||||||
|
target = %new_actor_url,
|
||||||
|
"broadcast_move: delivered to all accepted followers"
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn block_actor(
|
pub async fn block_actor(
|
||||||
&self,
|
&self,
|
||||||
local_user_id: uuid::Uuid,
|
local_user_id: uuid::Uuid,
|
||||||
|
|||||||
18
src/user.rs
18
src/user.rs
@@ -7,6 +7,24 @@ pub struct ApProfileField {
|
|||||||
pub value: String,
|
pub value: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resolved actor data returned by [`crate::service::ActivityPubService::lookup_actor_by_handle`].
|
||||||
|
/// Fetched via a signed HTTP request so strict instances (e.g. Threads) return full data.
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct LookedUpActor {
|
||||||
|
pub handle: String,
|
||||||
|
pub display_name: Option<String>,
|
||||||
|
pub bio: Option<String>,
|
||||||
|
pub avatar_url: Option<Url>,
|
||||||
|
pub banner_url: Option<Url>,
|
||||||
|
pub ap_url: Url,
|
||||||
|
pub outbox_url: Option<Url>,
|
||||||
|
pub followers_url: Option<Url>,
|
||||||
|
pub following_url: Option<Url>,
|
||||||
|
pub also_known_as: Option<String>,
|
||||||
|
pub profile_url: Option<Url>,
|
||||||
|
pub attachment: Vec<ApProfileField>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ApUser {
|
pub struct ApUser {
|
||||||
pub id: uuid::Uuid,
|
pub id: uuid::Uuid,
|
||||||
|
|||||||
Reference in New Issue
Block a user