diff --git a/plume-models/src/comments.rs b/plume-models/src/comments.rs index 37f800c3..2fe710ab 100644 --- a/plume-models/src/comments.rs +++ b/plume-models/src/comments.rs @@ -30,7 +30,7 @@ use chrono::{self, NaiveDateTime, TimeZone, Utc}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; use plume_common::{ activity_pub::{ - inbox::{AsActor, AsObject, FromId, FromId07}, + inbox::{AsActor, AsObject, AsObject07, FromId, FromId07}, sign::Signer, Id, IntoId, ToAsString, ToAsUri, PUBLIC_VISIBILITY, }, @@ -605,6 +605,45 @@ impl AsObject for Comment { } } +impl AsObject07 for Comment { + type Error = Error; + type Output = Self; + + fn activity07(self, _conn: &DbConn, _actor: User, _id: &str) -> Result { + // The actual creation takes place in the FromId impl + Ok(self) + } +} + +impl AsObject07 for Comment { + type Error = Error; + type Output = (); + + fn activity07(self, conn: &DbConn, actor: User, _id: &str) -> Result<()> { + if self.author_id != actor.id { + return Err(Error::Unauthorized); + } + + for m in Mention::list_for_comment(conn, self.id)? { + for n in Notification::find_for_mention(conn, &m)? { + n.delete(conn)?; + } + m.delete(conn)?; + } + + for n in Notification::find_for_comment(conn, &self)? { + n.delete(&**conn)?; + } + + diesel::update(comments::table) + .filter(comments::in_response_to_id.eq(self.id)) + .set(comments::in_response_to_id.eq(self.in_response_to_id)) + .execute(&**conn)?; + diesel::delete(&self).execute(&**conn)?; + Ok(()) + } +} + pub struct CommentTree { pub comment: Comment, pub responses: Vec,