use serde::Deserialize;
use crate::post::{Attachment, Post};
#[derive(Debug, Clone, Deserialize)]
pub struct Thread {
pub posts: Vec<Post>,
}
impl Thread {
pub fn op(&self) -> &Post { &self.posts[0] }
pub fn replies(&self) -> &[Post] { &self.posts[1..] }
pub fn no(&self) -> u64 { self.op().no }
pub fn is_archived(&self) -> bool { self.op().archived }
pub fn attachments(&self) -> impl Iterator<Item = &Attachment> {
self.posts.iter().filter_map(|p| p.attachment.as_ref())
}
pub fn image_attachments(&self) -> impl Iterator<Item = &Attachment> {
self.attachments().filter(|a| a.is_image())
}
}