From 680d321a2e2d68087fd6cf997c3f6820cfb05bf7 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Mon, 21 Mar 2022 09:34:33 +0900 Subject: [PATCH] Implement Post::create_activity07() --- plume-models/src/posts.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index def48c3a..15963e39 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -10,7 +10,8 @@ use activitypub::{ CustomObject, }; use activitystreams::{ - base::AnyBase, + activity::Create as Create07, + base::{AnyBase, Base}, iri_string::types::IriString, object::{ApObject, Article as Article07, Image as Image07}, prelude::*, @@ -506,6 +507,20 @@ impl Post { Ok(act) } + pub fn create_activity07(&self, conn: &Connection) -> Result { + let article = self.to_activity07(conn)?; + let to = article.to().ok_or(Error::MissingApProperty)?.clone(); + let cc = article.cc().ok_or(Error::MissingApProperty)?.clone(); + let mut act = Create07::new( + self.get_authors(conn)?[0].ap_url.parse::()?, + Base::retract(article)?.into_generic()?, + ); + act.set_id(format!("{}/activity", self.ap_url).parse::()?); + act.set_many_tos(to); + act.set_many_ccs(cc); + Ok(act) + } + pub fn update_activity(&self, conn: &Connection) -> Result { let article = self.to_activity(conn)?; let mut act = Update::default();