adds the ability to clear db
This commit is contained in:
@@ -29,6 +29,9 @@ pub enum Event {
|
||||
/// - conversation_id: The ID of the conversation to get messages for.
|
||||
/// - last_message_id: (optional) The ID of the last message to get. If None, all messages are returned.
|
||||
GetMessages(String, Option<String>, Reply<Vec<Message>>),
|
||||
|
||||
/// Delete all conversations from the database.
|
||||
DeleteAllConversations(Reply<()>),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -206,6 +206,15 @@ impl Daemon {
|
||||
let messages = self.get_messages(conversation_id, last_message_id).await;
|
||||
reply.send(messages).unwrap();
|
||||
},
|
||||
|
||||
Event::DeleteAllConversations(reply) => {
|
||||
self.delete_all_conversations().await
|
||||
.unwrap_or_else(|e| {
|
||||
log::error!("Failed to delete all conversations: {}", e);
|
||||
});
|
||||
|
||||
reply.send(()).unwrap();
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,6 +322,18 @@ impl Daemon {
|
||||
Ok(client)
|
||||
}
|
||||
|
||||
async fn delete_all_conversations(&mut self) -> Result<()> {
|
||||
self.database.with_repository(|r| -> Result<()> {
|
||||
r.delete_all_conversations()?;
|
||||
r.delete_all_messages()?;
|
||||
Ok(())
|
||||
}).await?;
|
||||
|
||||
self.signal_sender.send(Signal::ConversationsUpdated).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_database_path() -> PathBuf {
|
||||
if let Some(proj_dirs) = ProjectDirs::from("net", "buzzert", "kordophonecd") {
|
||||
let data_dir = proj_dirs.data_dir();
|
||||
|
||||
@@ -99,6 +99,10 @@ impl DbusRepository for ServerImpl {
|
||||
}).collect()
|
||||
})
|
||||
}
|
||||
|
||||
fn delete_all_conversations(&mut self) -> Result<(), dbus::MethodErr> {
|
||||
self.send_event_sync(Event::DeleteAllConversations)
|
||||
}
|
||||
}
|
||||
|
||||
impl DbusSettings for ServerImpl {
|
||||
|
||||
Reference in New Issue
Block a user