2021-04-09 00:22:17 +00:00
|
|
|
use chrono::{DateTime, Utc};
|
2023-04-24 15:35:32 +00:00
|
|
|
use serde::{de::Error as DeserializerError, Deserialize, Deserializer, Serialize};
|
2023-04-25 13:49:35 +00:00
|
|
|
use serde_json::{json, Value};
|
2022-07-14 10:18:03 +00:00
|
|
|
|
2023-02-28 00:20:59 +00:00
|
|
|
use super::receiver::parse_property_value;
|
2022-12-06 20:31:35 +00:00
|
|
|
use super::vocabulary::HASHTAG;
|
2021-04-09 00:22:17 +00:00
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct Attachment {
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
pub attachment_type: String,
|
|
|
|
|
2022-12-10 18:02:08 +00:00
|
|
|
pub name: Option<String>,
|
2021-12-29 13:57:57 +00:00
|
|
|
pub media_type: Option<String>,
|
2022-01-08 21:16:12 +00:00
|
|
|
pub url: Option<String>,
|
2021-04-09 00:22:17 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 14:09:57 +00:00
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct Link {
|
|
|
|
pub href: String,
|
|
|
|
}
|
|
|
|
|
2023-04-24 15:35:32 +00:00
|
|
|
fn default_tag_type() -> String {
|
|
|
|
HASHTAG.to_string()
|
|
|
|
}
|
2022-02-15 23:14:39 +00:00
|
|
|
|
2021-11-11 21:51:47 +00:00
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct Tag {
|
2022-04-27 09:53:52 +00:00
|
|
|
pub name: Option<String>,
|
2021-11-11 21:51:47 +00:00
|
|
|
|
2022-02-15 23:14:39 +00:00
|
|
|
#[serde(rename = "type", default = "default_tag_type")]
|
2021-11-11 21:51:47 +00:00
|
|
|
pub tag_type: String,
|
|
|
|
|
2021-11-24 19:00:36 +00:00
|
|
|
pub href: Option<String>,
|
2021-11-11 21:51:47 +00:00
|
|
|
}
|
|
|
|
|
2023-01-15 01:46:54 +00:00
|
|
|
#[derive(Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct SimpleTag {
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
pub tag_type: String,
|
|
|
|
pub href: String,
|
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// https://codeberg.org/fediverse/fep/src/branch/main/feps/fep-e232.md
|
2023-01-15 00:50:23 +00:00
|
|
|
#[derive(Deserialize, Serialize)]
|
2023-01-15 01:46:54 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct LinkTag {
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
pub tag_type: String,
|
|
|
|
pub href: String,
|
|
|
|
pub media_type: String,
|
|
|
|
pub name: Option<String>,
|
|
|
|
}
|
|
|
|
|
2023-01-21 00:23:15 +00:00
|
|
|
#[derive(Deserialize, Serialize)]
|
2023-01-14 21:51:25 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2023-01-20 01:11:29 +00:00
|
|
|
pub struct EmojiTagImage {
|
2023-01-14 21:51:25 +00:00
|
|
|
#[serde(rename = "type")]
|
2023-01-20 01:11:29 +00:00
|
|
|
pub object_type: String,
|
2023-01-07 19:28:26 +00:00
|
|
|
pub url: String,
|
|
|
|
pub media_type: Option<String>,
|
2023-01-14 21:51:25 +00:00
|
|
|
}
|
|
|
|
|
2023-01-21 00:23:15 +00:00
|
|
|
#[derive(Deserialize, Serialize)]
|
2023-01-14 21:51:25 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct EmojiTag {
|
|
|
|
#[serde(rename = "type")]
|
2023-01-20 01:11:29 +00:00
|
|
|
pub tag_type: String,
|
|
|
|
pub icon: EmojiTagImage,
|
2023-01-07 19:28:26 +00:00
|
|
|
pub id: String,
|
|
|
|
pub name: String,
|
|
|
|
pub updated: DateTime<Utc>,
|
2023-01-14 21:51:25 +00:00
|
|
|
}
|
|
|
|
|
2023-04-24 15:35:32 +00:00
|
|
|
pub fn deserialize_value_array<'de, D>(deserializer: D) -> Result<Vec<Value>, D::Error>
|
|
|
|
where
|
|
|
|
D: Deserializer<'de>,
|
2023-02-28 00:20:59 +00:00
|
|
|
{
|
|
|
|
let maybe_value: Option<Value> = Option::deserialize(deserializer)?;
|
|
|
|
let values = if let Some(value) = maybe_value {
|
|
|
|
parse_property_value(&value).map_err(DeserializerError::custom)?
|
|
|
|
} else {
|
|
|
|
vec![]
|
|
|
|
};
|
|
|
|
Ok(values)
|
|
|
|
}
|
|
|
|
|
2022-12-10 17:30:19 +00:00
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[cfg_attr(test, derive(Default))]
|
2021-04-09 00:22:17 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct Object {
|
2023-01-14 23:31:11 +00:00
|
|
|
// https://www.w3.org/TR/activitypub/#obj-id
|
|
|
|
// "id" and "type" are required properties
|
2021-04-09 00:22:17 +00:00
|
|
|
pub id: String,
|
|
|
|
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
pub object_type: String,
|
|
|
|
|
2022-04-29 13:15:16 +00:00
|
|
|
pub name: Option<String>,
|
2022-04-13 22:30:41 +00:00
|
|
|
pub attachment: Option<Value>,
|
2022-01-04 20:52:41 +00:00
|
|
|
pub cc: Option<Value>,
|
2022-10-13 12:44:45 +00:00
|
|
|
pub media_type: Option<String>,
|
2021-04-09 00:22:17 +00:00
|
|
|
pub published: Option<DateTime<Utc>>,
|
2021-12-24 15:13:25 +00:00
|
|
|
pub attributed_to: Option<Value>,
|
2021-04-09 00:22:17 +00:00
|
|
|
pub in_reply_to: Option<String>,
|
|
|
|
pub content: Option<String>,
|
2022-08-21 22:51:40 +00:00
|
|
|
pub quote_url: Option<String>,
|
2023-04-15 23:43:19 +00:00
|
|
|
pub sensitive: Option<bool>,
|
2023-02-28 00:20:59 +00:00
|
|
|
|
2023-04-24 15:35:32 +00:00
|
|
|
#[serde(default, deserialize_with = "deserialize_value_array")]
|
2023-02-28 00:20:59 +00:00
|
|
|
pub tag: Vec<Value>,
|
|
|
|
|
2021-04-09 00:22:17 +00:00
|
|
|
pub to: Option<Value>,
|
2022-05-11 12:50:36 +00:00
|
|
|
pub updated: Option<DateTime<Utc>>,
|
2022-07-28 14:09:57 +00:00
|
|
|
pub url: Option<Value>,
|
2021-04-09 00:22:17 +00:00
|
|
|
}
|
2023-01-28 22:35:46 +00:00
|
|
|
|
2023-04-25 13:49:35 +00:00
|
|
|
pub type Context = Value;
|
2023-01-28 22:35:46 +00:00
|
|
|
|
2023-02-19 23:20:25 +00:00
|
|
|
pub fn build_default_context() -> Context {
|
2023-04-25 13:49:35 +00:00
|
|
|
json!([
|
|
|
|
"https://www.w3.org/ns/activitystreams",
|
|
|
|
"https://w3id.org/security/v1",
|
|
|
|
{
|
|
|
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
|
|
|
"toot": "http://joinmastodon.org/ns#",
|
|
|
|
"featured": {
|
|
|
|
"@id": "toot:featured",
|
|
|
|
"@type": "@id"
|
|
|
|
},
|
|
|
|
"featuredTags": {
|
|
|
|
"@id": "toot:featuredTags",
|
|
|
|
"@type": "@id"
|
|
|
|
},
|
|
|
|
"alsoKnownAs": {
|
|
|
|
"@id": "as:alsoKnownAs",
|
|
|
|
"@type": "@id"
|
|
|
|
},
|
|
|
|
"movedTo": {
|
|
|
|
"@id": "as:movedTo",
|
|
|
|
"@type": "@id"
|
|
|
|
},
|
|
|
|
"schema": "http://schema.org#",
|
|
|
|
"PropertyValue": "schema:PropertyValue",
|
|
|
|
"value": "schema:value",
|
|
|
|
"IdentityProof": "toot:IdentityProof",
|
|
|
|
"discoverable": "toot:discoverable",
|
|
|
|
"Device": "toot:Device",
|
|
|
|
"Ed25519Signature": "toot:Ed25519Signature",
|
|
|
|
"Ed25519Key": "toot:Ed25519Key",
|
|
|
|
"Curve25519Key": "toot:Curve25519Key",
|
|
|
|
"EncryptedMessage": "toot:EncryptedMessage",
|
|
|
|
"publicKeyBase64": "toot:publicKeyBase64",
|
|
|
|
"deviceId": "toot:deviceId",
|
|
|
|
"claim": {
|
|
|
|
"@type": "@id",
|
|
|
|
"@id": "toot:claim"
|
|
|
|
},
|
|
|
|
"fingerprintKey": {
|
|
|
|
"@type": "@id",
|
|
|
|
"@id": "toot:fingerprintKey"
|
|
|
|
},
|
|
|
|
"identityKey": {
|
|
|
|
"@type": "@id",
|
|
|
|
"@id": "toot:identityKey"
|
|
|
|
},
|
|
|
|
"devices": {
|
|
|
|
"@type": "@id",
|
|
|
|
"@id": "toot:devices"
|
|
|
|
},
|
|
|
|
"messageFranking": "toot:messageFranking",
|
|
|
|
"messageType": "toot:messageType",
|
|
|
|
"cipherText": "toot:cipherText",
|
|
|
|
"suspended": "toot:suspended",
|
|
|
|
"focalPoint": {
|
|
|
|
"@container": "@list",
|
|
|
|
"@id": "toot:focalPoint"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
])
|
2023-01-28 22:35:46 +00:00
|
|
|
}
|