diff --git a/deltachat-jsonrpc/src/api.rs b/deltachat-jsonrpc/src/api.rs index 8fa77eb9dd..7477eef46c 100644 --- a/deltachat-jsonrpc/src/api.rs +++ b/deltachat-jsonrpc/src/api.rs @@ -14,7 +14,7 @@ use deltachat::chat::{ marknoticed_chat, remove_contact_from_chat, Chat, ChatId, ChatItem, MessageListOptions, }; use deltachat::chatlist::Chatlist; -use deltachat::config::Config; +use deltachat::config::{get_all_ui_config_keys, Config}; use deltachat::constants::DC_MSG_ID_DAYMARKER; use deltachat::contact::{may_be_valid_addr, Contact, ContactId, Origin}; use deltachat::context::get_info; @@ -458,6 +458,12 @@ impl CommandApi { Ok(result) } + /// Returns all `ui.*` config keys that were set by the UI. + async fn get_all_ui_config_keys(&self, account_id: u32) -> Result> { + let ctx = self.get_context(account_id).await?; + get_all_ui_config_keys(&ctx).await + } + async fn set_stock_strings(&self, strings: HashMap) -> Result<()> { let accounts = self.accounts.read().await; for (stock_id, stock_message) in strings { diff --git a/src/config.rs b/src/config.rs index bdb5ca2b14..3969c53e9f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -987,5 +987,18 @@ fn get_config_keys_string() -> String { format!(" {keys} ") } +/// Returns all `ui.*` config keys that were set by the UI. +pub async fn get_all_ui_config_keys(context: &Context) -> Result> { + let ui_keys = context + .sql + .query_map_vec( + "SELECT keyname FROM config WHERE keyname GLOB 'ui.*' ORDER BY config.id", + (), + |row| Ok(row.get::<_, String>(0)?), + ) + .await?; + Ok(ui_keys) +} + #[cfg(test)] mod config_tests; diff --git a/src/config/config_tests.rs b/src/config/config_tests.rs index aabe0e7f5f..78481f2941 100644 --- a/src/config/config_tests.rs +++ b/src/config/config_tests.rs @@ -81,6 +81,37 @@ async fn test_ui_config() -> Result<()> { Ok(()) } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_get_all_ui_config_keys() -> Result<()> { + let t = TestContext::new().await; + + t.set_ui_config("ui.android.screen_security", Some("safe")) + .await?; + t.set_ui_config("ui.lastchatid", Some("231")).await?; + t.set_ui_config( + "ui.desktop.webxdcBounds.528490", + Some(r#"{"x":954,"y":356,"width":378,"height":671}"#), + ) + .await?; + t.set_ui_config( + "ui.desktop.webxdcBounds.556543", + Some(r#"{"x":954,"y":356,"width":378,"height":671}"#), + ) + .await?; + + assert_eq!( + get_all_ui_config_keys(&t).await?, + vec![ + "ui.android.screen_security", + "ui.lastchatid", + "ui.desktop.webxdcBounds.528490", + "ui.desktop.webxdcBounds.556543" + ] + ); + + Ok(()) +} + /// Regression test for https://github.com/deltachat/deltachat-core-rust/issues/3012 #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_set_config_bool() -> Result<()> {