From ea385fabae2384dc414e4492034f505718b01250 Mon Sep 17 00:00:00 2001 From: link2xt Date: Mon, 11 Nov 2024 16:51:11 +0000 Subject: [PATCH] fix(deltachat-jsonrpc): do not fail `get_chatlist_items_by_entries` if the message got deleted The message may be deleted while chatlist item is loading. In this case displaying "No messages" is better than failing. Ideally loading of the chatlist item should happen in 1 database transaction and always return some message if chat is not empty, but this requires large refactoring. --- deltachat-jsonrpc/src/api/types/chat_list.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/deltachat-jsonrpc/src/api/types/chat_list.rs b/deltachat-jsonrpc/src/api/types/chat_list.rs index 4b39a17be..5a4e2cf26 100644 --- a/deltachat-jsonrpc/src/api/types/chat_list.rs +++ b/deltachat-jsonrpc/src/api/types/chat_list.rs @@ -88,11 +88,17 @@ pub(crate) async fn get_chat_list_item_by_id( let (last_updated, message_type) = match last_msgid { Some(id) => { - let last_message = deltachat::message::Message::load_from_db(ctx, id).await?; - ( - Some(last_message.get_timestamp() * 1000), - Some(last_message.get_viewtype().into()), - ) + if let Some(last_message) = + deltachat::message::Message::load_from_db_optional(ctx, id).await? + { + ( + Some(last_message.get_timestamp() * 1000), + Some(last_message.get_viewtype().into()), + ) + } else { + // Message may be deleted by the time we try to load it. + (None, None) + } } None => (None, None), };