resultify Contact::get_all_blocked()

This commit is contained in:
B. Petersen
2021-02-23 16:55:42 +01:00
committed by bjoern
parent 01af3b7547
commit 79e72418bb
3 changed files with 16 additions and 7 deletions

View File

@@ -1640,7 +1640,13 @@ pub unsafe extern "C" fn dc_get_blocked_cnt(context: *mut dc_context_t) -> libc:
}
let ctx = &*context;
block_on(async move { Contact::get_all_blocked(&ctx).await.len() as libc::c_int })
block_on(async move {
Contact::get_all_blocked(&ctx)
.await
.log_err(&ctx, "Can't get blocked count")
.unwrap_or_default()
.len() as libc::c_int
})
}
#[no_mangle]
@@ -1655,7 +1661,10 @@ pub unsafe extern "C" fn dc_get_blocked_contacts(
block_on(async move {
Box::into_raw(Box::new(dc_array_t::from(
Contact::get_all_blocked(&ctx).await,
Contact::get_all_blocked(&ctx)
.await
.log_err(&ctx, "Can't get blocked contacts")
.unwrap_or_default(),
)))
})
}

View File

@@ -1103,7 +1103,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
Contact::unblock(&context, contact_id).await;
}
"listblocked" => {
let contacts = Contact::get_all_blocked(&context).await;
let contacts = Contact::get_all_blocked(&context).await?;
log_contactlist(&context, &contacts).await;
println!("{} blocked contacts.", contacts.len());
}

View File

@@ -675,8 +675,8 @@ impl Contact {
}
/// Get blocked contacts.
pub async fn get_all_blocked(context: &Context) -> Vec<u32> {
context
pub async fn get_all_blocked(context: &Context) -> Result<Vec<u32>> {
let ret = context
.sql
.query_map(
"SELECT id FROM contacts WHERE id>? AND blocked!=0 ORDER BY LOWER(iif(name='',authname,name)||addr),id;",
@@ -687,8 +687,8 @@ impl Contact {
.map_err(Into::into)
},
)
.await
.unwrap_or_default()
.await?;
Ok(ret)
}
/// Returns a textual summary of the encryption state for the contact.