2018-05-12 20:14:43 +00:00
|
|
|
/*
|
|
|
|
* This file is part of ActivityStreams.
|
|
|
|
*
|
|
|
|
* Copyright © 2018 Riley Trautman
|
|
|
|
*
|
|
|
|
* ActivityStreams is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* ActivityStreams is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with ActivityStreams. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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};
|
2018-05-13 19:53:06 +00:00
|
|
|
|
|
|
|
pub type UtcTime = DateTime<Utc>;
|
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 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-13 19:53:06 +00:00
|
|
|
#[activitystreams(concrete(String, UtcTime), 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-13 19:53:06 +00:00
|
|
|
#[activitystreams(concrete(String, UtcTime), 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-13 19:53:06 +00:00
|
|
|
#[activitystreams(concrete(String, UtcTime), 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-13 19:53:06 +00:00
|
|
|
#[activitystreams(concrete(String, UtcTime), 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: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")]
|
2018-05-13 19:53:06 +00:00
|
|
|
#[activitystreams(concrete(String, UtcTime), functional)]
|
2018-05-12 19:35:10 +00:00
|
|
|
deleted: Option<serde_json::Value>,
|
2018-05-12 05:31:33 +00:00
|
|
|
}
|