aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wortman <ixineeringeverywhere@gmail.com>2017-12-01 01:48:32 -0800
committerAndy Wortman <ixineeringeverywhere@gmail.com>2017-12-01 01:48:32 -0800
commitbbe0e891a7cbb0708e2689b8123bb65a6d8ac7e0 (patch)
tree6e13adb9cbab7b5fd8d5635d25c01f3c7a027ce9
parent8ad1d470a11dfe99d28a4f5228a3fef335f692d1 (diff)
display locked and protected as applicable
-rw-r--r--src/display/mod.rs16
-rw-r--r--src/tw/user.rs22
2 files changed, 31 insertions, 7 deletions
diff --git a/src/display/mod.rs b/src/display/mod.rs
index 4a0f198..c3c4692 100644
--- a/src/display/mod.rs
+++ b/src/display/mod.rs
@@ -632,6 +632,14 @@ fn pad_lines(lines: Vec<String>, padding: &str) -> Vec<String> {
lines.into_iter().map(|x| format!("{}{}", padding, x)).collect()
}
+fn short_display_summary(u: &tw::user::User) -> String {
+ format!("{}{}{} ({}@{}{}{})",
+ color_for(&u.handle), u.name, color::Fg(color::Reset),
+ color_for(&u.handle), u.handle, color::Fg(color::Reset),
+ if u.verified { format!(" {}✔️{}", color::Fg(color::Blue), color::Fg(color::Reset)) } else { "".to_owned() }
+ )
+}
+
pub fn render_twete(twete_id: &TweetId, tweeter: &tw::TwitterCache, display_info: &mut DisplayInfo, width: Option<u16>) -> Vec<String> {
let mut lines = render_twete_no_recurse(twete_id, tweeter, display_info, width);
match tweeter.retrieve_tweet(twete_id).map(|x| x.clone()) {
@@ -678,7 +686,11 @@ pub fn render_twete_no_recurse(twete_id: &TweetId, tweeter: &tw::TwitterCache, d
// of the retweeter tweet if it's there
let mut id_string = format!("{}id {}", id_color, tweet_id);
- let mut author_string = format!("{}{}{} ({}@{}{})", color_for(&tweet_author.handle), tweet_author.name, color::Fg(color::Reset), color_for(&tweet_author.handle), tweet_author.handle, color::Fg(color::Reset));
+ let mut author_string = short_display_summary(&tweet_author);
+
+ if tweet_author.protected {
+ id_string.push_str(&format!(" {}locked{}", termion::style::Underline, termion::style::Reset));
+ }
if let Some(reply_id) = tweet.reply_to_tweet.clone() {
let reply_tweet_id = tweeter.display_id_for_tweet_id(&TweetId::Twitter(reply_id.to_owned()));
@@ -690,7 +702,7 @@ pub fn render_twete_no_recurse(twete_id: &TweetId, tweeter: &tw::TwitterCache, d
let rt_id = tweeter.display_id_for_tweet(&rt);
let rt_author = tweeter.retrieve_user(&rt.author_id).unwrap().clone();
id_string.push_str(&format!(" (rt id {})", rt_id));
- author_string.push_str(&format!(" via {}{}{} ({}@{}{}) RT", color_for(&rt_author.handle), rt_author.name, color::Fg(color::Reset), color_for(&rt_author.handle), rt_author.handle, color::Fg(color::Reset)));
+ author_string.push_str(&format!(" via {} RT", short_display_summary(&rt_author)));
}
id_string.push_str(&format!("{}", color::Fg(color::Reset)));
diff --git a/src/tw/user.rs b/src/tw/user.rs
index 86fbe3f..4fde026 100644
--- a/src/tw/user.rs
+++ b/src/tw/user.rs
@@ -4,7 +4,11 @@ extern crate serde_json;
pub struct User {
pub id: String,
pub name: String,
- pub handle: String
+ pub handle: String,
+ #[serde(default)]
+ pub protected: bool,
+ #[serde(default)]
+ pub verified: bool
}
impl Default for User {
@@ -12,7 +16,9 @@ impl Default for User {
User {
id: "".to_owned(),
name: "_default_".to_owned(),
- handle: "_default_".to_owned()
+ handle: "_default_".to_owned(),
+ protected: false,
+ verified: false
}
}
}
@@ -23,16 +29,22 @@ impl User {
if let (
Some(id_str),
Some(name),
- Some(screen_name)
+ Some(screen_name),
+ Some(protected),
+ Some(bluecheck)
) = (
json_map.get("id_str").and_then(|x| x.as_str()),
json_map.get("name").and_then(|x| x.as_str()),
- json_map.get("screen_name").and_then(|x| x.as_str())
+ json_map.get("screen_name").and_then(|x| x.as_str()),
+ json_map.get("protected").and_then(|x| x.as_bool()),
+ json_map.get("verified").and_then(|x| x.as_bool())
) {
Ok(User {
id: id_str.to_owned(),
name: name.to_owned(),
- handle: screen_name.to_owned()
+ handle: screen_name.to_owned(),
+ protected: protected.to_owned(),
+ verified: bluecheck.to_owned()
})
} else {
Err("user json missing one of id_str, name, screen_name".to_owned())