1use serde::Deserialize;
2
3use crate::post::{Attachment, Post};
4
5#[derive(Debug, Clone, Deserialize)]
7pub struct Thread {
8 pub posts: Vec<Post>,
9}
10
11impl Thread {
12 pub fn op(&self) -> &Post { &self.posts[0] }
14
15 pub fn replies(&self) -> &[Post] { &self.posts[1..] }
17
18 pub fn no(&self) -> u64 { self.op().no }
20
21 pub fn is_archived(&self) -> bool { self.op().archived }
24
25 pub fn attachments(&self) -> impl Iterator<Item = &Attachment> {
27 self.posts.iter().filter_map(|p| p.attachment.as_ref())
28 }
29
30 pub fn image_attachments(&self) -> impl Iterator<Item = &Attachment> {
32 self.attachments().filter(|a| a.is_image())
33 }
34}