Skip to content

Commit

Permalink
feat: show sender name in 'Saved Messages' summary (#6607)
Browse files Browse the repository at this point in the history
since <#5606>, 'Saved Messages' contain the sender name; therefore, show
the name in summaries as for groups
  • Loading branch information
r10s authored Mar 2, 2025
1 parent a50b435 commit ba0a7f1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 22 deletions.
46 changes: 37 additions & 9 deletions src/chatlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -479,13 +480,15 @@ 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,
};
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() {
Expand Down Expand Up @@ -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(), "[email protected]");
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;
Expand Down
27 changes: 14 additions & 13 deletions src/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ba0a7f1

Please sign in to comment.