diff options
| author | Andy Wortman <ixineeringeverywhere@gmail.com> | 2017-11-15 23:17:57 -0800 | 
|---|---|---|
| committer | Andy Wortman <ixineeringeverywhere@gmail.com> | 2017-11-15 23:17:57 -0800 | 
| commit | f8d53de1fea82a4fa5698a6d5501ca34a0677d65 (patch) | |
| tree | e9391245af9a8c03827270ae5301b0c325a1e2e6 /src/tw/tweet.rs | |
| parent | 66cb9a132ca6d61a2d6a5874ea3aaf14a812f948 (diff) | |
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.
Diffstat (limited to 'src/tw/tweet.rs')
| -rw-r--r-- | src/tw/tweet.rs | 10 | 
1 files changed, 10 insertions, 0 deletions
| 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<String, String>,      #[serde(skip_serializing_if="Option::is_none")]      #[serde(default = "Option::default")]      pub quoted_tweet_id: Option<String>, @@ -50,6 +55,10 @@ impl Tweet {      }      pub fn from_json(json: serde_json::Value) -> Result<Tweet, String> {          if let serde_json::Value::Object(json_map) = json { +            let mut url_map: HashMap<String, String> = 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()), | 
