introduce hosts from mentions

This commit is contained in:
Astro 2022-11-03 03:42:13 +01:00
parent 91c00e8027
commit f6d86376d1
2 changed files with 27 additions and 2 deletions

View File

@ -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()

View File

@ -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);
}
}