Move SessionView, Tab, Msg and the App data fields into voelin-ui-vm::state
The sessions and their chat tabs, the downloads, pins and linked pictures, and the data the screens share (the servers, the settings, the dialogs' targets, the share and watch bookkeeping) no longer live in the Slint crate. `SessionView<L>` and `Tab<L>` are generic over the list type of a tab's chat lines: the Slint app plugs in `Rows<ChatLine>` (`app::ChatRows`), a GPUI view can use a plain `Vec`. `App` keeps one `AppState` in `state` and the Slint models; every `self.sessions`, `self.current`, `self.bookmarks`, ... becomes `self.state.<field>`. server_icon and server_icon_for stay with the session: `ImageRef` is toolkit-free now, so they need no adapter. Tests for the tab and session logic (private chat focus, tab removal, read markers, the divider) are new, since that logic could not be tested without the Slint crate before. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ce7ec3afb7
commit
ac4cee0a8f
21 files changed
+1163
-864
No files matched your search
@@ -15,6 +15,7 @@ pub mod list;
|
||||
pub mod servers;
|
||||
pub mod settings;
|
||||
pub mod social;
|
||||
pub mod state;
|
||||
pub mod streams;
|
||||
pub mod studio;
|
||||
pub mod studio_bridge;
|
||||
|
||||
@@ -0,0 +1,719 @@
|
||||
//! What the client knows, apart from how it is shown: the servers' sessions
|
||||
//! with their chat tabs, and the data the screens share. A front end owns
|
||||
//! one [`AppState`] and fills it from the engine's events; the view models
|
||||
//! (`chat`, `tree`, `servers`, ...) turn it into rows.
|
||||
//!
|
||||
//! The lines of a chat tab are the front end's own list type `L`: a Slint
|
||||
//! model (`bind::rows::Rows`), or a plain `Vec` of rows.
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use voelin_core::stream::StreamInfo;
|
||||
use voelin_core::{
|
||||
AudioSettings, Bytes, Contact, HistoryMessage, OfflineMessageInfo, SessionState, TransferState,
|
||||
VoiceState,
|
||||
};
|
||||
use voelin_gateway_proto::{
|
||||
Action, ActivityEntry, ConfigEntry, EventInfo, PermRuleInfo, StreamEntry, TopicInfo,
|
||||
};
|
||||
use voelin_model::{Capabilities, ChannelId, ChatMessage, ChatTarget, GroupInfo, Presence};
|
||||
use voelin_store::Bookmark;
|
||||
|
||||
use crate::chat::{LineCache, Previous};
|
||||
use crate::image::ImageRef;
|
||||
use crate::settings::{ClientPlaybackMap, DeviceChoices, UiSettings};
|
||||
|
||||
/// The store's name of a chat.
|
||||
pub fn store_target(target: &ChatTarget) -> voelin_store::ChatTarget {
|
||||
match target {
|
||||
ChatTarget::Server => voelin_store::ChatTarget::Server,
|
||||
ChatTarget::Channel(cid) => voelin_store::ChatTarget::Channel(*cid),
|
||||
ChatTarget::Private(uid) => voelin_store::ChatTarget::Private(uid.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
/// A file being downloaded from a chat message.
|
||||
pub struct Download {
|
||||
/// The message's handle.
|
||||
pub key: i32,
|
||||
/// Which of the message's links this is.
|
||||
pub index: usize,
|
||||
/// The file's name.
|
||||
pub name: String,
|
||||
/// How the transfer stands.
|
||||
pub state: TransferState,
|
||||
}
|
||||
|
||||
/// A pinned message of a chat, with who pinned it.
|
||||
pub struct PinRow {
|
||||
/// The message's handle.
|
||||
pub key: i32,
|
||||
/// The message.
|
||||
pub message: HistoryMessage,
|
||||
/// Who pinned it.
|
||||
pub by: String,
|
||||
/// When it was pinned.
|
||||
pub ts_ms: i64,
|
||||
}
|
||||
|
||||
/// A linked picture.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Preview {
|
||||
/// Downloading (transfer id).
|
||||
Loading(u64),
|
||||
/// Downloaded: the file's bytes.
|
||||
Ready(Bytes),
|
||||
/// Too large, not a picture, or the download failed.
|
||||
Failed,
|
||||
}
|
||||
|
||||
/// What a session's gateway and voice connection add for these screens.
|
||||
#[derive(Default)]
|
||||
pub struct SessionExtra {
|
||||
/// The gateway's stream directory.
|
||||
pub directory: Vec<StreamEntry>,
|
||||
/// The gateway's events by start time.
|
||||
pub events: Vec<EventInfo>,
|
||||
/// The events were asked for and arrived.
|
||||
pub events_loaded: bool,
|
||||
/// The events whose answers are shown (by event id).
|
||||
pub expanded: HashSet<i64>,
|
||||
/// The activity feed, newest first.
|
||||
pub activity: Vec<ActivityEntry>,
|
||||
/// Our unique id at the gateway.
|
||||
pub gateway_uid: Option<String>,
|
||||
/// What we may do at the gateway.
|
||||
pub actions: Vec<Action>,
|
||||
/// Gateway administration: its keys.
|
||||
pub config: Vec<ConfigEntry>,
|
||||
/// Gateway administration: its permission rules.
|
||||
pub perms: Vec<PermRuleInfo>,
|
||||
/// Offline messages (voice).
|
||||
pub inbox: Vec<OfflineMessageInfo>,
|
||||
/// The offline messages were asked for.
|
||||
pub inbox_asked: bool,
|
||||
/// Pictures linked in chat, by link.
|
||||
pub previews: HashMap<String, Preview>,
|
||||
/// When this session's presence first came (ms): friends found in it
|
||||
/// then are not "coming online".
|
||||
pub presence_since: i64,
|
||||
/// "TeamSpeak 6", "TeamSpeak 3" once the server told what it runs;
|
||||
/// empty before that, and for software nobody recognised.
|
||||
pub product: String,
|
||||
}
|
||||
|
||||
/// A message of a chat with the handle the UI knows it by: the engine's
|
||||
/// local ids are 64 bit, a bridge `int` is not.
|
||||
pub struct Msg {
|
||||
/// The handle (see [`Tab::take_key`]).
|
||||
pub key: i32,
|
||||
/// The message as the engine stored it.
|
||||
pub message: HistoryMessage,
|
||||
}
|
||||
|
||||
/// A chat of a session: its lines (`L`) are what the chat view shows while
|
||||
/// the tab is selected, so a new message is one row appended.
|
||||
pub struct Tab<L> {
|
||||
/// The chat.
|
||||
pub target: ChatTarget,
|
||||
/// The tab's name.
|
||||
pub title: String,
|
||||
/// The lines the chat view shows.
|
||||
pub lines: L,
|
||||
/// 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)>,
|
||||
/// What the store has of `read`.
|
||||
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<PinRow>,
|
||||
/// The pins were asked for and arrived.
|
||||
pub pins_loaded: bool,
|
||||
/// The gateway topics of this chat.
|
||||
pub topics: Vec<TopicInfo>,
|
||||
/// The topics were asked for and arrived.
|
||||
pub topics_loaded: bool,
|
||||
/// The open topic.
|
||||
pub topic: Option<i64>,
|
||||
/// The messages of the open topic.
|
||||
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: LineCache,
|
||||
}
|
||||
|
||||
impl<L: Default> Tab<L> {
|
||||
/// An empty tab for a chat, nothing read or asked for.
|
||||
pub fn new(target: ChatTarget, title: String) -> Self {
|
||||
Self {
|
||||
target,
|
||||
title,
|
||||
lines: L::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
|
||||
}
|
||||
|
||||
/// The message with this handle, in the chat or in the open topic.
|
||||
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::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::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::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(&store_target(&self.target).key()) {
|
||||
self.read = self.read.max(Some(read));
|
||||
self.stored_read = Some(read);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What we know about one server session.
|
||||
pub struct SessionView<L> {
|
||||
/// Where the connections stand.
|
||||
pub state: SessionState,
|
||||
/// What the server offers.
|
||||
pub capabilities: Capabilities,
|
||||
/// The server's channels and clients.
|
||||
pub presence: Arc<Presence>,
|
||||
/// The channels folded in the tree.
|
||||
pub collapsed: HashSet<ChannelId>,
|
||||
/// The clients talking now.
|
||||
pub talking: HashSet<u16>,
|
||||
/// The chats, the server's first.
|
||||
pub tabs: Vec<Tab<L>>,
|
||||
/// The chat on screen (an index of `tabs`).
|
||||
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, Download>,
|
||||
/// The next transfer id.
|
||||
pub next_transfer: u64,
|
||||
/// What the home, messages and events screens keep of the session.
|
||||
pub extra: 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)>,
|
||||
/// The server unique id `reads` are for.
|
||||
pub reads_of: Option<String>,
|
||||
}
|
||||
|
||||
impl<L: Default> Default for SessionView<L> {
|
||||
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<L: Default> SessionView<L> {
|
||||
/// 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::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<L> {
|
||||
let tab = self.tabs.remove(index);
|
||||
if self.current_tab > index {
|
||||
self.current_tab -= 1;
|
||||
} else if self.current_tab == index {
|
||||
let (strip, _) = crate::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<L> {
|
||||
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) -> ImageRef {
|
||||
crate::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) -> ImageRef {
|
||||
if self.icon_address.as_deref() == Some(address) {
|
||||
self.server_icon()
|
||||
} else {
|
||||
ImageRef::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The data the screens share, apart from the engine and the toolkit: the
|
||||
/// servers and what is known of their sessions, the settings the screens
|
||||
/// show and the dialogs' targets.
|
||||
pub struct AppState<L> {
|
||||
/// The saved servers, in the rail's order.
|
||||
pub bookmarks: Vec<Bookmark>,
|
||||
/// The server shown (a bookmark id).
|
||||
pub current: Option<i64>,
|
||||
/// What is known of each server's session, by bookmark id.
|
||||
pub sessions: HashMap<i64, SessionView<L>>,
|
||||
/// The line at the bottom: what happened last.
|
||||
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 UI's own settings (a working copy of the `ui` key).
|
||||
pub settings: UiSettings,
|
||||
/// The audio settings (a working copy).
|
||||
pub audio: AudioSettings,
|
||||
/// Audio settings changed since they were last stored.
|
||||
pub audio_dirty: bool,
|
||||
/// The input devices, as the settings list them.
|
||||
pub inputs: DeviceChoices,
|
||||
/// The output devices, as the settings list them.
|
||||
pub outputs: DeviceChoices,
|
||||
/// Local playback of each client, by unique id.
|
||||
pub playback: ClientPlaybackMap,
|
||||
/// The engine's contacts, by unique id.
|
||||
pub contacts: HashMap<String, 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: the toolkit 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.
|
||||
pub reading: Option<(i64, ChatTarget)>,
|
||||
/// The microphone test runs.
|
||||
pub mic_test: bool,
|
||||
/// The capture for a share is being started.
|
||||
pub share_busy: bool,
|
||||
/// Why the last share did not start.
|
||||
pub share_error: String,
|
||||
/// 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,
|
||||
/// Servers whose gateway was looked up in this run.
|
||||
pub gateways_looked_up: HashSet<i64>,
|
||||
/// 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)>,
|
||||
}
|
||||
|
||||
impl<L> AppState<L> {
|
||||
/// The state at start: the saved servers (the first one shown), the
|
||||
/// stored settings, nothing known of any session yet.
|
||||
pub fn new(
|
||||
bookmarks: Vec<Bookmark>,
|
||||
settings: UiSettings,
|
||||
audio: AudioSettings,
|
||||
playback: ClientPlaybackMap,
|
||||
) -> Self {
|
||||
Self {
|
||||
current: bookmarks.first().map(|b| b.id),
|
||||
bookmarks,
|
||||
sessions: HashMap::new(),
|
||||
status: String::new(),
|
||||
copy_note: None,
|
||||
member_filter: String::new(),
|
||||
topic_filter: String::new(),
|
||||
voice_view: false,
|
||||
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,
|
||||
share_busy: false,
|
||||
share_error: String::new(),
|
||||
pending_watch: None,
|
||||
stream_volume: 100.0,
|
||||
gateways_looked_up: HashSet::new(),
|
||||
uploads: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use voelin_store::MessageSource;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn msg(key: i32, id: i64, ts_ms: i64, own: bool) -> Msg {
|
||||
Msg {
|
||||
key,
|
||||
message: HistoryMessage {
|
||||
id,
|
||||
message: ChatMessage {
|
||||
target: ChatTarget::Server,
|
||||
author_name: if own { "me" } else { "you" }.into(),
|
||||
author_uid: None,
|
||||
author_id: None,
|
||||
text: format!("message {id}"),
|
||||
ts_ms,
|
||||
via_relay: false,
|
||||
blocked: false,
|
||||
},
|
||||
source: MessageSource::Voice,
|
||||
remote_id: None,
|
||||
topic_id: None,
|
||||
reactions: Vec::new(),
|
||||
pinned: false,
|
||||
rev: 0,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn is_own(message: &ChatMessage) -> bool {
|
||||
message.author_name == "me"
|
||||
}
|
||||
|
||||
/// A session with the server's chat and then these.
|
||||
fn session(targets: &[ChatTarget]) -> SessionView<()> {
|
||||
let mut view = SessionView::<()>::default();
|
||||
for target in targets {
|
||||
view.tabs.push(Tab::new(target.clone(), "chat".into()));
|
||||
}
|
||||
view
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_private_chat_stays_current_until_its_page_is_left() {
|
||||
let mut view = session(&[ChatTarget::Channel(1), ChatTarget::Private("uid".into())]);
|
||||
view.set_current_tab(2);
|
||||
assert_eq!((view.current_tab, &view.channel_tab), (2, &ChatTarget::Server));
|
||||
// A chat of the strip does not take the private chat's place ...
|
||||
view.focus_tab(1);
|
||||
assert_eq!((view.current_tab, &view.channel_tab), (2, &ChatTarget::Channel(1)));
|
||||
// ... it is current once the page is left, and only once.
|
||||
assert!(view.leave_private());
|
||||
assert_eq!(view.current_tab, 1);
|
||||
assert!(!view.leave_private());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removing_a_tab_keeps_the_current_one_or_picks_the_next_of_the_strip() {
|
||||
let mut view = session(&[ChatTarget::Channel(1), ChatTarget::Channel(2)]);
|
||||
view.set_current_tab(2);
|
||||
view.remove_tab(1);
|
||||
assert_eq!(view.current_tab, 1);
|
||||
assert_eq!(view.tabs[1].target, ChatTarget::Channel(2));
|
||||
// The current tab itself: the strip's next one takes its place.
|
||||
let mut view = session(&[ChatTarget::Channel(1), ChatTarget::Channel(2)]);
|
||||
view.set_current_tab(1);
|
||||
view.remove_tab(1);
|
||||
assert_eq!(view.tabs[view.current_tab].target, ChatTarget::Channel(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unread_messages_are_counted_after_the_read_marker_and_not_ours() {
|
||||
let mut tab = Tab::<()>::new(ChatTarget::Server, "Server".into());
|
||||
tab.messages = vec![msg(1, 1, 100, false), msg(2, 2, 200, true), msg(3, 3, 300, false)];
|
||||
tab.count_unread(is_own);
|
||||
assert_eq!(tab.unread, 2);
|
||||
tab.read = Some((100, 1));
|
||||
tab.count_unread(is_own);
|
||||
assert_eq!(tab.unread, 1);
|
||||
assert_eq!(tab.newest(), Some((300, 3)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn entering_a_tab_puts_the_divider_above_the_first_new_message() {
|
||||
let mut tab = Tab::<()>::new(ChatTarget::Server, "Server".into());
|
||||
tab.messages = vec![msg(1, 1, 100, false), msg(2, 2, 200, false), msg(3, 3, 300, false)];
|
||||
tab.read = Some((100, 1));
|
||||
tab.count_unread(is_own);
|
||||
tab.enter(is_own);
|
||||
assert_eq!(tab.divider, Some(2));
|
||||
assert_eq!((tab.unread, tab.read), (0, Some((300, 3))));
|
||||
// A divider that shows stays when the tab is entered again.
|
||||
tab.unread = 1;
|
||||
tab.enter(is_own);
|
||||
assert_eq!(tab.divider, Some(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_new_tab_starts_from_where_the_store_says_the_chat_was_read() {
|
||||
let mut view = SessionView::<()>::default();
|
||||
view.reads.insert(store_target(&ChatTarget::Channel(5)).key(), (700, 9));
|
||||
let tab = view.new_tab(ChatTarget::Channel(5), "five".into());
|
||||
assert_eq!((tab.read, tab.stored_read), (Some((700, 9)), Some((700, 9))));
|
||||
let other = view.new_tab(ChatTarget::Channel(6), "six".into());
|
||||
assert_eq!((other.read, other.stored_read), (None, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn handles_are_taken_one_by_one_and_found_in_topics_too() {
|
||||
let mut tab = Tab::<()>::new(ChatTarget::Server, "Server".into());
|
||||
let (a, b) = (tab.take_key(), tab.take_key());
|
||||
assert_ne!(a, b);
|
||||
tab.topic_messages.push(msg(a, 4, 400, false));
|
||||
assert_eq!(tab.message(a).map(|m| m.id), Some(4));
|
||||
assert!(tab.message(b).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unread_counts_split_between_the_strip_and_private_chats() {
|
||||
let mut view = session(&[ChatTarget::Channel(1), ChatTarget::Private("uid".into())]);
|
||||
view.tabs[0].unread = 2;
|
||||
view.tabs[1].unread = 3;
|
||||
view.tabs[2].unread = 4;
|
||||
assert_eq!((view.channel_unread(), view.private_unread()), (5, 4));
|
||||
}
|
||||
}
|
||||
+57
-482
@@ -7,7 +7,6 @@
|
||||
//! 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,24 +21,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;
|
||||
use crate::vm::chat::Previous;
|
||||
|
||||
slint::include_modules!();
|
||||
|
||||
@@ -120,363 +114,17 @@ 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: Rows<vm::bridge::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: Rows::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) -> vm::ImageRef {
|
||||
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) -> vm::ImageRef {
|
||||
if self.icon_address.as_deref() == Some(address) {
|
||||
self.server_icon()
|
||||
} else {
|
||||
vm::ImageRef::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
|
||||
/// ([`Rows::sync`]).
|
||||
@@ -567,75 +215,28 @@ 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.
|
||||
@@ -829,44 +430,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 +506,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 +576,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 +612,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 +626,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 +660,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 +686,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 +699,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 +713,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 +746,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 +760,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 +788,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 +803,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 +819,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 +832,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 +857,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.
|
||||
@@ -1312,7 +887,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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ pub(super) fn wire(ui: &MainWindow) {
|
||||
});
|
||||
bridge.on_join_channel(|cid| {
|
||||
with_app(|app| {
|
||||
if let Some(session) = app.current {
|
||||
if let Some(session) = app.state.current {
|
||||
app.join_channel(session, cid as ChannelId);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ pub(super) fn wire(ui: &MainWindow) {
|
||||
with_app(|app| app.audio_changed(&form.into()));
|
||||
});
|
||||
bridge.on_toggle_mic_test(|| {
|
||||
with_app(|app| app.set_mic_test(!app.mic_test));
|
||||
with_app(|app| app.set_mic_test(!app.state.mic_test));
|
||||
});
|
||||
bridge.on_apply_ptt(|enabled, key| {
|
||||
with_app(|app| app.apply_ptt(enabled, key.to_string()));
|
||||
|
||||
@@ -30,12 +30,13 @@ use voelin_gateway_proto::{ErrorCode, TopicInfo, feature};
|
||||
use voelin_model::{ChatMessage, ChatTarget, HostMessageMode, ServerDetails};
|
||||
use voelin_store::ChatRead;
|
||||
|
||||
use crate::app::{App, Bridge, Msg, Nav, SessionView, Tab};
|
||||
use crate::app::{App, Bridge, Nav, SessionView, Tab};
|
||||
use crate::settings::UI_IMAGE_PREVIEW_KB;
|
||||
use crate::vm;
|
||||
use crate::vm::bbcode::LinkKind;
|
||||
use crate::vm::bridge::{ChatLine, ChatTab, FileItem, PinItem};
|
||||
use crate::vm::chat::{LineCache, LineCtx, Previous};
|
||||
use crate::vm::state::{Download, Msg, PinRow, store_target};
|
||||
|
||||
/// Where the server's welcome and host message keep what their lines were
|
||||
/// built from (`LineCache`), apart from the messages' ids.
|
||||
@@ -62,32 +63,6 @@ pub(crate) fn server_text<'a>(view: &'a SessionView, tab: &Tab, key: i32) -> Opt
|
||||
server_texts(&view.presence.server).get((-1 - key) as usize).map(|(text, _)| *text)
|
||||
}
|
||||
|
||||
/// The store's name of a chat.
|
||||
pub(crate) fn store_target(target: &ChatTarget) -> voelin_store::ChatTarget {
|
||||
match target {
|
||||
ChatTarget::Server => voelin_store::ChatTarget::Server,
|
||||
ChatTarget::Channel(cid) => voelin_store::ChatTarget::Channel(*cid),
|
||||
ChatTarget::Private(uid) => voelin_store::ChatTarget::Private(uid.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
/// A file being downloaded from a chat message.
|
||||
pub(crate) struct Download {
|
||||
/// The message's handle and which of its links this is.
|
||||
pub key: i32,
|
||||
pub index: usize,
|
||||
pub name: String,
|
||||
pub state: TransferState,
|
||||
}
|
||||
|
||||
/// A pinned message of a chat, with who pinned it.
|
||||
pub(crate) struct PinRow {
|
||||
pub key: i32,
|
||||
pub message: HistoryMessage,
|
||||
pub by: String,
|
||||
pub ts_ms: i64,
|
||||
}
|
||||
|
||||
/// "3 min ago", "yesterday", "12 Mar".
|
||||
fn ago(ts_ms: i64) -> String {
|
||||
let Some(then) = chrono::DateTime::from_timestamp_millis(ts_ms) else { return String::new() };
|
||||
@@ -105,10 +80,10 @@ fn ago(ts_ms: i64) -> String {
|
||||
|
||||
impl App {
|
||||
pub(crate) fn open_chat(&mut self, target: ChatTarget, focus: bool) {
|
||||
let Some(id) = self.current else { return };
|
||||
let Some(id) = self.state.current else { return };
|
||||
let index = self.chat_tab(id, target);
|
||||
if focus {
|
||||
self.sessions.entry(id).or_default().focus_tab(index);
|
||||
self.state.sessions.entry(id).or_default().focus_tab(index);
|
||||
self.prefetch_counts();
|
||||
self.track_reading();
|
||||
}
|
||||
@@ -123,7 +98,7 @@ impl App {
|
||||
ChatTarget::Private(uid) => self.peer_name(uid, None),
|
||||
_ => String::new(),
|
||||
};
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let view = self.state.sessions.entry(id).or_default();
|
||||
if let Some(i) = view.tabs.iter().position(|t| t.target == target) {
|
||||
return i;
|
||||
}
|
||||
@@ -149,7 +124,7 @@ impl App {
|
||||
view.set_current_tab(index);
|
||||
view.tabs[index].topic = None;
|
||||
}
|
||||
if let Some(id) = self.current {
|
||||
if let Some(id) = self.state.current {
|
||||
self.fetch_previews(id);
|
||||
}
|
||||
self.prefetch_counts();
|
||||
@@ -159,13 +134,13 @@ impl App {
|
||||
}
|
||||
|
||||
pub(crate) fn close_tab(&mut self, index: usize) {
|
||||
let Some(id) = self.current else { return };
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let Some(id) = self.state.current else { return };
|
||||
let view = self.state.sessions.entry(id).or_default();
|
||||
if index == 0 || index >= view.tabs.len() {
|
||||
return;
|
||||
}
|
||||
self.save_read(id, index);
|
||||
let tab = self.sessions.entry(id).or_default().remove_tab(index);
|
||||
let tab = self.state.sessions.entry(id).or_default().remove_tab(index);
|
||||
self.engine.send(Command::CloseChat { session: id as u64, target: tab.target });
|
||||
self.prefetch_counts();
|
||||
self.track_reading();
|
||||
@@ -174,8 +149,8 @@ impl App {
|
||||
}
|
||||
|
||||
pub(crate) fn send_message(&mut self, text: String) {
|
||||
let Some(id) = self.current else { return };
|
||||
let Some(view) = self.sessions.get(&id) else { return };
|
||||
let Some(id) = self.state.current else { return };
|
||||
let Some(view) = self.state.sessions.get(&id) else { return };
|
||||
let target = view.tabs[view.current_tab].target.clone();
|
||||
self.engine.send(Command::SendChat { session: id as u64, target, text });
|
||||
}
|
||||
@@ -199,10 +174,10 @@ impl App {
|
||||
/// A live message of a session without stored history: appended as it
|
||||
/// comes, without an id.
|
||||
pub(crate) fn add_message(&mut self, id: i64, message: ChatMessage) {
|
||||
let current = self.current == Some(id);
|
||||
let current = self.state.current == Some(id);
|
||||
let reading = self.reads_now(id);
|
||||
let new = !self.is_own(id, &message);
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let view = self.state.sessions.entry(id).or_default();
|
||||
let title = vm::chat::tab_title(&view.presence, &message.target, &message.author_name);
|
||||
let index = Self::tab_for(view, &message.target, || title);
|
||||
let seen = reading && view.current_tab == index;
|
||||
@@ -232,7 +207,7 @@ impl App {
|
||||
source: HistorySource,
|
||||
complete: bool,
|
||||
) {
|
||||
let current = self.current == Some(id);
|
||||
let current = self.state.current == Some(id);
|
||||
let reading = self.reads_now(id);
|
||||
// A private chat is named after the peer, whoever wrote first.
|
||||
let peer = match target {
|
||||
@@ -245,7 +220,7 @@ impl App {
|
||||
)),
|
||||
_ => None,
|
||||
};
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let view = self.state.sessions.entry(id).or_default();
|
||||
let author = messages.first().map_or("", |m| m.message.author_name.as_str());
|
||||
let title = peer.unwrap_or_else(|| vm::chat::tab_title(&view.presence, target, author));
|
||||
let index = Self::tab_for(view, target, || title);
|
||||
@@ -309,8 +284,8 @@ impl App {
|
||||
|
||||
/// The page of messages before the oldest one shown.
|
||||
pub(crate) fn load_older(&mut self) {
|
||||
let Some(id) = self.current else { return };
|
||||
let Some(view) = self.sessions.get_mut(&id) else { return };
|
||||
let Some(id) = self.state.current else { return };
|
||||
let Some(view) = self.state.sessions.get_mut(&id) else { return };
|
||||
let tab = &mut view.tabs[view.current_tab];
|
||||
if tab.loading || tab.complete {
|
||||
return;
|
||||
@@ -385,7 +360,7 @@ impl App {
|
||||
cache.keep(ids, messages.len());
|
||||
}
|
||||
// Pokes of a private chat's peer show among its messages.
|
||||
if let (ChatTarget::Private(uid), Some(session)) = (&tab.target, self.current) {
|
||||
if let (ChatTarget::Private(uid), Some(session)) = (&tab.target, self.state.current) {
|
||||
lines.extend(self.poke_lines(session, uid));
|
||||
lines.sort_by_key(|(ts, _)| *ts);
|
||||
}
|
||||
@@ -544,7 +519,7 @@ impl App {
|
||||
.divider
|
||||
.and_then(|d| tab.messages.iter().position(|m| m.message.id == d))
|
||||
.map_or(&[][..], |i| &tab.messages[i..]);
|
||||
let session = self.current.unwrap_or_default();
|
||||
let session = self.state.current.unwrap_or_default();
|
||||
let count = new.iter().filter(|m| !self.is_own(session, &m.message.message)).count();
|
||||
bridge.set_unread_index(divider.map_or(-1, |i| i as i32));
|
||||
bridge.set_unread_count(count as i32);
|
||||
@@ -585,7 +560,7 @@ impl App {
|
||||
})
|
||||
.collect();
|
||||
self.models.pins.sync(&pins);
|
||||
let filter = self.topic_filter.trim().to_lowercase();
|
||||
let filter = self.state.topic_filter.trim().to_lowercase();
|
||||
let now = chrono::Utc::now().timestamp_millis();
|
||||
let topics: Vec<vm::bridge::TopicItem> = tab
|
||||
.topics
|
||||
@@ -654,7 +629,7 @@ impl App {
|
||||
/// New messages of session `id` in its current tab are read as they
|
||||
/// come: they are on screen in the focused window.
|
||||
fn reads_now(&self, id: i64) -> bool {
|
||||
self.focused && self.current == Some(id) && self.chat_shown()
|
||||
self.state.focused && self.state.current == Some(id) && self.chat_shown()
|
||||
}
|
||||
|
||||
/// After anything that can change which chat is on screen (a tab, a
|
||||
@@ -662,26 +637,26 @@ impl App {
|
||||
/// loses its divider; the one on screen, in the focused window, is read
|
||||
/// (its divider above what was new). `true` if a tab changed.
|
||||
pub(crate) fn track_reading(&mut self) -> bool {
|
||||
let open = self.current.filter(|_| self.chat_shown()).and_then(|id| {
|
||||
let view = self.sessions.get(&id)?;
|
||||
let open = self.state.current.filter(|_| self.chat_shown()).and_then(|id| {
|
||||
let view = self.state.sessions.get(&id)?;
|
||||
Some((id, view.tabs.get(view.current_tab)?.target.clone()))
|
||||
});
|
||||
let mut changed = false;
|
||||
if open != self.reading {
|
||||
if let Some((id, target)) = self.reading.take()
|
||||
if open != self.state.reading {
|
||||
if let Some((id, target)) = self.state.reading.take()
|
||||
&& let Some(index) = self.tab_index(id, &target)
|
||||
{
|
||||
let tab = &mut self.sessions.entry(id).or_default().tabs[index];
|
||||
let tab = &mut self.state.sessions.entry(id).or_default().tabs[index];
|
||||
changed |= tab.divider.take().is_some();
|
||||
self.save_read(id, index);
|
||||
}
|
||||
self.reading = open.clone();
|
||||
self.state.reading = open.clone();
|
||||
}
|
||||
if let (true, Some((id, target))) = (self.focused, open)
|
||||
if let (true, Some((id, target))) = (self.state.focused, open)
|
||||
&& let Some(index) = self.tab_index(id, &target)
|
||||
{
|
||||
let own_uids = &self.social.own_uids;
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let view = self.state.sessions.entry(id).or_default();
|
||||
let own_client = view.state.own_client;
|
||||
let tab = &mut view.tabs[index];
|
||||
let before = (tab.unread, tab.divider);
|
||||
@@ -693,7 +668,7 @@ impl App {
|
||||
|
||||
/// Where the tab of `target` is in session `id`.
|
||||
fn tab_index(&self, id: i64, target: &ChatTarget) -> Option<usize> {
|
||||
self.sessions.get(&id)?.tabs.iter().position(|t| t.target == *target)
|
||||
self.state.sessions.get(&id)?.tabs.iter().position(|t| t.target == *target)
|
||||
}
|
||||
|
||||
/// The current chat came on screen or left it (`Nav.chat-shown`).
|
||||
@@ -708,7 +683,7 @@ impl App {
|
||||
/// only).
|
||||
#[cfg(not(target_os = "android"))]
|
||||
pub(crate) fn window_focused(&mut self, focused: bool) {
|
||||
self.focused = focused;
|
||||
self.state.focused = focused;
|
||||
if self.track_reading() {
|
||||
self.refresh_chat();
|
||||
self.refresh_servers();
|
||||
@@ -718,8 +693,8 @@ impl App {
|
||||
/// The current chat is read (the bar over its messages): the divider
|
||||
/// goes.
|
||||
pub(crate) fn mark_read(&mut self) {
|
||||
let Some(id) = self.current else { return };
|
||||
let Some(view) = self.sessions.get_mut(&id) else { return };
|
||||
let Some(id) = self.state.current else { return };
|
||||
let Some(view) = self.state.sessions.get_mut(&id) else { return };
|
||||
let index = view.current_tab;
|
||||
let tab = &mut view.tabs[index];
|
||||
tab.divider = None;
|
||||
@@ -735,7 +710,7 @@ impl App {
|
||||
if self.demo_ui {
|
||||
return;
|
||||
}
|
||||
let Some(view) = self.sessions.get_mut(&id) else { return };
|
||||
let Some(view) = self.state.sessions.get_mut(&id) else { return };
|
||||
let Some(server_uid) = view.state.server_uid.as_deref() else { return };
|
||||
let Some(tab) = view.tabs.get_mut(index) else { return };
|
||||
let Some((ts_ms, message)) = tab.read.filter(|r| tab.stored_read != Some(*r)) else {
|
||||
@@ -757,7 +732,7 @@ impl App {
|
||||
/// Store where every chat of session `id` was read (it ended, or the
|
||||
/// app exits).
|
||||
pub(crate) fn save_reads(&mut self, id: i64) {
|
||||
let count = self.sessions.get(&id).map_or(0, |v| v.tabs.len());
|
||||
let count = self.state.sessions.get(&id).map_or(0, |v| v.tabs.len());
|
||||
for index in 0..count {
|
||||
self.save_read(id, index);
|
||||
}
|
||||
@@ -767,7 +742,7 @@ impl App {
|
||||
/// server is known (or another one: the gateway's id wins): its tabs
|
||||
/// start from there, now and when they open.
|
||||
pub(crate) fn load_reads(&mut self, id: i64) {
|
||||
let Some(view) = self.sessions.get_mut(&id) else { return };
|
||||
let Some(view) = self.state.sessions.get_mut(&id) else { return };
|
||||
if self.demo_ui || view.state.server_uid.is_none() || view.reads_of == view.state.server_uid
|
||||
{
|
||||
return;
|
||||
@@ -794,8 +769,8 @@ impl App {
|
||||
}
|
||||
|
||||
pub(crate) fn gateway_update(&mut self, id: i64, update: GatewayUpdate) {
|
||||
let current = self.current == Some(id);
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let current = self.state.current == Some(id);
|
||||
let view = self.state.sessions.entry(id).or_default();
|
||||
match update {
|
||||
GatewayUpdate::Connected { capabilities, .. }
|
||||
| GatewayUpdate::Capabilities { capabilities } => {
|
||||
@@ -976,8 +951,8 @@ impl App {
|
||||
|
||||
/// The topics drawer's search.
|
||||
pub(crate) fn search_topics(&mut self, text: String) {
|
||||
if self.topic_filter != text {
|
||||
self.topic_filter = text;
|
||||
if self.state.topic_filter != text {
|
||||
self.state.topic_filter = text;
|
||||
self.refresh_chat();
|
||||
}
|
||||
}
|
||||
@@ -1024,7 +999,7 @@ impl App {
|
||||
|
||||
/// Download a file a message links, into the download folder.
|
||||
pub(crate) fn download_file(&mut self, key: i32, index: i32) {
|
||||
let Some(id) = self.current else { return };
|
||||
let Some(id) = self.state.current else { return };
|
||||
let index = index.max(0) as usize;
|
||||
let Some(file) =
|
||||
self.message_of(key).and_then(|m| m.message.file_refs().into_iter().nth(index))
|
||||
@@ -1033,7 +1008,7 @@ impl App {
|
||||
};
|
||||
let dir = dirs::download_dir().unwrap_or_else(|| PathBuf::from("."));
|
||||
let path = dir.join(&file.name);
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let view = self.state.sessions.entry(id).or_default();
|
||||
let transfer = view.next_transfer;
|
||||
view.next_transfer += 1;
|
||||
view.downloads.insert(
|
||||
@@ -1052,10 +1027,10 @@ impl App {
|
||||
|
||||
pub(crate) fn transfer_progress(&mut self, id: i64, transfer: u64, state: TransferState) {
|
||||
// An upload from the composer: post the file's link once it is up.
|
||||
if let Some((_, channel, name)) = self.uploads.get(&transfer).cloned() {
|
||||
if let Some((_, channel, name)) = self.state.uploads.get(&transfer).cloned() {
|
||||
match &state {
|
||||
TransferState::Done { size, .. } => {
|
||||
self.uploads.remove(&transfer);
|
||||
self.state.uploads.remove(&transfer);
|
||||
let file = voelin_model::FileRef {
|
||||
channel,
|
||||
path: "/".into(),
|
||||
@@ -1071,11 +1046,11 @@ impl App {
|
||||
self.set_status(format!("{name} shared"));
|
||||
}
|
||||
TransferState::Failed(e) => {
|
||||
self.uploads.remove(&transfer);
|
||||
self.state.uploads.remove(&transfer);
|
||||
self.set_status(format!("Could not upload {name}: {e}"));
|
||||
}
|
||||
TransferState::Cancelled => {
|
||||
self.uploads.remove(&transfer);
|
||||
self.state.uploads.remove(&transfer);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -1085,14 +1060,14 @@ impl App {
|
||||
return;
|
||||
}
|
||||
let done = matches!(state, TransferState::Done { .. });
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let view = self.state.sessions.entry(id).or_default();
|
||||
let Some(entry) = view.downloads.get_mut(&transfer) else { return };
|
||||
entry.state = state;
|
||||
let name = entry.name.clone();
|
||||
if done {
|
||||
self.set_status(format!("{name} downloaded"));
|
||||
}
|
||||
if self.current == Some(id) {
|
||||
if self.state.current == Some(id) {
|
||||
self.refresh_chat();
|
||||
}
|
||||
}
|
||||
@@ -1100,8 +1075,8 @@ impl App {
|
||||
/// Attach a file to the current channel chat: ask for one, upload it
|
||||
/// into the channel and post its link.
|
||||
pub(crate) fn attach_file(&mut self) {
|
||||
let Some(id) = self.current else { return };
|
||||
let Some(view) = self.sessions.get(&id) else { return };
|
||||
let Some(id) = self.state.current else { return };
|
||||
let Some(view) = self.state.sessions.get(&id) else { return };
|
||||
let ChatTarget::Channel(channel) = view.tabs[view.current_tab].target else {
|
||||
self.set_status("Files can be attached to a channel's chat.");
|
||||
return;
|
||||
@@ -1124,10 +1099,10 @@ impl App {
|
||||
/// Upload a file into a channel and link it in the chat once it is up.
|
||||
pub(crate) fn upload(&mut self, id: i64, channel: u64, from: PathBuf) {
|
||||
let Some(name) = from.file_name().map(|n| n.to_string_lossy().to_string()) else { return };
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let view = self.state.sessions.entry(id).or_default();
|
||||
let transfer = view.next_transfer;
|
||||
view.next_transfer += 1;
|
||||
self.uploads.insert(transfer, (id, channel, name.clone()));
|
||||
self.state.uploads.insert(transfer, (id, channel, name.clone()));
|
||||
self.engine.send(Command::UploadFile {
|
||||
session: id as u64,
|
||||
transfer,
|
||||
|
||||
+12
-12
@@ -184,7 +184,7 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
||||
}
|
||||
Some("observe") => {
|
||||
with_app(|app| {
|
||||
if let Some(id) = app.current {
|
||||
if let Some(id) = app.state.current {
|
||||
app.observe(id);
|
||||
}
|
||||
});
|
||||
@@ -214,7 +214,7 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
||||
}
|
||||
// The current server's dialog, Advanced open.
|
||||
"bookmark" if arg == "edit" => {
|
||||
if let Some(id) = with_app(|app| app.current).flatten() {
|
||||
if let Some(id) = with_app(|app| app.state.current).flatten() {
|
||||
nav.invoke_edit_server(id as i32);
|
||||
}
|
||||
}
|
||||
@@ -425,9 +425,9 @@ fn late(
|
||||
/// The current chat's read marker `back` messages before its end, as if
|
||||
/// they came while away, its "New" divider shown (`VOELIN_OPEN=unread`).
|
||||
fn open_unread(app: &mut App, back: usize) {
|
||||
let Some(id) = app.current else { return };
|
||||
let Some(id) = app.state.current else { return };
|
||||
let own_uids = app.social.own_uids.clone();
|
||||
let Some(view) = app.sessions.get_mut(&id) else { return };
|
||||
let Some(view) = app.state.sessions.get_mut(&id) else { return };
|
||||
let own_client = view.state.own_client;
|
||||
let own = |m: &ChatMessage| crate::social::own_message(&own_uids, own_client, m);
|
||||
let index = view.current_tab;
|
||||
@@ -483,7 +483,7 @@ fn save_png(image: &SharedPixelBuffer<Rgba8Pixel>, path: &std::path::Path) -> Re
|
||||
/// channel, which asks for its password; `wrong` as if the server had
|
||||
/// refused one.
|
||||
fn open_channel_password(app: &mut App, wrong: bool) {
|
||||
let Some(session) = app.current else { return };
|
||||
let Some(session) = app.state.current else { return };
|
||||
let locked = app
|
||||
.view()
|
||||
.and_then(|v| v.presence.channels.values().filter(|c| c.has_password).map(|c| c.id).min());
|
||||
@@ -549,7 +549,7 @@ fn demo_ui(app: &mut App) {
|
||||
client_version: None,
|
||||
cached_server_icon: None,
|
||||
};
|
||||
app.bookmarks = vec![
|
||||
app.state.bookmarks = vec![
|
||||
Bookmark {
|
||||
gateway_url: Some("wss://gw.nightfall.example/v1".into()),
|
||||
..bookmark(DEMO, "Nightfall Guild", "ts.nightfall.example:9987")
|
||||
@@ -559,12 +559,12 @@ fn demo_ui(app: &mut App) {
|
||||
];
|
||||
// Home's "Continue where you left off": a channel of a server without
|
||||
// voice, so it shows Join.
|
||||
app.settings.last_voice = Some(LastVoice {
|
||||
app.state.settings.last_voice = Some(LastVoice {
|
||||
bookmark: DEMO + 1,
|
||||
address: "pixel.example".into(),
|
||||
channel: vec!["Art Corner".into()],
|
||||
});
|
||||
app.current = Some(DEMO);
|
||||
app.state.current = Some(DEMO);
|
||||
let session = DEMO as u64;
|
||||
|
||||
let mut p = Presence { server_name: "Nightfall Guild".into(), ..Default::default() };
|
||||
@@ -940,7 +940,7 @@ fn demo_social(app: &mut App) {
|
||||
// The samples came one by one, as new ones do: all are read (no "New"
|
||||
// line, which a gateway page on screen gets), but for Mira's and
|
||||
// Lumen's messages, which came while away.
|
||||
for view in app.sessions.values_mut() {
|
||||
for view in app.state.sessions.values_mut() {
|
||||
for tab in &mut view.tabs {
|
||||
tab.divider = None;
|
||||
tab.catch_up();
|
||||
@@ -983,7 +983,7 @@ fn demo_social(app: &mut App) {
|
||||
});
|
||||
|
||||
// The pictures of the links, as if downloaded.
|
||||
if let Some(view) = app.sessions.get_mut(&DEMO) {
|
||||
if let Some(view) = app.state.sessions.get_mut(&DEMO) {
|
||||
for (channel, name) in
|
||||
[(2, "night-castle.png"), (2, "guild-banner.png"), (2, "map-notes.png")]
|
||||
{
|
||||
@@ -995,7 +995,7 @@ fn demo_social(app: &mut App) {
|
||||
};
|
||||
view.extra.previews.insert(
|
||||
crate::previews::link_key(&file),
|
||||
crate::previews::Preview::Ready(voelin_core::Bytes(
|
||||
crate::vm::state::Preview::Ready(voelin_core::Bytes(
|
||||
demo_picture(640, 360, name.len() as u32).into(),
|
||||
)),
|
||||
);
|
||||
@@ -1242,7 +1242,7 @@ fn demo_pictures(app: &mut App) {
|
||||
};
|
||||
let mut events = vec![Event::ServerDetails {
|
||||
session,
|
||||
address: app.bookmarks.iter().find(|b| b.id == DEMO).unwrap().address.clone(),
|
||||
address: app.state.bookmarks.iter().find(|b| b.id == DEMO).unwrap().address.clone(),
|
||||
details: Arc::new(voelin_model::ServerDetails {
|
||||
icon: DEMO_SERVER_ICON,
|
||||
..Default::default()
|
||||
|
||||
@@ -29,7 +29,7 @@ impl App {
|
||||
use GatewayUpdate as U;
|
||||
let mut ask: Vec<GatewayRequest> = Vec::new();
|
||||
let mut remind = None;
|
||||
let extra = &mut self.sessions.entry(id).or_default().extra;
|
||||
let extra = &mut self.state.sessions.entry(id).or_default().extra;
|
||||
match update {
|
||||
U::Connected { uid, capabilities, .. } => {
|
||||
extra.gateway_uid = Some(uid.clone());
|
||||
@@ -121,8 +121,8 @@ impl App {
|
||||
|
||||
/// The events page of the current server was opened.
|
||||
pub(crate) fn open_events(&mut self) {
|
||||
let Some(id) = self.current else { return };
|
||||
let loaded = self.sessions.get(&id).is_some_and(|v| v.extra.events_loaded);
|
||||
let Some(id) = self.state.current else { return };
|
||||
let loaded = self.state.sessions.get(&id).is_some_and(|v| v.extra.events_loaded);
|
||||
if !loaded {
|
||||
self.gateway_to(id, GatewayRequest::Events { query: EventQuery::default() });
|
||||
}
|
||||
@@ -232,16 +232,16 @@ impl App {
|
||||
|
||||
/// Answer an event ("" withdraws the answer).
|
||||
pub(crate) fn rsvp(&mut self, event_id: i32, status: &str) {
|
||||
let Some(id) = self.current else { return };
|
||||
let Some(id) = self.state.current else { return };
|
||||
let status = (!status.is_empty()).then(|| RsvpStatus::parse(status));
|
||||
self.gateway_to(id, GatewayRequest::Rsvp { event_id: i64::from(event_id), status });
|
||||
}
|
||||
|
||||
/// Show or hide who answered (fetching the event with its attendees).
|
||||
pub(crate) fn toggle_event(&mut self, event_id: i32) {
|
||||
let Some(id) = self.current else { return };
|
||||
let Some(id) = self.state.current else { return };
|
||||
let event_id = i64::from(event_id);
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let view = self.state.sessions.entry(id).or_default();
|
||||
if !view.extra.expanded.remove(&event_id) {
|
||||
view.extra.expanded.insert(event_id);
|
||||
self.gateway_to(id, GatewayRequest::GetEvent { id: event_id });
|
||||
@@ -277,7 +277,7 @@ impl App {
|
||||
|
||||
/// Create or change an event; the reason when the form is not right.
|
||||
pub(crate) fn save_event(&mut self, form: &EventForm) -> String {
|
||||
let Some(id) = self.current else { return "No server selected.".into() };
|
||||
let Some(id) = self.state.current else { return "No server selected.".into() };
|
||||
let Some(start_ms) = parse_local(&form.start) else {
|
||||
return "Write the start as YYYY-MM-DD HH:MM.".into();
|
||||
};
|
||||
@@ -315,14 +315,14 @@ impl App {
|
||||
}
|
||||
|
||||
pub(crate) fn delete_event(&mut self, event_id: i32) {
|
||||
if let Some(id) = self.current {
|
||||
if let Some(id) = self.state.current {
|
||||
self.gateway_to(id, GatewayRequest::DeleteEvent { id: i64::from(event_id) });
|
||||
}
|
||||
}
|
||||
|
||||
/// Watch the stream of a live scheduled stream.
|
||||
pub(crate) fn watch_event(&mut self, event_id: i32) {
|
||||
let Some(id) = self.current else { return };
|
||||
let Some(id) = self.state.current else { return };
|
||||
let stream = self
|
||||
.view()
|
||||
.and_then(|v| v.extra.events.iter().find(|e| e.id == i64::from(event_id)))
|
||||
|
||||
@@ -29,8 +29,10 @@ impl App {
|
||||
/// streaming.
|
||||
fn live_rooms(&self) -> Vec<LiveItem> {
|
||||
let mut rooms = Vec::new();
|
||||
for (b, backdrop) in self.bookmarks.iter().zip(vm::servers::tints(&self.bookmarks)) {
|
||||
let Some(view) = self.sessions.get(&b.id) else { continue };
|
||||
for (b, backdrop) in
|
||||
self.state.bookmarks.iter().zip(vm::servers::tints(&self.state.bookmarks))
|
||||
{
|
||||
let Some(view) = self.state.sessions.get(&b.id) else { continue };
|
||||
let channel_of = |cid: Option<u64>| {
|
||||
cid.and_then(|c| view.presence.channels.get(&c))
|
||||
.map(|c| vm::tree::channel_title(c).0.to_owned())
|
||||
@@ -123,8 +125,8 @@ impl App {
|
||||
let now = crate::social::now_ms();
|
||||
let mut events: Vec<(i64, HappeningItem, Happening)> = Vec::new();
|
||||
let mut news = Vec::new();
|
||||
for b in &self.bookmarks {
|
||||
let Some(view) = self.sessions.get(&b.id) else { continue };
|
||||
for b in &self.state.bookmarks {
|
||||
let Some(view) = self.state.sessions.get(&b.id) else { continue };
|
||||
for e in &view.extra.events {
|
||||
let ends = e.spec.end_ms.unwrap_or(e.spec.start_ms + 3 * 3_600_000);
|
||||
if ends < now {
|
||||
@@ -192,7 +194,7 @@ impl App {
|
||||
/// server (and the streamer's channel, watching once there).
|
||||
pub(crate) fn watch_live(&mut self, session: i64, id: &str) {
|
||||
self.show_server(session);
|
||||
let Some(view) = self.sessions.get(&session) else { return };
|
||||
let Some(view) = self.state.sessions.get(&session) else { return };
|
||||
if view.streams_available() && view.streams.iter().any(|s| s.id == id) {
|
||||
self.watch_stream(id.to_owned());
|
||||
return;
|
||||
@@ -232,8 +234,9 @@ impl App {
|
||||
}
|
||||
|
||||
fn last_resume(&self) -> Option<vm::home::Resume> {
|
||||
let voice = |id| self.sessions.get(&id).map_or(VoiceState::Disconnected, |v| v.state.voice);
|
||||
vm::home::resume(self.settings.last_voice.as_ref(), &self.bookmarks, voice)
|
||||
let voice =
|
||||
|id| self.state.sessions.get(&id).map_or(VoiceState::Disconnected, |v| v.state.voice);
|
||||
vm::home::resume(self.state.settings.last_voice.as_ref(), &self.state.bookmarks, voice)
|
||||
}
|
||||
|
||||
/// Home's "Continue where you left off", its server as the rail shows
|
||||
@@ -272,17 +275,17 @@ impl App {
|
||||
if self.demo_ui {
|
||||
return false;
|
||||
}
|
||||
let Some(view) = self.sessions.get(&session) else { return false };
|
||||
let Some(view) = self.state.sessions.get(&session) else { return false };
|
||||
let (VoiceState::Connected, Some(cid)) = (view.state.voice, view.state.own_channel) else {
|
||||
return false;
|
||||
};
|
||||
let channel = vm::tree::channel_path(&view.presence, cid);
|
||||
let Some(b) = self.bookmark(session).filter(|_| !channel.is_empty()) else { return false };
|
||||
let last = LastVoice { bookmark: session, address: b.address.clone(), channel };
|
||||
if self.settings.last_voice.as_ref() == Some(&last) {
|
||||
if self.state.settings.last_voice.as_ref() == Some(&last) {
|
||||
return false;
|
||||
}
|
||||
self.settings.last_voice = Some(last);
|
||||
self.state.settings.last_voice = Some(last);
|
||||
self.store_settings();
|
||||
true
|
||||
}
|
||||
|
||||
@@ -65,8 +65,8 @@ pub(crate) fn take() {
|
||||
|
||||
impl App {
|
||||
fn share(&mut self, nav: &Nav<'_>, text: Option<String>, files: Vec<PathBuf>) {
|
||||
let current = self.current.and_then(|id| {
|
||||
let view = self.sessions.get(&id)?;
|
||||
let current = self.state.current.and_then(|id| {
|
||||
let view = self.state.sessions.get(&id)?;
|
||||
let tab = &view.tabs[view.current_tab];
|
||||
// Files go to the channel of the chat, else to ours.
|
||||
let channel = match tab.target {
|
||||
|
||||
@@ -29,9 +29,14 @@ impl App {
|
||||
}
|
||||
};
|
||||
let in_voice = |id: i64| {
|
||||
self.sessions.get(&id).is_some_and(|v| v.state.voice == VoiceState::Connected)
|
||||
self.state.sessions.get(&id).is_some_and(|v| v.state.voice == VoiceState::Connected)
|
||||
};
|
||||
match vm::servers::link_server(&self.bookmarks, &link.address(), self.current, in_voice) {
|
||||
match vm::servers::link_server(
|
||||
&self.state.bookmarks,
|
||||
&link.address(),
|
||||
self.state.current,
|
||||
in_voice,
|
||||
) {
|
||||
Some((id, true)) => self.move_by_link(id, &link),
|
||||
saved => self.open_link_form(saved.map(|(id, _)| id), &link),
|
||||
}
|
||||
@@ -41,7 +46,7 @@ impl App {
|
||||
fn move_by_link(&mut self, session: i64, link: &ServerLink) {
|
||||
self.show_server(session);
|
||||
let Some(path) = &link.channel else { return };
|
||||
let Some(view) = self.sessions.get_mut(&session) else { return };
|
||||
let Some(view) = self.state.sessions.get_mut(&session) else { return };
|
||||
let Some(channel) = vm::servers::channel_by_path(&view.presence, path) else {
|
||||
let server = self.bookmark(session).map(|b| b.name.clone()).unwrap_or_default();
|
||||
self.set_status(format!("{server} has no channel \u{201c}{path}\u{201d}"));
|
||||
|
||||
@@ -46,9 +46,12 @@ impl App {
|
||||
let id = view.member_card?;
|
||||
let client = view.presence.clients.get(&id)?;
|
||||
let uid = client.uid.clone();
|
||||
let contact = uid.as_ref().and_then(|u| self.contacts.get(u));
|
||||
let playback =
|
||||
uid.as_ref().and_then(|u| self.playback.get(u)).copied().unwrap_or_default();
|
||||
let contact = uid.as_ref().and_then(|u| self.state.contacts.get(u));
|
||||
let playback = uid
|
||||
.as_ref()
|
||||
.and_then(|u| self.state.playback.get(u))
|
||||
.copied()
|
||||
.unwrap_or_default();
|
||||
let groups: Vec<Arc<str>> = client
|
||||
.server_groups
|
||||
.iter()
|
||||
@@ -83,8 +86,8 @@ impl App {
|
||||
|
||||
/// The card's buttons: "message", "poke", "friend", "blocked", "mute".
|
||||
pub(crate) fn member_action(&mut self, action: &str) {
|
||||
let Some(id) = self.current else { return };
|
||||
let Some(view) = self.sessions.get(&id) else { return };
|
||||
let Some(id) = self.state.current else { return };
|
||||
let Some(view) = self.state.sessions.get(&id) else { return };
|
||||
let Some(client) = view.member_card.and_then(|c| view.presence.clients.get(&c)) else {
|
||||
return;
|
||||
};
|
||||
@@ -105,18 +108,22 @@ impl App {
|
||||
"friend" | "blocked" => {
|
||||
let Some(uid) = uid else { return };
|
||||
let wanted = if action == "friend" { Relation::Friend } else { Relation::Blocked };
|
||||
let current = self.contacts.get(&uid).map(|c| c.relation);
|
||||
let mut contact =
|
||||
self.contacts.get(&uid).cloned().unwrap_or_else(|| Contact::new(uid.clone()));
|
||||
let current = self.state.contacts.get(&uid).map(|c| c.relation);
|
||||
let mut contact = self
|
||||
.state
|
||||
.contacts
|
||||
.get(&uid)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| Contact::new(uid.clone()));
|
||||
contact.nickname = nickname;
|
||||
contact.relation = if current == Some(wanted) { Relation::Neutral } else { wanted };
|
||||
self.contacts.insert(uid, contact.clone());
|
||||
self.state.contacts.insert(uid, contact.clone());
|
||||
self.engine.send(Command::SetContact { contact: Box::new(contact) });
|
||||
self.refresh_member_card();
|
||||
}
|
||||
"mute" => {
|
||||
let Some(uid) = uid else { return };
|
||||
let mut playback = self.playback.get(&uid).copied().unwrap_or_default();
|
||||
let mut playback = self.state.playback.get(&uid).copied().unwrap_or_default();
|
||||
playback.muted = !playback.muted;
|
||||
self.set_playback(&uid, client_id, playback);
|
||||
}
|
||||
@@ -126,9 +133,9 @@ impl App {
|
||||
|
||||
/// Open the poke dialog for a client (the member card, a contact).
|
||||
pub(crate) fn ask_poke(&mut self, session: i64, client: u16) {
|
||||
let Some(view) = self.sessions.get(&session) else { return };
|
||||
let Some(view) = self.state.sessions.get(&session) else { return };
|
||||
let name = view.nickname(client);
|
||||
self.poke_target = Some((session, client, name.clone()));
|
||||
self.state.poke_target = Some((session, client, name.clone()));
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let nav = ui.global::<Nav>();
|
||||
nav.set_poke_name(name.into());
|
||||
@@ -137,7 +144,7 @@ impl App {
|
||||
|
||||
/// The poke dialog's Send, with its message (may be empty).
|
||||
pub(crate) fn send_poke(&mut self, text: &str) {
|
||||
let Some((session, client, name)) = self.poke_target.take() else { return };
|
||||
let Some((session, client, name)) = self.state.poke_target.take() else { return };
|
||||
if !self.demo_ui {
|
||||
self.engine.send(Command::Poke {
|
||||
session: session as u64,
|
||||
@@ -155,7 +162,7 @@ impl App {
|
||||
return;
|
||||
};
|
||||
let (client_id, Some(uid)) = (client.id, client.uid.clone()) else { return };
|
||||
let mut playback = self.playback.get(&uid).copied().unwrap_or_default();
|
||||
let mut playback = self.state.playback.get(&uid).copied().unwrap_or_default();
|
||||
playback.volume = (percent / 100.0).clamp(0.0, 4.0);
|
||||
self.set_playback(&uid, client_id, playback);
|
||||
}
|
||||
@@ -163,11 +170,13 @@ impl App {
|
||||
/// Store one client's playback and apply it to the session.
|
||||
fn set_playback(&mut self, uid: &str, client: u16, playback: ClientPlayback) {
|
||||
if playback.is_default() {
|
||||
self.playback.remove(uid);
|
||||
self.state.playback.remove(uid);
|
||||
} else {
|
||||
self.playback.insert(uid.to_owned(), playback);
|
||||
self.state.playback.insert(uid.to_owned(), playback);
|
||||
}
|
||||
if let Err(e) = self.prefs.set(&crate::settings::CLIENT_PLAYBACK, self.playback.clone()) {
|
||||
if let Err(e) =
|
||||
self.prefs.set(&crate::settings::CLIENT_PLAYBACK, self.state.playback.clone())
|
||||
{
|
||||
tracing::warn!(%e, "could not store client volumes");
|
||||
}
|
||||
self.command(|session| Command::SetClientMuted { session, client, muted: playback.muted });
|
||||
|
||||
@@ -70,7 +70,7 @@ impl App {
|
||||
return;
|
||||
}
|
||||
self.social.dm.bookmark_of.clear();
|
||||
for b in &self.bookmarks {
|
||||
for b in &self.state.bookmarks {
|
||||
let gateways = b.gateways().into_iter().chain(b.gateway_url.clone());
|
||||
for alias in std::iter::once(format!("voice:{}", b.address))
|
||||
.chain(gateways.map(|url| format!("gateway:{url}")))
|
||||
@@ -96,7 +96,8 @@ impl App {
|
||||
|
||||
/// The session a server unique id belongs to.
|
||||
fn session_of_server(&self, server_uid: &str) -> Option<i64> {
|
||||
self.sessions
|
||||
self.state
|
||||
.sessions
|
||||
.iter()
|
||||
.find(|(_, v)| v.state.server_uid.as_deref() == Some(server_uid))
|
||||
.map(|(id, _)| *id)
|
||||
@@ -105,18 +106,18 @@ impl App {
|
||||
|
||||
/// What we call the peer of a private chat.
|
||||
pub(crate) fn peer_name(&self, uid: &str, last: Option<&HistoryMessage>) -> String {
|
||||
if let Some(c) = self.contacts.get(uid).filter(|c| !c.nickname.is_empty()) {
|
||||
if let Some(c) = self.state.contacts.get(uid).filter(|c| !c.nickname.is_empty()) {
|
||||
return c.nickname.clone();
|
||||
}
|
||||
if let Some(s) = self.spots_of(uid).first() {
|
||||
return self.sessions[&s.session].nickname(s.client);
|
||||
return self.state.sessions[&s.session].nickname(s.client);
|
||||
}
|
||||
let from_peer = |m: &HistoryMessage| {
|
||||
(m.message.author_uid.as_deref() == Some(uid)).then(|| m.message.author_name.clone())
|
||||
};
|
||||
last.and_then(from_peer)
|
||||
.or_else(|| {
|
||||
self.sessions.values().flat_map(|v| &v.tabs).find_map(|t| {
|
||||
self.state.sessions.values().flat_map(|v| &v.tabs).find_map(|t| {
|
||||
(t.target == ChatTarget::Private(uid.to_owned()))
|
||||
.then(|| t.messages.iter().rev().find_map(|m| from_peer(&m.message)))
|
||||
.flatten()
|
||||
@@ -128,8 +129,8 @@ impl App {
|
||||
/// Every chat, newest first; then the lists that show them.
|
||||
pub(crate) fn refresh_chats(&mut self) {
|
||||
let mut chats: Vec<ChatRef> = Vec::new();
|
||||
for b in &self.bookmarks {
|
||||
let Some(view) = self.sessions.get(&b.id) else { continue };
|
||||
for b in &self.state.bookmarks {
|
||||
let Some(view) = self.state.sessions.get(&b.id) else { continue };
|
||||
for tab in &view.tabs {
|
||||
let last = tab.messages.last().map(|m| m.message.clone());
|
||||
if last.is_none() && !matches!(tab.target, ChatTarget::Private(_)) {
|
||||
@@ -161,9 +162,10 @@ impl App {
|
||||
chats.sort_by_key(|c| std::cmp::Reverse(c.last.as_ref().map_or(0, |m| m.message.ts_ms)));
|
||||
self.social.dm.chats = chats;
|
||||
self.social.dm.inbox = self
|
||||
.state
|
||||
.bookmarks
|
||||
.iter()
|
||||
.filter_map(|b| self.sessions.get(&b.id).map(|v| (b.id, v)))
|
||||
.filter_map(|b| self.state.sessions.get(&b.id).map(|v| (b.id, v)))
|
||||
.flat_map(|(id, v)| v.extra.inbox.iter().map(move |m| (id, m.clone())))
|
||||
.collect();
|
||||
self.social.dm.inbox.sort_by_key(|(_, m)| std::cmp::Reverse(m.ts_s));
|
||||
@@ -185,7 +187,7 @@ impl App {
|
||||
),
|
||||
ChatTarget::Channel(cid) => {
|
||||
let name = session
|
||||
.and_then(|s| self.sessions.get(&s))
|
||||
.and_then(|s| self.state.sessions.get(&s))
|
||||
.and_then(|v| v.presence.channels.get(cid))
|
||||
.map_or_else(
|
||||
|| format!("Channel {cid}"),
|
||||
@@ -304,9 +306,10 @@ impl App {
|
||||
/// Unread messages in the private chats of every server (the rail and
|
||||
/// the chat strip leave them out).
|
||||
pub(crate) fn dm_unread(&self) -> i32 {
|
||||
self.bookmarks
|
||||
self.state
|
||||
.bookmarks
|
||||
.iter()
|
||||
.filter_map(|b| self.sessions.get(&b.id))
|
||||
.filter_map(|b| self.state.sessions.get(&b.id))
|
||||
.map(SessionView::private_unread)
|
||||
.sum()
|
||||
}
|
||||
@@ -321,9 +324,9 @@ impl App {
|
||||
};
|
||||
let target = ChatTarget::Private(uid);
|
||||
// Not for a session that is gone (its server was deleted).
|
||||
let Some(view) = self.sessions.get(&id) else { return };
|
||||
let Some(view) = self.state.sessions.get(&id) else { return };
|
||||
if !view.tabs.iter().any(|t| t.target == target)
|
||||
|| (self.current == Some(id)
|
||||
|| (self.state.current == Some(id)
|
||||
&& view.tabs.get(view.current_tab).is_some_and(|t| t.target == target))
|
||||
{
|
||||
return;
|
||||
@@ -336,8 +339,8 @@ impl App {
|
||||
/// the chat it shows, which must not be the strip's.
|
||||
fn focus_private(&mut self, id: i64, target: ChatTarget) {
|
||||
let index = self.chat_tab(id, target.clone());
|
||||
self.sessions.entry(id).or_default().set_current_tab(index);
|
||||
if self.current != Some(id) {
|
||||
self.state.sessions.entry(id).or_default().set_current_tab(index);
|
||||
if self.state.current != Some(id) {
|
||||
self.select_server(id);
|
||||
}
|
||||
self.open_chat(target, true);
|
||||
@@ -348,7 +351,7 @@ impl App {
|
||||
/// ([`SessionView::channel_tab`]).
|
||||
pub(crate) fn close_messages(&mut self) {
|
||||
let mut changed = false;
|
||||
for view in self.sessions.values_mut() {
|
||||
for view in self.state.sessions.values_mut() {
|
||||
changed |= view.leave_private();
|
||||
}
|
||||
if !changed {
|
||||
@@ -360,7 +363,7 @@ impl App {
|
||||
// (`Nav.select-server` leaves the page first) is selected by then,
|
||||
// and the chat that came back here was never on screen.
|
||||
later(|app| {
|
||||
if let Some(id) = app.current {
|
||||
if let Some(id) = app.state.current {
|
||||
app.fetch_previews(id);
|
||||
}
|
||||
app.prefetch_counts();
|
||||
@@ -371,7 +374,7 @@ impl App {
|
||||
pub(crate) fn dm_tab(&mut self, tab: i32) {
|
||||
self.social.dm.tab = tab;
|
||||
if tab == 2 {
|
||||
for view in self.sessions.values_mut() {
|
||||
for view in self.state.sessions.values_mut() {
|
||||
view.extra.inbox_asked = false;
|
||||
}
|
||||
self.ask_inboxes();
|
||||
@@ -432,7 +435,7 @@ impl App {
|
||||
.find(|c| c.target == target && (session.is_none() || c.session == session));
|
||||
let session = session.or_else(|| known.and_then(|c| c.session));
|
||||
let server_uid = session
|
||||
.and_then(|s| self.sessions.get(&s))
|
||||
.and_then(|s| self.state.sessions.get(&s))
|
||||
.and_then(|v| v.state.server_uid.clone())
|
||||
.or_else(|| known.and_then(|c| c.server_uid.clone()));
|
||||
self.open_dm(session, server_uid, uid);
|
||||
@@ -442,7 +445,7 @@ impl App {
|
||||
/// the store.
|
||||
pub(crate) fn open_dm(&mut self, session: Option<i64>, server_uid: Option<String>, uid: &str) {
|
||||
let live = session
|
||||
.and_then(|s| self.sessions.get(&s))
|
||||
.and_then(|s| self.state.sessions.get(&s))
|
||||
.is_some_and(|v| v.has_history() || v.state.voice == VoiceState::Connected);
|
||||
self.social.dm.open = Some(Open {
|
||||
session,
|
||||
@@ -519,11 +522,12 @@ impl App {
|
||||
return;
|
||||
};
|
||||
let uid = open.uid.as_str();
|
||||
let contact = self.contacts.get(uid);
|
||||
let contact = self.state.contacts.get(uid);
|
||||
let spots = self.spots_of(uid);
|
||||
let here = open.session.and_then(|s| spots.iter().find(|sp| sp.session == s));
|
||||
let view = open.session.and_then(|s| self.sessions.get(&s));
|
||||
let client = here.and_then(|s| self.sessions[&s.session].presence.clients.get(&s.client));
|
||||
let view = open.session.and_then(|s| self.state.sessions.get(&s));
|
||||
let client =
|
||||
here.and_then(|s| self.state.sessions[&s.session].presence.clients.get(&s.client));
|
||||
let tab =
|
||||
view.and_then(|v| v.tabs.iter().find(|t| t.target == ChatTarget::Private(uid.into())));
|
||||
let name = self.peer_name(uid, tab.and_then(|t| t.messages.last().map(|m| &m.message)));
|
||||
@@ -690,7 +694,7 @@ impl App {
|
||||
match action {
|
||||
"poke" | "join" | "mute" => self.contact_action(&uid, action),
|
||||
"friend" | "block" => {
|
||||
let current = self.contacts.get(&uid).map(|c| c.relation);
|
||||
let current = self.state.contacts.get(&uid).map(|c| c.relation);
|
||||
let wanted = if action == "friend" {
|
||||
voelin_core::Relation::Friend
|
||||
} else {
|
||||
@@ -748,9 +752,14 @@ impl App {
|
||||
/// Send an offline message through the open conversation's server.
|
||||
pub(crate) fn send_offline(&mut self, form: OfflineForm) {
|
||||
let session =
|
||||
self.social.dm.open.as_ref().and_then(|o| o.session).or(self.current).filter(|s| {
|
||||
self.sessions.get(s).is_some_and(|v| v.state.voice == VoiceState::Connected)
|
||||
});
|
||||
self.social.dm.open.as_ref().and_then(|o| o.session).or(self.state.current).filter(
|
||||
|s| {
|
||||
self.state
|
||||
.sessions
|
||||
.get(s)
|
||||
.is_some_and(|v| v.state.voice == VoiceState::Connected)
|
||||
},
|
||||
);
|
||||
let Some(session) = session else {
|
||||
self.set_status("Connect with voice to send an offline message.");
|
||||
return;
|
||||
@@ -796,7 +805,7 @@ impl App {
|
||||
pub(crate) fn mail_arrived(&mut self, session: i64, result: Result<OfflineMessage, String>) {
|
||||
match result {
|
||||
Ok(m) => {
|
||||
if let Some(view) = self.sessions.get_mut(&session)
|
||||
if let Some(view) = self.state.sessions.get_mut(&session)
|
||||
&& let Some(info) = view.extra.inbox.iter_mut().find(|i| i.id == m.id)
|
||||
{
|
||||
info.read = true;
|
||||
@@ -814,7 +823,7 @@ impl App {
|
||||
("send", Err(e)) => self.set_status(format!("Could not send the offline message: {e}")),
|
||||
(_, Err(e)) => self.set_status(format!("Offline messages: {e}")),
|
||||
(_, Ok(())) => {
|
||||
if let Some(view) = self.sessions.get_mut(&session) {
|
||||
if let Some(view) = self.state.sessions.get_mut(&session) {
|
||||
view.extra.inbox_asked = false;
|
||||
}
|
||||
self.ask_inboxes();
|
||||
@@ -828,6 +837,7 @@ impl App {
|
||||
return;
|
||||
}
|
||||
let ids: Vec<i64> = self
|
||||
.state
|
||||
.sessions
|
||||
.iter()
|
||||
.filter(|(_, v)| {
|
||||
@@ -839,7 +849,7 @@ impl App {
|
||||
.collect();
|
||||
for id in ids {
|
||||
let request = self.offline_request(id, "list");
|
||||
if let Some(view) = self.sessions.get_mut(&id) {
|
||||
if let Some(view) = self.state.sessions.get_mut(&id) {
|
||||
view.extra.inbox_asked = true;
|
||||
}
|
||||
self.engine.send(Command::ListOfflineMessages { session: id as u64, request });
|
||||
|
||||
@@ -94,10 +94,13 @@ impl App {
|
||||
}
|
||||
// The main window may have gone to another server meanwhile: else
|
||||
// the stream would play on, unseen.
|
||||
let session =
|
||||
self.watch.as_ref().and_then(|w| w.session).filter(|id| self.sessions.contains_key(id));
|
||||
let session = self
|
||||
.watch
|
||||
.as_ref()
|
||||
.and_then(|w| w.session)
|
||||
.filter(|id| self.state.sessions.contains_key(id));
|
||||
if let Some(id) = session
|
||||
&& self.current != Some(id)
|
||||
&& self.state.current != Some(id)
|
||||
{
|
||||
self.select_server(id);
|
||||
}
|
||||
|
||||
@@ -12,25 +12,16 @@ use std::borrow::Cow;
|
||||
use std::sync::Arc;
|
||||
|
||||
use voelin_core::settings::CACHE_FETCH_IMAGES;
|
||||
use voelin_core::{Bytes, Command, DownloadTo, TransferState, VoiceState};
|
||||
use voelin_core::{Command, DownloadTo, TransferState, VoiceState};
|
||||
use voelin_model::{ChatTarget, FileRef};
|
||||
|
||||
use crate::app::{App, SessionView};
|
||||
use crate::bind::convert;
|
||||
use crate::settings::UI_IMAGE_PREVIEW_KB;
|
||||
use crate::vm;
|
||||
use crate::vm::state::Preview;
|
||||
use crate::vm::{ImageRef, ImageSource};
|
||||
|
||||
/// A linked picture.
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) enum Preview {
|
||||
/// Downloading (transfer id).
|
||||
Loading(u64),
|
||||
Ready(Bytes),
|
||||
/// Too large, not a picture, or the download failed.
|
||||
Failed,
|
||||
}
|
||||
|
||||
/// Whether a file name is a picture the chat shows inline.
|
||||
pub(crate) fn is_previewable(name: &str) -> bool {
|
||||
let lower = name.to_ascii_lowercase();
|
||||
@@ -73,7 +64,7 @@ impl App {
|
||||
return;
|
||||
}
|
||||
self.fetch_web_pictures(session, limit);
|
||||
let Some(view) = self.sessions.get_mut(&session) else { return };
|
||||
let Some(view) = self.state.sessions.get_mut(&session) else { return };
|
||||
if view.state.voice != VoiceState::Connected || !view.capabilities.file_transfer {
|
||||
return;
|
||||
}
|
||||
@@ -111,7 +102,7 @@ impl App {
|
||||
if !self.prefs.get(&CACHE_FETCH_IMAGES) {
|
||||
return;
|
||||
}
|
||||
let Some(view) = self.sessions.get(&session) else { return };
|
||||
let Some(view) = self.state.sessions.get(&session) else { return };
|
||||
let Some(tab) = view.tabs.get(view.current_tab) else { return };
|
||||
// The server chat starts with the server's messages.
|
||||
let server = match tab.target {
|
||||
@@ -145,7 +136,7 @@ impl App {
|
||||
state: &TransferState,
|
||||
) -> bool {
|
||||
let limit = u64::from(self.prefs.get(&UI_IMAGE_PREVIEW_KB)) * 1024;
|
||||
let Some(view) = self.sessions.get_mut(&session) else { return false };
|
||||
let Some(view) = self.state.sessions.get_mut(&session) else { return false };
|
||||
let Some(key) = view
|
||||
.extra
|
||||
.previews
|
||||
@@ -164,7 +155,7 @@ impl App {
|
||||
}
|
||||
TransferState::Done { data: Some(data), .. } => {
|
||||
view.extra.previews.insert(key, Preview::Ready(data.clone()));
|
||||
if self.current == Some(session) {
|
||||
if self.state.current == Some(session) {
|
||||
self.refresh_chat();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,8 +104,11 @@ fn observing_stays(
|
||||
|
||||
impl App {
|
||||
pub(crate) fn connect_voice(&mut self) {
|
||||
let channel =
|
||||
self.current.and_then(|id| self.bookmark(id)).and_then(|b| b.default_channel.clone());
|
||||
let channel = self
|
||||
.state
|
||||
.current
|
||||
.and_then(|id| self.bookmark(id))
|
||||
.and_then(|b| b.default_channel.clone());
|
||||
self.connect_voice_to(channel, None, None);
|
||||
}
|
||||
|
||||
@@ -118,7 +121,9 @@ impl App {
|
||||
channel_password: Option<String>,
|
||||
token: Option<String>,
|
||||
) -> bool {
|
||||
let Some(b) = self.current.and_then(|id| self.bookmark(id)).cloned() else { return false };
|
||||
let Some(b) = self.state.current.and_then(|id| self.bookmark(id)).cloned() else {
|
||||
return false;
|
||||
};
|
||||
if self.demo_ui {
|
||||
return false;
|
||||
}
|
||||
@@ -171,7 +176,7 @@ impl App {
|
||||
/// (a gateway that moved, or one typed into an older version, which
|
||||
/// showed the field). Nothing found keeps what is stored.
|
||||
pub(crate) fn discover_gateway(&mut self, id: i64) {
|
||||
if self.demo_ui || !self.gateways_looked_up.insert(id) {
|
||||
if self.demo_ui || !self.state.gateways_looked_up.insert(id) {
|
||||
return;
|
||||
}
|
||||
let Some(b) = self.bookmark(id) else { return };
|
||||
@@ -193,7 +198,8 @@ impl App {
|
||||
/// observed through them if it is the one shown. Users never hear of
|
||||
/// them (logged only).
|
||||
fn gateway_found(&mut self, id: i64, address: &str, urls: Vec<String>, elapsed_ms: u64) {
|
||||
let Some(b) = self.bookmarks.iter_mut().find(|b| b.id == id && b.address == address) else {
|
||||
let Some(b) = self.state.bookmarks.iter_mut().find(|b| b.id == id && b.address == address)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let previous = b.gateways();
|
||||
@@ -206,12 +212,12 @@ impl App {
|
||||
warn!(%e, "could not keep the gateway found");
|
||||
return;
|
||||
}
|
||||
let observe = self.sessions.get(&id).map(|v| v.state.observe).unwrap_or_default();
|
||||
let observe = self.state.sessions.get(&id).map(|v| v.state.observe).unwrap_or_default();
|
||||
let kept = observing_stays(&previous, &b.gateways(), in_use.as_deref(), observe);
|
||||
info!(server = %b.address, urls = ?b.gateway_urls, ?previous, kept, elapsed_ms, "gateway found");
|
||||
self.refresh_toolbar();
|
||||
if kept {
|
||||
if self.current == Some(id) && observe == ObserveState::Off {
|
||||
if self.state.current == Some(id) && observe == ObserveState::Off {
|
||||
self.observe(id);
|
||||
}
|
||||
return;
|
||||
@@ -219,18 +225,18 @@ impl App {
|
||||
// Observed through the old ones: through these now.
|
||||
if !previous.is_empty() {
|
||||
self.engine.send(Command::StopObserving { session: id as u64 });
|
||||
if let Some(view) = self.sessions.get_mut(&id) {
|
||||
if let Some(view) = self.state.sessions.get_mut(&id) {
|
||||
view.state.observe = ObserveState::Off;
|
||||
}
|
||||
}
|
||||
if self.current == Some(id) {
|
||||
if self.state.current == Some(id) {
|
||||
self.observe(id);
|
||||
}
|
||||
}
|
||||
|
||||
/// The gateway logged in at `url`: it is the one in use from now on.
|
||||
pub(crate) fn gateway_in_use(&mut self, id: i64, url: &str) {
|
||||
let Some(b) = self.bookmarks.iter_mut().find(|b| b.id == id) else { return };
|
||||
let Some(b) = self.state.bookmarks.iter_mut().find(|b| b.id == id) else { return };
|
||||
if !b.gateway_in_use(url) {
|
||||
return;
|
||||
}
|
||||
@@ -244,7 +250,8 @@ impl App {
|
||||
/// The server told its name: a server still named by its address takes
|
||||
/// it, so the address is all a user has to type.
|
||||
pub(crate) fn adopt_server_name(&mut self, id: i64, name: &str) {
|
||||
let Some(b) = self.bookmarks.iter_mut().find(|b| b.id == id && b.name == b.address) else {
|
||||
let Some(b) = self.state.bookmarks.iter_mut().find(|b| b.id == id && b.name == b.address)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
if name.trim().is_empty() || self.demo_ui {
|
||||
@@ -269,7 +276,7 @@ impl App {
|
||||
return;
|
||||
}
|
||||
let session = b.id as u64;
|
||||
let state = self.sessions.get(&b.id).map(|v| v.state.observe).unwrap_or_default();
|
||||
let state = self.state.sessions.get(&b.id).map(|v| v.state.observe).unwrap_or_default();
|
||||
let urls = b.gateways();
|
||||
match state {
|
||||
ObserveState::Observing => return,
|
||||
@@ -323,7 +330,7 @@ impl App {
|
||||
|
||||
/// Show a server, and observe it.
|
||||
pub(crate) fn select_server(&mut self, id: i64) {
|
||||
self.current = Some(id);
|
||||
self.state.current = Some(id);
|
||||
self.prefetch_counts();
|
||||
self.track_reading();
|
||||
self.refresh_all();
|
||||
@@ -339,7 +346,7 @@ impl App {
|
||||
};
|
||||
};
|
||||
let password = self.secrets.get(&b.server_password_key()).ok().flatten();
|
||||
let state = self.sessions.get(&b.id).map(|view| &view.state);
|
||||
let state = self.state.sessions.get(&b.id).map(|view| &view.state);
|
||||
vm::servers::form(b, state, password.as_deref().unwrap_or_default())
|
||||
}
|
||||
|
||||
@@ -372,13 +379,13 @@ impl App {
|
||||
if old.query.is_some() {
|
||||
let _ = self.secrets.delete(&old.query_password_key());
|
||||
}
|
||||
self.gateways_looked_up.remove(&bookmark.id);
|
||||
self.state.gateways_looked_up.remove(&bookmark.id);
|
||||
self.engine.send(Command::StopObserving { session: bookmark.id as u64 });
|
||||
if let Some(view) = self.sessions.get_mut(&bookmark.id) {
|
||||
if let Some(view) = self.state.sessions.get_mut(&bookmark.id) {
|
||||
view.state.observe = ObserveState::Off;
|
||||
}
|
||||
}
|
||||
self.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||
self.state.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||
self.select_server(bookmark.id);
|
||||
Some(bookmark.id)
|
||||
}
|
||||
@@ -405,10 +412,10 @@ impl App {
|
||||
}
|
||||
let _ = self.store.delete_bookmark(id);
|
||||
self.save_reads(id);
|
||||
self.sessions.remove(&id);
|
||||
self.gateways_looked_up.remove(&id);
|
||||
self.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||
self.current = self.bookmarks.first().map(|b| b.id);
|
||||
self.state.sessions.remove(&id);
|
||||
self.state.gateways_looked_up.remove(&id);
|
||||
self.state.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||
self.state.current = self.state.bookmarks.first().map(|b| b.id);
|
||||
self.prefetch_counts();
|
||||
self.track_reading();
|
||||
self.refresh_all();
|
||||
@@ -416,11 +423,11 @@ impl App {
|
||||
|
||||
/// Keep only metadata supplied by the bookmark's current server.
|
||||
pub(crate) fn remember_server_icon(&mut self, id: i64, address: &str, icon: u32) {
|
||||
let Some(bookmark) = self.bookmarks.iter_mut().find(|b| b.id == id) else {
|
||||
let Some(bookmark) = self.state.bookmarks.iter_mut().find(|b| b.id == id) else {
|
||||
return;
|
||||
};
|
||||
let changed =
|
||||
apply_server_icon(bookmark, self.sessions.entry(id).or_default(), address, icon);
|
||||
apply_server_icon(bookmark, self.state.sessions.entry(id).or_default(), address, icon);
|
||||
if changed
|
||||
&& !self.demo_ui
|
||||
&& let Err(error) = self.store.update_bookmark(bookmark)
|
||||
@@ -431,6 +438,7 @@ impl App {
|
||||
|
||||
pub(crate) fn server_list_icon(&self, bookmark: &Bookmark) -> vm::ImageRef {
|
||||
let current = self
|
||||
.state
|
||||
.sessions
|
||||
.get(&bookmark.id)
|
||||
.map(|view| view.server_icon_for(&bookmark.address))
|
||||
@@ -444,8 +452,8 @@ impl App {
|
||||
|
||||
/// A server's colour, as the rail shows it ([`vm::servers::tints`]).
|
||||
pub(crate) fn server_tint(&self, id: i64) -> vm::Rgb {
|
||||
let tints = vm::servers::tints(&self.bookmarks);
|
||||
self.bookmarks.iter().position(|b| b.id == id).map(|i| tints[i]).unwrap_or_default()
|
||||
let tints = vm::servers::tints(&self.state.bookmarks);
|
||||
self.state.bookmarks.iter().position(|b| b.id == id).map(|i| tints[i]).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// The rail: servers with their state, unread count (without private
|
||||
@@ -454,13 +462,14 @@ impl App {
|
||||
pub(crate) fn refresh_servers(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let tints = vm::servers::tints(&self.bookmarks);
|
||||
let tints = vm::servers::tints(&self.state.bookmarks);
|
||||
let items: Vec<_> = self
|
||||
.state
|
||||
.bookmarks
|
||||
.iter()
|
||||
.zip(tints)
|
||||
.map(|(b, tint)| {
|
||||
let view = self.sessions.get(&b.id);
|
||||
let view = self.state.sessions.get(&b.id);
|
||||
let state = view.map(|v| v.state.clone()).unwrap_or_default();
|
||||
let unread = view.map_or(0, SessionView::channel_unread);
|
||||
let live = view.is_some_and(|v| v.streams_available() && !v.streams.is_empty());
|
||||
@@ -475,7 +484,7 @@ impl App {
|
||||
.collect();
|
||||
self.models.servers.sync(&items);
|
||||
bridge.set_last_place(self.last_place(&items).into());
|
||||
bridge.set_current_server(self.current.map_or(-1, |id| id as i32));
|
||||
bridge.set_current_server(self.state.current.map_or(-1, |id| id as i32));
|
||||
// Private chats count on the messages page (and the phone's Home).
|
||||
bridge.set_unread_total(self.view().map_or(0, SessionView::channel_unread));
|
||||
bridge.set_dm_unread(self.dm_unread());
|
||||
@@ -485,7 +494,7 @@ impl App {
|
||||
pub(crate) fn refresh_toolbar(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let bookmark = self.current.and_then(|id| self.bookmark(id));
|
||||
let bookmark = self.state.current.and_then(|id| self.bookmark(id));
|
||||
let view = self.view();
|
||||
let state = view.map(|v| v.state.clone()).unwrap_or_default();
|
||||
bridge.set_server_icon(convert::image(
|
||||
@@ -563,7 +572,7 @@ impl App {
|
||||
presence: &view.presence,
|
||||
collapsed: &view.collapsed,
|
||||
talking: &view.talking,
|
||||
playback: &self.playback,
|
||||
playback: &self.state.playback,
|
||||
own_channel: view.state.own_channel,
|
||||
own_client: view.state.own_client,
|
||||
filter: "",
|
||||
@@ -580,9 +589,9 @@ impl App {
|
||||
// The people in our channel first while their view is shown (not
|
||||
// while the stream plays in a window of its own).
|
||||
let watching = self.watch.as_ref().is_some_and(|w| w.shown) && self.popout.window.is_none();
|
||||
let voice_first = connected && (self.voice_view || watching);
|
||||
let voice_first = connected && (self.state.voice_view || watching);
|
||||
let everyone = vm::tree::server_members(&input, voice_first);
|
||||
let filter = self.member_filter.trim().to_lowercase();
|
||||
let filter = self.state.member_filter.trim().to_lowercase();
|
||||
let shown =
|
||||
if filter.is_empty() { everyone } else { vm::tree::matching(everyone, &filter) };
|
||||
self.models.server_members.sync(&shown);
|
||||
@@ -594,8 +603,8 @@ impl App {
|
||||
|
||||
/// The members panel's search.
|
||||
pub(crate) fn search_members(&mut self, text: String) {
|
||||
if self.member_filter != text {
|
||||
self.member_filter = text;
|
||||
if self.state.member_filter != text {
|
||||
self.state.member_filter = text;
|
||||
self.refresh_tree();
|
||||
}
|
||||
}
|
||||
@@ -603,7 +612,7 @@ impl App {
|
||||
/// The voice channel view was opened or closed: its chat is our
|
||||
/// channel's, and its people lead the members panel.
|
||||
pub(crate) fn show_voice_view(&mut self, on: bool) {
|
||||
self.voice_view = on;
|
||||
self.state.voice_view = on;
|
||||
if on && let Some(channel) = self.view().and_then(|v| v.state.own_channel) {
|
||||
self.open_chat(voelin_model::ChatTarget::Channel(channel), true);
|
||||
}
|
||||
@@ -614,7 +623,8 @@ impl App {
|
||||
/// copies it, and the copy's toast names the channel); empty, with a
|
||||
/// note, without one.
|
||||
pub(crate) fn invite_link(&mut self) -> String {
|
||||
let bookmark = self.current.and_then(|id| self.bookmark(id)).map(|b| b.address.clone());
|
||||
let bookmark =
|
||||
self.state.current.and_then(|id| self.bookmark(id)).map(|b| b.address.clone());
|
||||
let path = self.view().and_then(|v| {
|
||||
let cid = v.state.own_channel?;
|
||||
let own = v.presence.channels.get(&cid)?;
|
||||
@@ -631,7 +641,7 @@ impl App {
|
||||
};
|
||||
let path: Vec<&str> = path.iter().map(String::as_str).collect();
|
||||
let link = vm::servers::invite_link(&address, &path);
|
||||
self.copy_note = Some(format!("Copied an invite to {title}: {link}"));
|
||||
self.state.copy_note = Some(format!("Copied an invite to {title}: {link}"));
|
||||
link
|
||||
}
|
||||
|
||||
@@ -639,7 +649,7 @@ impl App {
|
||||
/// friend): move there with voice, or connect into it. A locked channel
|
||||
/// asks for its password first, unless it was given this connection.
|
||||
pub(crate) fn join_channel(&mut self, session: i64, channel: ChannelId) {
|
||||
let Some(view) = self.sessions.get(&session) else { return };
|
||||
let Some(view) = self.state.sessions.get(&session) else { return };
|
||||
let Some(info) = view.presence.channels.get(&channel) else { return };
|
||||
let remembered = view.channel_passwords.get(&channel).map(String::as_str);
|
||||
match vm::servers::join_password(info, remembered) {
|
||||
@@ -650,11 +660,11 @@ impl App {
|
||||
|
||||
/// The password dialog's Join.
|
||||
pub(crate) fn join_with_password(&mut self, password: String) {
|
||||
let Some((session, channel)) = self.join_target.take() else { return };
|
||||
let Some((session, channel)) = self.state.join_target.take() else { return };
|
||||
if password.is_empty() {
|
||||
return;
|
||||
}
|
||||
if let Some(view) = self.sessions.get_mut(&session) {
|
||||
if let Some(view) = self.state.sessions.get_mut(&session) {
|
||||
view.channel_passwords.insert(channel, password.clone());
|
||||
}
|
||||
self.enter_channel(session, channel, Some(password));
|
||||
@@ -662,7 +672,7 @@ impl App {
|
||||
|
||||
/// Move into a channel; without voice on its server, connect into it.
|
||||
fn enter_channel(&mut self, session: i64, channel: ChannelId, password: Option<String>) {
|
||||
let Some(view) = self.sessions.get_mut(&session) else { return };
|
||||
let Some(view) = self.state.sessions.get_mut(&session) else { return };
|
||||
if view.state.voice != VoiceState::Disconnected {
|
||||
// Chosen while connecting: no longer the one to join after.
|
||||
view.join_after_connect = None;
|
||||
@@ -675,13 +685,13 @@ impl App {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if self.current != Some(session) {
|
||||
if self.state.current != Some(session) {
|
||||
self.select_server(session);
|
||||
}
|
||||
// By id: by its name the server finds only a top-level channel (a
|
||||
// subchannel's name connects into the default channel).
|
||||
if self.connect_voice_to(Some(format!("/{channel}")), password, None)
|
||||
&& let Some(view) = self.sessions.get_mut(&session)
|
||||
&& let Some(view) = self.state.sessions.get_mut(&session)
|
||||
{
|
||||
view.join_after_connect = Some(channel);
|
||||
}
|
||||
@@ -693,7 +703,7 @@ impl App {
|
||||
/// move says why. Once the channel shows in the voice
|
||||
/// connection's presence, which can come after the own channel.
|
||||
pub(crate) fn join_after_connect(&mut self, session: i64) {
|
||||
let Some(view) = self.sessions.get_mut(&session) else { return };
|
||||
let Some(view) = self.state.sessions.get_mut(&session) else { return };
|
||||
let (VoiceState::Connected, Some(asked)) = (view.state.voice, view.join_after_connect)
|
||||
else {
|
||||
return;
|
||||
@@ -713,12 +723,12 @@ impl App {
|
||||
/// given was refused.
|
||||
fn ask_channel_password(&mut self, session: i64, channel: ChannelId, wrong: bool) {
|
||||
let Some(info) =
|
||||
self.sessions.get(&session).and_then(|v| v.presence.channels.get(&channel))
|
||||
self.state.sessions.get(&session).and_then(|v| v.presence.channels.get(&channel))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let name = vm::tree::channel_title(info).0.to_owned();
|
||||
self.join_target = Some((session, channel));
|
||||
self.state.join_target = Some((session, channel));
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let nav = ui.global::<Nav>();
|
||||
nav.set_channel_password_name(name.into());
|
||||
@@ -733,6 +743,7 @@ impl App {
|
||||
match reason {
|
||||
JoinFailure::Password => {
|
||||
let given = self
|
||||
.state
|
||||
.sessions
|
||||
.get_mut(&session)
|
||||
.and_then(|v| v.channel_passwords.remove(&channel))
|
||||
|
||||
@@ -29,17 +29,20 @@ impl App {
|
||||
};
|
||||
let inputs = list(voelin_audio::device::input_devices(), true);
|
||||
let outputs = list(voelin_audio::device::output_devices(), false);
|
||||
self.inputs = DeviceChoices::new(&inputs, self.audio.input_device.as_deref());
|
||||
self.outputs = DeviceChoices::new(&outputs, self.audio.output_device.as_deref());
|
||||
self.state.inputs = DeviceChoices::new(&inputs, self.state.audio.input_device.as_deref());
|
||||
self.state.outputs =
|
||||
DeviceChoices::new(&outputs, self.state.audio.output_device.as_deref());
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let names = |c: &DeviceChoices| model(c.names.iter().map(SharedString::from).collect());
|
||||
bridge.set_input_devices(names(&self.inputs));
|
||||
bridge.set_output_devices(names(&self.outputs));
|
||||
bridge.set_audio(settings::audio_form(&self.audio, &self.inputs, &self.outputs).into());
|
||||
bridge.set_global_ptt(self.settings.global_ptt);
|
||||
bridge.set_ptt_key(self.settings.ptt_key.clone().into());
|
||||
bridge.set_h264_enabled(self.settings.openh264);
|
||||
bridge.set_input_devices(names(&self.state.inputs));
|
||||
bridge.set_output_devices(names(&self.state.outputs));
|
||||
bridge.set_audio(
|
||||
settings::audio_form(&self.state.audio, &self.state.inputs, &self.state.outputs).into(),
|
||||
);
|
||||
bridge.set_global_ptt(self.state.settings.global_ptt);
|
||||
bridge.set_ptt_key(self.state.settings.ptt_key.clone().into());
|
||||
bridge.set_h264_enabled(self.state.settings.openh264);
|
||||
bridge.set_image_cache_usage(crate::images::usage_text().into());
|
||||
self.refresh_h264();
|
||||
self.refresh_identities();
|
||||
@@ -51,30 +54,35 @@ impl App {
|
||||
}
|
||||
|
||||
pub(crate) fn audio_changed(&mut self, form: &AudioForm) {
|
||||
let audio = settings::apply_audio_form(form, &self.audio, &self.inputs, &self.outputs);
|
||||
if audio == self.audio {
|
||||
let audio = settings::apply_audio_form(
|
||||
form,
|
||||
&self.state.audio,
|
||||
&self.state.inputs,
|
||||
&self.state.outputs,
|
||||
);
|
||||
if audio == self.state.audio {
|
||||
return;
|
||||
}
|
||||
self.audio = audio;
|
||||
self.audio_dirty = true;
|
||||
self.engine.send(Command::SetAudioSettings(Box::new(self.audio.clone())));
|
||||
self.state.audio = audio;
|
||||
self.state.audio_dirty = true;
|
||||
self.engine.send(Command::SetAudioSettings(Box::new(self.state.audio.clone())));
|
||||
}
|
||||
|
||||
pub(crate) fn save_audio(&mut self) {
|
||||
if !self.audio_dirty {
|
||||
if !self.state.audio_dirty {
|
||||
return;
|
||||
}
|
||||
self.audio_dirty = false;
|
||||
if let Err(e) = self.prefs.set(&AUDIO, self.audio.clone()) {
|
||||
self.state.audio_dirty = false;
|
||||
if let Err(e) = self.prefs.set(&AUDIO, self.state.audio.clone()) {
|
||||
warn!(%e, "could not store audio settings");
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn set_mic_test(&mut self, on: bool) {
|
||||
if self.mic_test == on {
|
||||
if self.state.mic_test == on {
|
||||
return;
|
||||
}
|
||||
self.mic_test = on;
|
||||
self.state.mic_test = on;
|
||||
self.engine.send(Command::TestMicrophone { on });
|
||||
if let Some(ui) = self.ui.upgrade() {
|
||||
let bridge = ui.global::<Bridge>();
|
||||
@@ -87,9 +95,9 @@ impl App {
|
||||
|
||||
pub(crate) fn apply_ptt(&mut self, enabled: bool, key: String) {
|
||||
let key = key.trim().to_owned();
|
||||
self.settings.global_ptt = enabled;
|
||||
self.state.settings.global_ptt = enabled;
|
||||
if !key.is_empty() {
|
||||
self.settings.ptt_key = key.clone();
|
||||
self.state.settings.ptt_key = key.clone();
|
||||
}
|
||||
self.store_settings();
|
||||
self.ptt.set((enabled && !key.is_empty()).then_some(key));
|
||||
@@ -102,7 +110,7 @@ impl App {
|
||||
}
|
||||
|
||||
pub(crate) fn set_h264(&mut self, enabled: bool) {
|
||||
self.settings.openh264 = enabled;
|
||||
self.state.settings.openh264 = enabled;
|
||||
self.store_settings();
|
||||
self.video.set_h264(enabled);
|
||||
self.refresh_h264();
|
||||
@@ -112,7 +120,7 @@ impl App {
|
||||
let runtime = self.engine.runtime().clone();
|
||||
self.video.download_h264(&runtime, |download| {
|
||||
later(move |app| {
|
||||
app.video.downloaded(download, app.settings.openh264);
|
||||
app.video.downloaded(download, app.state.settings.openh264);
|
||||
app.refresh_h264();
|
||||
});
|
||||
});
|
||||
@@ -132,9 +140,9 @@ impl App {
|
||||
pub(crate) fn refresh_settings_flags(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
bridge.set_h264_enabled(self.settings.openh264);
|
||||
bridge.set_h264_enabled(self.state.settings.openh264);
|
||||
bridge.set_h264_attribution(notices::OPENH264_ATTRIBUTION.into());
|
||||
bridge.set_crash_reports(self.settings.crash_reports);
|
||||
bridge.set_crash_reports(self.state.settings.crash_reports);
|
||||
}
|
||||
|
||||
/// The transmit mode for the voice controls (Hold to talk shows for
|
||||
@@ -144,12 +152,12 @@ impl App {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let mut form = bridge.get_audio();
|
||||
form.transmit = settings::transmit_index(self.audio.transmit);
|
||||
form.transmit = settings::transmit_index(self.state.audio.transmit);
|
||||
bridge.set_audio(form);
|
||||
}
|
||||
|
||||
pub(crate) fn set_crash_reports(&mut self, enabled: bool) {
|
||||
self.settings.crash_reports = enabled;
|
||||
self.state.settings.crash_reports = enabled;
|
||||
// Also in the blob, for older versions.
|
||||
self.store_settings();
|
||||
if let Err(e) = self.prefs.set(&CRASH_REPORTS, enabled) {
|
||||
@@ -207,13 +215,17 @@ impl App {
|
||||
|
||||
/// Fill the volume dialog for `client` of the current session.
|
||||
pub(crate) fn open_client(&mut self, client: u16) -> bool {
|
||||
let Some(id) = self.current else { return false };
|
||||
let Some(id) = self.state.current else { return false };
|
||||
let Some(info) = self.view().and_then(|v| v.presence.clients.get(&client)).cloned() else {
|
||||
return false;
|
||||
};
|
||||
let playback =
|
||||
info.uid.as_ref().and_then(|uid| self.playback.get(uid)).copied().unwrap_or_default();
|
||||
self.playback_dialog = Some((id, client, info.uid.clone()));
|
||||
let playback = info
|
||||
.uid
|
||||
.as_ref()
|
||||
.and_then(|uid| self.state.playback.get(uid))
|
||||
.copied()
|
||||
.unwrap_or_default();
|
||||
self.state.playback_dialog = Some((id, client, info.uid.clone()));
|
||||
if let Some(ui) = self.ui.upgrade() {
|
||||
ui.global::<Bridge>().set_client_audio(
|
||||
ClientAudio {
|
||||
@@ -230,7 +242,7 @@ impl App {
|
||||
}
|
||||
|
||||
pub(crate) fn client_playback_changed(&mut self, form: &ClientAudio) {
|
||||
let Some((session, client, uid)) = self.playback_dialog.clone() else { return };
|
||||
let Some((session, client, uid)) = self.state.playback_dialog.clone() else { return };
|
||||
let playback =
|
||||
ClientPlayback { volume: (form.volume / 100.0).clamp(0.0, 4.0), muted: form.muted };
|
||||
let session = session as u64;
|
||||
@@ -239,11 +251,11 @@ impl App {
|
||||
// Kept by unique id; clients without one only for this connection.
|
||||
if let Some(uid) = uid {
|
||||
if playback.is_default() {
|
||||
self.playback.remove(&uid);
|
||||
self.state.playback.remove(&uid);
|
||||
} else {
|
||||
self.playback.insert(uid, playback);
|
||||
self.state.playback.insert(uid, playback);
|
||||
}
|
||||
if let Err(e) = self.prefs.set(&CLIENT_PLAYBACK, self.playback.clone()) {
|
||||
if let Err(e) = self.prefs.set(&CLIENT_PLAYBACK, self.state.playback.clone()) {
|
||||
warn!(%e, "could not store client volumes");
|
||||
}
|
||||
}
|
||||
@@ -268,7 +280,7 @@ impl App {
|
||||
|
||||
/// Send the stored volumes of clients that appeared in a voice session.
|
||||
pub(crate) fn apply_client_playback(&mut self, session: i64) {
|
||||
let Some(view) = self.sessions.get_mut(&session) else { return };
|
||||
let Some(view) = self.state.sessions.get_mut(&session) else { return };
|
||||
if view.state.voice != VoiceState::Connected
|
||||
|| view.state.presence_source != Some(Source::Voice)
|
||||
{
|
||||
@@ -280,7 +292,7 @@ impl App {
|
||||
if !view.applied_playback.insert(client.id) {
|
||||
continue;
|
||||
}
|
||||
let stored = client.uid.as_ref().and_then(|uid| self.playback.get(uid));
|
||||
let stored = client.uid.as_ref().and_then(|uid| self.state.playback.get(uid));
|
||||
let Some(playback) = stored else { continue };
|
||||
let (s, c) = (session as u64, client.id);
|
||||
self.engine.send(Command::SetClientVolume {
|
||||
|
||||
@@ -752,11 +752,12 @@ impl App {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let items: Vec<GatewayItem> = self
|
||||
.state
|
||||
.bookmarks
|
||||
.iter()
|
||||
.filter_map(|b| {
|
||||
let url = b.gateway_url.clone()?;
|
||||
let view = self.sessions.get(&b.id);
|
||||
let view = self.state.sessions.get(&b.id);
|
||||
let caps = view.map(|v| v.gateway_caps.clone()).unwrap_or_default();
|
||||
let status = match view.map(|v| v.state.observe) {
|
||||
_ if !caps.is_empty() => "connected",
|
||||
@@ -775,7 +776,7 @@ impl App {
|
||||
.collect();
|
||||
bridge.set_gateways(convert::model(&items));
|
||||
bridge.set_admin_session(self.pages.admin.map_or(-1, |s| s as i32));
|
||||
let extra = self.pages.admin.and_then(|s| self.sessions.get(&s)).map(|v| &v.extra);
|
||||
let extra = self.pages.admin.and_then(|s| self.state.sessions.get(&s)).map(|v| &v.extra);
|
||||
let config: Vec<ConfigItem> = extra
|
||||
.map(|e| {
|
||||
e.config
|
||||
@@ -986,10 +987,10 @@ impl App {
|
||||
pub(crate) fn refresh_account(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let bookmark = self.current.and_then(|id| self.bookmark(id));
|
||||
let identity = self.identity_for(self.current);
|
||||
let bookmark = self.state.current.and_then(|id| self.bookmark(id));
|
||||
let identity = self.identity_for(self.state.current);
|
||||
let ids = UniqueIds::from_omega(&identity.key().to_pub().to_ts());
|
||||
let entry_id = self.identity_id_for(self.current);
|
||||
let entry_id = self.identity_id_for(self.state.current);
|
||||
let name = self
|
||||
.store
|
||||
.identities()
|
||||
@@ -1018,6 +1019,7 @@ impl App {
|
||||
let entries = self.store.identities().unwrap_or_default();
|
||||
let default = self.default_identity_id();
|
||||
let picks: Vec<(&str, Option<i64>)> = self
|
||||
.state
|
||||
.bookmarks
|
||||
.iter()
|
||||
.map(|b| (b.name.as_str(), self.identity_id_for(Some(b.id))))
|
||||
@@ -1053,6 +1055,7 @@ impl App {
|
||||
names.extend(entries.iter().map(|e| SharedString::from(e.name.as_str())));
|
||||
bridge.set_identity_names(model(names));
|
||||
let choices: Vec<BookmarkIdentity> = self
|
||||
.state
|
||||
.bookmarks
|
||||
.iter()
|
||||
.map(|b| BookmarkIdentity {
|
||||
@@ -1273,7 +1276,7 @@ impl App {
|
||||
self.set_status(format!("Could not save: {e}"));
|
||||
return;
|
||||
}
|
||||
self.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||
self.state.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||
self.refresh_identities();
|
||||
}
|
||||
|
||||
@@ -1347,8 +1350,8 @@ impl App {
|
||||
|
||||
/// Play a short tone on the speakers (the Test Sound button).
|
||||
pub(crate) fn test_sound(&mut self) {
|
||||
let device = self.audio.output_device.clone();
|
||||
let volume = self.audio.output_volume;
|
||||
let device = self.state.audio.output_device.clone();
|
||||
let volume = self.state.audio.output_volume;
|
||||
std::thread::spawn(move || {
|
||||
let result = crate::camera::play_tone(device.as_deref(), volume);
|
||||
if let Err(e) = result {
|
||||
|
||||
@@ -15,9 +15,6 @@ use tracing::debug;
|
||||
use voelin_core::{
|
||||
Command, Contact, Event, FriendSpot, HistoryMessage, HistorySource, Relation, VoiceState,
|
||||
};
|
||||
use voelin_gateway_proto::{
|
||||
Action, ActivityEntry, ConfigEntry, EventInfo, PermRuleInfo, StreamEntry,
|
||||
};
|
||||
use voelin_model::{ChatMessage, ChatTarget};
|
||||
|
||||
use crate::app::{App, Bridge, Nav, Page, SettingsSection};
|
||||
@@ -29,36 +26,6 @@ use crate::vm;
|
||||
use crate::vm::bridge::{ContactItem, NoticeItem, SearchItem};
|
||||
use crate::vm::social::{ago, matches, mentions, plain};
|
||||
|
||||
/// What a session's gateway and voice connection add for these screens.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct SessionExtra {
|
||||
/// The gateway's stream directory.
|
||||
pub directory: Vec<StreamEntry>,
|
||||
/// The gateway's events by start time, and those whose answers are shown.
|
||||
pub events: Vec<EventInfo>,
|
||||
pub events_loaded: bool,
|
||||
pub expanded: HashSet<i64>,
|
||||
/// The activity feed, newest first.
|
||||
pub activity: Vec<ActivityEntry>,
|
||||
/// Our unique id at the gateway, and what we may do there.
|
||||
pub gateway_uid: Option<String>,
|
||||
pub actions: Vec<Action>,
|
||||
/// Gateway administration: its keys and permission rules.
|
||||
pub config: Vec<ConfigEntry>,
|
||||
pub perms: Vec<PermRuleInfo>,
|
||||
/// Offline messages (voice), and whether they were asked for.
|
||||
pub inbox: Vec<voelin_core::OfflineMessageInfo>,
|
||||
pub inbox_asked: bool,
|
||||
/// Pictures linked in chat, by link (`previews.rs`).
|
||||
pub previews: HashMap<String, crate::previews::Preview>,
|
||||
/// When this session's presence first came (ms): friends found in it
|
||||
/// then are not "coming online".
|
||||
pub presence_since: i64,
|
||||
/// "TeamSpeak 6", "TeamSpeak 3" once the server told what it runs;
|
||||
/// empty before that, and for software nobody recognised.
|
||||
pub product: String,
|
||||
}
|
||||
|
||||
/// A poke we got.
|
||||
pub(crate) struct Poke {
|
||||
pub session: i64,
|
||||
@@ -270,24 +237,30 @@ const SETTING_PAGES: [(&str, &str, SettingsSection); 11] = [
|
||||
impl App {
|
||||
/// The avatar picture of someone by unique id, from any session.
|
||||
pub(crate) fn avatar_of(&self, uid: &str) -> vm::ImageRef {
|
||||
vm::avatar::image(self.sessions.values().find_map(|v| v.avatars.get(uid)))
|
||||
vm::avatar::image(self.state.sessions.values().find_map(|v| v.avatars.get(uid)))
|
||||
}
|
||||
|
||||
/// A server's name: its bookmark's, else what the session calls it.
|
||||
pub(crate) fn server_name(&self, session: i64) -> String {
|
||||
self.bookmark(session).map(|b| b.name.clone()).unwrap_or_else(|| {
|
||||
self.sessions.get(&session).map(|v| v.presence.server_name.clone()).unwrap_or_default()
|
||||
self.state
|
||||
.sessions
|
||||
.get(&session)
|
||||
.map(|v| v.presence.server_name.clone())
|
||||
.unwrap_or_default()
|
||||
})
|
||||
}
|
||||
|
||||
/// Every session where the client with this unique id is, in bookmark
|
||||
/// order.
|
||||
pub(crate) fn spots_of(&self, uid: &str) -> Vec<Spot> {
|
||||
let mut ids: Vec<i64> = self.sessions.keys().copied().collect();
|
||||
ids.sort_by_key(|id| self.bookmarks.iter().position(|b| b.id == *id).unwrap_or(usize::MAX));
|
||||
let mut ids: Vec<i64> = self.state.sessions.keys().copied().collect();
|
||||
ids.sort_by_key(|id| {
|
||||
self.state.bookmarks.iter().position(|b| b.id == *id).unwrap_or(usize::MAX)
|
||||
});
|
||||
let mut spots = Vec::new();
|
||||
for id in ids {
|
||||
let view = &self.sessions[&id];
|
||||
let view = &self.state.sessions[&id];
|
||||
let Some(c) = view.presence.clients.values().find(|c| c.uid.as_deref() == Some(uid))
|
||||
else {
|
||||
continue;
|
||||
@@ -312,7 +285,7 @@ impl App {
|
||||
/// The title of what someone streams, if a directory or the voice
|
||||
/// connection says.
|
||||
fn stream_title(&self, spot: &Spot, uid: &str) -> Option<String> {
|
||||
let view = self.sessions.get(&spot.session)?;
|
||||
let view = self.state.sessions.get(&spot.session)?;
|
||||
view.streams
|
||||
.iter()
|
||||
.find(|s| s.streamer == spot.client)
|
||||
@@ -329,7 +302,7 @@ impl App {
|
||||
let first = spots.first();
|
||||
let name = if contact.nickname.is_empty() {
|
||||
first
|
||||
.map(|s| self.sessions[&s.session].nickname(s.client))
|
||||
.map(|s| self.state.sessions[&s.session].nickname(s.client))
|
||||
.unwrap_or_else(|| contact.uid.chars().take(8).collect())
|
||||
} else {
|
||||
contact.nickname.clone()
|
||||
@@ -415,7 +388,7 @@ impl App {
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let m = &self.models.social;
|
||||
let mut all: Vec<ContactItem> =
|
||||
self.contacts.values().map(|c| self.contact_item(c)).collect();
|
||||
self.state.contacts.values().map(|c| self.contact_item(c)).collect();
|
||||
self.sorted_contacts(&mut all);
|
||||
let friends: Vec<ContactItem> =
|
||||
all.iter().filter(|c| &*c.relation == "friend").cloned().collect();
|
||||
@@ -424,7 +397,7 @@ impl App {
|
||||
// Online friends first, then the others by when they were seen.
|
||||
let mut activity = friends.clone();
|
||||
activity.sort_by_key(|c| {
|
||||
let seen = self.contacts.get(c.uid.as_ref()).map_or(0, |c| c.last_seen_ms);
|
||||
let seen = self.state.contacts.get(c.uid.as_ref()).map_or(0, |c| c.last_seen_ms);
|
||||
let since = self.social.online_since.get(c.uid.as_ref()).copied().unwrap_or(0);
|
||||
(!c.online, !c.streaming, std::cmp::Reverse(if c.online { since } else { seen }))
|
||||
});
|
||||
@@ -476,15 +449,15 @@ impl App {
|
||||
|
||||
/// Change a contact (or make one of someone we see).
|
||||
fn update_contact(&mut self, uid: &str, f: impl FnOnce(&mut Contact)) {
|
||||
let mut contact = self.contacts.get(uid).cloned().unwrap_or_else(|| {
|
||||
let mut contact = self.state.contacts.get(uid).cloned().unwrap_or_else(|| {
|
||||
let mut c = Contact::new(uid);
|
||||
if let Some(s) = self.spots_of(uid).first() {
|
||||
c.nickname = self.sessions[&s.session].nickname(s.client);
|
||||
c.nickname = self.state.sessions[&s.session].nickname(s.client);
|
||||
}
|
||||
c
|
||||
});
|
||||
f(&mut contact);
|
||||
self.contacts.insert(uid.to_owned(), contact.clone());
|
||||
self.state.contacts.insert(uid.to_owned(), contact.clone());
|
||||
if !self.demo_ui {
|
||||
self.engine.send(Command::SetContact { contact: Box::new(contact) });
|
||||
}
|
||||
@@ -514,7 +487,7 @@ impl App {
|
||||
"neutral" => self.update_contact(uid, |c| c.relation = Relation::Neutral),
|
||||
"mute" => self.update_contact(uid, |c| c.muted = !c.muted),
|
||||
"remove" => {
|
||||
self.contacts.remove(uid);
|
||||
self.state.contacts.remove(uid);
|
||||
if self.social.selected.as_deref() == Some(uid) {
|
||||
self.social.selected = None;
|
||||
}
|
||||
@@ -556,14 +529,14 @@ impl App {
|
||||
if s.voice {
|
||||
self.watch_client(s.client);
|
||||
} else {
|
||||
self.pending_watch = Some((s.session, s.client));
|
||||
self.state.pending_watch = Some((s.session, s.client));
|
||||
self.join_person(&[s]);
|
||||
}
|
||||
}
|
||||
|
||||
/// The server page of a session.
|
||||
pub(crate) fn show_server(&mut self, session: i64) {
|
||||
if self.current != Some(session) {
|
||||
if self.state.current != Some(session) {
|
||||
self.select_server(session);
|
||||
}
|
||||
self.navigate(|nav| nav.invoke_show(Page::Server));
|
||||
@@ -701,7 +674,7 @@ impl App {
|
||||
|
||||
/// Our nickname in a session.
|
||||
fn own_nick(&self, session: i64) -> String {
|
||||
let view = self.sessions.get(&session);
|
||||
let view = self.state.sessions.get(&session);
|
||||
view.and_then(|v| v.state.own_client.map(|c| v.nickname(c)))
|
||||
.or_else(|| self.bookmark(session).map(|b| b.nickname.clone()))
|
||||
.unwrap_or_default()
|
||||
@@ -709,7 +682,7 @@ impl App {
|
||||
|
||||
/// Whether a message is ours.
|
||||
pub(crate) fn is_own(&self, session: i64, message: &ChatMessage) -> bool {
|
||||
let own_client = self.sessions.get(&session).and_then(|v| v.state.own_client);
|
||||
let own_client = self.state.sessions.get(&session).and_then(|v| v.state.own_client);
|
||||
own_message(&self.social.own_uids, own_client, message)
|
||||
}
|
||||
|
||||
@@ -739,6 +712,7 @@ impl App {
|
||||
}
|
||||
let place = match target {
|
||||
ChatTarget::Channel(cid) => self
|
||||
.state
|
||||
.sessions
|
||||
.get(&session)
|
||||
.and_then(|v| v.presence.channels.get(cid))
|
||||
@@ -764,7 +738,7 @@ impl App {
|
||||
let mut touched = Touched::default();
|
||||
match event {
|
||||
Event::Presence { session, .. } => {
|
||||
let view = self.sessions.entry(*session as i64).or_default();
|
||||
let view = self.state.sessions.entry(*session as i64).or_default();
|
||||
if view.extra.presence_since == 0 {
|
||||
view.extra.presence_since = now_ms();
|
||||
}
|
||||
@@ -773,9 +747,9 @@ impl App {
|
||||
}
|
||||
Event::State { session, state } => {
|
||||
let id = *session as i64;
|
||||
let was = self.sessions.get(&id).map(|v| v.state.voice);
|
||||
let was = self.state.sessions.get(&id).map(|v| v.state.voice);
|
||||
if state.voice != VoiceState::Connected {
|
||||
if let Some(view) = self.sessions.get_mut(&id) {
|
||||
if let Some(view) = self.state.sessions.get_mut(&id) {
|
||||
view.extra.inbox_asked = false;
|
||||
}
|
||||
} else if was != Some(VoiceState::Connected) {
|
||||
@@ -785,7 +759,7 @@ impl App {
|
||||
touched.home = true;
|
||||
}
|
||||
Event::ServerInfo { session, backend, .. } => {
|
||||
self.sessions.entry(*session as i64).or_default().extra.product =
|
||||
self.state.sessions.entry(*session as i64).or_default().extra.product =
|
||||
backend.product.clone();
|
||||
touched.people = true;
|
||||
touched.home = true;
|
||||
@@ -830,7 +804,7 @@ impl App {
|
||||
}
|
||||
Event::Chat { session, message } => {
|
||||
let id = *session as i64;
|
||||
if !self.sessions.get(&id).is_some_and(|v| v.has_history()) {
|
||||
if !self.state.sessions.get(&id).is_some_and(|v| v.has_history()) {
|
||||
self.chat_notice(id, message);
|
||||
touched.chats = true;
|
||||
}
|
||||
@@ -839,6 +813,7 @@ impl App {
|
||||
let id = *session as i64;
|
||||
if *source == HistorySource::Live {
|
||||
let known: HashSet<i64> = self
|
||||
.state
|
||||
.sessions
|
||||
.get(&id)
|
||||
.and_then(|v| v.tabs.iter().find(|t| t.target == *target))
|
||||
@@ -855,7 +830,7 @@ impl App {
|
||||
Event::OfflineMessages { session, result, .. } => {
|
||||
match result {
|
||||
Ok(list) => {
|
||||
self.sessions.entry(*session as i64).or_default().extra.inbox =
|
||||
self.state.sessions.entry(*session as i64).or_default().extra.inbox =
|
||||
list.clone();
|
||||
}
|
||||
Err(e) => debug!("offline messages: {e}"),
|
||||
@@ -897,13 +872,14 @@ impl App {
|
||||
self.social.online_since.insert(uid.to_owned(), now);
|
||||
// Friends found in a session's first presence were there before.
|
||||
let new = sessions.iter().all(|s| {
|
||||
self.sessions.get(&(s.session as i64)).is_some_and(|v| {
|
||||
self.state.sessions.get(&(s.session as i64)).is_some_and(|v| {
|
||||
v.extra.presence_since > 0 && now - v.extra.presence_since > 10_000
|
||||
})
|
||||
});
|
||||
if new {
|
||||
let s = &sessions[0];
|
||||
let channel = self
|
||||
.state
|
||||
.sessions
|
||||
.get(&(s.session as i64))
|
||||
.and_then(|v| v.presence.channels.get(&s.channel))
|
||||
@@ -949,9 +925,10 @@ impl App {
|
||||
};
|
||||
if !people_only {
|
||||
let servers = self
|
||||
.state
|
||||
.bookmarks
|
||||
.iter()
|
||||
.zip(vm::servers::tints(&self.bookmarks))
|
||||
.zip(vm::servers::tints(&self.state.bookmarks))
|
||||
.filter(|(b, _)| matches(&query, &[&b.name, &b.address]))
|
||||
.map(|(b, tint)| {
|
||||
(
|
||||
@@ -972,8 +949,8 @@ impl App {
|
||||
}
|
||||
if !query.is_empty() && !people_only {
|
||||
let mut channels = Vec::new();
|
||||
for b in &self.bookmarks {
|
||||
let Some(view) = self.sessions.get(&b.id) else { continue };
|
||||
for b in &self.state.bookmarks {
|
||||
let Some(view) = self.state.sessions.get(&b.id) else { continue };
|
||||
for (channel, title) in
|
||||
vm::social::found_channels(view.presence.channels.values(), &query)
|
||||
{
|
||||
@@ -993,8 +970,8 @@ impl App {
|
||||
if !query.is_empty() || people_only {
|
||||
let mut people = Vec::new();
|
||||
let mut seen: HashSet<String> = HashSet::new();
|
||||
for b in &self.bookmarks {
|
||||
let Some(view) = self.sessions.get(&b.id) else { continue };
|
||||
for b in &self.state.bookmarks {
|
||||
let Some(view) = self.state.sessions.get(&b.id) else { continue };
|
||||
for c in view.presence.clients.values() {
|
||||
if c.is_query || Some(c.id) == view.state.own_client {
|
||||
continue;
|
||||
@@ -1024,7 +1001,7 @@ impl App {
|
||||
));
|
||||
}
|
||||
}
|
||||
for c in self.contacts.values() {
|
||||
for c in self.state.contacts.values() {
|
||||
if seen.contains(&c.uid) || !matches(&query, &[&c.nickname, &c.note]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -185,17 +185,18 @@ impl App {
|
||||
pub(crate) fn stream_event(&mut self, event: Event) {
|
||||
match event {
|
||||
Event::StreamsChanged { session, streams } => {
|
||||
let view = self.sessions.entry(session as i64).or_default();
|
||||
let view = self.state.sessions.entry(session as i64).or_default();
|
||||
// Development switch: watch the first stream that shows up.
|
||||
let autowatch = std::env::var("VOELIN_AUTOWATCH").is_ok_and(|v| v == "1")
|
||||
&& self.watch.is_none()
|
||||
&& self.current == Some(session as i64);
|
||||
&& self.state.current == Some(session as i64);
|
||||
let first = streams
|
||||
.iter()
|
||||
.find(|s| view.state.own_client != Some(s.streamer))
|
||||
.map(|s| s.id.clone());
|
||||
// A client whose stream was asked for while it was looked up.
|
||||
let pending = self
|
||||
.state
|
||||
.pending_watch
|
||||
.filter(|(s, _)| *s == session as i64)
|
||||
.and_then(|(_, client)| streams.iter().find(|s| s.streamer == client))
|
||||
@@ -204,7 +205,7 @@ impl App {
|
||||
self.refresh_streams();
|
||||
self.refresh_servers();
|
||||
if let Some(id) = pending {
|
||||
self.pending_watch = None;
|
||||
self.state.pending_watch = None;
|
||||
self.watch_stream(id);
|
||||
} else if autowatch && let Some(id) = first {
|
||||
self.watch_stream(id);
|
||||
@@ -212,7 +213,7 @@ impl App {
|
||||
}
|
||||
Event::StreamState { session, state } => self.share_state(session as i64, state),
|
||||
Event::StreamViewerRequest { session, viewer, .. } => {
|
||||
let name = self.sessions.entry(session as i64).or_default().nickname(viewer);
|
||||
let name = self.state.sessions.entry(session as i64).or_default().nickname(viewer);
|
||||
self.set_status(format!("{name} wants to watch your stream"));
|
||||
}
|
||||
Event::StreamViewers { session, viewers } => {
|
||||
@@ -253,7 +254,8 @@ impl App {
|
||||
StreamState::Ended(reason) => {
|
||||
let local = reason == EndReason::Local || share.stopping;
|
||||
self.share = None;
|
||||
self.share_error = if local { String::new() } else { share_end_text(&reason) };
|
||||
self.state.share_error =
|
||||
if local { String::new() } else { share_end_text(&reason) };
|
||||
self.set_status(if local {
|
||||
"You stopped sharing".into()
|
||||
} else {
|
||||
@@ -301,7 +303,7 @@ impl App {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let view = self.view();
|
||||
let current = self.current;
|
||||
let current = self.state.current;
|
||||
let mut items: Vec<StreamItem> = Vec::new();
|
||||
if let Some(view) = view.filter(|v| v.streams_available()) {
|
||||
// Every channel's streams (they can be watched from anywhere),
|
||||
@@ -370,12 +372,12 @@ impl App {
|
||||
let state = match share {
|
||||
Some(s) if s.live => "live",
|
||||
Some(_) => "starting",
|
||||
None if self.share_busy => "starting",
|
||||
None if self.state.share_busy => "starting",
|
||||
None => "",
|
||||
};
|
||||
bridge.set_share_state(state.into());
|
||||
bridge.set_share_busy(self.share_busy);
|
||||
bridge.set_share_error(self.share_error.clone().into());
|
||||
bridge.set_share_busy(self.state.share_busy);
|
||||
bridge.set_share_error(self.state.share_error.clone().into());
|
||||
bridge.set_share_audio(share.is_some_and(|s| s.capture.has_audio()));
|
||||
let viewers: Vec<ViewerItem> = share
|
||||
.map(|s| {
|
||||
@@ -404,7 +406,7 @@ impl App {
|
||||
let status = match share {
|
||||
Some(s) if s.live => s.capture.status(),
|
||||
Some(s) => format!("Starting the stream of {}…", s.capture.source_name()),
|
||||
None if self.share_busy => "Starting the capture…".into(),
|
||||
None if self.state.share_busy => "Starting the capture…".into(),
|
||||
None => String::new(),
|
||||
};
|
||||
bridge.set_share_status(status.into());
|
||||
@@ -438,7 +440,7 @@ impl App {
|
||||
// The watched stream's server, which the main window may have left
|
||||
// while the stream plays in its own.
|
||||
let view = match watch.session {
|
||||
Some(id) => self.sessions.get(&id),
|
||||
Some(id) => self.state.sessions.get(&id),
|
||||
None => self.view(),
|
||||
};
|
||||
let decoded = watch.decoder.as_ref().map(Decoder::info).unwrap_or_default();
|
||||
@@ -477,7 +479,7 @@ impl App {
|
||||
bridge.set_viewer_status(watch.status.as_str().into());
|
||||
bridge.set_viewer_ended(watch.ended);
|
||||
bridge.set_viewer_has_frame(watch.has_frame);
|
||||
bridge.set_viewer_volume(self.stream_volume);
|
||||
bridge.set_viewer_volume(self.state.stream_volume);
|
||||
bridge.set_viewer_info(info.as_str().into());
|
||||
bridge.set_viewer_streamer(watch.streamer.as_str().into());
|
||||
bridge.set_viewer_streamer_avatar(convert::image(&face.avatar));
|
||||
@@ -497,7 +499,7 @@ impl App {
|
||||
/// The watched stream is on the server on screen (or is the local test
|
||||
/// stream).
|
||||
pub(crate) fn watch_here(&self) -> bool {
|
||||
self.watch.as_ref().is_some_and(|w| w.session.is_none() || w.session == self.current)
|
||||
self.watch.as_ref().is_some_and(|w| w.session.is_none() || w.session == self.state.current)
|
||||
}
|
||||
|
||||
/// A simulcast layer of the watched stream (0: follow the bandwidth
|
||||
@@ -555,16 +557,16 @@ impl App {
|
||||
let test_pattern = cfg!(debug_assertions)
|
||||
|| self.demo
|
||||
|| std::env::var("VOELIN_TEST_PATTERN").is_ok_and(|v| v == "1");
|
||||
let restorable = self.settings.portal_restore_token.is_some();
|
||||
let restorable = self.state.settings.portal_restore_token.is_some();
|
||||
let sources = match self.video.sources(test_pattern, restorable) {
|
||||
Ok(sources) => {
|
||||
if self.share.is_none() {
|
||||
self.share_error.clear();
|
||||
self.state.share_error.clear();
|
||||
}
|
||||
sources
|
||||
}
|
||||
Err(e) => {
|
||||
self.share_error = e;
|
||||
self.state.share_error = e;
|
||||
Vec::new()
|
||||
}
|
||||
};
|
||||
@@ -578,8 +580,9 @@ impl App {
|
||||
self.refresh_streams();
|
||||
// Its audio: the Stream Studio's mixer rows and picker.
|
||||
self.mixer_show();
|
||||
let defaults = &self.settings.share;
|
||||
let nickname = self.current.and_then(|id| self.bookmark(id)).map(|b| b.nickname.clone());
|
||||
let defaults = &self.state.settings.share;
|
||||
let nickname =
|
||||
self.state.current.and_then(|id| self.bookmark(id)).map(|b| b.nickname.clone());
|
||||
let (fps, bitrate) = (self.prefs.get(&STREAM_FPS), self.prefs.get(&STREAM_BITRATE_KBPS));
|
||||
ShareForm {
|
||||
source: 0,
|
||||
@@ -628,12 +631,13 @@ impl App {
|
||||
}
|
||||
|
||||
pub(crate) fn start_share(&mut self, form: ShareForm) {
|
||||
let Some(session) = self.current else { return };
|
||||
if self.share_busy || self.share.is_some() {
|
||||
let Some(session) = self.state.current else { return };
|
||||
if self.state.share_busy || self.share.is_some() {
|
||||
return;
|
||||
}
|
||||
if self.studio_streams_to(session) {
|
||||
self.share_error = "The Stream Studio is live here: end that stream first.".into();
|
||||
self.state.share_error =
|
||||
"The Stream Studio is live here: end that stream first.".into();
|
||||
self.refresh_streams();
|
||||
return;
|
||||
}
|
||||
@@ -661,12 +665,12 @@ impl App {
|
||||
};
|
||||
// The mixer's sources (the sample studio's with VOELIN_DEMO_UI).
|
||||
let sources = self.studio_settings().get(&STREAM_AUDIO_SOURCES);
|
||||
let token = self.settings.portal_restore_token.clone();
|
||||
let token = self.state.settings.portal_restore_token.clone();
|
||||
let request = capture_request(fps, bitrate, form.audio, &sources, token);
|
||||
self.settings.share = defaults;
|
||||
self.state.settings.share = defaults;
|
||||
self.store_settings();
|
||||
self.share_busy = true;
|
||||
self.share_error.clear();
|
||||
self.state.share_busy = true;
|
||||
self.state.share_error.clear();
|
||||
self.refresh_streams();
|
||||
let setup = StreamSetup {
|
||||
name: form.name.trim().to_owned(),
|
||||
@@ -690,16 +694,16 @@ impl App {
|
||||
auto_accept: bool,
|
||||
result: Result<Capture, String>,
|
||||
) {
|
||||
self.share_busy = false;
|
||||
self.state.share_busy = false;
|
||||
match result {
|
||||
Err(e) => {
|
||||
self.share_error = format!("Could not start the capture: {e}");
|
||||
self.state.share_error = format!("Could not start the capture: {e}");
|
||||
}
|
||||
Ok(capture) => {
|
||||
if let Some(token) = capture.restore_token()
|
||||
&& self.settings.portal_restore_token.as_ref() != Some(&token)
|
||||
&& self.state.settings.portal_restore_token.as_ref() != Some(&token)
|
||||
{
|
||||
self.settings.portal_restore_token = Some(token);
|
||||
self.state.settings.portal_restore_token = Some(token);
|
||||
self.store_settings();
|
||||
}
|
||||
if setup.bitrate == 0 {
|
||||
@@ -791,8 +795,8 @@ impl App {
|
||||
self.start_demo();
|
||||
return;
|
||||
}
|
||||
let Some(session) = self.current else { return };
|
||||
let Some(view) = self.sessions.get(&session) else { return };
|
||||
let Some(session) = self.state.current else { return };
|
||||
let Some(view) = self.state.sessions.get(&session) else { return };
|
||||
let Some(info) = view.streams.iter().find(|s| s.id == stream_id) else { return };
|
||||
let streamer = view.nickname(info.streamer);
|
||||
let title =
|
||||
@@ -801,11 +805,11 @@ impl App {
|
||||
self.stop_watching();
|
||||
self.engine
|
||||
.send(Command::WatchStream { session: session as u64, stream_id: stream_id.clone() });
|
||||
if self.stream_volume != 100.0 {
|
||||
if self.state.stream_volume != 100.0 {
|
||||
self.engine.send(Command::SetStreamVolume {
|
||||
session: session as u64,
|
||||
stream_id: stream_id.clone(),
|
||||
volume: self.stream_volume / 100.0,
|
||||
volume: self.state.stream_volume / 100.0,
|
||||
});
|
||||
}
|
||||
let wake = || later(|app| app.show_picture());
|
||||
@@ -836,17 +840,17 @@ impl App {
|
||||
/// the lookup brings it (it may have started in another channel or
|
||||
/// before we joined).
|
||||
pub(crate) fn watch_client(&mut self, client: u16) {
|
||||
let Some(session) = self.current else { return };
|
||||
let Some(view) = self.sessions.get(&session) else { return };
|
||||
let Some(session) = self.state.current else { return };
|
||||
let Some(view) = self.state.sessions.get(&session) else { return };
|
||||
if view.state.own_client == Some(client) {
|
||||
return;
|
||||
}
|
||||
if let Some(id) = view.streams.iter().find(|s| s.streamer == client).map(|s| s.id.clone()) {
|
||||
self.pending_watch = None;
|
||||
self.state.pending_watch = None;
|
||||
self.watch_stream(id);
|
||||
} else if view.presence.clients.get(&client).is_some_and(|c| c.streaming == Some(true)) {
|
||||
let name = view.nickname(client);
|
||||
self.pending_watch = Some((session, client));
|
||||
self.state.pending_watch = Some((session, client));
|
||||
self.set_status(format!("Looking up {name}'s stream…"));
|
||||
}
|
||||
}
|
||||
@@ -972,14 +976,14 @@ impl App {
|
||||
}
|
||||
|
||||
pub(crate) fn set_stream_volume(&mut self, percent: f32) {
|
||||
self.stream_volume = percent.round().clamp(0.0, 200.0);
|
||||
self.state.stream_volume = percent.round().clamp(0.0, 200.0);
|
||||
if let Some(watch) = &self.watch
|
||||
&& let Some(session) = watch.session
|
||||
{
|
||||
self.engine.send(Command::SetStreamVolume {
|
||||
session: session as u64,
|
||||
stream_id: watch.stream_id.clone(),
|
||||
volume: self.stream_volume / 100.0,
|
||||
volume: self.state.stream_volume / 100.0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -858,18 +858,19 @@ impl App {
|
||||
/// one first.
|
||||
fn studio_destinations(&self) -> Vec<(i64, String)> {
|
||||
let mut ids: Vec<i64> = self
|
||||
.state
|
||||
.sessions
|
||||
.iter()
|
||||
.filter(|(_, v)| v.streams_available() && v.state.own_channel.is_some())
|
||||
.map(|(id, _)| *id)
|
||||
.collect();
|
||||
ids.sort_by_key(|id| (Some(*id) != self.current, *id));
|
||||
ids.sort_by_key(|id| (Some(*id) != self.state.current, *id));
|
||||
ids.into_iter().map(|id| (id, self.studio_destination_name(id))).collect()
|
||||
}
|
||||
|
||||
/// The channel and the server of a destination.
|
||||
fn studio_destination_parts(&self, id: i64) -> (String, String) {
|
||||
let Some(view) = self.sessions.get(&id) else { return Default::default() };
|
||||
let Some(view) = self.state.sessions.get(&id) else { return Default::default() };
|
||||
let channel = view
|
||||
.state
|
||||
.own_channel
|
||||
@@ -918,7 +919,7 @@ impl App {
|
||||
/// The session and channel the stream (and its chat) goes to.
|
||||
fn studio_chat_target(&self) -> Option<(i64, u64)> {
|
||||
let id = self.studio.destination?;
|
||||
Some((id, self.sessions.get(&id)?.state.own_channel?))
|
||||
Some((id, self.state.sessions.get(&id)?.state.own_channel?))
|
||||
}
|
||||
|
||||
/// Show the destination channel's chat (its tab opened, with its
|
||||
@@ -928,7 +929,7 @@ impl App {
|
||||
Some((id, channel)) => {
|
||||
let target = ChatTarget::Channel(channel);
|
||||
let demo = self.demo_ui;
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let view = self.state.sessions.entry(id).or_default();
|
||||
let name = view
|
||||
.presence
|
||||
.channels
|
||||
@@ -955,7 +956,7 @@ impl App {
|
||||
/// to date, and the stream's channel need not be that tab.
|
||||
fn studio_sync_chat(&self) {
|
||||
let tab = self.studio_chat_target().and_then(|(id, channel)| {
|
||||
let view = self.sessions.get(&id)?;
|
||||
let view = self.state.sessions.get(&id)?;
|
||||
let tab = view.tabs.iter().find(|t| t.target == ChatTarget::Channel(channel))?;
|
||||
Some((view, tab))
|
||||
});
|
||||
@@ -1148,7 +1149,7 @@ impl App {
|
||||
fn studio_viewer_name(&self, viewer: &ViewerInfo) -> String {
|
||||
let session = self.studio.stream.as_ref().map(|s| s.session);
|
||||
session
|
||||
.and_then(|id| self.sessions.get(&id))
|
||||
.and_then(|id| self.state.sessions.get(&id))
|
||||
.map_or_else(|| format!("client {}", viewer.client), |v| v.nickname(viewer.client))
|
||||
}
|
||||
|
||||
@@ -1946,7 +1947,7 @@ impl App {
|
||||
audio: self.studio.ui.audio,
|
||||
..StreamSetup::default()
|
||||
};
|
||||
let auto_accept = self.settings.share.auto_accept;
|
||||
let auto_accept = self.state.settings.share.auto_accept;
|
||||
// The stream's layers are the encoder's, so viewers move between
|
||||
// them (the session sends only layers it knows of).
|
||||
let session = session as u64;
|
||||
@@ -2040,7 +2041,7 @@ impl App {
|
||||
let target = ChatTarget::Channel(channel);
|
||||
// Sample data has no engine to echo the message: shown as it would be.
|
||||
if self.demo_ui {
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let view = self.state.sessions.entry(id).or_default();
|
||||
let (client, history) = (view.state.own_client, view.has_history());
|
||||
let author = self.bookmark(id).map(|b| b.nickname.clone()).unwrap_or_default();
|
||||
let ts_ms = chrono::Utc::now().timestamp_millis();
|
||||
@@ -2078,7 +2079,7 @@ impl App {
|
||||
/// The destination's chat in the main window.
|
||||
pub(crate) fn studio_open_chat(&mut self) {
|
||||
let Some((id, channel)) = self.studio_chat_target() else { return };
|
||||
if self.current != Some(id) {
|
||||
if self.state.current != Some(id) {
|
||||
self.select_server(id);
|
||||
}
|
||||
self.open_chat(ChatTarget::Channel(channel), true);
|
||||
@@ -2246,7 +2247,7 @@ impl App {
|
||||
let Some(session) = self.studio.stream.as_ref().map(|s| s.session) else { return };
|
||||
let name = stream_name(&self.studio.ui);
|
||||
let audio = self.studio.ui.audio;
|
||||
let Some(view) = self.sessions.get_mut(&session) else { return };
|
||||
let Some(view) = self.state.sessions.get_mut(&session) else { return };
|
||||
view.streams.retain(|s| s.id != "demo-studio");
|
||||
if live && let Some(own) = view.state.own_client {
|
||||
view.streams.push(StreamInfo {
|
||||
|
||||
Reference in new issue
Block a user