mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 21:36:29 +03:00
fix(deltachat-jsonrpc): do not fail get_draft if draft is deleted
This commit is contained in:
@@ -1135,9 +1135,11 @@ impl CommandApi {
|
|||||||
async fn get_message(&self, account_id: u32, msg_id: u32) -> Result<MessageObject> {
|
async fn get_message(&self, account_id: u32, msg_id: u32) -> Result<MessageObject> {
|
||||||
let ctx = self.get_context(account_id).await?;
|
let ctx = self.get_context(account_id).await?;
|
||||||
let msg_id = MsgId::new(msg_id);
|
let msg_id = MsgId::new(msg_id);
|
||||||
MessageObject::from_msg_id(&ctx, msg_id)
|
let message_object = MessageObject::from_msg_id(&ctx, msg_id)
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("Failed to load message {msg_id} for account {account_id}"))
|
.with_context(|| format!("Failed to load message {msg_id} for account {account_id}"))?
|
||||||
|
.with_context(|| format!("Message {msg_id} does not exist for account {account_id}"))?;
|
||||||
|
Ok(message_object)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_message_html(&self, account_id: u32, message_id: u32) -> Result<Option<String>> {
|
async fn get_message_html(&self, account_id: u32, message_id: u32) -> Result<Option<String>> {
|
||||||
@@ -1161,7 +1163,10 @@ impl CommandApi {
|
|||||||
messages.insert(
|
messages.insert(
|
||||||
message_id,
|
message_id,
|
||||||
match message_result {
|
match message_result {
|
||||||
Ok(message) => MessageLoadResult::Message(message),
|
Ok(Some(message)) => MessageLoadResult::Message(message),
|
||||||
|
Ok(None) => MessageLoadResult::LoadingError {
|
||||||
|
error: "Message does not exist".to_string(),
|
||||||
|
},
|
||||||
Err(error) => MessageLoadResult::LoadingError {
|
Err(error) => MessageLoadResult::LoadingError {
|
||||||
error: format!("{error:#}"),
|
error: format!("{error:#}"),
|
||||||
},
|
},
|
||||||
@@ -1999,9 +2004,7 @@ impl CommandApi {
|
|||||||
async fn get_draft(&self, account_id: u32, chat_id: u32) -> Result<Option<MessageObject>> {
|
async fn get_draft(&self, account_id: u32, chat_id: u32) -> Result<Option<MessageObject>> {
|
||||||
let ctx = self.get_context(account_id).await?;
|
let ctx = self.get_context(account_id).await?;
|
||||||
if let Some(draft) = ChatId::new(chat_id).get_draft(&ctx).await? {
|
if let Some(draft) = ChatId::new(chat_id).get_draft(&ctx).await? {
|
||||||
Ok(Some(
|
Ok(MessageObject::from_msg_id(&ctx, draft.get_id()).await?)
|
||||||
MessageObject::from_msg_id(&ctx, draft.get_id()).await?,
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
@@ -2170,7 +2173,9 @@ impl CommandApi {
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
let msg_id = chat::send_msg(&ctx, ChatId::new(chat_id), &mut message).await?;
|
let msg_id = chat::send_msg(&ctx, ChatId::new(chat_id), &mut message).await?;
|
||||||
let message = MessageObject::from_msg_id(&ctx, msg_id).await?;
|
let message = MessageObject::from_msg_id(&ctx, msg_id)
|
||||||
|
.await?
|
||||||
|
.context("Just sent message does not exist")?;
|
||||||
Ok((msg_id.to_u32(), message))
|
Ok((msg_id.to_u32(), message))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,8 +112,10 @@ enum MessageQuote {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MessageObject {
|
impl MessageObject {
|
||||||
pub async fn from_msg_id(context: &Context, msg_id: MsgId) -> Result<Self> {
|
pub async fn from_msg_id(context: &Context, msg_id: MsgId) -> Result<Option<Self>> {
|
||||||
let message = Message::load_from_db(context, msg_id).await?;
|
let Some(message) = Message::load_from_db_optional(context, msg_id).await? else {
|
||||||
|
return Ok(None);
|
||||||
|
};
|
||||||
|
|
||||||
let sender_contact = Contact::get_by_id(context, message.get_from_id())
|
let sender_contact = Contact::get_by_id(context, message.get_from_id())
|
||||||
.await
|
.await
|
||||||
@@ -183,7 +185,7 @@ impl MessageObject {
|
|||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Ok(MessageObject {
|
let message_object = MessageObject {
|
||||||
id: msg_id.to_u32(),
|
id: msg_id.to_u32(),
|
||||||
chat_id: message.get_chat_id().to_u32(),
|
chat_id: message.get_chat_id().to_u32(),
|
||||||
from_id: message.get_from_id().to_u32(),
|
from_id: message.get_from_id().to_u32(),
|
||||||
@@ -244,7 +246,8 @@ impl MessageObject {
|
|||||||
reactions,
|
reactions,
|
||||||
|
|
||||||
vcard_contact: vcard_contacts.first().cloned(),
|
vcard_contact: vcard_contacts.first().cloned(),
|
||||||
})
|
};
|
||||||
|
Ok(Some(message_object))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user