2018-05-12 19:51:54 +00:00
|
|
|
use chrono::{offset::Utc, DateTime};
|
2018-05-12 05:31:33 +00:00
|
|
|
use mime;
|
2018-05-12 19:35:10 +00:00
|
|
|
use serde_json::{self, Value};
|
2018-05-12 05:31:33 +00:00
|
|
|
|
|
|
|
use collection::Collection;
|
|
|
|
use error::{Error, Result};
|
|
|
|
use link::Link;
|
|
|
|
use object::{Image, Object};
|
|
|
|
use Properties;
|
|
|
|
|
2018-05-12 19:35:10 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, Properties)]
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct ObjectProperties {
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(concrete(String), functional)]
|
2018-05-12 05:31:33 +00:00
|
|
|
id: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(ab(Object, Link))]
|
2018-05-12 05:31:33 +00:00
|
|
|
attachment: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(ab(Object, Link))]
|
2018-05-12 05:31:33 +00:00
|
|
|
attributed_to: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(ab(Object, Link))]
|
2018-05-12 05:31:33 +00:00
|
|
|
audience: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(concrete(String))]
|
2018-05-12 05:31:33 +00:00
|
|
|
content: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none", rename = "@context")]
|
|
|
|
#[activitystreams(concrete(Value), functional)]
|
2018-05-12 05:31:33 +00:00
|
|
|
context: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(concrete(String))]
|
2018-05-12 05:31:33 +00:00
|
|
|
name: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(concrete(String), functional)]
|
2018-05-12 05:31:33 +00:00
|
|
|
end_time: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(ab(Object, Link))]
|
2018-05-12 05:31:33 +00:00
|
|
|
generator: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(ab(Link), concrete(Image))]
|
2018-05-12 05:31:33 +00:00
|
|
|
icon: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(ab(Link), concrete(Image))]
|
2018-05-12 05:31:33 +00:00
|
|
|
image: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(ab(Object, Link))]
|
2018-05-12 05:31:33 +00:00
|
|
|
in_reply_to: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(ab(Object, Link))]
|
2018-05-12 05:31:33 +00:00
|
|
|
location: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(ab(Object, Link))]
|
2018-05-12 05:31:33 +00:00
|
|
|
preview: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(concrete(String), functional)]
|
2018-05-12 05:31:33 +00:00
|
|
|
published: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(concrete(Collection), functional)]
|
2018-05-12 05:31:33 +00:00
|
|
|
replies: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(concrete(String), functional)]
|
2018-05-12 05:31:33 +00:00
|
|
|
start_time: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(concrete(String))]
|
2018-05-12 05:31:33 +00:00
|
|
|
summary: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(ab(Object, Link))]
|
2018-05-12 05:31:33 +00:00
|
|
|
tag: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(concrete(String), functional)]
|
2018-05-12 05:31:33 +00:00
|
|
|
updated: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(concrete(String), ab(Link))]
|
2018-05-12 05:31:33 +00:00
|
|
|
url: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(ab(Object, Link))]
|
2018-05-12 05:31:33 +00:00
|
|
|
to: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(ab(Object, Link))]
|
2018-05-12 05:31:33 +00:00
|
|
|
bto: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(ab(Object, Link))]
|
2018-05-12 05:31:33 +00:00
|
|
|
cc: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(ab(Object, Link))]
|
2018-05-12 05:31:33 +00:00
|
|
|
bcc: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(concrete(String), functional)]
|
2018-05-12 05:31:33 +00:00
|
|
|
media_type: Option<serde_json::Value>,
|
2018-05-12 19:35:10 +00:00
|
|
|
|
|
|
|
// TODO: xsd:duration
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(concrete(String), functional)]
|
2018-05-12 05:31:33 +00:00
|
|
|
duration: Option<serde_json::Value>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ObjectProperties {
|
|
|
|
pub fn media_type(&self) -> Result<mime::Mime> {
|
2018-05-12 19:35:10 +00:00
|
|
|
self.media_type_string()
|
2018-05-12 05:31:33 +00:00
|
|
|
.and_then(|s| s.parse().map_err(|_| Error::Deserialize))
|
|
|
|
}
|
2018-05-12 19:51:54 +00:00
|
|
|
|
|
|
|
pub fn end_time(&self) -> Result<DateTime<Utc>> {
|
|
|
|
self.end_time_string()
|
|
|
|
.and_then(|s| s.parse().map_err(|_| Error::Deserialize))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn published(&self) -> Result<DateTime<Utc>> {
|
|
|
|
self.published_string()
|
|
|
|
.and_then(|s| s.parse().map_err(|_| Error::Deserialize))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn start_time(&self) -> Result<DateTime<Utc>> {
|
|
|
|
self.start_time_string()
|
|
|
|
.and_then(|s| s.parse().map_err(|_| Error::Deserialize))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn updated(&self) -> Result<DateTime<Utc>> {
|
|
|
|
self.updated_string()
|
|
|
|
.and_then(|s| s.parse().map_err(|_| Error::Deserialize))
|
|
|
|
}
|
2018-05-12 05:31:33 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 19:35:10 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, Properties)]
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct PlaceProperties {
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(concrete(f64), functional)]
|
|
|
|
accuracy: Option<serde_json::Value>,
|
2018-05-12 05:31:33 +00:00
|
|
|
|
2018-05-12 19:35:10 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
#[activitystreams(concrete(f64), functional)]
|
|
|
|
altitude: Option<serde_json::Value>,
|
2018-05-12 05:31:33 +00:00
|
|
|
|
2018-05-12 19:35:10 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
#[activitystreams(concrete(f64), functional)]
|
|
|
|
latitude: Option<serde_json::Value>,
|
2018-05-12 05:31:33 +00:00
|
|
|
|
2018-05-12 19:35:10 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
#[activitystreams(concrete(f64), functional)]
|
|
|
|
longitude: Option<serde_json::Value>,
|
2018-05-12 05:31:33 +00:00
|
|
|
|
2018-05-12 19:35:10 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
#[activitystreams(concrete(f64), functional)]
|
|
|
|
radius: Option<serde_json::Value>,
|
2018-05-12 05:31:33 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 19:35:10 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, Properties)]
|
2018-05-12 05:31:33 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct TombstoneProperties {
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2018-05-12 19:35:10 +00:00
|
|
|
#[activitystreams(concrete(String))]
|
2018-05-12 05:31:33 +00:00
|
|
|
former_type: Option<serde_json::Value>,
|
|
|
|
|
2018-05-12 19:35:10 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
#[activitystreams(concrete(String), functional)]
|
|
|
|
deleted: Option<serde_json::Value>,
|
2018-05-12 05:31:33 +00:00
|
|
|
}
|
2018-05-12 19:51:54 +00:00
|
|
|
|
|
|
|
impl TombstoneProperties {
|
|
|
|
pub fn deleted(&self) -> Result<DateTime<Utc>> {
|
|
|
|
self.deleted_string()
|
|
|
|
.and_then(|s| s.parse().map_err(|_| Error::Deserialize))
|
|
|
|
}
|
|
|
|
}
|