diff options
Diffstat (limited to 'src/stream/tag.rs')
-rw-r--r-- | src/stream/tag.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/stream/tag.rs b/src/stream/tag.rs index 0d2ee23..36874c2 100644 --- a/src/stream/tag.rs +++ b/src/stream/tag.rs @@ -12,13 +12,19 @@ use url::Url; #[derive(Debug, Deserialize, PartialEq)] pub enum TagType { - #[serde(rename = "hashtag")] + #[serde(alias = "hashtag")] Hashtag, + + #[serde(alias = "mention")] + Mention, } #[derive(Debug, Deserialize, PartialEq)] pub struct Tag { + #[serde(alias = "name")] tag: String, + + #[serde(alias = "href")] url: Url, #[serde(rename = "type")] @@ -44,4 +50,20 @@ mod test { assert_eq!("https://example.com/search?tag=hubzilla", tag.url.to_string()); assert_eq!(TagType::Hashtag, tag.tag_type); } + + #[test] + fn test_parsing_mention_from_json() { + let json = r#" + { + "type": "Mention", + "href": "https://example.com/channel/ben", + "name": "@ben@example.com" + } + "#; + + let tag: Tag = serde_json::from_str(json).unwrap(); + assert_eq!(TagType::Mention, tag.tag_type); + assert_eq!("https://example.com/channel/ben", tag.url.to_string()); + assert_eq!("@ben@example.com", tag.tag); + } } |