mirror of
https://github.com/chatmail/core.git
synced 2026-04-21 15:36:30 +03:00
api: get_existing_msg_ids()
This API allows to check if the message with given ID exists and distinguish between message not existing and database error. It might also be faster than checking messages one by one if multiple messages need to be checked because of using a single SQL transaction.
This commit is contained in:
@@ -1868,6 +1868,33 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> Result<()>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Checks if the messages with given IDs exist.
|
||||
///
|
||||
/// Returns IDs of existing messages.
|
||||
pub async fn get_existing_msg_ids(context: &Context, ids: &[MsgId]) -> Result<Vec<MsgId>> {
|
||||
let query_only = true;
|
||||
let res = context
|
||||
.sql
|
||||
.transaction_ex(query_only, |transaction| {
|
||||
let mut res: Vec<MsgId> = Vec::new();
|
||||
for id in ids {
|
||||
if transaction.query_one(
|
||||
"SELECT COUNT(*) > 0 FROM msgs WHERE id=? AND chat_id!=3",
|
||||
(id,),
|
||||
|row| {
|
||||
let exists: bool = row.get(0)?;
|
||||
Ok(exists)
|
||||
},
|
||||
)? {
|
||||
res.push(*id);
|
||||
}
|
||||
}
|
||||
Ok(res)
|
||||
})
|
||||
.await?;
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
pub(crate) async fn update_msg_state(
|
||||
context: &Context,
|
||||
msg_id: MsgId,
|
||||
|
||||
Reference in New Issue
Block a user