aboutsummaryrefslogtreecommitdiff
path: root/src/commands/view.rs
blob: cc098e75454a78837647ef82b957eac1f2160a30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use tw;
use ::Queryer;

use commands::Command;

use std::str::FromStr;

use display;

pub static VIEW: Command = Command {
    keyword: "view",
    params: 1,
    exec: view
};

fn view(line: String, tweeter: &mut tw::TwitterCache, _queryer: &mut Queryer) {
    // TODO handle this unwrap
    let inner_twid = u64::from_str(&line).unwrap();
    let twete = tweeter.tweet_by_innerid(inner_twid).unwrap();
    display::render_twete(&twete.id, tweeter);
    println!(" link: https://twitter.com/i/web/status/{}", twete.id);
}

pub static VIEW_THREAD: Command = Command {
    keyword: "view_tr",
    params: 1,
    exec: view_tr
};

fn view_tr(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
    // TODO handle this unwrap
    let inner_twid = u64::from_str(&line).unwrap();
    view_tr_inner(inner_twid, tweeter, queryer);
}

fn view_tr_inner(id: u64, mut tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) {
    let twete: tw::tweet::Tweet = tweeter.tweet_by_innerid(id).unwrap().to_owned();
    if let Some(reply_id) = twete.reply_to_tweet.clone() {
        if let Some(reply_internal_id) = tweeter.fetch_tweet(&reply_id, queryer).map(|x| x.internal_id).map(|x| x.to_owned()) {
            view_tr_inner(reply_internal_id, tweeter, queryer);
            println!("      |");
            println!("      v");
        }
    }
    display::render_twete(&twete.id, tweeter);
//    println!("link: https://twitter.com/i/web/status/{}", twete.id);
}