diff --git a/plume-models/src/comments.rs b/plume-models/src/comments.rs index fb7ef85f..17093dda 100644 --- a/plume-models/src/comments.rs +++ b/plume-models/src/comments.rs @@ -17,7 +17,8 @@ use activitypub::{ object::{Note, Tombstone}, }; use activitystreams::{ - iri_string::types::IriString, object::Note as Note07, prelude::*, time::OffsetDateTime, + activity::Create as Create07, base::Base, iri_string::types::IriString, object::Note as Note07, + prelude::*, time::OffsetDateTime, }; use chrono::{self, NaiveDateTime, TimeZone, Utc}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; @@ -200,6 +201,29 @@ impl Comment { Ok(act) } + pub fn create_activity07(&self, conn: &DbConn) -> Result { + let author = User::get(conn, self.author_id)?; + + let note = self.to_activity07(conn)?; + let to = note.to().ok_or(Error::MissingApProperty)?.clone(); + let cc = note.cc().ok_or(Error::MissingApProperty)?.clone(); + + let mut act = Create07::new( + author.into_id().parse::()?, + Base::retract(note)?.into_generic()?, + ); + act.set_id( + format!( + "{}/activity", + self.ap_url.clone().ok_or(Error::MissingApProperty)?, + ) + .parse::()?, + ); + act.set_many_tos(to); + act.set_many_ccs(cc); + Ok(act) + } + pub fn notify(&self, conn: &Connection) -> Result<()> { for author in self.get_post(conn)?.get_authors(conn)? { if Mention::list_for_comment(conn, self.id)?