Skip to content

Conversation

@iequidoo
Copy link
Collaborator

@iequidoo iequidoo commented Nov 1, 2025

Contact::get_color() returns gray if own keypair doesn't exist yet and we don't want any UIs
displaying it. Keypair generation can't be done in get_color() or get_by_id_optional() to avoid
breaking Core tests on key import. Also this makes the API clearer, pure getters shouldn't modify
any visible state.

A previous failed attempt: #7289
Close #7374

@iequidoo iequidoo marked this pull request as draft November 1, 2025 19:10
@iequidoo iequidoo force-pushed the iequidoo/no-gray-self-color branch from 65c569d to ab8d5f3 Compare November 1, 2025 19:33
@iequidoo iequidoo marked this pull request as ready for review November 1, 2025 19:55
}
let ffi_contact = &*contact;
let ctx = &*ffi_contact.context;
if ffi_contact.contact.id == ContactId::SELF
Copy link
Collaborator

@link2xt link2xt Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic should go into Contact.get_color() or Contact loading code in deltachat crate, not into CFFI. This will also make it easy to test with a Rust test.

This issue also exists on Desktop and desktop is not using deltachat-ffi at all, so this does not fix the issue for dekstop. EDIT: did not notice that there is a similar fix in deltachat-jsonrpc, this will be unnecessary then.

Generally, no complex logic should go into deltachat-ffi and deltachat-jsonrpc crates, they are thin wrappers providing the APIs. deltachat-jsonrpc has a bit of logic here and there, but it is a bad example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the logic to Contact::get_color(). Already tried to generate own keypair in get_by_id() before and that broke Core tests on key import

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And even that didn't work. JSON-RPC tests call get_color() in unclear ways and instead of trying to understand how it happens i decided to add get_or_gen_color(), this makes the API clearer and protects tests on key import from future breakages

@iequidoo iequidoo force-pushed the iequidoo/no-gray-self-color branch from ab8d5f3 to 652a700 Compare November 7, 2025 09:25
@iequidoo iequidoo changed the title feat(ffi, jsonrpc): Ensure that own key exists before returning self-color (#7374) api!: Contact::get_color: Ensure that own key exists before returning self-color (#7374) Nov 7, 2025
@iequidoo iequidoo marked this pull request as draft November 7, 2025 09:41
@iequidoo iequidoo force-pushed the iequidoo/no-gray-self-color branch 2 times, most recently from bee79fd to 3e8496f Compare November 8, 2025 01:30
@iequidoo iequidoo changed the title api!: Contact::get_color: Ensure that own key exists before returning self-color (#7374) feat: Add Contact::get_or_gen_color. Use it in CFFI and JSON-RPC to avoid gray self-color (#7374) Nov 8, 2025
…void gray self-color (#7374)

`Contact::get_color()` returns gray if own keypair doesn't exist yet and we don't want any UIs
displaying it. Keypair generation can't be done in `get_color()` or `get_by_id_optional()` to avoid
breaking Core tests on key import. Also this makes the API clearer, pure getters shouldn't modify
any visible state.
@iequidoo iequidoo force-pushed the iequidoo/no-gray-self-color branch from 3e8496f to e3ddcb4 Compare November 8, 2025 01:33
@iequidoo iequidoo marked this pull request as ready for review November 8, 2025 01:37
@link2xt
Copy link
Collaborator

link2xt commented Nov 8, 2025

For rustfmt issue on the main, it is fixed in the first commit of #7420

@iequidoo iequidoo requested a review from link2xt November 8, 2025 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unstable appearing fallback avatar

3 participants