From e4925f0311574cd954909695bb587902179f8680 Mon Sep 17 00:00:00 2001 From: Andy Wortman Date: Sat, 25 Nov 2017 18:39:04 -0800 Subject: extract DisplayInfo from TwitterCache what a mess... threading this through to any point where printing happens is upsetting. probably should be a global mutable behind accessors. --- src/commands/fav.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/commands/fav.rs') diff --git a/src/commands/fav.rs b/src/commands/fav.rs index e823618..0bee8ce 100644 --- a/src/commands/fav.rs +++ b/src/commands/fav.rs @@ -1,3 +1,4 @@ +use display::DisplayInfo; use tw; use ::Queryer; @@ -16,25 +17,25 @@ pub static UNFAV: Command = Command { help_str: "Unfavorite a tweet." }; -fn unfav(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { +fn unfav(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer, display_info: &mut DisplayInfo) { let maybe_id = TweetId::parse(line.to_owned()); match maybe_id { Ok(twid) => { - if let Some(twete) = tweeter.retrieve_tweet(&twid).map(|x| x.clone()) { // TODO: no clone when this stops taking &mut self + if let Some(twete) = tweeter.retrieve_tweet(&twid, display_info).map(|x| x.clone()) { // TODO: no clone when this stops taking &mut self let result = match tweeter.current_profile() { Some(user_profile) => queryer.do_api_post(&format!("{}?id={}", UNFAV_TWEET_URL, twete.id), &tweeter.app_key, &user_profile.creds), None => Err("No logged in user to unfav from".to_owned()) }; match result { Ok(_) => (), - Err(e) => tweeter.display_info.status(e) + Err(e) => display_info.status(e) } } else { - tweeter.display_info.status(format!("No tweet for id: {:?}", twid)); + display_info.status(format!("No tweet for id: {:?}", twid)); } } Err(e) => { - tweeter.display_info.status(format!("Invalid id: {}", e)); + display_info.status(format!("Invalid id: {}", e)); } } } @@ -47,26 +48,26 @@ pub static FAV: Command = Command { help_str: "Favorite a tweet." }; -fn fav(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { +fn fav(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer, display_info: &mut DisplayInfo) { let maybe_id = TweetId::parse(line.to_owned()); match maybe_id { Ok(twid) => { // tweeter.to_twitter_tweet_id(twid)... - if let Some(twete) = tweeter.retrieve_tweet(&twid).map(|x| x.clone()) { // TODO: no clone when this stops taking &mut self + if let Some(twete) = tweeter.retrieve_tweet(&twid, display_info).map(|x| x.clone()) { // TODO: no clone when this stops taking &mut self let result = match tweeter.current_profile() { Some(user_profile) => queryer.do_api_post(&format!("{}?id={}", FAV_TWEET_URL, twete.id), &tweeter.app_key, &user_profile.creds), None => Err("No logged in user to fav from".to_owned()) }; match result { Ok(_) => (), - Err(e) => tweeter.display_info.status(e) + Err(e) => display_info.status(e) } } else { - tweeter.display_info.status(format!("No tweet for id: {:?}", twid)); + display_info.status(format!("No tweet for id: {:?}", twid)); } } Err(e) => { - tweeter.display_info.status(format!("Invalid id: {}", e)); + display_info.status(format!("Invalid id: {}", e)); } } } -- cgit v1.1