aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2024-10-30 10:01:12 +0100
committerHarald Eilertsen <haraldei@anduin.net>2024-10-30 10:01:12 +0100
commit7c680c033a4323be13a769f380f186677d1f89ba (patch)
tree3b73c2ef8ed5a5eae6d516d34362ff71fd5dc7e9 /src
parentf17b2afb3b812c1babad1602f13c35977b8e7701 (diff)
downloadrust-zotapi-7c680c033a4323be13a769f380f186677d1f89ba.tar.gz
rust-zotapi-7c680c033a4323be13a769f380f186677d1f89ba.tar.bz2
rust-zotapi-7c680c033a4323be13a769f380f186677d1f89ba.zip
stream::Activity: Add object_type field and update methods.
Diffstat (limited to 'src')
-rw-r--r--src/stream/activity.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/stream/activity.rs b/src/stream/activity.rs
index 6020558..c247477 100644
--- a/src/stream/activity.rs
+++ b/src/stream/activity.rs
@@ -29,6 +29,11 @@ pub enum ActivityEncoding {
}
#[derive(Debug, Deserialize, PartialEq)]
+pub enum ObjectType {
+ Note,
+}
+
+#[derive(Debug, Deserialize, PartialEq)]
#[serde(rename_all="snake_case")]
pub enum ActivityFlag {
Direct,
@@ -63,6 +68,7 @@ pub struct Activity {
pub commented: DateTime,
pub verb: Verb,
+ pub object_type: ObjectType,
pub title: String,
pub summary: String,
@@ -78,7 +84,17 @@ pub struct Activity {
impl Activity {
pub fn is_post(&self) -> bool {
- self.verb == Verb::Post
+ self.verb == Verb::Create
+ && self.object_type == ObjectType::Note
+ && self.has_flag(ActivityFlag::ThreadParent)
+ }
+
+ pub fn has_flag(&self, flag: ActivityFlag) -> bool {
+ self.flags
+ .as_ref()
+ .map_or(
+ false,
+ |flags| flags.iter().find( |f| *f == &flag ).is_some())
}
}
@@ -181,6 +197,9 @@ 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!(ActivityFlag::ThreadParent, item.flags.as_ref().unwrap()[0]);
+ assert_eq!(ObjectType::Note, item.object_type);
+
+ assert_eq!(true, item.has_flag(ActivityFlag::ThreadParent));
+ assert_eq!(true, item.is_post());
}
}