aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commands/auth.rs18
-rw-r--r--src/tw/mod.rs58
2 files changed, 63 insertions, 13 deletions
diff --git a/src/commands/auth.rs b/src/commands/auth.rs
index 65dcaf5..0743d4e 100644
--- a/src/commands/auth.rs
+++ b/src/commands/auth.rs
@@ -78,10 +78,26 @@ fn pin(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
}
// turns out the "actual" oauth creds are different
// TODO: profile names?
+ /*
+ * Option 1:
+ * ask user.
+ * yes, but I want this to be optional though (auth, pin 1234, profile now
+ * named main or after you or something)
+ * Option 2:
+ * make a request for profile settings when auth succeeds
+ * this becomes the fallback when nothing is provided in option 1
+ * what happens when you successfully auth, internet drops, and you fail to
+ * request settings?
+ *
+ * fallback to asking user to name the profile, i guess?
+ */
+ if tweeter.curr_profile.is_none() {
+ tweeter.curr_profile = Some("default".to_owned());
+ }
tweeter.add_profile(tw::TwitterProfile::new(tw::Credential {
key: as_map["oauth_token"].to_owned(),
secret: as_map["oauth_token_secret"].to_owned()
- }, tw::user::User::default()), Some("iximeow".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());
diff --git a/src/tw/mod.rs b/src/tw/mod.rs
index 52ab31c..dc91cdd 100644
--- a/src/tw/mod.rs
+++ b/src/tw/mod.rs
@@ -521,10 +521,24 @@ impl TwitterCache {
let followed = json["target"]["id_str"].as_str().unwrap().to_string();
self.cache_api_user(json["target"].clone());
self.cache_api_user(json["source"].clone());
- if follower == "iximeow" {
- // self.add_follow(
- } else {
- self.add_follower(&follower);
+ match self.current_profile().map(|profile| profile.to_owned()) {
+ Some(profile) => {
+ // for now assume single client?
+ // TODO: see note below - profile origin needs to be tracked.
+ //
+ if follower == profile.user.handle {
+ // self.add_follow(
+ } else {
+ self.add_follower(&follower);
+ }
+ },
+ None => {
+ // TODO: this isn't really reachable - we'd have to be connected on some
+ // ... this will break.
+ //
+ // events need to include what profile they're associated with so we can
+ // note that for the tweet and event if applicable.
+ }
}
},
Some("unfollow") => {
@@ -532,10 +546,24 @@ impl TwitterCache {
let followed = json["target"]["id_str"].as_str().unwrap().to_string();
self.cache_api_user(json["target"].clone());
self.cache_api_user(json["source"].clone());
- if follower == "iximeow" {
- // self.add_follow(
- } else {
- self.remove_follower(&follower);
+ match self.current_profile().map(|profile| profile.to_owned()) {
+ Some(profile) => {
+ // for now assume single client?
+ // TODO: see note below - profile origin needs to be tracked.
+ //
+ if follower == profile.user.handle {
+ // self.add_follow(
+ } else {
+ self.add_follower(&follower);
+ }
+ },
+ None => {
+ // TODO: this isn't really reachable - we'd have to be connected on some
+ // ... this will break.
+ //
+ // events need to include what profile they're associated with so we can
+ // note that for the tweet and event if applicable.
+ }
}
},
Some(_) => () /* an uninteresting event */,
@@ -784,14 +812,20 @@ fn handle_twitter_welcome(
let maybe_my_name = settings["screen_name"].as_str();
if let Some(my_name) = maybe_my_name {
// TODO: come back to this when custom profile names are supported?
- tweeter.curr_profile = Some(my_name.to_owned());
+// tweeter.curr_profile = Some(my_name.to_owned());
tweeter.display_info.status(format!("You are {}", my_name))
} else {
tweeter.display_info.status("Unable to make API call to figure out who you are...".to_string());
}
- let followers = tweeter.get_followers(queryer).unwrap();
- let id_arr: Vec<String> = followers["ids"].as_array().unwrap().iter().map(|x| x.as_str().unwrap().to_owned()).collect();
- tweeter.set_followers(id_arr);
+ match tweeter.get_followers(queryer) {
+ Ok(followers) => {
+ let id_arr: Vec<String> = followers["ids"].as_array().unwrap().iter().map(|x| x.as_str().unwrap().to_owned()).collect();
+ tweeter.set_followers(id_arr);
+ },
+ Err(e) => {
+ tweeter.display_info.status(e);
+ }
+ }
}
pub fn handle_message(