Private
Public Access
1
0

bugfixes, better handling of server url changes

This commit is contained in:
2025-06-13 17:11:29 -07:00
parent dece6f1abc
commit 45d873907f
5 changed files with 58 additions and 4 deletions

View File

@@ -32,7 +32,7 @@ use kordophone::model::outgoing_message::OutgoingMessage;
use kordophone::model::ConversationID;
mod update_monitor;
use update_monitor::UpdateMonitor;
use update_monitor::{UpdateMonitor, UpdateMonitorCommand};
mod auth_store;
use auth_store::DatabaseAuthenticationStore;
@@ -80,6 +80,7 @@ pub struct Daemon {
outgoing_messages: HashMap<ConversationID, Vec<OutgoingMessage>>,
attachment_store_sink: Option<Sender<AttachmentStoreEvent>>,
update_monitor_command_tx: Option<Sender<UpdateMonitorCommand>>,
version: String,
database: Arc<Mutex<Database>>,
@@ -120,6 +121,7 @@ impl Daemon {
post_office_source: Some(post_office_source),
outgoing_messages: HashMap::new(),
attachment_store_sink: None,
update_monitor_command_tx: None,
runtime,
})
}
@@ -131,6 +133,7 @@ impl Daemon {
// Update monitor
let mut update_monitor =
UpdateMonitor::new(self.database.clone(), self.event_sender.clone());
self.update_monitor_command_tx = Some(update_monitor.take_command_channel());
tokio::spawn(async move {
update_monitor.run().await; // should run indefinitely
});
@@ -248,10 +251,30 @@ impl Daemon {
}
Event::UpdateSettings(settings, reply) => {
let previous_server_url = self.get_settings().await.unwrap_or_default().server_url;
self.update_settings(&settings).await.unwrap_or_else(|e| {
log::error!(target: target::SETTINGS, "Failed to update settings: {}", e);
});
if previous_server_url != settings.server_url {
// If the server url has changed, we'll need to do a full re-sync.
self.delete_all_conversations().await.unwrap_or_else(|e| {
log::error!(target: target::SYNC, "Failed to delete all conversations: {}", e);
});
// Do a sync-list to get the new conversations.
self.spawn_conversation_list_sync();
// Also restart the update monitor.
self.update_monitor_command_tx
.as_ref()
.unwrap()
.send(UpdateMonitorCommand::Restart)
.await
.unwrap();
}
reply.send(()).unwrap();
}