Implements mark as read
This commit is contained in:
@@ -63,6 +63,7 @@ pub mod target {
|
||||
pub static SETTINGS: &str = "settings";
|
||||
pub static UPDATES: &str = "updates";
|
||||
pub static ATTACHMENTS: &str = "attachments";
|
||||
pub static DAEMON: &str = "daemon";
|
||||
}
|
||||
|
||||
pub struct Daemon {
|
||||
@@ -221,6 +222,31 @@ impl Daemon {
|
||||
reply.send(()).unwrap();
|
||||
}
|
||||
|
||||
Event::MarkConversationAsRead(conversation_id, reply) => {
|
||||
let mut db_clone = self.database.clone();
|
||||
self.runtime.spawn(async move {
|
||||
let result = Self::mark_conversation_as_read_impl(&mut db_clone, conversation_id).await;
|
||||
if let Err(e) = result {
|
||||
log::error!(target: target::DAEMON, "Error handling mark conversation as read event: {}", e);
|
||||
}
|
||||
});
|
||||
|
||||
reply.send(()).unwrap();
|
||||
}
|
||||
|
||||
Event::UpdateConversationMetadata(conversation, reply) => {
|
||||
let mut db_clone = self.database.clone();
|
||||
let signal_sender = self.signal_sender.clone();
|
||||
self.runtime.spawn(async move {
|
||||
let result = Self::update_conversation_metadata_impl(&mut db_clone, conversation, &signal_sender).await;
|
||||
if let Err(e) = result {
|
||||
log::error!(target: target::DAEMON, "Error handling update conversation metadata event: {}", e);
|
||||
}
|
||||
});
|
||||
|
||||
reply.send(()).unwrap();
|
||||
}
|
||||
|
||||
Event::UpdateStreamReconnected => {
|
||||
log::info!(target: target::UPDATES, "Update stream reconnected");
|
||||
|
||||
@@ -590,6 +616,33 @@ impl Daemon {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn mark_conversation_as_read_impl(
|
||||
database: &mut Arc<Mutex<Database>>,
|
||||
conversation_id: String,
|
||||
) -> Result<()> {
|
||||
log::debug!(target: target::DAEMON, "Marking conversation as read: {}", conversation_id);
|
||||
|
||||
let mut client = Self::get_client_impl(database).await?;
|
||||
client.mark_conversation_as_read(&conversation_id).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn update_conversation_metadata_impl(
|
||||
database: &mut Arc<Mutex<Database>>,
|
||||
conversation: Conversation,
|
||||
signal_sender: &Sender<Signal>,
|
||||
) -> Result<()> {
|
||||
log::debug!(target: target::DAEMON, "Updating conversation metadata: {}", conversation.guid);
|
||||
let updated = database.with_repository(|r| r.merge_conversation_metadata(conversation)).await?;
|
||||
if updated {
|
||||
signal_sender
|
||||
.send(Signal::ConversationsUpdated)
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_settings(&mut self) -> Result<Settings> {
|
||||
let settings = self.database.with_settings(Settings::from_db).await?;
|
||||
Ok(settings)
|
||||
|
||||
Reference in New Issue
Block a user