diff --git a/crates/adapters/activitypub/src/remote_review_repository.rs b/crates/adapters/activitypub/src/remote_review_repository.rs index 5970ce8..e137f84 100644 --- a/crates/adapters/activitypub/src/remote_review_repository.rs +++ b/crates/adapters/activitypub/src/remote_review_repository.rs @@ -23,6 +23,7 @@ pub trait RemoteReviewRepository: Send + Sync { rating: u8, comment: Option<&str>, watched_at: NaiveDateTime, + poster_url: Option<&str>, ) -> Result<()>; async fn delete_by_actor(&self, actor_url: &str) -> Result<()>; diff --git a/crates/adapters/activitypub/src/review_handler.rs b/crates/adapters/activitypub/src/review_handler.rs index d4ab3a8..4e786cf 100644 --- a/crates/adapters/activitypub/src/review_handler.rs +++ b/crates/adapters/activitypub/src/review_handler.rs @@ -153,6 +153,7 @@ impl ApObjectHandler for ReviewObjectHandler { obj.rating.min(5), obj.comment.as_deref(), obj.watched_at.naive_utc(), + obj.poster_url.as_deref(), ) .await?; diff --git a/crates/adapters/postgres-federation/src/lib.rs b/crates/adapters/postgres-federation/src/lib.rs index 380c88c..c082b03 100644 --- a/crates/adapters/postgres-federation/src/lib.rs +++ b/crates/adapters/postgres-federation/src/lib.rs @@ -685,6 +685,7 @@ impl RemoteReviewRepository for PostgresFederationRepository { rating: u8, comment: Option<&str>, watched_at: chrono::NaiveDateTime, + poster_url: Option<&str>, ) -> Result<()> { let watched_at_str = datetime_to_str(&watched_at); sqlx::query( @@ -698,6 +699,17 @@ impl RemoteReviewRepository for PostgresFederationRepository { .bind(actor_url) .execute(&self.pool) .await?; + if let Some(url) = poster_url { + sqlx::query( + "UPDATE movies SET poster_path = $1 + WHERE id = (SELECT movie_id FROM reviews WHERE ap_id = $2 AND remote_actor_url = $3)", + ) + .bind(url) + .bind(ap_id) + .bind(actor_url) + .execute(&self.pool) + .await?; + } Ok(()) } diff --git a/crates/adapters/sqlite-federation/src/lib.rs b/crates/adapters/sqlite-federation/src/lib.rs index 8d549b2..284b5c7 100644 --- a/crates/adapters/sqlite-federation/src/lib.rs +++ b/crates/adapters/sqlite-federation/src/lib.rs @@ -870,6 +870,7 @@ impl RemoteReviewRepository for SqliteFederationRepository { rating: u8, comment: Option<&str>, watched_at: chrono::NaiveDateTime, + poster_url: Option<&str>, ) -> Result<()> { let watched_at_str = datetime_to_str(&watched_at); sqlx::query( @@ -883,6 +884,17 @@ impl RemoteReviewRepository for SqliteFederationRepository { .bind(actor_url) .execute(&self.pool) .await?; + if let Some(url) = poster_url { + sqlx::query( + "UPDATE movies SET poster_path = ? + WHERE id = (SELECT movie_id FROM reviews WHERE ap_id = ? AND remote_actor_url = ?)", + ) + .bind(url) + .bind(ap_id) + .bind(actor_url) + .execute(&self.pool) + .await?; + } Ok(()) }