summaryrefslogtreecommitdiffstats
path: root/server/src/apub/post.rs
diff options
context:
space:
mode:
authorFelix Ableitner <me@nutomic.com>2020-04-03 07:02:43 +0200
committerFelix Ableitner <me@nutomic.com>2020-04-03 07:02:43 +0200
commit96c3621a801d96a8d2bffc849d871c297683e387 (patch)
tree32487c48a63fa9d01ce4ae4d9bb09421815e77e0 /server/src/apub/post.rs
parent0d369e60197fd8a967200ee6c02a9f84beaf5dca (diff)
Share list of communities over apub, some refactoring
Diffstat (limited to 'server/src/apub/post.rs')
-rw-r--r--server/src/apub/post.rs51
1 files changed, 50 insertions, 1 deletions
diff --git a/server/src/apub/post.rs b/server/src/apub/post.rs
index 706c1134..a9b50013 100644
--- a/server/src/apub/post.rs
+++ b/server/src/apub/post.rs
@@ -1,6 +1,6 @@
use crate::apub::{create_apub_response, make_apub_endpoint, EndpointType};
-use crate::convert_datetime;
use crate::db::post_view::PostView;
+use crate::{convert_datetime, naive_now};
use activitystreams::{object::properties::ObjectProperties, object::Page};
use actix_web::body::Body;
use actix_web::web::Path;
@@ -59,4 +59,53 @@ impl PostView {
Ok(page)
}
+
+ pub fn from_page(page: &Page) -> Result<PostView, Error> {
+ let oprops = &page.object_props;
+ Ok(PostView {
+ id: -1,
+ 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: -1,
+ community_id: -1,
+ removed: false,
+ locked: false,
+ published: oprops
+ .get_published()
+ .unwrap()
+ .as_ref()
+ .naive_local()
+ .to_owned(),
+ updated: oprops
+ .get_updated()
+ .map(|u| u.as_ref().to_owned().naive_local()),
+ deleted: false,
+ nsfw: false,
+ stickied: false,
+ embed_title: None,
+ embed_description: None,
+ embed_html: None,
+ thumbnail_url: None,
+ banned: false,
+ banned_from_community: false,
+ creator_name: "".to_string(),
+ creator_avatar: None,
+ community_name: "".to_string(),
+ community_removed: false,
+ community_deleted: false,
+ community_nsfw: false,
+ number_of_comments: -1,
+ score: -1,
+ upvotes: -1,
+ downvotes: -1,
+ hot_rank: -1,
+ newest_activity_time: naive_now(),
+ user_id: None,
+ my_vote: None,
+ subscribed: None,
+ read: None,
+ saved: None,
+ })
+ }
}