Skip to content

Commit

Permalink
fix(get_next_media): do not ignore load_from_db errors
Browse files Browse the repository at this point in the history
Use `Message::load_from_db_optional` so
actual errors like locked database
are not ignored.
  • Loading branch information
link2xt committed Oct 2, 2024
1 parent 4b021f5 commit 5b1b811
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3439,40 +3439,38 @@ pub async fn get_next_media(
msg_type2: Viewtype,
msg_type3: Viewtype,
) -> Result<Option<MsgId>> {
let mut ret: Option<MsgId> = 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<MsgId> = 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<MsgId> = 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.
Expand Down

0 comments on commit 5b1b811

Please sign in to comment.