Clearer language separation of Series Parts and Prepub Parts
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s

This commit is contained in:
Neshura 2023-12-16 13:44:37 +01:00
parent 6187fa1230
commit dd2cde35e4
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C

View file

@ -221,7 +221,7 @@ pub(crate) async fn check_feed(series_slug: &str, series_has_parts: bool) -> Res
// If no parts just use 0 as Part indicator as no Series with Parts has a Part 0
let mut volume_map: HashMap<u8, PostInfo> = HashMap::new();
let mut chapter_map: HashMap<u8, PostInfo> = HashMap::new();
let mut prepub_map: HashMap<u8, PostInfo> = HashMap::new();
for volume in volume_brief_data.volumes.iter() {
let publishing_date = DateTime::parse_from_rfc3339(&volume.publishing).unwrap();
@ -282,32 +282,32 @@ pub(crate) async fn check_feed(series_slug: &str, series_has_parts: bool) -> Res
.or_insert(new_post_info);
}
if let Some(part_info) = get_latest_part(&volume.slug).await? {
let part_post_info = Chapter {
if let Some(prepub_info) = get_latest_prepub(&volume.slug).await? {
let prepub_post_info = Chapter {
part: new_part_info,
volume: volume.number,
lemmy_info: part_info
lemmy_info: prepub_info
};
chapter_map
prepub_map
.entry(part_id)
.and_modify(|val| {
if *val < part_post_info {
*val = part_post_info.clone()
if *val < prepub_post_info {
*val = prepub_post_info.clone()
}
})
.or_insert(part_post_info);
.or_insert(prepub_post_info);
}
}
let mut result_vec: Vec<PostInfo> = volume_map.values().cloned().collect();
let mut chapter_vec: Vec<PostInfo> = chapter_map.values().cloned().collect();
result_vec.append(&mut chapter_vec);
let mut prepub_vec: Vec<PostInfo> = prepub_map.values().cloned().collect();
result_vec.append(&mut prepub_vec);
Ok(result_vec)
}
async fn get_latest_part(volume_slug: &str) -> Result<Option<LemmyPostInfo>, Box<dyn Error>> {
async fn get_latest_prepub(volume_slug: &str) -> Result<Option<LemmyPostInfo>, Box<dyn Error>> {
let response = HTTP_CLIENT
.get(api_url!() + "/volumes/" + volume_slug + "/parts?format=json")
.send()
@ -315,13 +315,13 @@ async fn get_latest_part(volume_slug: &str) -> Result<Option<LemmyPostInfo>, Box
.text()
.await?;
let mut volume_parts_data: ChapterWrapper = serde_json::from_str(&response)?;
volume_parts_data.parts.reverse(); // Makes breaking out of the parts loop easier
let mut volume_prepub_parts_data: ChapterWrapper = serde_json::from_str(&response)?;
volume_prepub_parts_data.parts.reverse(); // Makes breaking out of the parts loop easier
let mut post_details: Option<LemmyPostInfo> = None;
for part in volume_parts_data.parts.iter() {
let publishing_date = DateTime::parse_from_rfc3339(&part.launch).unwrap();
for prepub_part in volume_prepub_parts_data.parts.iter() {
let publishing_date = DateTime::parse_from_rfc3339(&prepub_part.launch).unwrap();
if publishing_date > Utc::now() {
break
}
@ -329,9 +329,9 @@ async fn get_latest_part(volume_slug: &str) -> Result<Option<LemmyPostInfo>, Box
continue
}
let post_url = format!("{}/read/{}", jnc_base_url!(), part.slug);
let post_url = format!("{}/read/{}", jnc_base_url!(), prepub_part.slug);
post_details = Some(LemmyPostInfo {
title: part.title.clone(),
title: prepub_part.title.clone(),
url: Url::parse(&post_url).unwrap(),
});