2019-12-19 21:59:13 +00:00
|
|
|
use crate::apub::make_apub_endpoint;
|
2020-03-12 00:01:25 +00:00
|
|
|
use crate::convert_datetime;
|
2019-12-19 21:59:13 +00:00
|
|
|
use crate::db::post::Post;
|
2020-03-12 00:01:25 +00:00
|
|
|
use activitystreams::{context, object::apub::Page, object::properties::ObjectProperties};
|
|
|
|
use failure::Error;
|
2019-12-19 21:59:13 +00:00
|
|
|
|
|
|
|
impl Post {
|
2020-03-12 00:01:25 +00:00
|
|
|
pub fn as_page(&self) -> Result<Page, Error> {
|
2019-12-19 21:59:13 +00:00
|
|
|
let base_url = make_apub_endpoint("post", self.id);
|
|
|
|
let mut page = Page::default();
|
2020-03-12 00:01:25 +00:00
|
|
|
let oprops: &mut ObjectProperties = page.as_mut();
|
2019-12-19 21:59:13 +00:00
|
|
|
|
2020-03-12 00:01:25 +00:00
|
|
|
oprops
|
|
|
|
.set_context_xsd_any_uri(context())?
|
|
|
|
.set_id(base_url)?
|
|
|
|
.set_name_xsd_string(self.name.to_owned())?
|
|
|
|
.set_published(convert_datetime(self.published))?
|
|
|
|
.set_attributed_to_xsd_any_uri(make_apub_endpoint("u", &self.creator_id))?;
|
2019-12-19 21:59:13 +00:00
|
|
|
|
|
|
|
if let Some(body) = &self.body {
|
2020-03-12 00:01:25 +00:00
|
|
|
oprops.set_content_xsd_string(body.to_owned())?;
|
2019-12-19 21:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(url) = &self.url {
|
2020-03-12 00:01:25 +00:00
|
|
|
oprops.set_url_xsd_any_uri(url.to_owned())?;
|
2019-12-19 21:59:13 +00:00
|
|
|
}
|
|
|
|
|
2020-03-12 00:01:25 +00:00
|
|
|
if let Some(u) = self.updated {
|
|
|
|
oprops.set_updated(convert_datetime(u))?;
|
2019-12-19 21:59:13 +00:00
|
|
|
}
|
|
|
|
|
2020-03-12 00:01:25 +00:00
|
|
|
Ok(page)
|
2019-12-19 21:59:13 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-12 00:01:25 +00:00
|
|
|
|
|
|
|
// TODO: need to serve this via actix
|