mirror of
https://github.com/chatmail/core.git
synced 2026-05-06 16:36:59 +03:00
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.
This commit is contained in:
@@ -121,14 +121,14 @@ impl CommandApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_context_opt(&self, id: u32) -> Option<deltachat::context::Context> {
|
||||||
|
self.accounts.read().await.get_account(id)
|
||||||
|
}
|
||||||
|
|
||||||
async fn get_context(&self, id: u32) -> Result<deltachat::context::Context> {
|
async fn get_context(&self, id: u32) -> Result<deltachat::context::Context> {
|
||||||
let sc = self
|
self.get_context_opt(id)
|
||||||
.accounts
|
|
||||||
.read()
|
|
||||||
.await
|
.await
|
||||||
.get_account(id)
|
.ok_or_else(|| anyhow!("account with id {id} not found"))
|
||||||
.ok_or_else(|| anyhow!("account with id {id} not found"))?;
|
|
||||||
Ok(sc)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn with_state<F, T>(&self, id: u32, with_state: F) -> T
|
async fn with_state<F, T>(&self, id: u32, with_state: F) -> T
|
||||||
@@ -1307,13 +1307,18 @@ impl CommandApi {
|
|||||||
///
|
///
|
||||||
/// Returns IDs of existing messages.
|
/// Returns IDs of existing messages.
|
||||||
async fn get_existing_msg_ids(&self, account_id: u32, msg_ids: Vec<u32>) -> Result<Vec<u32>> {
|
async fn get_existing_msg_ids(&self, account_id: u32, msg_ids: Vec<u32>) -> Result<Vec<u32>> {
|
||||||
let context = self.get_context(account_id).await?;
|
if let Some(context) = self.get_context_opt(account_id).await {
|
||||||
let msg_ids: Vec<MsgId> = msg_ids.into_iter().map(MsgId::new).collect();
|
let msg_ids: Vec<MsgId> = msg_ids.into_iter().map(MsgId::new).collect();
|
||||||
let existing_msg_ids = get_existing_msg_ids(&context, &msg_ids).await?;
|
let existing_msg_ids = get_existing_msg_ids(&context, &msg_ids).await?;
|
||||||
Ok(existing_msg_ids
|
Ok(existing_msg_ids
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|msg_id| msg_id.to_u32())
|
.map(|msg_id| msg_id.to_u32())
|
||||||
.collect())
|
.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(
|
async fn get_message_list_items(
|
||||||
|
|||||||
Reference in New Issue
Block a user