-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show sender name in 'Saved Messages' summary (#6607)
since <#5606>, 'Saved Messages' contain the sender name; therefore, show the name in summaries as for groups
- Loading branch information
Showing
2 changed files
with
51 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,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() { | ||
|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters