diff --git a/CHANGELOG.md b/CHANGELOG.md index b0d5ac441..0937a2157 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ ### Fixes - node: throw error when getting context with an invalid account id - node: throw error when instanciating a wrapper class on `null` (Context, Message, Chat, ChatList and so on) +- use same contact-color if email address differ only in upper-/lowercase #3327 ### Removed - node: remove unmaintained coverage scripts diff --git a/src/chat.rs b/src/chat.rs index 55c815d77..83f7b61fb 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -4905,6 +4905,22 @@ mod tests { Ok(()) } + #[async_std::test] + async fn test_chat_get_color() -> Result<()> { + let t = TestContext::new().await; + let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "a chat").await?; + let color1 = Chat::load_from_db(&t, chat_id).await?.get_color(&t).await?; + assert_eq!(color1, 0x008772); + + // upper-/lowercase makes a difference for the colors, these are different groups + // (in contrast to email addresses, where upper-/lowercase is ignored in practise) + let t = TestContext::new().await; + let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "A CHAT").await?; + let color2 = Chat::load_from_db(&t, chat_id).await?.get_color(&t).await?; + assert_ne!(color2, color1); + Ok(()) + } + async fn test_sticker(filename: &str, bytes: &[u8], w: i32, h: i32) -> Result<()> { let alice = TestContext::new_alice().await; let bob = TestContext::new_bob().await; diff --git a/src/contact.rs b/src/contact.rs index 54f8ab468..72a5c66df 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1082,7 +1082,7 @@ impl Contact { /// and can be used for an fallback avatar with white initials /// as well as for headlines in bubbles of group chats. pub fn get_color(&self) -> u32 { - str_to_color(&self.addr) + str_to_color(&self.addr.to_lowercase()) } /// Gets the contact's status. @@ -1946,6 +1946,25 @@ mod tests { assert_eq!(id, Some(ContactId::SELF)); } + #[async_std::test] + async fn test_contact_get_color() -> Result<()> { + let t = TestContext::new().await; + let contact_id = Contact::create(&t, "name", "name@example.net").await?; + let color1 = Contact::get_by_id(&t, contact_id).await?.get_color(); + assert_eq!(color1, 0xA739FF); + + let t = TestContext::new().await; + let contact_id = Contact::create(&t, "prename name", "name@example.net").await?; + let color2 = Contact::get_by_id(&t, contact_id).await?.get_color(); + assert_eq!(color2, color1); + + let t = TestContext::new().await; + let contact_id = Contact::create(&t, "Name", "nAme@exAmple.NET").await?; + let color3 = Contact::get_by_id(&t, contact_id).await?.get_color(); + assert_eq!(color3, color1); + Ok(()) + } + #[async_std::test] async fn test_contact_get_encrinfo() -> Result<()> { let alice = TestContext::new_alice().await;