From fb6974bca8878726330e2cc460e0c1ff2def1a99 Mon Sep 17 00:00:00 2001 From: Andy Wortman Date: Sun, 19 Nov 2017 03:27:59 -0800 Subject: support reconnecting specific profiles, switching profiles open issues: something is wrong with loading settings - something gets replayed from main account to alternate accounts. auth'ing a new account doesn't set handle, name, etc. i think most issue are because events aren't recorded with what connection they came from - welcome event for any account gets replayed onto curr_profile because we simply don't know which connection the event was from. the same will happen for twitter events, but those aren't logged. --- src/main.rs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index cd15ea9..b9bf27d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -210,14 +210,12 @@ fn main() { tweeter.display_info.status("Cache loaded".to_owned()); - let (tweet_tx, mut twete_rx) = chan::sync::>(0); + let (twete_tx, mut twete_rx) = chan::sync::>(0); let (coordination_tx, mut coordination_rx) = chan::sync::(0); - tweeter.current_profile() - .map(|user_profile| user_profile.to_owned()) - .map(|user_profile| { - connect_twitter_stream(tweeter.app_key.clone(), user_profile.creds, tweet_tx.clone(), coordination_tx.clone(), get_id()); - }); + for (ref profile_name, ref profile) in &tweeter.profiles { + connect_twitter_stream(tweeter.app_key.clone(), profile.creds.clone(), twete_tx.clone(), coordination_tx.clone(), get_id()); + } std::thread::spawn(move || { for input in stdin().events() { @@ -252,7 +250,7 @@ fn main() { }; loop { - match do_ui(ui_rx, twete_rx, coordination_rx, &mut tweeter, &mut queryer) { + match do_ui(ui_rx, twete_rx, &twete_tx, coordination_rx, &coordination_tx, &mut tweeter, &mut queryer) { Some((new_ui_rx, new_twete_rx, new_coordination_rx)) => { ui_rx = new_ui_rx; twete_rx = new_twete_rx; @@ -379,7 +377,9 @@ fn handle_twitter_line(line: Vec, mut tweeter: &mut tw::TwitterCache, mut qu fn do_ui( ui_rx_orig: chan::Receiver>, twete_rx: chan::Receiver>, + twete_tx: &chan::Sender>, coordination_rx: chan::Receiver, + coordination_tx: &chan::Sender, mut tweeter: &mut tw::TwitterCache, mut queryer: &mut ::Queryer ) -> Option<(chan::Receiver>, chan::Receiver>, chan::Receiver)> { @@ -411,7 +411,7 @@ fn do_ui( Err(e) => println!("{}", e) // TODO: we got here because writing to stdout failed. what to do now? }; - match tweeter.state { + match tweeter.state.clone() { tw::AppState::ShowHelp => { let mut help_lines: Vec = vec![ " Tweets", @@ -439,10 +439,16 @@ fn do_ui( display::paint(tweeter).unwrap(); tweeter.state = tw::AppState::View; } - tw::AppState::Reconnect => { + tw::AppState::Reconnect(profile_name) => { tweeter.state = tw::AppState::View; - // TODO: reconnect *which*? - return None // Some((ui_rx_orig.clone(), tweeter.profile.clone().map(|creds| connect_twitter_stream(tweeter.app_key.clone(), creds)))); + match tweeter.profiles.get(&profile_name).map(|profile| profile.creds.to_owned()) { + Some(user_creds) => { + connect_twitter_stream(tweeter.app_key.clone(), user_creds, twete_tx.clone(), coordination_tx.clone(), get_id()) + }, + None => { + tweeter.display_info.status(format!("No profile named {}", profile_name)); + } + } }, tw::AppState::Shutdown => { tweeter.display_info.status("Saving cache...".to_owned()); -- cgit v1.1