diff options
author | Andy Wortman <ixineeringeverywhere@gmail.com> | 2017-11-19 03:27:59 -0800 |
---|---|---|
committer | Andy Wortman <ixineeringeverywhere@gmail.com> | 2017-11-19 03:27:59 -0800 |
commit | fb6974bca8878726330e2cc460e0c1ff2def1a99 (patch) | |
tree | 2c15568ea02c682de71aa4e9193ac0b8748d32e1 /src/main.rs | |
parent | 1de0593b707540b4c1bd03f2c0a151281a893be6 (diff) |
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.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 28 |
1 files changed, 17 insertions, 11 deletions
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::<Vec<u8>>(0); + let (twete_tx, mut twete_rx) = chan::sync::<Vec<u8>>(0); let (coordination_tx, mut coordination_rx) = chan::sync::<TwitterConnectionState>(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<u8>, mut tweeter: &mut tw::TwitterCache, mut qu fn do_ui( ui_rx_orig: chan::Receiver<Result<termion::event::Event, std::io::Error>>, twete_rx: chan::Receiver<Vec<u8>>, + twete_tx: &chan::Sender<Vec<u8>>, coordination_rx: chan::Receiver<TwitterConnectionState>, + coordination_tx: &chan::Sender<TwitterConnectionState>, mut tweeter: &mut tw::TwitterCache, mut queryer: &mut ::Queryer ) -> Option<(chan::Receiver<Result<termion::event::Event, std::io::Error>>, chan::Receiver<Vec<u8>>, chan::Receiver<TwitterConnectionState>)> { @@ -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<String> = 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()); |