spread out posts within the same minute

main
xenofem 2022-02-20 05:41:25 -05:00
parent 0a2c67f47c
commit bac2311bc7
1 changed files with 17 additions and 2 deletions

View File

@ -5,7 +5,9 @@ use actix_web::{
};
use lazy_static::lazy_static;
use scraper::{Html, Selector};
use time::{format_description::well_known::Rfc3339, OffsetDateTime, PrimitiveDateTime, UtcOffset};
use time::{
format_description::well_known::Rfc3339, Duration, OffsetDateTime, PrimitiveDateTime, UtcOffset,
};
lazy_static! {
static ref FIRST_TEXT_SEL: Selector = Selector::parse("#delform > blockquote").unwrap();
@ -106,6 +108,8 @@ async fn get_posts(thread_id: &str) -> Option<Vec<Post>> {
.and_then(extract_time)
.unwrap_or(OffsetDateTime::UNIX_EPOCH);
let mut last_time = first_time;
let mut posts = vec![Post {
text: first_text,
image: first_image,
@ -137,11 +141,22 @@ async fn get_posts(thread_id: &str) -> Option<Vec<Post>> {
None
}
});
let time = element
let mut time = element
.select(&TIME_SEL)
.next()
.and_then(extract_time)
.unwrap_or(OffsetDateTime::UNIX_EPOCH);
// Spread out posts within the same minute so they'll be sorted properly
if last_time - (last_time.second() * Duration::SECOND) == time {
if last_time.second() < 59 {
last_time += Duration::SECOND;
}
time = last_time;
} else {
last_time = time;
}
posts.push(Post {
text,
image,