use display::DisplayInfo; use tw; use ::Queryer; use tw::TweetId; use commands::Command; use display; pub static VIEW: Command = Command { keyword: "view", params: 1, exec: view, param_str: " ", help_str: "Display tweet with a reference URL" }; fn view(line: String, tweeter: &mut tw::TwitterCache, _queryer: &mut Queryer, display_info: &mut DisplayInfo) { match TweetId::parse(line) { Ok(twid) => { if let Some(twete) = tweeter.retrieve_tweet(&twid) { display_info.recv(display::Infos::TweetWithContext( TweetId::Twitter(twete.id.to_owned()), format!("link: https://twitter.com/i/web/status/{}", twete.id) )); } else { display_info.status(format!("No tweet for id {:?}", twid)); } }, Err(e) => { display_info.status(format!("Invalid id {:?}", e)); } } } pub static VIEW_THREAD: Command = Command { keyword: "view_tr", params: 1, exec: view_tr, param_str: " ", help_str: "Display whole thread leading to , reference URLs for each" }; fn view_tr(line: String, mut tweeter: &mut tw::TwitterCache, queryer: &mut Queryer, display_info: &mut DisplayInfo) { let mut thread: Vec = Vec::new(); let maybe_curr_id = TweetId::parse(line); match maybe_curr_id { Ok(curr_id) => { let first_twete = tweeter.fetch_tweet(&curr_id, queryer, display_info).map(|x| x.to_owned()); if first_twete.is_some() { thread.push(curr_id); } let mut maybe_next_id = first_twete.and_then(|x| x.reply_to_tweet.to_owned()); while let Some(next_id) = maybe_next_id { let curr_id = TweetId::Twitter(next_id); maybe_next_id = tweeter.fetch_tweet(&curr_id, queryer, display_info).and_then(|x| x.reply_to_tweet.to_owned()); thread.push(curr_id); } }, Err(e) => { display_info.status(format!("Invalid id {:?}", e)); } } display_info.recv(display::Infos::Thread(thread)); } pub static VIEW_THREAD_FORWARD: Command = Command { keyword: "viewthread+", params: 1, exec: view_tr_forward, param_str: "", help_str: "help me make this work" }; fn view_tr_forward(_line: String, _tweeter: &mut tw::TwitterCache, _queryer: &mut Queryer, display_info: &mut DisplayInfo) { // first see if we have a thread for the tweet named // if we do not, we'll have to mimic a request like // curl 'https://twitter.com/jojonila/status/914383908090691584' \ // -H 'accept-encoding: gzip, deflate, br' \ // -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 \ // (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36' \ // -H 'x-overlay-request: true' /* * above results in a response: * { * "init_data": { ... }, * "title": "tweet, but for page title", * .. * "page": "HTML THAT'S JUST DROPPED IN AS A MODAL." * */ }