aboutsummaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/fav.rs14
-rw-r--r--src/commands/thread.rs20
-rw-r--r--src/commands/twete.rs12
-rw-r--r--src/commands/view.rs33
4 files changed, 39 insertions, 40 deletions
diff --git a/src/commands/fav.rs b/src/commands/fav.rs
index 7b9cce6..1cb41e4 100644
--- a/src/commands/fav.rs
+++ b/src/commands/fav.rs
@@ -5,8 +5,6 @@ use tw::TweetId;
use commands::Command;
-use std::str::FromStr;
-
static FAV_TWEET_URL: &str = "https://api.twitter.com/1.1/favorites/create.json";
static UNFAV_TWEET_URL: &str = "https://api.twitter.com/1.1/favorites/destroy.json";
@@ -21,12 +19,12 @@ fn unfav(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
// let inner_twid = u64::from_str(&line).unwrap();
let maybe_id = TweetId::parse(line.to_owned());
match maybe_id {
- Some(twid) => {
+ Ok(twid) => {
let twete = tweeter.retrieve_tweet(&twid).unwrap();
queryer.do_api_post(&format!("{}?id={}", UNFAV_TWEET_URL, twete.id));
}
- None => {
- println!("Invalid id: {}", line);
+ Err(e) => {
+ println!("Invalid id: {}", e);
}
}
}
@@ -41,12 +39,12 @@ fn fav(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
// TODO handle this unwrap
let maybe_id = TweetId::parse(line.to_owned());
match maybe_id {
- Some(twid) => {
+ Ok(twid) => {
let twete = tweeter.retrieve_tweet(&twid).unwrap();
queryer.do_api_post(&format!("{}?id={}", FAV_TWEET_URL, twete.id));
}
- None => {
- println!("Invalid id: {}", line);
+ Err(e) => {
+ println!("Invalid id: {}", e);
}
}
}
diff --git a/src/commands/thread.rs b/src/commands/thread.rs
index 57b410c..fd491ba 100644
--- a/src/commands/thread.rs
+++ b/src/commands/thread.rs
@@ -6,8 +6,6 @@ use tw::TweetId;
use commands::Command;
-use std::str::FromStr;
-
pub static FORGET_THREAD: Command = Command {
keyword: "forget",
params: 1,
@@ -34,13 +32,13 @@ fn remember(line: String, tweeter: &mut tw::TwitterCache, _queryer: &mut Queryer
if name.len() > 0 {
let maybe_id = TweetId::parse(line.to_owned());
match maybe_id {
- Some(twid) => {
+ Ok(twid) => {
let twete = tweeter.retrieve_tweet(&twid).unwrap().clone();
tweeter.set_thread(name.to_string(), twete.internal_id);
println!("Ok! Recorded {:?} as thread {}", twid, name);
}
- None => {
- println!("Invalid id: {}", line);
+ Err(e) => {
+ println!("Invalid id: {}", e);
}
}
}
@@ -55,12 +53,16 @@ pub static LIST_THREADS: Command = Command {
fn ls_threads(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
println!("Threads: ");
- for k in tweeter.threads() {
+ let threads: Vec<String> = tweeter.threads().collect::<Vec<&String>>().into_iter().map(|x| x.to_owned()).collect::<Vec<String>>();
+ for k in threads {
println!("Thread: {}", k);
- let latest_inner_id = tweeter.latest_in_thread(k.to_owned()).unwrap();
- if let Some(twete) = tweeter.retrieve_tweet(&TweetId::Bare(*latest_inner_id)) {
+ let latest_inner_id = tweeter.latest_in_thread(k.to_owned()).unwrap().to_owned();
+ // should be able to just directly render TweetId.. and threads should be Vec<TweetId>...
+ let twete_id_TEMP = tweeter.retrieve_tweet(&TweetId::Bare(latest_inner_id)).map(|x| x.id.to_owned());
+ if let Some(twete) = twete_id_TEMP {
// gross..
- display::render_twete(&twete.id, tweeter);
+ // and this ought to be a command to tweeter.display_info anyway...
+ display::render_twete(&TweetId::Twitter(twete), tweeter);
println!("");
} else {
println!("ERROR no tweet for remembered thread.");
diff --git a/src/commands/twete.rs b/src/commands/twete.rs
index c399df1..9f5cb0d 100644
--- a/src/commands/twete.rs
+++ b/src/commands/twete.rs
@@ -56,7 +56,7 @@ fn thread(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
let id_str = text.trim();
if reply.len() > 0 {
if let Some(inner_twid) = u64::from_str(&id_str).ok() {
- if let Some(twete) = tweeter.retrieve_tweet(&TweetId::Bare(inner_twid)) {
+ if let Some(twete) = tweeter.retrieve_tweet(&TweetId::Bare(inner_twid)).map(|x| x.clone()) {
let handle = &tweeter.retrieve_user(&twete.author_id).unwrap().handle;
// TODO: definitely breaks if you change your handle right now
if handle == &tweeter.current_user.handle {
@@ -92,7 +92,8 @@ fn rep(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
let id_str = text.trim();
if reply.len() > 0 {
if let Some(inner_twid) = u64::from_str(&id_str).ok() {
- if let Some(twete) = tweeter.retrieve_tweet(&TweetId::Bare(inner_twid)) {
+ // TODO: probably should just have Tweet impl Copy or something
+ if let Some(twete) = tweeter.retrieve_tweet(&TweetId::Bare(inner_twid)).map(|x| x.clone()) {
// get handles to reply to...
let author_handle = tweeter.retrieve_user(&twete.author_id).unwrap().handle.to_owned();
let mut ats: Vec<String> = twete.get_mentions(); //std::collections::HashSet::new();
@@ -103,13 +104,12 @@ fn rep(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
*/
ats.remove_item(&author_handle);
ats.insert(0, author_handle);
- // no idea why i have to .to_owned() here --v-- what about twete.rt_tweet is a move?
- if let Some(rt_tweet) = twete.rt_tweet.to_owned().and_then(|id| tweeter.retrieve_tweet(&TweetId::Twitter(id))) {
+ if let Some(rt_tweet) = twete.rt_tweet.and_then(|id| tweeter.retrieve_tweet(&TweetId::Twitter(id))).map(|x| x.clone()) {
let rt_author_handle = tweeter.retrieve_user(&rt_tweet.author_id).unwrap().handle.to_owned();
ats.remove_item(&rt_author_handle);
ats.insert(1, rt_author_handle);
}
- if let Some(qt_tweet) = twete.quoted_tweet_id.to_owned().and_then(|id| tweeter.retrieve_tweet(&TweetId::Twitter(id))) {
+ if let Some(qt_tweet) = twete.quoted_tweet_id.and_then(|id| tweeter.retrieve_tweet(&TweetId::Twitter(id))).map(|x| x.clone()) {
// let qt_author_handle = tweeter.retrieve_user(&qt_tweet.author_id).unwrap().handle.to_owned();
// ats.remove_item(&qt_author_handle);
// ats.insert(1, qt_author_handle);
@@ -145,7 +145,7 @@ fn quote(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
let id_str = text.trim();
if reply.len() > 0 {
if let Some(inner_twid) = u64::from_str(&id_str).ok() {
- if let Some(twete) = tweeter.retrieve_tweet(&TweetId::Bare(inner_twid)) {
+ if let Some(twete) = tweeter.retrieve_tweet(&TweetId::Bare(inner_twid)).map(|x| x.clone()) {
let substituted = ::url_encode(reply);
let attachment_url = ::url_encode(
&format!(
diff --git a/src/commands/view.rs b/src/commands/view.rs
index c14446a..e9b38ee 100644
--- a/src/commands/view.rs
+++ b/src/commands/view.rs
@@ -18,9 +18,10 @@ pub static VIEW: Command = Command {
fn view(line: String, tweeter: &mut tw::TwitterCache, _queryer: &mut Queryer) {
// TODO handle this unwrap
let inner_twid = u64::from_str(&line).unwrap();
- let twete = tweeter.retrieve_tweet(&TweetId::Bare(inner_twid)).unwrap();
- display::render_twete(&twete.id, tweeter);
- println!(" link: https://twitter.com/i/web/status/{}", twete.id);
+ let twete = tweeter.retrieve_tweet(&TweetId::Bare(inner_twid)).unwrap().clone();
+ tweeter.display_info.recv(display::Infos::Tweet(TweetId::Twitter(twete.id.to_owned())));
+// display::render_twete(&twete.id, tweeter);
+// println!(" link: https://twitter.com/i/web/status/{}", twete.id);
}
pub static VIEW_THREAD: Command = Command {
@@ -29,22 +30,20 @@ pub static VIEW_THREAD: Command = Command {
exec: view_tr
};
-fn view_tr(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
- // TODO handle this unwrap
+fn view_tr(line: String, mut tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
+ let mut thread: Vec<TweetId> = Vec::new();
let inner_twid = u64::from_str(&line).unwrap();
- view_tr_inner(inner_twid, tweeter, queryer);
-}
-
-fn view_tr_inner(id: u64, mut tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
- let twete: tw::tweet::Tweet = tweeter.retrieve_tweet(&TweetId::Bare(id)).unwrap().to_owned();
- if let Some(reply_id) = twete.reply_to_tweet.clone() {
- if let Some(reply_internal_id) = tweeter.fetch_tweet(&reply_id, queryer).map(|x| x.internal_id).map(|x| x.to_owned()) {
- view_tr_inner(reply_internal_id, tweeter, queryer);
- println!(" |");
- println!(" v");
- }
+ let curr_id = TweetId::Bare(inner_twid);
+ let mut maybe_next_id = tweeter.retrieve_tweet(&curr_id).and_then(|x| x.reply_to_tweet.to_owned());
+ thread.push(curr_id);
+ while let Some(next_id) = maybe_next_id {
+ let curr_id = TweetId::Twitter(next_id);
+ maybe_next_id = tweeter.retrieve_tweet(&curr_id).and_then(|x| x.reply_to_tweet.to_owned());
+ thread.push(curr_id);
}
- display::render_twete(&twete.id, tweeter);
+
+ tweeter.display_info.recv(display::Infos::Thread(thread));
+// display::render_twete(&twete.id, tweeter);
// println!("link: https://twitter.com/i/web/status/{}", twete.id);
}