aboutsummaryrefslogtreecommitdiff
path: root/src/tw/mod.rs
diff options
context:
space:
mode:
authorAndy Wortman <ixineeringeverywhere@gmail.com>2017-10-17 02:33:59 -0700
committerAndy Wortman <ixineeringeverywhere@gmail.com>2017-10-17 02:33:59 -0700
commit2f2a76aab3f23baaf9a47a72b7660a64e2e156dc (patch)
tree1c6312dd3f1f8cc30ec9dcfff944bb1274bf15e3 /src/tw/mod.rs
parentebe62b5ad92b60549deffd2d729c43134f93d96c (diff)
add rudimentary thread support
Diffstat (limited to 'src/tw/mod.rs')
-rw-r--r--src/tw/mod.rs32
1 files changed, 31 insertions, 1 deletions
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<String>,
lost_followers: HashSet<String>,
follower_history: HashMap<String, (String, i64)>, // userid:date??
+ threads: HashMap<String, u64>, // thread : latest_tweet_in_thread
#[serde(skip)]
id_to_tweet_id: HashMap<u64, String>,
#[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<serde_json::Value> {
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<Iterator<Item=&String> + 'a> {
+ Box::new(self.threads.keys())
+ }
}
fn handle_twitter_event(