From 3e488ad535a8490d7c039dbaa48993143e6ae467 Mon Sep 17 00:00:00 2001 From: iximeow Date: Tue, 17 Oct 2017 02:33:59 -0700 Subject: add rudimentary thread support --- src/tw/mod.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/tw') diff --git a/src/tw/mod.rs b/src/tw/mod.rs index 49b7add..b703960 100644 --- a/src/tw/mod.rs +++ b/src/tw/mod.rs @@ -93,6 +93,7 @@ pub struct TwitterCache { pub followers: HashSet, lost_followers: HashSet, follower_history: HashMap, // userid:date?? + threads: HashMap, // thread : latest_tweet_in_thread #[serde(skip)] id_to_tweet_id: HashMap, #[serde(skip)] @@ -121,7 +122,8 @@ impl TwitterCache { id_to_tweet_id: HashMap::new(), needs_save: false, caching_permitted: true, - current_user: User::default() + current_user: User::default(), + threads: HashMap::new() } } fn new_without_caching() -> TwitterCache { @@ -387,6 +389,34 @@ impl TwitterCache { pub fn get_followers(&self, queryer: &mut ::Queryer) -> Option { queryer.do_api_get(::GET_FOLLOWER_IDS_URL) } + + pub fn set_thread(&mut self, name: String, last_id: u64) -> bool { + self.threads.insert(name, last_id); + true + } + + pub fn update_thread(&mut self, name: String, last_id: u64) -> bool { + // ensure that last_id is threaded tweet from the last one stored by name. + // if no thread is stored by name, just use last_id. + // who'm am'st i kid'ing, just store it for now lol + self.threads.insert(name, last_id); + true + } + + pub fn latest_in_thread(&self, name: String) -> Option<&u64> { + self.threads.get(&name) + } + + pub fn forget_thread(&mut self, name: String) { + self.threads.remove(&name); + } + + /* + * can the return type here be Iterator< + */ + pub fn threads<'a>(&'a self) -> Box + 'a> { + Box::new(self.threads.keys()) + } } fn handle_twitter_event( -- cgit v1.1