feat(activitypub-base): LikeActivity struct + on_like/on_announce_received trait methods

This commit is contained in:
2026-05-15 04:49:20 +02:00
parent 6d365dd3cf
commit 0cf34184d9
3 changed files with 40 additions and 0 deletions

View File

@@ -13,6 +13,16 @@ use url::Url;
#[serde(rename = "Announce")] #[serde(rename = "Announce")]
pub struct AnnounceType; 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::actors::DbActor;
use crate::data::FederationData; use crate::data::FederationData;
use crate::error::Error; 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<DbActor>,
pub object: Url,
}
// --- Add --- // --- Add ---
#[derive(Clone, Default, Debug, Serialize, Deserialize)] #[derive(Clone, Default, Debug, Serialize, Deserialize)]

View File

@@ -42,6 +42,16 @@ pub trait ApObjectHandler: Send + Sync {
/// Actor unfollowed/was removed — clean up all their remote content. /// Actor unfollowed/was removed — clean up all their remote content.
async fn on_actor_removed(&self, actor_url: &Url) -> anyhow::Result<()>; 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. /// Total number of locally-authored posts across all users.
async fn count_local_posts(&self) -> anyhow::Result<u64>; async fn count_local_posts(&self) -> anyhow::Result<u64>;
} }

View File

@@ -170,6 +170,14 @@ impl ApObjectHandler for ThoughtsObjectHandler {
.map_err(|e| anyhow!("{e}")) .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<u64> { async fn count_local_posts(&self) -> Result<u64> {
self.repo self.repo
.count_local_notes() .count_local_notes()