resultify get_fresh_msgs(), this will make eg. test fail on bad sql

This commit is contained in:
B. Petersen
2021-02-27 00:48:15 +01:00
committed by bjoern
parent 81cd577bf0
commit f9c5ad817b
3 changed files with 9 additions and 6 deletions

View File

@@ -925,6 +925,8 @@ pub unsafe extern "C" fn dc_get_fresh_msgs(
let arr = dc_array_t::from( let arr = dc_array_t::from(
ctx.get_fresh_msgs() ctx.get_fresh_msgs()
.await .await
.log_err(ctx, "Failed to get fresh messages")
.unwrap_or_default()
.iter() .iter()
.map(|msg_id| msg_id.to_u32()) .map(|msg_id| msg_id.to_u32())
.collect::<Vec<u32>>(), .collect::<Vec<u32>>(),

View File

@@ -1000,7 +1000,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
println!("HTML written to: {:#?}", file); println!("HTML written to: {:#?}", file);
} }
"listfresh" => { "listfresh" => {
let msglist = context.get_fresh_msgs().await; let msglist = context.get_fresh_msgs().await?;
log_msglist(&context, &msglist).await?; log_msglist(&context, &msglist).await?;
print!("{} fresh messages.", msglist.len()); print!("{} fresh messages.", msglist.len());

View File

@@ -431,8 +431,9 @@ impl Context {
/// and is typically used to show notifications. /// and is typically used to show notifications.
/// Moreover, the number of returned messages /// Moreover, the number of returned messages
/// can be used for a badge counter on the app icon. /// can be used for a badge counter on the app icon.
pub async fn get_fresh_msgs(&self) -> Vec<MsgId> { pub async fn get_fresh_msgs(&self) -> Result<Vec<MsgId>> {
self.sql let ret = self
.sql
.query_map( .query_map(
concat!( concat!(
"SELECT m.id", "SELECT m.id",
@@ -459,8 +460,8 @@ impl Context {
Ok(ret) Ok(ret)
}, },
) )
.await .await?;
.unwrap_or_default() Ok(ret)
} }
/// Searches for messages containing the query string. /// Searches for messages containing the query string.
@@ -610,7 +611,7 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_get_fresh_msgs() { async fn test_get_fresh_msgs() {
let t = TestContext::new().await; let t = TestContext::new().await;
let fresh = t.get_fresh_msgs().await; let fresh = t.get_fresh_msgs().await.unwrap();
assert!(fresh.is_empty()) assert!(fresh.is_empty())
} }