diff --git a/src/chat.rs b/src/chat.rs index e6c1fa5a1..445a0efe9 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1798,7 +1798,7 @@ impl Chat { /// Returns chat avatar color. /// /// For 1:1 chats, the color is calculated from the contact's address. - /// For group chats the color is calculated from the chat name. + /// For group chats the color is calculated from the grpid, if present, or the chat name. pub async fn get_color(&self, context: &Context) -> Result { let mut color = 0; @@ -1809,6 +1809,8 @@ impl Chat { color = contact.get_color(); } } + } else if !self.grpid.is_empty() { + color = str_to_color(&self.grpid); } else { color = str_to_color(&self.name); } diff --git a/src/chat/chat_tests.rs b/src/chat/chat_tests.rs index 34f1775ea..f83542766 100644 --- a/src/chat/chat_tests.rs +++ b/src/chat/chat_tests.rs @@ -1929,19 +1929,31 @@ async fn test_classic_email_chat() -> Result<()> { #[tokio::test(flavor = "multi_thread", worker_threads = 2)] 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 chat_id = create_group_ex(&t, None, "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 chat_id = create_group_ex(&t, None, "A CHAT").await?; let color2 = Chat::load_from_db(&t, chat_id).await?.get_color(&t).await?; assert_ne!(color2, color1); Ok(()) } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_chat_get_color_encrypted() -> Result<()> { + let mut tcm = TestContextManager::new(); + let t = &tcm.alice().await; + let chat_id = create_group_ex(t, Some(ProtectionStatus::Unprotected), "a chat").await?; + let color1 = Chat::load_from_db(t, chat_id).await?.get_color(t).await?; + set_chat_name(t, chat_id, "A CHAT").await?; + let color2 = Chat::load_from_db(t, chat_id).await?.get_color(t).await?; + assert_eq!(color2, color1); + Ok(()) +} + async fn test_sticker( filename: &str, bytes: &[u8],