jsonrpc: auto restart io on setConfig for the following keys sentbox_watch, mvbox_move and only_fetch_mvbox (#3542)

Co-authored-by: Jikstra <34889164+Jikstra@users.noreply.github.com>
This commit is contained in:
Simon Laux
2022-08-18 16:27:03 +02:00
committed by GitHub
parent 8be5ca6c30
commit 7d97ab2731
3 changed files with 22 additions and 2 deletions

View File

@@ -17,6 +17,7 @@
- added a JSON RPC API, accessible through a WebSocket server, the CFFI bindings and the Node.js bindings #3463
### Changes
- jsonrpc: auto restart io on setConfig for the following keys `sentbox_watch`, `mvbox_move` and `only_fetch_mvbox` #3542
- refactorings #3545 #3551
- use [pathlib](https://docs.python.org/3/library/pathlib.html) in provider update script #3543
- `dc_get_chat_media()` can return media globally #3528

View File

@@ -671,11 +671,19 @@ async fn set_config(
value: Option<&str>,
) -> Result<(), anyhow::Error> {
if key.starts_with("ui.") {
ctx.set_ui_config(key, value).await
ctx.set_ui_config(key, value).await?;
} else {
ctx.set_config(Config::from_str(key).context("unknown key")?, value)
.await
.await?;
match key {
"sentbox_watch" | "mvbox_move" | "only_fetch_mvbox" => {
ctx.restart_io_if_running().await;
}
_ => {}
}
}
Ok(())
}
async fn get_config(

View File

@@ -239,6 +239,17 @@ impl Context {
}
}
/// Restarts the IO scheduler if it was running before
/// when it is not running this is an no-op
pub async fn restart_io_if_running(&self) {
info!(self, "restarting IO");
let is_running = { self.inner.scheduler.read().await.is_some() };
if is_running {
self.stop_io().await;
self.start_io().await;
}
}
/// Returns a reference to the underlying SQL instance.
///
/// Warning: this is only here for testing, not part of the public API.