From 5b1b8117e77771ff18b1afe81c580087423397f1 Mon Sep 17 00:00:00 2001 From: link2xt Date: Wed, 2 Oct 2024 23:23:56 +0000 Subject: [PATCH] fix(get_next_media): do not ignore `load_from_db` errors Use `Message::load_from_db_optional` so actual errors like locked database are not ignored. --- src/chat.rs | 56 ++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index a557df6e5b..548c240c01 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -3439,40 +3439,38 @@ pub async fn get_next_media( msg_type2: Viewtype, msg_type3: Viewtype, ) -> Result> { - let mut ret: Option = None; + let Some(msg) = Message::load_from_db_optional(context, curr_msg_id).await? else { + return Ok(None); + }; - if let Ok(msg) = Message::load_from_db(context, curr_msg_id).await { - let list: Vec = get_chat_media( - context, - Some(msg.chat_id), - if msg_type != Viewtype::Unknown { - msg_type - } else { - msg.viewtype - }, - msg_type2, - msg_type3, - ) - .await?; - for (i, msg_id) in list.iter().enumerate() { - if curr_msg_id == *msg_id { - match direction { - Direction::Forward => { - if i + 1 < list.len() { - ret = list.get(i + 1).copied(); - } - } - Direction::Backward => { - if i >= 1 { - ret = list.get(i - 1).copied(); - } + let list: Vec = get_chat_media( + context, + Some(msg.chat_id), + if msg_type != Viewtype::Unknown { + msg_type + } else { + msg.viewtype + }, + msg_type2, + msg_type3, + ) + .await?; + + for (i, msg_id) in list.iter().enumerate() { + if curr_msg_id == *msg_id { + return match direction { + Direction::Forward => Ok(list.get(i + 1).copied()), + Direction::Backward => { + if i >= 1 { + Ok(list.get(i - 1).copied()) + } else { + Ok(None) } } - break; - } + }; } } - Ok(ret) + Ok(None) } /// Returns a vector of contact IDs for given chat ID.