refactor: factor out insert_tombstone

This commit is contained in:
link2xt
2023-11-28 21:28:52 +00:00
parent 37d2aafb26
commit 4287a4d3ad

View File

@@ -98,6 +98,22 @@ pub async fn receive_imf(
receive_imf_inner(context, &rfc724_mid, imf_raw, seen, None, false).await
}
/// Inserts a tombstone into `msgs` table
/// to prevent downloading the same message in the future.
///
/// Returns tombstone database row ID.
async fn insert_tombstone(context: &Context, rfc724_mid: &str) -> Result<MsgId> {
let row_id = context
.sql
.insert(
"INSERT INTO msgs(rfc724_mid, chat_id) VALUES (?,?)",
(rfc724_mid, DC_CHAT_ID_TRASH),
)
.await?;
let msg_id = MsgId::new(u32::try_from(row_id)?);
Ok(msg_id)
}
/// Receive a message and add it to the database.
///
/// Returns an error on database failure or if the message is broken,
@@ -137,14 +153,7 @@ pub(crate) async fn receive_imf_inner(
return Ok(None);
}
let row_id = context
.sql
.insert(
"INSERT INTO msgs(rfc724_mid, chat_id) VALUES (?,?)",
(rfc724_mid, DC_CHAT_ID_TRASH),
)
.await?;
let msg_ids = vec![MsgId::new(u32::try_from(row_id)?)];
let msg_ids = vec![insert_tombstone(context, rfc724_mid).await?];
return Ok(Some(ReceivedMsg {
chat_id: DC_CHAT_ID_TRASH,