diff options
author | Felix Ableitner <me@nutomic.com> | 2020-04-07 23:02:32 +0200 |
---|---|---|
committer | Felix Ableitner <me@nutomic.com> | 2020-04-07 23:02:32 +0200 |
commit | 61c560c12c0edb56d006ba2c6ab07013567ffab8 (patch) | |
tree | 8dc666c604abe5b0d1468ca432bd247042de8cd3 /server/src/apub/post.rs | |
parent | d3bd7771d2a3cfbb24084e44083dc70f02b4ba8c (diff) |
Get users federated
Diffstat (limited to 'server/src/apub/post.rs')
-rw-r--r-- | server/src/apub/post.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/server/src/apub/post.rs b/server/src/apub/post.rs index 4c788418..2db5d8ec 100644 --- a/server/src/apub/post.rs +++ b/server/src/apub/post.rs @@ -1,7 +1,10 @@ +use crate::apub::puller::fetch_remote_user; use crate::apub::{create_apub_response, make_apub_endpoint, EndpointType}; use crate::convert_datetime; use crate::db::post::{Post, PostForm}; -use activitystreams::{object::properties::ObjectProperties, object::Page}; +use crate::db::user::User_; +use crate::db::Crud; +use activitystreams::{context, object::properties::ObjectProperties, object::Page}; use actix_web::body::Body; use actix_web::web::Path; use actix_web::{web, HttpResponse}; @@ -21,25 +24,23 @@ pub async fn get_apub_post( ) -> Result<HttpResponse<Body>, Error> { let id = info.post_id.parse::<i32>()?; let post = Post::read(&&db.get()?, id)?; - Ok(create_apub_response(&post.as_page()?)) + Ok(create_apub_response(&post.as_page(&db.get().unwrap())?)) } impl Post { - pub fn as_page(&self) -> Result<Page, Error> { + pub fn as_page(&self, conn: &PgConnection) -> Result<Page, Error> { let base_url = make_apub_endpoint(EndpointType::Post, &self.id.to_string()); let mut page = Page::default(); let oprops: &mut ObjectProperties = page.as_mut(); + let creator = User_::read(conn, self.creator_id)?; oprops // Not needed when the Post is embedded in a collection (like for community outbox) - //.set_context_xsd_any_uri(context())? + .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( - EndpointType::User, - &self.creator_id.to_string(), - ))?; + .set_attributed_to_xsd_any_uri(make_apub_endpoint(EndpointType::User, &creator.name))?; if let Some(body) = &self.body { oprops.set_content_xsd_string(body.to_owned())?; @@ -61,13 +62,17 @@ impl Post { } impl PostForm { - pub fn from_page(page: &Page) -> Result<PostForm, Error> { + pub fn from_page(page: &Page, conn: &PgConnection) -> Result<PostForm, Error> { let oprops = &page.object_props; + let creator = fetch_remote_user( + &oprops.get_attributed_to_xsd_any_uri().unwrap().to_string(), + conn, + )?; Ok(PostForm { name: oprops.get_name_xsd_string().unwrap().to_string(), url: oprops.get_url_xsd_any_uri().map(|u| u.to_string()), body: oprops.get_content_xsd_string().map(|c| c.to_string()), - creator_id: 2, + creator_id: creator.id, community_id: -1, removed: None, locked: None, |