Merge main (ad20979) into phase4/session-seam

Main brings the merge of phase5/ui-vm: the toolkit-free crates/voelin-ui-vm
crate and the logic/bind split of crates/voelin-ui. Conflicts, and what each
resolution keeps:

- crates/voelin-ui/src/settings_pages.rs: main deleted it (it is
  settings_pages/{mod,bind}.rs and voelin-ui-vm's settings_pages/logic.rs
  now), this branch had changed its voelin_core::identity paths. Deleted; the
  paths are voelin_core::ts::identity:: in bind.rs and in logic.rs.
- crates/voelin-ui/src/identities.rs: the module comment names
  voelin_core::ts::identity::import_new (this branch) and settings_pages/
  (main).
- docs/architecture.md: the voelin-core row of this branch with the
  voelin-ui-vm and voelin-ui rows of main.

Not conflicts, but needed to compile: voelin-ui-vm named the in-tree
voelin-model by path, which this branch moved to the protocol repository
(workspace dependency), and imported voelin_core::identity::Found, which is
voelin_core::ts::identity::Found. Cargo.lock merged without a conflict and
resolves with --locked; THIRD_PARTY_NOTICES.md is up to date
(scripts/notices.sh --check).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-24 10:32:05 +03:00
commit e13d401b9c
73 files changed
+11836 -5281

No files matched your search

