message: bubble up SQL errors in handle_mdn()

Previously handle_mdn() returned Ok(None) in response to SQL errors as
if SQL simply returned no rows.
This commit is contained in:
link2xt
2021-08-01 01:52:43 +03:00
parent ffb17c4e61
commit 265d54e431

View File

@@ -1644,7 +1644,7 @@ pub async fn handle_mdn(
let res = context let res = context
.sql .sql
.query_row( .query_row_optional(
concat!( concat!(
"SELECT", "SELECT",
" m.id AS msg_id,", " m.id AS msg_id,",
@@ -1665,14 +1665,20 @@ pub async fn handle_mdn(
)) ))
}, },
) )
.await; .await?;
if let Err(ref err) = res {
info!(context, "Failed to select MDN {:?}", err); let (msg_id, chat_id, chat_type, msg_state) = if let Some(res) = res {
} res
} else {
info!(
context,
"handle_mdn found no message with Message-ID {:?} sent by us in the database",
rfc724_mid
);
return Ok(None);
};
if let Ok((msg_id, chat_id, chat_type, msg_state)) = res {
let mut read_by_all = false; let mut read_by_all = false;
if msg_state == MessageState::OutPreparing if msg_state == MessageState::OutPreparing
|| msg_state == MessageState::OutPending || msg_state == MessageState::OutPending
|| msg_state == MessageState::OutDelivered || msg_state == MessageState::OutDelivered
@@ -1687,7 +1693,9 @@ pub async fn handle_mdn(
.unwrap_or_default(); .unwrap_or_default();
if !mdn_already_in_table { if !mdn_already_in_table {
context.sql.execute( context
.sql
.execute(
"INSERT INTO msgs_mdns (msg_id, contact_id, timestamp_sent) VALUES (?, ?, ?);", "INSERT INTO msgs_mdns (msg_id, contact_id, timestamp_sent) VALUES (?, ?, ?);",
paramsv![msg_id, from_id as i32, timestamp_sent], paramsv![msg_id, from_id as i32, timestamp_sent],
) )
@@ -1727,13 +1735,12 @@ pub async fn handle_mdn(
} // else wait for more receipts } // else wait for more receipts
} }
} }
return if read_by_all {
if read_by_all {
Ok(Some((chat_id, msg_id))) Ok(Some((chat_id, msg_id)))
} else { } else {
Ok(None) Ok(None)
};
} }
Ok(None)
} }
/// Marks a message as failed after an ndn (non-delivery-notification) arrived. /// Marks a message as failed after an ndn (non-delivery-notification) arrived.