Private
Public Access
1
0

plumb all known attachments via dbus if known

This commit is contained in:
2025-06-06 16:28:29 -07:00
parent 2e55f3ac9e
commit 77e1078d6a
10 changed files with 368 additions and 54 deletions

View File

@@ -0,0 +1,64 @@
use std::path::PathBuf;
#[derive(Debug, Clone)]
pub struct AttachmentMetadata {
pub attribution_info: Option<AttributionInfo>,
}
#[derive(Debug, Clone)]
pub struct AttributionInfo {
pub width: Option<u32>,
pub height: Option<u32>,
}
#[derive(Debug, Clone)]
pub struct Attachment {
pub guid: String,
pub base_path: PathBuf,
pub metadata: Option<AttachmentMetadata>,
}
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<kordophone::model::message::AttachmentMetadata> for AttachmentMetadata {
fn from(metadata: kordophone::model::message::AttachmentMetadata) -> Self {
Self {
attribution_info: metadata.attribution_info.map(|info| info.into()),
}
}
}
impl From<kordophone::model::message::AttributionInfo> for AttributionInfo {
fn from(info: kordophone::model::message::AttributionInfo) -> Self {
Self {
width: info.width,
height: info.height,
}
}
}
impl From<AttachmentMetadata> for kordophone::model::message::AttachmentMetadata {
fn from(metadata: AttachmentMetadata) -> Self {
Self {
attribution_info: metadata.attribution_info.map(|info| info.into()),
}
}
}
impl From<AttributionInfo> for kordophone::model::message::AttributionInfo {
fn from(info: AttributionInfo) -> Self {
Self {
width: info.width,
height: info.height,
}
}
}