Skip to main content

chan/
threadlist.rs

1use serde::Deserialize;
2
3/// `threads.json`, the lightweight summary list of every active thread on a
4/// board, useful for cheap polling with `If-Modified-Since`.
5#[derive(Debug, Clone, Deserialize)]
6#[serde(transparent)]
7pub struct ThreadList(pub Vec<ThreadListPage>);
8
9#[derive(Debug, Clone, Deserialize)]
10pub struct ThreadListPage {
11    pub page: u32,
12    pub threads: Vec<ThreadStub>,
13}
14
15#[derive(Debug, Clone, Deserialize)]
16pub struct ThreadStub {
17    pub no: u64,            /// OP number.
18    pub last_modified: i64, /// Unix timestamp 
19    pub replies: u32,
20}
21
22impl ThreadList {
23    pub fn pages(&self) -> &[ThreadListPage] { &self.0 }
24
25    pub fn threads(&self) -> impl Iterator<Item = &ThreadStub> {
26        self.0.iter().flat_map(|p| p.threads.iter())
27    }
28}