diff --git a/crates/adapters/activitypub-base/src/activities.rs b/crates/adapters/activitypub-base/src/activities.rs index 14d093e..e139377 100644 --- a/crates/adapters/activitypub-base/src/activities.rs +++ b/crates/adapters/activitypub-base/src/activities.rs @@ -13,6 +13,16 @@ use url::Url; #[serde(rename = "Announce")] pub struct AnnounceType; +#[derive(Clone, Debug, Deserialize, Serialize)] +#[serde(rename = "Like")] +pub struct LikeType; + +impl Default for LikeType { + fn default() -> Self { + Self + } +} + use crate::actors::DbActor; use crate::data::FederationData; use crate::error::Error; @@ -511,6 +521,18 @@ impl Activity for AnnounceActivity { } } +// --- Like --- + +#[derive(Clone, Debug, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct LikeActivity { + pub id: Url, + #[serde(rename = "type")] + pub kind: LikeType, + pub actor: ObjectId, + pub object: Url, +} + // --- Add --- #[derive(Clone, Default, Debug, Serialize, Deserialize)] diff --git a/crates/adapters/activitypub-base/src/content.rs b/crates/adapters/activitypub-base/src/content.rs index 83aad72..71eabc2 100644 --- a/crates/adapters/activitypub-base/src/content.rs +++ b/crates/adapters/activitypub-base/src/content.rs @@ -42,6 +42,16 @@ pub trait ApObjectHandler: Send + Sync { /// Actor unfollowed/was removed — clean up all their remote content. async fn on_actor_removed(&self, actor_url: &Url) -> anyhow::Result<()>; + /// Called when a remote actor likes a local thought. + /// `object_url` is the AP URL of the liked note (e.g. `{base}/thoughts/{uuid}`). + /// `actor_url` is the AP URL of the remote actor who sent the Like. + async fn on_like(&self, object_url: &Url, actor_url: &Url) -> anyhow::Result<()>; + + /// Called when a remote actor boosts (Announce) a local thought. + /// `object_url` is the AP URL of the announced note. + /// `actor_url` is the AP URL of the remote actor who sent the Announce. + async fn on_announce_received(&self, object_url: &Url, actor_url: &Url) -> anyhow::Result<()>; + /// Total number of locally-authored posts across all users. async fn count_local_posts(&self) -> anyhow::Result; } diff --git a/crates/adapters/activitypub/src/handler.rs b/crates/adapters/activitypub/src/handler.rs index 54000cc..242adda 100644 --- a/crates/adapters/activitypub/src/handler.rs +++ b/crates/adapters/activitypub/src/handler.rs @@ -170,6 +170,14 @@ impl ApObjectHandler for ThoughtsObjectHandler { .map_err(|e| anyhow!("{e}")) } + async fn on_like(&self, _object_url: &Url, _actor_url: &Url) -> Result<()> { + Ok(()) + } + + async fn on_announce_received(&self, _object_url: &Url, _actor_url: &Url) -> Result<()> { + Ok(()) + } + async fn count_local_posts(&self) -> Result { self.repo .count_local_notes()