lemmy/server/src/apub/post.rs

39 lines
1.1 KiB
Rust
Raw Normal View History

use crate::apub::make_apub_endpoint;
use crate::convert_datetime;
2020-03-14 00:05:42 +00:00
use crate::db::post_view::PostView;
use activitystreams::{object::apub::Page, object::properties::ObjectProperties};
use failure::Error;
2020-03-14 00:05:42 +00:00
impl PostView {
pub fn as_page(&self) -> Result<Page, Error> {
let base_url = make_apub_endpoint("post", self.id);
let mut page = Page::default();
let oprops: &mut ObjectProperties = page.as_mut();
oprops
2020-03-14 00:05:42 +00:00
// Not needed when the Post is embedded in a collection (like for community outbox)
//.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))?;
if let Some(body) = &self.body {
oprops.set_content_xsd_string(body.to_owned())?;
}
2020-03-14 00:05:42 +00:00
if let Some(_url) = &self.url {
// TODO: crashes here
//oprops.set_url_xsd_any_uri(url.to_owned())?;
}
if let Some(u) = self.updated {
oprops.set_updated(convert_datetime(u))?;
}
Ok(page)
}
}
// TODO: need to serve this via actix