From f8d53de1fea82a4fa5698a6d5501ca34a0677d65 Mon Sep 17 00:00:00 2001 From: Andy Wortman Date: Wed, 15 Nov 2017 23:17:57 -0800 Subject: move line wrapping into render_twete this is, hopefully, the start of support for correctly wrapping lines with ANSI control codes included. additionally, hopefully the start of supporting coloring @'s in tweets. --- src/tw/tweet.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/tw/tweet.rs') diff --git a/src/tw/tweet.rs b/src/tw/tweet.rs index dc89774..38b838d 100644 --- a/src/tw/tweet.rs +++ b/src/tw/tweet.rs @@ -1,5 +1,7 @@ extern crate serde_json; +use std::collections::HashMap; + use tw::user::User; #[derive(Debug, Serialize, Deserialize, Clone)] @@ -8,6 +10,9 @@ pub struct Tweet { pub author_id: String, pub text: String, pub created_at: String, // lol + #[serde(skip_serializing_if="HashMap::is_empty")] + #[serde(default = "HashMap::default")] + pub urls: HashMap, #[serde(skip_serializing_if="Option::is_none")] #[serde(default = "Option::default")] pub quoted_tweet_id: Option, @@ -50,6 +55,10 @@ impl Tweet { } pub fn from_json(json: serde_json::Value) -> Result { if let serde_json::Value::Object(json_map) = json { + let mut url_map: HashMap = HashMap::new(); + for entry in json_map["entities"]["urls"].as_array().unwrap() { + url_map.insert(entry["url"].as_str().unwrap().to_owned(), entry["expanded_url"].as_str().unwrap().to_owned()); + } let text = ::tw::full_twete_text(&json_map); let rt_twete = json_map.get("retweeted_status") .and_then(|x| x.get("id_str")) @@ -75,6 +84,7 @@ impl Tweet { author_id: author_id.to_owned(), text: text, created_at: created_at.to_owned(), + urls: url_map, quoted_tweet_id: json_map.get("quoted_status_id_str") .and_then(|x| x.as_str()) .map(|x| x.to_owned()), -- cgit v1.1