Skip to content

VCard color is different from contact color #7294

@WofWca

Description

@WofWca
  • Operating System (Linux/Mac/Windows/iOS/Android): All
  • Core Version: v2.17.0
  • Client Version: 2.15.0

Expected behavior

"Share contact" VCard color is the same as the eventual contact's color when you start a chat with that contact.

Actual behavior

The colors are different.

Steps to reproduce the problem

  1. Share a contact that has no avatar in a chat.

Screenshots

Image Image

The bug exists since 9af00af (#7134). The VCard color and contact color used to be the same, str_to_color(addr.to_lowercase()), but fell out of sync.

let color = color::str_to_color(&vc.addr.to_lowercase());

core/src/contact.rs

Lines 1577 to 1588 in af58b86

/// Get a color for the contact.
/// 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 {
if let Some(fingerprint) = self.fingerprint() {
str_to_color(&fingerprint.hex())
} else {
str_to_color(&self.addr.to_lowercase())
}
}

It would have been easy to fix, but apparently VCard doesn't have the "fingerprint" property, only a key:

/// A Contact, as represented in a VCard.
pub struct VcardContact {
/// The email address, vcard property `email`
pub addr: String,
/// This must be the name authorized by the contact itself, not a locally given name. Vcard
/// property `fn`. Can be empty, one should use `display_name()` to obtain the display name.
pub authname: String,
/// The contact's public PGP key in Base64, vcard property `key`
pub key: Option<String>,
/// The contact's profile image (=avatar) in Base64, vcard property `photo`
pub profile_image: Option<String>,
/// The biography, stored in the vcard property `note`
pub biography: Option<String>,
/// The timestamp when the vcard was created / last updated, vcard property `rev`
pub timestamp: Result<i64>,
}

I'm not sure if it's worth recalculating the fingerprint every time, or maybe it's better to store it together with the key.

core/src/contact.rs

Lines 339 to 355 in af58b86

let fingerprint;
if let Some(public_key) = key {
fingerprint = public_key.dc_fingerprint().hex();
context
.sql
.execute(
"INSERT INTO public_keys (fingerprint, public_key)
VALUES (?, ?)
ON CONFLICT (fingerprint)
DO NOTHING",
(&fingerprint, public_key.to_bytes()),
)
.await?;
} else {
fingerprint = String::new();
}

Metadata

Metadata

Assignees

Labels

bugSomething is not working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions