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/thread.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/commands/thread.rs (limited to 'src/commands/thread.rs') 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