Use the TeamSpeak identity instead of the one Voelin made itself
The user wants to appear as their TeamSpeak identity. Until now the
official client's default became Voelin's only on a store without
identities, so anyone who had started Voelin once kept the identity the
app had created on its own, which nobody chose.
The store now records where each identity came from and which one is
the default (schema 4: identities.origin created/imported/user and
is_default; the migration marks the first identity named Default as
created, the rest as imported, the first as the default). When the
import on start finds the official client's default while Voelin's
default is still the created one, that identity becomes the default,
once: the created one is kept, and choosing it again later makes it the
user's own, which no import replaces. The status says so ("You now use
your TeamSpeak identity "X"; your previous one is kept").
The toast wrapped nothing and was cut at 560 pixels, wider than a phone;
it now wraps within the window. voelinctl identity list shows the origin
and the default. Tested with synthetic databases and in the app headless
with a fake home: created, then replaced once, then left alone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
068a327160
commit
020b43a94e
9 files changed
+333
-65
No files matched your search
@@ -534,24 +534,24 @@ pub fn run(options: RunOptions) -> Result<()> {
|
||||
let prefs = open_settings(&dir, &options.setting_overrides);
|
||||
let switches = crate::dev::Switches::from_env();
|
||||
// New identities of the official TeamSpeak clients, on every start (not
|
||||
// with the sample data of VOELIN_DEMO_UI); with none of our own yet, the
|
||||
// client's default identity becomes ours.
|
||||
let had_identity = !store.identities()?.is_empty();
|
||||
// with the sample data of VOELIN_DEMO_UI); the client's default
|
||||
// identity becomes ours while we have none the user chose.
|
||||
let imported = if prefs.get(&IDENTITY_IMPORT) && !switches.demo_ui {
|
||||
voelin_core::identity::import_new(&store, &voelin_core::identity::discover())
|
||||
.unwrap_or_else(|e| {
|
||||
warn!(%e, "could not import TeamSpeak identities");
|
||||
Vec::new()
|
||||
Default::default()
|
||||
})
|
||||
} else {
|
||||
Vec::new()
|
||||
Default::default()
|
||||
};
|
||||
let identity = match store.identities()?.first() {
|
||||
let identity = match store.default_identity()? {
|
||||
Some(entry) => store.identity(entry.id)?,
|
||||
None => {
|
||||
// Creating an identity takes a moment (security level 8).
|
||||
let identity = tsclientlib::Identity::create();
|
||||
store.add_identity(crate::servers::CREATED_IDENTITY, &identity)?;
|
||||
let origin = voelin_store::IdentityOrigin::Created;
|
||||
store.add_identity(crate::servers::CREATED_IDENTITY, &identity, origin)?;
|
||||
identity
|
||||
}
|
||||
};
|
||||
@@ -636,7 +636,7 @@ pub fn run(options: RunOptions) -> Result<()> {
|
||||
if app.demo {
|
||||
app.start_demo();
|
||||
}
|
||||
if let Some(text) = crate::servers::imported_status(&imported, had_identity) {
|
||||
if let Some(text) = crate::servers::imported_status(&imported) {
|
||||
app.set_status(text);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use slint::{ComponentHandle, SharedString};
|
||||
use tracing::warn;
|
||||
use voelin_core::identity::Found;
|
||||
use voelin_core::identity::LaunchImport;
|
||||
use voelin_core::{Command, ObserveState, Source, VoiceOptions, VoiceState};
|
||||
use voelin_store::{Bookmark, QueryConfig, QueryTransport};
|
||||
|
||||
@@ -14,20 +14,20 @@ use crate::vm;
|
||||
pub(crate) const CREATED_IDENTITY: &str = "Default";
|
||||
|
||||
/// What to tell the user about the identities imported from the official
|
||||
/// clients at start ([`voelin_core::identity::import_new`]), if any.
|
||||
/// `had_identity`: we had one before, so it stays the default.
|
||||
pub(crate) fn imported_status(imported: &[Found], had_identity: bool) -> Option<String> {
|
||||
let first = imported.first()?;
|
||||
let n = imported.len();
|
||||
let names = imported.iter().map(|f| f.nickname.as_str()).collect::<Vec<_>>().join(", ");
|
||||
Some(match (had_identity, n) {
|
||||
(true, 1) => format!("Imported the identity \u{201c}{names}\u{201d} from TeamSpeak"),
|
||||
(true, _) => format!("Imported {n} identities from TeamSpeak: {names}"),
|
||||
(false, 1) => format!("Using your TeamSpeak identity \u{201c}{names}\u{201d}"),
|
||||
(false, _) => format!(
|
||||
"Using your TeamSpeak identity \u{201c}{}\u{201d} ({n} imported: {names})",
|
||||
first.nickname
|
||||
/// clients at start ([`voelin_core::identity::import_new`]), if anything.
|
||||
pub(crate) fn imported_status(report: &LaunchImport) -> Option<String> {
|
||||
let n = report.added.len();
|
||||
let names = report.added.iter().map(|f| f.nickname.as_str()).collect::<Vec<_>>().join(", ");
|
||||
let more = if n > 1 { format!(" ({n} imported: {names})") } else { String::new() };
|
||||
Some(match &report.default {
|
||||
Some(f) if report.replaced => format!(
|
||||
"You now use your TeamSpeak identity \u{201c}{}\u{201d}; your previous one is kept{more}",
|
||||
f.nickname
|
||||
),
|
||||
Some(f) => format!("Using your TeamSpeak identity \u{201c}{}\u{201d}{more}", f.nickname),
|
||||
None if n == 1 => format!("Imported the identity \u{201c}{names}\u{201d} from TeamSpeak"),
|
||||
None if n > 1 => format!("Imported {n} identities from TeamSpeak: {names}"),
|
||||
None => return None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -104,9 +104,9 @@ impl App {
|
||||
/// from TeamSpeak keeps the nickname used there), else the system user's.
|
||||
pub(crate) fn default_nickname(&self) -> String {
|
||||
self.store
|
||||
.identities()
|
||||
.default_identity()
|
||||
.ok()
|
||||
.and_then(|identities| identities.into_iter().next())
|
||||
.flatten()
|
||||
.map(|identity| identity.name)
|
||||
.filter(|name| {
|
||||
![CREATED_IDENTITY, voelin_core::identity::DEFAULT_NICKNAME]
|
||||
@@ -470,6 +470,8 @@ impl App {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use voelin_core::identity::Found;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
@@ -536,14 +538,24 @@ mod tests {
|
||||
source: "settings.db".into(),
|
||||
selected: false,
|
||||
};
|
||||
assert_eq!(imported_status(&[], false), None);
|
||||
let report = |added: &[&str], default: Option<&str>, replaced| LaunchImport {
|
||||
added: added.iter().map(|n| found(n)).collect(),
|
||||
default: default.map(found),
|
||||
replaced,
|
||||
};
|
||||
assert_eq!(imported_status(&report(&[], None, false)), None);
|
||||
assert_eq!(
|
||||
imported_status(&[found("Main")], false).unwrap(),
|
||||
imported_status(&report(&["Main"], Some("Main"), false)).unwrap(),
|
||||
"Using your TeamSpeak identity \u{201c}Main\u{201d}"
|
||||
);
|
||||
assert_eq!(
|
||||
imported_status(&[found("Main"), found("Alt")], true).unwrap(),
|
||||
imported_status(&report(&["Main", "Alt"], None, false)).unwrap(),
|
||||
"Imported 2 identities from TeamSpeak: Main, Alt"
|
||||
);
|
||||
// Imported earlier, now ours instead of the one the app made.
|
||||
assert_eq!(
|
||||
imported_status(&report(&[], Some("Main"), true)).unwrap(),
|
||||
"You now use your TeamSpeak identity \u{201c}Main\u{201d}; your previous one is kept"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user