Compare commits

...

5 Commits

Author SHA1 Message Date
Hocuri
b39abc84d3 No need to set the origin anymore 2025-01-06 15:45:11 +01:00
Hocuri
057501cacd Revert the refactoring for now, it maybe things too difficult to review 2025-01-06 15:44:39 +01:00
Hocuri
1f82241465 Fix all tests 2025-01-06 15:32:04 +01:00
Hocuri
9b7e740926 Fix almost all test failures. One of the failures is real, though. 2025-01-06 14:50:40 +01:00
Hocuri
84456e510b Add tilde if origin<ManuallyCreated, fix some tests 2025-01-05 23:08:42 +01:00
16 changed files with 64 additions and 64 deletions

View File

@@ -661,7 +661,7 @@ mod tests {
let contacts = get_chat_contacts(&t, chat_id).await?;
let contact_id = *contacts.first().unwrap();
let chat = Chat::load_from_db(&t, chat_id).await?;
assert_eq!(chat.get_name(), "Bob Authname");
assert_eq!(chat.get_name(), "~Bob Authname");
// check, the one-to-one-chat can be found using chatlist search query
let chats = Chatlist::try_load(&t, 0, Some("bob authname"), None).await?;
@@ -682,7 +682,7 @@ mod tests {
let test_id = Contact::create(&t, "", "bob@example.org").await?;
assert_eq!(contact_id, test_id);
let chat = Chat::load_from_db(&t, chat_id).await?;
assert_eq!(chat.get_name(), "Bob Authname");
assert_eq!(chat.get_name(), "~Bob Authname");
let chats = Chatlist::try_load(&t, 0, Some("bob authname"), None).await?;
assert_eq!(chats.len(), 1);
let chats = Chatlist::try_load(&t, 0, Some("bob nickname"), None).await?;

View File

@@ -921,7 +921,7 @@ impl Contact {
let chat_name = if !name.is_empty() {
name
} else if !authname.is_empty() {
authname
format!("~{}", authname)
} else {
addr
};
@@ -1365,14 +1365,14 @@ impl Contact {
///
/// This name is typically used in lists.
/// To get the name editable in a formular, use `Contact::get_name`.
pub fn get_display_name(&self) -> &str {
pub fn get_display_name(&self) -> String {
if !self.name.is_empty() {
return &self.name;
return self.name.clone();
}
if !self.authname.is_empty() {
return &self.authname;
return format!("~{}", self.authname);
}
&self.addr
self.addr.clone()
}
/// Get a summary of authorized name and address.
@@ -1404,7 +1404,7 @@ impl Contact {
if !self.name.is_empty() {
format!("{} ({})", self.name, self.addr)
} else if !self.authname.is_empty() {
format!("{} ({})", self.authname, self.addr)
format!("~{} ({})", self.authname, self.addr)
} else {
(&self.addr).into()
}
@@ -2053,7 +2053,7 @@ mod tests {
let contact = Contact::get_by_id(&context.ctx, id).await.unwrap();
assert_eq!(contact.get_name(), "");
assert_eq!(contact.get_authname(), "bob");
assert_eq!(contact.get_display_name(), "bob");
assert_eq!(contact.get_display_name(), "~bob");
// Search by name.
let contacts = Contact::get_all(&context.ctx, 0, Some("bob")).await?;
@@ -2185,7 +2185,7 @@ mod tests {
assert_eq!(contact_id, contact_id_test);
assert_eq!(sth_modified, Modifier::Modified);
let contact = Contact::get_by_id(&t, contact_id).await.unwrap();
assert_eq!(contact.get_name_n_addr(), "m. serious (three@drei.sam)");
assert_eq!(contact.get_name_n_addr(), "~m. serious (three@drei.sam)");
assert!(!contact.is_blocked());
// manually edit name of third contact (does not changed authorized name)
@@ -2276,14 +2276,14 @@ mod tests {
)
.await?;
let chat_id = t.get_last_msg().await.get_chat_id();
assert_eq!(Chat::load_from_db(&t, chat_id).await?.name, "Flobbyfoo");
assert_eq!(Chat::load_from_db(&t, chat_id).await?.name, "~Flobbyfoo");
let chatlist = Chatlist::try_load(&t, 0, Some("flobbyfoo"), None).await?;
assert_eq!(chatlist.len(), 1);
let contact = Contact::get_by_id(&t, *contact_id).await?;
assert_eq!(contact.get_authname(), "Flobbyfoo");
assert_eq!(contact.get_name(), "");
assert_eq!(contact.get_display_name(), "Flobbyfoo");
assert_eq!(contact.get_name_n_addr(), "Flobbyfoo (f@example.org)");
assert_eq!(contact.get_display_name(), "~Flobbyfoo");
assert_eq!(contact.get_name_n_addr(), "~Flobbyfoo (f@example.org)");
let contacts = Contact::get_all(&t, 0, Some("f@example.org")).await?;
assert_eq!(contacts.len(), 1);
let contacts = Contact::get_all(&t, 0, Some("flobbyfoo")).await?;
@@ -2304,7 +2304,7 @@ mod tests {
)
.await?;
let chat_id = t.get_last_msg().await.get_chat_id();
assert_eq!(Chat::load_from_db(&t, chat_id).await?.name, "Foo Flobby");
assert_eq!(Chat::load_from_db(&t, chat_id).await?.name, "~Foo Flobby");
let chatlist = Chatlist::try_load(&t, 0, Some("Flobbyfoo"), None).await?;
assert_eq!(chatlist.len(), 0);
let chatlist = Chatlist::try_load(&t, 0, Some("Foo Flobby"), None).await?;
@@ -2312,8 +2312,8 @@ mod tests {
let contact = Contact::get_by_id(&t, *contact_id).await?;
assert_eq!(contact.get_authname(), "Foo Flobby");
assert_eq!(contact.get_name(), "");
assert_eq!(contact.get_display_name(), "Foo Flobby");
assert_eq!(contact.get_name_n_addr(), "Foo Flobby (f@example.org)");
assert_eq!(contact.get_display_name(), "~Foo Flobby");
assert_eq!(contact.get_name_n_addr(), "~Foo Flobby (f@example.org)");
let contacts = Contact::get_all(&t, 0, Some("f@example.org")).await?;
assert_eq!(contacts.len(), 1);
let contacts = Contact::get_all(&t, 0, Some("flobbyfoo")).await?;
@@ -2439,7 +2439,7 @@ mod tests {
let contact = Contact::get_by_id(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), "bob1");
assert_eq!(contact.get_name(), "");
assert_eq!(contact.get_display_name(), "bob1");
assert_eq!(contact.get_display_name(), "~bob1");
// incoming mail `From: bob2 <bob@example.org>` - this should update authname
let (contact_id, sth_modified) = Contact::add_or_lookup(
@@ -2455,7 +2455,7 @@ mod tests {
let contact = Contact::get_by_id(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), "bob2");
assert_eq!(contact.get_name(), "");
assert_eq!(contact.get_display_name(), "bob2");
assert_eq!(contact.get_display_name(), "~bob2");
// manually edit name to "bob3" - authname should be still be "bob2" as given in `From:` above
let contact_id = Contact::create(&t, "bob3", "bob@example.org")
@@ -2510,7 +2510,7 @@ mod tests {
let contact = Contact::get_by_id(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), "claire1");
assert_eq!(contact.get_name(), "");
assert_eq!(contact.get_display_name(), "claire1");
assert_eq!(contact.get_display_name(), "~claire1");
// incoming mail `From: claire2 <claire@example.org>` - this should update authname
let (contact_id_same, sth_modified) = Contact::add_or_lookup(
@@ -2526,7 +2526,7 @@ mod tests {
let contact = Contact::get_by_id(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), "claire2");
assert_eq!(contact.get_name(), "");
assert_eq!(contact.get_display_name(), "claire2");
assert_eq!(contact.get_display_name(), "~claire2");
}
/// Regression test.
@@ -2547,7 +2547,7 @@ mod tests {
.await?;
assert_eq!(sth_modified, Modifier::Created);
let contact = Contact::get_by_id(&t, contact_id).await?;
assert_eq!(contact.get_display_name(), "Bob");
assert_eq!(contact.get_display_name(), "~Bob");
// Incoming message from someone else with "Not Bob" <bob@example.org> in the "To:" field.
let (contact_id_same, sth_modified) = Contact::add_or_lookup(
@@ -2560,7 +2560,7 @@ mod tests {
assert_eq!(contact_id, contact_id_same);
assert_eq!(sth_modified, Modifier::Modified);
let contact = Contact::get_by_id(&t, contact_id).await?;
assert_eq!(contact.get_display_name(), "Not Bob");
assert_eq!(contact.get_display_name(), "~Not Bob");
// Incoming message from Bob, changing the name back.
let (contact_id_same, sth_modified) = Contact::add_or_lookup(
@@ -2573,7 +2573,7 @@ mod tests {
assert_eq!(contact_id, contact_id_same);
assert_eq!(sth_modified, Modifier::Modified); // This was None until the bugfix
let contact = Contact::get_by_id(&t, contact_id).await?;
assert_eq!(contact.get_display_name(), "Bob");
assert_eq!(contact.get_display_name(), "~Bob");
Ok(())
}
@@ -2610,7 +2610,7 @@ mod tests {
let contact = Contact::get_by_id(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), "dave2");
assert_eq!(contact.get_name(), "");
assert_eq!(contact.get_display_name(), "dave2");
assert_eq!(contact.get_display_name(), "~dave2");
}
#[test]

View File

@@ -241,7 +241,7 @@ mod test_chatlist_events {
.await;
bob.recv_msg(&sent_msg).await;
let alice_on_bob = bob.add_or_lookup_contact(&alice).await;
assert!(alice_on_bob.get_display_name() == "Alice");
assert_eq!(alice_on_bob.get_display_name(), "~Alice");
wait_for_chatlist_all_items(&bob).await;

View File

@@ -230,7 +230,7 @@ impl MsgId {
let name = from_contact.get_name_n_addr();
if let Some(override_sender_name) = msg.get_override_sender_name() {
let addr = from_contact.get_addr();
ret += &format!(" by ~{override_sender_name} ({addr})");
ret += &format!(" by {override_sender_name} ({addr})");
} else {
ret += &format!(" by {name}");
}
@@ -895,7 +895,7 @@ impl Message {
pub fn get_override_sender_name(&self) -> Option<String> {
self.param
.get(Param::OverrideSenderDisplayname)
.map(|name| name.to_string())
.map(|name| format!("~{name}"))
}
// Exposing this function over the ffi instead of get_override_sender_name() would mean that at least Android Java code has
@@ -2437,10 +2437,10 @@ mod tests {
msg.set_override_sender_name(Some("over ride".to_string()));
assert_eq!(
msg.get_override_sender_name(),
Some("over ride".to_string())
Some("~over ride".to_string())
);
assert_eq!(msg.get_sender_name(&contact), "over ride".to_string());
assert_ne!(contact.get_display_name(), "over ride".to_string());
assert_eq!(msg.get_sender_name(&contact), "~over ride".to_string());
assert_ne!(contact.get_display_name(), "~over ride".to_string());
chat::send_msg(&alice, chat.id, &mut msg).await.unwrap();
let sent_msg = alice.pop_sent_msg().await;
@@ -2457,10 +2457,10 @@ mod tests {
assert_eq!(msg.text, "bla blubb");
assert_eq!(
msg.get_override_sender_name(),
Some("over ride".to_string())
Some("~over ride".to_string())
);
assert_eq!(msg.get_sender_name(&contact), "over ride".to_string());
assert_ne!(contact.get_display_name(), "over ride".to_string());
assert_eq!(msg.get_sender_name(&contact), "~over ride".to_string());
assert_ne!(contact.get_display_name(), "~over ride".to_string());
// explicitly check that the message does not create a mailing list
// (mailing lists may also use `Sender:`-header)
@@ -2471,7 +2471,7 @@ mod tests {
let msg = alice2.recv_msg(&sent_msg).await;
assert_eq!(
msg.get_override_sender_name(),
Some("over ride".to_string())
Some("~over ride".to_string())
);
}

View File

@@ -664,7 +664,7 @@ impl Peerstate {
let old_contact = Contact::get_by_id(context, contact_id).await?;
stock_str::aeap_addr_changed(
context,
old_contact.get_display_name(),
&old_contact.get_display_name(),
&self.addr,
new_addr,
)

View File

@@ -731,7 +731,7 @@ Here's my footer -- bob@example.net"
assert_eq!(summary.state, MessageState::InFresh); // state refers to message, not to reaction
assert!(summary.prefix.is_none());
assert!(summary.thumbnail_path.is_none());
assert_summary(&alice, "BOB reacted 👍 to \"Party?\"").await;
assert_summary(&alice, "~BOB reacted 👍 to \"Party?\"").await;
// Alice reacts to own message as well
SystemTime::shift(Duration::from_secs(10));
@@ -742,7 +742,7 @@ Here's my footer -- bob@example.net"
expect_no_unwanted_events(&bob).await;
assert_summary(&alice, "You reacted 🍿 to \"Party?\"").await;
assert_summary(&bob, "ALICE reacted 🍿 to \"Party?\"").await;
assert_summary(&bob, "~ALICE reacted 🍿 to \"Party?\"").await;
// Alice sends a newer message, this overwrites reaction summaries
SystemTime::shift(Duration::from_secs(10));
@@ -759,7 +759,7 @@ Here's my footer -- bob@example.net"
bob.recv_msg_opt(&alice_send_reaction).await;
assert_summary(&alice, "You reacted 🤘 to \"Party?\"").await;
assert_summary(&bob, "ALICE reacted 🤘 to \"Party?\"").await;
assert_summary(&bob, "~ALICE reacted 🤘 to \"Party?\"").await;
// Retracted reactions remove all summary reactions
SystemTime::shift(Duration::from_secs(10));

View File

@@ -165,7 +165,7 @@ async fn test_adhoc_group_show_accepted_contact_accepted() {
chat_id.accept(&t).await.unwrap();
let chat = chat::Chat::load_from_db(&t, chat_id).await.unwrap();
assert_eq!(chat.typ, Chattype::Single);
assert_eq!(chat.name, "Bob");
assert_eq!(chat.name, "~Bob");
assert_eq!(chat::get_chat_contacts(&t, chat_id).await.unwrap().len(), 1);
assert_eq!(chat::get_chat_msgs(&t, chat_id).await.unwrap().len(), 1);
@@ -584,7 +584,7 @@ async fn test_escaped_recipients() {
.unwrap();
let contact = Contact::get_by_id(&t, carl_contact_id).await.unwrap();
assert_eq!(contact.get_name(), "");
assert_eq!(contact.get_display_name(), "h2");
assert_eq!(contact.get_display_name(), "~h2");
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
let msg = Message::load_from_db(&t, chats.get_msg_id(0).unwrap().unwrap())
@@ -631,7 +631,7 @@ async fn test_cc_to_contact() {
.unwrap();
let contact = Contact::get_by_id(&t, carl_contact_id).await.unwrap();
assert_eq!(contact.get_name(), "");
assert_eq!(contact.get_display_name(), "Carl");
assert_eq!(contact.get_display_name(), "~Carl");
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
@@ -1011,8 +1011,8 @@ async fn test_github_mailing_list() -> Result<()> {
let contact2 = Contact::get_by_id(&t.ctx, msg2.from_id).await?;
assert_eq!(contact2.get_addr(), "notifications@github.com");
assert_eq!(msg1.get_override_sender_name().unwrap(), "Max Mustermann");
assert_eq!(msg2.get_override_sender_name().unwrap(), "Github");
assert_eq!(msg1.get_override_sender_name().unwrap(), "~Max Mustermann");
assert_eq!(msg2.get_override_sender_name().unwrap(), "~Github");
Ok(())
}
@@ -2077,7 +2077,7 @@ async fn check_alias_reply(from_dc: bool, chat_request: bool, group_request: boo
}
assert_eq!(
answer.get_override_sender_name().unwrap(),
"bob@example.net"
"~bob@example.net"
); // Bob is not part of the group, so override-sender-name should be set
// Check that Claire also gets the message in the same chat.
@@ -2089,7 +2089,7 @@ async fn check_alias_reply(from_dc: bool, chat_request: bool, group_request: boo
assert_eq!(answer.chat_id, request.chat_id);
assert_eq!(
answer.get_override_sender_name().unwrap(),
"bob@example.net"
"~bob@example.net"
);
}
@@ -2313,12 +2313,12 @@ Second signature";
receive_imf(&alice, first_message, false).await?;
let contact = Contact::get_by_id(&alice, bob_contact_id).await?;
assert_eq!(contact.get_status(), "First signature");
assert_eq!(contact.get_display_name(), "Bob1");
assert_eq!(contact.get_display_name(), "~Bob1");
receive_imf(&alice, second_message, false).await?;
let contact = Contact::get_by_id(&alice, bob_contact_id).await?;
assert_eq!(contact.get_status(), "Second signature");
assert_eq!(contact.get_display_name(), "Bob2");
assert_eq!(contact.get_display_name(), "~Bob2");
// Duplicate message, should be ignored
receive_imf(&alice, first_message, false).await?;
@@ -2326,7 +2326,7 @@ Second signature";
// No change because last message is duplicate of the first.
let contact = Contact::get_by_id(&alice, bob_contact_id).await?;
assert_eq!(contact.get_status(), "Second signature");
assert_eq!(contact.get_display_name(), "Bob2");
assert_eq!(contact.get_display_name(), "~Bob2");
Ok(())
}
@@ -5230,7 +5230,7 @@ async fn test_list_from() -> Result<()> {
let raw = include_bytes!("../../test-data/message/list-from.eml");
let received = receive_imf(t, raw, false).await?.unwrap();
let msg = Message::load_from_db(t, *received.msg_ids.last().unwrap()).await?;
assert_eq!(msg.get_override_sender_name().unwrap(), "ÖAMTC");
assert_eq!(msg.get_override_sender_name().unwrap(), "~ÖAMTC");
let sender_contact = Contact::get_by_id(t, msg.from_id).await?;
assert_eq!(
sender_contact.get_display_name(),

View File

@@ -822,7 +822,7 @@ pub(crate) async fn secure_join_started(
translated(context, StockMessage::SecureJoinStarted)
.await
.replace1(&contact.get_name_n_addr())
.replace2(contact.get_display_name())
.replace2(&contact.get_display_name())
} else {
format!("secure_join_started: unknown contact {inviter_contact_id}")
}

View File

@@ -770,7 +770,7 @@ impl TestContext {
} else {
assert_eq!(
actual, expected,
"To update the expected value, run `UPDATE_GOLDEN_TESTS=1 cargo test`"
"To update the expected value, run `UPDATE_GOLDEN_TESTS=1 cargo nextest run`"
);
}
}

View File

@@ -288,7 +288,8 @@ async fn check_that_transition_worked(
let info_msg = get_last_info_msg(bob, *group).await.unwrap();
let expected_text =
stock_str::aeap_addr_changed(bob, name, old_alice_addr, new_alice_addr).await;
stock_str::aeap_addr_changed(bob, &format!("{name}"), old_alice_addr, new_alice_addr)
.await;
assert_eq!(info_msg.text, expected_text);
assert_eq!(info_msg.from_id, ContactId::INFO);

View File

@@ -947,8 +947,7 @@ async fn test_no_unencrypted_name_if_encrypted() -> Result<()> {
let msg = alice.recv_msg(msg).await;
let contact = Contact::get_by_id(&alice, msg.from_id).await?;
assert_eq!(Contact::get_display_name(&contact), "Bob Smith");
assert_eq!(Contact::get_display_name(&contact), "~Bob Smith");
}
Ok(())
}

View File

@@ -1,6 +1,6 @@
Single#Chat#10: Bob [bob@example.net]
Single#Chat#10: ~Bob [bob@example.net]
--------------------------------------------------------------------------------
Msg#10: info (Contact#Contact#Info): Messages are guaranteed to be end-to-end encrypted from now on. [NOTICED][INFO 🛡️]
Msg#11: info (Contact#Contact#Info): Bob sent a message from another device. [NOTICED][INFO 🛡️❌]
Msg#11: info (Contact#Contact#Info): ~Bob sent a message from another device. [NOTICED][INFO 🛡️❌]
Msg#12: (Contact#Contact#10): Message from Thunderbird [SEEN]
--------------------------------------------------------------------------------

View File

@@ -1,7 +1,7 @@
Single#Chat#10: Bob [bob@example.net]
Single#Chat#10: ~Bob [bob@example.net]
--------------------------------------------------------------------------------
Msg#10: info (Contact#Contact#Info): Messages are guaranteed to be end-to-end encrypted from now on. [NOTICED][INFO 🛡️]
Msg#11: info (Contact#Contact#Info): Bob sent a message from another device. [NOTICED][INFO 🛡️❌]
Msg#11: info (Contact#Contact#Info): ~Bob sent a message from another device. [NOTICED][INFO 🛡️❌]
Msg#12: (Contact#Contact#10): Somewhat old message [FRESH]
Msg#13: (Contact#Contact#10): Even older message, that must NOT be shown before the info message [SEEN]
--------------------------------------------------------------------------------

View File

@@ -1,8 +1,8 @@
Single#Chat#10: Bob [bob@example.net] 🛡️
Single#Chat#10: ~Bob [bob@example.net] 🛡️
--------------------------------------------------------------------------------
Msg#10: info (Contact#Contact#Info): Messages are guaranteed to be end-to-end encrypted from now on. [NOTICED][INFO 🛡️]
Msg#11🔒: (Contact#Contact#10): Heyho from my verified device! [FRESH]
Msg#12: info (Contact#Contact#Info): Bob sent a message from another device. [NOTICED][INFO 🛡️❌]
Msg#12: info (Contact#Contact#Info): ~Bob sent a message from another device. [NOTICED][INFO 🛡️❌]
Msg#13: (Contact#Contact#10): Old, unverified message [SEEN]
Msg#14: info (Contact#Contact#Info): Messages are guaranteed to be end-to-end encrypted from now on. [NOTICED][INFO 🛡️]
--------------------------------------------------------------------------------

View File

@@ -1,4 +1,4 @@
Single#Chat#10: Bob [bob@example.net]
Single#Chat#10: ~Bob [bob@example.net]
--------------------------------------------------------------------------------
Msg#10: Me (Contact#Contact#Self): Happy birthday, Bob! √
Msg#11: (Contact#Contact#10): Happy birthday to me, Alice! [FRESH]

View File

@@ -1,11 +1,11 @@
Single#Chat#10: Bob [bob@example.net] 🛡️
Single#Chat#10: ~Bob [bob@example.net] 🛡️
--------------------------------------------------------------------------------
Msg#10: info (Contact#Contact#Info): Messages are guaranteed to be end-to-end encrypted from now on. [NOTICED][INFO 🛡️]
Msg#11: info (Contact#Contact#Info): Bob sent a message from another device. [NOTICED][INFO 🛡️❌]
Msg#11: info (Contact#Contact#Info): ~Bob sent a message from another device. [NOTICED][INFO 🛡️❌]
Msg#12: (Contact#Contact#10): Message from Thunderbird [FRESH]
Msg#13: info (Contact#Contact#Info): Messages are guaranteed to be end-to-end encrypted from now on. [NOTICED][INFO 🛡️]
Msg#14🔒: (Contact#Contact#10): Hello from DC [FRESH]
Msg#15: info (Contact#Contact#Info): Bob sent a message from another device. [NOTICED][INFO 🛡️❌]
Msg#15: info (Contact#Contact#Info): ~Bob sent a message from another device. [NOTICED][INFO 🛡️❌]
Msg#16: (Contact#Contact#10): Message from Thunderbird [FRESH]
Msg#17: info (Contact#Contact#Info): Messages are guaranteed to be end-to-end encrypted from now on. [NOTICED][INFO 🛡️]
Msg#18🔒: (Contact#Contact#10): Hello from DC [FRESH]