introduce hosts from mentions
This commit is contained in:
parent
91c00e8027
commit
f6d86376d1
20
src/feed.rs
20
src/feed.rs
|
@ -31,6 +31,23 @@ pub struct Application {
|
|||
pub website: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct Mention {
|
||||
pub username: Option<String>,
|
||||
pub url: String,
|
||||
pub acct: Option<String>,
|
||||
}
|
||||
|
||||
impl Mention {
|
||||
pub fn user_host(&self) -> Option<String> {
|
||||
reqwest::Url::parse(&self.url)
|
||||
.ok()
|
||||
.and_then(|url| url.domain()
|
||||
.map(|s| s.to_owned())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct Post {
|
||||
pub created_at: String,
|
||||
|
@ -40,11 +57,10 @@ pub struct Post {
|
|||
pub tags: Vec<Tag>,
|
||||
pub application: Option<Application>,
|
||||
pub sensitive: Option<bool>,
|
||||
pub mentions: Vec<Mention>,
|
||||
}
|
||||
|
||||
impl Post {
|
||||
// fn time
|
||||
// fn text_content
|
||||
pub fn url_host(&self) -> Option<String> {
|
||||
reqwest::Url::parse(&self.url)
|
||||
.ok()
|
||||
|
|
|
@ -45,11 +45,20 @@ pub fn fetch_and_process(
|
|||
// introduce new hosts, validate posts
|
||||
let mut hosts = HashSet::new();
|
||||
for post in feed.posts.into_iter() {
|
||||
// introduce instances from mentions
|
||||
for mention in &post.mentions {
|
||||
if let Some(user_host) = mention.user_host() {
|
||||
hosts.insert(user_host);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(author_host) = post.account.host() {
|
||||
if author_host == host && post.url_host().as_ref() == Some(&host) {
|
||||
// send away to redis
|
||||
let _ = posts_tx.send(post);
|
||||
}
|
||||
|
||||
// introduce instances from authors
|
||||
hosts.insert(author_host);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue