mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
let get_selection_account return an Option<>
This commit is contained in:
@@ -2486,6 +2486,7 @@ dc_context_t* dc_accounts_get_account (dc_accounts_t* accounts, uint32
|
|||||||
* unmanaged account-context as created by dc_context_new().
|
* unmanaged account-context as created by dc_context_new().
|
||||||
* Once you do no longer need the context-object, you have to call dc_context_unref() on it,
|
* Once you do no longer need the context-object, you have to call dc_context_unref() on it,
|
||||||
* which, however, will not close the account but only decrease a reference counter.
|
* which, however, will not close the account but only decrease a reference counter.
|
||||||
|
* If there is no selected account, NULL is returned.
|
||||||
*/
|
*/
|
||||||
dc_context_t* dc_accounts_get_selected_account (dc_accounts_t* accounts);
|
dc_context_t* dc_accounts_get_selected_account (dc_accounts_t* accounts);
|
||||||
|
|
||||||
|
|||||||
@@ -3695,8 +3695,9 @@ pub unsafe extern "C" fn dc_accounts_get_selected_account(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let accounts = &*accounts;
|
let accounts = &*accounts;
|
||||||
let ctx = block_on(accounts.get_selected_account());
|
block_on(accounts.get_selected_account())
|
||||||
Box::into_raw(Box::new(ctx))
|
.map(|ctx| Box::into_raw(Box::new(ctx)))
|
||||||
|
.unwrap_or_else(std::ptr::null_mut)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|||||||
@@ -65,14 +65,9 @@ impl Accounts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the currently selected account.
|
/// Get the currently selected account.
|
||||||
pub async fn get_selected_account(&self) -> Context {
|
pub async fn get_selected_account(&self) -> Option<Context> {
|
||||||
let id = self.config.get_selected_account().await;
|
let id = self.config.get_selected_account().await;
|
||||||
self.accounts
|
self.accounts.read().await.get(&id).cloned()
|
||||||
.read()
|
|
||||||
.await
|
|
||||||
.get(&id)
|
|
||||||
.cloned()
|
|
||||||
.expect("inconsistent state")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Select the given account.
|
/// Select the given account.
|
||||||
@@ -509,7 +504,7 @@ mod tests {
|
|||||||
assert_eq!(accounts.accounts.read().await.len(), 1);
|
assert_eq!(accounts.accounts.read().await.len(), 1);
|
||||||
assert_eq!(accounts.config.get_selected_account().await, 1);
|
assert_eq!(accounts.config.get_selected_account().await, 1);
|
||||||
|
|
||||||
let ctx = accounts.get_selected_account().await;
|
let ctx = accounts.get_selected_account().await.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"me@mail.com",
|
"me@mail.com",
|
||||||
ctx.get_config(crate::config::Config::Addr)
|
ctx.get_config(crate::config::Config::Addr)
|
||||||
@@ -581,7 +576,7 @@ mod tests {
|
|||||||
|
|
||||||
let (id0_reopened, id1_reopened, id2_reopened) = {
|
let (id0_reopened, id1_reopened, id2_reopened) = {
|
||||||
let accounts = Accounts::new("my_os".into(), p.clone()).await?;
|
let accounts = Accounts::new("my_os".into(), p.clone()).await?;
|
||||||
let ctx = accounts.get_selected_account().await;
|
let ctx = accounts.get_selected_account().await.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ctx.get_config(crate::config::Config::Addr).await?,
|
ctx.get_config(crate::config::Config::Addr).await?,
|
||||||
Some("two@example.org".to_string())
|
Some("two@example.org".to_string())
|
||||||
|
|||||||
Reference in New Issue
Block a user