From dd687928318cd0b4cad76228b80d1959c1319997 Mon Sep 17 00:00:00 2001 From: Andy Wortman Date: Sun, 24 Dec 2017 23:01:16 -0800 Subject: remove dependence on nightly and remove_item (turns out remove_item was wrong anyway, i wanted to remove all instances of a string, it only removed the first) this sneaks in a big change on self-replies, now removes the @ mention of you if you reply to yourself --- src/commands/twete.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src/commands') diff --git a/src/commands/twete.rs b/src/commands/twete.rs index d727b9e..450c225 100644 --- a/src/commands/twete.rs +++ b/src/commands/twete.rs @@ -155,24 +155,31 @@ fn rep(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer, disp if let Some(twete) = tweeter.retrieve_tweet(&twid).map(|x| x.clone()) { // TODO: no clone when this stops taking &mut self // get handles to reply to... let author_handle = tweeter.retrieve_user(&twete.author_id).unwrap().handle.to_owned(); - let mut ats: Vec = twete.get_mentions(); //std::collections::HashSet::new(); - ats.remove_item(&author_handle); - ats.insert(0, author_handle); + let raw_ats: Vec = twete.get_mentions(); //std::collections::HashSet::new(); + let mut reordered_ats: Vec = Vec::new(); + if &author_handle != &user_profile.user.handle { + reordered_ats.push(author_handle); + } + for handle in raw_ats.into_iter() { + if &handle != &user_profile.user.handle { + reordered_ats.push(handle); + } + } 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); + let mut reordered_with_rt = Vec::new(); + for mention in reordered_ats { + if mention != rt_author_handle { + reordered_with_rt.push(mention); + } + } + reordered_with_rt.insert(1, rt_author_handle); + reordered_ats = reordered_with_rt; } - // if you're directly replying to yourself, i trust you know what you're doing and - // want to @ yourself again (this keeps self-replies from showing up on your - // profile as threaded tweets, f.ex) - if !(ats.len() > 0 && &ats[0] == &user_profile.user.handle) { - ats.remove_item(&user_profile.user.handle); - } //let ats_vec: Vec<&str> = ats.into_iter().collect(); //let full_reply = format!("{} {}", ats_vec.join(" "), reply); - let decorated_ats: Vec = ats.into_iter().map(|x| format!("@{}", x)).collect(); + let decorated_ats: Vec = reordered_ats.into_iter().map(|x| format!("@{}", x)).collect(); let full_reply = format!("{} {}", decorated_ats.join(" "), reply); if reply.len() > 0 { -- cgit v1.1