diff --git a/src/chatlist.rs b/src/chatlist.rs index 85a6067fa..2d628be20 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -407,16 +407,17 @@ impl Chatlist { let lastcontact = if let Some(lastmsg) = &lastmsg { if lastmsg.from_id == ContactId::SELF { None + } else if chat.typ == Chattype::Group + || chat.typ == Chattype::Broadcast + || chat.typ == Chattype::Mailinglist + || chat.is_self_talk() + { + let lastcontact = Contact::get_by_id(context, lastmsg.from_id) + .await + .context("loading contact failed")?; + Some(lastcontact) } else { - match chat.typ { - Chattype::Group | Chattype::Broadcast | Chattype::Mailinglist => { - let lastcontact = Contact::get_by_id(context, lastmsg.from_id) - .await - .context("loading contact failed")?; - Some(lastcontact) - } - Chattype::Single => None, - } + None } } else { None @@ -479,6 +480,7 @@ pub async fn get_last_message_for_chat( #[cfg(test)] mod tests { use super::*; + use crate::chat::save_msgs; use crate::chat::{ add_contact_to_chat, create_group_chat, get_chat_contacts, remove_contact_from_chat, send_text_msg, ProtectionStatus, @@ -486,6 +488,7 @@ mod tests { use crate::receive_imf::receive_imf; use crate::stock_str::StockMessage; use crate::test_utils::TestContext; + use crate::test_utils::TestContextManager; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_try_load() { @@ -787,6 +790,31 @@ mod tests { assert!(summary_res.is_ok()); } + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_get_summary_for_saved_messages() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = tcm.alice().await; + let bob = tcm.bob().await; + let chat_alice = alice.create_chat(&bob).await; + + send_text_msg(&alice, chat_alice.id, "hi".into()).await?; + let sent1 = alice.pop_sent_msg().await; + save_msgs(&alice, &[sent1.sender_msg_id]).await?; + let chatlist = Chatlist::try_load(&alice, 0, None, None).await?; + let summary = chatlist.get_summary(&alice, 0, None).await?; + assert_eq!(summary.prefix.unwrap().to_string(), "Me"); + assert_eq!(summary.text, "hi"); + + let msg = bob.recv_msg(&sent1).await; + save_msgs(&bob, &[msg.id]).await?; + let chatlist = Chatlist::try_load(&bob, 0, None, None).await?; + let summary = chatlist.get_summary(&bob, 0, None).await?; + assert_eq!(summary.prefix.unwrap().to_string(), "alice@example.org"); + assert_eq!(summary.text, "hi"); + + Ok(()) + } + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_load_broken() { let t = TestContext::new_bob().await; diff --git a/src/summary.rs b/src/summary.rs index 2f0064c80..2f38c5d00 100644 --- a/src/summary.rs +++ b/src/summary.rs @@ -97,24 +97,25 @@ impl Summary { let prefix = if msg.state == MessageState::OutDraft { Some(SummaryPrefix::Draft(stock_str::draft(context).await)) } else if msg.from_id == ContactId::SELF { - if msg.is_info() || chat.is_self_talk() { + if msg.is_info() { None } else { Some(SummaryPrefix::Me(stock_str::self_msg(context).await)) } - } else { - match chat.typ { - Chattype::Group | Chattype::Broadcast | Chattype::Mailinglist => { - if msg.is_info() || contact.is_none() { - None - } else { - msg.get_override_sender_name() - .or_else(|| contact.map(|contact| msg.get_sender_name(contact))) - .map(SummaryPrefix::Username) - } - } - Chattype::Single => None, + } else if chat.typ == Chattype::Group + || chat.typ == Chattype::Broadcast + || chat.typ == Chattype::Mailinglist + || chat.is_self_talk() + { + if msg.is_info() || contact.is_none() { + None + } else { + msg.get_override_sender_name() + .or_else(|| contact.map(|contact| msg.get_sender_name(contact))) + .map(SummaryPrefix::Username) } + } else { + None }; let mut text = msg.get_summary_text(context).await;