mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
fix: do not ignore Message::load_from_db errors
This commit is contained in:
@@ -459,7 +459,19 @@ impl Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Loads message with given ID from the database.
|
/// Loads message with given ID from the database.
|
||||||
|
///
|
||||||
|
/// Returns an error if the message does not exist.
|
||||||
pub async fn load_from_db(context: &Context, id: MsgId) -> Result<Message> {
|
pub async fn load_from_db(context: &Context, id: MsgId) -> Result<Message> {
|
||||||
|
let message = Self::load_from_db_optional(context, id)
|
||||||
|
.await?
|
||||||
|
.context("Message {id} does not exist")?;
|
||||||
|
Ok(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Loads message with given ID from the database.
|
||||||
|
///
|
||||||
|
/// Returns `None` if the message does not exist.
|
||||||
|
pub async fn load_from_db_optional(context: &Context, id: MsgId) -> Result<Option<Message>> {
|
||||||
ensure!(
|
ensure!(
|
||||||
!id.is_special(),
|
!id.is_special(),
|
||||||
"Can not load special message ID {} from DB",
|
"Can not load special message ID {} from DB",
|
||||||
@@ -467,7 +479,7 @@ impl Message {
|
|||||||
);
|
);
|
||||||
let msg = context
|
let msg = context
|
||||||
.sql
|
.sql
|
||||||
.query_row(
|
.query_row_optional(
|
||||||
concat!(
|
concat!(
|
||||||
"SELECT",
|
"SELECT",
|
||||||
" m.id AS id,",
|
" m.id AS id,",
|
||||||
|
|||||||
@@ -348,7 +348,9 @@ impl Chat {
|
|||||||
// The message reacted to may be deleted physically (`load_from_db()` fails) or marked as a tombstone (`is_trash()`).
|
// The message reacted to may be deleted physically (`load_from_db()` fails) or marked as a tombstone (`is_trash()`).
|
||||||
// These are no errors as `Param::LastReaction*` are just weak pointers.
|
// These are no errors as `Param::LastReaction*` are just weak pointers.
|
||||||
// Instead, just return `Ok(None)` and let the caller create another summary.
|
// Instead, just return `Ok(None)` and let the caller create another summary.
|
||||||
if let Ok(reaction_msg) = Message::load_from_db(context, reaction_msg_id).await {
|
if let Some(reaction_msg) =
|
||||||
|
Message::load_from_db_optional(context, reaction_msg_id).await?
|
||||||
|
{
|
||||||
if !reaction_msg.chat_id.is_trash() {
|
if !reaction_msg.chat_id.is_trash() {
|
||||||
let reaction_contact_id = ContactId::new(
|
let reaction_contact_id = ContactId::new(
|
||||||
self.param
|
self.param
|
||||||
|
|||||||
Reference in New Issue
Block a user