From 08ac7227b5a33c852e20a1c8cfd73257ed58114c Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 3 Apr 2022 21:44:21 +0900 Subject: [PATCH] Implement Comment::builde_delete07() --- plume-models/src/comments.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/plume-models/src/comments.rs b/plume-models/src/comments.rs index 17093dda..574c626c 100644 --- a/plume-models/src/comments.rs +++ b/plume-models/src/comments.rs @@ -17,8 +17,12 @@ use activitypub::{ object::{Note, Tombstone}, }; use activitystreams::{ - activity::Create as Create07, base::Base, iri_string::types::IriString, object::Note as Note07, - prelude::*, time::OffsetDateTime, + activity::{Create as Create07, Delete as Delete07}, + base::Base, + iri_string::types::IriString, + object::{Note as Note07, Tombstone as Tombstone07}, + prelude::*, + time::OffsetDateTime, }; use chrono::{self, NaiveDateTime, TimeZone, Utc}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; @@ -262,6 +266,26 @@ impl Comment { Ok(act) } + + pub fn build_delete07(&self, conn: &Connection) -> Result { + let mut tombstone = Tombstone07::new(); + tombstone.set_id( + self.ap_url + .as_ref() + .ok_or(Error::MissingApProperty)? + .parse::()?, + ); + + let mut act = Delete07::new( + self.get_author(conn)?.into_id().parse::()?, + Base::retract(tombstone)?.into_generic()?, + ); + + act.set_id(format!("{}#delete", self.ap_url.clone().unwrap()).parse::()?); + act.set_many_tos(vec![PUBLIC_VISIBILITY.parse::()?]); + + Ok(act) + } } impl FromId for Comment {