Sort all segments by start time.

This commit is contained in:
Kavin 2022-10-25 23:10:56 +01:00
parent 525cded71e
commit fe6f74d205
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD
2 changed files with 11 additions and 0 deletions

View File

@ -109,6 +109,10 @@ pub async fn skip_segments(
}
}
for sponsor in sponsors.values_mut() {
sponsor.segments.sort_by(|a, b| a.partial_cmp(b).unwrap());
}
if !sponsors.is_empty() {
let sponsors: Vec<&Sponsor> = sponsors.values().collect();
return content::RawJson(serde_json::to_string(&sponsors).unwrap());

View File

@ -1,3 +1,4 @@
use std::cmp::Ordering;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug)]
@ -30,3 +31,9 @@ impl PartialEq for Segment {
self.uuid == other.uuid
}
}
impl PartialOrd for Segment {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.segment[0].partial_cmp(&other.segment[0])
}
}