Files
VoelinClient/crates/voelin-store/src/lib.rs
T
faumarayandClaude Sonnet 5.5 a77ccc0415 voelin-ui-vm: the server sequences both front ends ran twice are one
The GPUI shell repeated the Slint crate's connect, observe, gateway lookup,
save and remove of a server, its default nickname, its FallbackSecrets and its
settings opening and key registration. They now live once and both front ends
call them:

- voelin_ui_vm::servers::sequence: connect_voice(_to), observe,
  discover_gateway, gateway_found, select_server, save_bookmark,
  save_and_connect, delete_bookmark, bookmark_form and default_nickname, as
  transitions over the state, the Cx and a Backing (the store, the secrets,
  the identity a connection uses). The commands, the status line and what to
  keep go out through the Update as for every other transition; a new field,
  Update::discover, asks the front end to look a gateway up (the thread hop
  stays with each front end: Later in GPUI, later() in Slint). stream_peer is
  the one input a front end gives (Slint's codecs; GPUI passes none).
- voelin_ui_vm::settings::open_settings and register_keys; a front end adds
  its own key (ui.window, studio.ui) through a function it passes, so Slint's
  settings page still lists what it listed.
- voelin_store::FallbackSecrets (feature keyring) and Store::identity_for.
- voelin-ui: the methods of servers/bind.rs, open_settings and default_secrets
  call them, so their call sites are unchanged; host.rs gets transition_with
  and the discover arm of perform. voelin-gpui: AppState's methods and the
  Backend call them. What cannot move is named in docs/ui.md.

voelin-ui-vm now depends on tracing (the sequences log as the copies did): one
line of Cargo.lock, THIRD_PARTY_NOTICES.md unchanged (scripts/notices.sh
--check clean), cargo deny check clean. The sequences have ten tests over a
fake front end (commands, status, store, secrets, gateways), open_settings and
Store::identity_for one each; the GPUI and Slint suites pass unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-27 20:05:46 +03:00

87 lines
3.2 KiB
Rust

//! Local persistence for the client.
//!
//! One SQLite database holds identities, bookmarks, settings, contacts
//! ([`contacts`]) and the chat history ([`chat`]). Passwords and query
//! credentials never go into the database; they live in a [`Secrets`] store
//! (the OS keyring with the `keyring` feature).
//!
//! The schema is versioned (`PRAGMA user_version`): opening a database runs
//! the migrations it has not seen, each in one transaction, keeping the data.
//!
//! The `identities` table keeps identities of more than one kind. [`Store`]
//! has the TeamSpeak identities the client has always had; [`SqliteKeyStore`]
//! is the table as a `voelin_identity::KeyStore`: every kind (TeamSpeak, a
//! Voelin key, the record of the signed-in account), each with the binding that
//! says whether it belongs to an account, and the sign-out of that account.
pub mod chat;
pub mod contacts;
mod keystore;
mod secrets;
mod store;
pub use chat::{
ChatCursor, ChatRead, ChatTarget, MessageSource, NewMessage, PageQuery, Reaction, RemoteInfo,
StoredMessage, SyncState, WriteOutcome, Written,
};
pub use contacts::{Contact, ContactSeen, Relation};
pub use keystore::SqliteKeyStore;
#[cfg(feature = "keyring")]
pub use secrets::{FallbackSecrets, KeyringSecrets};
pub use secrets::{MemorySecrets, Secrets};
pub use store::{
Bookmark, CachedServerIcon, IdentityEntry, IdentityOrigin, QueryConfig, QueryTransport, Store,
};
/// How the JSON of a stored TeamSpeak identity is wrong: the category of the
/// reader's complaint and nothing of the text, which holds a private key.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum IdentityDamage {
/// The text is not JSON.
Malformed,
/// The text ends before the JSON does.
CutShort,
/// The JSON is not that of an identity: a field is missing or of another
/// type, or the key does not import.
NotAnIdentity,
/// The text could not be read.
Unreadable,
}
impl std::fmt::Display for IdentityDamage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::Malformed => "malformed",
Self::CutShort => "cut short",
Self::NotAnIdentity => "not an identity",
Self::Unreadable => "unreadable",
})
}
}
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("database: {0}")]
Db(#[from] rusqlite::Error),
#[error("serialization: {0}")]
Json(#[from] serde_json::Error),
/// The JSON of a stored TeamSpeak identity cannot be read, which only damage
/// outside the client can cause. It says how the text is wrong and where, and
/// never what it holds: the text is a private key, and the message of the
/// JSON reader quotes the value it refuses (`tsproto` reports a key that does
/// not import as an invalid value, the key string and all), so that message is
/// not kept, not here and not in a log line.
#[error(
"the stored TeamSpeak identity cannot be read: {damage} at line {line}, column {column}"
)]
Identity { damage: IdentityDamage, line: usize, column: usize },
#[error("{0} {1} not found")]
NotFound(&'static str, i64),
#[error("secret store: {0}")]
Secrets(String),
#[error("io: {0}")]
Io(#[from] std::io::Error),
}
pub type Result<T> = std::result::Result<T, Error>;