use std::path::PathBuf; #[derive(Debug, Clone)] pub struct AttachmentMetadata { pub attribution_info: Option, } #[derive(Debug, Clone)] pub struct AttributionInfo { pub width: Option, pub height: Option, } #[derive(Debug, Clone)] pub struct Attachment { pub guid: String, pub base_path: PathBuf, pub metadata: Option, } impl Attachment { pub fn get_path(&self, preview: bool) -> PathBuf { self.base_path.with_extension(if preview { "preview" } else { "full" }) } pub fn is_downloaded(&self, preview: bool) -> bool { std::fs::exists(&self.get_path(preview)) .expect(format!("Wasn't able to check for the existence of an attachment file path at {}", &self.get_path(preview).display()).as_str()) } } impl From for AttachmentMetadata { fn from(metadata: kordophone::model::message::AttachmentMetadata) -> Self { Self { attribution_info: metadata.attribution_info.map(|info| info.into()), } } } impl From for AttributionInfo { fn from(info: kordophone::model::message::AttributionInfo) -> Self { Self { width: info.width, height: info.height, } } } impl From for kordophone::model::message::AttachmentMetadata { fn from(metadata: AttachmentMetadata) -> Self { Self { attribution_info: metadata.attribution_info.map(|info| info.into()), } } } impl From for kordophone::model::message::AttributionInfo { fn from(info: AttributionInfo) -> Self { Self { width: info.width, height: info.height, } } }