AttachmentStore now has its own runloop, can download attachments
This commit is contained in:
@@ -43,7 +43,8 @@ use post_office::PostOffice;
|
||||
|
||||
mod attachment_store;
|
||||
pub use attachment_store::Attachment;
|
||||
use attachment_store::AttachmentStore;
|
||||
pub use attachment_store::AttachmentStore;
|
||||
pub use attachment_store::AttachmentStoreEvent;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DaemonError {
|
||||
@@ -75,7 +76,7 @@ pub struct Daemon {
|
||||
|
||||
outgoing_messages: HashMap<ConversationID, Vec<OutgoingMessage>>,
|
||||
|
||||
attachment_store: AttachmentStore,
|
||||
attachment_store_sink: Option<Sender<AttachmentStoreEvent>>,
|
||||
|
||||
version: String,
|
||||
database: Arc<Mutex<Database>>,
|
||||
@@ -105,9 +106,6 @@ impl Daemon {
|
||||
let database_impl = Database::new(&database_path.to_string_lossy())?;
|
||||
let database = Arc::new(Mutex::new(database_impl));
|
||||
|
||||
let data_path = Self::get_data_dir().expect("Unable to get data path");
|
||||
let attachment_store = AttachmentStore::new(&data_path);
|
||||
|
||||
Ok(Self {
|
||||
version: "0.1.0".to_string(),
|
||||
database,
|
||||
@@ -118,7 +116,7 @@ impl Daemon {
|
||||
post_office_sink,
|
||||
post_office_source: Some(post_office_source),
|
||||
outgoing_messages: HashMap::new(),
|
||||
attachment_store: attachment_store,
|
||||
attachment_store_sink: None,
|
||||
runtime,
|
||||
})
|
||||
}
|
||||
@@ -148,6 +146,14 @@ impl Daemon {
|
||||
});
|
||||
}
|
||||
|
||||
// Attachment store
|
||||
let data_path = Self::get_data_dir().expect("Unable to get data path");
|
||||
let mut attachment_store = AttachmentStore::new(&data_path, self.database.clone(), self.event_sender.clone());
|
||||
self.attachment_store_sink = Some(attachment_store.get_event_sink());
|
||||
tokio::spawn(async move {
|
||||
attachment_store.run().await;
|
||||
});
|
||||
|
||||
while let Some(event) = self.event_receiver.recv().await {
|
||||
log::debug!(target: target::EVENT, "Received event: {:?}", event);
|
||||
self.handle_event(event).await;
|
||||
@@ -282,13 +288,24 @@ impl Daemon {
|
||||
}
|
||||
|
||||
Event::GetAttachment(guid, reply) => {
|
||||
let attachment = self.attachment_store.get_attachment(&guid);
|
||||
reply.send(attachment).unwrap();
|
||||
self.attachment_store_sink
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.send(AttachmentStoreEvent::GetAttachmentInfo(guid, reply))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
Event::DownloadAttachment(attachment_id, reply) => {
|
||||
// For now, just return success - we'll implement the actual download logic later
|
||||
log::info!(target: target::ATTACHMENTS, "Download requested for attachment: {}", attachment_id);
|
||||
Event::DownloadAttachment(attachment_id, preview, reply) => {
|
||||
log::info!(target: target::ATTACHMENTS, "Download requested for attachment: {}, preview: {}", &attachment_id, preview);
|
||||
|
||||
self.attachment_store_sink
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.send(AttachmentStoreEvent::QueueDownloadAttachment(attachment_id, preview))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
reply.send(()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user