summaryrefslogtreecommitdiffstats
path: root/server/src/apub/user.rs
diff options
context:
space:
mode:
authorFelix <me@nutomic.com>2020-03-12 01:01:25 +0100
committerFelix <me@nutomic.com>2020-03-12 01:01:25 +0100
commit54172bd322c5aef4ff7243a3ece316c8bbf80c2c (patch)
tree8d2bced971aa9fde57262e654b57061f751cb8eb /server/src/apub/user.rs
parent8867fa1d52967c3755eabf677654c3bb04b0fd67 (diff)
updated to activitystreams 0.4.0-alpha.3
Diffstat (limited to 'server/src/apub/user.rs')
-rw-r--r--server/src/apub/user.rs71
1 files changed, 28 insertions, 43 deletions
diff --git a/server/src/apub/user.rs b/server/src/apub/user.rs
index 5f2421f1..c1ffcedd 100644
--- a/server/src/apub/user.rs
+++ b/server/src/apub/user.rs
@@ -1,58 +1,41 @@
use crate::apub::make_apub_endpoint;
+use crate::convert_datetime;
use crate::db::establish_unpooled_connection;
use crate::db::user::User_;
-use crate::to_datetime_utc;
-use activitypub::{actor::Person, context};
+use activitystreams::{actor::apub::Person, context, object::properties::ObjectProperties};
use actix_web::body::Body;
use actix_web::web::Path;
use actix_web::HttpResponse;
+use failure::Error;
use serde::Deserialize;
impl User_ {
- pub fn as_person(&self) -> Person {
+ pub fn as_person(&self) -> Result<Person, Error> {
let base_url = make_apub_endpoint("u", &self.name);
+
let mut person = Person::default();
- person.object_props.set_context_object(context()).ok();
- person.object_props.set_id_string(base_url.to_string()).ok();
- person
- .object_props
- .set_name_string(self.name.to_owned())
- .ok();
- person
- .object_props
- .set_published_utctime(to_datetime_utc(self.published))
- .ok();
- if let Some(updated) = self.updated {
- person
- .object_props
- .set_updated_utctime(to_datetime_utc(updated))
- .ok();
+ let oprops: &mut ObjectProperties = person.as_mut();
+ oprops
+ .set_context_xsd_any_uri(context())?
+ .set_id(base_url.to_string())?
+ .set_published(convert_datetime(self.published))?;
+
+ if let Some(u) = self.updated {
+ oprops.set_updated(convert_datetime(u))?;
}
- person
- .ap_actor_props
- .set_inbox_string(format!("{}/inbox", &base_url))
- .ok();
- person
- .ap_actor_props
- .set_outbox_string(format!("{}/outbox", &base_url))
- .ok();
- person
- .ap_actor_props
- .set_following_string(format!("{}/following", &base_url))
- .ok();
- person
- .ap_actor_props
- .set_liked_string(format!("{}/liked", &base_url))
- .ok();
if let Some(i) = &self.preferred_username {
- person
- .ap_actor_props
- .set_preferred_username_string(i.to_string())
- .ok();
+ oprops.set_name_xsd_string(i.to_owned())?;
}
person
+ .ap_actor_props
+ .set_inbox(format!("{}/inbox", &base_url))?
+ .set_outbox(format!("{}/outbox", &base_url))?
+ .set_following(format!("{}/following", &base_url))?
+ .set_liked(format!("{}/liked", &base_url))?;
+
+ Ok(person)
}
}
@@ -61,14 +44,16 @@ pub struct UserQuery {
user_name: String,
}
-pub async fn get_apub_user(info: Path<UserQuery>) -> HttpResponse<Body> {
+pub async fn get_apub_user(info: Path<UserQuery>) -> Result<HttpResponse<Body>, Error> {
let connection = establish_unpooled_connection();
if let Ok(user) = User_::find_by_email_or_username(&connection, &info.user_name) {
- HttpResponse::Ok()
- .content_type("application/activity+json")
- .body(serde_json::to_string(&user.as_person()).unwrap())
+ Ok(
+ HttpResponse::Ok()
+ .content_type("application/activity+json")
+ .body(serde_json::to_string(&user.as_person()?).unwrap()),
+ )
} else {
- HttpResponse::NotFound().finish()
+ Ok(HttpResponse::NotFound().finish())
}
}