mirror of
https://github.com/chatmail/core.git
synced 2026-05-17 05:46:30 +03:00
refactor: factor out insert_tombstone
This commit is contained in:
@@ -98,6 +98,22 @@ pub async fn receive_imf(
|
|||||||
receive_imf_inner(context, &rfc724_mid, imf_raw, seen, None, false).await
|
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.
|
/// Receive a message and add it to the database.
|
||||||
///
|
///
|
||||||
/// Returns an error on database failure or if the message is broken,
|
/// 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);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let row_id = context
|
let msg_ids = vec![insert_tombstone(context, rfc724_mid).await?];
|
||||||
.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)?)];
|
|
||||||
|
|
||||||
return Ok(Some(ReceivedMsg {
|
return Ok(Some(ReceivedMsg {
|
||||||
chat_id: DC_CHAT_ID_TRASH,
|
chat_id: DC_CHAT_ID_TRASH,
|
||||||
|
|||||||
Reference in New Issue
Block a user