Implement Post::create_activity07()

This commit is contained in:
Kitaiti Makoto 2022-03-21 09:34:33 +09:00
parent c37ff54857
commit 680d321a2e

View File

@ -10,7 +10,8 @@ use activitypub::{
CustomObject, CustomObject,
}; };
use activitystreams::{ use activitystreams::{
base::AnyBase, activity::Create as Create07,
base::{AnyBase, Base},
iri_string::types::IriString, iri_string::types::IriString,
object::{ApObject, Article as Article07, Image as Image07}, object::{ApObject, Article as Article07, Image as Image07},
prelude::*, prelude::*,
@ -506,6 +507,20 @@ impl Post {
Ok(act) Ok(act)
} }
pub fn create_activity07(&self, conn: &Connection) -> Result<Create07> {
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::<IriString>()?,
Base::retract(article)?.into_generic()?,
);
act.set_id(format!("{}/activity", self.ap_url).parse::<IriString>()?);
act.set_many_tos(to);
act.set_many_ccs(cc);
Ok(act)
}
pub fn update_activity(&self, conn: &Connection) -> Result<Update> { pub fn update_activity(&self, conn: &Connection) -> Result<Update> {
let article = self.to_activity(conn)?; let article = self.to_activity(conn)?;
let mut act = Update::default(); let mut act = Update::default();