Return selected account by ID

Otherwise you do not know which account needs unlocking if the
selected account is locked.
This commit is contained in:
Floris Bruynooghe
2022-02-07 21:19:48 +01:00
parent 2d14f1e187
commit 8bd58a0d51
2 changed files with 14 additions and 17 deletions

View File

@@ -2734,7 +2734,7 @@ dc_context_t* dc_accounts_load_encrypted (dc_accounts_t* accounts, uint32_t acc
/** /**
* Get the currently selected account. * Get the currently selected account ID.
* *
* If there is at least one account in the account-manager, * If there is at least one account in the account-manager,
* there is always a selected one. * there is always a selected one.
@@ -2743,17 +2743,15 @@ dc_context_t* dc_accounts_load_encrypted (dc_accounts_t* accounts, uint32_t acc
* *
* @memberof dc_accounts_t * @memberof dc_accounts_t
* @param accounts Account manager as created by dc_accounts_new(). * @param accounts Account manager as created by dc_accounts_new().
* @return The account-context, this can be used most similar as a normal, * @return The account ID of the selected account. The context of
* unmanaged account-context as created by dc_context_new(). * the selected account can then be retrieved using dc_accounts_get_account().
* Once you do no longer need the context-object, you have to call dc_context_unref() on it, * Note that if the selected account is encrypted you may first have to
* which, however, will not close the account but only decrease a reference counter. * load it using dc_accounts_load_encrypted(), you can verify if this is needed
* * using dc_accounts_get_encrypted().
* If there is no selected account, NULL is returned. * If no account is selected 0 is returned. However this is only possible if
* * there is no single account in the account manager.
* If the selected account is encrypted and not yet loaded using
* dc_accounts_load_encrypted(), NULL is returned.
*/ */
dc_context_t* dc_accounts_get_selected_account (dc_accounts_t* accounts); uint32_t* dc_accounts_get_selected_account_id (dc_accounts_t* accounts);
/** /**

View File

@@ -4068,18 +4068,17 @@ pub unsafe extern "C" fn dc_accounts_get_account(
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn dc_accounts_get_selected_account( pub unsafe extern "C" fn dc_accounts_get_selected_account_id(
accounts: *mut dc_accounts_t, accounts: *mut dc_accounts_t,
) -> *mut dc_context_t { ) -> u32 {
if accounts.is_null() { if accounts.is_null() {
eprintln!("ignoring careless call to dc_accounts_get_selected_account()"); eprintln!("ignoring careless call to dc_accounts_get_selected_account()");
return ptr::null_mut(); return 0;
} }
let accounts = &*accounts; let accounts = &*accounts;
block_on(async move { accounts.read().await.get_selected_account().await }) block_on(async move { accounts.read().await.get_selected_account_id().await })
.map(|ctx| Box::into_raw(Box::new(ctx))) .unwrap_or(0)
.unwrap_or_else(std::ptr::null_mut)
} }
#[no_mangle] #[no_mangle]