aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorXe Iaso <me@christine.website>2022-10-08 16:36:13 +0000
committerXe Iaso <me@christine.website>2022-10-08 16:36:13 +0000
commitc324bf0ef0ee9a14534943de2734e04f7c2eabf5 (patch)
tree2a42c7b62504b2bf26c17a996220acb0f7933d02 /lib
parentb3d3c7991ec0d88783a541f03e5c8f76cbce3c53 (diff)
downloadxesite-c324bf0ef0ee9a14534943de2734e04f7c2eabf5.tar.xz
xesite-c324bf0ef0ee9a14534943de2734e04f7c2eabf5.zip
xesite_types: add mastodon types for future mastodon embed tag
Signed-off-by: Xe Iaso <me@christine.website>
Diffstat (limited to 'lib')
-rw-r--r--lib/xesite_types/Cargo.toml1
-rw-r--r--lib/xesite_types/src/lib.rs2
-rw-r--r--lib/xesite_types/src/mastodon.rs212
-rw-r--r--lib/xesite_types/src/testdata/post_attachment.json62
-rw-r--r--lib/xesite_types/src/testdata/post_hashtags.json59
-rw-r--r--lib/xesite_types/src/testdata/post_mention.json54
-rw-r--r--lib/xesite_types/src/testdata/robocadey.json97
7 files changed, 487 insertions, 0 deletions
diff --git a/lib/xesite_types/Cargo.toml b/lib/xesite_types/Cargo.toml
index 3d72524..6d1854d 100644
--- a/lib/xesite_types/Cargo.toml
+++ b/lib/xesite_types/Cargo.toml
@@ -10,3 +10,4 @@ license = "zlib"
[dependencies]
chrono = { version = "0.4", features = [ "serde" ] }
serde = { version = "1.0", features = [ "derive" ] }
+serde_json = "1" \ No newline at end of file
diff --git a/lib/xesite_types/src/lib.rs b/lib/xesite_types/src/lib.rs
index 68ae4c4..646f711 100644
--- a/lib/xesite_types/src/lib.rs
+++ b/lib/xesite_types/src/lib.rs
@@ -1,5 +1,7 @@
use serde::{Deserialize, Serialize};
+pub mod mastodon;
+
#[derive(Eq, PartialEq, Deserialize, Default, Debug, Serialize, Clone)]
pub struct Frontmatter {
#[serde(default = "frontmatter_about")]
diff --git a/lib/xesite_types/src/mastodon.rs b/lib/xesite_types/src/mastodon.rs
new file mode 100644
index 0000000..3b4eb2a
--- /dev/null
+++ b/lib/xesite_types/src/mastodon.rs
@@ -0,0 +1,212 @@
+use chrono::prelude::*;
+use serde::{Deserialize, Serialize};
+
+#[derive(Serialize, Deserialize)]
+pub struct User {
+ #[serde(rename = "id")]
+ id: String,
+
+ #[serde(rename = "type")]
+ user_type: String,
+
+ #[serde(rename = "following")]
+ following: String,
+
+ #[serde(rename = "followers")]
+ followers: String,
+
+ #[serde(rename = "inbox")]
+ inbox: String,
+
+ #[serde(rename = "outbox")]
+ outbox: String,
+
+ #[serde(rename = "featured")]
+ featured: String,
+
+ #[serde(rename = "featuredTags")]
+ featured_tags: String,
+
+ #[serde(rename = "preferredUsername")]
+ preferred_username: String,
+
+ #[serde(rename = "name")]
+ name: String,
+
+ #[serde(rename = "summary")]
+ summary: String,
+
+ #[serde(rename = "url")]
+ url: String,
+
+ #[serde(rename = "manuallyApprovesFollowers")]
+ manually_approves_followers: bool,
+
+ #[serde(rename = "discoverable")]
+ discoverable: bool,
+
+ #[serde(rename = "published")]
+ published: String,
+
+ #[serde(rename = "devices")]
+ devices: String,
+
+ #[serde(rename = "icon")]
+ icon: Icon,
+
+ #[serde(rename = "image")]
+ image: Icon,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct Icon {
+ #[serde(rename = "type")]
+ icon_type: String,
+
+ #[serde(rename = "mediaType")]
+ media_type: String,
+
+ #[serde(rename = "url")]
+ url: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct Toot {
+ #[serde(rename = "id")]
+ id: String,
+
+ #[serde(rename = "type")]
+ toot_type: String,
+
+ #[serde(rename = "inReplyTo")]
+ in_reply_to: Option<String>,
+
+ #[serde(rename = "published")]
+ published: DateTime<Utc>,
+
+ #[serde(rename = "url")]
+ url: String,
+
+ #[serde(rename = "attributedTo")]
+ attributed_to: String,
+
+ #[serde(rename = "to")]
+ to: Vec<String>,
+
+ #[serde(rename = "cc")]
+ cc: Vec<String>,
+
+ #[serde(rename = "sensitive")]
+ sensitive: bool,
+
+ #[serde(rename = "atomUri")]
+ atom_uri: String,
+
+ #[serde(rename = "inReplyToAtomUri")]
+ in_reply_to_atom_uri: Option<String>,
+
+ #[serde(rename = "conversation")]
+ conversation: String,
+
+ #[serde(rename = "content")]
+ content: String,
+
+ #[serde(rename = "contentMap")]
+ content_map: ContentMap,
+
+ #[serde(rename = "attachment")]
+ attachment: Vec<Attachment>,
+
+ #[serde(rename = "tag")]
+ tag: Vec<Tag>,
+
+ #[serde(rename = "replies")]
+ replies: Replies,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct Tag {
+ #[serde(rename = "type")]
+ tag_type: String,
+
+ #[serde(rename = "href")]
+ href: String,
+
+ #[serde(rename = "name")]
+ name: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct Attachment {
+ #[serde(rename = "type")]
+ attachment_type: String,
+
+ #[serde(rename = "mediaType")]
+ media_type: String,
+
+ #[serde(rename = "url")]
+ url: String,
+
+ #[serde(rename = "name")]
+ name: Option<serde_json::Value>,
+
+ #[serde(rename = "blurhash")]
+ blurhash: String,
+
+ #[serde(rename = "width")]
+ width: i64,
+
+ #[serde(rename = "height")]
+ height: i64,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct ContentMap {
+ #[serde(rename = "en")]
+ en: String,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct Replies {
+ #[serde(rename = "id")]
+ id: String,
+
+ #[serde(rename = "type")]
+ replies_type: String,
+
+ #[serde(rename = "first")]
+ first: Page,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct Page {
+ #[serde(rename = "type")]
+ first_type: String,
+
+ #[serde(rename = "next")]
+ next: String,
+
+ #[serde(rename = "partOf")]
+ part_of: String,
+
+ #[serde(rename = "items")]
+ items: Vec<String>,
+}
+
+#[cfg(test)]
+pub mod test {
+ use super::*;
+ use serde_json::from_str;
+
+ #[test]
+ fn user() {
+ let _: User = from_str(include_str!("./testdata/robocadey.json")).unwrap();
+ }
+
+ #[test]
+ fn toot() {
+ let _attachment: Toot = from_str(include_str!("./testdata/post_attachment.json")).unwrap();
+ let _hashtags: Toot = from_str(include_str!("./testdata/post_hashtags.json")).unwrap();
+ let _mention: Toot = from_str(include_str!("./testdata/post_mention.json")).unwrap();
+ }
+}
diff --git a/lib/xesite_types/src/testdata/post_attachment.json b/lib/xesite_types/src/testdata/post_attachment.json
new file mode 100644
index 0000000..4c4ba7c
--- /dev/null
+++ b/lib/xesite_types/src/testdata/post_attachment.json
@@ -0,0 +1,62 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ {
+ "ostatus": "http://ostatus.org#",
+ "atomUri": "ostatus:atomUri",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "conversation": "ostatus:conversation",
+ "sensitive": "as:sensitive",
+ "toot": "http://joinmastodon.org/ns#",
+ "votersCount": "toot:votersCount",
+ "blurhash": "toot:blurhash",
+ "focalPoint": {
+ "@container": "@list",
+ "@id": "toot:focalPoint"
+ }
+ }
+ ],
+ "id": "https://pony.social/users/cadey/statuses/109122208862903363",
+ "type": "Note",
+ "summary": null,
+ "inReplyTo": null,
+ "published": "2022-10-06T16:12:47Z",
+ "url": "https://pony.social/@cadey/109122208862903363",
+ "attributedTo": "https://pony.social/users/cadey",
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "cc": [
+ "https://pony.social/users/cadey/followers"
+ ],
+ "sensitive": false,
+ "atomUri": "https://pony.social/users/cadey/statuses/109122208862903363",
+ "inReplyToAtomUri": null,
+ "conversation": "tag:pony.social,2022-10-06:objectId=5615742:objectType=Conversation",
+ "content": "<p>Normal human hands</p>",
+ "contentMap": {
+ "en": "<p>Normal human hands</p>"
+ },
+ "attachment": [
+ {
+ "type": "Document",
+ "mediaType": "image/png",
+ "url": "https://cdn.pony.social/file/tscs37-pony-social/media_attachments/files/109/122/208/408/843/969/original/0bb50ba4b067e8dd.png",
+ "name": null,
+ "blurhash": "UKLVj$9?CjIq$]Y4Q-VuE14:}@My58RRr@T0",
+ "width": 512,
+ "height": 768
+ }
+ ],
+ "tag": [],
+ "replies": {
+ "id": "https://pony.social/users/cadey/statuses/109122208862903363/replies",
+ "type": "Collection",
+ "first": {
+ "type": "CollectionPage",
+ "next": "https://pony.social/users/cadey/statuses/109122208862903363/replies?only_other_accounts=true&page=true",
+ "partOf": "https://pony.social/users/cadey/statuses/109122208862903363/replies",
+ "items": []
+ }
+ }
+}
diff --git a/lib/xesite_types/src/testdata/post_hashtags.json b/lib/xesite_types/src/testdata/post_hashtags.json
new file mode 100644
index 0000000..5be859d
--- /dev/null
+++ b/lib/xesite_types/src/testdata/post_hashtags.json
@@ -0,0 +1,59 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ {
+ "ostatus": "http://ostatus.org#",
+ "atomUri": "ostatus:atomUri",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "conversation": "ostatus:conversation",
+ "sensitive": "as:sensitive",
+ "toot": "http://joinmastodon.org/ns#",
+ "votersCount": "toot:votersCount",
+ "Hashtag": "as:Hashtag"
+ }
+ ],
+ "id": "https://pony.social/users/cadey/statuses/109133556398059513",
+ "type": "Note",
+ "summary": null,
+ "inReplyTo": null,
+ "published": "2022-10-08T16:18:36Z",
+ "url": "https://pony.social/@cadey/109133556398059513",
+ "attributedTo": "https://pony.social/users/cadey",
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "cc": [
+ "https://pony.social/users/cadey/followers"
+ ],
+ "sensitive": false,
+ "atomUri": "https://pony.social/users/cadey/statuses/109133556398059513",
+ "inReplyToAtomUri": null,
+ "conversation": "tag:pony.social,2022-10-08:objectId=5625805:objectType=Conversation",
+ "content": "<p><a href=\"https://pony.social/tags/yolo\" class=\"mention hashtag\" rel=\"tag\">#<span>yolo</span></a> <a href=\"https://pony.social/tags/swag\" class=\"mention hashtag\" rel=\"tag\">#<span>swag</span></a></p>",
+ "contentMap": {
+ "en": "<p><a href=\"https://pony.social/tags/yolo\" class=\"mention hashtag\" rel=\"tag\">#<span>yolo</span></a> <a href=\"https://pony.social/tags/swag\" class=\"mention hashtag\" rel=\"tag\">#<span>swag</span></a></p>"
+ },
+ "attachment": [],
+ "tag": [
+ {
+ "type": "Hashtag",
+ "href": "https://pony.social/tags/yolo",
+ "name": "#yolo"
+ },
+ {
+ "type": "Hashtag",
+ "href": "https://pony.social/tags/swag",
+ "name": "#swag"
+ }
+ ],
+ "replies": {
+ "id": "https://pony.social/users/cadey/statuses/109133556398059513/replies",
+ "type": "Collection",
+ "first": {
+ "type": "CollectionPage",
+ "next": "https://pony.social/users/cadey/statuses/109133556398059513/replies?only_other_accounts=true&page=true",
+ "partOf": "https://pony.social/users/cadey/statuses/109133556398059513/replies",
+ "items": []
+ }
+ }
+}
diff --git a/lib/xesite_types/src/testdata/post_mention.json b/lib/xesite_types/src/testdata/post_mention.json
new file mode 100644
index 0000000..c4473bd
--- /dev/null
+++ b/lib/xesite_types/src/testdata/post_mention.json
@@ -0,0 +1,54 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ {
+ "ostatus": "http://ostatus.org#",
+ "atomUri": "ostatus:atomUri",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "conversation": "ostatus:conversation",
+ "sensitive": "as:sensitive",
+ "toot": "http://joinmastodon.org/ns#",
+ "votersCount": "toot:votersCount"
+ }
+ ],
+ "id": "https://pony.social/users/robocadey/statuses/109133487137738104",
+ "type": "Note",
+ "summary": null,
+ "inReplyTo": null,
+ "published": "2022-10-08T16:00:59Z",
+ "url": "https://pony.social/@robocadey/109133487137738104",
+ "attributedTo": "https://pony.social/users/robocadey",
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "cc": [
+ "https://pony.social/users/robocadey/followers",
+ "https://pony.social/users/cadey"
+ ],
+ "sensitive": false,
+ "atomUri": "https://pony.social/users/robocadey/statuses/109133487137738104",
+ "inReplyToAtomUri": null,
+ "conversation": "tag:pony.social,2022-10-08:objectId=5625572:objectType=Conversation",
+ "content": "<p>Beep boop! I am Robocadey, a robotic shitposting accessory. I am owned by <span class=\"h-card\"><a href=\"https://pony.social/@cadey\" class=\"u-url mention\">@<span>cadey</span></a></span> and will occasionally brighten your day with new wisdom.</p>",
+ "contentMap": {
+ "en": "<p>Beep boop! I am Robocadey, a robotic shitposting accessory. I am owned by <span class=\"h-card\"><a href=\"https://pony.social/@cadey\" class=\"u-url mention\">@<span>cadey</span></a></span> and will occasionally brighten your day with new wisdom.</p>"
+ },
+ "attachment": [],
+ "tag": [
+ {
+ "type": "Mention",
+ "href": "https://pony.social/users/cadey",
+ "name": "@cadey"
+ }
+ ],
+ "replies": {
+ "id": "https://pony.social/users/robocadey/statuses/109133487137738104/replies",
+ "type": "Collection",
+ "first": {
+ "type": "CollectionPage",
+ "next": "https://pony.social/users/robocadey/statuses/109133487137738104/replies?only_other_accounts=true&page=true",
+ "partOf": "https://pony.social/users/robocadey/statuses/109133487137738104/replies",
+ "items": []
+ }
+ }
+}
diff --git a/lib/xesite_types/src/testdata/robocadey.json b/lib/xesite_types/src/testdata/robocadey.json
new file mode 100644
index 0000000..3ef6f40
--- /dev/null
+++ b/lib/xesite_types/src/testdata/robocadey.json
@@ -0,0 +1,97 @@
+{
+ "@context": [
+ "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",
+ "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"
+ }
+ }
+ ],
+ "id": "https://pony.social/users/robocadey",
+ "type": "Service",
+ "following": "https://pony.social/users/robocadey/following",
+ "followers": "https://pony.social/users/robocadey/followers",
+ "inbox": "https://pony.social/users/robocadey/inbox",
+ "outbox": "https://pony.social/users/robocadey/outbox",
+ "featured": "https://pony.social/users/robocadey/collections/featured",
+ "featuredTags": "https://pony.social/users/robocadey/collections/tags",
+ "preferredUsername": "robocadey",
+ "name": "Robocadey",
+ "summary": "<p>Owned by <span class=\"h-card\"><a href=\"https://pony.social/@cadey\" class=\"u-url mention\">@<span>cadey</span></a></span>.</p><p>Toots GPT-2 generated shitposts from @theprincessxena@twitter.com tweets along with images created with Waifu Diffusion v1.3</p>",
+ "url": "https://pony.social/@robocadey",
+ "manuallyApprovesFollowers": false,
+ "discoverable": false,
+ "published": "2022-10-08T00:00:00Z",
+ "devices": "https://pony.social/users/robocadey/collections/devices",
+ "publicKey": {
+ "id": "https://pony.social/users/robocadey#main-key",
+ "owner": "https://pony.social/users/robocadey",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvIn1CxWOEh/EotQa1FED\nZvVPw2DxmmL48eZrE8xoWoBD7APi/oUk5EKITDMlLYWNb2rECX7FrunPP3f/lXPC\nkJvMIimQxBWX8IFxl1alVbwNYfwBjtLHUl5ZBqNFhWUAaauMVxkSSrpEgJUzJmea\nsJD1z9nm7R9jppNGdnUIz/gsO9DvC0kN0YlfLchbtfYIqqctSMHbOPyVcw5/xho/\nH6wAv9SEM/1ETQXPVXRdI7W/yN+9cituoB4NdQdOMtsBeo7c7/qH9WFOlTTA4N39\nTCRqYmvexaOmlDxKDmctJFLdT3noar3hHP3b/ICjbcvMNSBN1H0rs6n8GZMgzvQx\nnwIDAQAB\n-----END PUBLIC KEY-----\n"
+ },
+ "tag": [],
+ "attachment": [],
+ "endpoints": {
+ "sharedInbox": "https://pony.social/inbox"
+ },
+ "icon": {
+ "type": "Image",
+ "mediaType": "image/png",
+ "url": "https://cdn.pony.social/file/tscs37-pony-social/accounts/avatars/109/133/463/176/529/998/original/7231b4900b06513d.png"
+ },
+ "image": {
+ "type": "Image",
+ "mediaType": "image/png",
+ "url": "https://cdn.pony.social/file/tscs37-pony-social/accounts/headers/109/133/463/176/529/998/original/ece50a6e21c9d773.png"
+ }
+}