diff options
-rw-r--r-- | src/stream.rs | 10 | ||||
-rw-r--r-- | src/stream/activity.rs | 26 |
2 files changed, 18 insertions, 18 deletions
diff --git a/src/stream.rs b/src/stream.rs index 9575675..c784922 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -20,9 +20,9 @@ mod verb; pub use actor::Actor; pub use datetime::DateTime; pub use activity::{ - StreamItem, - StreamItemEncoding, - StreamItemType, + Activity, + ActivityEncoding, + ActivityType, }; pub use tag::{ Tag, @@ -37,12 +37,12 @@ use std::{ #[derive(Debug, PartialEq)] pub struct Stream { - pub items: Vec<StreamItem>, + pub items: Vec<Activity>, } impl Stream { pub fn from_json(json: &str) -> Result<Self, Box<dyn Error + 'static>> { - let items: Vec<StreamItem> = serde_json::from_str(&json)?; + let items: Vec<Activity> = serde_json::from_str(&json)?; Ok(Self { items }) } } diff --git a/src/stream/activity.rs b/src/stream/activity.rs index dd311d7..6020558 100644 --- a/src/stream/activity.rs +++ b/src/stream/activity.rs @@ -1,5 +1,5 @@ /** - * Representation of a stream item, as received from the zot api streams. + * Representation of an activity, as received from the zot api streams. * * SPDX-FileCopyrightText: 2023 Eilertsens Kodeknekkeri * SPDX-FileCopyrightText: 2023 Harald Eilertsen <haraldei@anduin.net> @@ -18,19 +18,19 @@ use uuid::Uuid; #[derive(Debug, Deserialize, PartialEq)] #[serde(rename_all="snake_case")] -pub enum StreamItemType { +pub enum ActivityType { Activity, } #[derive(Debug, Deserialize, PartialEq)] #[serde(rename_all="snake_case")] -pub enum StreamItemEncoding { +pub enum ActivityEncoding { Zot, } #[derive(Debug, Deserialize, PartialEq)] #[serde(rename_all="snake_case")] -pub enum StreamItemFlag { +pub enum ActivityFlag { Direct, Notshown, Private, @@ -41,10 +41,10 @@ pub enum StreamItemFlag { * Represents an item as returned by the stream API's. */ #[derive(Debug, Deserialize, PartialEq)] -pub struct StreamItem { +pub struct Activity { #[serde(rename="type")] - pub item_type: StreamItemType, - pub encoding: StreamItemEncoding, + pub item_type: ActivityType, + pub encoding: ActivityEncoding, pub uuid: Uuid, pub message_id: Url, @@ -72,11 +72,11 @@ pub struct StreamItem { pub author: Actor, pub signature: String, - pub flags: Option<Vec<StreamItemFlag>>, + pub flags: Option<Vec<ActivityFlag>>, pub tags: Option<Vec<Tag>>, } -impl StreamItem { +impl Activity { pub fn is_post(&self) -> bool { self.verb == Verb::Post } @@ -164,10 +164,10 @@ mod test { ] }"#; - let item: StreamItem = serde_json::from_str(&json).unwrap(); + let item: Activity = serde_json::from_str(&json).unwrap(); - assert_eq!(StreamItemType::Activity, item.item_type); - assert_eq!(StreamItemEncoding::Zot, item.encoding); + assert_eq!(ActivityType::Activity, item.item_type); + assert_eq!(ActivityEncoding::Zot, item.encoding); assert_eq!("2c102ec3-676b-4d84-b2b4-9141467a254f", item.uuid.to_string()); assert_eq!("https://example.com/item/2c102ec3-676b-4d84-b2b4-9141467a254f", item.message_id.to_string()); assert_eq!("https://example.com/item/2c102ec3-676b-4d84-b2b4-9141467a254f", item.message_top.to_string()); @@ -181,6 +181,6 @@ mod test { assert_eq!("2023-12-12 17:00:42", &item.edited.to_string()); assert_eq!("0000-00-00 00:00:00", &item.expires.to_string()); assert_eq!("2023-12-19 09:01:15", &item.commented.to_string()); - assert_eq!(StreamItemFlag::ThreadParent, item.flags.as_ref().unwrap()[0]); + assert_eq!(ActivityFlag::ThreadParent, item.flags.as_ref().unwrap()[0]); } } |