From 4010c60e7b6d00846fe23d688a4933ac4e9ca2df Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 26 Aug 2025 16:35:25 +0000 Subject: [PATCH] feat: use key fingerprints for color generation This way contact colors stays the same even if the address changes later. --- src/chat.rs | 3 ++- src/contact.rs | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 445a0efe9..e9d63e609 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1797,7 +1797,8 @@ impl Chat { /// Returns chat avatar color. /// - /// For 1:1 chats, the color is calculated from the contact's address. + /// For 1:1 chats, the color is calculated from the contact's address + /// for address-contacts and from the OpenPGP key fingerprint for key-contacts. /// 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; diff --git a/src/contact.rs b/src/contact.rs index 18893e98e..2eb8bda66 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1575,11 +1575,16 @@ impl Contact { } /// Get a color for the contact. - /// The color is calculated from the contact's email address - /// and can be used for an fallback avatar with white initials + /// The color is calculated from the contact's fingerprint (for key-contacts) + /// or email address (for address-contacts) 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.to_lowercase()) + if let Some(fingerprint) = self.fingerprint() { + str_to_color(&fingerprint.hex()) + } else { + str_to_color(&self.addr.to_lowercase()) + } } /// Gets the contact's status.