~vpzom/hitide

ref: 802f8597fcf5d9981e716db7e10fdc3cfa166b6b hitide/src/util.rs -rw-r--r-- 672 bytes
802f8597Colin Reeder rustfmt a month ago
                                                                                
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
use crate::resp_types::{RespLoginInfo, RespMinimalAuthorInfo};

pub fn abbreviate_link(href: &str) -> &str {
    // Attempt to find the hostname from the URL
    href.find("://")
        .and_then(|idx1| {
            href[(idx1 + 3)..]
                .find('/')
                .map(|idx2| &href[(idx1 + 3)..(idx1 + 3 + idx2)])
        })
        .unwrap_or(href)
}

pub fn author_is_me(
    author: &Option<RespMinimalAuthorInfo<'_>>,
    login: &Option<RespLoginInfo>,
) -> bool {
    if let Some(author) = author {
        if let Some(login) = login {
            if author.id == login.user.id {
                return true;
            }
        }
    }
    false
}