+121 -544
View File
@@ -3,11 +3,12 @@
//!
//! The screens' logic is elsewhere: servers and the channel tree in
//! `servers.rs`, chat in `chat.rs`, streams in `streams.rs`, the settings
//! page in `settings_page.rs` and `appearance.rs`, the view models in `vm/`,
//! callbacks in `bind/`, development switches in `dev.rs`.
//! page in `settings_page.rs` and `appearance.rs`, the settings pages in
//! `settings_pages/`, the Stream Studio in `studio/`, the view models in the
//! `voelin-ui-vm` crate (`vm`), callbacks in `bind/`, development switches in
//! `dev.rs`.
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::Arc;
@@ -22,22 +23,19 @@ use voelin_core::settings::{
AUDIO, CRASH_REPORTS, IDENTITY_IMPORT, STREAM_DECODER_BACKEND, STREAM_HARDWARE_DECODING,
Settings,
};
use voelin_core::stream::StreamInfo;
use voelin_core::{
AudioSettings, BackendInfo, Command, Engine, Event, History, HistoryMessage, ObserveState,
SessionState, VoiceState,
AudioSettings, BackendInfo, Command, Engine, Event, History, ObserveState, VoiceState,
};
use voelin_model::{Capabilities, ChannelId, ChatMessage, ChatTarget, GroupInfo, Presence};
use voelin_model::ChatTarget;
use voelin_platform::crash;
use voelin_store::{Bookmark, MemorySecrets, Secrets, Store};
use crate::bind::rows::Rows;
use crate::hotkey::GlobalPtt;
use crate::settings::{
CLIENT_PLAYBACK, ClientPlaybackMap, DeviceChoices, UI, UiSettings, appearance_keys,
};
use crate::settings::{CLIENT_PLAYBACK, ClientPlaybackMap, UI, UiSettings, appearance_keys};
use crate::streams::{Share, Watch};
use crate::video::Video;
use crate::vm::chat::Previous;
use crate::vm;
slint::include_modules!();
@@ -58,7 +56,7 @@ fn open_settings(dir: &Path, overrides: &[String]) -> Settings {
for key in crate::settings::page_keys() {
prefs.register(key);
}
prefs.register(&crate::studio::STUDIO_UI);
prefs.register(&crate::vm::studio::logic::STUDIO_UI);
let config = std::env::var_os("VOELIN_CONFIG")
.map(PathBuf::from)
.or_else(|| Some(dir.join("config.toml")).filter(|p| p.exists()));
@@ -118,420 +116,72 @@ impl Secrets for FallbackSecrets {
}
}
/// A message of a chat with the handle the UI knows it by: the engine's
/// local ids are 64 bit, a Slint `int` is not.
pub(crate) struct Msg {
pub key: i32,
pub message: HistoryMessage,
}
/// The lines of a chat as the chat view shows them.
pub(crate) type ChatRows = Rows<vm::bridge::ChatLine>;
/// A chat of a session: its lines are the model the chat view shows while
/// the tab is selected, so a new message is one row appended.
pub(crate) struct Tab {
pub target: ChatTarget,
pub title: String,
pub lines: Rc<VecModel<ChatLine>>,
/// The messages, oldest first, by `(ts_ms, id)`.
pub messages: Vec<Msg>,
/// Live messages of a session that keeps no history (no server unique
/// id yet): grouped from the message before, without ids.
pub last: Option<Previous>,
/// Messages not read, not ours: those after `read` (without stored
/// history, those that came while the tab was not on screen).
pub unread: i32,
/// The newest message read, by `(ts_ms, id)`: kept in the store
/// (`chat_reads`) when the tab is left, the session closes and on exit
/// (`App::save_read`). `stored_read` is what the store has.
pub read: Option<(i64, i64)>,
pub stored_read: Option<(i64, i64)>,
/// The message the "New" divider is above: the first that was new when
/// the tab came on screen. It stays until the tab is left.
pub divider: Option<i64>,
/// Nothing older exists as far as the engine can tell.
pub complete: bool,
/// A gateway page arrived: the chat is not only what we saw.
pub synced: bool,
/// An older page was asked for.
pub loading: bool,
/// The next message handle.
next_key: i32,
/// The pins of this chat, once asked for.
pub pins: Vec<crate::chat::PinRow>,
pub pins_loaded: bool,
/// The gateway topics of this chat, and the open one with its messages.
pub topics: Vec<voelin_gateway_proto::TopicInfo>,
pub topics_loaded: bool,
pub topic: Option<i64>,
pub topic_messages: Vec<Msg>,
/// The message jumped to from the pins.
pub marked: Option<i64>,
/// What the lines of `messages` were built from.
pub cache: crate::vm::chat::LineCache,
}
impl Tab {
pub fn new(target: ChatTarget, title: String) -> Self {
Self {
target,
title,
lines: Rc::new(VecModel::default()),
messages: Vec::new(),
last: None,
unread: 0,
read: None,
stored_read: None,
divider: None,
complete: false,
synced: false,
loading: false,
next_key: 1,
pins: Vec::new(),
pins_loaded: false,
topics: Vec::new(),
topics_loaded: false,
topic: None,
topic_messages: Vec::new(),
marked: None,
cache: Default::default(),
}
}
/// A private chat (on the Direct Messages page, not in the chat strip).
pub fn is_private(&self) -> bool {
matches!(self.target, ChatTarget::Private(_))
}
/// A handle for a message that has none yet.
pub fn take_key(&mut self) -> i32 {
self.next_key += 1;
self.next_key
}
pub fn message(&self, key: i32) -> Option<&HistoryMessage> {
self.messages.iter().chain(&self.topic_messages).find(|m| m.key == key).map(|m| &m.message)
}
/// Where each message is and whether it is ours (`own`), for the read
/// markers ([`crate::vm::chat::first_unread`]).
pub fn positions(&self, own: impl Fn(&ChatMessage) -> bool) -> Vec<(i64, i64, bool)> {
self.messages
.iter()
.map(|m| (m.message.message.ts_ms, m.message.id, own(&m.message.message)))
.collect()
}
/// Where the newest message is.
pub fn newest(&self) -> Option<(i64, i64)> {
self.messages.last().map(|m| (m.message.message.ts_ms, m.message.id))
}
/// The tab came on screen: the first new message gets the divider
/// (unless one shows), and everything is read.
pub fn enter(&mut self, own: impl Fn(&ChatMessage) -> bool) {
if self.unread > 0 && self.divider.is_none() {
let first = crate::vm::chat::first_unread(&self.positions(own), self.read);
self.divider = first.map(|i| self.messages[i].message.id);
}
self.catch_up();
}
/// Everything in the tab is read (it is on screen).
pub fn catch_up(&mut self) {
self.read = self.read.max(self.newest());
self.unread = 0;
}
/// Count what is not read: what came after `read`, not ours.
pub fn count_unread(&mut self, own: impl Fn(&ChatMessage) -> bool) {
self.unread = crate::vm::chat::unread_count(&self.positions(own), self.read);
}
/// Start from where the store says the chat was read (`reads`: by the
/// store's name of the chat).
pub fn read_from(&mut self, reads: &HashMap<String, (i64, i64)>) {
if let Some(&read) = reads.get(&crate::chat::store_target(&self.target).key()) {
self.read = self.read.max(Some(read));
self.stored_read = Some(read);
}
}
}
/// A chat of a session (see `voelin_ui_vm::state`).
pub(crate) type Tab = vm::state::Tab<ChatRows>;
/// What we know about one server session.
pub(crate) struct SessionView {
pub state: SessionState,
pub capabilities: Capabilities,
pub presence: Arc<Presence>,
pub collapsed: HashSet<ChannelId>,
pub talking: HashSet<u16>,
pub tabs: Vec<Tab>,
pub current_tab: usize,
/// The chat strip's chat last current (the server's or a channel's): a
/// private chat is current only on the Direct Messages page, and this
/// one is current again when that page is left.
pub channel_tab: ChatTarget,
/// The own channel's tab was focused for this voice connection.
pub focused_own_channel: bool,
/// The streams in our channel (TeamSpeak 6).
pub streams: Vec<StreamInfo>,
/// Clients whose stored volume was sent for this voice connection.
pub applied_playback: HashSet<u16>,
/// Avatar pictures in the engine's cache, by unique id
/// ([`Event::AvatarReady`]).
pub avatars: HashMap<String, PathBuf>,
/// Icons in the engine's cache, by icon id ([`Event::IconReady`]).
pub icons: HashMap<u32, PathBuf>,
/// Banners and badges in the engine's cache, by address
/// ([`Event::PictureReady`]).
pub pictures: HashMap<String, PathBuf>,
/// The server's icon id as its voice connection last told it
/// ([`Event::ServerDetails`]); kept while disconnected, for the rail.
pub server_icon: u32,
/// Bookmark address that supplied this session's icon.
pub icon_address: Option<String>,
/// The server groups in display order ([`Event::Groups`]).
pub server_groups: Vec<GroupInfo>,
/// The channel groups ([`Event::Groups`]).
pub channel_groups: Vec<GroupInfo>,
/// What the session's gateway offers (`voelin_gateway_proto::feature`).
pub gateway_caps: Vec<String>,
/// The client whose member card is open.
pub member_card: Option<u16>,
/// Passwords given for locked channels, until voice disconnects.
pub channel_passwords: HashMap<ChannelId, String>,
/// The channel a voice connection was asked into, until it is joined
/// or joined again (`App::join_after_connect`).
pub join_after_connect: Option<ChannelId>,
/// Viewers of the streams in the gateway's directory, by stream id.
pub stream_viewers: HashMap<String, u32>,
/// Downloads started from chat, by transfer id.
pub downloads: HashMap<u64, crate::chat::Download>,
/// The next transfer id.
pub next_transfer: u64,
/// What the home, messages and events screens keep of the session.
pub extra: crate::social::SessionExtra,
/// Where its chats were read, from the store (by the store's name of
/// the chat), for the server unique id `reads_of`.
pub reads: HashMap<String, (i64, i64)>,
pub reads_of: Option<String>,
}
pub(crate) type SessionView = vm::state::SessionView<ChatRows>;
impl Default for SessionView {
fn default() -> Self {
Self {
state: SessionState::default(),
capabilities: Capabilities::default(),
presence: Arc::default(),
collapsed: HashSet::new(),
talking: HashSet::new(),
tabs: vec![Tab::new(ChatTarget::Server, "Server".into())],
current_tab: 0,
channel_tab: ChatTarget::Server,
focused_own_channel: false,
streams: Vec::new(),
applied_playback: HashSet::new(),
avatars: HashMap::new(),
icons: HashMap::new(),
pictures: HashMap::new(),
server_icon: 0,
icon_address: None,
server_groups: Vec::new(),
channel_groups: Vec::new(),
gateway_caps: Vec::new(),
member_card: None,
channel_passwords: HashMap::new(),
join_after_connect: None,
stream_viewers: HashMap::new(),
downloads: HashMap::new(),
next_transfer: 1,
extra: Default::default(),
reads: HashMap::new(),
reads_of: None,
}
}
}
impl SessionView {
/// Streams can be watched and shared: TeamSpeak 6, connected with voice.
pub fn streams_available(&self) -> bool {
self.capabilities.streams && self.state.voice == VoiceState::Connected
}
/// The channel a client is in.
pub fn channel_of(&self, client: u16) -> Option<u64> {
self.presence.clients.get(&client).map(|c| c.channel)
}
/// The name of a client's channel when it is not ours; empty in ours.
pub fn other_channel_name(&self, client: u16) -> String {
self.channel_of(client)
.filter(|c| Some(*c) != self.state.own_channel)
.and_then(|c| self.presence.channels.get(&c))
.map_or_else(String::new, |c| crate::vm::tree::channel_title(c).0.to_owned())
}
/// A client's nickname, or its id.
pub fn nickname(&self, client: u16) -> String {
self.presence
.clients
.get(&client)
.map_or_else(|| format!("client {client}"), |c| c.nickname.clone())
}
/// Unread messages in the server's and the channels' chats (the rail and
/// the chat strip count them; private chats count on the Direct
/// Messages page).
pub fn channel_unread(&self) -> i32 {
self.tabs.iter().filter(|t| !t.is_private()).map(|t| t.unread).sum()
}
/// Unread messages in private chats.
pub fn private_unread(&self) -> i32 {
self.tabs.iter().filter(|t| t.is_private()).map(|t| t.unread).sum()
}
/// Make tab `index` the current one; the chat strip remembers it unless
/// it is a private chat.
pub fn set_current_tab(&mut self, index: usize) {
self.current_tab = index;
if let Some(tab) = self.tabs.get(index).filter(|t| !t.is_private()) {
self.channel_tab = tab.target.clone();
}
}
/// Focus tab `index`. While a private chat is current (the Direct
/// Messages page shows it, and its composer sends there), a chat of the
/// strip does not take its place: it is the strip's chat, current once
/// that page is left (voice connecting focuses its channel's chat).
pub fn focus_tab(&mut self, index: usize) {
let Some(tab) = self.tabs.get(index) else { return };
if !tab.is_private() && self.tabs.get(self.current_tab).is_some_and(Tab::is_private) {
self.channel_tab = tab.target.clone();
} else {
self.set_current_tab(index);
}
}
/// Remove tab `index`. The current tab stays; when it is this one, the
/// chat strip's next tab takes its place, else its last.
pub fn remove_tab(&mut self, index: usize) -> Tab {
let tab = self.tabs.remove(index);
if self.current_tab > index {
self.current_tab -= 1;
} else if self.current_tab == index {
let (strip, _) = crate::vm::chat::strip(self.tabs.iter().map(|t| &t.target), 0);
let next = strip.iter().find(|&&i| i >= index).or(strip.last()).copied();
self.set_current_tab(next.unwrap_or(0));
}
tab
}
/// Leave a current private chat for the chat strip's last one (the
/// Direct Messages page was left); `true` if the current tab changed.
pub fn leave_private(&mut self) -> bool {
if !self.tabs.get(self.current_tab).is_some_and(Tab::is_private) {
return false;
}
self.current_tab = self.tabs.iter().position(|t| t.target == self.channel_tab).unwrap_or(0);
true
}
/// A new tab for `target`, read as far as the store says.
pub fn new_tab(&self, target: ChatTarget, title: String) -> Tab {
let mut tab = Tab::new(target, title);
tab.read_from(&self.reads);
tab
}
/// The session's gateway offers this feature
/// (`voelin_gateway_proto::feature`).
pub fn gateway_has(&self, feature: &str) -> bool {
self.gateway_caps.iter().any(|c| c == feature)
}
/// The chat history is kept by the engine (it knows the server): its
/// messages come with ids, reactions and pins.
pub fn has_history(&self) -> bool {
self.state.server_uid.is_some()
}
/// The avatar picture of a client, if the engine fetched one.
pub fn avatar(&self, client: u16) -> Option<&PathBuf> {
let uid = self.presence.clients.get(&client)?.uid.as_deref()?;
self.avatars.get(uid)
}
/// The server's icon, if it has one and the engine fetched it.
pub fn server_icon(&self) -> slint::Image {
crate::vm::avatar::image(
self.icons.get(&self.server_icon).filter(|_| self.server_icon != 0),
)
}
/// Icons stay associated with the address that supplied them, including
/// while a reconnect to an edited bookmark is pending or has failed.
pub fn server_icon_for(&self, address: &str) -> slint::Image {
if self.icon_address.as_deref() == Some(address) {
self.server_icon()
} else {
slint::Image::default()
}
}
}
/// What the screens share, apart from the window and the engine.
pub(crate) type AppState = vm::state::AppState<ChatRows>;
/// The models the Bridge shows, created once and updated row by row
/// (`vm::list::sync`).
/// ([`Rows::sync`]).
pub(crate) struct Models {
pub servers: Rc<VecModel<ServerItem>>,
pub tree: Rc<VecModel<TreeItem>>,
pub members: Rc<VecModel<MemberItem>>,
pub server_members: Rc<VecModel<MemberItem>>,
pub servers: Rows<vm::bridge::ServerItem>,
pub tree: Rows<vm::bridge::TreeItem>,
pub members: Rows<vm::bridge::MemberItem>,
pub server_members: Rows<vm::bridge::MemberItem>,
/// The chat strip: the current session's tabs without its private chats.
pub tabs: Rc<VecModel<ChatTab>>,
pub tabs: Rows<vm::bridge::ChatTab>,
/// Which of the session's tabs each of `tabs` is ([`crate::vm::chat::strip`]).
pub strip: RefCell<Vec<usize>>,
pub streams: Rc<VecModel<StreamItem>>,
pub viewers: Rc<VecModel<ViewerItem>>,
pub pins: Rc<VecModel<PinItem>>,
pub topics: Rc<VecModel<TopicItem>>,
pub topic_messages: Rc<VecModel<ChatLine>>,
pub streams: Rows<vm::bridge::StreamItem>,
pub viewers: Rows<vm::bridge::ViewerItem>,
pub pins: Rows<vm::bridge::PinItem>,
pub topics: Rows<vm::bridge::TopicItem>,
pub topic_messages: Rows<vm::bridge::ChatLine>,
/// The quality choices of the watched stream.
pub qualities: Rc<VecModel<slint::SharedString>>,
pub qualities: Rows<Arc<str>>,
/// Shown when there is no chat.
pub no_chat: Rc<VecModel<ChatLine>>,
pub no_chat: Rows<vm::bridge::ChatLine>,
/// Home, friends, messages, the bell, the search, events.
pub social: crate::social::SocialModels,
/// Settings pages.
pub layers: Rc<VecModel<LayerItem>>,
pub audio_sources: Rc<VecModel<AudioSourceItem>>,
pub identities: Rc<VecModel<IdentityItem>>,
pub gateway_config: Rc<VecModel<ConfigItem>>,
pub gateway_perms: Rc<VecModel<PermItem>>,
pub all_settings: Rc<VecModel<SettingItem>>,
pub layers: Rows<vm::bridge::LayerItem>,
pub audio_sources: Rows<vm::bridge::AudioSourceItem>,
pub identities: Rows<vm::bridge::IdentityItem>,
pub gateway_config: Rows<vm::bridge::ConfigItem>,
pub gateway_perms: Rows<vm::bridge::PermItem>,
pub all_settings: Rows<vm::bridge::SettingItem>,
}
impl Models {
fn new(bridge: &Bridge) -> Self {
let models = Self {
servers: Rc::default(),
tree: Rc::default(),
members: Rc::default(),
server_members: Rc::default(),
tabs: Rc::default(),
servers: Rows::default(),
tree: Rows::default(),
members: Rows::default(),
server_members: Rows::default(),
tabs: Rows::default(),
strip: RefCell::new(vec![0]),
streams: Rc::default(),
viewers: Rc::default(),
pins: Rc::default(),
topics: Rc::default(),
topic_messages: Rc::default(),
qualities: Rc::default(),
no_chat: Rc::default(),
streams: Rows::default(),
viewers: Rows::default(),
pins: Rows::default(),
topics: Rows::default(),
topic_messages: Rows::default(),
qualities: Rows::default(),
no_chat: Rows::default(),
social: crate::social::SocialModels::new(bridge),
layers: Rc::default(),
audio_sources: Rc::default(),
identities: Rc::default(),
gateway_config: Rc::default(),
gateway_perms: Rc::default(),
all_settings: Rc::default(),
layers: Rows::default(),
audio_sources: Rows::default(),
identities: Rows::default(),
gateway_config: Rows::default(),
gateway_perms: Rows::default(),
all_settings: Rows::default(),
};
models.attach(bridge);
models
@@ -540,24 +190,24 @@ impl Models {
/// Show the models in `bridge`: the main window's, and the viewer's own
/// window's (its player reads the stream's qualities).
pub(crate) fn attach(&self, bridge: &Bridge) {
bridge.set_servers(ModelRc::from(self.servers.clone()));
bridge.set_tree(ModelRc::from(self.tree.clone()));
bridge.set_members(ModelRc::from(self.members.clone()));
bridge.set_server_members(ModelRc::from(self.server_members.clone()));
bridge.set_tabs(ModelRc::from(self.tabs.clone()));
bridge.set_streams(ModelRc::from(self.streams.clone()));
bridge.set_share_viewers(ModelRc::from(self.viewers.clone()));
bridge.set_pins(ModelRc::from(self.pins.clone()));
bridge.set_topics(ModelRc::from(self.topics.clone()));
bridge.set_topic_messages(ModelRc::from(self.topic_messages.clone()));
bridge.set_viewer_qualities(ModelRc::from(self.qualities.clone()));
bridge.set_messages(ModelRc::from(self.no_chat.clone()));
bridge.set_layers(ModelRc::from(self.layers.clone()));
bridge.set_audio_sources(ModelRc::from(self.audio_sources.clone()));
bridge.set_identities(ModelRc::from(self.identities.clone()));
bridge.set_gateway_config(ModelRc::from(self.gateway_config.clone()));
bridge.set_gateway_perms(ModelRc::from(self.gateway_perms.clone()));
bridge.set_all_settings(ModelRc::from(self.all_settings.clone()));
bridge.set_servers(self.servers.model());
bridge.set_tree(self.tree.model());
bridge.set_members(self.members.model());
bridge.set_server_members(self.server_members.model());
bridge.set_tabs(self.tabs.model());
bridge.set_streams(self.streams.model());
bridge.set_share_viewers(self.viewers.model());
bridge.set_pins(self.pins.model());
bridge.set_topics(self.topics.model());
bridge.set_topic_messages(self.topic_messages.model());
bridge.set_viewer_qualities(self.qualities.model());
bridge.set_messages(self.no_chat.model());
bridge.set_layers(self.layers.model());
bridge.set_audio_sources(self.audio_sources.model());
bridge.set_identities(self.identities.model());
bridge.set_gateway_config(self.gateway_config.model());
bridge.set_gateway_perms(self.gateway_perms.model());
bridge.set_all_settings(self.all_settings.model());
}
}
@@ -567,80 +217,33 @@ pub(crate) struct App {
pub secrets: Box<dyn Secrets>,
pub engine: Engine,
pub identity: tsclientlib::Identity,
pub bookmarks: Vec<Bookmark>,
pub current: Option<i64>,
pub sessions: HashMap<i64, SessionView>,
/// The data the screens share (`voelin_ui_vm::state`).
pub state: AppState,
pub models: Models,
pub status: String,
/// What the toast of the next copy says instead of "Copied" (an invite
/// names its channel and link).
pub copy_note: Option<String>,
/// The members panel's search.
pub member_filter: String,
/// The topics drawer's search.
pub topic_filter: String,
/// The voice channel view is shown (its people come first in the
/// members panel).
pub voice_view: bool,
/// The settings service (shared with the engine); `settings`, `audio`
/// and `playback` are working copies of its keys.
/// The settings service (shared with the engine); `state.settings`,
/// `state.audio` and `state.playback` are working copies of its keys.
pub prefs: Settings,
pub settings: UiSettings,
pub audio: AudioSettings,
/// Audio settings changed since they were last stored.
pub audio_dirty: bool,
pub inputs: DeviceChoices,
pub outputs: DeviceChoices,
pub playback: ClientPlaybackMap,
/// The engine's contacts, by unique id ([`Event::ContactsChanged`]).
pub contacts: HashMap<String, voelin_core::Contact>,
/// The client in the volume dialog: session, client id, unique id.
pub playback_dialog: Option<(i64, u16, Option<String>)>,
/// The locked channel the password dialog is for: session, channel.
pub join_target: Option<(i64, ChannelId)>,
/// Who the poke dialog pokes: session, client, nickname.
pub poke_target: Option<(i64, u16, String)>,
/// The window has the focus (desktop: winit tells; elsewhere assumed):
/// messages are read only then.
pub focused: bool,
/// The chat whose messages are on screen (session, target): when it is
/// left, it is stored and loses its divider (`App::track_reading`).
pub reading: Option<(i64, ChatTarget)>,
pub mic_test: bool,
pub ptt: GlobalPtt,
pub video: Video,
/// Our stream.
pub share: Option<Share>,
/// The capture for a share is being started.
pub share_busy: bool,
pub share_error: String,
/// The stream in the viewer.
pub watch: Option<Watch>,
/// A client whose stream was asked for before it was known (session,
/// client): watched when the lookup brings it.
pub pending_watch: Option<(i64, u16)>,
/// Stream volume in percent, kept between streams.
pub stream_volume: f32,
/// `VOELIN_DEMO_STREAM`: the viewer shows a local test stream.
pub demo: bool,
/// `VOELIN_DEMO_UI`: sample servers, channels and chat (dev.rs).
pub demo_ui: bool,
/// Servers whose gateway was looked up in this run (`discover_gateway`).
pub gateways_looked_up: HashSet<i64>,
/// `VOELIN_AUTOSHARE=test-pattern`: share the test pattern once streams work.
pub autoshare: bool,
/// `VOELIN_OPEN=client`: open the volume dialog of the first other client.
pub open_client_pending: bool,
/// The notices are in the About page's model.
pub notices_loaded: bool,
/// Files being uploaded to a channel from the composer: session,
/// channel and name, so the link can be posted when they are up.
pub uploads: HashMap<u64, (i64, u64, String)>,
/// Home, friends, messages, the bell and the search.
pub social: crate::social::Social,
/// The settings pages of the new design.
pub pages: crate::settings_pages::Pages,
/// The Stream Studio (studio.rs).
/// The Stream Studio (studio/).
pub studio: crate::studio::StudioState,
/// The stream's own window (popout.rs).
pub popout: crate::popout::Popout,
@@ -829,44 +432,18 @@ pub fn run(options: RunOptions) -> Result<()> {
}),
engine: engine.clone(),
identity,
current: bookmarks.first().map(|b| b.id),
bookmarks,
sessions: HashMap::new(),
state: AppState::new(bookmarks, settings, audio, playback),
models,
status: String::new(),
copy_note: None,
member_filter: String::new(),
topic_filter: String::new(),
voice_view: false,
prefs,
settings,
audio,
audio_dirty: false,
inputs: DeviceChoices::default(),
outputs: DeviceChoices::default(),
playback,
contacts: HashMap::new(),
playback_dialog: None,
join_target: None,
poke_target: None,
focused: true,
reading: None,
mic_test: false,
ptt,
video,
share: None,
share_busy: false,
share_error: String::new(),
watch: None,
pending_watch: None,
stream_volume: 100.0,
demo: switches.demo_stream,
demo_ui: switches.demo_ui,
gateways_looked_up: HashSet::new(),
autoshare: switches.autoshare,
open_client_pending: switches.open_client,
notices_loaded: false,
uploads: HashMap::new(),
social: Default::default(),
pages: Default::default(),
studio: Default::default(),
@@ -931,18 +508,18 @@ pub fn run(options: RunOptions) -> Result<()> {
if let Err(e) = app.prefs.flush() {
warn!(%e, "could not store settings");
}
let ids: Vec<i64> = app.sessions.keys().copied().collect();
let ids: Vec<i64> = app.state.sessions.keys().copied().collect();
for id in ids {
app.save_reads(id);
}
app.watch = None;
app.share = None;
if own && !app.demo_ui {
for id in app.sessions.keys() {
for id in app.state.sessions.keys() {
app.engine.send(Command::CloseSession { session: *id as u64 });
}
}
own && !app.sessions.is_empty() && !app.demo_ui
own && !app.state.sessions.is_empty() && !app.demo_ui
});
APP.with(|a| a.borrow_mut().take());
if let Some(runtime) = own_runtime {
@@ -1001,30 +578,30 @@ pub(crate) fn model<T: Clone + 'static>(items: Vec<T>) -> ModelRc<T> {
impl App {
pub fn view_mut(&mut self) -> Option<&mut SessionView> {
let id = self.current?;
Some(self.sessions.entry(id).or_default())
let id = self.state.current?;
Some(self.state.sessions.entry(id).or_default())
}
pub fn view(&self) -> Option<&SessionView> {
self.current.and_then(|id| self.sessions.get(&id))
self.state.current.and_then(|id| self.state.sessions.get(&id))
}
pub fn bookmark(&self, id: i64) -> Option<&Bookmark> {
self.bookmarks.iter().find(|b| b.id == id)
self.state.bookmarks.iter().find(|b| b.id == id)
}
/// Send a command for the current session. Not for the sample
/// sessions of VOELIN_DEMO_UI: the engine would open them for real.
pub fn command(&self, f: impl FnOnce(u64) -> Command) {
if let Some(id) = self.current.filter(|_| !self.demo_ui) {
if let Some(id) = self.state.current.filter(|_| !self.demo_ui) {
self.engine.send(f(id as u64));
}
}
pub fn set_status(&mut self, text: impl Into<String>) {
self.status = text.into();
self.state.status = text.into();
if let Some(ui) = self.ui.upgrade() {
ui.global::<Bridge>().set_status_text(self.status.clone().into());
ui.global::<Bridge>().set_status_text(self.state.status.clone().into());
}
}
@@ -1037,12 +614,12 @@ impl App {
/// Nav.copy put text on the clipboard: one toast says so.
pub fn copied(&mut self) {
let text = self.copy_note.take().unwrap_or_else(|| "Copied".to_owned());
let text = self.state.copy_note.take().unwrap_or_else(|| "Copied".to_owned());
self.set_status(text);
}
pub fn store_settings(&self) {
if let Err(e) = self.prefs.set(&UI, self.settings.clone()) {
if let Err(e) = self.prefs.set(&UI, self.state.settings.clone()) {
warn!(%e, "could not store settings");
}
}
@@ -1051,19 +628,19 @@ impl App {
/// the values the window keeps copies of. The engine applies audio
/// settings itself.
fn setting_changed(&mut self, key: &str) {
if key == AUDIO.name() && !self.audio_dirty {
self.audio = self.prefs.get(&AUDIO);
if key == AUDIO.name() && !self.state.audio_dirty {
self.state.audio = self.prefs.get(&AUDIO);
// The voice controls follow the transmit mode.
self.refresh_transmit();
} else if key == CRASH_REPORTS.name() {
let enabled = self.prefs.get(&CRASH_REPORTS);
if enabled != self.settings.crash_reports {
self.settings.crash_reports = enabled;
if enabled != self.state.settings.crash_reports {
self.state.settings.crash_reports = enabled;
crash::set_enabled(enabled);
self.refresh_settings_flags();
}
} else if key == CLIENT_PLAYBACK.name() {
self.playback = self.prefs.get(&CLIENT_PLAYBACK);
self.state.playback = self.prefs.get(&CLIENT_PLAYBACK);
} else if appearance_keys().iter().any(|k| k.name() == key) {
self.apply_appearance();
} else if key == voelin_core::settings::STREAM_AUDIO_SOURCES.name() {
@@ -1085,7 +662,7 @@ impl App {
match event {
Event::State { session, state } => {
let id = session as i64;
let view = self.sessions.entry(id).or_default();
let view = self.state.sessions.entry(id).or_default();
let was_voice = view.state.voice;
let was_observe = view.state.observe;
let was_channel = view.state.own_channel;
@@ -1111,12 +688,12 @@ impl App {
if off(state.voice, state.observe) && !off(was_voice, was_observe) {
self.save_reads(id);
}
let view = self.sessions.entry(id).or_default();
let view = self.state.sessions.entry(id).or_default();
let focus = !view.focused_own_channel;
if state.voice == VoiceState::Connected && was_voice != VoiceState::Connected {
self.set_status("Connected");
}
if self.current == Some(id) {
if self.state.current == Some(id) {
if self.track_reading() {
self.refresh_chat();
}
@@ -1124,7 +701,7 @@ impl App {
// once per connection.
if let (Some(cid), VoiceState::Connected) = (state.own_channel, state.voice) {
self.open_chat(ChatTarget::Channel(cid), focus);
self.sessions.entry(id).or_default().focused_own_channel = true;
self.state.sessions.entry(id).or_default().focused_own_channel = true;
}
}
// Where we are with voice, when it changed here: home's last
@@ -1138,22 +715,22 @@ impl App {
self.refresh_tree();
self.refresh_streams();
self.autoshare();
if self.open_client_pending && self.current == Some(id) {
if self.open_client_pending && self.state.current == Some(id) {
self.open_first_client();
}
self.join_after_connect(id);
}
Event::ServerInfo { session, name, backend, capabilities } => {
self.sessions.entry(session as i64).or_default().capabilities = capabilities;
self.state.sessions.entry(session as i64).or_default().capabilities = capabilities;
self.adopt_server_name(session as i64, &name);
if self.current == Some(session as i64) {
if self.state.current == Some(session as i64) {
self.set_status(connected_status(&name, &backend));
}
self.refresh_streams();
self.autoshare();
}
Event::Presence { session, presence } => {
let view = self.sessions.entry(session as i64).or_default();
let view = self.state.sessions.entry(session as i64).or_default();
// The server chat shows its welcome and host message, with
// their pictures.
let said = crate::chat::server_texts(&view.presence.server)
@@ -1171,7 +748,7 @@ impl App {
if renamed && self.remember_voice(session as i64) {
self.refresh_servers();
}
if self.current == Some(session as i64) {
if self.state.current == Some(session as i64) {
if said {
self.fetch_previews(session as i64);
}
@@ -1185,20 +762,20 @@ impl App {
}
}
Event::Talking { session, client, talking } => {
let view = self.sessions.entry(session as i64).or_default();
let view = self.state.sessions.entry(session as i64).or_default();
if talking {
view.talking.insert(client);
} else {
view.talking.remove(&client);
}
if self.current == Some(session as i64) {
if self.state.current == Some(session as i64) {
self.refresh_tree();
}
}
Event::InputLevel { session, level_db, sending } => {
let shown = match session {
Some(s) => self.current == Some(s as i64),
None => self.mic_test,
Some(s) => self.state.current == Some(s as i64),
None => self.state.mic_test,
};
if shown && let Some(ui) = self.ui.upgrade() {
let bridge = ui.global::<Bridge>();
@@ -1213,7 +790,7 @@ impl App {
// know the server yet): those get ids and reactions instead.
Event::Chat { session, message } => {
let id = session as i64;
if !self.sessions.entry(id).or_default().has_history() {
if !self.state.sessions.entry(id).or_default().has_history() {
self.add_message(id, message);
}
}
@@ -1228,12 +805,12 @@ impl App {
self.gateway_update(session as i64, update);
}
Event::Groups { session, server_groups, channel_groups } => {
let view = self.sessions.entry(session as i64).or_default();
let view = self.state.sessions.entry(session as i64).or_default();
view.server_groups = (*server_groups).clone();
// Display order, as TeamSpeak sorts them.
view.server_groups.sort_by_key(|g| (g.sort_id, g.id));
view.channel_groups = (*channel_groups).clone();
if self.current == Some(session as i64) {
if self.state.current == Some(session as i64) {
self.refresh_tree();
}
}
@@ -1244,11 +821,11 @@ impl App {
}
// Pictures can arrive after the rows were built: draw them again.
Event::AvatarReady { session, client_uid, path, .. } => {
let view = self.sessions.entry(session as i64).or_default();
let view = self.state.sessions.entry(session as i64).or_default();
// A file that arrives again is decoded again if it changed.
crate::images::reloaded(&path);
view.avatars.insert(client_uid, path);
if self.current == Some(session as i64) {
if self.state.current == Some(session as i64) {
self.refresh_tree();
self.refresh_chat();
self.refresh_toolbar();
@@ -1257,21 +834,21 @@ impl App {
}
}
Event::IconReady { session, icon, path } => {
let view = self.sessions.entry(session as i64).or_default();
let view = self.state.sessions.entry(session as i64).or_default();
crate::images::reloaded(&path);
view.icons.insert(icon, path);
self.refresh_servers();
if self.current == Some(session as i64) {
if self.state.current == Some(session as i64) {
self.refresh_tree();
self.refresh_toolbar();
}
}
Event::PictureReady { session, url, path } => {
let view = self.sessions.entry(session as i64).or_default();
let view = self.state.sessions.entry(session as i64).or_default();
// The host banner reloads into the same file.
crate::images::reloaded(&path);
view.pictures.insert(url, path);
if self.current == Some(session as i64) {
if self.state.current == Some(session as i64) {
self.refresh_toolbar();
self.refresh_tree();
self.refresh_chat();
@@ -1282,9 +859,9 @@ impl App {
self.transfer_progress(session as i64, transfer, state);
}
// The engine's contacts would replace the sample ones.
Event::ContactsChanged { .. } if self.demo_ui && !self.contacts.is_empty() => {}
Event::ContactsChanged { .. } if self.demo_ui && !self.state.contacts.is_empty() => {}
Event::ContactsChanged { contacts } => {
self.contacts = contacts.iter().map(|c| (c.uid.clone(), c.clone())).collect();
self.state.contacts = contacts.iter().map(|c| (c.uid.clone(), c.clone())).collect();
self.refresh_member_card();
}
// The sample sessions of VOELIN_DEMO_UI are unknown to the engine.
@@ -1297,7 +874,7 @@ impl App {
Event::SettingRejected { key, message } => {
self.set_status(format!("Setting {key}: {message}"));
}
// The Stream Studio's stream (studio.rs).
// The Stream Studio's stream (studio/).
Event::StreamState { session, state } if self.studio_streams_to(session as i64) => {
self.studio_stream_state(state);
}
@@ -1312,7 +889,7 @@ impl App {
fn tick(&mut self) {
self.tick_streams();
self.tick_pages();
if self.audio_dirty {
if self.state.audio_dirty {
self.save_audio();
}
}