mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
fix: do not fail to load chatlist summary if the message got removed
This commit is contained in:
@@ -394,25 +394,32 @@ impl Chatlist {
|
|||||||
&chat_loaded
|
&chat_loaded
|
||||||
};
|
};
|
||||||
|
|
||||||
let (lastmsg, lastcontact) = if let Some(lastmsg_id) = lastmsg_id {
|
let lastmsg = if let Some(lastmsg_id) = lastmsg_id {
|
||||||
let lastmsg = Message::load_from_db(context, lastmsg_id)
|
// Message may be deleted by the time we try to load it,
|
||||||
|
// so use `load_from_db_optional` instead of `load_from_db`.
|
||||||
|
Message::load_from_db_optional(context, lastmsg_id)
|
||||||
.await
|
.await
|
||||||
.context("loading message failed")?;
|
.context("Loading message failed")?
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let lastcontact = if let Some(lastmsg) = &lastmsg {
|
||||||
if lastmsg.from_id == ContactId::SELF {
|
if lastmsg.from_id == ContactId::SELF {
|
||||||
(Some(lastmsg), None)
|
None
|
||||||
} else {
|
} else {
|
||||||
match chat.typ {
|
match chat.typ {
|
||||||
Chattype::Group | Chattype::Broadcast | Chattype::Mailinglist => {
|
Chattype::Group | Chattype::Broadcast | Chattype::Mailinglist => {
|
||||||
let lastcontact = Contact::get_by_id(context, lastmsg.from_id)
|
let lastcontact = Contact::get_by_id(context, lastmsg.from_id)
|
||||||
.await
|
.await
|
||||||
.context("loading contact failed")?;
|
.context("loading contact failed")?;
|
||||||
(Some(lastmsg), Some(lastcontact))
|
Some(lastcontact)
|
||||||
}
|
}
|
||||||
Chattype::Single => (Some(lastmsg), None),
|
Chattype::Single => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(None, None)
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
if chat.id.is_archived_link() {
|
if chat.id.is_archived_link() {
|
||||||
@@ -761,6 +768,25 @@ mod tests {
|
|||||||
assert_eq!(summary.text, "foo: bar test"); // the linebreak should be removed from summary
|
assert_eq!(summary.text, "foo: bar test"); // the linebreak should be removed from summary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Tests that summary does not fail to load
|
||||||
|
/// if the draft was deleted after loading the chatlist.
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn test_get_summary_deleted_draft() {
|
||||||
|
let t = TestContext::new().await;
|
||||||
|
|
||||||
|
let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "a chat")
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let mut msg = Message::new_text("Foobar".to_string());
|
||||||
|
chat_id.set_draft(&t, Some(&mut msg)).await.unwrap();
|
||||||
|
|
||||||
|
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
|
||||||
|
chat_id.set_draft(&t, None).await.unwrap();
|
||||||
|
|
||||||
|
let summary_res = chats.get_summary(&t, 0, None).await;
|
||||||
|
assert!(summary_res.is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_load_broken() {
|
async fn test_load_broken() {
|
||||||
let t = TestContext::new_bob().await;
|
let t = TestContext::new_bob().await;
|
||||||
|
|||||||
Reference in New Issue
Block a user