From 8a7498a9a89d4169e81fa1333cff657122c41a9f Mon Sep 17 00:00:00 2001 From: link2xt Date: Thu, 27 Nov 2025 20:42:53 +0000 Subject: [PATCH] fix: handle the case when account does not exist in get_existing_msg_ids() If account is removed, this means the messages are removed as well. We do not reuse account IDs, so the account will not reappear. --- deltachat-jsonrpc/src/api.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/deltachat-jsonrpc/src/api.rs b/deltachat-jsonrpc/src/api.rs index 82e2bcc32..8fa77eb9d 100644 --- a/deltachat-jsonrpc/src/api.rs +++ b/deltachat-jsonrpc/src/api.rs @@ -121,14 +121,14 @@ impl CommandApi { } } + async fn get_context_opt(&self, id: u32) -> Option { + self.accounts.read().await.get_account(id) + } + async fn get_context(&self, id: u32) -> Result { - let sc = self - .accounts - .read() + self.get_context_opt(id) .await - .get_account(id) - .ok_or_else(|| anyhow!("account with id {id} not found"))?; - Ok(sc) + .ok_or_else(|| anyhow!("account with id {id} not found")) } async fn with_state(&self, id: u32, with_state: F) -> T @@ -1307,13 +1307,18 @@ impl CommandApi { /// /// Returns IDs of existing messages. async fn get_existing_msg_ids(&self, account_id: u32, msg_ids: Vec) -> Result> { - let context = self.get_context(account_id).await?; - let msg_ids: Vec = msg_ids.into_iter().map(MsgId::new).collect(); - let existing_msg_ids = get_existing_msg_ids(&context, &msg_ids).await?; - Ok(existing_msg_ids - .into_iter() - .map(|msg_id| msg_id.to_u32()) - .collect()) + if let Some(context) = self.get_context_opt(account_id).await { + let msg_ids: Vec = msg_ids.into_iter().map(MsgId::new).collect(); + let existing_msg_ids = get_existing_msg_ids(&context, &msg_ids).await?; + Ok(existing_msg_ids + .into_iter() + .map(|msg_id| msg_id.to_u32()) + .collect()) + } else { + // Account does not exist, so messages do not exist either, + // but this is not an error. + Ok(Vec::new()) + } } async fn get_message_list_items(