aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wortman <ixineeringeverywhere@gmail.com>2017-10-02 01:27:41 -0700
committerAndy Wortman <ixineeringeverywhere@gmail.com>2017-10-02 02:32:46 -0700
commitfe80b29ca03ed5e4462800804f33ecc00e1f880f (patch)
treeb6dda082bbdbcfabebf426ba3cec41af0cb550f1
parentea4e93f01d9e4ef17effae1e9a807bb1977865fe (diff)
store and show reply_to info if present
-rw-r--r--src/display/mod.rs33
-rw-r--r--src/main.rs6
-rw-r--r--src/tw/tweet.rs7
3 files changed, 38 insertions, 8 deletions
diff --git a/src/display/mod.rs b/src/display/mod.rs
index 24f7e33..e66ac77 100644
--- a/src/display/mod.rs
+++ b/src/display/mod.rs
@@ -102,8 +102,15 @@ pub fn render_twete(twete_id: &String, tweeter: &tw::TwitterCache) {
let rt = tweeter.retrieve_tweet(rt_id).unwrap();
// and its author
let rt_author = tweeter.retrieve_user(&rt.author_id).unwrap();
- println!("{} id:{} (rt_id:{}){}",
- id_color, rt.internal_id, twete.internal_id, color::Fg(color::Reset)
+ println!("{} id:{} (rt_id:{}){}{}",
+ id_color, rt.internal_id, twete.internal_id,
+ rt.reply_to_tweet.clone()
+ .map(|id| tweeter.retrieve_tweet(&id)
+ .and_then(|tw| Some(format!(" reply_to:{}", tw.internal_id)))
+ .unwrap_or(format!(" reply_to:twitter::{}", id))
+ )
+ .unwrap_or("".to_string()),
+ color::Fg(color::Reset)
);
println!(" {}{}{} ({}@{}{}) via {}{}{} ({}@{}{}) RT:",
color_for(&rt_author.handle), rt_author.name, color::Fg(color::Reset),
@@ -113,8 +120,15 @@ pub fn render_twete(twete_id: &String, tweeter: &tw::TwitterCache) {
);
}
None => {
- println!("{} id:{}{}",
- id_color, twete.internal_id, color::Fg(color::Reset)
+ println!("{} id:{}{}{}",
+ id_color, twete.internal_id,
+ twete.reply_to_tweet.clone()
+ .map(|id| tweeter.retrieve_tweet(&id)
+ .and_then(|tw| Some(format!(" reply_to:{}", tw.internal_id)))
+ .unwrap_or(format!(" reply_to:twitter::{}", id))
+ )
+ .unwrap_or("".to_string()),
+ color::Fg(color::Reset)
);
println!(" {}{}{} ({}@{}{})",
color_for(&user.handle), user.name, color::Fg(color::Reset),
@@ -128,8 +142,15 @@ pub fn render_twete(twete_id: &String, tweeter: &tw::TwitterCache) {
if let Some(ref qt_id) = twete.quoted_tweet_id {
if let Some(ref qt) = tweeter.retrieve_tweet(qt_id) {
let qt_author = tweeter.retrieve_user(&qt.author_id).unwrap();
- println!("{} id:{}{}",
- id_color, qt.internal_id, color::Fg(color::Reset)
+ println!("{} id:{}{}{}",
+ id_color, qt.internal_id,
+ qt.reply_to_tweet.clone()
+ .map(|id| tweeter.retrieve_tweet(&id)
+ .and_then(|tw| Some(format!(" reply_to:{}", tw.internal_id)))
+ .unwrap_or(format!(" reply_to:twitter::{}", id))
+ )
+ .unwrap_or("".to_string()),
+ color::Fg(color::Reset)
);
println!(
" {}{}{} ({}@{}{})",
diff --git a/src/main.rs b/src/main.rs
index 37082a1..820bcb1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -319,8 +319,10 @@ fn parse_word_command<'a, 'b>(line: &'b str, commands: &[&'a Command]) -> Option
return Some(("", &cmd));
}
} else if line.starts_with(cmd.keyword) {
- // let inner_twid = u64::from_str(&linestr.split(" ").collect::<Vec<&str>>()[1]).unwrap();
- return Some((line.get((cmd.keyword.len() + 1)..).unwrap().trim(), &cmd));
+ if line.find(" ").map(|x| x == cmd.keyword.len()).unwrap_or(false) {
+ // let inner_twid = u64::from_str(&linestr.split(" ").collect::<Vec<&str>>()[1]).unwrap();
+ return Some((line.get((cmd.keyword.len() + 1)..).unwrap().trim(), &cmd));
+ }
}
}
return None
diff --git a/src/tw/tweet.rs b/src/tw/tweet.rs
index 778461a..aa272d6 100644
--- a/src/tw/tweet.rs
+++ b/src/tw/tweet.rs
@@ -14,6 +14,9 @@ pub struct Tweet {
#[serde(skip_serializing_if="Option::is_none")]
#[serde(default = "Option::default")]
pub rt_tweet: Option<String>,
+ #[serde(skip_serializing_if="Option::is_none")]
+ #[serde(default = "Option::default")]
+ pub reply_to_tweet: Option<String>,
#[serde(skip)]
pub internal_id: u64
}
@@ -47,6 +50,9 @@ impl Tweet {
.and_then(|x| x.get("id_str"))
.and_then(|x| x.as_str())
.map(|x| x.to_owned());
+ let reply_to_tweet = json_map.get("in_reply_to_status_id_str")
+ .and_then(|x| x.as_str())
+ .map(|x| x.to_owned());
if json_map.contains_key("id_str") &&
json_map.contains_key("user") &&
json_map.contains_key("created_at") {
@@ -68,6 +74,7 @@ impl Tweet {
.and_then(|x| x.as_str())
.map(|x| x.to_owned()),
rt_tweet: rt_twete,
+ reply_to_tweet: reply_to_tweet,
internal_id: 0
})
}