aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commands/auth.rs20
-rw-r--r--src/commands/mod.rs2
-rw-r--r--src/main.rs28
-rw-r--r--src/tw/mod.rs3
4 files changed, 36 insertions, 17 deletions
diff --git a/src/commands/auth.rs b/src/commands/auth.rs
index 0743d4e..db3a143 100644
--- a/src/commands/auth.rs
+++ b/src/commands/auth.rs
@@ -94,13 +94,23 @@ fn pin(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
if tweeter.curr_profile.is_none() {
tweeter.curr_profile = Some("default".to_owned());
}
- tweeter.add_profile(tw::TwitterProfile::new(tw::Credential {
+ let user_credential = tw::Credential {
key: as_map["oauth_token"].to_owned(),
secret: as_map["oauth_token_secret"].to_owned()
- }, tw::user::User::default()), Some("default".to_owned()));
- tweeter.WIP_auth = None;
- tweeter.state = tw::AppState::Reconnect;
- tweeter.display_info.status("Looks like you authed! Connecting...".to_owned());
+ };
+
+ match queryer.do_api_get(::ACCOUNT_SETTINGS_URL, &tweeter.app_key, &user_credential) {
+ Ok(settings) => {
+ let user_handle = settings["screen_name"].as_str().unwrap().to_owned();
+ tweeter.add_profile(tw::TwitterProfile::new(user_credential, tw::user::User::default()), Some(user_handle.clone()));
+ tweeter.WIP_auth = None;
+ tweeter.state = tw::AppState::Reconnect(user_handle);
+ tweeter.display_info.status("Looks like you authed! Connecting...".to_owned());
+ },
+ Err(_) => {
+ tweeter.display_info.status("Auth failed - couldn't find your handle.".to_owned());
+ }
+ };
},
Err(_) =>
tweeter.display_info.status("couldn't rebuild url".to_owned())
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index e8efdb1..3404470 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -19,8 +19,10 @@ pub mod quit;
pub mod fav;
pub mod follow;
pub mod thread;
+pub mod profile;
pub static COMMANDS: &[&Command] = &[
+ &profile::PROFILE,
&help::HELP,
&auth::AUTH,
&auth::PIN,
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());
diff --git a/src/tw/mod.rs b/src/tw/mod.rs
index dc91cdd..b81fa52 100644
--- a/src/tw/mod.rs
+++ b/src/tw/mod.rs
@@ -23,10 +23,11 @@ use self::tweet::Tweet;
pub mod user;
use self::user::User;
+#[derive(Clone)]
pub enum AppState {
Shutdown,
ShowHelp,
- Reconnect,
+ Reconnect(String),
Compose,
View
}