From 2f2a76aab3f23baaf9a47a72b7660a64e2e156dc Mon Sep 17 00:00:00 2001 From: Andy Wortman Date: Tue, 17 Oct 2017 02:33:59 -0700 Subject: add rudimentary thread support --- src/commands/follow.rs | 2 -- src/commands/mod.rs | 6 ++++- src/commands/thread.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 src/commands/thread.rs (limited to 'src/commands') diff --git a/src/commands/follow.rs b/src/commands/follow.rs index 0da07a8..b2f0aa6 100644 --- a/src/commands/follow.rs +++ b/src/commands/follow.rs @@ -3,8 +3,6 @@ use ::Queryer; use commands::Command; -use std::str::FromStr; - static FOLLOW_URL: &str = "https://api.twitter.com/1.1/friendships/create.json"; static UNFOLLOW_URL: &str = "https://api.twitter.com/1.1/friendships/destroy.json"; diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 4052326..49b2cba 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -14,6 +14,7 @@ mod view; mod quit; mod fav; mod follow; +mod thread; pub static COMMANDS: &[&Command] = &[ &show_cache::SHOW_CACHE, @@ -31,7 +32,10 @@ pub static COMMANDS: &[&Command] = &[ &twete::QUOTE, &twete::RETWETE, &twete::REP, - &twete::THREAD + &twete::THREAD, + &thread::FORGET_THREAD, + &thread::REMEMBER_THREAD, + &thread::LIST_THREADS /* &QUIT, &LOOK_UP_USER, diff --git a/src/commands/thread.rs b/src/commands/thread.rs new file mode 100644 index 0000000..92566fc --- /dev/null +++ b/src/commands/thread.rs @@ -0,0 +1,59 @@ +use tw; +use ::Queryer; +use ::display; + +use commands::Command; + +use std::str::FromStr; + +pub static FORGET_THREAD: Command = Command { + keyword: "forget", + params: 1, + exec: forget +}; + +fn forget(line: String, tweeter: &mut tw::TwitterCache, _queryer: &mut Queryer) { + tweeter.forget_thread(line.trim().to_string()); + println!("Ok! Forgot thread {}", line.trim().to_string()); +} + +pub static REMEMBER_THREAD: Command = Command { + keyword: "remember", + params: 2, + exec: remember +}; + +fn remember(line: String, tweeter: &mut tw::TwitterCache, _queryer: &mut Queryer) { + let mut text: String = line.trim().to_string(); + if let Some(id_end_idx) = text.find(" ") { + let name_bare = text.split_off(id_end_idx + 1); + let name = name_bare.trim(); + let id_str = text.trim(); + if name.len() > 0 { + if let Some(inner_twid) = u64::from_str(&id_str).ok() { + if tweeter.tweet_by_innerid(inner_twid).is_some() { + tweeter.set_thread(name.to_string(), inner_twid); + println!("Ok! Recorded {} as thread {}", inner_twid, name); + } + } + } + } +} + +pub static LIST_THREADS: Command = Command { + keyword: "ls_threads", + params: 0, + exec: ls_threads +}; + +fn ls_threads(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { + println!("Threads: "); + for k in tweeter.threads() { + println!("Thread: {}", k); + let latest_inner_id = tweeter.latest_in_thread(k.to_owned()).unwrap(); + let twete = tweeter.tweet_by_innerid(*latest_inner_id).unwrap(); + // gross.. + display::render_twete(&twete.id, tweeter); + println!(""); + } +} -- cgit v1.1