feat: enhance watchlist handling with entry discriminator and update broadcast methods

This commit is contained in:
2026-05-13 00:45:44 +02:00
parent 31fbb79451
commit 7c08e4a942
3 changed files with 10 additions and 3 deletions

View File

@@ -36,9 +36,11 @@ impl ApObjectHandler for CompositeObjectHandler {
actor_url: &Url, actor_url: &Url,
object: serde_json::Value, object: serde_json::Value,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let is_watchlist = object.get("watchlistEntry").and_then(|v| v.as_bool()) == Some(true)
|| (object.get("movieTitle").is_some() && object.get("rating").is_none());
if object.get("rating").is_some() { if object.get("rating").is_some() {
self.review.on_create(ap_id, actor_url, object).await self.review.on_create(ap_id, actor_url, object).await
} else if object.get("movieTitle").is_some() { } else if is_watchlist {
self.watchlist.on_create(ap_id, actor_url, object).await self.watchlist.on_create(ap_id, actor_url, object).await
} else { } else {
tracing::debug!(ap_id = %ap_id, "ignoring Create for unknown object type"); tracing::debug!(ap_id = %ap_id, "ignoring Create for unknown object type");

View File

@@ -214,7 +214,7 @@ impl ActivityPubEventHandler {
let json = serde_json::to_value(obj)?; let json = serde_json::to_value(obj)?;
self.ap_service self.ap_service
.broadcast_add_to_followers(user_id.value(), ap_id, json) .broadcast_to_followers(user_id.value(), ap_id, json)
.await?; .await?;
Ok(()) Ok(())
} }
@@ -227,7 +227,7 @@ impl ActivityPubEventHandler {
use crate::urls::watchlist_entry_url; use crate::urls::watchlist_entry_url;
let ap_id = watchlist_entry_url(&self.base_url, user_id.value(), movie_id.value()); let ap_id = watchlist_entry_url(&self.base_url, user_id.value(), movie_id.value());
self.ap_service self.ap_service
.broadcast_undo_add_to_followers(user_id.value(), ap_id) .broadcast_delete_to_followers(user_id.value(), ap_id)
.await?; .await?;
Ok(()) Ok(())
} }

View File

@@ -115,6 +115,10 @@ pub struct WatchlistObject {
pub(crate) poster_url: Option<String>, pub(crate) poster_url: Option<String>,
#[serde(default)] #[serde(default)]
pub(crate) tag: Vec<ApHashtag>, pub(crate) tag: Vec<ApHashtag>,
/// Discriminator so Movies Diary instances distinguish this from a review Note.
/// Non-Movies-Diary apps ignore unknown fields.
#[serde(default)]
pub(crate) watchlist_entry: bool,
} }
pub fn watchlist_to_ap_object( pub fn watchlist_to_ap_object(
@@ -160,6 +164,7 @@ pub fn watchlist_to_ap_object(
external_metadata_id, external_metadata_id,
poster_url, poster_url,
tag, tag,
watchlist_entry: true,
} }
} }