Skip to content

Commit 1da8e0f

Browse files
committed
api: Emit AccountsItemChanged when own key is generated/imported, use gray self-color until that (#7296)
Emitting an `AccountsItemChanged` event is needed for UIs to know when `Contact::get_color()` starts returning the true color for `SELF`. Before, an address-based color was returned for a new account which was changing to a fingerprint-based color e.g. on app restart. Now the self-color is our favorite gray until own keypair is generated or imported e.g. via ASM.
1 parent 87035ff commit 1da8e0f

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/contact.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,8 @@ impl Contact {
15821582
pub fn get_color(&self) -> u32 {
15831583
if let Some(fingerprint) = self.fingerprint() {
15841584
str_to_color(&fingerprint.hex())
1585+
} else if self.id == ContactId::SELF {
1586+
0x808080
15851587
} else {
15861588
str_to_color(&self.addr.to_lowercase())
15871589
}

src/key.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rand::thread_rng;
1515
use tokio::runtime::Handle;
1616

1717
use crate::context::Context;
18+
use crate::events::EventType;
1819
use crate::log::{LogExt, info};
1920
use crate::pgp::KeyPair;
2021
use crate::tools::{self, time_elapsed};
@@ -414,15 +415,11 @@ pub(crate) async fn store_self_keypair(context: &Context, keypair: &KeyPair) ->
414415
"INSERT INTO config (keyname, value) VALUES ('key_id', ?)",
415416
(new_key_id,),
416417
)?;
417-
Ok(Some(new_key_id))
418+
Ok(new_key_id)
418419
})
419420
.await?;
420-
421-
if let Some(new_key_id) = new_key_id {
422-
// Update config cache if transaction succeeded and changed current default key.
423-
config_cache_lock.insert("key_id".to_string(), Some(new_key_id.to_string()));
424-
}
425-
421+
context.emit_event(EventType::AccountsItemChanged);
422+
config_cache_lock.insert("key_id".to_string(), Some(new_key_id.to_string()));
426423
Ok(())
427424
}
428425

0 commit comments

Comments
 (0)