Files
VoelinClient/crates/voelin-ui/src/identities.rs
T
selikhovandClaude Opus 5.5 4cb6c6b527 Merge the identity defaults: one default, one identities page
The development branch's identity work and this wave's Profiles page
were two models of the same thing: the store's default identity (schema
4: where each identity came from and which one is the default, which the
import on start relies on to replace Voelin's own identity once) next to
this wave's identity.default setting, and a separate Identities section
next to Profiles. They are one now.

- The store's default is the only default: the identity.default setting
  is gone (never released, so nothing to migrate). Choosing an identity
  calls Store::set_default_identity as the user's choice, which no
  import replaces, and says it applies from the next connection.
- One place picks the identity of a connection: the bookmark's own if it
  names one that exists, else the store's default. Connecting, My
  Account and each identity's "Used by" all go through it.
- Profiles has what Identities had: each identity's origin ("Made in
  Voelin", "Imported", "Chosen by you") with its level, the Default
  badge or "Use as default", and the switch for importing the official
  clients' identities on start, next to this wave's rename, export,
  delete, security level, import by hand and identity per server. The
  Identities section, its sidebar entry and the phone's sixth tab are
  gone; VOELIN_OPEN=settings:identities opens Profiles.
- docs/identity.md and docs/ui.md say so; the Identities screenshot gives
  way to the Profiles one, taken from a store with the created identity
  and a synthetic TeamSpeak one.

Checked headless with a fake home and synthetic identities only: the
first start creates Default; the second, with a synthetic TeamSpeak 6
database, makes its identity the default once and says so; the third
changes nothing, and My Account shows the store's default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 09:56:25 +03:00

67 lines
2.0 KiB
Rust

//! The identity servers see us as: the store's default (schema 4,
//! `Store::default_identity`), chosen under Settings → Profiles, and the
//! import of the official clients' identities on start
//! (`voelin_core::identity::import_new`, app.rs). The rest of the Profiles
//! page is in `settings_pages.rs`.
use tracing::warn;
use voelin_core::settings::IDENTITY_IMPORT;
use voelin_store::IdentityOrigin;
use crate::app::App;
/// Where an identity came from, as Profiles says it.
pub(crate) fn origin_label(origin: IdentityOrigin) -> &'static str {
match origin {
IdentityOrigin::Created => "Made in Voelin",
IdentityOrigin::Imported => "Imported",
IdentityOrigin::User => "Chosen by you",
}
}
impl App {
/// The user's choice of the identity servers see us as, from the next
/// connection on; no import replaces it.
pub(crate) fn use_identity(&mut self, id: i64) {
let result =
self.store.set_default_identity(id, true).and_then(|()| self.store.identity(id));
match result {
Ok(identity) => {
self.identity = identity;
let name = self
.store
.identities()
.ok()
.and_then(|all| all.into_iter().find(|e| e.id == id))
.map(|e| e.name)
.unwrap_or_default();
self.set_status(format!(
"Servers see you as \u{201c}{name}\u{201d} from your next connection"
));
}
Err(e) => self.set_status(format!("Could not change the identity: {e}")),
}
self.refresh_identities();
}
pub(crate) fn set_identity_import(&mut self, on: bool) {
if let Err(e) = self.prefs.set(&IDENTITY_IMPORT, on) {
warn!(%e, "could not store the setting");
}
self.refresh_identities();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn rows_say_where_an_identity_came_from() {
assert_eq!(origin_label(IdentityOrigin::Created), "Made in Voelin");
assert_eq!(origin_label(IdentityOrigin::Imported), "Imported");
// Made by the app, then chosen: an import never replaces it.
assert_eq!(origin_label(IdentityOrigin::User), "Chosen by you");
}
}