Merge phase5/ui-vm: the toolkit-free voelin-ui-vm crate (plan section 6 step 2)
CI / Linux checks (push) Failing after 1m7s
CI / Linux checks (push) Failing after 1m7s
Shared view-model types (ImageSource, Rgb, list diffing), the view models, the BBCode reader and the Twemoji archive, SessionView/Tab/Msg and the App state moved out of the Slint crate into voelin-ui-vm; the Slint crate keeps adapters and bindings (studio and settings split into logic and bind). Opus gate accepted with five minors left as follow-ups (server_tint falls back to black, ImageSource::size reads headers only, convert::image does not check the RGBA length, docs/ui.md metric wording, field docs on the mirrored bridge structs). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
commit
ad2097963e
73 files changed
+11836
-5281
No files matched your search
@@ -69,6 +69,13 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- The view models, the app's state and the decisions of the settings pages and
|
||||||
|
of the Stream Studio moved out of `voelin-ui` into a new crate,
|
||||||
|
`voelin-ui-vm`, which depends on no UI toolkit (a second front end can use
|
||||||
|
it); `voelin-ui` converts its plain rows into Slint's and keeps the window,
|
||||||
|
the Bridge writes and the engine's tasks. The chat formatting reader and the
|
||||||
|
Twemoji archive moved with them. Nothing changes on screen. See
|
||||||
|
docs/ui.md, "Two crates".
|
||||||
- The identity store keeps identities of more than one kind (TeamSpeak, a Voelin
|
- The identity store keeps identities of more than one kind (TeamSpeak, a Voelin
|
||||||
key, the signed-in account) with the account each belongs to, as a
|
key, the signed-in account) with the account each belongs to, as a
|
||||||
`voelin-identity` key store, in two database migrations. Existing
|
`voelin-identity` key store, in two database migrations. Existing
|
||||||
|
|||||||
Generated
+19
-1
@@ -9736,7 +9736,6 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"dirs",
|
"dirs",
|
||||||
"image",
|
"image",
|
||||||
"miniz_oxide 0.8.9",
|
|
||||||
"png",
|
"png",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -9754,6 +9753,25 @@ dependencies = [
|
|||||||
"voelin-platform",
|
"voelin-platform",
|
||||||
"voelin-query",
|
"voelin-query",
|
||||||
"voelin-store",
|
"voelin-store",
|
||||||
|
"voelin-ui-vm",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "voelin-ui-vm"
|
||||||
|
version = "0.0.1-alpha"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
"image",
|
||||||
|
"miniz_oxide 0.8.9",
|
||||||
|
"png",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"unicode-segmentation",
|
||||||
|
"voelin-audio",
|
||||||
|
"voelin-core",
|
||||||
|
"voelin-gateway-proto",
|
||||||
|
"voelin-model",
|
||||||
|
"voelin-store",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ members = [
|
|||||||
"crates/voelin-store",
|
"crates/voelin-store",
|
||||||
"crates/voelin-stream",
|
"crates/voelin-stream",
|
||||||
"crates/voelin-ui",
|
"crates/voelin-ui",
|
||||||
|
"crates/voelin-ui-vm",
|
||||||
"tools/voelinctl",
|
"tools/voelinctl",
|
||||||
]
|
]
|
||||||
default-members = [
|
default-members = [
|
||||||
@@ -43,6 +44,7 @@ default-members = [
|
|||||||
"crates/voelin-store",
|
"crates/voelin-store",
|
||||||
"crates/voelin-stream",
|
"crates/voelin-stream",
|
||||||
"crates/voelin-ui",
|
"crates/voelin-ui",
|
||||||
|
"crates/voelin-ui-vm",
|
||||||
"tools/voelinctl",
|
"tools/voelinctl",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ Done so far (milestones M0–M4 and the first part of M5 of [the plan](docs/arch
|
|||||||
(in the window and as a global hotkey), audio settings with a level meter, per-client volume, and on
|
(in the window and as a global hotkey), audio settings with a level meter, per-client volume, and on
|
||||||
TeamSpeak 6 streams: watch in a viewer, share the screen with sound. Desktop and phone layouts
|
TeamSpeak 6 streams: watch in a viewer, share the screen with sound. Desktop and phone layouts
|
||||||
from one design system, dark and light themes, text size, emoji ([docs/ui.md](docs/ui.md))
|
from one design system, dark and light themes, text size, emoji ([docs/ui.md](docs/ui.md))
|
||||||
|
- `crates/voelin-ui-vm`: the view models and the app's state behind the UI, with no UI toolkit: engine state
|
||||||
|
as plain rows and forms, chat formatting, the Twemoji archive, and what the settings pages and the
|
||||||
|
Stream Studio decide; `voelin-ui` puts them on Slint windows ([docs/ui.md](docs/ui.md))
|
||||||
- `crates/voelin-stream`: TeamSpeak 6 streams: stream commands and notifications, JSON signalling,
|
- `crates/voelin-stream`: TeamSpeak 6 streams: stream commands and notifications, JSON signalling,
|
||||||
WebRTC peers (str0m) with host and STUN candidates. A live test streams VP8 + Opus between two
|
WebRTC peers (str0m) with host and STUN candidates. A live test streams VP8 + Opus between two
|
||||||
clients through a TS6 server
|
clients through a TS6 server
|
||||||
|
|||||||
@@ -11991,7 +11991,8 @@ bzip2/libbzip2 version 1.1.0 of 6 September 2010
|
|||||||
|
|
||||||
<!-- From about-assets.md, appended by scripts/notices.sh. -->
|
<!-- From about-assets.md, appended by scripts/notices.sh. -->
|
||||||
|
|
||||||
The user interface bundles these assets (in crates/voelin-ui):
|
The user interface bundles these assets (in crates/voelin-ui, the Twemoji
|
||||||
|
archive in crates/voelin-ui-vm):
|
||||||
|
|
||||||
- Inter (the UI font), Copyright (c) 2016 The Inter Project Authors, under
|
- Inter (the UI font), Copyright (c) 2016 The Inter Project Authors, under
|
||||||
the SIL Open Font License 1.1 (OFL-1.1; text below).
|
the SIL Open Font License 1.1 (OFL-1.1; text below).
|
||||||
|
|||||||
+2
-1
@@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
<!-- From about-assets.md, appended by scripts/notices.sh. -->
|
<!-- From about-assets.md, appended by scripts/notices.sh. -->
|
||||||
|
|
||||||
The user interface bundles these assets (in crates/voelin-ui):
|
The user interface bundles these assets (in crates/voelin-ui, the Twemoji
|
||||||
|
archive in crates/voelin-ui-vm):
|
||||||
|
|
||||||
- Inter (the UI font), Copyright (c) 2016 The Inter Project Authors, under
|
- Inter (the UI font), Copyright (c) 2016 The Inter Project Authors, under
|
||||||
the SIL Open Font License 1.1 (OFL-1.1; text below).
|
the SIL Open Font License 1.1 (OFL-1.1; text below).
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
[package]
|
||||||
|
name = "voelin-ui-vm"
|
||||||
|
version = "0.0.1-alpha"
|
||||||
|
description = "Toolkit-free view models of the desktop client: engine state turned into plain rows, shared by the Slint and GPUI front ends."
|
||||||
|
edition.workspace = true
|
||||||
|
rust-version.workspace = true
|
||||||
|
license.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
publish.workspace = true
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "voelin_ui_vm"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
|
# No UI toolkit here (no slint, no gpui): `cargo tree -p voelin-ui-vm -e normal`
|
||||||
|
# must show neither. The front ends convert these types (docs/ui.md).
|
||||||
|
[dependencies]
|
||||||
|
chrono = { version = "0.4.45", default-features = false, features = ["clock"] }
|
||||||
|
# Picture sizes (the header of a file); PNG and JPEG are listed as the
|
||||||
|
# front end's toolkit used to bring them.
|
||||||
|
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "gif", "webp", "bmp", "ico"] }
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
# JSON values of the settings and the gateway's configuration keys.
|
||||||
|
serde_json = "1"
|
||||||
|
# The Twemoji archive's blocks (raw deflate).
|
||||||
|
miniz_oxide = "0.8"
|
||||||
|
# Grapheme clusters for emoji in chat text.
|
||||||
|
unicode-segmentation = "1.13"
|
||||||
|
voelin-audio = { path = "../voelin-audio", default-features = false }
|
||||||
|
voelin-core = { path = "../voelin-core", default-features = false, features = ["media"] }
|
||||||
|
voelin-gateway-proto = { path = "../voelin-gateway-proto" }
|
||||||
|
voelin-model = { path = "../voelin-model" }
|
||||||
|
voelin-store = { path = "../voelin-store" }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
png = "0.18"
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Bundled assets
|
||||||
|
|
||||||
|
- `twemoji.bin`: the Twemoji 15.0 SVGs (3720 emoji, from the `@twemoji/svg`
|
||||||
|
15.0.0 package) packed by `scripts/pack-twemoji.py` into blocks of raw
|
||||||
|
deflate with an index; `src/emoji.rs` reads it. Twemoji graphics by Twitter,
|
||||||
|
Inc and other contributors, licensed under CC-BY 4.0
|
||||||
|
(https://creativecommons.org/licenses/by/4.0/). The files are unchanged
|
||||||
|
apart from surrounding whitespace.
|
||||||
|
|
||||||
|
It is credited in `THIRD_PARTY_NOTICES.md` and the About page, with the fonts
|
||||||
|
and icons of the Slint front end (`crates/voelin-ui/assets/README.md`).
|
||||||
File renamed without changes.
@@ -1,8 +1,10 @@
|
|||||||
//! Avatars without pictures: initials on a colour from the name.
|
//! Avatars without pictures: initials on a colour from the name.
|
||||||
|
|
||||||
use slint::Color;
|
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
|
use crate::color::Rgb;
|
||||||
|
use crate::image::{ImageRef, ImageSource};
|
||||||
|
|
||||||
/// Background colours for initials; white text reads on all of them.
|
/// Background colours for initials; white text reads on all of them.
|
||||||
const TINTS: [u32; 10] = [
|
const TINTS: [u32; 10] = [
|
||||||
0x2d6bff, 0x7c4dff, 0xc2379a, 0xe0572e, 0xd08a00, 0x1f9d6b, 0x0c93b8, 0x5865f2, 0xa0439e,
|
0x2d6bff, 0x7c4dff, 0xc2379a, 0xe0572e, 0xd08a00, 0x1f9d6b, 0x0c93b8, 0x5865f2, 0xa0439e,
|
||||||
@@ -31,10 +33,10 @@ pub fn first_letter(initials: &str) -> String {
|
|||||||
initials.graphemes(true).next().unwrap_or_default().to_owned()
|
initials.graphemes(true).next().unwrap_or_default().to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A picture from the engine's cache (an avatar, a group icon), decoded
|
/// A picture from the engine's cache (an avatar, a group icon); none when
|
||||||
/// once; an empty image when there is none.
|
/// there is no path.
|
||||||
pub fn image(path: Option<&std::path::PathBuf>) -> slint::Image {
|
pub fn image(path: Option<&std::path::PathBuf>) -> ImageRef {
|
||||||
path.map(|p| crate::images::file(p)).unwrap_or_default()
|
path.map(ImageSource::file).unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A stable number for a name, in any case (FNV-1a).
|
/// A stable number for a name, in any case (FNV-1a).
|
||||||
@@ -48,12 +50,12 @@ pub fn name_hash(name: &str) -> u32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// `0xrrggbb` as a colour.
|
/// `0xrrggbb` as a colour.
|
||||||
pub fn rgb(rgb: u32) -> Color {
|
pub fn rgb(rgb: u32) -> Rgb {
|
||||||
Color::from_rgb_u8((rgb >> 16) as u8, (rgb >> 8) as u8, rgb as u8)
|
Rgb::from(rgb)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A stable colour for a name.
|
/// A stable colour for a name.
|
||||||
pub fn tint(name: &str) -> Color {
|
pub fn tint(name: &str) -> Rgb {
|
||||||
rgb(TINTS[(name_hash(name) % TINTS.len() as u32) as usize])
|
rgb(TINTS[(name_hash(name) % TINTS.len() as u32) as usize])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,10 +88,7 @@ mod tests {
|
|||||||
fn tints_are_stable() {
|
fn tints_are_stable() {
|
||||||
assert_eq!(tint("Alice"), tint("alice"));
|
assert_eq!(tint("Alice"), tint("alice"));
|
||||||
let distinct: std::collections::HashSet<_> =
|
let distinct: std::collections::HashSet<_> =
|
||||||
["Alice", "Bob", "Carol", "Dave", "Eve", "Mallory"]
|
["Alice", "Bob", "Carol", "Dave", "Eve", "Mallory"].iter().map(|n| tint(n).0).collect();
|
||||||
.iter()
|
|
||||||
.map(|n| tint(n).as_argb_encoded())
|
|
||||||
.collect();
|
|
||||||
assert!(distinct.len() > 2);
|
assert!(distinct.len() > 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File renamed without changes.
@@ -0,0 +1,934 @@
|
|||||||
|
//! The bridge structs: the rows and forms the screens show, as plain
|
||||||
|
//! values. They mirror the Slint structs of `crates/voelin-ui/ui/bridge.slint`
|
||||||
|
//! field by field (strings are shared `Arc<str>`, pictures [`ImageRef`],
|
||||||
|
//! colours [`Rgb`], lists `Vec`); the Slint crate converts them
|
||||||
|
//! (`bind/convert.rs`), the GPUI client will render them as they are.
|
||||||
|
//! `MytsBadge` and `MytsForm` (account screens without a data source in this
|
||||||
|
//! build) stay in Slint.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::color::Rgb;
|
||||||
|
use crate::image::ImageRef;
|
||||||
|
|
||||||
|
/// A row or form of the bridge (the plain counterpart of the Slint struct `ServerItem`).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct ServerItem {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub address: Arc<str>,
|
||||||
|
/// "offline", "connecting", "observing" or "connected"
|
||||||
|
pub status: Arc<str>,
|
||||||
|
/// Avatar of a server without an icon.
|
||||||
|
pub initials: Arc<str>,
|
||||||
|
pub tint: Rgb,
|
||||||
|
/// The server's icon, empty without one.
|
||||||
|
pub icon: ImageRef,
|
||||||
|
/// Unread messages in its chats.
|
||||||
|
pub unread: i32,
|
||||||
|
/// Someone streams in our channel there.
|
||||||
|
pub live: bool,
|
||||||
|
/// "9 online · 7 channels" while its presence is known, else the address.
|
||||||
|
pub detail: Arc<str>,
|
||||||
|
/// "TeamSpeak 6", "TeamSpeak 3", "" before it was reached.
|
||||||
|
pub product: Arc<str>,
|
||||||
|
/// Gateway or query credentials: presence without joining.
|
||||||
|
pub gateway: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A row or form of the bridge (the plain counterpart of the Slint struct `TreeItem`).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct TreeItem {
|
||||||
|
pub is_channel: bool,
|
||||||
|
/// A TeamSpeak spacer channel, its name without the `[cspacer1]` part:
|
||||||
|
/// 0 none, 1 left, 2 centred, 3 right, 4 a line (the name repeats its
|
||||||
|
/// pattern across the row).
|
||||||
|
pub spacer: i32,
|
||||||
|
pub depth: i32,
|
||||||
|
pub id: i32,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub own: bool,
|
||||||
|
pub talking: bool,
|
||||||
|
pub muted: bool,
|
||||||
|
pub sound_off: bool,
|
||||||
|
pub away: bool,
|
||||||
|
pub streaming: bool,
|
||||||
|
pub locked: bool,
|
||||||
|
pub collapsed: bool,
|
||||||
|
/// Local playback of this client: muted, or its volume in percent
|
||||||
|
/// (100 = unchanged).
|
||||||
|
pub local_muted: bool,
|
||||||
|
pub local_volume: i32,
|
||||||
|
/// Our own client.
|
||||||
|
pub myself: bool,
|
||||||
|
/// Avatar of a client.
|
||||||
|
pub initials: Arc<str>,
|
||||||
|
pub tint: Rgb,
|
||||||
|
/// The client's avatar picture, empty without one.
|
||||||
|
pub avatar: ImageRef,
|
||||||
|
/// Channels: clients inside, and the limit (-1: none).
|
||||||
|
pub members: i32,
|
||||||
|
pub max_members: i32,
|
||||||
|
/// Leading channel icon or trailing client icons, empty where absent: a channel's
|
||||||
|
/// icon; a client's server group icons, its channel group's and its own,
|
||||||
|
/// in that order (the first three).
|
||||||
|
pub icon: ImageRef,
|
||||||
|
pub icon_2: ImageRef,
|
||||||
|
pub icon_3: ImageRef,
|
||||||
|
/// A client's badges (myTeamSpeak), the first three in its order, empty
|
||||||
|
/// where absent; shown after the name.
|
||||||
|
pub badge: ImageRef,
|
||||||
|
pub badge_2: ImageRef,
|
||||||
|
pub badge_3: ImageRef,
|
||||||
|
/// A channel's banner picture (TeamSpeak 6), drawn behind the row;
|
||||||
|
/// Wire sizing metadata; compact decorative backgrounds always cover.
|
||||||
|
pub banner: ImageRef,
|
||||||
|
pub banner_mode: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A client for the members panel (everyone on the server) and the voice
|
||||||
|
/// channel view (our channel).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct MemberItem {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub initials: Arc<str>,
|
||||||
|
pub tint: Rgb,
|
||||||
|
pub avatar: ImageRef,
|
||||||
|
pub talking: bool,
|
||||||
|
pub muted: bool,
|
||||||
|
pub sound_off: bool,
|
||||||
|
pub away: bool,
|
||||||
|
pub streaming: bool,
|
||||||
|
pub myself: bool,
|
||||||
|
/// "Speaking", "Streaming", "Away", ...
|
||||||
|
pub status: Arc<str>,
|
||||||
|
/// The away message, empty without one.
|
||||||
|
pub away_message: Arc<str>,
|
||||||
|
/// The section the row is in (a server group, "In Voice",
|
||||||
|
/// "Streaming"), and the group's icon.
|
||||||
|
pub group: Arc<str>,
|
||||||
|
pub group_icon: ImageRef,
|
||||||
|
/// The first row of its section draws the heading, with the number of
|
||||||
|
/// rows in the section.
|
||||||
|
pub first_in_group: bool,
|
||||||
|
pub group_count: i32,
|
||||||
|
/// Badges: a crown for the server's admin groups.
|
||||||
|
pub admin: bool,
|
||||||
|
/// A moderator group's name, shown as a role next to the name.
|
||||||
|
pub role: Arc<str>,
|
||||||
|
pub priority: bool,
|
||||||
|
pub commander: bool,
|
||||||
|
pub recording: bool,
|
||||||
|
/// Its channel needs more talk power than it has (and it is no
|
||||||
|
/// talker): it cannot speak.
|
||||||
|
pub cannot_talk: bool,
|
||||||
|
/// myTeamSpeak badges, as in `TreeItem`.
|
||||||
|
pub badge: ImageRef,
|
||||||
|
pub badge_2: ImageRef,
|
||||||
|
pub badge_3: ImageRef,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A myTeamSpeak badge on the member card: "Badge" and its GUID for one
|
||||||
|
/// the app does not know; its picture is empty until it is downloaded.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct BadgeItem {
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub description: Arc<str>,
|
||||||
|
pub icon: ImageRef,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The member card over a member row: everything about one client and what
|
||||||
|
/// can be done with them.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct MemberCard {
|
||||||
|
pub open: bool,
|
||||||
|
pub id: i32,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub initials: Arc<str>,
|
||||||
|
pub tint: Rgb,
|
||||||
|
pub avatar: ImageRef,
|
||||||
|
pub status: Arc<str>,
|
||||||
|
pub description: Arc<str>,
|
||||||
|
/// Server groups, one per line.
|
||||||
|
pub groups: Vec<Arc<str>>,
|
||||||
|
/// The badges the client shows (at most three, in its order).
|
||||||
|
pub badges: Vec<BadgeItem>,
|
||||||
|
pub country: Arc<str>,
|
||||||
|
pub talk_power: i32,
|
||||||
|
pub friend: bool,
|
||||||
|
pub blocked: bool,
|
||||||
|
/// Local playback, in percent.
|
||||||
|
pub volume: f32,
|
||||||
|
pub muted: bool,
|
||||||
|
/// The client has a unique id, so contacts and private chats work.
|
||||||
|
pub known: bool,
|
||||||
|
/// The client streams: the card offers to watch it.
|
||||||
|
pub streaming: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A row or form of the bridge (the plain counterpart of the Slint struct `ChatTab`).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct ChatTab {
|
||||||
|
/// "Lobby", "@alice", "Server"
|
||||||
|
pub title: Arc<str>,
|
||||||
|
/// The name alone ("Lobby").
|
||||||
|
pub name: Arc<str>,
|
||||||
|
/// 0 = server chat, 1 = channel chat, 2 = private chat
|
||||||
|
pub kind: i32,
|
||||||
|
pub id: i32,
|
||||||
|
pub unread: i32,
|
||||||
|
/// The channel's topic (channel chats).
|
||||||
|
pub topic: Arc<str>,
|
||||||
|
/// The last message ("Mira: the banner I promised") and its time.
|
||||||
|
pub last: Arc<str>,
|
||||||
|
pub time: Arc<str>,
|
||||||
|
/// The channel's banner picture behind the chat's header (as TreeItem).
|
||||||
|
pub banner: ImageRef,
|
||||||
|
pub banner_mode: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A piece of a chat line: a word in its style, or an emoji shown as an
|
||||||
|
/// image (`emoji` is its Twemoji key, e.g. "1f600"; `text` then holds the
|
||||||
|
/// characters).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct TextRun {
|
||||||
|
pub text: Arc<str>,
|
||||||
|
pub emoji: Arc<str>,
|
||||||
|
pub bold: bool,
|
||||||
|
pub italic: bool,
|
||||||
|
pub underline: bool,
|
||||||
|
pub strike: bool,
|
||||||
|
/// Code: on a background.
|
||||||
|
pub code: bool,
|
||||||
|
/// The author's colour, made readable on each theme; transparent: the
|
||||||
|
/// text's own.
|
||||||
|
pub ink_dark: Option<Rgb>,
|
||||||
|
pub ink_light: Option<Rgb>,
|
||||||
|
/// Where it links to ("": nowhere), and whether its text shows something
|
||||||
|
/// else (a page's name, another address): asked about before it opens.
|
||||||
|
pub link: Arc<str>,
|
||||||
|
pub masked: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A block of a chat line (`vm::bbcode`): its runs, and what it is.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct TextBlock {
|
||||||
|
pub runs: Vec<TextRun>,
|
||||||
|
/// 0 = a line, 1 = a quote's line, 2 = a line of code, 3 = a list item,
|
||||||
|
/// 4 = a rule (no runs)
|
||||||
|
pub kind: i32,
|
||||||
|
/// Who a quote quotes, on its first line.
|
||||||
|
pub caption: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One emoji under a message, with how many put it there.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct ReactionItem {
|
||||||
|
/// The Twemoji key of the first emoji in `text` ("1f389"), for the image.
|
||||||
|
pub key: Arc<str>,
|
||||||
|
pub text: Arc<str>,
|
||||||
|
pub count: i32,
|
||||||
|
/// We reacted with it.
|
||||||
|
pub me: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A file linked in a message (`ChatMessage::file_refs`).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct FileItem {
|
||||||
|
pub name: Arc<str>,
|
||||||
|
/// "2.4 MB", or what the transfer is doing.
|
||||||
|
pub detail: Arc<str>,
|
||||||
|
/// Index of the link in the message (what `download-file` takes).
|
||||||
|
pub index: i32,
|
||||||
|
/// "", "running", "done", "failed"
|
||||||
|
pub state: Arc<str>,
|
||||||
|
/// 0 … 1 while it downloads.
|
||||||
|
pub progress: f32,
|
||||||
|
/// A picture, so the icon differs.
|
||||||
|
pub picture: bool,
|
||||||
|
/// The picture itself, once downloaded: shown inline instead of the card.
|
||||||
|
pub preview: ImageRef,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A row or form of the bridge (the plain counterpart of the Slint struct `ChatLine`).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct ChatLine {
|
||||||
|
/// A handle for this message in its chat, stable while the chat is open
|
||||||
|
/// (the engine's ids do not fit a Slint int).
|
||||||
|
pub key: i32,
|
||||||
|
pub author: Arc<str>,
|
||||||
|
/// The text without formatting, a line per block (shown as it is when
|
||||||
|
/// the message has neither formatting nor emoji, and read out).
|
||||||
|
pub text: Arc<str>,
|
||||||
|
pub time: Arc<str>,
|
||||||
|
/// The text in blocks of styled runs; only filled when it has
|
||||||
|
/// formatting or emoji (`rich`).
|
||||||
|
pub blocks: Vec<TextBlock>,
|
||||||
|
pub rich: bool,
|
||||||
|
/// Only one to three emoji: shown large.
|
||||||
|
pub jumbo: bool,
|
||||||
|
/// Same author as the line before, shortly after: no header.
|
||||||
|
pub continued: bool,
|
||||||
|
pub initials: Arc<str>,
|
||||||
|
pub tint: Rgb,
|
||||||
|
pub avatar: ImageRef,
|
||||||
|
/// From a blocked contact.
|
||||||
|
pub blocked: bool,
|
||||||
|
pub pinned: bool,
|
||||||
|
pub reactions: Vec<ReactionItem>,
|
||||||
|
pub files: Vec<FileItem>,
|
||||||
|
/// The gateway knows this message: it can be pinned, reacted to and
|
||||||
|
/// made into a topic.
|
||||||
|
pub remote: bool,
|
||||||
|
/// The topic it belongs to, "" outside a topic.
|
||||||
|
pub topic: Arc<str>,
|
||||||
|
/// Highlighted after jumping to it from the pins.
|
||||||
|
pub marked: bool,
|
||||||
|
/// The first web address it links to, "" if none.
|
||||||
|
pub link: Arc<str>,
|
||||||
|
/// The first new message: the "New" divider is above it (never
|
||||||
|
/// `continued`).
|
||||||
|
pub unread_start: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A pinned message in the pins drawer.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct PinItem {
|
||||||
|
pub line: ChatLine,
|
||||||
|
/// "pinned by Nova · 12:04"
|
||||||
|
pub by: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A gateway topic (thread).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct TopicItem {
|
||||||
|
pub id: i32,
|
||||||
|
pub title: Arc<str>,
|
||||||
|
pub creator: Arc<str>,
|
||||||
|
/// "12 messages · by Nova"
|
||||||
|
pub detail: Arc<str>,
|
||||||
|
/// "Last active 3 min ago", and whether that was within the hour.
|
||||||
|
pub activity: Arc<str>,
|
||||||
|
pub recent: bool,
|
||||||
|
pub archived: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The server dialog: a bookmark (id -1: a new one) and, from a link, where
|
||||||
|
/// Connect goes.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct BookmarkForm {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub address: Arc<str>,
|
||||||
|
pub nickname: Arc<str>,
|
||||||
|
pub server_password: Arc<str>,
|
||||||
|
/// The server has voice: no Connect.
|
||||||
|
pub connected: bool,
|
||||||
|
/// From a link, not stored with the server: the channel to join (a
|
||||||
|
/// path, or /<id>), its password and a privilege key.
|
||||||
|
pub channel: Arc<str>,
|
||||||
|
pub channel_password: Arc<str>,
|
||||||
|
pub token: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A stream on the server, ours first: a stream can be watched from any
|
||||||
|
/// channel. An empty id: a client that streams, but whose stream is still
|
||||||
|
/// being looked up (it started before we joined, or in another channel).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct StreamItem {
|
||||||
|
pub id: Arc<str>,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub streamer: Arc<str>,
|
||||||
|
/// The streamer's channel when it is not ours; empty in ours.
|
||||||
|
pub channel: Arc<str>,
|
||||||
|
/// The streamer's client id (their avatar in the members).
|
||||||
|
pub streamer_id: i32,
|
||||||
|
/// The streamer's avatar, as the members show it: their picture, or
|
||||||
|
/// their initials on their colour (also the card's picture's colour).
|
||||||
|
pub initials: Arc<str>,
|
||||||
|
pub tint: Rgb,
|
||||||
|
pub avatar: ImageRef,
|
||||||
|
/// How many watch it (the gateway's directory; 0 unknown).
|
||||||
|
pub viewers: i32,
|
||||||
|
pub audio: bool,
|
||||||
|
/// "Screen", "Window", "Camera"; and the announced bitrate ("8 Mbit/s").
|
||||||
|
pub kind: Arc<str>,
|
||||||
|
pub bitrate: Arc<str>,
|
||||||
|
/// Shown in the viewer.
|
||||||
|
pub watching: bool,
|
||||||
|
/// Our own stream.
|
||||||
|
pub own: bool,
|
||||||
|
/// Ours from the Stream Studio: its preview is the card's picture.
|
||||||
|
pub studio: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A viewer of our stream. state: "requested", "connecting" or "connected".
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct ViewerItem {
|
||||||
|
pub client: i32,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub state: Arc<str>,
|
||||||
|
pub message: Arc<str>,
|
||||||
|
/// Their avatar picture, empty without one.
|
||||||
|
pub avatar: ImageRef,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A capture source for the share dialog.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct SourceItem {
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub detail: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A row or form of the bridge (the plain counterpart of the Slint struct `ShareForm`).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct ShareForm {
|
||||||
|
pub source: i32,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
/// Index into the frame rate choices (15, 30, 60, 120, 144, 240, 320).
|
||||||
|
pub fps_index: i32,
|
||||||
|
/// Frames per second as typed; a choice fills it in. Any number above 0.
|
||||||
|
pub fps: Arc<str>,
|
||||||
|
/// Index into the bitrate choices (Auto, 2.5, 4.6, 8, 10, 20, 40, 60
|
||||||
|
/// Mbit/s).
|
||||||
|
pub bitrate_index: i32,
|
||||||
|
/// Video bitrate in kbit/s as typed; a choice fills it in. Empty with
|
||||||
|
/// Auto: from the size and frame rate shared, up to 60 Mbit/s.
|
||||||
|
pub bitrate: Arc<str>,
|
||||||
|
pub audio: bool,
|
||||||
|
pub auto_accept: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A row or form of the bridge (the plain counterpart of the Slint struct `AudioForm`).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct AudioForm {
|
||||||
|
/// 0 = system default, then the devices.
|
||||||
|
pub input_index: i32,
|
||||||
|
pub output_index: i32,
|
||||||
|
/// 0 = push-to-talk, 1 = voice activation, 2 = continuous.
|
||||||
|
pub transmit: i32,
|
||||||
|
/// dBFS.
|
||||||
|
pub vad_threshold: f32,
|
||||||
|
pub echo_cancellation: bool,
|
||||||
|
pub noise_suppression: bool,
|
||||||
|
/// 0 = low ... 3 = very high.
|
||||||
|
pub noise_level: i32,
|
||||||
|
pub auto_gain: bool,
|
||||||
|
/// dB.
|
||||||
|
pub input_gain: f32,
|
||||||
|
/// Percent.
|
||||||
|
pub output_volume: f32,
|
||||||
|
/// Milliseconds.
|
||||||
|
pub playback_buffer: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Local playback settings of one client. volume in percent.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct ClientAudio {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub volume: f32,
|
||||||
|
pub muted: bool,
|
||||||
|
/// The client streams: the dialog offers to watch it.
|
||||||
|
pub streaming: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The appearance settings (`ui.*` keys).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct AppearanceForm {
|
||||||
|
/// "dark", "light" or "system"
|
||||||
|
pub theme: Arc<str>,
|
||||||
|
pub font_scale: f32,
|
||||||
|
/// Pixels.
|
||||||
|
pub narrow_breakpoint: f32,
|
||||||
|
pub image_cache_mb: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A contact (friend, blocked or neutral) and where they are now.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct ContactItem {
|
||||||
|
pub uid: Arc<str>,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub initials: Arc<str>,
|
||||||
|
pub tint: Rgb,
|
||||||
|
pub avatar: ImageRef,
|
||||||
|
/// "friend", "blocked" or "neutral"
|
||||||
|
pub relation: Arc<str>,
|
||||||
|
pub online: bool,
|
||||||
|
pub away: bool,
|
||||||
|
pub streaming: bool,
|
||||||
|
/// What they do: "In Chill Zone", "Streaming", "Away: brb", "Offline".
|
||||||
|
pub status: Arc<str>,
|
||||||
|
/// Where: the server of the first session that sees them, or "Last seen
|
||||||
|
/// 2 h ago on Nightfall Guild".
|
||||||
|
pub place: Arc<str>,
|
||||||
|
/// "12m ago": online since (this run), else when last seen.
|
||||||
|
pub when: Arc<str>,
|
||||||
|
pub note: Arc<str>,
|
||||||
|
/// Local playback in percent.
|
||||||
|
pub volume: f32,
|
||||||
|
pub muted: bool,
|
||||||
|
/// "Contact since 14 Jan 2022".
|
||||||
|
pub since: Arc<str>,
|
||||||
|
/// Every session that sees them: "Nightfall Guild · Chill Zone".
|
||||||
|
pub spots: Vec<Arc<str>>,
|
||||||
|
/// A voice connection sees them: they can be messaged, poked, joined.
|
||||||
|
pub reachable: bool,
|
||||||
|
pub selected: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A live stream on one of our servers (home page).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct LiveItem {
|
||||||
|
/// The session (bookmark id) and the stream (directory or stream id).
|
||||||
|
pub session: i32,
|
||||||
|
pub id: Arc<str>,
|
||||||
|
pub title: Arc<str>,
|
||||||
|
pub streamer: Arc<str>,
|
||||||
|
pub initials: Arc<str>,
|
||||||
|
pub tint: Rgb,
|
||||||
|
pub avatar: ImageRef,
|
||||||
|
pub server: Arc<str>,
|
||||||
|
pub channel: Arc<str>,
|
||||||
|
/// 0: unknown.
|
||||||
|
pub viewers: i32,
|
||||||
|
/// "Screen", "Camera", ...
|
||||||
|
pub kind: Arc<str>,
|
||||||
|
/// The server's colour, for the card's picture.
|
||||||
|
pub backdrop: Rgb,
|
||||||
|
/// In our voice channel: it can be watched at once.
|
||||||
|
pub watchable: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A chat in the recent chats and in the direct messages list.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct ConversationItem {
|
||||||
|
/// Index in Rust's list (what `open-conversation` takes).
|
||||||
|
pub key: i32,
|
||||||
|
/// 0 server chat, 1 channel chat, 2 private chat, 3 offline message.
|
||||||
|
pub kind: i32,
|
||||||
|
pub title: Arc<str>,
|
||||||
|
/// The server's name.
|
||||||
|
pub server: Arc<str>,
|
||||||
|
/// "You: That works!", "Sent a file".
|
||||||
|
pub preview: Arc<str>,
|
||||||
|
/// "11:42", "Yesterday", "Mon", "12 Mar".
|
||||||
|
pub time: Arc<str>,
|
||||||
|
/// "10m ago".
|
||||||
|
pub ago: Arc<str>,
|
||||||
|
pub unread: i32,
|
||||||
|
pub initials: Arc<str>,
|
||||||
|
pub tint: Rgb,
|
||||||
|
pub avatar: ImageRef,
|
||||||
|
pub online: bool,
|
||||||
|
pub selected: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A notification of the bell.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct NoticeItem {
|
||||||
|
pub key: i32,
|
||||||
|
/// "mention", "poke", "message", "event", "friend"
|
||||||
|
pub kind: Arc<str>,
|
||||||
|
pub title: Arc<str>,
|
||||||
|
pub body: Arc<str>,
|
||||||
|
/// "3 min ago"
|
||||||
|
pub time: Arc<str>,
|
||||||
|
pub unread: bool,
|
||||||
|
pub initials: Arc<str>,
|
||||||
|
pub tint: Rgb,
|
||||||
|
pub avatar: ImageRef,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A result of the search (Ctrl+K).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct SearchItem {
|
||||||
|
/// "server", "channel", "person", "contact", "setting"
|
||||||
|
pub kind: Arc<str>,
|
||||||
|
pub title: Arc<str>,
|
||||||
|
pub subtitle: Arc<str>,
|
||||||
|
pub initials: Arc<str>,
|
||||||
|
pub tint: Rgb,
|
||||||
|
pub avatar: ImageRef,
|
||||||
|
/// The first result of a group names it ("Servers", "People", ...).
|
||||||
|
pub header: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Something on our servers: an event, a scheduled stream or server news.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct HappeningItem {
|
||||||
|
/// "event", "stream", "news"
|
||||||
|
pub kind: Arc<str>,
|
||||||
|
pub title: Arc<str>,
|
||||||
|
pub subtitle: Arc<str>,
|
||||||
|
/// "Sat 26 Apr · 19:00"
|
||||||
|
pub when: Arc<str>,
|
||||||
|
pub session: i32,
|
||||||
|
pub id: i32,
|
||||||
|
pub live: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Home's "Continue where you left off": the voice channel we were in last.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct ResumeItem {
|
||||||
|
/// There is one: its server is still a bookmark at the same address.
|
||||||
|
pub shown: bool,
|
||||||
|
pub server_id: i32,
|
||||||
|
pub server: Arc<str>,
|
||||||
|
pub initials: Arc<str>,
|
||||||
|
pub tint: Rgb,
|
||||||
|
pub icon: ImageRef,
|
||||||
|
/// The channel's name as the tree shows it.
|
||||||
|
pub channel: Arc<str>,
|
||||||
|
/// Voice is connected there: the button shows the server; else it
|
||||||
|
/// connects into the channel.
|
||||||
|
pub open: bool,
|
||||||
|
pub connecting: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A scheduled event of a server's gateway.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct EventItem {
|
||||||
|
pub id: i32,
|
||||||
|
pub title: Arc<str>,
|
||||||
|
pub description: Arc<str>,
|
||||||
|
/// The date block: "SAT", "26", "APR".
|
||||||
|
pub weekday: Arc<str>,
|
||||||
|
pub day: Arc<str>,
|
||||||
|
pub month: Arc<str>,
|
||||||
|
/// "Sat 26 Apr, 19:00 – 21:00"
|
||||||
|
pub when: Arc<str>,
|
||||||
|
/// "Raid Night" or "Server-wide".
|
||||||
|
pub place: Arc<str>,
|
||||||
|
/// A scheduled stream: "Exploring the Lands Between · Elden Ring".
|
||||||
|
pub stream: Arc<str>,
|
||||||
|
pub live: bool,
|
||||||
|
pub going: i32,
|
||||||
|
pub maybe: i32,
|
||||||
|
pub not_going: i32,
|
||||||
|
/// "going", "maybe", "not_going" or "".
|
||||||
|
pub rsvp: Arc<str>,
|
||||||
|
pub creator: Arc<str>,
|
||||||
|
/// We may edit and delete it (ours, or we moderate).
|
||||||
|
pub editable: bool,
|
||||||
|
/// "Starts in 15 min", "Started 5 min ago", "".
|
||||||
|
pub soon: Arc<str>,
|
||||||
|
/// "Nova (going)", ...; filled once the event was opened.
|
||||||
|
pub attendees: Vec<Arc<str>>,
|
||||||
|
pub expanded: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The event form (create or edit).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct EventForm {
|
||||||
|
/// -1: a new event.
|
||||||
|
pub id: i32,
|
||||||
|
pub title: Arc<str>,
|
||||||
|
pub description: Arc<str>,
|
||||||
|
/// "2026-10-04 19:00", local time.
|
||||||
|
pub start: Arc<str>,
|
||||||
|
/// Empty: no end.
|
||||||
|
pub end: Arc<str>,
|
||||||
|
/// Index into `event-channels` (0: server-wide).
|
||||||
|
pub channel: i32,
|
||||||
|
pub stream: bool,
|
||||||
|
pub stream_title: Arc<str>,
|
||||||
|
pub game: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An offline message to write (mail the server keeps).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct OfflineForm {
|
||||||
|
/// The peer's unique id and name.
|
||||||
|
pub uid: Arc<str>,
|
||||||
|
pub to: Arc<str>,
|
||||||
|
pub subject: Arc<str>,
|
||||||
|
pub text: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The open direct message: who, and what can be done.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct DmPeer {
|
||||||
|
pub open: bool,
|
||||||
|
pub uid: Arc<str>,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub initials: Arc<str>,
|
||||||
|
pub tint: Rgb,
|
||||||
|
pub avatar: ImageRef,
|
||||||
|
pub online: bool,
|
||||||
|
/// "Online · Nightfall Guild · Chill Zone", "Offline · last seen 2 h ago".
|
||||||
|
pub status: Arc<str>,
|
||||||
|
pub description: Arc<str>,
|
||||||
|
pub groups: Vec<Arc<str>>,
|
||||||
|
pub note: Arc<str>,
|
||||||
|
pub since: Arc<str>,
|
||||||
|
/// Where they are now, or where they were last seen.
|
||||||
|
pub servers: Vec<Arc<str>>,
|
||||||
|
/// Pictures linked in the conversation that are downloaded, newest
|
||||||
|
/// first (at most six; `media-more` counts the others), and the other
|
||||||
|
/// files: name, "2.4 MB · Today at 11:36", picture.
|
||||||
|
pub media: Vec<ImageRef>,
|
||||||
|
pub media_more: i32,
|
||||||
|
pub files: Vec<FileItem>,
|
||||||
|
pub friend: bool,
|
||||||
|
pub blocked: bool,
|
||||||
|
pub volume: f32,
|
||||||
|
pub muted: bool,
|
||||||
|
/// Messages can be sent now (a voice connection that sees them).
|
||||||
|
pub can_send: bool,
|
||||||
|
/// Why not: "Kairo is offline.", "Connect to Nightfall Guild to send."
|
||||||
|
pub notice: Arc<str>,
|
||||||
|
/// The server keeps offline messages: offer one.
|
||||||
|
pub offline: bool,
|
||||||
|
/// Connect with voice to the server of this conversation.
|
||||||
|
pub can_connect: bool,
|
||||||
|
/// The messages come from the store, without a session: read-only.
|
||||||
|
pub stored: bool,
|
||||||
|
/// An offline message is shown instead of the conversation.
|
||||||
|
pub mail: bool,
|
||||||
|
pub mail_subject: Arc<str>,
|
||||||
|
pub mail_text: Arc<str>,
|
||||||
|
pub mail_time: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An identity (Profiles page); never its key.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct IdentityItem {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
/// Unique ids on TeamSpeak 3 and TeamSpeak 6 servers.
|
||||||
|
pub uid: Arc<str>,
|
||||||
|
pub uid6: Arc<str>,
|
||||||
|
pub level: i32,
|
||||||
|
/// The store's default: servers see us as this one unless a bookmark
|
||||||
|
/// names another.
|
||||||
|
pub default: bool,
|
||||||
|
/// Where it came from: "Made in Voelin", "Imported", "Chosen by you".
|
||||||
|
pub origin: Arc<str>,
|
||||||
|
/// Raising its level: the level aimed at and the best one reached (0: no).
|
||||||
|
pub improving: i32,
|
||||||
|
pub reached: i32,
|
||||||
|
/// The bookmarks that use it.
|
||||||
|
pub used_by: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An identity found in another client's files (import).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct FoundIdentity {
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub uid: Arc<str>,
|
||||||
|
pub level: i32,
|
||||||
|
pub source: Arc<str>,
|
||||||
|
/// Already in our identities.
|
||||||
|
pub known: bool,
|
||||||
|
pub picked: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A bookmark and the identity it connects with (Profiles page).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct BookmarkIdentity {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
/// Index into `identity-names` (0: the default identity).
|
||||||
|
pub identity: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Camera, video and stream quality (Voice & Video page).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct VideoForm {
|
||||||
|
/// Index into `cameras`.
|
||||||
|
pub camera: i32,
|
||||||
|
/// 0 none, 1 blur.
|
||||||
|
pub background: i32,
|
||||||
|
/// "auto", "1280x720", ...
|
||||||
|
pub resolution: Arc<str>,
|
||||||
|
/// `stream.fps` as typed.
|
||||||
|
pub fps: Arc<str>,
|
||||||
|
/// auto, vp8, vp9, h264, av1.
|
||||||
|
pub codec: i32,
|
||||||
|
pub hardware: bool,
|
||||||
|
pub mirror: bool,
|
||||||
|
/// everyone, friends, channel, nobody.
|
||||||
|
pub permissions: i32,
|
||||||
|
/// 0 auto, 1 720p, 2 1080p, 3 1440p, -1 other layers.
|
||||||
|
pub quality: i32,
|
||||||
|
/// kbit/s.
|
||||||
|
pub bitrate: f32,
|
||||||
|
/// The camera preview runs.
|
||||||
|
pub preview: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A simulcast layer of our stream (Streaming page); numbers as typed.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct LayerItem {
|
||||||
|
/// "1920x1080", or a scale like "0.5".
|
||||||
|
pub size: Arc<str>,
|
||||||
|
/// Frames per second; "" no cap.
|
||||||
|
pub fps: Arc<str>,
|
||||||
|
/// kbit/s.
|
||||||
|
pub bitrate: Arc<str>,
|
||||||
|
pub min_bitrate: Arc<str>,
|
||||||
|
pub max_bitrate: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An audio source mixed into our stream.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct AudioSourceItem {
|
||||||
|
/// "desktop", "app", "window", "microphone", "synthetic"
|
||||||
|
pub kind: Arc<str>,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub detail: Arc<str>,
|
||||||
|
/// Percent.
|
||||||
|
pub gain: f32,
|
||||||
|
pub muted: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stream defaults (Streaming page).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct StreamingForm {
|
||||||
|
pub fps: Arc<str>,
|
||||||
|
pub bitrate: Arc<str>,
|
||||||
|
/// auto, vp8, vp9, h264, av1.
|
||||||
|
pub codec: i32,
|
||||||
|
/// auto, portal, wlroots, x11.
|
||||||
|
pub capture: i32,
|
||||||
|
pub replay_seconds: Arc<str>,
|
||||||
|
pub replay_memory: Arc<str>,
|
||||||
|
pub recording_dir: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Notification kinds: 0 off, 1 in the app, 2 also on the desktop.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct NotifyForm {
|
||||||
|
pub mentions: i32,
|
||||||
|
pub pokes: i32,
|
||||||
|
pub messages: i32,
|
||||||
|
pub events: i32,
|
||||||
|
pub friends: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Privacy & Safety.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct PrivacyForm {
|
||||||
|
/// 0 hide, 1 show flagged.
|
||||||
|
pub block_mode: i32,
|
||||||
|
/// everyone, friends, nobody.
|
||||||
|
pub messages: i32,
|
||||||
|
pub pokes: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A server's gateway (Integrations page).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct GatewayItem {
|
||||||
|
pub session: i32,
|
||||||
|
pub server: Arc<str>,
|
||||||
|
pub url: Arc<str>,
|
||||||
|
/// "connected", "connecting", "off"
|
||||||
|
pub status: Arc<str>,
|
||||||
|
pub features: Vec<Arc<str>>,
|
||||||
|
pub admin: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A gateway configuration key (gateway administration).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct ConfigItem {
|
||||||
|
pub key: Arc<str>,
|
||||||
|
/// JSON.
|
||||||
|
pub value: Arc<str>,
|
||||||
|
pub source: Arc<str>,
|
||||||
|
pub description: Arc<str>,
|
||||||
|
pub kind: Arc<str>,
|
||||||
|
pub bootstrap: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A gateway permission rule.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct PermItem {
|
||||||
|
pub action: Arc<str>,
|
||||||
|
/// "Everyone", "Server groups 6, 7", "Default: server admins".
|
||||||
|
pub rule: Arc<str>,
|
||||||
|
pub source: Arc<str>,
|
||||||
|
pub everyone: bool,
|
||||||
|
pub server_groups: Arc<str>,
|
||||||
|
pub channel_groups: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A video encoder backend (Integrations page).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct EncoderItem {
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub api: Arc<str>,
|
||||||
|
pub codec: Arc<str>,
|
||||||
|
pub hardware: bool,
|
||||||
|
pub ok: bool,
|
||||||
|
/// Why it does not work, or "used first".
|
||||||
|
pub status: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Any registered setting (Advanced page).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct SettingItem {
|
||||||
|
pub key: Arc<str>,
|
||||||
|
pub doc: Arc<str>,
|
||||||
|
/// JSON.
|
||||||
|
pub value: Arc<str>,
|
||||||
|
/// "set here", "command line", "config file", "default".
|
||||||
|
pub source: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A recording or clip of the Stream Studio (Library).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct RecordingItem {
|
||||||
|
pub name: Arc<str>,
|
||||||
|
/// "12.3 MB · 3 Oct 18:04".
|
||||||
|
pub detail: Arc<str>,
|
||||||
|
pub clip: bool,
|
||||||
|
pub path: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Encoders, chat history, cache and logs (Advanced page); numbers as typed.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct AdvancedForm {
|
||||||
|
pub encoder: Arc<str>,
|
||||||
|
pub hardware: bool,
|
||||||
|
/// `stream.decoder_backend`, `stream.hardware_decoding`.
|
||||||
|
pub decoder: Arc<str>,
|
||||||
|
pub hardware_decoding: bool,
|
||||||
|
pub store_history: bool,
|
||||||
|
pub history_page: Arc<str>,
|
||||||
|
pub dedupe_ms: Arc<str>,
|
||||||
|
pub retention_days: Arc<str>,
|
||||||
|
pub cache_mb: Arc<str>,
|
||||||
|
pub fetch_images: bool,
|
||||||
|
pub progress_ms: Arc<str>,
|
||||||
|
/// `ui.image_preview_kb`.
|
||||||
|
pub preview_kb: Arc<str>,
|
||||||
|
pub logs: Arc<str>,
|
||||||
|
pub crash_dir: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A row or form of the bridge (the plain counterpart of the Slint struct `AccountForm`).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct AccountForm {
|
||||||
|
pub nickname: Arc<str>,
|
||||||
|
pub identity: Arc<str>,
|
||||||
|
pub uid: Arc<str>,
|
||||||
|
pub uid6: Arc<str>,
|
||||||
|
pub level: i32,
|
||||||
|
pub server: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One emoji of the picker. `text` is what picking it inserts.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct EmojiCell {
|
||||||
|
pub key: Arc<str>,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub text: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A row or form of the bridge (the plain counterpart of the Slint struct `EmojiRow`).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct EmojiRow {
|
||||||
|
pub cells: Vec<EmojiCell>,
|
||||||
|
}
|
||||||
@@ -6,17 +6,17 @@ use std::borrow::Cow;
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use slint::{Color, Image, ModelRc, VecModel};
|
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
use voelin_core::HistoryMessage;
|
use voelin_core::HistoryMessage;
|
||||||
use voelin_model::{ChatMessage, ChatTarget, FileRef, Presence};
|
use voelin_model::{ChatMessage, ChatTarget, FileRef, Presence};
|
||||||
|
|
||||||
use crate::app::{ChatLine, FileItem, ReactionItem, TextBlock, TextRun};
|
use crate::avatar;
|
||||||
|
use crate::bbcode::{self, BlockKind, Doc, Span, Style};
|
||||||
|
use crate::bridge::{ChatLine, FileItem, ReactionItem, TextBlock, TextRun};
|
||||||
|
use crate::color::Rgb;
|
||||||
use crate::emoji;
|
use crate::emoji;
|
||||||
use crate::vm::avatar;
|
use crate::image::ImageRef;
|
||||||
use crate::vm::bbcode::{self, BlockKind, Doc, Span, Style};
|
|
||||||
|
|
||||||
/// Lines of the same author within this time are grouped (no header).
|
/// Lines of the same author within this time are grouped (no header).
|
||||||
const GROUP_MS: i64 = 5 * 60 * 1000;
|
const GROUP_MS: i64 = 5 * 60 * 1000;
|
||||||
@@ -29,6 +29,7 @@ pub struct Previous {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Previous {
|
impl Previous {
|
||||||
|
/// The line `message` is, as the line after it sees it.
|
||||||
pub fn of(message: &ChatMessage) -> Self {
|
pub fn of(message: &ChatMessage) -> Self {
|
||||||
Self { author: message.author_name.clone(), ts_ms: message.ts_ms }
|
Self { author: message.author_name.clone(), ts_ms: message.ts_ms }
|
||||||
}
|
}
|
||||||
@@ -40,7 +41,7 @@ pub struct LineCtx<'a> {
|
|||||||
/// The message's handle in its chat.
|
/// The message's handle in its chat.
|
||||||
pub key: i32,
|
pub key: i32,
|
||||||
/// The author's avatar picture.
|
/// The author's avatar picture.
|
||||||
pub avatar: Image,
|
pub avatar: ImageRef,
|
||||||
/// The gateway takes reactions and pins for this chat.
|
/// The gateway takes reactions and pins for this chat.
|
||||||
pub gateway: bool,
|
pub gateway: bool,
|
||||||
/// Highlighted (jumped to from the pins).
|
/// Highlighted (jumped to from the pins).
|
||||||
@@ -50,7 +51,7 @@ pub struct LineCtx<'a> {
|
|||||||
/// The state of the downloads started from this message, by link index.
|
/// The state of the downloads started from this message, by link index.
|
||||||
pub downloads: Vec<(usize, FileItem)>,
|
pub downloads: Vec<(usize, FileItem)>,
|
||||||
/// Pictures of the links shown inline, by link index.
|
/// Pictures of the links shown inline, by link index.
|
||||||
pub previews: Vec<(usize, Image)>,
|
pub previews: Vec<(usize, ImageRef)>,
|
||||||
/// Pictures on the web in the engine's cache, by address: the `[img]`
|
/// Pictures on the web in the engine's cache, by address: the `[img]`
|
||||||
/// pictures here show as picture cards, the others as links (`None`:
|
/// pictures here show as picture cards, the others as links (`None`:
|
||||||
/// all as links).
|
/// all as links).
|
||||||
@@ -137,7 +138,7 @@ pub fn size_text(bytes: u64) -> String {
|
|||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
struct Body {
|
struct Body {
|
||||||
text: String,
|
text: String,
|
||||||
blocks: ModelRc<TextBlock>,
|
blocks: Vec<TextBlock>,
|
||||||
rich: bool,
|
rich: bool,
|
||||||
jumbo: bool,
|
jumbo: bool,
|
||||||
link: String,
|
link: String,
|
||||||
@@ -152,10 +153,9 @@ struct Read {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// What lines of a chat were built from, by message id, kept between
|
/// What lines of a chat were built from, by message id, kept between
|
||||||
/// refreshes: a message whose text, reactions and cards did not change is
|
/// refreshes: a message whose text did not change is not read again (its
|
||||||
/// not read again and gets the same models (they compare by pointer), so
|
/// BBCode parsed, its blocks and runs split), and builds the same line, so
|
||||||
/// its line compares equal and `list::sync` leaves its row. (Not with an
|
/// the list diff leaves its row.
|
||||||
/// empty picture: Slint's empty `Image` equals nothing, not even itself.)
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct LineCache(RefCell<HashMap<i64, Parts>>);
|
pub struct LineCache(RefCell<HashMap<i64, Parts>>);
|
||||||
|
|
||||||
@@ -166,8 +166,6 @@ struct Parts {
|
|||||||
read: Option<Read>,
|
read: Option<Read>,
|
||||||
/// The body last built, and which pictures were cards then.
|
/// The body last built, and which pictures were cards then.
|
||||||
body: Option<(Vec<bool>, Body)>,
|
body: Option<(Vec<bool>, Body)>,
|
||||||
reactions: (Vec<ReactionItem>, ModelRc<ReactionItem>),
|
|
||||||
files: (Vec<FileItem>, ModelRc<FileItem>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LineCache {
|
impl LineCache {
|
||||||
@@ -190,22 +188,6 @@ fn current<'a>(all: &'a mut HashMap<i64, Parts>, id: i64, rev: i64, text: &str)
|
|||||||
parts
|
parts
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `rows` as a model: the one in `kept` when they are the same rows.
|
|
||||||
fn model_of<T: Clone + PartialEq + 'static>(
|
|
||||||
rows: Vec<T>,
|
|
||||||
kept: Option<&mut (Vec<T>, ModelRc<T>)>,
|
|
||||||
) -> ModelRc<T> {
|
|
||||||
match kept {
|
|
||||||
Some((old, model)) if *old == rows => model.clone(),
|
|
||||||
Some(kept) => {
|
|
||||||
let model = ModelRc::from(Rc::new(VecModel::from(rows.clone())));
|
|
||||||
*kept = (rows, model.clone());
|
|
||||||
model
|
|
||||||
}
|
|
||||||
None => ModelRc::from(Rc::new(VecModel::from(rows))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A link to a channel's file, which the chat shows as a card.
|
/// A link to a channel's file, which the chat shows as a card.
|
||||||
fn is_file(address: &str) -> bool {
|
fn is_file(address: &str) -> bool {
|
||||||
FileRef::parse(address).is_some()
|
FileRef::parse(address).is_some()
|
||||||
@@ -236,11 +218,13 @@ pub fn web_pictures(text: &str) -> Vec<String> {
|
|||||||
|
|
||||||
/// The colours of a span: the author's made readable on the dark and the
|
/// The colours of a span: the author's made readable on the dark and the
|
||||||
/// light theme, or transparent for the text's own.
|
/// light theme, or transparent for the text's own.
|
||||||
fn inks(color: Option<[u8; 3]>) -> (Color, Color) {
|
fn inks(color: Option<[u8; 3]>) -> (Option<Rgb>, Option<Rgb>) {
|
||||||
let rgb = |[r, g, b]: [u8; 3]| Color::from_rgb_u8(r, g, b);
|
|
||||||
match color {
|
match color {
|
||||||
Some(c) => (rgb(bbcode::readable(c, true)), rgb(bbcode::readable(c, false))),
|
Some(c) => (
|
||||||
None => (Color::default(), Color::default()),
|
Some(Rgb::from(bbcode::readable(c, true))),
|
||||||
|
Some(Rgb::from(bbcode::readable(c, false))),
|
||||||
|
),
|
||||||
|
None => (None, None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,7 +235,7 @@ fn run(
|
|||||||
emoji: Option<String>,
|
emoji: Option<String>,
|
||||||
style: &Style,
|
style: &Style,
|
||||||
masked: bool,
|
masked: bool,
|
||||||
inks: (Color, Color),
|
inks: (Option<Rgb>, Option<Rgb>),
|
||||||
) -> TextRun {
|
) -> TextRun {
|
||||||
TextRun {
|
TextRun {
|
||||||
text: text.into(),
|
text: text.into(),
|
||||||
@@ -356,11 +340,7 @@ fn blocks_of(doc: &Doc) -> Option<(Vec<TextBlock>, bool)> {
|
|||||||
if count > bbcode::MAX_RUNS {
|
if count > bbcode::MAX_RUNS {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
blocks.push(TextBlock {
|
blocks.push(TextBlock { runs, kind, caption: caption.into() });
|
||||||
runs: ModelRc::from(Rc::new(VecModel::from(runs))),
|
|
||||||
kind,
|
|
||||||
caption: caption.into(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some((blocks, any_emoji))
|
Some((blocks, any_emoji))
|
||||||
@@ -388,19 +368,13 @@ fn body_of(doc: &Doc, cards: &[bool]) -> Body {
|
|||||||
let rich = !doc.is_plain() || words.iter().any(|w| w.emoji.is_some());
|
let rich = !doc.is_plain() || words.iter().any(|w| w.emoji.is_some());
|
||||||
// Past the runs a line can have: its plain text.
|
// Past the runs a line can have: its plain text.
|
||||||
match rich.then(|| blocks_of(&doc)).flatten() {
|
match rich.then(|| blocks_of(&doc)).flatten() {
|
||||||
Some((blocks, _)) => Body {
|
Some((blocks, _)) => Body { text, blocks, rich: true, jumbo, link },
|
||||||
text,
|
None => Body { text, blocks: Vec::new(), rich: false, jumbo, link },
|
||||||
blocks: ModelRc::from(Rc::new(VecModel::from(blocks))),
|
|
||||||
rich: true,
|
|
||||||
jumbo,
|
|
||||||
link,
|
|
||||||
},
|
|
||||||
None => Body { text, blocks: ModelRc::default(), rich: false, jumbo, link },
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The picture at `url`, if the engine has it and it can be shown.
|
/// The picture at `url`, if the engine has it and it can be shown.
|
||||||
fn picture(pictures: Option<&HashMap<String, PathBuf>>, url: &str) -> Option<Image> {
|
fn picture(pictures: Option<&HashMap<String, PathBuf>>, url: &str) -> Option<ImageRef> {
|
||||||
let image = avatar::image(pictures?.get(url));
|
let image = avatar::image(pictures?.get(url));
|
||||||
(image.size().width > 0).then_some(image)
|
(image.size().width > 0).then_some(image)
|
||||||
}
|
}
|
||||||
@@ -417,7 +391,7 @@ pub fn tab_title(presence: &Presence, target: &ChatTarget, peer: &str) -> String
|
|||||||
match target {
|
match target {
|
||||||
ChatTarget::Channel(cid) => presence.channels.get(cid).map_or_else(
|
ChatTarget::Channel(cid) => presence.channels.get(cid).map_or_else(
|
||||||
|| format!("Channel {cid}"),
|
|| format!("Channel {cid}"),
|
||||||
|c| crate::vm::tree::channel_title(c).0.to_owned(),
|
|c| crate::tree::channel_title(c).0.to_owned(),
|
||||||
),
|
),
|
||||||
ChatTarget::Private(_) => format!("@{peer}"),
|
ChatTarget::Private(_) => format!("@{peer}"),
|
||||||
ChatTarget::Server => "Server".into(),
|
ChatTarget::Server => "Server".into(),
|
||||||
@@ -469,7 +443,7 @@ pub fn preview(message: &ChatMessage) -> (String, String) {
|
|||||||
std::iter::once(read.doc.one_line()).chain(names).collect::<Vec<_>>().join(" ")
|
std::iter::once(read.doc.one_line()).chain(names).collect::<Vec<_>>().join(" ")
|
||||||
};
|
};
|
||||||
// A one-line text cannot show emoji (they are pictures): left out.
|
// A one-line text cannot show emoji (they are pictures): left out.
|
||||||
let mut text = crate::vm::social::without_emoji(&text);
|
let mut text = crate::social::without_emoji(&text);
|
||||||
if text.is_empty() {
|
if text.is_empty() {
|
||||||
text = "sent an emoji".into();
|
text = "sent an emoji".into();
|
||||||
}
|
}
|
||||||
@@ -560,12 +534,11 @@ fn line_of(
|
|||||||
&& previous.is_some_and(|p| {
|
&& previous.is_some_and(|p| {
|
||||||
p.author == message.author_name && (0..GROUP_MS).contains(&(message.ts_ms - p.ts_ms))
|
p.author == message.author_name && (0..GROUP_MS).contains(&(message.ts_ms - p.ts_ms))
|
||||||
});
|
});
|
||||||
let cached = parts.is_some();
|
|
||||||
let mut own = Parts::default();
|
let mut own = Parts::default();
|
||||||
let parts = parts.unwrap_or(&mut own);
|
let parts = parts.unwrap_or(&mut own);
|
||||||
let read = parts.read.get_or_insert_with(|| read(message));
|
let read = parts.read.get_or_insert_with(|| read(message));
|
||||||
// Pictures on the web that are here are cards, after the files'.
|
// Pictures on the web that are here are cards, after the files'.
|
||||||
let pictures: Vec<Option<Image>> =
|
let pictures: Vec<Option<ImageRef>> =
|
||||||
read.images.iter().map(|url| picture(ctx.pictures, url)).collect();
|
read.images.iter().map(|url| picture(ctx.pictures, url)).collect();
|
||||||
let shown: Vec<bool> = pictures.iter().map(Option::is_some).collect();
|
let shown: Vec<bool> = pictures.iter().map(Option::is_some).collect();
|
||||||
let body = match &parts.body {
|
let body = match &parts.body {
|
||||||
@@ -612,8 +585,6 @@ fn line_of(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let files = model_of(cards, cached.then_some(&mut parts.files));
|
|
||||||
let reactions = model_of(reactions, cached.then_some(&mut parts.reactions));
|
|
||||||
ChatLine {
|
ChatLine {
|
||||||
key: ctx.key,
|
key: ctx.key,
|
||||||
author: message.author_name.clone().into(),
|
author: message.author_name.clone().into(),
|
||||||
@@ -629,7 +600,7 @@ fn line_of(
|
|||||||
blocked: message.blocked,
|
blocked: message.blocked,
|
||||||
pinned: false,
|
pinned: false,
|
||||||
reactions,
|
reactions,
|
||||||
files,
|
files: cards,
|
||||||
remote: false,
|
remote: false,
|
||||||
topic: ctx.topic.clone().into(),
|
topic: ctx.topic.clone().into(),
|
||||||
marked: ctx.marked,
|
marked: ctx.marked,
|
||||||
@@ -645,6 +616,7 @@ pub fn picture_link(message: &ChatMessage, index: usize) -> Option<String> {
|
|||||||
index.checked_sub(read.files.len()).and_then(|i| read.images.into_iter().nth(i))
|
index.checked_sub(read.files.len()).and_then(|i| read.images.into_iter().nth(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether a file name is a picture's, by its extension.
|
||||||
pub fn is_picture(name: &str) -> bool {
|
pub fn is_picture(name: &str) -> bool {
|
||||||
let lower = name.to_ascii_lowercase();
|
let lower = name.to_ascii_lowercase();
|
||||||
[".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg"].iter().any(|e| lower.ends_with(e))
|
[".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg"].iter().any(|e| lower.ends_with(e))
|
||||||
@@ -652,7 +624,7 @@ pub fn is_picture(name: &str) -> bool {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use slint::Model;
|
use crate::image::ImageSource;
|
||||||
use voelin_core::HistoryMessage;
|
use voelin_core::HistoryMessage;
|
||||||
use voelin_gateway_proto::ReactionCount;
|
use voelin_gateway_proto::ReactionCount;
|
||||||
use voelin_store::MessageSource;
|
use voelin_store::MessageSource;
|
||||||
@@ -690,7 +662,7 @@ mod tests {
|
|||||||
let first = message("Alice", "hi", 1_000_000);
|
let first = message("Alice", "hi", 1_000_000);
|
||||||
let a = line(&first, None);
|
let a = line(&first, None);
|
||||||
assert!(!a.continued);
|
assert!(!a.continued);
|
||||||
assert_eq!(a.initials, "AL");
|
assert_eq!(&*a.initials, "AL");
|
||||||
let prev = Previous::of(&first);
|
let prev = Previous::of(&first);
|
||||||
assert!(line(&message("Alice", "again", 1_060_000), Some(&prev)).continued);
|
assert!(line(&message("Alice", "again", 1_060_000), Some(&prev)).continued);
|
||||||
assert!(!line(&message("Bob", "me", 1_060_000), Some(&prev)).continued);
|
assert!(!line(&message("Bob", "me", 1_060_000), Some(&prev)).continued);
|
||||||
@@ -744,27 +716,27 @@ mod tests {
|
|||||||
|
|
||||||
/// The runs of block `i` of a line, as (text, emoji).
|
/// The runs of block `i` of a line, as (text, emoji).
|
||||||
fn runs(line: &ChatLine, i: usize) -> Vec<TextRun> {
|
fn runs(line: &ChatLine, i: usize) -> Vec<TextRun> {
|
||||||
line.blocks.row_data(i).unwrap().runs.iter().collect()
|
line.blocks[i].runs.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn emoji_runs() {
|
fn emoji_runs() {
|
||||||
let plain = line(&message("A", "no emoji here\nnor here", 0), None);
|
let plain = line(&message("A", "no emoji here\nnor here", 0), None);
|
||||||
assert!(!plain.rich && plain.blocks.row_count() == 0);
|
assert!(!plain.rich && plain.blocks.is_empty());
|
||||||
assert_eq!(plain.text, "no emoji here\nnor here");
|
assert_eq!(&*plain.text, "no emoji here\nnor here");
|
||||||
let rich = line(&message("A", "gg 🎉", 0), None);
|
let rich = line(&message("A", "gg 🎉", 0), None);
|
||||||
assert!(rich.rich && !rich.jumbo);
|
assert!(rich.rich && !rich.jumbo);
|
||||||
assert_eq!(rich.blocks.row_count(), 1);
|
assert_eq!(rich.blocks.len(), 1);
|
||||||
let r = runs(&rich, 0);
|
let r = runs(&rich, 0);
|
||||||
assert_eq!((r.len(), r[0].text.as_str(), r[1].emoji.as_str()), (2, "gg ", "1f389"));
|
assert_eq!((r.len(), r[0].text.as_ref(), r[1].emoji.as_ref()), (2, "gg ", "1f389"));
|
||||||
assert!(line(&message("A", "🎉", 0), None).jumbo);
|
assert!(line(&message("A", "🎉", 0), None).jumbo);
|
||||||
// Formatting around it: still large.
|
// Formatting around it: still large.
|
||||||
let jumbo = line(&message("A", "[b]🎉[/b]", 0), None);
|
let jumbo = line(&message("A", "[b]🎉[/b]", 0), None);
|
||||||
assert!(jumbo.rich && jumbo.jumbo);
|
assert!(jumbo.rich && jumbo.jumbo);
|
||||||
// Lines stay lines with emoji (they were run together).
|
// Lines stay lines with emoji (they were run together).
|
||||||
let lines = line(&message("A", "first 🎉\nsecond", 0), None);
|
let lines = line(&message("A", "first 🎉\nsecond", 0), None);
|
||||||
assert_eq!(lines.blocks.row_count(), 2);
|
assert_eq!(lines.blocks.len(), 2);
|
||||||
assert_eq!(lines.text, "first 🎉\nsecond");
|
assert_eq!(&*lines.text, "first 🎉\nsecond");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -775,10 +747,10 @@ mod tests {
|
|||||||
let line = line(&message("A", text, 0), None);
|
let line = line(&message("A", text, 0), None);
|
||||||
assert!(line.rich && !line.jumbo);
|
assert!(line.rich && !line.jumbo);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
line.text,
|
&*line.text,
|
||||||
"Raid at 8, see https://x.org/raid\n> Nova: bring elixirs\n• one\n• two\n---\na\n\nb"
|
"Raid at 8, see https://x.org/raid\n> Nova: bring elixirs\n• one\n• two\n---\na\n\nb"
|
||||||
);
|
);
|
||||||
assert_eq!(line.link, "https://x.org/raid");
|
assert_eq!(&*line.link, "https://x.org/raid");
|
||||||
let kinds: Vec<(i32, String)> =
|
let kinds: Vec<(i32, String)> =
|
||||||
line.blocks.iter().map(|b| (b.kind, b.caption.to_string())).collect();
|
line.blocks.iter().map(|b| (b.kind, b.caption.to_string())).collect();
|
||||||
let kind = |k: i32| (k, String::new());
|
let kind = |k: i32| (k, String::new());
|
||||||
@@ -787,15 +759,15 @@ mod tests {
|
|||||||
[kind(0), (1, "Nova".into()), kind(3), kind(3), kind(4), kind(2), kind(2), kind(2)]
|
[kind(0), (1, "Nova".into()), kind(3), kind(3), kind(4), kind(2), kind(2), kind(2)]
|
||||||
);
|
);
|
||||||
let first = runs(&line, 0);
|
let first = runs(&line, 0);
|
||||||
assert!(first[0].bold && first[0].text == "Raid");
|
assert!(first[0].bold && &*first[0].text == "Raid");
|
||||||
let eight = first.iter().find(|r| r.text.starts_with('8')).unwrap();
|
let eight = first.iter().find(|r| r.text.starts_with('8')).unwrap();
|
||||||
// The author's red, readable on both themes.
|
// The author's red, readable on both themes.
|
||||||
assert!(eight.ink_dark.alpha() == 255 && eight.ink_light.alpha() == 255);
|
let (dark, light) = (eight.ink_dark.unwrap(), eight.ink_light.unwrap());
|
||||||
assert!(eight.ink_dark.red() > eight.ink_dark.green());
|
assert!(dark.r() > dark.g() && light.r() > light.g());
|
||||||
assert_eq!(first[0].ink_dark.alpha(), 0, "the text's own colour");
|
assert_eq!(first[0].ink_dark, None, "the text's own colour");
|
||||||
let address = first.iter().find(|r| !r.link.is_empty()).unwrap();
|
let address = first.iter().find(|r| !r.link.is_empty()).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(address.text.as_str(), address.link.as_str()),
|
(address.text.as_ref(), address.link.as_ref()),
|
||||||
("https://x.org/raid", "https://x.org/raid")
|
("https://x.org/raid", "https://x.org/raid")
|
||||||
);
|
);
|
||||||
assert!(!address.masked, "its own address");
|
assert!(!address.masked, "its own address");
|
||||||
@@ -807,10 +779,10 @@ mod tests {
|
|||||||
// Inline code: one run.
|
// Inline code: one run.
|
||||||
let inline = super::line(&message("A", "run [code]/pull 10[/code]", 0), None);
|
let inline = super::line(&message("A", "run [code]/pull 10[/code]", 0), None);
|
||||||
let r = runs(&inline, 0);
|
let r = runs(&inline, 0);
|
||||||
assert!(r[1].code && r[1].text == "/pull 10");
|
assert!(r[1].code && &*r[1].text == "/pull 10");
|
||||||
// Not formatting: plain.
|
// Not formatting: plain.
|
||||||
let relayed = super::line(&message("A", "[Nova] hi [1]", 0), None);
|
let relayed = super::line(&message("A", "[Nova] hi [1]", 0), None);
|
||||||
assert!(!relayed.rich && relayed.text == "[Nova] hi [1]" && relayed.link.is_empty());
|
assert!(!relayed.rich && &*relayed.text == "[Nova] hi [1]" && relayed.link.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A link whose text is not its address asks before it opens: each of
|
/// A link whose text is not its address asks before it opens: each of
|
||||||
@@ -916,15 +888,15 @@ mod tests {
|
|||||||
let url = format!("https://x.org/{}", "a".repeat(40));
|
let url = format!("https://x.org/{}", "a".repeat(40));
|
||||||
let line = line(&message("A", &format!("see {url}"), 0), None);
|
let line = line(&message("A", &format!("see {url}"), 0), None);
|
||||||
let r = runs(&line, 0);
|
let r = runs(&line, 0);
|
||||||
let pieces: Vec<&str> = r[1..].iter().map(|r| r.text.as_str()).collect();
|
let pieces: Vec<&str> = r[1..].iter().map(|r| r.text.as_ref()).collect();
|
||||||
assert_eq!(pieces.concat(), url);
|
assert_eq!(pieces.concat(), url);
|
||||||
assert!(pieces.len() == 3 && pieces.iter().all(|p| p.chars().count() <= LONG_WORD));
|
assert!(pieces.len() == 3 && pieces.iter().all(|p| p.chars().count() <= LONG_WORD));
|
||||||
assert!(r[1..].iter().all(|r| r.link == url.as_str()));
|
assert!(r[1..].iter().all(|r| &*r.link == url.as_str()));
|
||||||
let code = "cargo build --release --locked -j 1";
|
let code = "cargo build --release --locked -j 1";
|
||||||
let line = super::line(&message("A", &format!("[code]{code}[/code]"), 0), None);
|
let line = super::line(&message("A", &format!("[code]{code}[/code]"), 0), None);
|
||||||
let r = runs(&line, 0);
|
let r = runs(&line, 0);
|
||||||
assert!(r.len() > 1 && r.iter().all(|r| r.code));
|
assert!(r.len() > 1 && r.iter().all(|r| r.code));
|
||||||
assert_eq!(r.iter().map(|r| r.text.as_str()).collect::<String>(), code);
|
assert_eq!(r.iter().map(|r| r.text.as_ref()).collect::<String>(), code);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -933,9 +905,9 @@ mod tests {
|
|||||||
let text = format!("loot [img]{url}[/img]");
|
let text = format!("loot [img]{url}[/img]");
|
||||||
// Not here (or not fetched): the address, as a link.
|
// Not here (or not fetched): the address, as a link.
|
||||||
let link = line(&message("A", &text, 0), None);
|
let link = line(&message("A", &text, 0), None);
|
||||||
assert_eq!(link.files.row_count(), 0);
|
assert_eq!(link.files.len(), 0);
|
||||||
let r = runs(&link, 0);
|
let r = runs(&link, 0);
|
||||||
assert_eq!((r[1].text.as_str(), r[1].link.as_str()), (url, url));
|
assert_eq!((r[1].text.as_ref(), r[1].link.as_ref()), (url, url));
|
||||||
// Here: a picture card after the files, and no address.
|
// Here: a picture card after the files, and no address.
|
||||||
let dir = std::env::temp_dir().join(format!("voelin-chat-picture-{}", std::process::id()));
|
let dir = std::env::temp_dir().join(format!("voelin-chat-picture-{}", std::process::id()));
|
||||||
std::fs::create_dir_all(&dir).unwrap();
|
std::fs::create_dir_all(&dir).unwrap();
|
||||||
@@ -951,10 +923,10 @@ mod tests {
|
|||||||
let stored = stored(message("A", &format!("{text} [URL={file}]plan.pdf[/URL]"), 0));
|
let stored = stored(message("A", &format!("{text} [URL={file}]plan.pdf[/URL]"), 0));
|
||||||
let ctx = LineCtx { pictures: Some(&pictures), ..Default::default() };
|
let ctx = LineCtx { pictures: Some(&pictures), ..Default::default() };
|
||||||
let shown = history_line(&stored, None, &ctx);
|
let shown = history_line(&stored, None, &ctx);
|
||||||
assert_eq!(shown.text, "loot");
|
assert_eq!(&*shown.text, "loot");
|
||||||
assert_eq!(shown.files.row_count(), 2);
|
assert_eq!(shown.files.len(), 2);
|
||||||
let card = shown.files.row_data(1).unwrap();
|
let card = shown.files[1].clone();
|
||||||
assert_eq!((card.name.as_str(), card.index, card.preview.size().width), ("loot.png", 1, 4));
|
assert_eq!((card.name.as_ref(), card.index, card.preview.size().width), ("loot.png", 1, 4));
|
||||||
assert_eq!(picture_link(&stored.message, 1).as_deref(), Some(url));
|
assert_eq!(picture_link(&stored.message, 1).as_deref(), Some(url));
|
||||||
assert_eq!(picture_link(&stored.message, 0), None);
|
assert_eq!(picture_link(&stored.message, 0), None);
|
||||||
assert_eq!(web_pictures(&text), [url]);
|
assert_eq!(web_pictures(&text), [url]);
|
||||||
@@ -962,20 +934,18 @@ mod tests {
|
|||||||
std::fs::remove_dir_all(dir).unwrap();
|
std::fs::remove_dir_all(dir).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A line built again from an unchanged message is equal (its models
|
/// A line built again from an unchanged message is equal (so the list diff
|
||||||
/// are the same), so `list::sync` leaves its row; a change builds anew.
|
/// leaves its row), with the cache or without; a change builds anew.
|
||||||
#[test]
|
#[test]
|
||||||
fn unchanged_lines_compare_equal() {
|
fn unchanged_lines_compare_equal() {
|
||||||
let cache = LineCache::default();
|
let cache = LineCache::default();
|
||||||
// An avatar: an empty picture is never equal.
|
let avatar = ImageSource::rgba(1, 1, vec![0u8; 4]);
|
||||||
let avatar = Image::from_rgba8(slint::SharedPixelBuffer::new(1, 1));
|
|
||||||
let ctx = LineCtx { key: 3, avatar, cache: Some(&cache), ..Default::default() };
|
let ctx = LineCtx { key: 3, avatar, cache: Some(&cache), ..Default::default() };
|
||||||
let mut stored = stored(message("A", "[b]hi[/b] 🎉", 0));
|
let mut stored = stored(message("A", "[b]hi[/b] 🎉", 0));
|
||||||
let first = history_line(&stored, None, &ctx);
|
let first = history_line(&stored, None, &ctx);
|
||||||
assert!(first == history_line(&stored, None, &ctx));
|
assert!(first == history_line(&stored, None, &ctx));
|
||||||
// Without the cache, models are new each time.
|
|
||||||
let plain = LineCtx { key: 3, avatar: ctx.avatar.clone(), ..Default::default() };
|
let plain = LineCtx { key: 3, avatar: ctx.avatar.clone(), ..Default::default() };
|
||||||
assert!(history_line(&stored, None, &plain) != history_line(&stored, None, &plain));
|
assert!(history_line(&stored, None, &plain) == first);
|
||||||
stored.reactions[0].count = 3;
|
stored.reactions[0].count = 3;
|
||||||
let reacted = history_line(&stored, None, &ctx);
|
let reacted = history_line(&stored, None, &ctx);
|
||||||
assert!(reacted != first && reacted.blocks == first.blocks);
|
assert!(reacted != first && reacted.blocks == first.blocks);
|
||||||
@@ -983,7 +953,7 @@ mod tests {
|
|||||||
stored.rev = 2;
|
stored.rev = 2;
|
||||||
let edited = history_line(&stored, None, &ctx);
|
let edited = history_line(&stored, None, &ctx);
|
||||||
assert!(edited.blocks != first.blocks);
|
assert!(edited.blocks != first.blocks);
|
||||||
assert_eq!(edited.text, "edited");
|
assert_eq!(&*edited.text, "edited");
|
||||||
cache.keep([], 0);
|
cache.keep([], 0);
|
||||||
assert_eq!(cache.0.borrow().len(), 1, "few: kept");
|
assert_eq!(cache.0.borrow().len(), 1, "few: kept");
|
||||||
}
|
}
|
||||||
@@ -994,9 +964,9 @@ mod tests {
|
|||||||
let ctx = LineCtx { key: -1, cache: Some(&cache), ..Default::default() };
|
let ctx = LineCtx { key: -1, cache: Some(&cache), ..Default::default() };
|
||||||
let welcome =
|
let welcome =
|
||||||
server_line("Nightfall", "Welcome to [b]Nightfall[/b]!", i64::MIN, false, &ctx);
|
server_line("Nightfall", "Welcome to [b]Nightfall[/b]!", i64::MIN, false, &ctx);
|
||||||
assert_eq!((welcome.author.as_str(), welcome.time.as_str()), ("Nightfall", ""));
|
assert_eq!((welcome.author.as_ref(), welcome.time.as_ref()), ("Nightfall", ""));
|
||||||
assert!(welcome.rich && !welcome.continued && !welcome.remote && welcome.key == -1);
|
assert!(welcome.rich && !welcome.continued && !welcome.remote && welcome.key == -1);
|
||||||
assert_eq!(welcome.text, "Welcome to Nightfall!");
|
assert_eq!(&*welcome.text, "Welcome to Nightfall!");
|
||||||
assert!(server_line("Nightfall", "News", i64::MIN + 1, true, &ctx).continued);
|
assert!(server_line("Nightfall", "News", i64::MIN + 1, true, &ctx).continued);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1005,9 +975,9 @@ mod tests {
|
|||||||
let ctx = LineCtx { key: 4, gateway: true, ..Default::default() };
|
let ctx = LineCtx { key: 4, gateway: true, ..Default::default() };
|
||||||
let line = history_line(&stored(message("A", "hi", 0)), None, &ctx);
|
let line = history_line(&stored(message("A", "hi", 0)), None, &ctx);
|
||||||
assert!(line.pinned && line.remote && line.key == 4);
|
assert!(line.pinned && line.remote && line.key == 4);
|
||||||
assert_eq!(line.reactions.row_count(), 1);
|
assert_eq!(line.reactions.len(), 1);
|
||||||
let r = line.reactions.row_data(0).unwrap();
|
let r = line.reactions[0].clone();
|
||||||
assert_eq!((r.key.as_str(), r.count, r.me), ("1f389", 2, true));
|
assert_eq!((r.key.as_ref(), r.count, r.me), ("1f389", 2, true));
|
||||||
// Without a gateway nothing can be pinned or reacted to.
|
// Without a gateway nothing can be pinned or reacted to.
|
||||||
let plain = history_line(&stored(message("A", "hi", 0)), None, &LineCtx::default());
|
let plain = history_line(&stored(message("A", "hi", 0)), None, &LineCtx::default());
|
||||||
assert!(!plain.remote);
|
assert!(!plain.remote);
|
||||||
@@ -1022,10 +992,10 @@ mod tests {
|
|||||||
format!("here you go {url} 🎉"),
|
format!("here you go {url} 🎉"),
|
||||||
] {
|
] {
|
||||||
let line = line(&message("A", &text, 0), None);
|
let line = line(&message("A", &text, 0), None);
|
||||||
assert_eq!(line.files.row_count(), 1);
|
assert_eq!(line.files.len(), 1);
|
||||||
let file = line.files.row_data(0).unwrap();
|
let file = line.files[0].clone();
|
||||||
assert_eq!((file.name.as_str(), file.detail.as_str()), ("plan.pdf", "2.0 kB"));
|
assert_eq!((file.name.as_ref(), file.detail.as_ref()), ("plan.pdf", "2.0 kB"));
|
||||||
assert_eq!(line.text, "here you go 🎉");
|
assert_eq!(&*line.text, "here you go 🎉");
|
||||||
assert!(line.rich);
|
assert!(line.rich);
|
||||||
}
|
}
|
||||||
// Only the link: no text.
|
// Only the link: no text.
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
//! Colours without a toolkit.
|
||||||
|
|
||||||
|
/// An opaque colour as `0xrrggbb`. Where "no colour" means something (a
|
||||||
|
/// text's own colour), the field is an `Option<Rgb>`.
|
||||||
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||||
|
pub struct Rgb(pub u32);
|
||||||
|
|
||||||
|
impl Rgb {
|
||||||
|
/// The colour with these channels.
|
||||||
|
pub const fn new(r: u8, g: u8, b: u8) -> Self {
|
||||||
|
Self((r as u32) << 16 | (g as u32) << 8 | b as u32)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The red channel.
|
||||||
|
pub const fn r(self) -> u8 {
|
||||||
|
(self.0 >> 16) as u8
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The green channel.
|
||||||
|
pub const fn g(self) -> u8 {
|
||||||
|
(self.0 >> 8) as u8
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The blue channel.
|
||||||
|
pub const fn b(self) -> u8 {
|
||||||
|
self.0 as u8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u32> for Rgb {
|
||||||
|
/// `0xrrggbb`; the top byte is ignored.
|
||||||
|
fn from(rgb: u32) -> Self {
|
||||||
|
Self(rgb & 0x00ff_ffff)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<[u8; 3]> for Rgb {
|
||||||
|
fn from([r, g, b]: [u8; 3]) -> Self {
|
||||||
|
Self::new(r, g, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn channels() {
|
||||||
|
let c = Rgb::from(0x2d6bff);
|
||||||
|
assert_eq!((c.r(), c.g(), c.b()), (0x2d, 0x6b, 0xff));
|
||||||
|
assert_eq!(Rgb::new(0x2d, 0x6b, 0xff), c);
|
||||||
|
assert_eq!(Rgb::from([1, 2, 3]), Rgb(0x010203));
|
||||||
|
assert_eq!(Rgb::from(0xff12_3456), Rgb(0x123456));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -119,12 +119,7 @@ impl Archive {
|
|||||||
.map(|i| &self.entries[i])
|
.map(|i| &self.entries[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Number of emoji in the archive.
|
/// The archive has an emoji for this key (code points joined by `-`).
|
||||||
#[cfg(test)]
|
|
||||||
pub fn len(&self) -> usize {
|
|
||||||
self.entries.len()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn contains(&self, key: &str) -> bool {
|
pub fn contains(&self, key: &str) -> bool {
|
||||||
self.find(key).is_some()
|
self.find(key).is_some()
|
||||||
}
|
}
|
||||||
@@ -350,7 +345,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn archive_opens() {
|
fn archive_opens() {
|
||||||
let a = archive();
|
let a = archive();
|
||||||
assert!(a.len() > 3000);
|
assert!(a.entries.len() > 3000);
|
||||||
assert!(a.contains("1f600"));
|
assert!(a.contains("1f600"));
|
||||||
assert!(!a.contains("zzz"));
|
assert!(!a.contains("zzz"));
|
||||||
assert_eq!(a.name("1f600"), Some("grinning face"));
|
assert_eq!(a.name("1f600"), Some("grinning face"));
|
||||||
File renamed without changes.
@@ -0,0 +1,308 @@
|
|||||||
|
//! Pictures without a toolkit: where a picture comes from, and how large it
|
||||||
|
//! is. A front end turns an [`ImageRef`] into its own image type (Slint's
|
||||||
|
//! `Image` through its decoded-picture cache, GPUI's `img()`).
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::fmt;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
|
/// A picture: shared, cheap to clone, compared by what it is made of.
|
||||||
|
pub type ImageRef = Arc<ImageSource>;
|
||||||
|
|
||||||
|
/// Where a picture comes from.
|
||||||
|
#[derive(Clone, Default, PartialEq, Eq)]
|
||||||
|
pub enum ImageSource {
|
||||||
|
/// No picture.
|
||||||
|
#[default]
|
||||||
|
None,
|
||||||
|
/// A file of the engine's picture cache (`avatars/<md5>`, `icons/<id>`,
|
||||||
|
/// banners): PNG, JPEG, GIF, WebP, BMP, ICO or SVG, told by content, not
|
||||||
|
/// by name. The engine writes a picture that arrives again into the same
|
||||||
|
/// file, so the reference carries the file's [`Stamp`]: a changed file is
|
||||||
|
/// another picture, and a list that shows it redraws the row.
|
||||||
|
File {
|
||||||
|
/// Where the file is.
|
||||||
|
path: PathBuf,
|
||||||
|
/// What the file was when the reference was made.
|
||||||
|
stamp: Stamp,
|
||||||
|
},
|
||||||
|
/// Decoded pixels, 4 bytes per pixel in the order red, green, blue, alpha.
|
||||||
|
Rgba {
|
||||||
|
/// Width in pixels.
|
||||||
|
w: u32,
|
||||||
|
/// Height in pixels.
|
||||||
|
h: u32,
|
||||||
|
/// `w * h * 4` bytes.
|
||||||
|
bytes: Arc<[u8]>,
|
||||||
|
},
|
||||||
|
/// An SVG document.
|
||||||
|
Svg(Arc<[u8]>),
|
||||||
|
/// A picture file held in memory (a chat picture downloaded for its
|
||||||
|
/// preview): the file's bytes, and a key the front end may keep its
|
||||||
|
/// decoded picture under.
|
||||||
|
Memory {
|
||||||
|
/// Names the picture, for caches.
|
||||||
|
key: Arc<str>,
|
||||||
|
/// The file's bytes.
|
||||||
|
bytes: Arc<[u8]>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for ImageSource {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::None => f.write_str("None"),
|
||||||
|
Self::File { path, .. } => f.debug_tuple("File").field(path).finish(),
|
||||||
|
Self::Rgba { w, h, .. } => write!(f, "Rgba({w}x{h})"),
|
||||||
|
Self::Svg(bytes) => write!(f, "Svg({} bytes)", bytes.len()),
|
||||||
|
Self::Memory { key, bytes } => write!(f, "Memory({key}, {} bytes)", bytes.len()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What identifies a file's content without reading it: its length and the
|
||||||
|
/// time it was last written. Both zero for a file that is missing.
|
||||||
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||||
|
pub struct Stamp {
|
||||||
|
len: u64,
|
||||||
|
modified: Option<SystemTime>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Stamp {
|
||||||
|
/// The stamp of the file at `path`.
|
||||||
|
pub fn of(path: &Path) -> Self {
|
||||||
|
std::fs::metadata(path)
|
||||||
|
.map(|meta| Self { len: meta.len(), modified: meta.modified().ok() })
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A picture's size in pixels.
|
||||||
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||||
|
pub struct Size {
|
||||||
|
/// Width, 0 for no picture.
|
||||||
|
pub width: u32,
|
||||||
|
/// Height, 0 for no picture.
|
||||||
|
pub height: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ImageSource {
|
||||||
|
/// A reference to no picture.
|
||||||
|
pub fn none() -> ImageRef {
|
||||||
|
ImageRef::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A reference to a file of the picture cache, as the file is now.
|
||||||
|
pub fn file(path: impl Into<PathBuf>) -> ImageRef {
|
||||||
|
let path = path.into();
|
||||||
|
let stamp = Stamp::of(&path);
|
||||||
|
Arc::new(Self::File { path, stamp })
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A reference to decoded pixels (`bytes`: `w * h * 4`, red, green, blue,
|
||||||
|
/// alpha); no picture if the length does not fit.
|
||||||
|
pub fn rgba(w: u32, h: u32, bytes: impl Into<Arc<[u8]>>) -> ImageRef {
|
||||||
|
let bytes = bytes.into();
|
||||||
|
if bytes.len() as u64 == u64::from(w) * u64::from(h) * 4 {
|
||||||
|
Arc::new(Self::Rgba { w, h, bytes })
|
||||||
|
} else {
|
||||||
|
Self::none()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The size the picture shows with; 0 by 0 when there is none or it can
|
||||||
|
/// not be shown: a file that is missing, is not a picture, or is too
|
||||||
|
/// large to decode (a front end drops those, as it would show nothing).
|
||||||
|
/// A file's size is read from its header, once while it stays as it is;
|
||||||
|
/// a vector picture has none of its own: its stated width and height,
|
||||||
|
/// else 1 by 1.
|
||||||
|
pub fn size(&self) -> Size {
|
||||||
|
match self {
|
||||||
|
Self::None => Size::default(),
|
||||||
|
Self::File { path, stamp } => file_size(path, *stamp),
|
||||||
|
Self::Rgba { w, h, .. } => Size { width: *w, height: *h },
|
||||||
|
Self::Svg(bytes) => svg_size(bytes),
|
||||||
|
Self::Memory { bytes, .. } => bytes_size(bytes),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// There is no picture, or it can not be shown ([`Self::size`]).
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.size().width == 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A picture with more pixels than this (as RGBA bytes) is not decoded.
|
||||||
|
const MAX_DECODED_BYTES: u64 = 128 << 20;
|
||||||
|
|
||||||
|
fn checked(width: u32, height: u32) -> Size {
|
||||||
|
if width == 0 || height == 0 || u64::from(width) * u64::from(height) * 4 > MAX_DECODED_BYTES {
|
||||||
|
Size::default()
|
||||||
|
} else {
|
||||||
|
Size { width, height }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The size of a picture file's bytes, told by content.
|
||||||
|
fn bytes_size(bytes: &[u8]) -> Size {
|
||||||
|
let bytes = bytes.strip_prefix(b"\xef\xbb\xbf").unwrap_or(bytes);
|
||||||
|
let Ok(reader) = image::ImageReader::new(std::io::Cursor::new(bytes)).with_guessed_format()
|
||||||
|
else {
|
||||||
|
return Size::default();
|
||||||
|
};
|
||||||
|
if reader.format().is_none() {
|
||||||
|
return if voelin_core::is_svg(bytes) { svg_size(bytes) } else { Size::default() };
|
||||||
|
}
|
||||||
|
reader.into_dimensions().map_or_else(|_| Size::default(), |(w, h)| checked(w, h))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The number at the start of an attribute's value ("48", "48px", "4.5em").
|
||||||
|
fn number(value: &str) -> Option<u32> {
|
||||||
|
let end = value.find(|c: char| !c.is_ascii_digit() && c != '.').unwrap_or(value.len());
|
||||||
|
value[..end].parse::<f32>().ok().filter(|v| *v >= 1.0).map(|v| v as u32)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The value of `name="…"` in the root tag of an SVG.
|
||||||
|
fn attribute<'a>(tag: &'a str, name: &str) -> Option<&'a str> {
|
||||||
|
let mut rest = tag;
|
||||||
|
while let Some(at) = rest.find(name) {
|
||||||
|
let before = rest[..at].chars().next_back();
|
||||||
|
let after = &rest[at + name.len()..];
|
||||||
|
let after = after.trim_start();
|
||||||
|
if before.is_none_or(char::is_whitespace)
|
||||||
|
&& let Some(value) = after.strip_prefix('=')
|
||||||
|
{
|
||||||
|
let value = value.trim_start();
|
||||||
|
let quote = value.chars().next().filter(|q| matches!(q, '"' | '\''))?;
|
||||||
|
return value[1..].split(quote).next();
|
||||||
|
}
|
||||||
|
rest = &rest[at + name.len()..];
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn svg_size(bytes: &[u8]) -> Size {
|
||||||
|
let text = String::from_utf8_lossy(bytes);
|
||||||
|
let Some(start) = text.find("<svg") else { return Size { width: 1, height: 1 } };
|
||||||
|
let tag = &text[start..];
|
||||||
|
let tag = &tag[..tag.find('>').unwrap_or(tag.len())];
|
||||||
|
let stated =
|
||||||
|
attribute(tag, "width").and_then(number).zip(attribute(tag, "height").and_then(number));
|
||||||
|
let boxed = || {
|
||||||
|
let mut parts = attribute(tag, "viewBox")?.split([' ', ',']).filter(|p| !p.is_empty());
|
||||||
|
let (_, _, w, h) = (parts.next()?, parts.next()?, parts.next()?, parts.next()?);
|
||||||
|
number(w).zip(number(h))
|
||||||
|
};
|
||||||
|
let (width, height) = stated.or_else(boxed).unwrap_or((1, 1));
|
||||||
|
checked(width, height)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What a probe of a file found, and what the file was then.
|
||||||
|
type Probe = (Stamp, Size);
|
||||||
|
|
||||||
|
/// Probed files, so a picture shown in many rows is read once; entries are
|
||||||
|
/// checked against the file's length and time before use.
|
||||||
|
static PROBES: Mutex<Option<HashMap<PathBuf, Probe>>> = Mutex::new(None);
|
||||||
|
|
||||||
|
/// Probes kept at most; the picture cache is far smaller than this.
|
||||||
|
const MAX_PROBES: usize = 4096;
|
||||||
|
|
||||||
|
fn file_size(path: &Path, stamp: Stamp) -> Size {
|
||||||
|
if stamp == Stamp::default() {
|
||||||
|
return Size::default();
|
||||||
|
}
|
||||||
|
let mut guard = PROBES.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
let probes = guard.get_or_insert_with(HashMap::new);
|
||||||
|
if let Some((was, size)) = probes.get(path)
|
||||||
|
&& *was == stamp
|
||||||
|
{
|
||||||
|
return *size;
|
||||||
|
}
|
||||||
|
// The file is read with the lock held; probes are short and rare.
|
||||||
|
let size = std::fs::read(path).map_or_else(|_| Size::default(), |bytes| bytes_size(&bytes));
|
||||||
|
if probes.len() >= MAX_PROBES {
|
||||||
|
probes.clear();
|
||||||
|
}
|
||||||
|
probes.insert(path.to_owned(), (stamp, size));
|
||||||
|
size
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
/// A PNG of `width` by `height` pixels.
|
||||||
|
pub(crate) fn png(width: u32, height: u32) -> Vec<u8> {
|
||||||
|
let mut bytes = Vec::new();
|
||||||
|
let mut encoder = ::png::Encoder::new(&mut bytes, width, height);
|
||||||
|
encoder.set_color(::png::ColorType::Rgba);
|
||||||
|
encoder.set_depth(::png::BitDepth::Eight);
|
||||||
|
let pixels = vec![200; width as usize * height as usize * 4];
|
||||||
|
encoder.write_header().unwrap().write_image_data(&pixels).unwrap();
|
||||||
|
bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
fn temp(name: &str) -> PathBuf {
|
||||||
|
let dir = std::env::temp_dir().join(format!("voelin-ui-vm-{name}-{}", std::process::id()));
|
||||||
|
std::fs::create_dir_all(&dir).unwrap();
|
||||||
|
dir
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pixels_and_nothing() {
|
||||||
|
assert_eq!(ImageSource::none().size(), Size::default());
|
||||||
|
assert!(ImageSource::none().is_empty());
|
||||||
|
let pixels = ImageSource::rgba(2, 3, vec![0u8; 24]);
|
||||||
|
assert_eq!(pixels.size(), Size { width: 2, height: 3 });
|
||||||
|
assert!(!pixels.is_empty());
|
||||||
|
// The wrong length is no picture.
|
||||||
|
assert!(ImageSource::rgba(2, 3, vec![0u8; 23]).is_empty());
|
||||||
|
assert_eq!(format!("{pixels:?}"), "Rgba(2x3)");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn files_by_content() {
|
||||||
|
let dir = temp("files");
|
||||||
|
// No extension: the cache's files have none.
|
||||||
|
let path = dir.join("1234");
|
||||||
|
std::fs::write(&path, png(4, 2)).unwrap();
|
||||||
|
assert_eq!(ImageSource::file(&path).size(), Size { width: 4, height: 2 });
|
||||||
|
let before = ImageSource::file(&path);
|
||||||
|
// A changed file is read again.
|
||||||
|
std::fs::write(&path, png(5, 3)).unwrap();
|
||||||
|
let after = ImageSource::file(&path);
|
||||||
|
assert_eq!(after.size(), Size { width: 5, height: 3 });
|
||||||
|
// The same file, another picture: a list redraws the row.
|
||||||
|
assert_ne!(before, after);
|
||||||
|
assert_eq!(after, ImageSource::file(&path));
|
||||||
|
let junk = dir.join("junk");
|
||||||
|
std::fs::write(&junk, b"not a picture").unwrap();
|
||||||
|
assert!(ImageSource::file(&junk).is_empty());
|
||||||
|
assert!(ImageSource::file(dir.join("missing")).is_empty());
|
||||||
|
std::fs::remove_dir_all(dir).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn vector_pictures() {
|
||||||
|
let size = |svg: &str| ImageSource::Svg(svg.as_bytes().into()).size();
|
||||||
|
assert_eq!(size("<svg width=\"32\" height=\"16\"/>"), Size { width: 32, height: 16 });
|
||||||
|
assert_eq!(size("<svg viewBox='0 0 24 12'/>"), Size { width: 24, height: 12 });
|
||||||
|
assert_eq!(size("<svg xmlns='http://www.w3.org/2000/svg'/>"), Size { width: 1, height: 1 });
|
||||||
|
assert_eq!(size("<svg width=\"4096px\" height=\"4096px\"/>").width, 4096);
|
||||||
|
// Too large to decode.
|
||||||
|
assert!(
|
||||||
|
ImageSource::Svg(b"<svg width=\"99999\" height=\"99999\"/>".as_slice().into())
|
||||||
|
.is_empty()
|
||||||
|
);
|
||||||
|
// An SVG file with a byte order mark and a prolog, and in memory.
|
||||||
|
let svg: &[u8] = b"\xef\xbb\xbf<?xml version=\"1.0\"?><svg width=\"8\" height=\"8\"/>";
|
||||||
|
let dir = temp("svg");
|
||||||
|
std::fs::write(dir.join("icon"), svg).unwrap();
|
||||||
|
assert_eq!(ImageSource::file(dir.join("icon")).size().width, 8);
|
||||||
|
let memory = ImageSource::Memory { key: "k".into(), bytes: png(3, 3).into() };
|
||||||
|
assert_eq!(memory.size(), Size { width: 3, height: 3 });
|
||||||
|
std::fs::remove_dir_all(dir).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
//! Toolkit-free view models of the desktop client: engine state turned into
|
||||||
|
//! plain rows and forms, with the logic that decides what the screens show.
|
||||||
|
//! Neither Slint nor GPUI is a dependency; each front end converts these
|
||||||
|
//! types (docs/ui.md, "Two crates").
|
||||||
|
|
||||||
|
pub mod avatar;
|
||||||
|
pub mod bbcode;
|
||||||
|
pub mod bridge;
|
||||||
|
pub mod chat;
|
||||||
|
pub mod color;
|
||||||
|
pub mod emoji;
|
||||||
|
pub mod home;
|
||||||
|
pub mod image;
|
||||||
|
pub mod list;
|
||||||
|
pub mod servers;
|
||||||
|
pub mod settings;
|
||||||
|
pub mod settings_pages;
|
||||||
|
pub mod social;
|
||||||
|
pub mod state;
|
||||||
|
pub mod streams;
|
||||||
|
pub mod studio;
|
||||||
|
pub mod studio_bridge;
|
||||||
|
pub mod tree;
|
||||||
|
|
||||||
|
pub use color::Rgb;
|
||||||
|
pub use image::{ImageRef, ImageSource, Size};
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
//! Incremental list updates: what changed between two versions of a list,
|
||||||
|
//! as row operations. A front end that keeps a list model (Slint's
|
||||||
|
//! `VecModel`) applies them row by row, so a client that starts talking
|
||||||
|
//! redraws one row of the tree; one that rebuilds from the list (GPUI) just
|
||||||
|
//! re-renders and has no use for them.
|
||||||
|
|
||||||
|
/// One row operation of a [`Changes`].
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
pub enum Change {
|
||||||
|
/// Row `i` holds another value: `new[i]`.
|
||||||
|
Update(usize),
|
||||||
|
/// Row `i` is gone.
|
||||||
|
Remove(usize),
|
||||||
|
/// `new[i]` is a new row, at `i`.
|
||||||
|
Insert(usize),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Row operations that turn the old list into the new one, in the order to
|
||||||
|
/// apply them: updates, then removals (each at the index it has when its
|
||||||
|
/// turn comes), then insertions (in ascending order).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||||
|
pub struct Changes(pub Vec<Change>);
|
||||||
|
|
||||||
|
impl Changes {
|
||||||
|
/// Nothing changed.
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.0.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// How many rows are updated in place.
|
||||||
|
pub fn updated(&self) -> usize {
|
||||||
|
self.0.iter().filter(|c| matches!(c, Change::Update(_))).count()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// How many rows are removed.
|
||||||
|
pub fn removed(&self) -> usize {
|
||||||
|
self.0.iter().filter(|c| matches!(c, Change::Remove(_))).count()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// How many rows are inserted.
|
||||||
|
pub fn inserted(&self) -> usize {
|
||||||
|
self.0.iter().filter(|c| matches!(c, Change::Insert(_))).count()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Apply the changes to `rows` (the old list), which then equals `new`.
|
||||||
|
/// Also the reference for front ends: their models do the same
|
||||||
|
/// operations in the same order.
|
||||||
|
pub fn apply<T: Clone>(&self, rows: &mut Vec<T>, new: &[T]) {
|
||||||
|
for change in &self.0 {
|
||||||
|
match *change {
|
||||||
|
Change::Update(i) => rows[i] = new[i].clone(),
|
||||||
|
Change::Remove(i) => {
|
||||||
|
rows.remove(i);
|
||||||
|
}
|
||||||
|
Change::Insert(i) => rows.insert(i, new[i].clone()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What changes `old` into `new` with few row operations: the rows both
|
||||||
|
/// share at the start and the end stay, rows in between are changed in
|
||||||
|
/// place where they differ, and the rest inserted or removed.
|
||||||
|
pub fn diff<T: PartialEq>(old: &[T], new: &[T]) -> Changes {
|
||||||
|
let min = old.len().min(new.len());
|
||||||
|
let prefix = old.iter().zip(new).take_while(|(a, b)| a == b).count();
|
||||||
|
let suffix = old[prefix..]
|
||||||
|
.iter()
|
||||||
|
.rev()
|
||||||
|
.zip(new[prefix..].iter().rev())
|
||||||
|
.take(min - prefix)
|
||||||
|
.take_while(|(a, b)| a == b)
|
||||||
|
.count();
|
||||||
|
let old_mid = old.len() - prefix - suffix;
|
||||||
|
let new_mid = new.len() - prefix - suffix;
|
||||||
|
let common = old_mid.min(new_mid);
|
||||||
|
let mut changes = Vec::new();
|
||||||
|
for i in prefix..prefix + common {
|
||||||
|
if old[i] != new[i] {
|
||||||
|
changes.push(Change::Update(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let at = prefix + common;
|
||||||
|
changes.extend((new_mid..old_mid).map(|_| Change::Remove(at)));
|
||||||
|
changes.extend((at..at + new_mid.saturating_sub(old_mid)).map(Change::Insert));
|
||||||
|
Changes(changes)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
/// The changes from `old` to `new`; applying them gives `new`.
|
||||||
|
fn run(old: &[i32], new: &[i32]) -> Changes {
|
||||||
|
let changes = diff(old, new);
|
||||||
|
let mut rows = old.to_vec();
|
||||||
|
changes.apply(&mut rows, new);
|
||||||
|
assert_eq!(rows, new, "{old:?} -> {new:?}");
|
||||||
|
changes
|
||||||
|
}
|
||||||
|
|
||||||
|
fn counts(changes: &Changes) -> (usize, usize, usize) {
|
||||||
|
(changes.updated(), changes.inserted(), changes.removed())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn minimal_changes() {
|
||||||
|
assert!(run(&[1, 2, 3], &[1, 2, 3]).is_empty());
|
||||||
|
assert_eq!(run(&[1, 2, 3], &[1, 9, 3]), Changes(vec![Change::Update(1)]));
|
||||||
|
assert_eq!(run(&[1, 2, 3], &[1, 2, 7, 3]), Changes(vec![Change::Insert(2)]));
|
||||||
|
assert_eq!(run(&[1, 2, 3], &[1, 3]), Changes(vec![Change::Remove(1)]));
|
||||||
|
assert_eq!(counts(&run(&[], &[1, 2])), (0, 2, 0));
|
||||||
|
assert_eq!(counts(&run(&[1, 2], &[])), (0, 0, 2));
|
||||||
|
assert_eq!(run(&[1, 2, 3, 4], &[5, 6]).updated(), 2);
|
||||||
|
run(&[1, 1, 1], &[1, 1]);
|
||||||
|
run(&[1, 2, 1], &[1, 1, 2, 1]);
|
||||||
|
run(&[4, 5, 6], &[1, 2, 3, 4, 5, 6, 7]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whatever the lists, applying the changes gives the new list, and
|
||||||
|
/// rows that stay at the ends are not touched.
|
||||||
|
#[test]
|
||||||
|
fn every_small_pair() {
|
||||||
|
let lists: Vec<Vec<i32>> = (0..4usize)
|
||||||
|
.flat_map(|n| (0..3i32.pow(n as u32)).map(move |k| (n, k)))
|
||||||
|
.map(|(n, k)| (0..n as u32).map(|i| (k / 3i32.pow(i)) % 3).collect())
|
||||||
|
.collect();
|
||||||
|
for old in &lists {
|
||||||
|
for new in &lists {
|
||||||
|
let changes = run(old, new);
|
||||||
|
let kept = old.iter().zip(new).take_while(|(a, b)| a == b).count();
|
||||||
|
assert!(changes.0.iter().all(|c| match *c {
|
||||||
|
Change::Update(i) | Change::Remove(i) | Change::Insert(i) => i >= kept,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,19 @@
|
|||||||
//! The server rail, the server dialog, and joining a channel.
|
//! The server rail, the server dialog, and joining a channel.
|
||||||
|
|
||||||
use slint::{Color, SharedString};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use voelin_core::{ObserveState, SessionState, VoiceState};
|
use voelin_core::{ObserveState, SessionState, VoiceState};
|
||||||
use voelin_model::{ChannelId, ChannelInfo, Presence, ServerLink};
|
use voelin_model::{ChannelId, ChannelInfo, Presence, ServerLink};
|
||||||
use voelin_store::Bookmark;
|
use voelin_store::Bookmark;
|
||||||
|
|
||||||
use crate::app::{BookmarkForm, ServerItem};
|
use crate::avatar;
|
||||||
use crate::vm::avatar;
|
use crate::bridge::{BookmarkForm, ServerItem};
|
||||||
|
use crate::color::Rgb;
|
||||||
|
use crate::image::ImageRef;
|
||||||
|
|
||||||
/// Restore a known server icon before any session exists. A missing/evicted
|
/// Restore a known server icon before any session exists. A missing/evicted
|
||||||
/// cache file falls back to initials; the bookmark stores no filesystem path.
|
/// cache file falls back to initials; the bookmark stores no filesystem path.
|
||||||
pub fn cached_icon(bookmark: &Bookmark, cache: &voelin_core::Cache) -> slint::Image {
|
pub fn cached_icon(bookmark: &Bookmark, cache: &voelin_core::Cache) -> ImageRef {
|
||||||
avatar::image(bookmark.server_icon_id().and_then(|id| cache.icon(id)).as_ref())
|
avatar::image(bookmark.server_icon_id().and_then(|id| cache.icon(id)).as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +36,7 @@ const SERVER_TINTS: [u32; 10] = [
|
|||||||
/// when an earlier server has it, it takes the next free one. So no two
|
/// when an earlier server has it, it takes the next free one. So no two
|
||||||
/// share a colour until there are more servers than colours (then they
|
/// share a colour until there are more servers than colours (then they
|
||||||
/// start over), and adding a server leaves the others' colours.
|
/// start over), and adding a server leaves the others' colours.
|
||||||
pub fn tints(bookmarks: &[Bookmark]) -> Vec<Color> {
|
pub fn tints(bookmarks: &[Bookmark]) -> Vec<Rgb> {
|
||||||
let n = SERVER_TINTS.len();
|
let n = SERVER_TINTS.len();
|
||||||
let mut taken = [false; SERVER_TINTS.len()];
|
let mut taken = [false; SERVER_TINTS.len()];
|
||||||
bookmarks
|
bookmarks
|
||||||
@@ -76,8 +79,8 @@ pub fn item(
|
|||||||
live: bool,
|
live: bool,
|
||||||
detail: String,
|
detail: String,
|
||||||
product: String,
|
product: String,
|
||||||
icon: slint::Image,
|
icon: ImageRef,
|
||||||
tint: Color,
|
tint: Rgb,
|
||||||
) -> ServerItem {
|
) -> ServerItem {
|
||||||
ServerItem {
|
ServerItem {
|
||||||
id: bookmark.id as i32,
|
id: bookmark.id as i32,
|
||||||
@@ -106,7 +109,7 @@ pub fn form(
|
|||||||
BookmarkForm {
|
BookmarkForm {
|
||||||
id: bookmark.id as i32,
|
id: bookmark.id as i32,
|
||||||
name: if bookmark.name == bookmark.address {
|
name: if bookmark.name == bookmark.address {
|
||||||
SharedString::new()
|
"".into()
|
||||||
} else {
|
} else {
|
||||||
bookmark.name.clone().into()
|
bookmark.name.clone().into()
|
||||||
},
|
},
|
||||||
@@ -134,7 +137,7 @@ pub struct ConnectTo {
|
|||||||
/// channel; and the link's privilege key.
|
/// channel; and the link's privilege key.
|
||||||
pub fn connect_to(form: &BookmarkForm, saved: Option<&Bookmark>) -> Option<ConnectTo> {
|
pub fn connect_to(form: &BookmarkForm, saved: Option<&Bookmark>) -> Option<ConnectTo> {
|
||||||
let saved = saved?;
|
let saved = saved?;
|
||||||
let given = |text: &SharedString| Some(text.to_string()).filter(|t| !t.is_empty());
|
let given = |text: &Arc<str>| Some(text.to_string()).filter(|t| !t.is_empty());
|
||||||
let channel = given(&form.channel);
|
let channel = given(&form.channel);
|
||||||
Some(ConnectTo {
|
Some(ConnectTo {
|
||||||
channel_password: channel.as_ref().and_then(|_| given(&form.channel_password)),
|
channel_password: channel.as_ref().and_then(|_| given(&form.channel_password)),
|
||||||
@@ -215,7 +218,7 @@ pub fn link_form(
|
|||||||
mut form: BookmarkForm,
|
mut form: BookmarkForm,
|
||||||
default_nickname: &str,
|
default_nickname: &str,
|
||||||
) -> BookmarkForm {
|
) -> BookmarkForm {
|
||||||
let text = |value: &Option<String>| SharedString::from(value.as_deref().unwrap_or_default());
|
let text = |value: &Option<String>| Arc::<str>::from(value.as_deref().unwrap_or_default());
|
||||||
if form.id < 0 {
|
if form.id < 0 {
|
||||||
form.address = link.address().into();
|
form.address = link.address().into();
|
||||||
}
|
}
|
||||||
@@ -223,7 +226,7 @@ pub fn link_form(
|
|||||||
form.nickname = link.nickname.as_deref().unwrap_or(default_nickname).into();
|
form.nickname = link.nickname.as_deref().unwrap_or(default_nickname).into();
|
||||||
}
|
}
|
||||||
if let Some(password) = &link.password {
|
if let Some(password) = &link.password {
|
||||||
form.server_password = password.into();
|
form.server_password = password.as_str().into();
|
||||||
}
|
}
|
||||||
form.channel = text(&link.channel);
|
form.channel = text(&link.channel);
|
||||||
form.channel_password = text(&link.channel_password);
|
form.channel_password = text(&link.channel_password);
|
||||||
@@ -302,9 +305,9 @@ mod tests {
|
|||||||
String::new(),
|
String::new(),
|
||||||
String::new(),
|
String::new(),
|
||||||
cached_icon(&bookmark, &cache),
|
cached_icon(&bookmark, &cache),
|
||||||
Color::default(),
|
Rgb::default(),
|
||||||
);
|
);
|
||||||
assert_eq!(server.status.as_str(), "offline");
|
assert_eq!(server.status.as_ref(), "offline");
|
||||||
assert_eq!(server.icon.size().width, 4);
|
assert_eq!(server.icon.size().width, 4);
|
||||||
bookmark.address = "different.test".into();
|
bookmark.address = "different.test".into();
|
||||||
assert_eq!(cached_icon(&bookmark, &cache).size().width, 0);
|
assert_eq!(cached_icon(&bookmark, &cache).size().width, 0);
|
||||||
@@ -328,12 +331,12 @@ mod tests {
|
|||||||
String::new(),
|
String::new(),
|
||||||
product.into(),
|
product.into(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Color::default(),
|
Rgb::default(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
assert_eq!(on("TeamSpeak 6").product.as_str(), "TeamSpeak 6");
|
assert_eq!(on("TeamSpeak 6").product.as_ref(), "TeamSpeak 6");
|
||||||
// Before the server answered, and for software nobody recognised: none.
|
// Before the server answered, and for software nobody recognised: none.
|
||||||
assert_eq!(on("").product.as_str(), "");
|
assert_eq!(on("").product.as_ref(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn named(names: &[&str]) -> Vec<Bookmark> {
|
fn named(names: &[&str]) -> Vec<Bookmark> {
|
||||||
@@ -341,7 +344,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The colour a name picks.
|
/// The colour a name picks.
|
||||||
fn own_tint(name: &str, step: usize) -> Color {
|
fn own_tint(name: &str, step: usize) -> Rgb {
|
||||||
let n = SERVER_TINTS.len();
|
let n = SERVER_TINTS.len();
|
||||||
avatar::rgb(SERVER_TINTS[(avatar::name_hash(name) as usize + step) % n])
|
avatar::rgb(SERVER_TINTS[(avatar::name_hash(name) as usize + step) % n])
|
||||||
}
|
}
|
||||||
@@ -351,7 +354,7 @@ mod tests {
|
|||||||
let names: Vec<String> = (0..SERVER_TINTS.len()).map(|i| format!("Server {i}")).collect();
|
let names: Vec<String> = (0..SERVER_TINTS.len()).map(|i| format!("Server {i}")).collect();
|
||||||
let mut bookmarks = named(&names.iter().map(String::as_str).collect::<Vec<_>>());
|
let mut bookmarks = named(&names.iter().map(String::as_str).collect::<Vec<_>>());
|
||||||
let distinct: std::collections::HashSet<_> =
|
let distinct: std::collections::HashSet<_> =
|
||||||
tints(&bookmarks).iter().map(|t| t.as_argb_encoded()).collect();
|
tints(&bookmarks).iter().map(|t| t.0).collect();
|
||||||
assert_eq!(distinct.len(), SERVER_TINTS.len());
|
assert_eq!(distinct.len(), SERVER_TINTS.len());
|
||||||
// One more starts over with its name's colour.
|
// One more starts over with its name's colour.
|
||||||
bookmarks.extend(named(&["One more"]));
|
bookmarks.extend(named(&["One more"]));
|
||||||
@@ -385,8 +388,8 @@ mod tests {
|
|||||||
};
|
};
|
||||||
let mut state = SessionState::default();
|
let mut state = SessionState::default();
|
||||||
let f = form(&b, None, "pw");
|
let f = form(&b, None, "pw");
|
||||||
assert_eq!((f.id, f.name.as_str(), f.address.as_str()), (3, "", "ts.example.test"));
|
assert_eq!((f.id, f.name.as_ref(), f.address.as_ref()), (3, "", "ts.example.test"));
|
||||||
assert_eq!((f.nickname.as_str(), f.server_password.as_str()), ("Nova", "pw"));
|
assert_eq!((f.nickname.as_ref(), f.server_password.as_ref()), ("Nova", "pw"));
|
||||||
assert!(!f.connected);
|
assert!(!f.connected);
|
||||||
for (voice, connected) in [
|
for (voice, connected) in [
|
||||||
(VoiceState::Disconnected, false),
|
(VoiceState::Disconnected, false),
|
||||||
@@ -402,7 +405,7 @@ mod tests {
|
|||||||
state.observe = ObserveState::Observing;
|
state.observe = ObserveState::Observing;
|
||||||
assert!(!form(&b, Some(&state), "").connected);
|
assert!(!form(&b, Some(&state), "").connected);
|
||||||
let named = Bookmark { name: "Nightfall".into(), ..b };
|
let named = Bookmark { name: "Nightfall".into(), ..b };
|
||||||
assert_eq!(form(&named, None, "").name.as_str(), "Nightfall");
|
assert_eq!(form(&named, None, "").name.as_ref(), "Nightfall");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -568,16 +571,16 @@ mod tests {
|
|||||||
// A new server: the link's address, nickname and password.
|
// A new server: the link's address, nickname and password.
|
||||||
let new = BookmarkForm { id: -1, nickname: "Me".into(), ..Default::default() };
|
let new = BookmarkForm { id: -1, nickname: "Me".into(), ..Default::default() };
|
||||||
let f = link_form(&link, new.clone(), "Me");
|
let f = link_form(&link, new.clone(), "Me");
|
||||||
assert_eq!((f.id, f.name.as_str(), f.address.as_str()), (-1, "", "ts.example.org:9988"));
|
assert_eq!((f.id, f.name.as_ref(), f.address.as_ref()), (-1, "", "ts.example.org:9988"));
|
||||||
assert_eq!((f.nickname.as_str(), f.server_password.as_str()), ("Link", "pw"));
|
assert_eq!((f.nickname.as_ref(), f.server_password.as_ref()), ("Link", "pw"));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(f.channel.as_str(), f.channel_password.as_str(), f.token.as_str()),
|
(f.channel.as_ref(), f.channel_password.as_ref(), f.token.as_ref()),
|
||||||
("Gaming/Raid Night", "raid", "key")
|
("Gaming/Raid Night", "raid", "key")
|
||||||
);
|
);
|
||||||
let f = link_form(&bare, new, "Me");
|
let f = link_form(&bare, new, "Me");
|
||||||
assert_eq!((f.address.as_str(), f.nickname.as_str()), ("ts.example.org", "Me"));
|
assert_eq!((f.address.as_ref(), f.nickname.as_ref()), ("ts.example.org", "Me"));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(f.server_password.as_str(), f.channel.as_str(), f.token.as_str()),
|
(f.server_password.as_ref(), f.channel.as_ref(), f.token.as_ref()),
|
||||||
("", "", "")
|
("", "", "")
|
||||||
);
|
);
|
||||||
// A saved server keeps its address, name, nickname and password...
|
// A saved server keeps its address, name, nickname and password...
|
||||||
@@ -591,14 +594,14 @@ mod tests {
|
|||||||
};
|
};
|
||||||
let f = link_form(&bare, saved.clone(), "Me");
|
let f = link_form(&bare, saved.clone(), "Me");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(f.id, f.name.as_str(), f.address.as_str()),
|
(f.id, f.name.as_ref(), f.address.as_ref()),
|
||||||
(3, "Nightfall", "TS.example.org:9988")
|
(3, "Nightfall", "TS.example.org:9988")
|
||||||
);
|
);
|
||||||
assert_eq!((f.nickname.as_str(), f.server_password.as_str()), ("Nova", "stored"));
|
assert_eq!((f.nickname.as_ref(), f.server_password.as_ref()), ("Nova", "stored"));
|
||||||
// ...the link's password in place of the stored one.
|
// ...the link's password in place of the stored one.
|
||||||
let f = link_form(&link, saved, "Me");
|
let f = link_form(&link, saved, "Me");
|
||||||
assert_eq!((f.nickname.as_str(), f.server_password.as_str()), ("Nova", "pw"));
|
assert_eq!((f.nickname.as_ref(), f.server_password.as_ref()), ("Nova", "pw"));
|
||||||
assert_eq!((f.channel.as_str(), f.token.as_str()), ("Gaming/Raid Night", "key"));
|
assert_eq!((f.channel.as_ref(), f.token.as_ref()), ("Gaming/Raid Night", "key"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -9,7 +9,7 @@ use voelin_audio::process::NoiseLevel;
|
|||||||
use voelin_core::settings::{Key, Kind};
|
use voelin_core::settings::{Key, Kind};
|
||||||
use voelin_core::{AudioSettings, TransmitMode};
|
use voelin_core::{AudioSettings, TransmitMode};
|
||||||
|
|
||||||
use crate::app::AudioForm;
|
use crate::bridge::AudioForm;
|
||||||
|
|
||||||
/// The window's settings, one value (the `ui` blob of earlier versions).
|
/// The window's settings, one value (the `ui` blob of earlier versions).
|
||||||
pub static UI: Key<UiSettings> = Key::new(
|
pub static UI: Key<UiSettings> = Key::new(
|
||||||
@@ -39,6 +39,7 @@ pub enum ThemeChoice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ThemeChoice {
|
impl ThemeChoice {
|
||||||
|
/// The value stored for this choice.
|
||||||
pub fn as_str(self) -> &'static str {
|
pub fn as_str(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::Dark => "dark",
|
Self::Dark => "dark",
|
||||||
@@ -47,6 +48,7 @@ impl ThemeChoice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The choice a stored value names (dark for any other).
|
||||||
pub fn parse(text: &str) -> Self {
|
pub fn parse(text: &str) -> Self {
|
||||||
match text {
|
match text {
|
||||||
"light" => Self::Light,
|
"light" => Self::Light,
|
||||||
@@ -133,10 +135,12 @@ pub enum NotifyLevel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NotifyLevel {
|
impl NotifyLevel {
|
||||||
|
/// The position in the settings' list (off, app, desktop).
|
||||||
pub fn index(self) -> i32 {
|
pub fn index(self) -> i32 {
|
||||||
self as i32
|
self as i32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The choice at a list position (desktop for any other).
|
||||||
pub fn from_index(index: i32) -> Self {
|
pub fn from_index(index: i32) -> Self {
|
||||||
match index {
|
match index {
|
||||||
0 => Self::Off,
|
0 => Self::Off,
|
||||||
@@ -155,22 +159,26 @@ pub static NOTIFY_MENTIONS: Key<NotifyLevel> = Key::new(
|
|||||||
"Our name in a channel or server chat: off, app (the bell) or desktop.",
|
"Our name in a channel or server chat: off, app (the bell) or desktop.",
|
||||||
NotifyLevel::default,
|
NotifyLevel::default,
|
||||||
);
|
);
|
||||||
|
/// Private messages: off, app (the bell) or desktop.
|
||||||
pub static NOTIFY_MESSAGES: Key<NotifyLevel> = Key::new(
|
pub static NOTIFY_MESSAGES: Key<NotifyLevel> = Key::new(
|
||||||
"notify.private_messages",
|
"notify.private_messages",
|
||||||
NOTIFY_LEVELS,
|
NOTIFY_LEVELS,
|
||||||
"Private messages: off, app (the bell) or desktop.",
|
"Private messages: off, app (the bell) or desktop.",
|
||||||
NotifyLevel::default,
|
NotifyLevel::default,
|
||||||
);
|
);
|
||||||
|
/// Pokes: off, app (the bell) or desktop.
|
||||||
pub static NOTIFY_POKES: Key<NotifyLevel> =
|
pub static NOTIFY_POKES: Key<NotifyLevel> =
|
||||||
Key::new("notify.pokes", NOTIFY_LEVELS, "Pokes: off, app (the bell) or desktop.", || {
|
Key::new("notify.pokes", NOTIFY_LEVELS, "Pokes: off, app (the bell) or desktop.", || {
|
||||||
NotifyLevel::Desktop
|
NotifyLevel::Desktop
|
||||||
});
|
});
|
||||||
|
/// Reminders of scheduled events: off, app (the bell) or desktop.
|
||||||
pub static NOTIFY_EVENTS: Key<NotifyLevel> = Key::new(
|
pub static NOTIFY_EVENTS: Key<NotifyLevel> = Key::new(
|
||||||
"notify.event_reminders",
|
"notify.event_reminders",
|
||||||
NOTIFY_LEVELS,
|
NOTIFY_LEVELS,
|
||||||
"Reminders of scheduled events: off, app (the bell) or desktop.",
|
"Reminders of scheduled events: off, app (the bell) or desktop.",
|
||||||
NotifyLevel::default,
|
NotifyLevel::default,
|
||||||
);
|
);
|
||||||
|
/// Friends coming online: off, app (the bell) or desktop.
|
||||||
pub static NOTIFY_FRIENDS: Key<NotifyLevel> = Key::new(
|
pub static NOTIFY_FRIENDS: Key<NotifyLevel> = Key::new(
|
||||||
"notify.friends_online",
|
"notify.friends_online",
|
||||||
NOTIFY_LEVELS,
|
NOTIFY_LEVELS,
|
||||||
@@ -253,11 +261,14 @@ pub fn page_keys() -> [&'static dyn voelin_core::settings::Setting; 10] {
|
|||||||
/// offers, in the order of its lists (`dialogs.slint`); any other value can
|
/// offers, in the order of its lists (`dialogs.slint`); any other value can
|
||||||
/// be typed in.
|
/// be typed in.
|
||||||
pub const FPS_CHOICES: [u32; 7] = [15, 30, 60, 120, 144, 240, 320];
|
pub const FPS_CHOICES: [u32; 7] = [15, 30, 60, 120, 144, 240, 320];
|
||||||
|
/// The bitrates (kbit/s, 0 for automatic) the share dialog offers, in the
|
||||||
|
/// order of its list.
|
||||||
pub const BITRATE_CHOICES: [u32; 8] = [0, 2500, 4608, 8000, 10_000, 20_000, 40_000, 60_000];
|
pub const BITRATE_CHOICES: [u32; 8] = [0, 2500, 4608, 8000, 10_000, 20_000, 40_000, 60_000];
|
||||||
|
|
||||||
/// The share dialog's lists before they grew, which [`ShareDefaults`]
|
/// The share dialog's lists before they grew, which [`ShareDefaults`]
|
||||||
/// indexes for older versions.
|
/// indexes for older versions.
|
||||||
pub const LEGACY_FPS_CHOICES: [u32; 3] = [15, 30, 60];
|
pub const LEGACY_FPS_CHOICES: [u32; 3] = [15, 30, 60];
|
||||||
|
/// The bitrates of the share dialog's list before it grew.
|
||||||
pub const LEGACY_BITRATE_CHOICES: [u32; 4] = [2500, 4608, 8000, 10_000];
|
pub const LEGACY_BITRATE_CHOICES: [u32; 4] = [2500, 4608, 8000, 10_000];
|
||||||
|
|
||||||
/// The index of the choice closest to `value`.
|
/// The index of the choice closest to `value`.
|
||||||
@@ -270,6 +281,8 @@ pub fn parse_positive(text: &str) -> Option<u32> {
|
|||||||
text.trim().parse().ok().filter(|v| *v > 0)
|
text.trim().parse().ok().filter(|v| *v > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The `ui` settings: what the front end keeps about itself (the push-to-talk
|
||||||
|
/// hotkey, codecs, the share dialog's defaults, the last voice channel).
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct UiSettings {
|
pub struct UiSettings {
|
||||||
@@ -347,11 +360,13 @@ impl Default for ClientPlayback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ClientPlayback {
|
impl ClientPlayback {
|
||||||
|
/// Nothing differs from the defaults, so there is nothing to store.
|
||||||
pub fn is_default(&self) -> bool {
|
pub fn is_default(&self) -> bool {
|
||||||
*self == Self::default()
|
*self == Self::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Each client's playback settings, by the client's unique id.
|
||||||
pub type ClientPlaybackMap = BTreeMap<String, ClientPlayback>;
|
pub type ClientPlaybackMap = BTreeMap<String, ClientPlayback>;
|
||||||
|
|
||||||
/// Audio devices as listed in the settings: the system default first.
|
/// Audio devices as listed in the settings: the system default first.
|
||||||
@@ -387,10 +402,14 @@ impl DeviceChoices {
|
|||||||
choices
|
choices
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The index of the choice for device `id` (the system default for `None` or
|
||||||
|
/// an unknown id).
|
||||||
pub fn index_of(&self, id: Option<&str>) -> usize {
|
pub fn index_of(&self, id: Option<&str>) -> usize {
|
||||||
self.ids.iter().position(|i| i.as_deref() == id).unwrap_or(0)
|
self.ids.iter().position(|i| i.as_deref() == id).unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The device id of choice `index`; `None` for the system default or an index
|
||||||
|
/// outside the list.
|
||||||
pub fn id_at(&self, index: i32) -> Option<String> {
|
pub fn id_at(&self, index: i32) -> Option<String> {
|
||||||
usize::try_from(index).ok().and_then(|i| self.ids.get(i).cloned()).flatten()
|
usize::try_from(index).ok().and_then(|i| self.ids.get(i).cloned()).flatten()
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,7 @@
|
|||||||
|
//! The settings pages added with the new design: My Account, Profiles
|
||||||
|
//! (identities), Voice & Video, Streaming, Devices, Notifications, Privacy &
|
||||||
|
//! Safety, Integrations (gateways, gateway administration, encoders) and
|
||||||
|
//! Advanced. [`logic`] has what the pages show and what their controls
|
||||||
|
//! change; the front ends put the rows on screen.
|
||||||
|
|
||||||
|
pub mod logic;
|
||||||
@@ -4,6 +4,23 @@
|
|||||||
//! chats of the home sidebar; pure, so they are tested here.
|
//! chats of the home sidebar; pure, so they are tested here.
|
||||||
|
|
||||||
use chrono::{DateTime, Local, NaiveDateTime, TimeZone};
|
use chrono::{DateTime, Local, NaiveDateTime, TimeZone};
|
||||||
|
use voelin_core::HistoryMessage;
|
||||||
|
use voelin_model::ChatTarget;
|
||||||
|
|
||||||
|
/// A chat of any server.
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct ChatRef {
|
||||||
|
/// The bookmark (session) it belongs to, when known.
|
||||||
|
pub session: Option<i64>,
|
||||||
|
/// The server's unique id.
|
||||||
|
pub server_uid: Option<String>,
|
||||||
|
/// Which chat of the server.
|
||||||
|
pub target: ChatTarget,
|
||||||
|
/// Its newest message.
|
||||||
|
pub last: Option<HistoryMessage>,
|
||||||
|
/// Messages not read.
|
||||||
|
pub unread: i32,
|
||||||
|
}
|
||||||
|
|
||||||
fn local(ts_ms: i64) -> Option<NaiveDateTime> {
|
fn local(ts_ms: i64) -> Option<NaiveDateTime> {
|
||||||
DateTime::from_timestamp_millis(ts_ms).map(|t| t.with_timezone(&Local).naive_local())
|
DateTime::from_timestamp_millis(ts_ms).map(|t| t.with_timezone(&Local).naive_local())
|
||||||
@@ -18,6 +35,7 @@ pub fn ago(ts_ms: i64) -> String {
|
|||||||
ago_at(ts_ms, chrono::Utc::now().timestamp_millis())
|
ago_at(ts_ms, chrono::Utc::now().timestamp_millis())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// [`ago`] for a given time `now_ms`.
|
||||||
pub fn ago_at(ts_ms: i64, now_ms: i64) -> String {
|
pub fn ago_at(ts_ms: i64, now_ms: i64) -> String {
|
||||||
if ts_ms <= 0 {
|
if ts_ms <= 0 {
|
||||||
return String::new();
|
return String::new();
|
||||||
@@ -39,6 +57,7 @@ pub fn list_time(ts_ms: i64) -> String {
|
|||||||
local(ts_ms).map(|t| list_time_at(t, now_local())).unwrap_or_default()
|
local(ts_ms).map(|t| list_time_at(t, now_local())).unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// [`list_time`] for a given local time `now`.
|
||||||
pub fn list_time_at(then: NaiveDateTime, now: NaiveDateTime) -> String {
|
pub fn list_time_at(then: NaiveDateTime, now: NaiveDateTime) -> String {
|
||||||
use chrono::Datelike;
|
use chrono::Datelike;
|
||||||
let days = (now.date() - then.date()).num_days();
|
let days = (now.date() - then.date()).num_days();
|
||||||
@@ -53,7 +72,7 @@ pub fn list_time_at(then: NaiveDateTime, now: NaiveDateTime) -> String {
|
|||||||
|
|
||||||
/// Chat text without BBCode (`[b]`, `[URL=…]`, `[/URL]`), on one line.
|
/// Chat text without BBCode (`[b]`, `[URL=…]`, `[/URL]`), on one line.
|
||||||
pub fn plain(text: &str) -> String {
|
pub fn plain(text: &str) -> String {
|
||||||
without_emoji(&crate::vm::bbcode::parse(text).one_line())
|
without_emoji(&crate::bbcode::parse(text).one_line())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Text without emoji, runs of spaces as one: one line of text draws no
|
/// Text without emoji, runs of spaces as one: one line of text draws no
|
||||||
@@ -76,7 +95,7 @@ fn is_emoji(c: char) -> bool {
|
|||||||
pub fn preview(text: &str, mine: bool, files: &[voelin_model::FileRef]) -> String {
|
pub fn preview(text: &str, mine: bool, files: &[voelin_model::FileRef]) -> String {
|
||||||
let body = if files.is_empty() { plain(text) } else { String::new() };
|
let body = if files.is_empty() { plain(text) } else { String::new() };
|
||||||
let body = if body.is_empty() && !files.is_empty() {
|
let body = if body.is_empty() && !files.is_empty() {
|
||||||
if files.iter().any(|f| crate::vm::chat::is_picture(&f.name)) {
|
if files.iter().any(|f| crate::chat::is_picture(&f.name)) {
|
||||||
"Sent a picture".to_owned()
|
"Sent a picture".to_owned()
|
||||||
} else {
|
} else {
|
||||||
"Sent a file".to_owned()
|
"Sent a file".to_owned()
|
||||||
@@ -116,7 +135,7 @@ pub fn poke_message(text: &str) -> String {
|
|||||||
|
|
||||||
/// The private chats of the home sidebar, by their index in `chats`
|
/// The private chats of the home sidebar, by their index in `chats`
|
||||||
/// (newest first): at most `n`, those with unread messages first.
|
/// (newest first): at most `n`, those with unread messages first.
|
||||||
pub fn sidebar_dms(chats: &[crate::messages::ChatRef], n: usize) -> Vec<usize> {
|
pub fn sidebar_dms(chats: &[ChatRef], n: usize) -> Vec<usize> {
|
||||||
let mut private: Vec<usize> = (0..chats.len())
|
let mut private: Vec<usize> = (0..chats.len())
|
||||||
.filter(|&i| matches!(chats[i].target, voelin_model::ChatTarget::Private(_)))
|
.filter(|&i| matches!(chats[i].target, voelin_model::ChatTarget::Private(_)))
|
||||||
.collect();
|
.collect();
|
||||||
@@ -133,7 +152,7 @@ pub fn found_channels<'a>(
|
|||||||
) -> Vec<(u64, &'a str)> {
|
) -> Vec<(u64, &'a str)> {
|
||||||
channels
|
channels
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|c| Some((c.id, crate::vm::tree::listed_title(c)?)))
|
.filter_map(|c| Some((c.id, crate::tree::listed_title(c)?)))
|
||||||
.filter(|(_, title)| matches(query, &[*title]))
|
.filter(|(_, title)| matches(query, &[*title]))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
@@ -287,7 +306,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn sidebar_chats() {
|
fn sidebar_chats() {
|
||||||
use voelin_model::ChatTarget;
|
use voelin_model::ChatTarget;
|
||||||
let chat = |target: ChatTarget, unread| crate::messages::ChatRef {
|
let chat = |target: ChatTarget, unread| ChatRef {
|
||||||
session: Some(1),
|
session: Some(1),
|
||||||
server_uid: None,
|
server_uid: None,
|
||||||
target,
|
target,
|
||||||
@@ -0,0 +1,723 @@
|
|||||||
|
//! 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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<L> Tab<L> {
|
||||||
|
/// 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> 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
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<L: Default> SessionView<L> {
|
||||||
|
/// 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 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,8 +5,8 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
use voelin_core::stream::StreamKind;
|
use voelin_core::stream::StreamKind;
|
||||||
|
|
||||||
use crate::app::StreamItem;
|
use crate::avatar;
|
||||||
use crate::vm::avatar;
|
use crate::bridge::StreamItem;
|
||||||
|
|
||||||
/// "Screen", "Window", "Camera"; "" for a kind we do not know.
|
/// "Screen", "Window", "Camera"; "" for a kind we do not know.
|
||||||
pub fn kind_label(kind: &StreamKind) -> &'static str {
|
pub fn kind_label(kind: &StreamKind) -> &'static str {
|
||||||
@@ -40,6 +40,7 @@ pub fn streamer(name: &str, picture: Option<&PathBuf>) -> StreamItem {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::Size;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn kinds_have_labels() {
|
fn kinds_have_labels() {
|
||||||
@@ -60,10 +61,10 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn streamers_look_as_in_the_members() {
|
fn streamers_look_as_in_the_members() {
|
||||||
let item = streamer("Nova Star", None);
|
let item = streamer("Nova Star", None);
|
||||||
assert_eq!(item.streamer, "Nova Star");
|
assert_eq!(&*item.streamer, "Nova Star");
|
||||||
assert_eq!(item.initials, "NS");
|
assert_eq!(&*item.initials, "NS");
|
||||||
assert_eq!(item.tint, avatar::tint("Nova Star"));
|
assert_eq!(item.tint, avatar::tint("Nova Star"));
|
||||||
assert_eq!(item.avatar.size(), slint::Image::default().size());
|
assert_eq!(item.avatar.size(), Size::default());
|
||||||
assert!(item.id.is_empty() && !item.own && !item.studio);
|
assert!(item.id.is_empty() && !item.own && !item.studio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,9 @@
|
|||||||
//! The Stream Studio's view models: scene, source, mixer and layer rows,
|
//! The Stream Studio's view models: scene, source, mixer and layer rows,
|
||||||
//! the header's numbers, the source dialog's form, where new sources go and
|
//! the header's numbers, the source dialog's form, where new sources go and
|
||||||
//! the overlay sources the stream settings' switches keep in the scenes.
|
//! the overlay sources the stream settings' switches keep in the scenes.
|
||||||
|
//! Decisions of the studio (what it does when) are in [`logic`].
|
||||||
|
|
||||||
|
pub mod logic;
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@@ -11,7 +14,7 @@ use voelin_core::studio::scene::{
|
|||||||
Align, Background, Colour, Crop, Fit, Scene, Scenes, Source, SourceKind, Transform,
|
Align, Background, Colour, Crop, Fit, Scene, Scenes, Source, SourceKind, Transform,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::app::{StudioAudio, StudioLayer, StudioScene, StudioSource, StudioSourceForm};
|
use crate::studio_bridge::{StudioAudio, StudioLayer, StudioScene, StudioSource, StudioSourceForm};
|
||||||
|
|
||||||
/// The scenes; the live one marked, each with what it shows.
|
/// The scenes; the live one marked, each with what it shows.
|
||||||
pub fn scenes(scenes: &Scenes) -> Vec<StudioScene> {
|
pub fn scenes(scenes: &Scenes) -> Vec<StudioScene> {
|
||||||
@@ -36,6 +39,7 @@ fn summary(scene: &Scene) -> String {
|
|||||||
if names.is_empty() { "Empty".into() } else { names.join(" + ") }
|
if names.is_empty() { "Empty".into() } else { names.join(" + ") }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The kind of a background by name: keep, blur, image or colour.
|
||||||
pub fn background_name(background: &Background) -> &'static str {
|
pub fn background_name(background: &Background) -> &'static str {
|
||||||
match background {
|
match background {
|
||||||
Background::Keep => "keep",
|
Background::Keep => "keep",
|
||||||
@@ -259,6 +263,7 @@ pub fn parse_colour(text: &str) -> Option<Colour> {
|
|||||||
Some(Colour::rgba(byte(0)?, byte(2)?, byte(4)?, a))
|
Some(Colour::rgba(byte(0)?, byte(2)?, byte(4)?, a))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A colour as `#rrggbb`, or `#rrggbbaa` when it is not opaque.
|
||||||
pub fn colour_text(c: Colour) -> String {
|
pub fn colour_text(c: Colour) -> String {
|
||||||
if c.a == 255 {
|
if c.a == 255 {
|
||||||
format!("#{:02x}{:02x}{:02x}", c.r, c.g, c.b)
|
format!("#{:02x}{:02x}{:02x}", c.r, c.g, c.b)
|
||||||
@@ -356,7 +361,7 @@ fn transform(form: &StudioSourceForm) -> Result<Transform, String> {
|
|||||||
width: parse_size(&form.width, "width")?,
|
width: parse_size(&form.width, "width")?,
|
||||||
height: parse_size(&form.height, "height")?,
|
height: parse_size(&form.height, "height")?,
|
||||||
scale,
|
scale,
|
||||||
fit: match form.fit.as_str() {
|
fit: match form.fit.as_ref() {
|
||||||
"cover" => Fit::Cover,
|
"cover" => Fit::Cover,
|
||||||
"stretch" => Fit::Stretch,
|
"stretch" => Fit::Stretch,
|
||||||
_ => Fit::Contain,
|
_ => Fit::Contain,
|
||||||
@@ -365,7 +370,7 @@ fn transform(form: &StudioSourceForm) -> Result<Transform, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn background(form: &StudioSourceForm) -> Result<Background, String> {
|
fn background(form: &StudioSourceForm) -> Result<Background, String> {
|
||||||
Ok(match form.background.as_str() {
|
Ok(match form.background.as_ref() {
|
||||||
"blur" => Background::Blur { strength: parse_f32(&form.blur, "blur")?.max(0.0) / 100.0 },
|
"blur" => Background::Blur { strength: parse_f32(&form.blur, "blur")?.max(0.0) / 100.0 },
|
||||||
"image" if !form.background_path.trim().is_empty() => {
|
"image" if !form.background_path.trim().is_empty() => {
|
||||||
Background::Image { path: form.background_path.trim().into() }
|
Background::Image { path: form.background_path.trim().into() }
|
||||||
@@ -392,7 +397,7 @@ pub fn change(form: &StudioSourceForm, old: &Source) -> Result<SourceChange, Str
|
|||||||
let opacity = (form.opacity / 100.0).clamp(0.0, 1.0);
|
let opacity = (form.opacity / 100.0).clamp(0.0, 1.0);
|
||||||
let differs = |a: bool| a.then_some(());
|
let differs = |a: bool| a.then_some(());
|
||||||
Ok(SourceChange {
|
Ok(SourceChange {
|
||||||
name: differs(form.name.as_str() != old.name).map(|_| form.name.to_string()),
|
name: differs(form.name.as_ref() != old.name).map(|_| form.name.to_string()),
|
||||||
kind: differs(kind != old.kind).map(|_| kind),
|
kind: differs(kind != old.kind).map(|_| kind),
|
||||||
transform: differs(transform != old.transform).map(|_| transform),
|
transform: differs(transform != old.transform).map(|_| transform),
|
||||||
crop: differs(crop != old.crop).map(|_| crop),
|
crop: differs(crop != old.crop).map(|_| crop),
|
||||||
@@ -406,7 +411,7 @@ pub fn change(form: &StudioSourceForm, old: &Source) -> Result<SourceChange, Str
|
|||||||
/// The kind as the form says: text, colour and image from their fields, a
|
/// The kind as the form says: text, colour and image from their fields, a
|
||||||
/// camera's mirroring, anything else as it was.
|
/// camera's mirroring, anything else as it was.
|
||||||
fn kind(form: &StudioSourceForm, old: Option<&SourceKind>) -> Result<SourceKind, String> {
|
fn kind(form: &StudioSourceForm, old: Option<&SourceKind>) -> Result<SourceKind, String> {
|
||||||
Ok(match (form.kind.as_str(), old) {
|
Ok(match (form.kind.as_ref(), old) {
|
||||||
("text", old) => {
|
("text", old) => {
|
||||||
let (font, backdrop, align, padding) = match old {
|
let (font, backdrop, align, padding) = match old {
|
||||||
Some(SourceKind::Text { font, backdrop, align, padding, .. }) => {
|
Some(SourceKind::Text { font, backdrop, align, padding, .. }) => {
|
||||||
@@ -454,7 +459,7 @@ pub fn new_source(form: &StudioSourceForm, output: (u32, u32)) -> Result<Source,
|
|||||||
let kind = kind(form, None)?;
|
let kind = kind(form, None)?;
|
||||||
let mut source = Source::new(0, kind);
|
let mut source = Source::new(0, kind);
|
||||||
source.name = form.name.trim().to_owned();
|
source.name = form.name.trim().to_owned();
|
||||||
source.transform = if form.kind == "colour" {
|
source.transform = if &*form.kind == "colour" {
|
||||||
Transform::full(output.0, output.1)
|
Transform::full(output.0, output.1)
|
||||||
} else {
|
} else {
|
||||||
let mut t = placement(&source.kind, output);
|
let mut t = placement(&source.kind, output);
|
||||||
@@ -501,8 +506,11 @@ pub struct Overlay {
|
|||||||
pub text: Option<String>,
|
pub text: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The overlay source that shows how many are watching.
|
||||||
pub const OVERLAY_VIEWERS: &str = "Viewer count";
|
pub const OVERLAY_VIEWERS: &str = "Viewer count";
|
||||||
|
/// The overlay source that shows the stream chat's last lines.
|
||||||
pub const OVERLAY_CHAT: &str = "Chat overlay";
|
pub const OVERLAY_CHAT: &str = "Chat overlay";
|
||||||
|
/// The overlay source that names what plays.
|
||||||
pub const OVERLAY_NOW_PLAYING: &str = "Now playing";
|
pub const OVERLAY_NOW_PLAYING: &str = "Now playing";
|
||||||
|
|
||||||
fn overlay_kind(name: &str, text: &str) -> SourceKind {
|
fn overlay_kind(name: &str, text: &str) -> SourceKind {
|
||||||
@@ -598,11 +606,11 @@ mod tests {
|
|||||||
let rows = super::scenes(&scenes);
|
let rows = super::scenes(&scenes);
|
||||||
assert_eq!(rows.len(), 2);
|
assert_eq!(rows.len(), 2);
|
||||||
assert!(rows[0].live && !rows[1].live);
|
assert!(rows[0].live && !rows[1].live);
|
||||||
assert_eq!(rows[0].detail, "Screen + Camera");
|
assert_eq!(&*rows[0].detail, "Screen + Camera");
|
||||||
assert_eq!(rows[1].detail, "Empty");
|
assert_eq!(&*rows[1].detail, "Empty");
|
||||||
let sources = super::sources(scenes.active(), &[]);
|
let sources = super::sources(scenes.active(), &[]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
sources.iter().map(|s| s.name.as_str()).collect::<Vec<_>>(),
|
sources.iter().map(|s| s.name.as_ref()).collect::<Vec<_>>(),
|
||||||
["Camera", "Screen"]
|
["Camera", "Screen"]
|
||||||
);
|
);
|
||||||
assert!(sources[0].front && !sources[0].back && sources[1].back);
|
assert!(sources[0].front && !sources[0].back && sources[1].back);
|
||||||
@@ -652,7 +660,7 @@ mod tests {
|
|||||||
assert!(parse_layer(&row("big", "", "800"), &old).is_err());
|
assert!(parse_layer(&row("big", "", "800"), &old).is_err());
|
||||||
assert!(parse_layer(&row("1", "", "fast"), &old).is_err());
|
assert!(parse_layer(&row("1", "", "fast"), &old).is_err());
|
||||||
let rows = layers(&[l]);
|
let rows = layers(&[l]);
|
||||||
assert_eq!((rows[0].scale.as_str(), rows[0].bitrate.as_str()), ("0.5", "800"));
|
assert_eq!((rows[0].scale.as_ref(), rows[0].bitrate.as_ref()), ("0.5", "800"));
|
||||||
let below = next_layer(&[LayerSetting { bitrate: 8_000_000, ..old.clone() }], 8000);
|
let below = next_layer(&[LayerSetting { bitrate: 8_000_000, ..old.clone() }], 8000);
|
||||||
assert_eq!((below.scale, below.bitrate), (0.5, 2_000_000));
|
assert_eq!((below.scale, below.bitrate), (0.5, 2_000_000));
|
||||||
}
|
}
|
||||||
@@ -673,8 +681,8 @@ mod tests {
|
|||||||
);
|
);
|
||||||
source.transform = Transform::box_at(10.0, 20.0, 300.0, 100.0);
|
source.transform = Transform::box_at(10.0, 20.0, 300.0, 100.0);
|
||||||
let mut f = form(&source);
|
let mut f = form(&source);
|
||||||
assert_eq!(f.text, "Hello\\nthere");
|
assert_eq!(&*f.text, "Hello\\nthere");
|
||||||
assert_eq!((f.x.as_str(), f.width.as_str()), ("10", "300"));
|
assert_eq!((f.x.as_ref(), f.width.as_ref()), ("10", "300"));
|
||||||
assert_eq!(change(&f, &source).unwrap(), SourceChange::default());
|
assert_eq!(change(&f, &source).unwrap(), SourceChange::default());
|
||||||
f.x = "40".into();
|
f.x = "40".into();
|
||||||
f.opacity = 50.0;
|
f.opacity = 50.0;
|
||||||
@@ -0,0 +1,195 @@
|
|||||||
|
//! The Stream Studio's structs: the plain counterparts of
|
||||||
|
//! `crates/voelin-ui/ui/studio-bridge.slint`, as [`crate::bridge`] has those of
|
||||||
|
//! `bridge.slint`.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::image::ImageRef;
|
||||||
|
|
||||||
|
/// A scene of the studio.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct StudioScene {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
/// Its sources, front first: "Screen + Camera + Text".
|
||||||
|
pub detail: Arc<str>,
|
||||||
|
/// Composited now (the live scene).
|
||||||
|
pub live: bool,
|
||||||
|
/// The kind of its front-most source (for the icon).
|
||||||
|
pub kind: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A source of the live scene, front first.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct StudioSource {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
/// screen, window, portal, camera, image, text, colour, pattern
|
||||||
|
pub kind: Arc<str>,
|
||||||
|
pub visible: bool,
|
||||||
|
pub locked: bool,
|
||||||
|
/// keep, blur, image, colour
|
||||||
|
pub background: Arc<str>,
|
||||||
|
/// Why it shows nothing ("" while it works).
|
||||||
|
pub error: Arc<str>,
|
||||||
|
/// "1920×1080 · 60 fps"
|
||||||
|
pub info: Arc<str>,
|
||||||
|
/// At the front or the back (cannot move further).
|
||||||
|
pub front: bool,
|
||||||
|
pub back: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An audio source of the stream (`stream.audio_sources`).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct StudioAudio {
|
||||||
|
pub name: Arc<str>,
|
||||||
|
/// "Elgato Wave:3", the application...
|
||||||
|
pub detail: Arc<str>,
|
||||||
|
/// microphone, desktop, app, window, tone
|
||||||
|
pub kind: Arc<str>,
|
||||||
|
pub gain_db: f32,
|
||||||
|
pub muted: bool,
|
||||||
|
/// The meter in dBFS, after the gain.
|
||||||
|
pub level: f32,
|
||||||
|
/// Why it captures nothing.
|
||||||
|
pub error: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A simulcast layer (`stream.layers`) as typed: any numbers.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct StudioLayer {
|
||||||
|
/// "1280x720"; empty: `scale` of the output.
|
||||||
|
pub size: Arc<str>,
|
||||||
|
pub scale: Arc<str>,
|
||||||
|
/// Frame-rate cap; empty: the output's.
|
||||||
|
pub fps: Arc<str>,
|
||||||
|
/// kbit/s.
|
||||||
|
pub bitrate: Arc<str>,
|
||||||
|
/// kbit/s a viewer needs for this layer.
|
||||||
|
pub min_bitrate: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A viewer of the studio's stream.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct StudioViewer {
|
||||||
|
pub client: i32,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
/// requested, connecting, connected
|
||||||
|
pub state: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An entry of a picker (screens, windows, cameras, audio sources).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct StudioPick {
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub detail: Arc<str>,
|
||||||
|
/// For the icon: monitor, window, portal, camera, microphone, desktop, app, tone
|
||||||
|
pub kind: Arc<str>,
|
||||||
|
/// The application's own icon (audio), if it has one.
|
||||||
|
pub icon: ImageRef,
|
||||||
|
/// Already mixed in (audio): picking it again takes it out.
|
||||||
|
pub selected: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The header, the preview's badges and the bottom bar.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct StudioStatus {
|
||||||
|
/// The engine runs (preview, mixer, replay buffer).
|
||||||
|
pub running: bool,
|
||||||
|
/// "Chill Zone • Starfall Community"; empty without a destination.
|
||||||
|
pub destination: Arc<str>,
|
||||||
|
/// 0: not live, 1: poor, 2: fair, 3: good, 4: excellent.
|
||||||
|
pub quality: i32,
|
||||||
|
pub quality_text: Arc<str>,
|
||||||
|
/// "1080p • 60 FPS • 8,250 kbps"
|
||||||
|
pub format: Arc<str>,
|
||||||
|
/// The numbers behind it, for the info button.
|
||||||
|
pub details: Arc<str>,
|
||||||
|
pub live: bool,
|
||||||
|
/// Going live: waiting for the server.
|
||||||
|
pub starting: bool,
|
||||||
|
/// "00:12:34"
|
||||||
|
pub elapsed: Arc<str>,
|
||||||
|
pub viewers: i32,
|
||||||
|
pub participants: i32,
|
||||||
|
pub can_go_live: bool,
|
||||||
|
/// Why Go Live is off, or what goes wrong.
|
||||||
|
pub hint: Arc<str>,
|
||||||
|
pub recording: bool,
|
||||||
|
pub recorded: Arc<str>,
|
||||||
|
/// The replay buffer's window (0: off) and what it holds now.
|
||||||
|
pub replay_seconds: i32,
|
||||||
|
pub replay_held: Arc<str>,
|
||||||
|
pub output_width: i32,
|
||||||
|
pub output_height: i32,
|
||||||
|
pub fps: i32,
|
||||||
|
pub detached: bool,
|
||||||
|
/// A window of its own is possible (not on Android).
|
||||||
|
pub can_detach: bool,
|
||||||
|
/// The live scene shows a screen, a camera, a window (the phone's cards).
|
||||||
|
pub screen_shown: bool,
|
||||||
|
pub camera_shown: bool,
|
||||||
|
pub window_shown: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The stream settings panel (`studio.stream`, `stream.bitrate_kbps`).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct StudioForm {
|
||||||
|
pub destination: i32,
|
||||||
|
pub title: Arc<str>,
|
||||||
|
pub game: Arc<str>,
|
||||||
|
pub message: Arc<str>,
|
||||||
|
pub show_viewers: bool,
|
||||||
|
pub show_chat: bool,
|
||||||
|
pub show_now_playing: bool,
|
||||||
|
pub audio: bool,
|
||||||
|
/// kbit/s of the stream without layers, as typed.
|
||||||
|
pub bitrate: Arc<str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The source properties dialog (also for adding text, colour and image
|
||||||
|
/// sources: `id` -1). Numbers as typed.
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct StudioSourceForm {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: Arc<str>,
|
||||||
|
pub kind: Arc<str>,
|
||||||
|
pub x: Arc<str>,
|
||||||
|
pub y: Arc<str>,
|
||||||
|
/// Empty: the source's own size times `scale`.
|
||||||
|
pub width: Arc<str>,
|
||||||
|
pub height: Arc<str>,
|
||||||
|
pub scale: Arc<str>,
|
||||||
|
/// contain, cover, stretch
|
||||||
|
pub fit: Arc<str>,
|
||||||
|
pub crop_left: Arc<str>,
|
||||||
|
pub crop_top: Arc<str>,
|
||||||
|
pub crop_right: Arc<str>,
|
||||||
|
pub crop_bottom: Arc<str>,
|
||||||
|
/// Percent.
|
||||||
|
pub opacity: f32,
|
||||||
|
pub locked: bool,
|
||||||
|
pub visible: bool,
|
||||||
|
/// keep, blur, image, colour
|
||||||
|
pub background: Arc<str>,
|
||||||
|
/// Blur radius in percent of the picture's height.
|
||||||
|
pub blur: Arc<str>,
|
||||||
|
pub background_path: Arc<str>,
|
||||||
|
pub background_colour: Arc<str>,
|
||||||
|
/// Text, colour ("#rrggbb" or "#rrggbbaa") and image sources.
|
||||||
|
pub text: Arc<str>,
|
||||||
|
pub text_size: Arc<str>,
|
||||||
|
pub colour: Arc<str>,
|
||||||
|
pub path: Arc<str>,
|
||||||
|
pub mirror: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The studio settings dialog (`studio.*` keys and the preview).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
|
pub struct StudioSettingsForm {
|
||||||
|
pub replay_seconds: Arc<str>,
|
||||||
|
pub replay_memory: Arc<str>,
|
||||||
|
pub recording_dir: Arc<str>,
|
||||||
|
pub preview_width: Arc<str>,
|
||||||
|
pub preview_fps: Arc<str>,
|
||||||
|
}
|
||||||
@@ -10,9 +10,10 @@ use voelin_model::{
|
|||||||
tree_rows,
|
tree_rows,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::app::{BadgeItem, MemberItem, TreeItem};
|
use crate::avatar;
|
||||||
|
use crate::bridge::{BadgeItem, MemberItem, TreeItem};
|
||||||
|
use crate::image::ImageRef;
|
||||||
use crate::settings::ClientPlaybackMap;
|
use crate::settings::ClientPlaybackMap;
|
||||||
use crate::vm::avatar;
|
|
||||||
|
|
||||||
/// A banner mode as the UI takes it (`TreeItem.banner-mode`).
|
/// A banner mode as the UI takes it (`TreeItem.banner-mode`).
|
||||||
pub fn banner_mode(mode: BannerMode) -> i32 {
|
pub fn banner_mode(mode: BannerMode) -> i32 {
|
||||||
@@ -24,12 +25,12 @@ pub fn banner_mode(mode: BannerMode) -> i32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The picture of a banner address, if the engine fetched it.
|
/// The picture of a banner address, if the engine fetched it.
|
||||||
pub fn banner(pictures: &HashMap<String, PathBuf>, url: Option<&str>) -> slint::Image {
|
pub fn banner(pictures: &HashMap<String, PathBuf>, url: Option<&str>) -> ImageRef {
|
||||||
avatar::image(url.and_then(|u| pictures.get(u)))
|
avatar::image(url.and_then(|u| pictures.get(u)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A badge's picture, if the engine fetched it.
|
/// A badge's picture, if the engine fetched it.
|
||||||
fn badge_icon(pictures: &HashMap<String, PathBuf>, guid: &str) -> slint::Image {
|
fn badge_icon(pictures: &HashMap<String, PathBuf>, guid: &str) -> ImageRef {
|
||||||
avatar::image(badges::icon_url(guid).and_then(|url| pictures.get(&url)))
|
avatar::image(badges::icon_url(guid).and_then(|url| pictures.get(&url)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,19 +80,19 @@ pub struct TreeInput<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TreeInput<'_> {
|
impl TreeInput<'_> {
|
||||||
fn avatar(&self, client: &ClientInfo) -> slint::Image {
|
fn avatar(&self, client: &ClientInfo) -> ImageRef {
|
||||||
avatar::image(client.uid.as_ref().and_then(|uid| self.avatars.get(uid)))
|
avatar::image(client.uid.as_ref().and_then(|uid| self.avatars.get(uid)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An icon by id, if the engine fetched it (0: none).
|
/// An icon by id, if the engine fetched it (0: none).
|
||||||
fn icon(&self, id: u32) -> Option<slint::Image> {
|
fn icon(&self, id: u32) -> Option<ImageRef> {
|
||||||
let path = self.icons.get(&id).filter(|_| id != 0)?;
|
let path = self.icons.get(&id).filter(|_| id != 0)?;
|
||||||
Some(avatar::image(Some(path))).filter(|i| i.size().width > 0)
|
Some(avatar::image(Some(path))).filter(|i| i.size().width > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The icons beside a client, as TeamSpeak shows them: its server
|
/// The icons beside a client, as TeamSpeak shows them: its server
|
||||||
/// groups' in display order, its channel group's, its own.
|
/// groups' in display order, its channel group's, its own.
|
||||||
fn client_icons(&self, client: &ClientInfo) -> Vec<slint::Image> {
|
fn client_icons(&self, client: &ClientInfo) -> Vec<ImageRef> {
|
||||||
let groups = self.groups.iter().filter(|g| client.server_groups.contains(&g.id));
|
let groups = self.groups.iter().filter(|g| client.server_groups.contains(&g.id));
|
||||||
let channel_group =
|
let channel_group =
|
||||||
self.channel_groups.iter().filter(|g| client.channel_group == Some(g.id));
|
self.channel_groups.iter().filter(|g| client.channel_group == Some(g.id));
|
||||||
@@ -105,7 +106,7 @@ impl TreeInput<'_> {
|
|||||||
|
|
||||||
/// The pictures of the badges a client shows that arrived, in its
|
/// The pictures of the badges a client shows that arrived, in its
|
||||||
/// order; empty slots last.
|
/// order; empty slots last.
|
||||||
fn badges(&self, client: &ClientInfo) -> [slint::Image; badges::SHOWN] {
|
fn badges(&self, client: &ClientInfo) -> [ImageRef; badges::SHOWN] {
|
||||||
let mut icons = client
|
let mut icons = client
|
||||||
.badges
|
.badges
|
||||||
.iter()
|
.iter()
|
||||||
@@ -384,7 +385,7 @@ impl TreeInput<'_> {
|
|||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
struct Section {
|
struct Section {
|
||||||
title: String,
|
title: String,
|
||||||
icon: slint::Image,
|
icon: ImageRef,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rows in sections: each section's first row carries the heading and how
|
/// Rows in sections: each section's first row carries the heading and how
|
||||||
@@ -456,7 +457,7 @@ pub fn matching(rows: Vec<MemberItem>, filter: &str) -> Vec<MemberItem> {
|
|||||||
pub fn server_members(input: &TreeInput, voice_first: bool) -> Vec<MemberItem> {
|
pub fn server_members(input: &TreeInput, voice_first: bool) -> Vec<MemberItem> {
|
||||||
let first = Section {
|
let first = Section {
|
||||||
title: if voice_first { "In Voice" } else { "Streaming" }.into(),
|
title: if voice_first { "In Voice" } else { "Streaming" }.into(),
|
||||||
icon: slint::Image::default(),
|
icon: ImageRef::default(),
|
||||||
};
|
};
|
||||||
let clients = input
|
let clients = input
|
||||||
.presence
|
.presence
|
||||||
@@ -596,7 +597,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
let (t, c, pb) = (HashSet::new(), HashSet::new(), ClientPlaybackMap::new());
|
let (t, c, pb) = (HashSet::new(), HashSet::new(), ClientPlaybackMap::new());
|
||||||
let rows = rows(&input(&p, &t, &c, &pb, "", &e));
|
let rows = rows(&input(&p, &t, &c, &pb, "", &e));
|
||||||
let width = |i: &slint::Image| i.size().width;
|
let width = |i: &ImageRef| i.size().width;
|
||||||
let lobby = &rows[0];
|
let lobby = &rows[0];
|
||||||
assert_eq!((width(&lobby.icon), width(&lobby.banner), lobby.banner_mode), (7, 9, 2));
|
assert_eq!((width(&lobby.icon), width(&lobby.banner), lobby.banner_mode), (7, 9, 2));
|
||||||
let alice = &rows[1];
|
let alice = &rows[1];
|
||||||
@@ -631,11 +632,11 @@ mod tests {
|
|||||||
pictures: HashMap::from([picture(0, 3), picture(2, 5), picture(3, 7)]),
|
pictures: HashMap::from([picture(0, 3), picture(2, 5), picture(3, 7)]),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let width = |i: &slint::Image| i.size().width;
|
let width = |i: &ImageRef| i.size().width;
|
||||||
let card = badge_items(&guids, &e.pictures);
|
let card = badge_items(&guids, &e.pictures);
|
||||||
let names: Vec<_> = card.iter().map(|b| b.name.as_str()).collect();
|
let names: Vec<_> = card.iter().map(|b| b.name.as_ref()).collect();
|
||||||
assert_eq!(names, ["20th Anniversary", "Badge", "April Fools!"]);
|
assert_eq!(names, ["20th Anniversary", "Badge", "April Fools!"]);
|
||||||
assert_eq!(card[1].description.as_str(), guids[1]);
|
assert_eq!(card[1].description.as_ref(), guids[1]);
|
||||||
assert_eq!(card.iter().map(|b| width(&b.icon)).collect::<Vec<_>>(), [3, 0, 5]);
|
assert_eq!(card.iter().map(|b| width(&b.icon)).collect::<Vec<_>>(), [3, 0, 5]);
|
||||||
|
|
||||||
let mut p = presence();
|
let mut p = presence();
|
||||||
@@ -697,7 +698,7 @@ mod tests {
|
|||||||
let c = HashSet::new();
|
let c = HashSet::new();
|
||||||
let rows = super::rows(&input(&p, &t, &c, &pb, "", &e));
|
let rows = super::rows(&input(&p, &t, &c, &pb, "", &e));
|
||||||
let chess = rows.iter().find(|r| r.is_channel && r.id == 3).unwrap();
|
let chess = rows.iter().find(|r| r.is_channel && r.id == 3).unwrap();
|
||||||
assert_eq!((chess.name.as_str(), chess.spacer), ("[cspacer1]Chess", 0));
|
assert_eq!((chess.name.as_ref(), chess.spacer), ("[cspacer1]Chess", 0));
|
||||||
assert_eq!(channel_title(&p.channels[&2]), ("Гамесы", Some(Spacer::Center)));
|
assert_eq!(channel_title(&p.channels[&2]), ("Гамесы", Some(Spacer::Center)));
|
||||||
assert_eq!(channel_title(&p.channels[&3]), ("[cspacer1]Chess", None));
|
assert_eq!(channel_title(&p.channels[&3]), ("[cspacer1]Chess", None));
|
||||||
// Lists and pickers leave out what only separates.
|
// Lists and pickers leave out what only separates.
|
||||||
@@ -737,12 +738,12 @@ mod tests {
|
|||||||
let (t, c, pb) = (HashSet::from([11]), HashSet::new(), ClientPlaybackMap::new());
|
let (t, c, pb) = (HashSet::from([11]), HashSet::new(), ClientPlaybackMap::new());
|
||||||
let e = Extras::default();
|
let e = Extras::default();
|
||||||
let rows = rows(&input(&p, &t, &c, &pb, "", &e));
|
let rows = rows(&input(&p, &t, &c, &pb, "", &e));
|
||||||
let names: Vec<_> = rows.iter().map(|r| r.name.as_str()).collect();
|
let names: Vec<_> = rows.iter().map(|r| r.name.as_ref()).collect();
|
||||||
assert_eq!(names, ["Lobby", "Alice", "Games", "bob", "Chess", "Carol"]);
|
assert_eq!(names, ["Lobby", "Alice", "Games", "bob", "Chess", "Carol"]);
|
||||||
assert_eq!((rows[0].members, rows[0].max_members), (1, -1));
|
assert_eq!((rows[0].members, rows[0].max_members), (1, -1));
|
||||||
assert_eq!((rows[2].members, rows[2].max_members, rows[2].own), (1, 5, true));
|
assert_eq!((rows[2].members, rows[2].max_members, rows[2].own), (1, 5, true));
|
||||||
assert!(rows[3].talking && rows[3].myself);
|
assert!(rows[3].talking && rows[3].myself);
|
||||||
assert_eq!(rows[3].initials, "BO");
|
assert_eq!(&*rows[3].initials, "BO");
|
||||||
assert_eq!(stats(&p), "3 online · 3 channels");
|
assert_eq!(stats(&p), "3 online · 3 channels");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -752,7 +753,7 @@ mod tests {
|
|||||||
let (t, c, pb) = (HashSet::new(), HashSet::new(), ClientPlaybackMap::new());
|
let (t, c, pb) = (HashSet::new(), HashSet::new(), ClientPlaybackMap::new());
|
||||||
let e = Extras::default();
|
let e = Extras::default();
|
||||||
let rows = rows(&input(&p, &t, &c, &pb, "car", &e));
|
let rows = rows(&input(&p, &t, &c, &pb, "car", &e));
|
||||||
let names: Vec<_> = rows.iter().map(|r| r.name.as_str()).collect();
|
let names: Vec<_> = rows.iter().map(|r| r.name.as_ref()).collect();
|
||||||
assert_eq!(names, ["Games", "Chess", "Carol"]);
|
assert_eq!(names, ["Games", "Chess", "Carol"]);
|
||||||
let rows = super::rows(&input(&p, &t, &c, &pb, "LOBBY", &e));
|
let rows = super::rows(&input(&p, &t, &c, &pb, "LOBBY", &e));
|
||||||
assert_eq!(rows.len(), 1);
|
assert_eq!(rows.len(), 1);
|
||||||
@@ -766,7 +767,7 @@ mod tests {
|
|||||||
let (t, c, pb) = (HashSet::new(), HashSet::new(), ClientPlaybackMap::new());
|
let (t, c, pb) = (HashSet::new(), HashSet::new(), ClientPlaybackMap::new());
|
||||||
let e = Extras::default();
|
let e = Extras::default();
|
||||||
let members = members(&input(&p, &t, &c, &pb, "", &e));
|
let members = members(&input(&p, &t, &c, &pb, "", &e));
|
||||||
let names: Vec<_> = members.iter().map(|m| (m.name.as_str(), m.status.as_str())).collect();
|
let names: Vec<_> = members.iter().map(|m| (m.name.as_ref(), m.status.as_ref())).collect();
|
||||||
assert_eq!(names, [("bob", "Listening"), ("Carol", "Away")]);
|
assert_eq!(names, [("bob", "Listening"), ("Carol", "Away")]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -790,7 +791,7 @@ mod tests {
|
|||||||
let (t, c, pb) = (HashSet::new(), HashSet::new(), ClientPlaybackMap::new());
|
let (t, c, pb) = (HashSet::new(), HashSet::new(), ClientPlaybackMap::new());
|
||||||
let members = members(&input(&p, &t, &c, &pb, "", &e));
|
let members = members(&input(&p, &t, &c, &pb, "", &e));
|
||||||
let rows: Vec<_> =
|
let rows: Vec<_> =
|
||||||
members.iter().map(|m| (m.name.as_str(), m.group.as_str(), m.first_in_group)).collect();
|
members.iter().map(|m| (m.name.as_ref(), m.group.as_ref(), m.first_in_group)).collect();
|
||||||
assert_eq!(rows, [("Carol", "Server Admin", true), ("bob", "Guest", true)]);
|
assert_eq!(rows, [("Carol", "Server Admin", true), ("bob", "Guest", true)]);
|
||||||
assert!(members[0].admin && !members[1].admin);
|
assert!(members[0].admin && !members[1].admin);
|
||||||
}
|
}
|
||||||
@@ -884,12 +885,14 @@ mod tests {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
let all = server_members(&input(&p, &t, &c, &pb, "", &e), false);
|
let all = server_members(&input(&p, &t, &c, &pb, "", &e), false);
|
||||||
assert_eq!(all[1].role, "Moderator");
|
assert_eq!(&*all[1].role, "Moderator");
|
||||||
assert!(!all[1].admin);
|
assert!(!all[1].admin);
|
||||||
// The search keeps the sections of what it finds.
|
// The search keeps the sections of what it finds.
|
||||||
let found = matching(all, "al");
|
let found = matching(all, "al");
|
||||||
assert_eq!(found.len(), 1);
|
assert_eq!(found.len(), 1);
|
||||||
assert!(found[0].first_in_group && found[0].group == "Guest" && found[0].group_count == 1);
|
assert!(
|
||||||
|
found[0].first_in_group && &*found[0].group == "Guest" && found[0].group_count == 1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -24,8 +24,6 @@ dirs = "6"
|
|||||||
# avatars, icons and banners on TeamSpeak servers are GIF and WebP too (the
|
# avatars, icons and banners on TeamSpeak servers are GIF and WebP too (the
|
||||||
# decoders are in the tree already, for SVG pictures).
|
# decoders are in the tree already, for SVG pictures).
|
||||||
image = { version = "0.25", default-features = false, features = ["gif", "webp", "bmp", "ico"] }
|
image = { version = "0.25", default-features = false, features = ["gif", "webp", "bmp", "ico"] }
|
||||||
# Twemoji archive blocks (raw deflate); already used by png.
|
|
||||||
miniz_oxide = "0.8"
|
|
||||||
png = "0.18"
|
png = "0.18"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
# Settings and gateway values as JSON (the advanced and integrations pages).
|
# Settings and gateway values as JSON (the advanced and integrations pages).
|
||||||
@@ -44,6 +42,7 @@ voelin-model = { path = "../voelin-model" }
|
|||||||
voelin-platform = { path = "../voelin-platform", default-features = false }
|
voelin-platform = { path = "../voelin-platform", default-features = false }
|
||||||
voelin-query = { path = "../voelin-query" }
|
voelin-query = { path = "../voelin-query" }
|
||||||
voelin-store = { path = "../voelin-store" }
|
voelin-store = { path = "../voelin-store" }
|
||||||
|
voelin-ui-vm = { path = "../voelin-ui-vm" }
|
||||||
tsclientlib = { path = "../proto/tsclientlib" }
|
tsclientlib = { path = "../proto/tsclientlib" }
|
||||||
|
|
||||||
# Desktop: the keyring for passwords, stream media with libvpx, OpenH264, X11
|
# Desktop: the keyring for passwords, stream media with libvpx, OpenH264, X11
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
# Bundled assets
|
# Bundled assets
|
||||||
|
|
||||||
- `twemoji.bin`: the Twemoji 15.0 SVGs (3720 emoji, from the `@twemoji/svg`
|
The Twemoji archive is with the code that reads it, in
|
||||||
15.0.0 package) packed by `scripts/pack-twemoji.py` into blocks of raw
|
`crates/voelin-ui-vm/assets/` (its license note is there).
|
||||||
deflate with an index; `src/emoji.rs` reads it. Twemoji graphics by Twitter,
|
|
||||||
Inc and other contributors, licensed under CC-BY 4.0
|
|
||||||
(https://creativecommons.org/licenses/by/4.0/). The files are unchanged
|
|
||||||
apart from surrounding whitespace.
|
|
||||||
|
|
||||||
The fonts (Inter, SIL OFL 1.1) and icons (Lucide, ISC) that the Slint files
|
The fonts (Inter, SIL OFL 1.1) and icons (Lucide, ISC) that the Slint files
|
||||||
import are under `ui/assets/`, each with its license. All three are credited
|
import are under `ui/assets/`, each with its license. All three are credited
|
||||||
|
|||||||
+121
-544
@@ -3,11 +3,12 @@
|
|||||||
//!
|
//!
|
||||||
//! The screens' logic is elsewhere: servers and the channel tree in
|
//! The screens' logic is elsewhere: servers and the channel tree in
|
||||||
//! `servers.rs`, chat in `chat.rs`, streams in `streams.rs`, the settings
|
//! `servers.rs`, chat in `chat.rs`, streams in `streams.rs`, the settings
|
||||||
//! page in `settings_page.rs` and `appearance.rs`, the view models in `vm/`,
|
//! page in `settings_page.rs` and `appearance.rs`, the settings pages in
|
||||||
//! callbacks in `bind/`, development switches in `dev.rs`.
|
//! `settings_pages/`, the Stream Studio in `studio/`, the view models in the
|
||||||
|
//! `voelin-ui-vm` crate (`vm`), callbacks in `bind/`, development switches in
|
||||||
|
//! `dev.rs`.
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::{HashMap, HashSet};
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -22,22 +23,19 @@ use voelin_core::settings::{
|
|||||||
AUDIO, CRASH_REPORTS, IDENTITY_IMPORT, STREAM_DECODER_BACKEND, STREAM_HARDWARE_DECODING,
|
AUDIO, CRASH_REPORTS, IDENTITY_IMPORT, STREAM_DECODER_BACKEND, STREAM_HARDWARE_DECODING,
|
||||||
Settings,
|
Settings,
|
||||||
};
|
};
|
||||||
use voelin_core::stream::StreamInfo;
|
|
||||||
use voelin_core::{
|
use voelin_core::{
|
||||||
AudioSettings, BackendInfo, Command, Engine, Event, History, HistoryMessage, ObserveState,
|
AudioSettings, BackendInfo, Command, Engine, Event, History, ObserveState, VoiceState,
|
||||||
SessionState, VoiceState,
|
|
||||||
};
|
};
|
||||||
use voelin_model::{Capabilities, ChannelId, ChatMessage, ChatTarget, GroupInfo, Presence};
|
use voelin_model::ChatTarget;
|
||||||
use voelin_platform::crash;
|
use voelin_platform::crash;
|
||||||
use voelin_store::{Bookmark, MemorySecrets, Secrets, Store};
|
use voelin_store::{Bookmark, MemorySecrets, Secrets, Store};
|
||||||
|
|
||||||
|
use crate::bind::rows::Rows;
|
||||||
use crate::hotkey::GlobalPtt;
|
use crate::hotkey::GlobalPtt;
|
||||||
use crate::settings::{
|
use crate::settings::{CLIENT_PLAYBACK, ClientPlaybackMap, UI, UiSettings, appearance_keys};
|
||||||
CLIENT_PLAYBACK, ClientPlaybackMap, DeviceChoices, UI, UiSettings, appearance_keys,
|
|
||||||
};
|
|
||||||
use crate::streams::{Share, Watch};
|
use crate::streams::{Share, Watch};
|
||||||
use crate::video::Video;
|
use crate::video::Video;
|
||||||
use crate::vm::chat::Previous;
|
use crate::vm;
|
||||||
|
|
||||||
slint::include_modules!();
|
slint::include_modules!();
|
||||||
|
|
||||||
@@ -58,7 +56,7 @@ fn open_settings(dir: &Path, overrides: &[String]) -> Settings {
|
|||||||
for key in crate::settings::page_keys() {
|
for key in crate::settings::page_keys() {
|
||||||
prefs.register(key);
|
prefs.register(key);
|
||||||
}
|
}
|
||||||
prefs.register(&crate::studio::STUDIO_UI);
|
prefs.register(&crate::vm::studio::logic::STUDIO_UI);
|
||||||
let config = std::env::var_os("VOELIN_CONFIG")
|
let config = std::env::var_os("VOELIN_CONFIG")
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.or_else(|| Some(dir.join("config.toml")).filter(|p| p.exists()));
|
.or_else(|| Some(dir.join("config.toml")).filter(|p| p.exists()));
|
||||||
@@ -118,420 +116,72 @@ impl Secrets for FallbackSecrets {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A message of a chat with the handle the UI knows it by: the engine's
|
/// The lines of a chat as the chat view shows them.
|
||||||
/// local ids are 64 bit, a Slint `int` is not.
|
pub(crate) type ChatRows = Rows<vm::bridge::ChatLine>;
|
||||||
pub(crate) struct Msg {
|
|
||||||
pub key: i32,
|
|
||||||
pub message: HistoryMessage,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A chat of a session: its lines are the model the chat view shows while
|
/// A chat of a session (see `voelin_ui_vm::state`).
|
||||||
/// the tab is selected, so a new message is one row appended.
|
pub(crate) type Tab = vm::state::Tab<ChatRows>;
|
||||||
pub(crate) struct Tab {
|
|
||||||
pub target: ChatTarget,
|
|
||||||
pub title: String,
|
|
||||||
pub lines: Rc<VecModel<ChatLine>>,
|
|
||||||
/// The messages, oldest first, by `(ts_ms, id)`.
|
|
||||||
pub messages: Vec<Msg>,
|
|
||||||
/// Live messages of a session that keeps no history (no server unique
|
|
||||||
/// id yet): grouped from the message before, without ids.
|
|
||||||
pub last: Option<Previous>,
|
|
||||||
/// Messages not read, not ours: those after `read` (without stored
|
|
||||||
/// history, those that came while the tab was not on screen).
|
|
||||||
pub unread: i32,
|
|
||||||
/// The newest message read, by `(ts_ms, id)`: kept in the store
|
|
||||||
/// (`chat_reads`) when the tab is left, the session closes and on exit
|
|
||||||
/// (`App::save_read`). `stored_read` is what the store has.
|
|
||||||
pub read: Option<(i64, i64)>,
|
|
||||||
pub stored_read: Option<(i64, i64)>,
|
|
||||||
/// The message the "New" divider is above: the first that was new when
|
|
||||||
/// the tab came on screen. It stays until the tab is left.
|
|
||||||
pub divider: Option<i64>,
|
|
||||||
/// Nothing older exists as far as the engine can tell.
|
|
||||||
pub complete: bool,
|
|
||||||
/// A gateway page arrived: the chat is not only what we saw.
|
|
||||||
pub synced: bool,
|
|
||||||
/// An older page was asked for.
|
|
||||||
pub loading: bool,
|
|
||||||
/// The next message handle.
|
|
||||||
next_key: i32,
|
|
||||||
/// The pins of this chat, once asked for.
|
|
||||||
pub pins: Vec<crate::chat::PinRow>,
|
|
||||||
pub pins_loaded: bool,
|
|
||||||
/// The gateway topics of this chat, and the open one with its messages.
|
|
||||||
pub topics: Vec<voelin_gateway_proto::TopicInfo>,
|
|
||||||
pub topics_loaded: bool,
|
|
||||||
pub topic: Option<i64>,
|
|
||||||
pub topic_messages: Vec<Msg>,
|
|
||||||
/// The message jumped to from the pins.
|
|
||||||
pub marked: Option<i64>,
|
|
||||||
/// What the lines of `messages` were built from.
|
|
||||||
pub cache: crate::vm::chat::LineCache,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Tab {
|
|
||||||
pub fn new(target: ChatTarget, title: String) -> Self {
|
|
||||||
Self {
|
|
||||||
target,
|
|
||||||
title,
|
|
||||||
lines: Rc::new(VecModel::default()),
|
|
||||||
messages: Vec::new(),
|
|
||||||
last: None,
|
|
||||||
unread: 0,
|
|
||||||
read: None,
|
|
||||||
stored_read: None,
|
|
||||||
divider: None,
|
|
||||||
complete: false,
|
|
||||||
synced: false,
|
|
||||||
loading: false,
|
|
||||||
next_key: 1,
|
|
||||||
pins: Vec::new(),
|
|
||||||
pins_loaded: false,
|
|
||||||
topics: Vec::new(),
|
|
||||||
topics_loaded: false,
|
|
||||||
topic: None,
|
|
||||||
topic_messages: Vec::new(),
|
|
||||||
marked: None,
|
|
||||||
cache: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A private chat (on the Direct Messages page, not in the chat strip).
|
|
||||||
pub fn is_private(&self) -> bool {
|
|
||||||
matches!(self.target, ChatTarget::Private(_))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A handle for a message that has none yet.
|
|
||||||
pub fn take_key(&mut self) -> i32 {
|
|
||||||
self.next_key += 1;
|
|
||||||
self.next_key
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn message(&self, key: i32) -> Option<&HistoryMessage> {
|
|
||||||
self.messages.iter().chain(&self.topic_messages).find(|m| m.key == key).map(|m| &m.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Where each message is and whether it is ours (`own`), for the read
|
|
||||||
/// markers ([`crate::vm::chat::first_unread`]).
|
|
||||||
pub fn positions(&self, own: impl Fn(&ChatMessage) -> bool) -> Vec<(i64, i64, bool)> {
|
|
||||||
self.messages
|
|
||||||
.iter()
|
|
||||||
.map(|m| (m.message.message.ts_ms, m.message.id, own(&m.message.message)))
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Where the newest message is.
|
|
||||||
pub fn newest(&self) -> Option<(i64, i64)> {
|
|
||||||
self.messages.last().map(|m| (m.message.message.ts_ms, m.message.id))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The tab came on screen: the first new message gets the divider
|
|
||||||
/// (unless one shows), and everything is read.
|
|
||||||
pub fn enter(&mut self, own: impl Fn(&ChatMessage) -> bool) {
|
|
||||||
if self.unread > 0 && self.divider.is_none() {
|
|
||||||
let first = crate::vm::chat::first_unread(&self.positions(own), self.read);
|
|
||||||
self.divider = first.map(|i| self.messages[i].message.id);
|
|
||||||
}
|
|
||||||
self.catch_up();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Everything in the tab is read (it is on screen).
|
|
||||||
pub fn catch_up(&mut self) {
|
|
||||||
self.read = self.read.max(self.newest());
|
|
||||||
self.unread = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Count what is not read: what came after `read`, not ours.
|
|
||||||
pub fn count_unread(&mut self, own: impl Fn(&ChatMessage) -> bool) {
|
|
||||||
self.unread = crate::vm::chat::unread_count(&self.positions(own), self.read);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Start from where the store says the chat was read (`reads`: by the
|
|
||||||
/// store's name of the chat).
|
|
||||||
pub fn read_from(&mut self, reads: &HashMap<String, (i64, i64)>) {
|
|
||||||
if let Some(&read) = reads.get(&crate::chat::store_target(&self.target).key()) {
|
|
||||||
self.read = self.read.max(Some(read));
|
|
||||||
self.stored_read = Some(read);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// What we know about one server session.
|
/// What we know about one server session.
|
||||||
pub(crate) struct SessionView {
|
pub(crate) type SessionView = vm::state::SessionView<ChatRows>;
|
||||||
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>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for SessionView {
|
/// What the screens share, apart from the window and the engine.
|
||||||
fn default() -> Self {
|
pub(crate) type AppState = vm::state::AppState<ChatRows>;
|
||||||
Self {
|
|
||||||
state: SessionState::default(),
|
|
||||||
capabilities: Capabilities::default(),
|
|
||||||
presence: Arc::default(),
|
|
||||||
collapsed: HashSet::new(),
|
|
||||||
talking: HashSet::new(),
|
|
||||||
tabs: vec![Tab::new(ChatTarget::Server, "Server".into())],
|
|
||||||
current_tab: 0,
|
|
||||||
channel_tab: ChatTarget::Server,
|
|
||||||
focused_own_channel: false,
|
|
||||||
streams: Vec::new(),
|
|
||||||
applied_playback: HashSet::new(),
|
|
||||||
avatars: HashMap::new(),
|
|
||||||
icons: HashMap::new(),
|
|
||||||
pictures: HashMap::new(),
|
|
||||||
server_icon: 0,
|
|
||||||
icon_address: None,
|
|
||||||
server_groups: Vec::new(),
|
|
||||||
channel_groups: Vec::new(),
|
|
||||||
gateway_caps: Vec::new(),
|
|
||||||
member_card: None,
|
|
||||||
channel_passwords: HashMap::new(),
|
|
||||||
join_after_connect: None,
|
|
||||||
stream_viewers: HashMap::new(),
|
|
||||||
downloads: HashMap::new(),
|
|
||||||
next_transfer: 1,
|
|
||||||
extra: Default::default(),
|
|
||||||
reads: HashMap::new(),
|
|
||||||
reads_of: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SessionView {
|
|
||||||
/// Streams can be watched and shared: TeamSpeak 6, connected with voice.
|
|
||||||
pub fn streams_available(&self) -> bool {
|
|
||||||
self.capabilities.streams && self.state.voice == VoiceState::Connected
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The channel a client is in.
|
|
||||||
pub fn channel_of(&self, client: u16) -> Option<u64> {
|
|
||||||
self.presence.clients.get(&client).map(|c| c.channel)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The name of a client's channel when it is not ours; empty in ours.
|
|
||||||
pub fn other_channel_name(&self, client: u16) -> String {
|
|
||||||
self.channel_of(client)
|
|
||||||
.filter(|c| Some(*c) != self.state.own_channel)
|
|
||||||
.and_then(|c| self.presence.channels.get(&c))
|
|
||||||
.map_or_else(String::new, |c| crate::vm::tree::channel_title(c).0.to_owned())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A client's nickname, or its id.
|
|
||||||
pub fn nickname(&self, client: u16) -> String {
|
|
||||||
self.presence
|
|
||||||
.clients
|
|
||||||
.get(&client)
|
|
||||||
.map_or_else(|| format!("client {client}"), |c| c.nickname.clone())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Unread messages in the server's and the channels' chats (the rail and
|
|
||||||
/// the chat strip count them; private chats count on the Direct
|
|
||||||
/// Messages page).
|
|
||||||
pub fn channel_unread(&self) -> i32 {
|
|
||||||
self.tabs.iter().filter(|t| !t.is_private()).map(|t| t.unread).sum()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Unread messages in private chats.
|
|
||||||
pub fn private_unread(&self) -> i32 {
|
|
||||||
self.tabs.iter().filter(|t| t.is_private()).map(|t| t.unread).sum()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Make tab `index` the current one; the chat strip remembers it unless
|
|
||||||
/// it is a private chat.
|
|
||||||
pub fn set_current_tab(&mut self, index: usize) {
|
|
||||||
self.current_tab = index;
|
|
||||||
if let Some(tab) = self.tabs.get(index).filter(|t| !t.is_private()) {
|
|
||||||
self.channel_tab = tab.target.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Focus tab `index`. While a private chat is current (the Direct
|
|
||||||
/// Messages page shows it, and its composer sends there), a chat of the
|
|
||||||
/// strip does not take its place: it is the strip's chat, current once
|
|
||||||
/// that page is left (voice connecting focuses its channel's chat).
|
|
||||||
pub fn focus_tab(&mut self, index: usize) {
|
|
||||||
let Some(tab) = self.tabs.get(index) else { return };
|
|
||||||
if !tab.is_private() && self.tabs.get(self.current_tab).is_some_and(Tab::is_private) {
|
|
||||||
self.channel_tab = tab.target.clone();
|
|
||||||
} else {
|
|
||||||
self.set_current_tab(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Remove tab `index`. The current tab stays; when it is this one, the
|
|
||||||
/// chat strip's next tab takes its place, else its last.
|
|
||||||
pub fn remove_tab(&mut self, index: usize) -> Tab {
|
|
||||||
let tab = self.tabs.remove(index);
|
|
||||||
if self.current_tab > index {
|
|
||||||
self.current_tab -= 1;
|
|
||||||
} else if self.current_tab == index {
|
|
||||||
let (strip, _) = crate::vm::chat::strip(self.tabs.iter().map(|t| &t.target), 0);
|
|
||||||
let next = strip.iter().find(|&&i| i >= index).or(strip.last()).copied();
|
|
||||||
self.set_current_tab(next.unwrap_or(0));
|
|
||||||
}
|
|
||||||
tab
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Leave a current private chat for the chat strip's last one (the
|
|
||||||
/// Direct Messages page was left); `true` if the current tab changed.
|
|
||||||
pub fn leave_private(&mut self) -> bool {
|
|
||||||
if !self.tabs.get(self.current_tab).is_some_and(Tab::is_private) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
self.current_tab = self.tabs.iter().position(|t| t.target == self.channel_tab).unwrap_or(0);
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A new tab for `target`, read as far as the store says.
|
|
||||||
pub fn new_tab(&self, target: ChatTarget, title: String) -> Tab {
|
|
||||||
let mut tab = Tab::new(target, title);
|
|
||||||
tab.read_from(&self.reads);
|
|
||||||
tab
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The session's gateway offers this feature
|
|
||||||
/// (`voelin_gateway_proto::feature`).
|
|
||||||
pub fn gateway_has(&self, feature: &str) -> bool {
|
|
||||||
self.gateway_caps.iter().any(|c| c == feature)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The chat history is kept by the engine (it knows the server): its
|
|
||||||
/// messages come with ids, reactions and pins.
|
|
||||||
pub fn has_history(&self) -> bool {
|
|
||||||
self.state.server_uid.is_some()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The avatar picture of a client, if the engine fetched one.
|
|
||||||
pub fn avatar(&self, client: u16) -> Option<&PathBuf> {
|
|
||||||
let uid = self.presence.clients.get(&client)?.uid.as_deref()?;
|
|
||||||
self.avatars.get(uid)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The server's icon, if it has one and the engine fetched it.
|
|
||||||
pub fn server_icon(&self) -> slint::Image {
|
|
||||||
crate::vm::avatar::image(
|
|
||||||
self.icons.get(&self.server_icon).filter(|_| self.server_icon != 0),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Icons stay associated with the address that supplied them, including
|
|
||||||
/// while a reconnect to an edited bookmark is pending or has failed.
|
|
||||||
pub fn server_icon_for(&self, address: &str) -> slint::Image {
|
|
||||||
if self.icon_address.as_deref() == Some(address) {
|
|
||||||
self.server_icon()
|
|
||||||
} else {
|
|
||||||
slint::Image::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The models the Bridge shows, created once and updated row by row
|
/// The models the Bridge shows, created once and updated row by row
|
||||||
/// (`vm::list::sync`).
|
/// ([`Rows::sync`]).
|
||||||
pub(crate) struct Models {
|
pub(crate) struct Models {
|
||||||
pub servers: Rc<VecModel<ServerItem>>,
|
pub servers: Rows<vm::bridge::ServerItem>,
|
||||||
pub tree: Rc<VecModel<TreeItem>>,
|
pub tree: Rows<vm::bridge::TreeItem>,
|
||||||
pub members: Rc<VecModel<MemberItem>>,
|
pub members: Rows<vm::bridge::MemberItem>,
|
||||||
pub server_members: Rc<VecModel<MemberItem>>,
|
pub server_members: Rows<vm::bridge::MemberItem>,
|
||||||
/// The chat strip: the current session's tabs without its private chats.
|
/// The chat strip: the current session's tabs without its private chats.
|
||||||
pub tabs: Rc<VecModel<ChatTab>>,
|
pub tabs: Rows<vm::bridge::ChatTab>,
|
||||||
/// Which of the session's tabs each of `tabs` is ([`crate::vm::chat::strip`]).
|
/// Which of the session's tabs each of `tabs` is ([`crate::vm::chat::strip`]).
|
||||||
pub strip: RefCell<Vec<usize>>,
|
pub strip: RefCell<Vec<usize>>,
|
||||||
pub streams: Rc<VecModel<StreamItem>>,
|
pub streams: Rows<vm::bridge::StreamItem>,
|
||||||
pub viewers: Rc<VecModel<ViewerItem>>,
|
pub viewers: Rows<vm::bridge::ViewerItem>,
|
||||||
pub pins: Rc<VecModel<PinItem>>,
|
pub pins: Rows<vm::bridge::PinItem>,
|
||||||
pub topics: Rc<VecModel<TopicItem>>,
|
pub topics: Rows<vm::bridge::TopicItem>,
|
||||||
pub topic_messages: Rc<VecModel<ChatLine>>,
|
pub topic_messages: Rows<vm::bridge::ChatLine>,
|
||||||
/// The quality choices of the watched stream.
|
/// The quality choices of the watched stream.
|
||||||
pub qualities: Rc<VecModel<slint::SharedString>>,
|
pub qualities: Rows<Arc<str>>,
|
||||||
/// Shown when there is no chat.
|
/// Shown when there is no chat.
|
||||||
pub no_chat: Rc<VecModel<ChatLine>>,
|
pub no_chat: Rows<vm::bridge::ChatLine>,
|
||||||
/// Home, friends, messages, the bell, the search, events.
|
/// Home, friends, messages, the bell, the search, events.
|
||||||
pub social: crate::social::SocialModels,
|
pub social: crate::social::SocialModels,
|
||||||
/// Settings pages.
|
/// Settings pages.
|
||||||
pub layers: Rc<VecModel<LayerItem>>,
|
pub layers: Rows<vm::bridge::LayerItem>,
|
||||||
pub audio_sources: Rc<VecModel<AudioSourceItem>>,
|
pub audio_sources: Rows<vm::bridge::AudioSourceItem>,
|
||||||
pub identities: Rc<VecModel<IdentityItem>>,
|
pub identities: Rows<vm::bridge::IdentityItem>,
|
||||||
pub gateway_config: Rc<VecModel<ConfigItem>>,
|
pub gateway_config: Rows<vm::bridge::ConfigItem>,
|
||||||
pub gateway_perms: Rc<VecModel<PermItem>>,
|
pub gateway_perms: Rows<vm::bridge::PermItem>,
|
||||||
pub all_settings: Rc<VecModel<SettingItem>>,
|
pub all_settings: Rows<vm::bridge::SettingItem>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Models {
|
impl Models {
|
||||||
fn new(bridge: &Bridge) -> Self {
|
fn new(bridge: &Bridge) -> Self {
|
||||||
let models = Self {
|
let models = Self {
|
||||||
servers: Rc::default(),
|
servers: Rows::default(),
|
||||||
tree: Rc::default(),
|
tree: Rows::default(),
|
||||||
members: Rc::default(),
|
members: Rows::default(),
|
||||||
server_members: Rc::default(),
|
server_members: Rows::default(),
|
||||||
tabs: Rc::default(),
|
tabs: Rows::default(),
|
||||||
strip: RefCell::new(vec![0]),
|
strip: RefCell::new(vec![0]),
|
||||||
streams: Rc::default(),
|
streams: Rows::default(),
|
||||||
viewers: Rc::default(),
|
viewers: Rows::default(),
|
||||||
pins: Rc::default(),
|
pins: Rows::default(),
|
||||||
topics: Rc::default(),
|
topics: Rows::default(),
|
||||||
topic_messages: Rc::default(),
|
topic_messages: Rows::default(),
|
||||||
qualities: Rc::default(),
|
qualities: Rows::default(),
|
||||||
no_chat: Rc::default(),
|
no_chat: Rows::default(),
|
||||||
social: crate::social::SocialModels::new(bridge),
|
social: crate::social::SocialModels::new(bridge),
|
||||||
layers: Rc::default(),
|
layers: Rows::default(),
|
||||||
audio_sources: Rc::default(),
|
audio_sources: Rows::default(),
|
||||||
identities: Rc::default(),
|
identities: Rows::default(),
|
||||||
gateway_config: Rc::default(),
|
gateway_config: Rows::default(),
|
||||||
gateway_perms: Rc::default(),
|
gateway_perms: Rows::default(),
|
||||||
all_settings: Rc::default(),
|
all_settings: Rows::default(),
|
||||||
};
|
};
|
||||||
models.attach(bridge);
|
models.attach(bridge);
|
||||||
models
|
models
|
||||||
@@ -540,24 +190,24 @@ impl Models {
|
|||||||
/// Show the models in `bridge`: the main window's, and the viewer's own
|
/// Show the models in `bridge`: the main window's, and the viewer's own
|
||||||
/// window's (its player reads the stream's qualities).
|
/// window's (its player reads the stream's qualities).
|
||||||
pub(crate) fn attach(&self, bridge: &Bridge) {
|
pub(crate) fn attach(&self, bridge: &Bridge) {
|
||||||
bridge.set_servers(ModelRc::from(self.servers.clone()));
|
bridge.set_servers(self.servers.model());
|
||||||
bridge.set_tree(ModelRc::from(self.tree.clone()));
|
bridge.set_tree(self.tree.model());
|
||||||
bridge.set_members(ModelRc::from(self.members.clone()));
|
bridge.set_members(self.members.model());
|
||||||
bridge.set_server_members(ModelRc::from(self.server_members.clone()));
|
bridge.set_server_members(self.server_members.model());
|
||||||
bridge.set_tabs(ModelRc::from(self.tabs.clone()));
|
bridge.set_tabs(self.tabs.model());
|
||||||
bridge.set_streams(ModelRc::from(self.streams.clone()));
|
bridge.set_streams(self.streams.model());
|
||||||
bridge.set_share_viewers(ModelRc::from(self.viewers.clone()));
|
bridge.set_share_viewers(self.viewers.model());
|
||||||
bridge.set_pins(ModelRc::from(self.pins.clone()));
|
bridge.set_pins(self.pins.model());
|
||||||
bridge.set_topics(ModelRc::from(self.topics.clone()));
|
bridge.set_topics(self.topics.model());
|
||||||
bridge.set_topic_messages(ModelRc::from(self.topic_messages.clone()));
|
bridge.set_topic_messages(self.topic_messages.model());
|
||||||
bridge.set_viewer_qualities(ModelRc::from(self.qualities.clone()));
|
bridge.set_viewer_qualities(self.qualities.model());
|
||||||
bridge.set_messages(ModelRc::from(self.no_chat.clone()));
|
bridge.set_messages(self.no_chat.model());
|
||||||
bridge.set_layers(ModelRc::from(self.layers.clone()));
|
bridge.set_layers(self.layers.model());
|
||||||
bridge.set_audio_sources(ModelRc::from(self.audio_sources.clone()));
|
bridge.set_audio_sources(self.audio_sources.model());
|
||||||
bridge.set_identities(ModelRc::from(self.identities.clone()));
|
bridge.set_identities(self.identities.model());
|
||||||
bridge.set_gateway_config(ModelRc::from(self.gateway_config.clone()));
|
bridge.set_gateway_config(self.gateway_config.model());
|
||||||
bridge.set_gateway_perms(ModelRc::from(self.gateway_perms.clone()));
|
bridge.set_gateway_perms(self.gateway_perms.model());
|
||||||
bridge.set_all_settings(ModelRc::from(self.all_settings.clone()));
|
bridge.set_all_settings(self.all_settings.model());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -567,80 +217,33 @@ pub(crate) struct App {
|
|||||||
pub secrets: Box<dyn Secrets>,
|
pub secrets: Box<dyn Secrets>,
|
||||||
pub engine: Engine,
|
pub engine: Engine,
|
||||||
pub identity: tsclientlib::Identity,
|
pub identity: tsclientlib::Identity,
|
||||||
pub bookmarks: Vec<Bookmark>,
|
/// The data the screens share (`voelin_ui_vm::state`).
|
||||||
pub current: Option<i64>,
|
pub state: AppState,
|
||||||
pub sessions: HashMap<i64, SessionView>,
|
|
||||||
pub models: Models,
|
pub models: Models,
|
||||||
pub status: String,
|
/// The settings service (shared with the engine); `state.settings`,
|
||||||
/// What the toast of the next copy says instead of "Copied" (an invite
|
/// `state.audio` and `state.playback` are working copies of its keys.
|
||||||
/// 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.
|
|
||||||
pub prefs: Settings,
|
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 ptt: GlobalPtt,
|
||||||
pub video: Video,
|
pub video: Video,
|
||||||
/// Our stream.
|
/// Our stream.
|
||||||
pub share: Option<Share>,
|
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.
|
/// The stream in the viewer.
|
||||||
pub watch: Option<Watch>,
|
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.
|
/// `VOELIN_DEMO_STREAM`: the viewer shows a local test stream.
|
||||||
pub demo: bool,
|
pub demo: bool,
|
||||||
/// `VOELIN_DEMO_UI`: sample servers, channels and chat (dev.rs).
|
/// `VOELIN_DEMO_UI`: sample servers, channels and chat (dev.rs).
|
||||||
pub demo_ui: bool,
|
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.
|
/// `VOELIN_AUTOSHARE=test-pattern`: share the test pattern once streams work.
|
||||||
pub autoshare: bool,
|
pub autoshare: bool,
|
||||||
/// `VOELIN_OPEN=client`: open the volume dialog of the first other client.
|
/// `VOELIN_OPEN=client`: open the volume dialog of the first other client.
|
||||||
pub open_client_pending: bool,
|
pub open_client_pending: bool,
|
||||||
/// The notices are in the About page's model.
|
/// The notices are in the About page's model.
|
||||||
pub notices_loaded: bool,
|
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.
|
/// Home, friends, messages, the bell and the search.
|
||||||
pub social: crate::social::Social,
|
pub social: crate::social::Social,
|
||||||
/// The settings pages of the new design.
|
/// The settings pages of the new design.
|
||||||
pub pages: crate::settings_pages::Pages,
|
pub pages: crate::settings_pages::Pages,
|
||||||
/// The Stream Studio (studio.rs).
|
/// The Stream Studio (studio/).
|
||||||
pub studio: crate::studio::StudioState,
|
pub studio: crate::studio::StudioState,
|
||||||
/// The stream's own window (popout.rs).
|
/// The stream's own window (popout.rs).
|
||||||
pub popout: crate::popout::Popout,
|
pub popout: crate::popout::Popout,
|
||||||
@@ -829,44 +432,18 @@ pub fn run(options: RunOptions) -> Result<()> {
|
|||||||
}),
|
}),
|
||||||
engine: engine.clone(),
|
engine: engine.clone(),
|
||||||
identity,
|
identity,
|
||||||
current: bookmarks.first().map(|b| b.id),
|
state: AppState::new(bookmarks, settings, audio, playback),
|
||||||
bookmarks,
|
|
||||||
sessions: HashMap::new(),
|
|
||||||
models,
|
models,
|
||||||
status: String::new(),
|
|
||||||
copy_note: None,
|
|
||||||
member_filter: String::new(),
|
|
||||||
topic_filter: String::new(),
|
|
||||||
voice_view: false,
|
|
||||||
prefs,
|
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,
|
ptt,
|
||||||
video,
|
video,
|
||||||
share: None,
|
share: None,
|
||||||
share_busy: false,
|
|
||||||
share_error: String::new(),
|
|
||||||
watch: None,
|
watch: None,
|
||||||
pending_watch: None,
|
|
||||||
stream_volume: 100.0,
|
|
||||||
demo: switches.demo_stream,
|
demo: switches.demo_stream,
|
||||||
demo_ui: switches.demo_ui,
|
demo_ui: switches.demo_ui,
|
||||||
gateways_looked_up: HashSet::new(),
|
|
||||||
autoshare: switches.autoshare,
|
autoshare: switches.autoshare,
|
||||||
open_client_pending: switches.open_client,
|
open_client_pending: switches.open_client,
|
||||||
notices_loaded: false,
|
notices_loaded: false,
|
||||||
uploads: HashMap::new(),
|
|
||||||
social: Default::default(),
|
social: Default::default(),
|
||||||
pages: Default::default(),
|
pages: Default::default(),
|
||||||
studio: Default::default(),
|
studio: Default::default(),
|
||||||
@@ -931,18 +508,18 @@ pub fn run(options: RunOptions) -> Result<()> {
|
|||||||
if let Err(e) = app.prefs.flush() {
|
if let Err(e) = app.prefs.flush() {
|
||||||
warn!(%e, "could not store settings");
|
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 {
|
for id in ids {
|
||||||
app.save_reads(id);
|
app.save_reads(id);
|
||||||
}
|
}
|
||||||
app.watch = None;
|
app.watch = None;
|
||||||
app.share = None;
|
app.share = None;
|
||||||
if own && !app.demo_ui {
|
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 });
|
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());
|
APP.with(|a| a.borrow_mut().take());
|
||||||
if let Some(runtime) = own_runtime {
|
if let Some(runtime) = own_runtime {
|
||||||
@@ -1001,30 +578,30 @@ pub(crate) fn model<T: Clone + 'static>(items: Vec<T>) -> ModelRc<T> {
|
|||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub fn view_mut(&mut self) -> Option<&mut SessionView> {
|
pub fn view_mut(&mut self) -> Option<&mut SessionView> {
|
||||||
let id = self.current?;
|
let id = self.state.current?;
|
||||||
Some(self.sessions.entry(id).or_default())
|
Some(self.state.sessions.entry(id).or_default())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Option<&SessionView> {
|
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> {
|
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
|
/// Send a command for the current session. Not for the sample
|
||||||
/// sessions of VOELIN_DEMO_UI: the engine would open them for real.
|
/// sessions of VOELIN_DEMO_UI: the engine would open them for real.
|
||||||
pub fn command(&self, f: impl FnOnce(u64) -> Command) {
|
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));
|
self.engine.send(f(id as u64));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_status(&mut self, text: impl Into<String>) {
|
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() {
|
if let Some(ui) = self.ui.upgrade() {
|
||||||
ui.global::<Bridge>().set_status_text(self.status.clone().into());
|
ui.global::<Bridge>().set_status_text(self.state.status.clone().into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1037,12 +614,12 @@ impl App {
|
|||||||
|
|
||||||
/// Nav.copy put text on the clipboard: one toast says so.
|
/// Nav.copy put text on the clipboard: one toast says so.
|
||||||
pub fn copied(&mut self) {
|
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);
|
self.set_status(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn store_settings(&self) {
|
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");
|
warn!(%e, "could not store settings");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1051,19 +628,19 @@ impl App {
|
|||||||
/// the values the window keeps copies of. The engine applies audio
|
/// the values the window keeps copies of. The engine applies audio
|
||||||
/// settings itself.
|
/// settings itself.
|
||||||
fn setting_changed(&mut self, key: &str) {
|
fn setting_changed(&mut self, key: &str) {
|
||||||
if key == AUDIO.name() && !self.audio_dirty {
|
if key == AUDIO.name() && !self.state.audio_dirty {
|
||||||
self.audio = self.prefs.get(&AUDIO);
|
self.state.audio = self.prefs.get(&AUDIO);
|
||||||
// The voice controls follow the transmit mode.
|
// The voice controls follow the transmit mode.
|
||||||
self.refresh_transmit();
|
self.refresh_transmit();
|
||||||
} else if key == CRASH_REPORTS.name() {
|
} else if key == CRASH_REPORTS.name() {
|
||||||
let enabled = self.prefs.get(&CRASH_REPORTS);
|
let enabled = self.prefs.get(&CRASH_REPORTS);
|
||||||
if enabled != self.settings.crash_reports {
|
if enabled != self.state.settings.crash_reports {
|
||||||
self.settings.crash_reports = enabled;
|
self.state.settings.crash_reports = enabled;
|
||||||
crash::set_enabled(enabled);
|
crash::set_enabled(enabled);
|
||||||
self.refresh_settings_flags();
|
self.refresh_settings_flags();
|
||||||
}
|
}
|
||||||
} else if key == CLIENT_PLAYBACK.name() {
|
} 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) {
|
} else if appearance_keys().iter().any(|k| k.name() == key) {
|
||||||
self.apply_appearance();
|
self.apply_appearance();
|
||||||
} else if key == voelin_core::settings::STREAM_AUDIO_SOURCES.name() {
|
} else if key == voelin_core::settings::STREAM_AUDIO_SOURCES.name() {
|
||||||
@@ -1085,7 +662,7 @@ impl App {
|
|||||||
match event {
|
match event {
|
||||||
Event::State { session, state } => {
|
Event::State { session, state } => {
|
||||||
let id = session as i64;
|
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_voice = view.state.voice;
|
||||||
let was_observe = view.state.observe;
|
let was_observe = view.state.observe;
|
||||||
let was_channel = view.state.own_channel;
|
let was_channel = view.state.own_channel;
|
||||||
@@ -1111,12 +688,12 @@ impl App {
|
|||||||
if off(state.voice, state.observe) && !off(was_voice, was_observe) {
|
if off(state.voice, state.observe) && !off(was_voice, was_observe) {
|
||||||
self.save_reads(id);
|
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;
|
let focus = !view.focused_own_channel;
|
||||||
if state.voice == VoiceState::Connected && was_voice != VoiceState::Connected {
|
if state.voice == VoiceState::Connected && was_voice != VoiceState::Connected {
|
||||||
self.set_status("Connected");
|
self.set_status("Connected");
|
||||||
}
|
}
|
||||||
if self.current == Some(id) {
|
if self.state.current == Some(id) {
|
||||||
if self.track_reading() {
|
if self.track_reading() {
|
||||||
self.refresh_chat();
|
self.refresh_chat();
|
||||||
}
|
}
|
||||||
@@ -1124,7 +701,7 @@ impl App {
|
|||||||
// once per connection.
|
// once per connection.
|
||||||
if let (Some(cid), VoiceState::Connected) = (state.own_channel, state.voice) {
|
if let (Some(cid), VoiceState::Connected) = (state.own_channel, state.voice) {
|
||||||
self.open_chat(ChatTarget::Channel(cid), focus);
|
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
|
// Where we are with voice, when it changed here: home's last
|
||||||
@@ -1138,22 +715,22 @@ impl App {
|
|||||||
self.refresh_tree();
|
self.refresh_tree();
|
||||||
self.refresh_streams();
|
self.refresh_streams();
|
||||||
self.autoshare();
|
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.open_first_client();
|
||||||
}
|
}
|
||||||
self.join_after_connect(id);
|
self.join_after_connect(id);
|
||||||
}
|
}
|
||||||
Event::ServerInfo { session, name, backend, capabilities } => {
|
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);
|
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.set_status(connected_status(&name, &backend));
|
||||||
}
|
}
|
||||||
self.refresh_streams();
|
self.refresh_streams();
|
||||||
self.autoshare();
|
self.autoshare();
|
||||||
}
|
}
|
||||||
Event::Presence { session, presence } => {
|
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
|
// The server chat shows its welcome and host message, with
|
||||||
// their pictures.
|
// their pictures.
|
||||||
let said = crate::chat::server_texts(&view.presence.server)
|
let said = crate::chat::server_texts(&view.presence.server)
|
||||||
@@ -1171,7 +748,7 @@ impl App {
|
|||||||
if renamed && self.remember_voice(session as i64) {
|
if renamed && self.remember_voice(session as i64) {
|
||||||
self.refresh_servers();
|
self.refresh_servers();
|
||||||
}
|
}
|
||||||
if self.current == Some(session as i64) {
|
if self.state.current == Some(session as i64) {
|
||||||
if said {
|
if said {
|
||||||
self.fetch_previews(session as i64);
|
self.fetch_previews(session as i64);
|
||||||
}
|
}
|
||||||
@@ -1185,20 +762,20 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Talking { session, client, talking } => {
|
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 {
|
if talking {
|
||||||
view.talking.insert(client);
|
view.talking.insert(client);
|
||||||
} else {
|
} else {
|
||||||
view.talking.remove(&client);
|
view.talking.remove(&client);
|
||||||
}
|
}
|
||||||
if self.current == Some(session as i64) {
|
if self.state.current == Some(session as i64) {
|
||||||
self.refresh_tree();
|
self.refresh_tree();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::InputLevel { session, level_db, sending } => {
|
Event::InputLevel { session, level_db, sending } => {
|
||||||
let shown = match session {
|
let shown = match session {
|
||||||
Some(s) => self.current == Some(s as i64),
|
Some(s) => self.state.current == Some(s as i64),
|
||||||
None => self.mic_test,
|
None => self.state.mic_test,
|
||||||
};
|
};
|
||||||
if shown && let Some(ui) = self.ui.upgrade() {
|
if shown && let Some(ui) = self.ui.upgrade() {
|
||||||
let bridge = ui.global::<Bridge>();
|
let bridge = ui.global::<Bridge>();
|
||||||
@@ -1213,7 +790,7 @@ impl App {
|
|||||||
// know the server yet): those get ids and reactions instead.
|
// know the server yet): those get ids and reactions instead.
|
||||||
Event::Chat { session, message } => {
|
Event::Chat { session, message } => {
|
||||||
let id = session as i64;
|
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);
|
self.add_message(id, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1228,12 +805,12 @@ impl App {
|
|||||||
self.gateway_update(session as i64, update);
|
self.gateway_update(session as i64, update);
|
||||||
}
|
}
|
||||||
Event::Groups { session, server_groups, channel_groups } => {
|
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();
|
view.server_groups = (*server_groups).clone();
|
||||||
// Display order, as TeamSpeak sorts them.
|
// Display order, as TeamSpeak sorts them.
|
||||||
view.server_groups.sort_by_key(|g| (g.sort_id, g.id));
|
view.server_groups.sort_by_key(|g| (g.sort_id, g.id));
|
||||||
view.channel_groups = (*channel_groups).clone();
|
view.channel_groups = (*channel_groups).clone();
|
||||||
if self.current == Some(session as i64) {
|
if self.state.current == Some(session as i64) {
|
||||||
self.refresh_tree();
|
self.refresh_tree();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1244,11 +821,11 @@ impl App {
|
|||||||
}
|
}
|
||||||
// Pictures can arrive after the rows were built: draw them again.
|
// Pictures can arrive after the rows were built: draw them again.
|
||||||
Event::AvatarReady { session, client_uid, path, .. } => {
|
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.
|
// A file that arrives again is decoded again if it changed.
|
||||||
crate::images::reloaded(&path);
|
crate::images::reloaded(&path);
|
||||||
view.avatars.insert(client_uid, 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_tree();
|
||||||
self.refresh_chat();
|
self.refresh_chat();
|
||||||
self.refresh_toolbar();
|
self.refresh_toolbar();
|
||||||
@@ -1257,21 +834,21 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::IconReady { session, icon, path } => {
|
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);
|
crate::images::reloaded(&path);
|
||||||
view.icons.insert(icon, path);
|
view.icons.insert(icon, path);
|
||||||
self.refresh_servers();
|
self.refresh_servers();
|
||||||
if self.current == Some(session as i64) {
|
if self.state.current == Some(session as i64) {
|
||||||
self.refresh_tree();
|
self.refresh_tree();
|
||||||
self.refresh_toolbar();
|
self.refresh_toolbar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::PictureReady { session, url, path } => {
|
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.
|
// The host banner reloads into the same file.
|
||||||
crate::images::reloaded(&path);
|
crate::images::reloaded(&path);
|
||||||
view.pictures.insert(url, 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_toolbar();
|
||||||
self.refresh_tree();
|
self.refresh_tree();
|
||||||
self.refresh_chat();
|
self.refresh_chat();
|
||||||
@@ -1282,9 +859,9 @@ impl App {
|
|||||||
self.transfer_progress(session as i64, transfer, state);
|
self.transfer_progress(session as i64, transfer, state);
|
||||||
}
|
}
|
||||||
// The engine's contacts would replace the sample ones.
|
// 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 } => {
|
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();
|
self.refresh_member_card();
|
||||||
}
|
}
|
||||||
// The sample sessions of VOELIN_DEMO_UI are unknown to the engine.
|
// The sample sessions of VOELIN_DEMO_UI are unknown to the engine.
|
||||||
@@ -1297,7 +874,7 @@ impl App {
|
|||||||
Event::SettingRejected { key, message } => {
|
Event::SettingRejected { key, message } => {
|
||||||
self.set_status(format!("Setting {key}: {message}"));
|
self.set_status(format!("Setting {key}: {message}"));
|
||||||
}
|
}
|
||||||
// The Stream Studio's stream (studio.rs).
|
// The Stream Studio's stream (studio/).
|
||||||
Event::StreamState { session, state } if self.studio_streams_to(session as i64) => {
|
Event::StreamState { session, state } if self.studio_streams_to(session as i64) => {
|
||||||
self.studio_stream_state(state);
|
self.studio_stream_state(state);
|
||||||
}
|
}
|
||||||
@@ -1312,7 +889,7 @@ impl App {
|
|||||||
fn tick(&mut self) {
|
fn tick(&mut self) {
|
||||||
self.tick_streams();
|
self.tick_streams();
|
||||||
self.tick_pages();
|
self.tick_pages();
|
||||||
if self.audio_dirty {
|
if self.state.audio_dirty {
|
||||||
self.save_audio();
|
self.save_audio();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,13 @@
|
|||||||
use slint::ComponentHandle;
|
use slint::ComponentHandle;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
use crate::app::{App, AppearanceForm, Bridge, Nav, Theme};
|
use crate::app::{App, Bridge, Nav, Theme};
|
||||||
use crate::images;
|
use crate::images;
|
||||||
use crate::settings::{
|
use crate::settings::{
|
||||||
ThemeChoice, UI_FONT_SCALE, UI_IMAGE_CACHE_MB, UI_MEMBERS_WIDTH, UI_NARROW_BREAKPOINT,
|
ThemeChoice, UI_FONT_SCALE, UI_IMAGE_CACHE_MB, UI_MEMBERS_WIDTH, UI_NARROW_BREAKPOINT,
|
||||||
UI_THEME, UI_VOICE_COMPACT,
|
UI_THEME, UI_VOICE_COMPACT,
|
||||||
};
|
};
|
||||||
|
use crate::vm::bridge::AppearanceForm;
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
/// Show the current values of the appearance keys.
|
/// Show the current values of the appearance keys.
|
||||||
@@ -33,12 +34,15 @@ impl App {
|
|||||||
}
|
}
|
||||||
nav.set_voice_compact(self.prefs.get(&UI_VOICE_COMPACT));
|
nav.set_voice_compact(self.prefs.get(&UI_VOICE_COMPACT));
|
||||||
let bridge = ui.global::<Bridge>();
|
let bridge = ui.global::<Bridge>();
|
||||||
bridge.set_appearance(AppearanceForm {
|
bridge.set_appearance(
|
||||||
theme: theme.as_str().into(),
|
AppearanceForm {
|
||||||
font_scale: scale,
|
theme: theme.as_str().into(),
|
||||||
narrow_breakpoint: breakpoint as f32,
|
font_scale: scale,
|
||||||
image_cache_mb: cache_mb as f32,
|
narrow_breakpoint: breakpoint as f32,
|
||||||
});
|
image_cache_mb: cache_mb as f32,
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
bridge.set_image_cache_usage(images::usage_text().into());
|
bridge.set_image_cache_usage(images::usage_text().into());
|
||||||
self.theme_windows();
|
self.theme_windows();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
//! Plain view-model values (`voelin-ui-vm`) to Slint values, and back where
|
||||||
|
//! that can be done. Temporary, like the Slint front end itself: the rows
|
||||||
|
//! (`items`) are converted when [`super::rows::Rows`] applies a change, so
|
||||||
|
//! only changed rows pay for it.
|
||||||
|
|
||||||
|
use std::rc::Rc;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use slint::{Color, Image, ModelRc, Rgba8Pixel, SharedPixelBuffer, SharedString, VecModel};
|
||||||
|
use voelin_ui_vm::{ImageRef, ImageSource, Rgb};
|
||||||
|
|
||||||
|
mod items;
|
||||||
|
|
||||||
|
/// An opaque colour.
|
||||||
|
pub(crate) fn color(c: Rgb) -> Color {
|
||||||
|
Color::from_rgb_u8(c.r(), c.g(), c.b())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A colour that may be absent: transparent is the text's own colour.
|
||||||
|
pub(crate) fn ink(c: Option<Rgb>) -> Color {
|
||||||
|
c.map(color).unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The opaque colour of a Slint colour (its transparency is dropped).
|
||||||
|
pub(crate) fn unrgb(c: Color) -> Rgb {
|
||||||
|
Rgb::new(c.red(), c.green(), c.blue())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The colour of a Slint colour, none for a transparent one.
|
||||||
|
pub(crate) fn unink(c: Color) -> Option<Rgb> {
|
||||||
|
(c.alpha() > 0).then(|| unrgb(c))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A picture as Slint shows it: files and downloaded pictures through the
|
||||||
|
/// decoded-picture cache (`images.rs`), pixels as they are.
|
||||||
|
pub(crate) fn image(picture: &ImageRef) -> Image {
|
||||||
|
match &**picture {
|
||||||
|
ImageSource::None => Image::default(),
|
||||||
|
ImageSource::File { path, .. } => crate::images::file(path),
|
||||||
|
ImageSource::Rgba { w, h, bytes } => {
|
||||||
|
Image::from_rgba8(SharedPixelBuffer::<Rgba8Pixel>::clone_from_slice(bytes, *w, *h))
|
||||||
|
}
|
||||||
|
ImageSource::Svg(data) => Image::load_from_svg_data(data).unwrap_or_default(),
|
||||||
|
ImageSource::Memory { key, bytes } => crate::images::picture(key, bytes),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A model of pictures.
|
||||||
|
pub(crate) fn images(pictures: &[ImageRef]) -> ModelRc<Image> {
|
||||||
|
ModelRc::from(Rc::new(VecModel::from(pictures.iter().map(image).collect::<Vec<_>>())))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A model of strings.
|
||||||
|
pub(crate) fn strings(texts: &[Arc<str>]) -> ModelRc<SharedString> {
|
||||||
|
ModelRc::from(Rc::new(VecModel::from(
|
||||||
|
texts.iter().map(|t| SharedString::from(&**t)).collect::<Vec<_>>(),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The strings of a model.
|
||||||
|
pub(crate) fn unstrings(model: &ModelRc<SharedString>) -> Vec<Arc<str>> {
|
||||||
|
slint::Model::iter(model).map(|t| Arc::from(t.as_str())).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A model of the Slint rows the plain rows convert to.
|
||||||
|
pub(crate) fn model<V, S: for<'a> From<&'a V> + Clone + 'static>(rows: &[V]) -> ModelRc<S> {
|
||||||
|
ModelRc::from(Rc::new(VecModel::from(rows.iter().map(S::from).collect::<Vec<_>>())))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The plain rows of a model.
|
||||||
|
pub(crate) fn rows<S: Clone + 'static, V: From<S>>(model: &ModelRc<S>) -> Vec<V> {
|
||||||
|
slint::Model::iter(model).map(V::from).collect()
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -2,8 +2,10 @@
|
|||||||
//! area; each has a `wire` that the window calls once.
|
//! area; each has a `wire` that the window calls once.
|
||||||
|
|
||||||
mod chat;
|
mod chat;
|
||||||
|
pub(crate) mod convert;
|
||||||
mod emoji;
|
mod emoji;
|
||||||
mod pages;
|
mod pages;
|
||||||
|
pub(crate) mod rows;
|
||||||
mod servers;
|
mod servers;
|
||||||
mod settings;
|
mod settings;
|
||||||
mod social;
|
mod social;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//! The settings pages of the new design (settings_pages.rs).
|
//! The settings pages of the new design (`settings_pages/`).
|
||||||
|
|
||||||
use slint::ComponentHandle;
|
use slint::ComponentHandle;
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ pub(super) fn wire(ui: &MainWindow) {
|
|||||||
});
|
});
|
||||||
// Voice & Video.
|
// Voice & Video.
|
||||||
bridge.on_video_changed(|form| {
|
bridge.on_video_changed(|form| {
|
||||||
with_app(|app| app.video_changed(&form));
|
with_app(|app| app.video_changed(&form.into()));
|
||||||
});
|
});
|
||||||
bridge.on_toggle_camera_preview(|| {
|
bridge.on_toggle_camera_preview(|| {
|
||||||
with_app(|app| app.toggle_camera_preview());
|
with_app(|app| app.toggle_camera_preview());
|
||||||
@@ -43,10 +43,10 @@ pub(super) fn wire(ui: &MainWindow) {
|
|||||||
});
|
});
|
||||||
// Streaming.
|
// Streaming.
|
||||||
bridge.on_streaming_changed(|form| {
|
bridge.on_streaming_changed(|form| {
|
||||||
with_app(|app| app.streaming_changed(&form));
|
with_app(|app| app.streaming_changed(&form.into()));
|
||||||
});
|
});
|
||||||
bridge.on_layer_changed(|index, item| {
|
bridge.on_layer_changed(|index, item| {
|
||||||
with_app(|app| app.layer_changed(index, &item));
|
with_app(|app| app.layer_changed(index, &item.into()));
|
||||||
});
|
});
|
||||||
bridge.on_add_layer(|| {
|
bridge.on_add_layer(|| {
|
||||||
with_app(|app| app.add_layer());
|
with_app(|app| app.add_layer());
|
||||||
@@ -55,7 +55,7 @@ pub(super) fn wire(ui: &MainWindow) {
|
|||||||
with_app(|app| app.remove_layer(index));
|
with_app(|app| app.remove_layer(index));
|
||||||
});
|
});
|
||||||
bridge.on_audio_source_changed(|index, item| {
|
bridge.on_audio_source_changed(|index, item| {
|
||||||
with_app(|app| app.audio_source_changed(index, &item));
|
with_app(|app| app.audio_source_changed(index, &item.into()));
|
||||||
});
|
});
|
||||||
bridge.on_add_audio_source(|kind, name| {
|
bridge.on_add_audio_source(|kind, name| {
|
||||||
with_app(|app| app.add_audio_source(&kind, &name));
|
with_app(|app| app.add_audio_source(&kind, &name));
|
||||||
@@ -65,13 +65,13 @@ pub(super) fn wire(ui: &MainWindow) {
|
|||||||
});
|
});
|
||||||
// Notifications, privacy.
|
// Notifications, privacy.
|
||||||
bridge.on_notify_changed(|form| {
|
bridge.on_notify_changed(|form| {
|
||||||
with_app(|app| app.notify_changed(&form));
|
with_app(|app| app.notify_changed(&form.into()));
|
||||||
});
|
});
|
||||||
bridge.on_test_notification(|| {
|
bridge.on_test_notification(|| {
|
||||||
with_app(|app| app.test_notification());
|
with_app(|app| app.test_notification());
|
||||||
});
|
});
|
||||||
bridge.on_privacy_changed(|form| {
|
bridge.on_privacy_changed(|form| {
|
||||||
with_app(|app| app.privacy_changed(&form));
|
with_app(|app| app.privacy_changed(&form.into()));
|
||||||
});
|
});
|
||||||
// Integrations.
|
// Integrations.
|
||||||
bridge.on_gateway_admin(|session| {
|
bridge.on_gateway_admin(|session| {
|
||||||
@@ -97,7 +97,7 @@ pub(super) fn wire(ui: &MainWindow) {
|
|||||||
});
|
});
|
||||||
// Advanced.
|
// Advanced.
|
||||||
bridge.on_advanced_changed(|form| {
|
bridge.on_advanced_changed(|form| {
|
||||||
with_app(|app| app.advanced_changed(&form));
|
with_app(|app| app.advanced_changed(&form.into()));
|
||||||
});
|
});
|
||||||
bridge.on_srtp_move(|index, by| {
|
bridge.on_srtp_move(|index, by| {
|
||||||
with_app(|app| app.srtp_move(index, by));
|
with_app(|app| app.srtp_move(index, by));
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
//! A Slint list model kept in step with plain rows: the view-model code
|
||||||
|
//! produces the new list, [`list::diff`](voelin_ui_vm::list::diff) finds
|
||||||
|
//! the row operations, and only those rows are converted and handed to the
|
||||||
|
//! `VecModel` (views redraw only the rows that changed: a client that
|
||||||
|
//! starts talking is one `set_row_data`).
|
||||||
|
|
||||||
|
use std::cell::{Ref, RefCell};
|
||||||
|
use std::rc::Rc;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use slint::{Model, ModelRc, SharedString, VecModel};
|
||||||
|
use voelin_ui_vm::list::{Change, Changes, diff};
|
||||||
|
|
||||||
|
/// A plain row that a Slint model shows as another type. Implemented for
|
||||||
|
/// the bridge structs (`convert/items.rs`).
|
||||||
|
pub(crate) trait Row: Clone + PartialEq {
|
||||||
|
/// The Slint type of the row.
|
||||||
|
type Shown: Clone + 'static;
|
||||||
|
|
||||||
|
/// The row as the window shows it.
|
||||||
|
fn show(&self) -> Self::Shown;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Row for Arc<str> {
|
||||||
|
type Shown = SharedString;
|
||||||
|
|
||||||
|
fn show(&self) -> SharedString {
|
||||||
|
SharedString::from(&**self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The rows of a list as the view model made them (`T`), and the model the
|
||||||
|
/// window shows.
|
||||||
|
pub(crate) struct Rows<T: Row> {
|
||||||
|
model: Rc<VecModel<T::Shown>>,
|
||||||
|
rows: RefCell<Vec<T>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Row> Default for Rows<T> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self { model: Rc::default(), rows: RefCell::default() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Row> Rows<T> {
|
||||||
|
/// The model, for a window property.
|
||||||
|
pub fn model(&self) -> ModelRc<T::Shown> {
|
||||||
|
ModelRc::from(self.model.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The rows now.
|
||||||
|
pub fn rows(&self) -> Ref<'_, [T]> {
|
||||||
|
Ref::map(self.rows.borrow(), Vec::as_slice)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Row `i` now.
|
||||||
|
pub fn get(&self, i: usize) -> Option<T> {
|
||||||
|
self.rows.borrow().get(i).cloned()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Change row `i` to `row` if it differs.
|
||||||
|
pub fn set(&self, i: usize, row: T) {
|
||||||
|
let mut rows = self.rows.borrow_mut();
|
||||||
|
if rows.get(i).is_some_and(|old| *old != row) {
|
||||||
|
self.model.set_row_data(i, row.show());
|
||||||
|
rows[i] = row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Append a row.
|
||||||
|
pub fn push(&self, row: T) {
|
||||||
|
self.model.push(row.show());
|
||||||
|
self.rows.borrow_mut().push(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Make the list `new`, with the fewest row operations.
|
||||||
|
pub fn sync(&self, new: &[T]) -> Changes {
|
||||||
|
let mut rows = self.rows.borrow_mut();
|
||||||
|
let changes = diff(&rows, new);
|
||||||
|
for change in &changes.0 {
|
||||||
|
match *change {
|
||||||
|
Change::Update(i) => self.model.set_row_data(i, new[i].show()),
|
||||||
|
Change::Remove(i) => {
|
||||||
|
self.model.remove(i);
|
||||||
|
}
|
||||||
|
Change::Insert(i) => self.model.insert(i, new[i].show()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
changes.apply(&mut rows, new);
|
||||||
|
changes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
struct Plain(i32);
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
struct Shown(i32);
|
||||||
|
impl Row for Plain {
|
||||||
|
type Shown = Shown;
|
||||||
|
|
||||||
|
fn show(&self) -> Shown {
|
||||||
|
Shown(self.0 * 10)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(old: &[i32], new: &[i32]) -> Changes {
|
||||||
|
let rows: Rows<Plain> = Rows::default();
|
||||||
|
rows.sync(&old.iter().map(|&n| Plain(n)).collect::<Vec<_>>());
|
||||||
|
let changes = rows.sync(&new.iter().map(|&n| Plain(n)).collect::<Vec<_>>());
|
||||||
|
let shown: Vec<i32> = rows.model.iter().map(|s| s.0).collect();
|
||||||
|
assert_eq!(shown, new.iter().map(|n| n * 10).collect::<Vec<_>>(), "{old:?} -> {new:?}");
|
||||||
|
assert_eq!(rows.rows.borrow().len(), new.len());
|
||||||
|
changes
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_model_follows_the_rows() {
|
||||||
|
assert!(run(&[1, 2, 3], &[1, 2, 3]).is_empty());
|
||||||
|
assert_eq!(run(&[1, 2, 3], &[1, 9, 3]).updated(), 1);
|
||||||
|
assert_eq!(run(&[1, 2, 3], &[1, 2, 7, 3]).inserted(), 1);
|
||||||
|
assert_eq!(run(&[1, 2, 3], &[1, 3]).removed(), 1);
|
||||||
|
run(&[], &[1, 2]);
|
||||||
|
run(&[1, 2], &[]);
|
||||||
|
run(&[1, 2, 1], &[1, 1, 2, 1]);
|
||||||
|
run(&[4, 5, 6], &[1, 2, 3, 4, 5, 6, 7]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn strings_are_rows() {
|
||||||
|
let rows: Rows<Arc<str>> = Rows::default();
|
||||||
|
rows.sync(&["720p".into(), "1080p".into()]);
|
||||||
|
assert_eq!(rows.model().row_data(1).as_deref(), Some("1080p"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,7 +25,7 @@ pub(super) fn wire(ui: &MainWindow) {
|
|||||||
});
|
});
|
||||||
bridge.on_join_channel(|cid| {
|
bridge.on_join_channel(|cid| {
|
||||||
with_app(|app| {
|
with_app(|app| {
|
||||||
if let Some(session) = app.current {
|
if let Some(session) = app.state.current {
|
||||||
app.join_channel(session, cid as ChannelId);
|
app.join_channel(session, cid as ChannelId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -45,17 +45,21 @@ pub(super) fn wire(ui: &MainWindow) {
|
|||||||
bridge.on_push_to_talk(|on| {
|
bridge.on_push_to_talk(|on| {
|
||||||
with_app(|app| app.command(|session| Command::SetTransmitting { session, on }));
|
with_app(|app| app.command(|session| Command::SetTransmitting { session, on }));
|
||||||
});
|
});
|
||||||
bridge.on_edit_bookmark(|id| with_app(|app| app.bookmark_form(id as i64)).unwrap_or_default());
|
bridge.on_edit_bookmark(|id| {
|
||||||
|
with_app(|app| app.bookmark_form(id as i64)).unwrap_or_default().into()
|
||||||
|
});
|
||||||
bridge.on_save_bookmark(|form| {
|
bridge.on_save_bookmark(|form| {
|
||||||
with_app(|app| app.save_bookmark(&form));
|
with_app(|app| app.save_bookmark(&form.into()));
|
||||||
|
});
|
||||||
|
bridge.on_save_and_connect(|form| {
|
||||||
|
with_app(|app| app.save_and_connect(&form.into())).unwrap_or(false)
|
||||||
});
|
});
|
||||||
bridge.on_save_and_connect(|form| with_app(|app| app.save_and_connect(&form)).unwrap_or(false));
|
|
||||||
bridge.on_delete_bookmark(|id| {
|
bridge.on_delete_bookmark(|id| {
|
||||||
with_app(|app| app.delete_bookmark(id as i64));
|
with_app(|app| app.delete_bookmark(id as i64));
|
||||||
});
|
});
|
||||||
bridge.on_open_client(|id| with_app(|app| app.open_client(id as u16)).unwrap_or(false));
|
bridge.on_open_client(|id| with_app(|app| app.open_client(id as u16)).unwrap_or(false));
|
||||||
bridge.on_client_audio_changed(|form| {
|
bridge.on_client_audio_changed(|form| {
|
||||||
with_app(|app| app.client_playback_changed(&form));
|
with_app(|app| app.client_playback_changed(&form.into()));
|
||||||
});
|
});
|
||||||
bridge.on_invite(|| with_app(|app| app.invite_link()).unwrap_or_default().into());
|
bridge.on_invite(|| with_app(|app| app.invite_link()).unwrap_or_default().into());
|
||||||
// Nav.copy, from any screen.
|
// Nav.copy, from any screen.
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ pub(super) fn wire(ui: &MainWindow) {
|
|||||||
with_app(|app| app.close_settings());
|
with_app(|app| app.close_settings());
|
||||||
});
|
});
|
||||||
bridge.on_audio_changed(|form| {
|
bridge.on_audio_changed(|form| {
|
||||||
with_app(|app| app.audio_changed(&form));
|
with_app(|app| app.audio_changed(&form.into()));
|
||||||
});
|
});
|
||||||
bridge.on_toggle_mic_test(|| {
|
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| {
|
bridge.on_apply_ptt(|enabled, key| {
|
||||||
with_app(|app| app.apply_ptt(enabled, key.to_string()));
|
with_app(|app| app.apply_ptt(enabled, key.to_string()));
|
||||||
@@ -34,7 +34,7 @@ pub(super) fn wire(ui: &MainWindow) {
|
|||||||
with_app(|app| app.voice_compact_changed(compact));
|
with_app(|app| app.voice_compact_changed(compact));
|
||||||
});
|
});
|
||||||
bridge.on_appearance_changed(|form| {
|
bridge.on_appearance_changed(|form| {
|
||||||
with_app(|app| app.appearance_changed(&form));
|
with_app(|app| app.appearance_changed(&form.into()));
|
||||||
});
|
});
|
||||||
bridge.on_set_crash_reports(|enabled| {
|
bridge.on_set_crash_reports(|enabled| {
|
||||||
with_app(|app| app.set_crash_reports(enabled));
|
with_app(|app| app.set_crash_reports(enabled));
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ pub(super) fn wire(ui: &MainWindow) {
|
|||||||
with_app(|app| app.dm_volume(percent));
|
with_app(|app| app.dm_volume(percent));
|
||||||
});
|
});
|
||||||
bridge.on_send_offline(|form| {
|
bridge.on_send_offline(|form| {
|
||||||
with_app(|app| app.send_offline(form));
|
with_app(|app| app.send_offline(form.into()));
|
||||||
});
|
});
|
||||||
|
|
||||||
// The bell.
|
// The bell.
|
||||||
@@ -97,8 +97,10 @@ pub(super) fn wire(ui: &MainWindow) {
|
|||||||
bridge.on_toggle_event(|id| {
|
bridge.on_toggle_event(|id| {
|
||||||
with_app(|app| app.toggle_event(id));
|
with_app(|app| app.toggle_event(id));
|
||||||
});
|
});
|
||||||
bridge.on_edit_event(|id| with_app(|app| app.edit_event(id)).unwrap_or_default());
|
bridge.on_edit_event(|id| with_app(|app| app.edit_event(id)).unwrap_or_default().into());
|
||||||
bridge.on_save_event(|form| with_app(|app| app.save_event(&form)).unwrap_or_default().into());
|
bridge.on_save_event(|form| {
|
||||||
|
with_app(|app| app.save_event(&form.into())).unwrap_or_default().into()
|
||||||
|
});
|
||||||
bridge.on_delete_event(|id| {
|
bridge.on_delete_event(|id| {
|
||||||
with_app(|app| app.delete_event(id));
|
with_app(|app| app.delete_event(id));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
use crate::app::{Bridge, with_app};
|
use crate::app::{Bridge, with_app};
|
||||||
|
|
||||||
pub(crate) fn wire(bridge: &Bridge) {
|
pub(crate) fn wire(bridge: &Bridge) {
|
||||||
bridge.on_open_share(|| with_app(|app| app.open_share()).unwrap_or_default());
|
bridge.on_open_share(|| with_app(|app| app.open_share()).unwrap_or_default().into());
|
||||||
bridge.on_start_share(|form| {
|
bridge.on_start_share(|form| {
|
||||||
with_app(|app| app.start_share(form));
|
with_app(|app| app.start_share(form.into()));
|
||||||
});
|
});
|
||||||
bridge.on_stop_share(|| {
|
bridge.on_stop_share(|| {
|
||||||
with_app(|app| app.stop_share());
|
with_app(|app| app.stop_share());
|
||||||
|
|||||||
@@ -52,13 +52,13 @@ pub(crate) fn wire(bridge: &StudioBridge) {
|
|||||||
with_app(|app| app.studio_add_picked(index(i)));
|
with_app(|app| app.studio_add_picked(index(i)));
|
||||||
});
|
});
|
||||||
bridge.on_add_source(|form| {
|
bridge.on_add_source(|form| {
|
||||||
with_app(|app| app.studio_add_source(&form));
|
with_app(|app| app.studio_add_source(&form.into()));
|
||||||
});
|
});
|
||||||
bridge.on_source_form(|source| {
|
bridge.on_source_form(|source| {
|
||||||
with_app(|app| app.studio_source_form(id(source))).unwrap_or_default()
|
with_app(|app| app.studio_source_form(id(source))).unwrap_or_default().into()
|
||||||
});
|
});
|
||||||
bridge.on_apply_source(|form| {
|
bridge.on_apply_source(|form| {
|
||||||
with_app(|app| app.studio_apply_source(&form));
|
with_app(|app| app.studio_apply_source(&form.into()));
|
||||||
});
|
});
|
||||||
bridge.on_toggle_source(|source| {
|
bridge.on_toggle_source(|source| {
|
||||||
with_app(|app| app.studio_toggle_source(id(source)));
|
with_app(|app| app.studio_toggle_source(id(source)));
|
||||||
@@ -93,7 +93,7 @@ pub(crate) fn wire(bridge: &StudioBridge) {
|
|||||||
with_app(|app| app.studio_set_output(&w, &h, &fps));
|
with_app(|app| app.studio_set_output(&w, &h, &fps));
|
||||||
});
|
});
|
||||||
bridge.on_set_layer(|i, layer| {
|
bridge.on_set_layer(|i, layer| {
|
||||||
with_app(|app| app.studio_set_layer(index(i), &layer));
|
with_app(|app| app.studio_set_layer(index(i), &layer.into()));
|
||||||
});
|
});
|
||||||
bridge.on_add_layer(|| {
|
bridge.on_add_layer(|| {
|
||||||
with_app(|app| app.studio_add_layer());
|
with_app(|app| app.studio_add_layer());
|
||||||
@@ -120,9 +120,10 @@ pub(crate) fn wire(bridge: &StudioBridge) {
|
|||||||
bridge.on_end_stream(|| {
|
bridge.on_end_stream(|| {
|
||||||
with_app(|app| app.studio_end());
|
with_app(|app| app.studio_end());
|
||||||
});
|
});
|
||||||
bridge.on_settings_form(|| with_app(|app| app.studio_settings_form()).unwrap_or_default());
|
bridge
|
||||||
|
.on_settings_form(|| with_app(|app| app.studio_settings_form()).unwrap_or_default().into());
|
||||||
bridge.on_apply_settings(|form| {
|
bridge.on_apply_settings(|form| {
|
||||||
with_app(|app| app.studio_apply_settings(&form));
|
with_app(|app| app.studio_apply_settings(&form.into()));
|
||||||
});
|
});
|
||||||
|
|
||||||
bridge.on_respond_viewer(|client, accept| {
|
bridge.on_respond_viewer(|client, accept| {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
//! The engine keeps the history: [`Event::ChatHistory`] is an upsert of
|
//! The engine keeps the history: [`Event::ChatHistory`] is an upsert of
|
||||||
//! messages by their local id (see `voelin_core::history`), so a tab holds
|
//! messages by their local id (see `voelin_core::history`), so a tab holds
|
||||||
//! the messages it was given, ordered by `(ts_ms, id)`, and the lines of
|
//! the messages it was given, ordered by `(ts_ms, id)`, and the lines of
|
||||||
//! the selected tab are rebuilt from them with [`vm::list::sync`], which
|
//! the selected tab are rebuilt from them and synced ([`Rows::sync`]), which
|
||||||
//! touches only the rows that changed. Sessions the engine keeps no history
|
//! touches only the rows that changed. Sessions the engine keeps no history
|
||||||
//! for (it does not know the server yet) fall back to [`Event::Chat`].
|
//! for (it does not know the server yet) fall back to [`Event::Chat`].
|
||||||
//!
|
//!
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use slint::{ComponentHandle, ModelRc};
|
use slint::ComponentHandle;
|
||||||
use voelin_core::gateway::Pin;
|
use voelin_core::gateway::Pin;
|
||||||
use voelin_core::settings::CACHE_FETCH_IMAGES;
|
use voelin_core::settings::CACHE_FETCH_IMAGES;
|
||||||
use voelin_core::{
|
use voelin_core::{
|
||||||
@@ -30,11 +30,13 @@ use voelin_gateway_proto::{ErrorCode, TopicInfo, feature};
|
|||||||
use voelin_model::{ChatMessage, ChatTarget, HostMessageMode, ServerDetails};
|
use voelin_model::{ChatMessage, ChatTarget, HostMessageMode, ServerDetails};
|
||||||
use voelin_store::ChatRead;
|
use voelin_store::ChatRead;
|
||||||
|
|
||||||
use crate::app::{App, Bridge, ChatLine, ChatTab, FileItem, Msg, Nav, PinItem, SessionView, Tab};
|
use crate::app::{App, Bridge, Nav, SessionView, Tab};
|
||||||
use crate::settings::UI_IMAGE_PREVIEW_KB;
|
use crate::settings::UI_IMAGE_PREVIEW_KB;
|
||||||
use crate::vm;
|
use crate::vm;
|
||||||
use crate::vm::bbcode::LinkKind;
|
use crate::vm::bbcode::LinkKind;
|
||||||
|
use crate::vm::bridge::{ChatLine, ChatTab, FileItem, PinItem};
|
||||||
use crate::vm::chat::{LineCache, LineCtx, Previous};
|
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
|
/// Where the server's welcome and host message keep what their lines were
|
||||||
/// built from (`LineCache`), apart from the messages' ids.
|
/// built from (`LineCache`), apart from the messages' ids.
|
||||||
@@ -61,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)
|
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".
|
/// "3 min ago", "yesterday", "12 Mar".
|
||||||
fn ago(ts_ms: i64) -> String {
|
fn ago(ts_ms: i64) -> String {
|
||||||
let Some(then) = chrono::DateTime::from_timestamp_millis(ts_ms) else { return String::new() };
|
let Some(then) = chrono::DateTime::from_timestamp_millis(ts_ms) else { return String::new() };
|
||||||
@@ -104,10 +80,10 @@ fn ago(ts_ms: i64) -> String {
|
|||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub(crate) fn open_chat(&mut self, target: ChatTarget, focus: bool) {
|
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);
|
let index = self.chat_tab(id, target);
|
||||||
if focus {
|
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.prefetch_counts();
|
||||||
self.track_reading();
|
self.track_reading();
|
||||||
}
|
}
|
||||||
@@ -122,7 +98,7 @@ impl App {
|
|||||||
ChatTarget::Private(uid) => self.peer_name(uid, None),
|
ChatTarget::Private(uid) => self.peer_name(uid, None),
|
||||||
_ => String::new(),
|
_ => 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) {
|
if let Some(i) = view.tabs.iter().position(|t| t.target == target) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -148,7 +124,7 @@ impl App {
|
|||||||
view.set_current_tab(index);
|
view.set_current_tab(index);
|
||||||
view.tabs[index].topic = None;
|
view.tabs[index].topic = None;
|
||||||
}
|
}
|
||||||
if let Some(id) = self.current {
|
if let Some(id) = self.state.current {
|
||||||
self.fetch_previews(id);
|
self.fetch_previews(id);
|
||||||
}
|
}
|
||||||
self.prefetch_counts();
|
self.prefetch_counts();
|
||||||
@@ -158,13 +134,13 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn close_tab(&mut self, index: usize) {
|
pub(crate) fn close_tab(&mut self, index: usize) {
|
||||||
let Some(id) = self.current else { return };
|
let Some(id) = self.state.current else { return };
|
||||||
let view = self.sessions.entry(id).or_default();
|
let view = self.state.sessions.entry(id).or_default();
|
||||||
if index == 0 || index >= view.tabs.len() {
|
if index == 0 || index >= view.tabs.len() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.save_read(id, index);
|
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.engine.send(Command::CloseChat { session: id as u64, target: tab.target });
|
||||||
self.prefetch_counts();
|
self.prefetch_counts();
|
||||||
self.track_reading();
|
self.track_reading();
|
||||||
@@ -173,8 +149,8 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn send_message(&mut self, text: String) {
|
pub(crate) fn send_message(&mut self, text: String) {
|
||||||
let Some(id) = self.current else { return };
|
let Some(id) = self.state.current else { return };
|
||||||
let Some(view) = self.sessions.get(&id) else { return };
|
let Some(view) = self.state.sessions.get(&id) else { return };
|
||||||
let target = view.tabs[view.current_tab].target.clone();
|
let target = view.tabs[view.current_tab].target.clone();
|
||||||
self.engine.send(Command::SendChat { session: id as u64, target, text });
|
self.engine.send(Command::SendChat { session: id as u64, target, text });
|
||||||
}
|
}
|
||||||
@@ -198,10 +174,10 @@ impl App {
|
|||||||
/// A live message of a session without stored history: appended as it
|
/// A live message of a session without stored history: appended as it
|
||||||
/// comes, without an id.
|
/// comes, without an id.
|
||||||
pub(crate) fn add_message(&mut self, id: i64, message: ChatMessage) {
|
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 reading = self.reads_now(id);
|
||||||
let new = !self.is_own(id, &message);
|
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 title = vm::chat::tab_title(&view.presence, &message.target, &message.author_name);
|
||||||
let index = Self::tab_for(view, &message.target, || title);
|
let index = Self::tab_for(view, &message.target, || title);
|
||||||
let seen = reading && view.current_tab == index;
|
let seen = reading && view.current_tab == index;
|
||||||
@@ -231,7 +207,7 @@ impl App {
|
|||||||
source: HistorySource,
|
source: HistorySource,
|
||||||
complete: bool,
|
complete: bool,
|
||||||
) {
|
) {
|
||||||
let current = self.current == Some(id);
|
let current = self.state.current == Some(id);
|
||||||
let reading = self.reads_now(id);
|
let reading = self.reads_now(id);
|
||||||
// A private chat is named after the peer, whoever wrote first.
|
// A private chat is named after the peer, whoever wrote first.
|
||||||
let peer = match target {
|
let peer = match target {
|
||||||
@@ -244,7 +220,7 @@ impl App {
|
|||||||
)),
|
)),
|
||||||
_ => None,
|
_ => 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 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 title = peer.unwrap_or_else(|| vm::chat::tab_title(&view.presence, target, author));
|
||||||
let index = Self::tab_for(view, target, || title);
|
let index = Self::tab_for(view, target, || title);
|
||||||
@@ -308,8 +284,8 @@ impl App {
|
|||||||
|
|
||||||
/// The page of messages before the oldest one shown.
|
/// The page of messages before the oldest one shown.
|
||||||
pub(crate) fn load_older(&mut self) {
|
pub(crate) fn load_older(&mut self) {
|
||||||
let Some(id) = self.current else { return };
|
let Some(id) = self.state.current else { return };
|
||||||
let Some(view) = self.sessions.get_mut(&id) else { return };
|
let Some(view) = self.state.sessions.get_mut(&id) else { return };
|
||||||
let tab = &mut view.tabs[view.current_tab];
|
let tab = &mut view.tabs[view.current_tab];
|
||||||
if tab.loading || tab.complete {
|
if tab.loading || tab.complete {
|
||||||
return;
|
return;
|
||||||
@@ -329,7 +305,7 @@ impl App {
|
|||||||
|
|
||||||
/// The lines of a tab's messages (`main`) or of its open topic, grouped
|
/// The lines of a tab's messages (`main`) or of its open topic, grouped
|
||||||
/// and with everything the row shows (also the stream chat of the
|
/// and with everything the row shows (also the stream chat of the
|
||||||
/// Stream Studio, studio.rs). The server chat starts with what the
|
/// Stream Studio, studio/). The server chat starts with what the
|
||||||
/// server says to everyone who connects ([`Self::server_lines`]).
|
/// server says to everyone who connects ([`Self::server_lines`]).
|
||||||
pub(crate) fn lines_of(&self, view: &SessionView, tab: &Tab, main: bool) -> Vec<ChatLine> {
|
pub(crate) fn lines_of(&self, view: &SessionView, tab: &Tab, main: bool) -> Vec<ChatLine> {
|
||||||
let messages = if main { &tab.messages } else { &tab.topic_messages };
|
let messages = if main { &tab.messages } else { &tab.topic_messages };
|
||||||
@@ -384,7 +360,7 @@ impl App {
|
|||||||
cache.keep(ids, messages.len());
|
cache.keep(ids, messages.len());
|
||||||
}
|
}
|
||||||
// Pokes of a private chat's peer show among its messages.
|
// 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.extend(self.poke_lines(session, uid));
|
||||||
lines.sort_by_key(|(ts, _)| *ts);
|
lines.sort_by_key(|(ts, _)| *ts);
|
||||||
}
|
}
|
||||||
@@ -466,14 +442,11 @@ impl App {
|
|||||||
let Some(ui) = self.ui.upgrade() else { return };
|
let Some(ui) = self.ui.upgrade() else { return };
|
||||||
let bridge = ui.global::<Bridge>();
|
let bridge = ui.global::<Bridge>();
|
||||||
let Some(view) = self.view() else {
|
let Some(view) = self.view() else {
|
||||||
vm::list::sync(
|
self.models.tabs.sync(&[ChatTab { title: "Server".into(), ..Default::default() }]);
|
||||||
&self.models.tabs,
|
|
||||||
&[ChatTab { title: "Server".into(), ..Default::default() }],
|
|
||||||
);
|
|
||||||
*self.models.strip.borrow_mut() = vec![0];
|
*self.models.strip.borrow_mut() = vec![0];
|
||||||
bridge.set_current_tab(0);
|
bridge.set_current_tab(0);
|
||||||
bridge.set_current_chat(0);
|
bridge.set_current_chat(0);
|
||||||
let empty = ModelRc::from(self.models.no_chat.clone());
|
let empty = self.models.no_chat.model();
|
||||||
if bridge.get_messages() != empty {
|
if bridge.get_messages() != empty {
|
||||||
bridge.set_messages(empty);
|
bridge.set_messages(empty);
|
||||||
}
|
}
|
||||||
@@ -523,7 +496,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
vm::list::sync(&self.models.tabs, &tabs);
|
self.models.tabs.sync(&tabs);
|
||||||
*self.models.strip.borrow_mut() = strip;
|
*self.models.strip.borrow_mut() = strip;
|
||||||
if bridge.get_current_tab() != current {
|
if bridge.get_current_tab() != current {
|
||||||
bridge.set_current_tab(current);
|
bridge.set_current_tab(current);
|
||||||
@@ -535,9 +508,9 @@ impl App {
|
|||||||
if view.has_history() {
|
if view.has_history() {
|
||||||
let lines = self.lines_of(view, tab, true);
|
let lines = self.lines_of(view, tab, true);
|
||||||
divider = lines.iter().position(|l| l.unread_start);
|
divider = lines.iter().position(|l| l.unread_start);
|
||||||
vm::list::sync(&tab.lines, &lines);
|
tab.lines.sync(&lines);
|
||||||
}
|
}
|
||||||
let lines = ModelRc::from(tab.lines.clone());
|
let lines = tab.lines.model();
|
||||||
if bridge.get_messages() != lines {
|
if bridge.get_messages() != lines {
|
||||||
bridge.set_messages(lines);
|
bridge.set_messages(lines);
|
||||||
}
|
}
|
||||||
@@ -546,7 +519,7 @@ impl App {
|
|||||||
.divider
|
.divider
|
||||||
.and_then(|d| tab.messages.iter().position(|m| m.message.id == d))
|
.and_then(|d| tab.messages.iter().position(|m| m.message.id == d))
|
||||||
.map_or(&[][..], |i| &tab.messages[i..]);
|
.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();
|
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_index(divider.map_or(-1, |i| i as i32));
|
||||||
bridge.set_unread_count(count as i32);
|
bridge.set_unread_count(count as i32);
|
||||||
@@ -586,14 +559,14 @@ impl App {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
vm::list::sync(&self.models.pins, &pins);
|
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 now = chrono::Utc::now().timestamp_millis();
|
||||||
let topics: Vec<crate::app::TopicItem> = tab
|
let topics: Vec<vm::bridge::TopicItem> = tab
|
||||||
.topics
|
.topics
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|t| filter.is_empty() || t.title.to_lowercase().contains(&filter))
|
.filter(|t| filter.is_empty() || t.title.to_lowercase().contains(&filter))
|
||||||
.map(|t| crate::app::TopicItem {
|
.map(|t| vm::bridge::TopicItem {
|
||||||
id: t.id as i32,
|
id: t.id as i32,
|
||||||
title: t.title.clone().into(),
|
title: t.title.clone().into(),
|
||||||
creator: t.creator.name.clone().into(),
|
creator: t.creator.name.clone().into(),
|
||||||
@@ -609,7 +582,7 @@ impl App {
|
|||||||
archived: t.archived,
|
archived: t.archived,
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
vm::list::sync(&self.models.topics, &topics);
|
self.models.topics.sync(&topics);
|
||||||
bridge.set_current_topic(tab.topic.map_or(-1, |t| t as i32));
|
bridge.set_current_topic(tab.topic.map_or(-1, |t| t as i32));
|
||||||
bridge.set_topic_title(
|
bridge.set_topic_title(
|
||||||
tab.topic
|
tab.topic
|
||||||
@@ -618,7 +591,7 @@ impl App {
|
|||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
vm::list::sync(&self.models.topic_messages, &self.lines_of(view, tab, false));
|
self.models.topic_messages.sync(&self.lines_of(view, tab, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A link in a message was clicked (`masked`: its text shows something
|
/// A link in a message was clicked (`masked`: its text shows something
|
||||||
@@ -656,7 +629,7 @@ impl App {
|
|||||||
/// New messages of session `id` in its current tab are read as they
|
/// New messages of session `id` in its current tab are read as they
|
||||||
/// come: they are on screen in the focused window.
|
/// come: they are on screen in the focused window.
|
||||||
fn reads_now(&self, id: i64) -> bool {
|
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
|
/// After anything that can change which chat is on screen (a tab, a
|
||||||
@@ -664,26 +637,26 @@ impl App {
|
|||||||
/// loses its divider; the one on screen, in the focused window, is read
|
/// loses its divider; the one on screen, in the focused window, is read
|
||||||
/// (its divider above what was new). `true` if a tab changed.
|
/// (its divider above what was new). `true` if a tab changed.
|
||||||
pub(crate) fn track_reading(&mut self) -> bool {
|
pub(crate) fn track_reading(&mut self) -> bool {
|
||||||
let open = self.current.filter(|_| self.chat_shown()).and_then(|id| {
|
let open = self.state.current.filter(|_| self.chat_shown()).and_then(|id| {
|
||||||
let view = self.sessions.get(&id)?;
|
let view = self.state.sessions.get(&id)?;
|
||||||
Some((id, view.tabs.get(view.current_tab)?.target.clone()))
|
Some((id, view.tabs.get(view.current_tab)?.target.clone()))
|
||||||
});
|
});
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
if open != self.reading {
|
if open != self.state.reading {
|
||||||
if let Some((id, target)) = self.reading.take()
|
if let Some((id, target)) = self.state.reading.take()
|
||||||
&& let Some(index) = self.tab_index(id, &target)
|
&& 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();
|
changed |= tab.divider.take().is_some();
|
||||||
self.save_read(id, index);
|
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 Some(index) = self.tab_index(id, &target)
|
||||||
{
|
{
|
||||||
let own_uids = &self.social.own_uids;
|
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 own_client = view.state.own_client;
|
||||||
let tab = &mut view.tabs[index];
|
let tab = &mut view.tabs[index];
|
||||||
let before = (tab.unread, tab.divider);
|
let before = (tab.unread, tab.divider);
|
||||||
@@ -695,7 +668,7 @@ impl App {
|
|||||||
|
|
||||||
/// Where the tab of `target` is in session `id`.
|
/// Where the tab of `target` is in session `id`.
|
||||||
fn tab_index(&self, id: i64, target: &ChatTarget) -> Option<usize> {
|
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`).
|
/// The current chat came on screen or left it (`Nav.chat-shown`).
|
||||||
@@ -710,7 +683,7 @@ impl App {
|
|||||||
/// only).
|
/// only).
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
pub(crate) fn window_focused(&mut self, focused: bool) {
|
pub(crate) fn window_focused(&mut self, focused: bool) {
|
||||||
self.focused = focused;
|
self.state.focused = focused;
|
||||||
if self.track_reading() {
|
if self.track_reading() {
|
||||||
self.refresh_chat();
|
self.refresh_chat();
|
||||||
self.refresh_servers();
|
self.refresh_servers();
|
||||||
@@ -720,8 +693,8 @@ impl App {
|
|||||||
/// The current chat is read (the bar over its messages): the divider
|
/// The current chat is read (the bar over its messages): the divider
|
||||||
/// goes.
|
/// goes.
|
||||||
pub(crate) fn mark_read(&mut self) {
|
pub(crate) fn mark_read(&mut self) {
|
||||||
let Some(id) = self.current else { return };
|
let Some(id) = self.state.current else { return };
|
||||||
let Some(view) = self.sessions.get_mut(&id) else { return };
|
let Some(view) = self.state.sessions.get_mut(&id) else { return };
|
||||||
let index = view.current_tab;
|
let index = view.current_tab;
|
||||||
let tab = &mut view.tabs[index];
|
let tab = &mut view.tabs[index];
|
||||||
tab.divider = None;
|
tab.divider = None;
|
||||||
@@ -737,7 +710,7 @@ impl App {
|
|||||||
if self.demo_ui {
|
if self.demo_ui {
|
||||||
return;
|
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(server_uid) = view.state.server_uid.as_deref() else { return };
|
||||||
let Some(tab) = view.tabs.get_mut(index) 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 {
|
let Some((ts_ms, message)) = tab.read.filter(|r| tab.stored_read != Some(*r)) else {
|
||||||
@@ -759,7 +732,7 @@ impl App {
|
|||||||
/// Store where every chat of session `id` was read (it ended, or the
|
/// Store where every chat of session `id` was read (it ended, or the
|
||||||
/// app exits).
|
/// app exits).
|
||||||
pub(crate) fn save_reads(&mut self, id: i64) {
|
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 {
|
for index in 0..count {
|
||||||
self.save_read(id, index);
|
self.save_read(id, index);
|
||||||
}
|
}
|
||||||
@@ -769,7 +742,7 @@ impl App {
|
|||||||
/// server is known (or another one: the gateway's id wins): its tabs
|
/// server is known (or another one: the gateway's id wins): its tabs
|
||||||
/// start from there, now and when they open.
|
/// start from there, now and when they open.
|
||||||
pub(crate) fn load_reads(&mut self, id: i64) {
|
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
|
if self.demo_ui || view.state.server_uid.is_none() || view.reads_of == view.state.server_uid
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -796,8 +769,8 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn gateway_update(&mut self, id: i64, update: GatewayUpdate) {
|
pub(crate) fn gateway_update(&mut self, id: i64, update: GatewayUpdate) {
|
||||||
let current = self.current == Some(id);
|
let current = self.state.current == Some(id);
|
||||||
let view = self.sessions.entry(id).or_default();
|
let view = self.state.sessions.entry(id).or_default();
|
||||||
match update {
|
match update {
|
||||||
GatewayUpdate::Connected { capabilities, .. }
|
GatewayUpdate::Connected { capabilities, .. }
|
||||||
| GatewayUpdate::Capabilities { capabilities } => {
|
| GatewayUpdate::Capabilities { capabilities } => {
|
||||||
@@ -978,8 +951,8 @@ impl App {
|
|||||||
|
|
||||||
/// The topics drawer's search.
|
/// The topics drawer's search.
|
||||||
pub(crate) fn search_topics(&mut self, text: String) {
|
pub(crate) fn search_topics(&mut self, text: String) {
|
||||||
if self.topic_filter != text {
|
if self.state.topic_filter != text {
|
||||||
self.topic_filter = text;
|
self.state.topic_filter = text;
|
||||||
self.refresh_chat();
|
self.refresh_chat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1026,7 +999,7 @@ impl App {
|
|||||||
|
|
||||||
/// Download a file a message links, into the download folder.
|
/// Download a file a message links, into the download folder.
|
||||||
pub(crate) fn download_file(&mut self, key: i32, index: i32) {
|
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 index = index.max(0) as usize;
|
||||||
let Some(file) =
|
let Some(file) =
|
||||||
self.message_of(key).and_then(|m| m.message.file_refs().into_iter().nth(index))
|
self.message_of(key).and_then(|m| m.message.file_refs().into_iter().nth(index))
|
||||||
@@ -1035,7 +1008,7 @@ impl App {
|
|||||||
};
|
};
|
||||||
let dir = dirs::download_dir().unwrap_or_else(|| PathBuf::from("."));
|
let dir = dirs::download_dir().unwrap_or_else(|| PathBuf::from("."));
|
||||||
let path = dir.join(&file.name);
|
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;
|
let transfer = view.next_transfer;
|
||||||
view.next_transfer += 1;
|
view.next_transfer += 1;
|
||||||
view.downloads.insert(
|
view.downloads.insert(
|
||||||
@@ -1054,10 +1027,10 @@ impl App {
|
|||||||
|
|
||||||
pub(crate) fn transfer_progress(&mut self, id: i64, transfer: u64, state: TransferState) {
|
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.
|
// 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 {
|
match &state {
|
||||||
TransferState::Done { size, .. } => {
|
TransferState::Done { size, .. } => {
|
||||||
self.uploads.remove(&transfer);
|
self.state.uploads.remove(&transfer);
|
||||||
let file = voelin_model::FileRef {
|
let file = voelin_model::FileRef {
|
||||||
channel,
|
channel,
|
||||||
path: "/".into(),
|
path: "/".into(),
|
||||||
@@ -1073,11 +1046,11 @@ impl App {
|
|||||||
self.set_status(format!("{name} shared"));
|
self.set_status(format!("{name} shared"));
|
||||||
}
|
}
|
||||||
TransferState::Failed(e) => {
|
TransferState::Failed(e) => {
|
||||||
self.uploads.remove(&transfer);
|
self.state.uploads.remove(&transfer);
|
||||||
self.set_status(format!("Could not upload {name}: {e}"));
|
self.set_status(format!("Could not upload {name}: {e}"));
|
||||||
}
|
}
|
||||||
TransferState::Cancelled => {
|
TransferState::Cancelled => {
|
||||||
self.uploads.remove(&transfer);
|
self.state.uploads.remove(&transfer);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@@ -1087,14 +1060,14 @@ impl App {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let done = matches!(state, TransferState::Done { .. });
|
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 };
|
let Some(entry) = view.downloads.get_mut(&transfer) else { return };
|
||||||
entry.state = state;
|
entry.state = state;
|
||||||
let name = entry.name.clone();
|
let name = entry.name.clone();
|
||||||
if done {
|
if done {
|
||||||
self.set_status(format!("{name} downloaded"));
|
self.set_status(format!("{name} downloaded"));
|
||||||
}
|
}
|
||||||
if self.current == Some(id) {
|
if self.state.current == Some(id) {
|
||||||
self.refresh_chat();
|
self.refresh_chat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1102,8 +1075,8 @@ impl App {
|
|||||||
/// Attach a file to the current channel chat: ask for one, upload it
|
/// Attach a file to the current channel chat: ask for one, upload it
|
||||||
/// into the channel and post its link.
|
/// into the channel and post its link.
|
||||||
pub(crate) fn attach_file(&mut self) {
|
pub(crate) fn attach_file(&mut self) {
|
||||||
let Some(id) = self.current else { return };
|
let Some(id) = self.state.current else { return };
|
||||||
let Some(view) = self.sessions.get(&id) else { return };
|
let Some(view) = self.state.sessions.get(&id) else { return };
|
||||||
let ChatTarget::Channel(channel) = view.tabs[view.current_tab].target else {
|
let ChatTarget::Channel(channel) = view.tabs[view.current_tab].target else {
|
||||||
self.set_status("Files can be attached to a channel's chat.");
|
self.set_status("Files can be attached to a channel's chat.");
|
||||||
return;
|
return;
|
||||||
@@ -1126,10 +1099,10 @@ impl App {
|
|||||||
/// Upload a file into a channel and link it in the chat once it is up.
|
/// 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) {
|
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 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;
|
let transfer = view.next_transfer;
|
||||||
view.next_transfer += 1;
|
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 {
|
self.engine.send(Command::UploadFile {
|
||||||
session: id as u64,
|
session: id as u64,
|
||||||
transfer,
|
transfer,
|
||||||
|
|||||||
+21
-27
@@ -83,10 +83,9 @@ use voelin_model::{
|
|||||||
};
|
};
|
||||||
use voelin_store::{Bookmark, MessageSource};
|
use voelin_store::{Bookmark, MessageSource};
|
||||||
|
|
||||||
use crate::app::{
|
use crate::app::{App, Bridge, MainWindow, MobileTab, Nav, Page, SettingsSection, with_app};
|
||||||
App, Bridge, MainWindow, MobileTab, Nav, Page, RecordingItem, SettingsSection, with_app,
|
|
||||||
};
|
|
||||||
use crate::settings::LastVoice;
|
use crate::settings::LastVoice;
|
||||||
|
use crate::vm::bridge::RecordingItem;
|
||||||
|
|
||||||
/// The switches read at start.
|
/// The switches read at start.
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
@@ -185,7 +184,7 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
|||||||
}
|
}
|
||||||
Some("observe") => {
|
Some("observe") => {
|
||||||
with_app(|app| {
|
with_app(|app| {
|
||||||
if let Some(id) = app.current {
|
if let Some(id) = app.state.current {
|
||||||
app.observe(id);
|
app.observe(id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -215,7 +214,7 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
|||||||
}
|
}
|
||||||
// The current server's dialog, Advanced open.
|
// The current server's dialog, Advanced open.
|
||||||
"bookmark" if arg == "edit" => {
|
"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);
|
nav.invoke_edit_server(id as i32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -426,9 +425,9 @@ fn late(
|
|||||||
/// The current chat's read marker `back` messages before its end, as if
|
/// The current chat's read marker `back` messages before its end, as if
|
||||||
/// they came while away, its "New" divider shown (`VOELIN_OPEN=unread`).
|
/// they came while away, its "New" divider shown (`VOELIN_OPEN=unread`).
|
||||||
fn open_unread(app: &mut App, back: usize) {
|
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 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_client = view.state.own_client;
|
||||||
let own = |m: &ChatMessage| crate::social::own_message(&own_uids, own_client, m);
|
let own = |m: &ChatMessage| crate::social::own_message(&own_uids, own_client, m);
|
||||||
let index = view.current_tab;
|
let index = view.current_tab;
|
||||||
@@ -484,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
|
/// channel, which asks for its password; `wrong` as if the server had
|
||||||
/// refused one.
|
/// refused one.
|
||||||
fn open_channel_password(app: &mut App, wrong: bool) {
|
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
|
let locked = app
|
||||||
.view()
|
.view()
|
||||||
.and_then(|v| v.presence.channels.values().filter(|c| c.has_password).map(|c| c.id).min());
|
.and_then(|v| v.presence.channels.values().filter(|c| c.has_password).map(|c| c.id).min());
|
||||||
@@ -550,7 +549,7 @@ fn demo_ui(app: &mut App) {
|
|||||||
client_version: None,
|
client_version: None,
|
||||||
cached_server_icon: None,
|
cached_server_icon: None,
|
||||||
};
|
};
|
||||||
app.bookmarks = vec![
|
app.state.bookmarks = vec![
|
||||||
Bookmark {
|
Bookmark {
|
||||||
gateway_url: Some("wss://gw.nightfall.example/v1".into()),
|
gateway_url: Some("wss://gw.nightfall.example/v1".into()),
|
||||||
..bookmark(DEMO, "Nightfall Guild", "ts.nightfall.example:9987")
|
..bookmark(DEMO, "Nightfall Guild", "ts.nightfall.example:9987")
|
||||||
@@ -560,12 +559,12 @@ fn demo_ui(app: &mut App) {
|
|||||||
];
|
];
|
||||||
// Home's "Continue where you left off": a channel of a server without
|
// Home's "Continue where you left off": a channel of a server without
|
||||||
// voice, so it shows Join.
|
// voice, so it shows Join.
|
||||||
app.settings.last_voice = Some(LastVoice {
|
app.state.settings.last_voice = Some(LastVoice {
|
||||||
bookmark: DEMO + 1,
|
bookmark: DEMO + 1,
|
||||||
address: "pixel.example".into(),
|
address: "pixel.example".into(),
|
||||||
channel: vec!["Art Corner".into()],
|
channel: vec!["Art Corner".into()],
|
||||||
});
|
});
|
||||||
app.current = Some(DEMO);
|
app.state.current = Some(DEMO);
|
||||||
let session = DEMO as u64;
|
let session = DEMO as u64;
|
||||||
|
|
||||||
let mut p = Presence { server_name: "Nightfall Guild".into(), ..Default::default() };
|
let mut p = Presence { server_name: "Nightfall Guild".into(), ..Default::default() };
|
||||||
@@ -941,7 +940,7 @@ fn demo_social(app: &mut App) {
|
|||||||
// The samples came one by one, as new ones do: all are read (no "New"
|
// 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
|
// line, which a gateway page on screen gets), but for Mira's and
|
||||||
// Lumen's messages, which came while away.
|
// 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 {
|
for tab in &mut view.tabs {
|
||||||
tab.divider = None;
|
tab.divider = None;
|
||||||
tab.catch_up();
|
tab.catch_up();
|
||||||
@@ -984,7 +983,7 @@ fn demo_social(app: &mut App) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// The pictures of the links, as if downloaded.
|
// 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
|
for (channel, name) in
|
||||||
[(2, "night-castle.png"), (2, "guild-banner.png"), (2, "map-notes.png")]
|
[(2, "night-castle.png"), (2, "guild-banner.png"), (2, "map-notes.png")]
|
||||||
{
|
{
|
||||||
@@ -996,7 +995,7 @@ fn demo_social(app: &mut App) {
|
|||||||
};
|
};
|
||||||
view.extra.previews.insert(
|
view.extra.previews.insert(
|
||||||
crate::previews::link_key(&file),
|
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(),
|
demo_picture(640, 360, name.len() as u32).into(),
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
@@ -1195,15 +1194,12 @@ fn demo_social(app: &mut App) {
|
|||||||
clip: name.contains("clip"),
|
clip: name.contains("clip"),
|
||||||
path: format!("/tmp/{name}").into(),
|
path: format!("/tmp/{name}").into(),
|
||||||
};
|
};
|
||||||
crate::vm::list::sync(
|
app.models.social.recordings.sync(&[
|
||||||
&app.models.social.recordings,
|
recording("raid-night-2026-10-02.webm", "1.2 GB · 2 Oct 22:41"),
|
||||||
&[
|
recording("clip-boss-down.mkv", "38.4 MB · 2 Oct 21:57"),
|
||||||
recording("raid-night-2026-10-02.webm", "1.2 GB · 2 Oct 22:41"),
|
recording("lands-between-stream.mkv", "2.8 GB · 28 Sep 20:12"),
|
||||||
recording("clip-boss-down.mkv", "38.4 MB · 2 Oct 21:57"),
|
recording("clip-lucky-parry.mkv", "12.1 MB · 28 Sep 19:40"),
|
||||||
recording("lands-between-stream.mkv", "2.8 GB · 28 Sep 20:12"),
|
]);
|
||||||
recording("clip-lucky-parry.mkv", "12.1 MB · 28 Sep 19:40"),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
app.refresh_chats();
|
app.refresh_chats();
|
||||||
app.refresh_people();
|
app.refresh_people();
|
||||||
app.refresh_home();
|
app.refresh_home();
|
||||||
@@ -1246,7 +1242,7 @@ fn demo_pictures(app: &mut App) {
|
|||||||
};
|
};
|
||||||
let mut events = vec![Event::ServerDetails {
|
let mut events = vec![Event::ServerDetails {
|
||||||
session,
|
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 {
|
details: Arc::new(voelin_model::ServerDetails {
|
||||||
icon: DEMO_SERVER_ICON,
|
icon: DEMO_SERVER_ICON,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@@ -1638,9 +1634,8 @@ fn demo_chat(app: &mut App, session: u64) {
|
|||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
let mut id = 1;
|
|
||||||
let mut pinned: Vec<HistoryMessage> = Vec::new();
|
let mut pinned: Vec<HistoryMessage> = Vec::new();
|
||||||
for (chat, author, client, text, ago, relay, reactions, pin, topic) in lines {
|
for (id, (chat, author, client, text, ago, relay, reactions, pin, topic)) in (1..).zip(lines) {
|
||||||
let target = if chat == DEMO { ChatTarget::Channel(2) } else { ChatTarget::Server };
|
let target = if chat == DEMO { ChatTarget::Channel(2) } else { ChatTarget::Server };
|
||||||
let message = HistoryMessage {
|
let message = HistoryMessage {
|
||||||
id,
|
id,
|
||||||
@@ -1671,7 +1666,6 @@ fn demo_chat(app: &mut App, session: u64) {
|
|||||||
source: HistorySource::Gateway,
|
source: HistorySource::Gateway,
|
||||||
complete: false,
|
complete: false,
|
||||||
});
|
});
|
||||||
id += 1;
|
|
||||||
}
|
}
|
||||||
// A server chat besides the channel chat.
|
// A server chat besides the channel chat.
|
||||||
app.handle_event(Event::ChatHistory {
|
app.handle_event(Event::ChatHistory {
|
||||||
|
|||||||
@@ -3,13 +3,16 @@
|
|||||||
//! home page), our permissions there, its configuration (gateway
|
//! home page), our permissions there, its configuration (gateway
|
||||||
//! administration). The pins, reactions and topics are in `chat.rs`.
|
//! administration). The pins, reactions and topics are in `chat.rs`.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use slint::{ComponentHandle, SharedString};
|
use slint::{ComponentHandle, SharedString};
|
||||||
use voelin_core::{Command, GatewayRequest, GatewayUpdate};
|
use voelin_core::{Command, GatewayRequest, GatewayUpdate};
|
||||||
use voelin_gateway_proto::{Action, EventKind, EventQuery, EventSpec, RsvpStatus, feature};
|
use voelin_gateway_proto::{Action, EventKind, EventQuery, EventSpec, RsvpStatus, feature};
|
||||||
|
|
||||||
use crate::app::{App, Bridge, EventForm, EventItem};
|
use crate::app::{App, Bridge};
|
||||||
use crate::social::{NoticeKind, NoticeTarget, now_ms};
|
use crate::social::{NoticeKind, NoticeTarget, now_ms};
|
||||||
use crate::vm;
|
use crate::vm;
|
||||||
|
use crate::vm::bridge::{EventForm, EventItem};
|
||||||
use crate::vm::social::{date_block, event_when, format_local, parse_local, soon};
|
use crate::vm::social::{date_block, event_when, format_local, parse_local, soon};
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
@@ -26,7 +29,7 @@ impl App {
|
|||||||
use GatewayUpdate as U;
|
use GatewayUpdate as U;
|
||||||
let mut ask: Vec<GatewayRequest> = Vec::new();
|
let mut ask: Vec<GatewayRequest> = Vec::new();
|
||||||
let mut remind = None;
|
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 {
|
match update {
|
||||||
U::Connected { uid, capabilities, .. } => {
|
U::Connected { uid, capabilities, .. } => {
|
||||||
extra.gateway_uid = Some(uid.clone());
|
extra.gateway_uid = Some(uid.clone());
|
||||||
@@ -118,8 +121,8 @@ impl App {
|
|||||||
|
|
||||||
/// The events page of the current server was opened.
|
/// The events page of the current server was opened.
|
||||||
pub(crate) fn open_events(&mut self) {
|
pub(crate) fn open_events(&mut self) {
|
||||||
let Some(id) = self.current else { return };
|
let Some(id) = self.state.current else { return };
|
||||||
let loaded = self.sessions.get(&id).is_some_and(|v| v.extra.events_loaded);
|
let loaded = self.state.sessions.get(&id).is_some_and(|v| v.extra.events_loaded);
|
||||||
if !loaded {
|
if !loaded {
|
||||||
self.gateway_to(id, GatewayRequest::Events { query: EventQuery::default() });
|
self.gateway_to(id, GatewayRequest::Events { query: EventQuery::default() });
|
||||||
}
|
}
|
||||||
@@ -205,41 +208,40 @@ impl App {
|
|||||||
editable: moderate
|
editable: moderate
|
||||||
|| extra.gateway_uid.as_deref() == Some(e.creator.uid.as_str()),
|
|| extra.gateway_uid.as_deref() == Some(e.creator.uid.as_str()),
|
||||||
soon: soon(e.spec.start_ms, e.spec.end_ms, now).into(),
|
soon: soon(e.spec.start_ms, e.spec.end_ms, now).into(),
|
||||||
attendees: crate::app::model(
|
attendees: e
|
||||||
e.attendees
|
.attendees
|
||||||
.iter()
|
.iter()
|
||||||
.map(|a| {
|
.map(|a| {
|
||||||
let status = match a.status {
|
let status = match a.status {
|
||||||
RsvpStatus::Going => "going",
|
RsvpStatus::Going => "going",
|
||||||
RsvpStatus::Maybe => "maybe",
|
RsvpStatus::Maybe => "maybe",
|
||||||
RsvpStatus::NotGoing => "not going",
|
RsvpStatus::NotGoing => "not going",
|
||||||
RsvpStatus::Unknown => "?",
|
RsvpStatus::Unknown => "?",
|
||||||
};
|
};
|
||||||
SharedString::from(format!("{} ({status})", a.user.name))
|
Arc::<str>::from(format!("{} ({status})", a.user.name))
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
),
|
|
||||||
expanded: extra.expanded.contains(&e.id),
|
expanded: extra.expanded.contains(&e.id),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
vm::list::sync(&self.models.social.events, &items);
|
self.models.social.events.sync(&items);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Answer an event ("" withdraws the answer).
|
/// Answer an event ("" withdraws the answer).
|
||||||
pub(crate) fn rsvp(&mut self, event_id: i32, status: &str) {
|
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));
|
let status = (!status.is_empty()).then(|| RsvpStatus::parse(status));
|
||||||
self.gateway_to(id, GatewayRequest::Rsvp { event_id: i64::from(event_id), 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).
|
/// Show or hide who answered (fetching the event with its attendees).
|
||||||
pub(crate) fn toggle_event(&mut self, event_id: i32) {
|
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 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) {
|
if !view.extra.expanded.remove(&event_id) {
|
||||||
view.extra.expanded.insert(event_id);
|
view.extra.expanded.insert(event_id);
|
||||||
self.gateway_to(id, GatewayRequest::GetEvent { id: event_id });
|
self.gateway_to(id, GatewayRequest::GetEvent { id: event_id });
|
||||||
@@ -275,7 +277,7 @@ impl App {
|
|||||||
|
|
||||||
/// Create or change an event; the reason when the form is not right.
|
/// Create or change an event; the reason when the form is not right.
|
||||||
pub(crate) fn save_event(&mut self, form: &EventForm) -> String {
|
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 {
|
let Some(start_ms) = parse_local(&form.start) else {
|
||||||
return "Write the start as YYYY-MM-DD HH:MM.".into();
|
return "Write the start as YYYY-MM-DD HH:MM.".into();
|
||||||
};
|
};
|
||||||
@@ -289,7 +291,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
let channels = self.event_channels();
|
let channels = self.event_channels();
|
||||||
let text = |s: &slint::SharedString| Some(s.to_string()).filter(|s| !s.trim().is_empty());
|
let text = |s: &Arc<str>| Some(s.to_string()).filter(|s| !s.trim().is_empty());
|
||||||
let spec = EventSpec {
|
let spec = EventSpec {
|
||||||
title: form.title.trim().to_owned(),
|
title: form.title.trim().to_owned(),
|
||||||
description: form.description.to_string(),
|
description: form.description.to_string(),
|
||||||
@@ -313,14 +315,14 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn delete_event(&mut self, event_id: i32) {
|
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) });
|
self.gateway_to(id, GatewayRequest::DeleteEvent { id: i64::from(event_id) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Watch the stream of a live scheduled stream.
|
/// Watch the stream of a live scheduled stream.
|
||||||
pub(crate) fn watch_event(&mut self, event_id: i32) {
|
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
|
let stream = self
|
||||||
.view()
|
.view()
|
||||||
.and_then(|v| v.extra.events.iter().find(|e| e.id == i64::from(event_id)))
|
.and_then(|v| v.extra.events.iter().find(|e| e.id == i64::from(event_id)))
|
||||||
|
|||||||
@@ -9,11 +9,10 @@ use std::path::{Path, PathBuf};
|
|||||||
use slint::ComponentHandle;
|
use slint::ComponentHandle;
|
||||||
use voelin_core::VoiceState;
|
use voelin_core::VoiceState;
|
||||||
|
|
||||||
use crate::app::{
|
use crate::app::{App, Bridge, Page};
|
||||||
App, Bridge, HappeningItem, LiveItem, Page, RecordingItem, ResumeItem, ServerItem,
|
|
||||||
};
|
|
||||||
use crate::settings::LastVoice;
|
use crate::settings::LastVoice;
|
||||||
use crate::vm;
|
use crate::vm;
|
||||||
|
use crate::vm::bridge::{HappeningItem, LiveItem, RecordingItem, ResumeItem, ServerItem};
|
||||||
use crate::vm::home::ResumeAction;
|
use crate::vm::home::ResumeAction;
|
||||||
use crate::vm::social::{event_when, plain};
|
use crate::vm::social::{event_when, plain};
|
||||||
|
|
||||||
@@ -30,8 +29,10 @@ impl App {
|
|||||||
/// streaming.
|
/// streaming.
|
||||||
fn live_rooms(&self) -> Vec<LiveItem> {
|
fn live_rooms(&self) -> Vec<LiveItem> {
|
||||||
let mut rooms = Vec::new();
|
let mut rooms = Vec::new();
|
||||||
for (b, backdrop) in self.bookmarks.iter().zip(vm::servers::tints(&self.bookmarks)) {
|
for (b, backdrop) in
|
||||||
let Some(view) = self.sessions.get(&b.id) else { continue };
|
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>| {
|
let channel_of = |cid: Option<u64>| {
|
||||||
cid.and_then(|c| view.presence.channels.get(&c))
|
cid.and_then(|c| view.presence.channels.get(&c))
|
||||||
.map(|c| vm::tree::channel_title(c).0.to_owned())
|
.map(|c| vm::tree::channel_title(c).0.to_owned())
|
||||||
@@ -45,7 +46,7 @@ impl App {
|
|||||||
let avatar = match (client, uid) {
|
let avatar = match (client, uid) {
|
||||||
(Some(c), _) if view.avatar(c).is_some() => vm::avatar::image(view.avatar(c)),
|
(Some(c), _) if view.avatar(c).is_some() => vm::avatar::image(view.avatar(c)),
|
||||||
(_, Some(uid)) => self.avatar_of(uid),
|
(_, Some(uid)) => self.avatar_of(uid),
|
||||||
_ => slint::Image::default(),
|
_ => vm::ImageRef::default(),
|
||||||
};
|
};
|
||||||
LiveItem {
|
LiveItem {
|
||||||
session: b.id as i32,
|
session: b.id as i32,
|
||||||
@@ -124,8 +125,8 @@ impl App {
|
|||||||
let now = crate::social::now_ms();
|
let now = crate::social::now_ms();
|
||||||
let mut events: Vec<(i64, HappeningItem, Happening)> = Vec::new();
|
let mut events: Vec<(i64, HappeningItem, Happening)> = Vec::new();
|
||||||
let mut news = Vec::new();
|
let mut news = Vec::new();
|
||||||
for b in &self.bookmarks {
|
for b in &self.state.bookmarks {
|
||||||
let Some(view) = self.sessions.get(&b.id) else { continue };
|
let Some(view) = self.state.sessions.get(&b.id) else { continue };
|
||||||
for e in &view.extra.events {
|
for e in &view.extra.events {
|
||||||
let ends = e.spec.end_ms.unwrap_or(e.spec.start_ms + 3 * 3_600_000);
|
let ends = e.spec.end_ms.unwrap_or(e.spec.start_ms + 3 * 3_600_000);
|
||||||
if ends < now {
|
if ends < now {
|
||||||
@@ -184,16 +185,16 @@ impl App {
|
|||||||
/// `refresh_chats`).
|
/// `refresh_chats`).
|
||||||
pub(crate) fn refresh_home(&self) {
|
pub(crate) fn refresh_home(&self) {
|
||||||
let m = &self.models.social;
|
let m = &self.models.social;
|
||||||
vm::list::sync(&m.live, &self.live_rooms());
|
m.live.sync(&self.live_rooms());
|
||||||
let items: Vec<HappeningItem> = self.happenings().into_iter().map(|(i, _)| i).collect();
|
let items: Vec<HappeningItem> = self.happenings().into_iter().map(|(i, _)| i).collect();
|
||||||
vm::list::sync(&m.happenings, &items);
|
m.happenings.sync(&items);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A live room's card: watch it at once in our channel, else go to its
|
/// A live room's card: watch it at once in our channel, else go to its
|
||||||
/// server (and the streamer's channel, watching once there).
|
/// server (and the streamer's channel, watching once there).
|
||||||
pub(crate) fn watch_live(&mut self, session: i64, id: &str) {
|
pub(crate) fn watch_live(&mut self, session: i64, id: &str) {
|
||||||
self.show_server(session);
|
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) {
|
if view.streams_available() && view.streams.iter().any(|s| s.id == id) {
|
||||||
self.watch_stream(id.to_owned());
|
self.watch_stream(id.to_owned());
|
||||||
return;
|
return;
|
||||||
@@ -233,8 +234,9 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn last_resume(&self) -> Option<vm::home::Resume> {
|
fn last_resume(&self) -> Option<vm::home::Resume> {
|
||||||
let voice = |id| self.sessions.get(&id).map_or(VoiceState::Disconnected, |v| v.state.voice);
|
let voice =
|
||||||
vm::home::resume(self.settings.last_voice.as_ref(), &self.bookmarks, 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
|
/// Home's "Continue where you left off", its server as the rail shows
|
||||||
@@ -253,7 +255,7 @@ impl App {
|
|||||||
icon: server.icon.clone(),
|
icon: server.icon.clone(),
|
||||||
channel: resume.title().into(),
|
channel: resume.title().into(),
|
||||||
open: resume.action == ResumeAction::Open,
|
open: resume.action == ResumeAction::Open,
|
||||||
connecting: server.status == "connecting",
|
connecting: &*server.status == "connecting",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,17 +275,17 @@ impl App {
|
|||||||
if self.demo_ui {
|
if self.demo_ui {
|
||||||
return false;
|
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 {
|
let (VoiceState::Connected, Some(cid)) = (view.state.voice, view.state.own_channel) else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let channel = vm::tree::channel_path(&view.presence, cid);
|
let channel = vm::tree::channel_path(&view.presence, cid);
|
||||||
let Some(b) = self.bookmark(session).filter(|_| !channel.is_empty()) else { return false };
|
let Some(b) = self.bookmark(session).filter(|_| !channel.is_empty()) else { return false };
|
||||||
let last = LastVoice { bookmark: session, address: b.address.clone(), channel };
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
self.settings.last_voice = Some(last);
|
self.state.settings.last_voice = Some(last);
|
||||||
self.store_settings();
|
self.store_settings();
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@@ -304,7 +306,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
let dir = self.recordings_dir();
|
let dir = self.recordings_dir();
|
||||||
let items = recordings_in(&dir);
|
let items = recordings_in(&dir);
|
||||||
vm::list::sync(&self.models.social.recordings, &items);
|
self.models.social.recordings.sync(&items);
|
||||||
if let Some(ui) = self.ui.upgrade() {
|
if let Some(ui) = self.ui.upgrade() {
|
||||||
ui.global::<Bridge>().set_recordings_dir(dir.display().to_string().into());
|
ui.global::<Bridge>().set_recordings_dir(dir.display().to_string().into());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,23 +2,13 @@
|
|||||||
//! `Store::default_identity`), chosen under Settings → Profiles, and the
|
//! `Store::default_identity`), chosen under Settings → Profiles, and the
|
||||||
//! import of the official clients' identities on start
|
//! import of the official clients' identities on start
|
||||||
//! (`voelin_core::identity::import_new`, app.rs). The rest of the Profiles
|
//! (`voelin_core::identity::import_new`, app.rs). The rest of the Profiles
|
||||||
//! page is in `settings_pages.rs`.
|
//! page is in `settings_pages/`.
|
||||||
|
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
use voelin_core::settings::IDENTITY_IMPORT;
|
use voelin_core::settings::IDENTITY_IMPORT;
|
||||||
use voelin_store::IdentityOrigin;
|
|
||||||
|
|
||||||
use crate::app::App;
|
use crate::app::App;
|
||||||
|
|
||||||
/// Where an identity came from, as Profiles says it.
|
|
||||||
pub(crate) fn origin_label(origin: IdentityOrigin) -> &'static str {
|
|
||||||
match origin {
|
|
||||||
IdentityOrigin::Created => "Made in Voelin",
|
|
||||||
IdentityOrigin::Imported => "Imported",
|
|
||||||
IdentityOrigin::User => "Chosen by you",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
/// The user's choice of the identity servers see us as, from the next
|
/// The user's choice of the identity servers see us as, from the next
|
||||||
/// connection on; no import replaces it.
|
/// connection on; no import replaces it.
|
||||||
@@ -51,16 +41,3 @@ impl App {
|
|||||||
self.refresh_identities();
|
self.refresh_identities();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn rows_say_where_an_identity_came_from() {
|
|
||||||
assert_eq!(origin_label(IdentityOrigin::Created), "Made in Voelin");
|
|
||||||
assert_eq!(origin_label(IdentityOrigin::Imported), "Imported");
|
|
||||||
// Made by the app, then chosen: an import never replaces it.
|
|
||||||
assert_eq!(origin_label(IdentityOrigin::User), "Chosen by you");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -65,8 +65,8 @@ pub(crate) fn take() {
|
|||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
fn share(&mut self, nav: &Nav<'_>, text: Option<String>, files: Vec<PathBuf>) {
|
fn share(&mut self, nav: &Nav<'_>, text: Option<String>, files: Vec<PathBuf>) {
|
||||||
let current = self.current.and_then(|id| {
|
let current = self.state.current.and_then(|id| {
|
||||||
let view = self.sessions.get(&id)?;
|
let view = self.state.sessions.get(&id)?;
|
||||||
let tab = &view.tabs[view.current_tab];
|
let tab = &view.tabs[view.current_tab];
|
||||||
// Files go to the channel of the chat, else to ours.
|
// Files go to the channel of the chat, else to ours.
|
||||||
let channel = match tab.target {
|
let channel = match tab.target {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ mod bind;
|
|||||||
mod camera;
|
mod camera;
|
||||||
mod chat;
|
mod chat;
|
||||||
mod dev;
|
mod dev;
|
||||||
mod emoji;
|
|
||||||
mod events;
|
mod events;
|
||||||
mod home;
|
mod home;
|
||||||
mod hotkey;
|
mod hotkey;
|
||||||
@@ -19,14 +18,15 @@ mod messages;
|
|||||||
mod popout;
|
mod popout;
|
||||||
mod previews;
|
mod previews;
|
||||||
mod servers;
|
mod servers;
|
||||||
mod settings;
|
|
||||||
mod settings_page;
|
mod settings_page;
|
||||||
mod settings_pages;
|
mod settings_pages;
|
||||||
mod social;
|
mod social;
|
||||||
mod streams;
|
mod streams;
|
||||||
mod studio;
|
mod studio;
|
||||||
mod video;
|
mod video;
|
||||||
mod vm;
|
|
||||||
|
// The view models live in their own crate; the modules keep their old paths.
|
||||||
|
use voelin_ui_vm::{self as vm, emoji, settings};
|
||||||
|
|
||||||
pub use app::{HostedEngine, RunOptions, run};
|
pub use app::{HostedEngine, RunOptions, run};
|
||||||
pub use inbox::{Request, request};
|
pub use inbox::{Request, request};
|
||||||
@@ -29,9 +29,14 @@ impl App {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
let in_voice = |id: i64| {
|
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),
|
Some((id, true)) => self.move_by_link(id, &link),
|
||||||
saved => self.open_link_form(saved.map(|(id, _)| 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) {
|
fn move_by_link(&mut self, session: i64, link: &ServerLink) {
|
||||||
self.show_server(session);
|
self.show_server(session);
|
||||||
let Some(path) = &link.channel else { return };
|
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 Some(channel) = vm::servers::channel_by_path(&view.presence, path) else {
|
||||||
let server = self.bookmark(session).map(|b| b.name.clone()).unwrap_or_default();
|
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}"));
|
self.set_status(format!("{server} has no channel \u{201c}{path}\u{201d}"));
|
||||||
@@ -64,7 +69,7 @@ impl App {
|
|||||||
let form = vm::servers::link_form(link, form, &self.default_nickname());
|
let form = vm::servers::link_form(link, form, &self.default_nickname());
|
||||||
let Some(ui) = self.ui.upgrade() else { return };
|
let Some(ui) = self.ui.upgrade() else { return };
|
||||||
let nav = ui.global::<Nav>();
|
let nav = ui.global::<Nav>();
|
||||||
nav.set_bookmark_form(form);
|
nav.set_bookmark_form(form.into());
|
||||||
nav.set_bookmark_open(true);
|
nav.set_bookmark_open(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,12 +2,15 @@
|
|||||||
//! (private chat, poke, contacts, per-client volume). The rows themselves
|
//! (private chat, poke, contacts, per-client volume). The rows themselves
|
||||||
//! are built in `vm::tree::members`.
|
//! are built in `vm::tree::members`.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use slint::ComponentHandle;
|
use slint::ComponentHandle;
|
||||||
use voelin_core::{Command, Contact, Relation};
|
use voelin_core::{Command, Contact, Relation};
|
||||||
|
|
||||||
use crate::app::{App, Bridge, MemberCard, Nav};
|
use crate::app::{App, Bridge, Nav};
|
||||||
use crate::settings::ClientPlayback;
|
use crate::settings::ClientPlayback;
|
||||||
use crate::vm;
|
use crate::vm;
|
||||||
|
use crate::vm::bridge::MemberCard;
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
/// `VOELIN_OPEN=member`: the card of the first person that is not us.
|
/// `VOELIN_OPEN=member`: the card of the first person that is not us.
|
||||||
@@ -43,10 +46,13 @@ impl App {
|
|||||||
let id = view.member_card?;
|
let id = view.member_card?;
|
||||||
let client = view.presence.clients.get(&id)?;
|
let client = view.presence.clients.get(&id)?;
|
||||||
let uid = client.uid.clone();
|
let uid = client.uid.clone();
|
||||||
let contact = uid.as_ref().and_then(|u| self.contacts.get(u));
|
let contact = uid.as_ref().and_then(|u| self.state.contacts.get(u));
|
||||||
let playback =
|
let playback = uid
|
||||||
uid.as_ref().and_then(|u| self.playback.get(u)).copied().unwrap_or_default();
|
.as_ref()
|
||||||
let groups: Vec<slint::SharedString> = client
|
.and_then(|u| self.state.playback.get(u))
|
||||||
|
.copied()
|
||||||
|
.unwrap_or_default();
|
||||||
|
let groups: Vec<Arc<str>> = client
|
||||||
.server_groups
|
.server_groups
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|g| view.server_groups.iter().find(|i| i.id == *g))
|
.filter_map(|g| view.server_groups.iter().find(|i| i.id == *g))
|
||||||
@@ -62,8 +68,8 @@ impl App {
|
|||||||
avatar: vm::avatar::image(view.avatar(id)),
|
avatar: vm::avatar::image(view.avatar(id)),
|
||||||
status: vm::tree::status_of(client, view.talking.contains(&id)).into(),
|
status: vm::tree::status_of(client, view.talking.contains(&id)).into(),
|
||||||
description: client.description.clone().unwrap_or_default().into(),
|
description: client.description.clone().unwrap_or_default().into(),
|
||||||
groups: crate::app::model(groups),
|
groups,
|
||||||
badges: crate::app::model(badges),
|
badges,
|
||||||
country: client.country.clone().unwrap_or_default().into(),
|
country: client.country.clone().unwrap_or_default().into(),
|
||||||
talk_power: client.talk_power,
|
talk_power: client.talk_power,
|
||||||
friend: contact.is_some_and(|c| c.relation == Relation::Friend),
|
friend: contact.is_some_and(|c| c.relation == Relation::Friend),
|
||||||
@@ -75,13 +81,13 @@ impl App {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
bridge.set_member_card(card);
|
bridge.set_member_card(card.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The card's buttons: "message", "poke", "friend", "blocked", "mute".
|
/// The card's buttons: "message", "poke", "friend", "blocked", "mute".
|
||||||
pub(crate) fn member_action(&mut self, action: &str) {
|
pub(crate) fn member_action(&mut self, action: &str) {
|
||||||
let Some(id) = self.current else { return };
|
let Some(id) = self.state.current else { return };
|
||||||
let Some(view) = self.sessions.get(&id) 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 {
|
let Some(client) = view.member_card.and_then(|c| view.presence.clients.get(&c)) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@@ -102,18 +108,22 @@ impl App {
|
|||||||
"friend" | "blocked" => {
|
"friend" | "blocked" => {
|
||||||
let Some(uid) = uid else { return };
|
let Some(uid) = uid else { return };
|
||||||
let wanted = if action == "friend" { Relation::Friend } else { Relation::Blocked };
|
let wanted = if action == "friend" { Relation::Friend } else { Relation::Blocked };
|
||||||
let current = self.contacts.get(&uid).map(|c| c.relation);
|
let current = self.state.contacts.get(&uid).map(|c| c.relation);
|
||||||
let mut contact =
|
let mut contact = self
|
||||||
self.contacts.get(&uid).cloned().unwrap_or_else(|| Contact::new(uid.clone()));
|
.state
|
||||||
|
.contacts
|
||||||
|
.get(&uid)
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or_else(|| Contact::new(uid.clone()));
|
||||||
contact.nickname = nickname;
|
contact.nickname = nickname;
|
||||||
contact.relation = if current == Some(wanted) { Relation::Neutral } else { wanted };
|
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.engine.send(Command::SetContact { contact: Box::new(contact) });
|
||||||
self.refresh_member_card();
|
self.refresh_member_card();
|
||||||
}
|
}
|
||||||
"mute" => {
|
"mute" => {
|
||||||
let Some(uid) = uid else { return };
|
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;
|
playback.muted = !playback.muted;
|
||||||
self.set_playback(&uid, client_id, playback);
|
self.set_playback(&uid, client_id, playback);
|
||||||
}
|
}
|
||||||
@@ -123,9 +133,9 @@ impl App {
|
|||||||
|
|
||||||
/// Open the poke dialog for a client (the member card, a contact).
|
/// Open the poke dialog for a client (the member card, a contact).
|
||||||
pub(crate) fn ask_poke(&mut self, session: i64, client: u16) {
|
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);
|
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 Some(ui) = self.ui.upgrade() else { return };
|
||||||
let nav = ui.global::<Nav>();
|
let nav = ui.global::<Nav>();
|
||||||
nav.set_poke_name(name.into());
|
nav.set_poke_name(name.into());
|
||||||
@@ -134,7 +144,7 @@ impl App {
|
|||||||
|
|
||||||
/// The poke dialog's Send, with its message (may be empty).
|
/// The poke dialog's Send, with its message (may be empty).
|
||||||
pub(crate) fn send_poke(&mut self, text: &str) {
|
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 {
|
if !self.demo_ui {
|
||||||
self.engine.send(Command::Poke {
|
self.engine.send(Command::Poke {
|
||||||
session: session as u64,
|
session: session as u64,
|
||||||
@@ -152,7 +162,7 @@ impl App {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let (client_id, Some(uid)) = (client.id, client.uid.clone()) else { 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);
|
playback.volume = (percent / 100.0).clamp(0.0, 4.0);
|
||||||
self.set_playback(&uid, client_id, playback);
|
self.set_playback(&uid, client_id, playback);
|
||||||
}
|
}
|
||||||
@@ -160,11 +170,13 @@ impl App {
|
|||||||
/// Store one client's playback and apply it to the session.
|
/// Store one client's playback and apply it to the session.
|
||||||
fn set_playback(&mut self, uid: &str, client: u16, playback: ClientPlayback) {
|
fn set_playback(&mut self, uid: &str, client: u16, playback: ClientPlayback) {
|
||||||
if playback.is_default() {
|
if playback.is_default() {
|
||||||
self.playback.remove(uid);
|
self.state.playback.remove(uid);
|
||||||
} else {
|
} 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");
|
tracing::warn!(%e, "could not store client volumes");
|
||||||
}
|
}
|
||||||
self.command(|session| Command::SetClientMuted { session, client, muted: playback.muted });
|
self.command(|session| Command::SetClientMuted { session, client, muted: playback.muted });
|
||||||
|
|||||||
+114
-106
@@ -14,32 +14,21 @@
|
|||||||
//! read-only.
|
//! read-only.
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use slint::{ComponentHandle, Image, SharedString};
|
use slint::ComponentHandle;
|
||||||
use voelin_core::{Command, HistoryMessage, OfflineMessage, OfflineMessageInfo, VoiceState};
|
use voelin_core::{Command, HistoryMessage, OfflineMessage, OfflineMessageInfo, VoiceState};
|
||||||
use voelin_model::ChatTarget;
|
use voelin_model::ChatTarget;
|
||||||
use voelin_store::PageQuery;
|
use voelin_store::PageQuery;
|
||||||
|
|
||||||
use crate::app::{
|
use crate::app::{App, Bridge, Nav, Page, SessionView, later};
|
||||||
App, Bridge, ConversationItem, DmPeer, FileItem, Nav, OfflineForm, Page, SessionView, later,
|
|
||||||
};
|
|
||||||
use crate::vm;
|
use crate::vm;
|
||||||
use crate::vm::social::{ago, list_time, matches, plain, preview};
|
use crate::vm::bridge::{ConversationItem, DmPeer, FileItem, OfflineForm};
|
||||||
|
use crate::vm::social::{ChatRef, ago, list_time, matches, plain, preview};
|
||||||
|
|
||||||
/// Keys of offline messages in the conversation list start here.
|
/// Keys of offline messages in the conversation list start here.
|
||||||
const MAIL: i32 = 10_000;
|
const MAIL: i32 = 10_000;
|
||||||
|
|
||||||
/// A chat of any server.
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
|
||||||
pub(crate) struct ChatRef {
|
|
||||||
/// The bookmark (session) it belongs to, when known.
|
|
||||||
pub session: Option<i64>,
|
|
||||||
pub server_uid: Option<String>,
|
|
||||||
pub target: ChatTarget,
|
|
||||||
pub last: Option<HistoryMessage>,
|
|
||||||
pub unread: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The open conversation.
|
/// The open conversation.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub(crate) struct Open {
|
pub(crate) struct Open {
|
||||||
@@ -81,7 +70,7 @@ impl App {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.social.dm.bookmark_of.clear();
|
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());
|
let gateways = b.gateways().into_iter().chain(b.gateway_url.clone());
|
||||||
for alias in std::iter::once(format!("voice:{}", b.address))
|
for alias in std::iter::once(format!("voice:{}", b.address))
|
||||||
.chain(gateways.map(|url| format!("gateway:{url}")))
|
.chain(gateways.map(|url| format!("gateway:{url}")))
|
||||||
@@ -107,7 +96,8 @@ impl App {
|
|||||||
|
|
||||||
/// The session a server unique id belongs to.
|
/// The session a server unique id belongs to.
|
||||||
fn session_of_server(&self, server_uid: &str) -> Option<i64> {
|
fn session_of_server(&self, server_uid: &str) -> Option<i64> {
|
||||||
self.sessions
|
self.state
|
||||||
|
.sessions
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(_, v)| v.state.server_uid.as_deref() == Some(server_uid))
|
.find(|(_, v)| v.state.server_uid.as_deref() == Some(server_uid))
|
||||||
.map(|(id, _)| *id)
|
.map(|(id, _)| *id)
|
||||||
@@ -116,18 +106,18 @@ impl App {
|
|||||||
|
|
||||||
/// What we call the peer of a private chat.
|
/// What we call the peer of a private chat.
|
||||||
pub(crate) fn peer_name(&self, uid: &str, last: Option<&HistoryMessage>) -> String {
|
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();
|
return c.nickname.clone();
|
||||||
}
|
}
|
||||||
if let Some(s) = self.spots_of(uid).first() {
|
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| {
|
let from_peer = |m: &HistoryMessage| {
|
||||||
(m.message.author_uid.as_deref() == Some(uid)).then(|| m.message.author_name.clone())
|
(m.message.author_uid.as_deref() == Some(uid)).then(|| m.message.author_name.clone())
|
||||||
};
|
};
|
||||||
last.and_then(from_peer)
|
last.and_then(from_peer)
|
||||||
.or_else(|| {
|
.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()))
|
(t.target == ChatTarget::Private(uid.to_owned()))
|
||||||
.then(|| t.messages.iter().rev().find_map(|m| from_peer(&m.message)))
|
.then(|| t.messages.iter().rev().find_map(|m| from_peer(&m.message)))
|
||||||
.flatten()
|
.flatten()
|
||||||
@@ -139,8 +129,8 @@ impl App {
|
|||||||
/// Every chat, newest first; then the lists that show them.
|
/// Every chat, newest first; then the lists that show them.
|
||||||
pub(crate) fn refresh_chats(&mut self) {
|
pub(crate) fn refresh_chats(&mut self) {
|
||||||
let mut chats: Vec<ChatRef> = Vec::new();
|
let mut chats: Vec<ChatRef> = Vec::new();
|
||||||
for b in &self.bookmarks {
|
for b in &self.state.bookmarks {
|
||||||
let Some(view) = self.sessions.get(&b.id) else { continue };
|
let Some(view) = self.state.sessions.get(&b.id) else { continue };
|
||||||
for tab in &view.tabs {
|
for tab in &view.tabs {
|
||||||
let last = tab.messages.last().map(|m| m.message.clone());
|
let last = tab.messages.last().map(|m| m.message.clone());
|
||||||
if last.is_none() && !matches!(tab.target, ChatTarget::Private(_)) {
|
if last.is_none() && !matches!(tab.target, ChatTarget::Private(_)) {
|
||||||
@@ -172,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)));
|
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.chats = chats;
|
||||||
self.social.dm.inbox = self
|
self.social.dm.inbox = self
|
||||||
|
.state
|
||||||
.bookmarks
|
.bookmarks
|
||||||
.iter()
|
.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())))
|
.flat_map(|(id, v)| v.extra.inbox.iter().map(move |m| (id, m.clone())))
|
||||||
.collect();
|
.collect();
|
||||||
self.social.dm.inbox.sort_by_key(|(_, m)| std::cmp::Reverse(m.ts_s));
|
self.social.dm.inbox.sort_by_key(|(_, m)| std::cmp::Reverse(m.ts_s));
|
||||||
@@ -196,15 +187,15 @@ impl App {
|
|||||||
),
|
),
|
||||||
ChatTarget::Channel(cid) => {
|
ChatTarget::Channel(cid) => {
|
||||||
let name = session
|
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))
|
.and_then(|v| v.presence.channels.get(cid))
|
||||||
.map_or_else(
|
.map_or_else(
|
||||||
|| format!("Channel {cid}"),
|
|| format!("Channel {cid}"),
|
||||||
|c| vm::tree::channel_title(c).0.to_owned(),
|
|c| vm::tree::channel_title(c).0.to_owned(),
|
||||||
);
|
);
|
||||||
(name, slint::Image::default(), false, 1)
|
(name, vm::ImageRef::default(), false, 1)
|
||||||
}
|
}
|
||||||
ChatTarget::Server => (server.clone(), slint::Image::default(), false, 0),
|
ChatTarget::Server => (server.clone(), vm::ImageRef::default(), false, 0),
|
||||||
};
|
};
|
||||||
let (text, ts) = match &chat.last {
|
let (text, ts) = match &chat.last {
|
||||||
Some(m) => {
|
Some(m) => {
|
||||||
@@ -258,7 +249,7 @@ impl App {
|
|||||||
.take(4)
|
.take(4)
|
||||||
.map(|(i, c)| self.conversation_item(i, c))
|
.map(|(i, c)| self.conversation_item(i, c))
|
||||||
.collect();
|
.collect();
|
||||||
vm::list::sync(&self.models.social.recent, &recent);
|
self.models.social.recent.sync(&recent);
|
||||||
// Shown beside other pages: none is the open one.
|
// Shown beside other pages: none is the open one.
|
||||||
let sidebar: Vec<ConversationItem> = vm::social::sidebar_dms(&dm.chats, 5)
|
let sidebar: Vec<ConversationItem> = vm::social::sidebar_dms(&dm.chats, 5)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -267,7 +258,7 @@ impl App {
|
|||||||
..self.conversation_item(i, &dm.chats[i])
|
..self.conversation_item(i, &dm.chats[i])
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
vm::list::sync(&self.models.social.sidebar_dms, &sidebar);
|
self.models.social.sidebar_dms.sync(&sidebar);
|
||||||
let private = |c: &&ChatRef| matches!(c.target, ChatTarget::Private(_));
|
let private = |c: &&ChatRef| matches!(c.target, ChatTarget::Private(_));
|
||||||
let items: Vec<ConversationItem> = if dm.tab == 2 {
|
let items: Vec<ConversationItem> = if dm.tab == 2 {
|
||||||
dm.inbox
|
dm.inbox
|
||||||
@@ -286,9 +277,9 @@ impl App {
|
|||||||
unread: i32::from(!m.read),
|
unread: i32::from(!m.read),
|
||||||
// A letter in the sender's colour, no initials or
|
// A letter in the sender's colour, no initials or
|
||||||
// picture under it.
|
// picture under it.
|
||||||
initials: SharedString::new(),
|
initials: Arc::default(),
|
||||||
tint: vm::avatar::tint(&name),
|
tint: vm::avatar::tint(&name),
|
||||||
avatar: Image::default(),
|
avatar: vm::ImageRef::default(),
|
||||||
online: false,
|
online: false,
|
||||||
selected: dm
|
selected: dm
|
||||||
.open
|
.open
|
||||||
@@ -296,7 +287,7 @@ impl App {
|
|||||||
.is_some_and(|o| o.mail == Some((*session, m.id))),
|
.is_some_and(|o| o.mail == Some((*session, m.id))),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter(|c| matches(&dm.filter, &[&c.title, &c.preview]))
|
.filter(|c| matches(&dm.filter, &[&*c.title, &*c.preview]))
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
dm.chats
|
dm.chats
|
||||||
@@ -304,10 +295,10 @@ impl App {
|
|||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|(_, c)| private(c) && (dm.tab == 0 || c.unread > 0))
|
.filter(|(_, c)| private(c) && (dm.tab == 0 || c.unread > 0))
|
||||||
.map(|(i, c)| self.conversation_item(i, c))
|
.map(|(i, c)| self.conversation_item(i, c))
|
||||||
.filter(|c| matches(&dm.filter, &[&c.title, &c.preview]))
|
.filter(|c| matches(&dm.filter, &[&*c.title, &*c.preview]))
|
||||||
.collect()
|
.collect()
|
||||||
};
|
};
|
||||||
vm::list::sync(&self.models.social.conversations, &items);
|
self.models.social.conversations.sync(&items);
|
||||||
bridge.set_dm_unread(self.dm_unread());
|
bridge.set_dm_unread(self.dm_unread());
|
||||||
bridge.set_inbox_unread(dm.inbox.iter().filter(|(_, m)| !m.read).count() as i32);
|
bridge.set_inbox_unread(dm.inbox.iter().filter(|(_, m)| !m.read).count() as i32);
|
||||||
}
|
}
|
||||||
@@ -315,9 +306,10 @@ impl App {
|
|||||||
/// Unread messages in the private chats of every server (the rail and
|
/// Unread messages in the private chats of every server (the rail and
|
||||||
/// the chat strip leave them out).
|
/// the chat strip leave them out).
|
||||||
pub(crate) fn dm_unread(&self) -> i32 {
|
pub(crate) fn dm_unread(&self) -> i32 {
|
||||||
self.bookmarks
|
self.state
|
||||||
|
.bookmarks
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|b| self.sessions.get(&b.id))
|
.filter_map(|b| self.state.sessions.get(&b.id))
|
||||||
.map(SessionView::private_unread)
|
.map(SessionView::private_unread)
|
||||||
.sum()
|
.sum()
|
||||||
}
|
}
|
||||||
@@ -332,9 +324,9 @@ impl App {
|
|||||||
};
|
};
|
||||||
let target = ChatTarget::Private(uid);
|
let target = ChatTarget::Private(uid);
|
||||||
// Not for a session that is gone (its server was deleted).
|
// 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)
|
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))
|
&& view.tabs.get(view.current_tab).is_some_and(|t| t.target == target))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -347,8 +339,8 @@ impl App {
|
|||||||
/// the chat it shows, which must not be the strip's.
|
/// the chat it shows, which must not be the strip's.
|
||||||
fn focus_private(&mut self, id: i64, target: ChatTarget) {
|
fn focus_private(&mut self, id: i64, target: ChatTarget) {
|
||||||
let index = self.chat_tab(id, target.clone());
|
let index = self.chat_tab(id, target.clone());
|
||||||
self.sessions.entry(id).or_default().set_current_tab(index);
|
self.state.sessions.entry(id).or_default().set_current_tab(index);
|
||||||
if self.current != Some(id) {
|
if self.state.current != Some(id) {
|
||||||
self.select_server(id);
|
self.select_server(id);
|
||||||
}
|
}
|
||||||
self.open_chat(target, true);
|
self.open_chat(target, true);
|
||||||
@@ -359,7 +351,7 @@ impl App {
|
|||||||
/// ([`SessionView::channel_tab`]).
|
/// ([`SessionView::channel_tab`]).
|
||||||
pub(crate) fn close_messages(&mut self) {
|
pub(crate) fn close_messages(&mut self) {
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
for view in self.sessions.values_mut() {
|
for view in self.state.sessions.values_mut() {
|
||||||
changed |= view.leave_private();
|
changed |= view.leave_private();
|
||||||
}
|
}
|
||||||
if !changed {
|
if !changed {
|
||||||
@@ -371,7 +363,7 @@ impl App {
|
|||||||
// (`Nav.select-server` leaves the page first) is selected by then,
|
// (`Nav.select-server` leaves the page first) is selected by then,
|
||||||
// and the chat that came back here was never on screen.
|
// and the chat that came back here was never on screen.
|
||||||
later(|app| {
|
later(|app| {
|
||||||
if let Some(id) = app.current {
|
if let Some(id) = app.state.current {
|
||||||
app.fetch_previews(id);
|
app.fetch_previews(id);
|
||||||
}
|
}
|
||||||
app.prefetch_counts();
|
app.prefetch_counts();
|
||||||
@@ -382,7 +374,7 @@ impl App {
|
|||||||
pub(crate) fn dm_tab(&mut self, tab: i32) {
|
pub(crate) fn dm_tab(&mut self, tab: i32) {
|
||||||
self.social.dm.tab = tab;
|
self.social.dm.tab = tab;
|
||||||
if tab == 2 {
|
if tab == 2 {
|
||||||
for view in self.sessions.values_mut() {
|
for view in self.state.sessions.values_mut() {
|
||||||
view.extra.inbox_asked = false;
|
view.extra.inbox_asked = false;
|
||||||
}
|
}
|
||||||
self.ask_inboxes();
|
self.ask_inboxes();
|
||||||
@@ -443,7 +435,7 @@ impl App {
|
|||||||
.find(|c| c.target == target && (session.is_none() || c.session == session));
|
.find(|c| c.target == target && (session.is_none() || c.session == session));
|
||||||
let session = session.or_else(|| known.and_then(|c| c.session));
|
let session = session.or_else(|| known.and_then(|c| c.session));
|
||||||
let server_uid = 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())
|
.and_then(|v| v.state.server_uid.clone())
|
||||||
.or_else(|| known.and_then(|c| c.server_uid.clone()));
|
.or_else(|| known.and_then(|c| c.server_uid.clone()));
|
||||||
self.open_dm(session, server_uid, uid);
|
self.open_dm(session, server_uid, uid);
|
||||||
@@ -453,7 +445,7 @@ impl App {
|
|||||||
/// the store.
|
/// the store.
|
||||||
pub(crate) fn open_dm(&mut self, session: Option<i64>, server_uid: Option<String>, uid: &str) {
|
pub(crate) fn open_dm(&mut self, session: Option<i64>, server_uid: Option<String>, uid: &str) {
|
||||||
let live = session
|
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);
|
.is_some_and(|v| v.has_history() || v.state.voice == VoiceState::Connected);
|
||||||
self.social.dm.open = Some(Open {
|
self.social.dm.open = Some(Open {
|
||||||
session,
|
session,
|
||||||
@@ -463,7 +455,7 @@ impl App {
|
|||||||
stored: !live,
|
stored: !live,
|
||||||
});
|
});
|
||||||
self.social.dm.mail = None;
|
self.social.dm.mail = None;
|
||||||
vm::list::sync(&self.models.social.dm_lines, &[]);
|
self.models.social.dm_lines.sync(&[]);
|
||||||
let target = ChatTarget::Private(uid.to_owned());
|
let target = ChatTarget::Private(uid.to_owned());
|
||||||
if let (true, Some(id)) = (live, session) {
|
if let (true, Some(id)) = (live, session) {
|
||||||
self.focus_private(id, target);
|
self.focus_private(id, target);
|
||||||
@@ -505,7 +497,7 @@ impl App {
|
|||||||
line
|
line
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
vm::list::sync(&self.models.social.dm_lines, &lines);
|
self.models.social.dm_lines.sync(&lines);
|
||||||
self.refresh_dm();
|
self.refresh_dm();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -526,15 +518,16 @@ impl App {
|
|||||||
let Some(ui) = self.ui.upgrade() else { return };
|
let Some(ui) = self.ui.upgrade() else { return };
|
||||||
let bridge = ui.global::<Bridge>();
|
let bridge = ui.global::<Bridge>();
|
||||||
let Some(open) = &self.social.dm.open else {
|
let Some(open) = &self.social.dm.open else {
|
||||||
bridge.set_dm(DmPeer::default());
|
bridge.set_dm(DmPeer::default().into());
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let uid = open.uid.as_str();
|
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 spots = self.spots_of(uid);
|
||||||
let here = open.session.and_then(|s| spots.iter().find(|sp| sp.session == s));
|
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 view = open.session.and_then(|s| self.state.sessions.get(&s));
|
||||||
let client = here.and_then(|s| self.sessions[&s.session].presence.clients.get(&s.client));
|
let client =
|
||||||
|
here.and_then(|s| self.state.sessions[&s.session].presence.clients.get(&s.client));
|
||||||
let tab =
|
let tab =
|
||||||
view.and_then(|v| v.tabs.iter().find(|t| t.target == ChatTarget::Private(uid.into())));
|
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)));
|
let name = self.peer_name(uid, tab.and_then(|t| t.messages.last().map(|m| &m.message)));
|
||||||
@@ -554,7 +547,7 @@ impl App {
|
|||||||
None => "Offline".into(),
|
None => "Offline".into(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let groups: Vec<SharedString> = match (client, view) {
|
let groups: Vec<Arc<str>> = match (client, view) {
|
||||||
(Some(c), Some(v)) => c
|
(Some(c), Some(v)) => c
|
||||||
.server_groups
|
.server_groups
|
||||||
.iter()
|
.iter()
|
||||||
@@ -563,7 +556,7 @@ impl App {
|
|||||||
.collect(),
|
.collect(),
|
||||||
_ => Vec::new(),
|
_ => Vec::new(),
|
||||||
};
|
};
|
||||||
let servers: Vec<SharedString> = if spots.is_empty() {
|
let servers: Vec<Arc<str>> = if spots.is_empty() {
|
||||||
contact
|
contact
|
||||||
.and_then(|c| c.last_server.clone())
|
.and_then(|c| c.last_server.clone())
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
@@ -638,51 +631,60 @@ impl App {
|
|||||||
.find(|(ms, m)| *ms == s && m.id == id)
|
.find(|(ms, m)| *ms == s && m.id == id)
|
||||||
.map(|(_, m)| m.clone())
|
.map(|(_, m)| m.clone())
|
||||||
});
|
});
|
||||||
bridge.set_dm(DmPeer {
|
bridge.set_dm(
|
||||||
open: true,
|
DmPeer {
|
||||||
uid: uid.into(),
|
open: true,
|
||||||
name: name.clone().into(),
|
uid: uid.into(),
|
||||||
initials: vm::avatar::initials(&name).into(),
|
name: name.clone().into(),
|
||||||
tint: vm::avatar::tint(&name),
|
initials: vm::avatar::initials(&name).into(),
|
||||||
avatar: self.avatar_of(uid),
|
tint: vm::avatar::tint(&name),
|
||||||
online: !spots.is_empty(),
|
avatar: self.avatar_of(uid),
|
||||||
status: status.into(),
|
online: !spots.is_empty(),
|
||||||
description: client.and_then(|c| c.description.clone()).unwrap_or_default().into(),
|
status: status.into(),
|
||||||
groups: crate::app::model(groups),
|
description: client.and_then(|c| c.description.clone()).unwrap_or_default().into(),
|
||||||
note: contact.map(|c| c.note.clone()).unwrap_or_default().into(),
|
groups,
|
||||||
since: contact
|
note: contact.map(|c| c.note.clone()).unwrap_or_default().into(),
|
||||||
.filter(|c| c.added_ms > 0)
|
since: contact
|
||||||
.and_then(|c| chrono::DateTime::from_timestamp_millis(c.added_ms))
|
.filter(|c| c.added_ms > 0)
|
||||||
.map(|t| {
|
.and_then(|c| chrono::DateTime::from_timestamp_millis(c.added_ms))
|
||||||
format!("Contact since {}", t.with_timezone(&chrono::Local).format("%-d %b %Y"))
|
.map(|t| {
|
||||||
})
|
format!(
|
||||||
.unwrap_or_default()
|
"Contact since {}",
|
||||||
.into(),
|
t.with_timezone(&chrono::Local).format("%-d %b %Y")
|
||||||
servers: crate::app::model(servers),
|
)
|
||||||
media: crate::app::model(media),
|
})
|
||||||
media_more: media_more as i32,
|
.unwrap_or_default()
|
||||||
files: crate::app::model(files),
|
.into(),
|
||||||
friend: contact.is_some_and(|c| c.relation == voelin_core::Relation::Friend),
|
servers,
|
||||||
blocked,
|
media,
|
||||||
volume: contact.map_or(100.0, |c| c.volume * 100.0),
|
media_more: media_more as i32,
|
||||||
muted: contact.is_some_and(|c| c.muted),
|
files,
|
||||||
can_send,
|
friend: contact.is_some_and(|c| c.relation == voelin_core::Relation::Friend),
|
||||||
notice: notice.into(),
|
blocked,
|
||||||
offline,
|
volume: contact.map_or(100.0, |c| c.volume * 100.0),
|
||||||
can_connect: !voice && in_bookmarks,
|
muted: contact.is_some_and(|c| c.muted),
|
||||||
stored: open.stored,
|
can_send,
|
||||||
mail: open.mail.is_some(),
|
notice: notice.into(),
|
||||||
mail_subject: mail.as_ref().map(|m| m.subject.clone()).unwrap_or_default().into(),
|
offline,
|
||||||
mail_text: self
|
can_connect: !voice && in_bookmarks,
|
||||||
.social
|
stored: open.stored,
|
||||||
.dm
|
mail: open.mail.is_some(),
|
||||||
.mail
|
mail_subject: mail.as_ref().map(|m| m.subject.clone()).unwrap_or_default().into(),
|
||||||
.as_ref()
|
mail_text: self
|
||||||
.map(|m| plain(&m.text))
|
.social
|
||||||
.unwrap_or_default()
|
.dm
|
||||||
.into(),
|
.mail
|
||||||
mail_time: mail.map(|m| vm::chat::time_of(m.ts_s * 1000)).unwrap_or_default().into(),
|
.as_ref()
|
||||||
});
|
.map(|m| plain(&m.text))
|
||||||
|
.unwrap_or_default()
|
||||||
|
.into(),
|
||||||
|
mail_time: mail
|
||||||
|
.map(|m| vm::chat::time_of(m.ts_s * 1000))
|
||||||
|
.unwrap_or_default()
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The buttons of the open conversation.
|
/// The buttons of the open conversation.
|
||||||
@@ -692,7 +694,7 @@ impl App {
|
|||||||
match action {
|
match action {
|
||||||
"poke" | "join" | "mute" => self.contact_action(&uid, action),
|
"poke" | "join" | "mute" => self.contact_action(&uid, action),
|
||||||
"friend" | "block" => {
|
"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" {
|
let wanted = if action == "friend" {
|
||||||
voelin_core::Relation::Friend
|
voelin_core::Relation::Friend
|
||||||
} else {
|
} else {
|
||||||
@@ -750,9 +752,14 @@ impl App {
|
|||||||
/// Send an offline message through the open conversation's server.
|
/// Send an offline message through the open conversation's server.
|
||||||
pub(crate) fn send_offline(&mut self, form: OfflineForm) {
|
pub(crate) fn send_offline(&mut self, form: OfflineForm) {
|
||||||
let session =
|
let session =
|
||||||
self.social.dm.open.as_ref().and_then(|o| o.session).or(self.current).filter(|s| {
|
self.social.dm.open.as_ref().and_then(|o| o.session).or(self.state.current).filter(
|
||||||
self.sessions.get(s).is_some_and(|v| v.state.voice == VoiceState::Connected)
|
|s| {
|
||||||
});
|
self.state
|
||||||
|
.sessions
|
||||||
|
.get(s)
|
||||||
|
.is_some_and(|v| v.state.voice == VoiceState::Connected)
|
||||||
|
},
|
||||||
|
);
|
||||||
let Some(session) = session else {
|
let Some(session) = session else {
|
||||||
self.set_status("Connect with voice to send an offline message.");
|
self.set_status("Connect with voice to send an offline message.");
|
||||||
return;
|
return;
|
||||||
@@ -798,7 +805,7 @@ impl App {
|
|||||||
pub(crate) fn mail_arrived(&mut self, session: i64, result: Result<OfflineMessage, String>) {
|
pub(crate) fn mail_arrived(&mut self, session: i64, result: Result<OfflineMessage, String>) {
|
||||||
match result {
|
match result {
|
||||||
Ok(m) => {
|
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)
|
&& let Some(info) = view.extra.inbox.iter_mut().find(|i| i.id == m.id)
|
||||||
{
|
{
|
||||||
info.read = true;
|
info.read = true;
|
||||||
@@ -816,7 +823,7 @@ impl App {
|
|||||||
("send", Err(e)) => self.set_status(format!("Could not send the offline message: {e}")),
|
("send", Err(e)) => self.set_status(format!("Could not send the offline message: {e}")),
|
||||||
(_, Err(e)) => self.set_status(format!("Offline messages: {e}")),
|
(_, Err(e)) => self.set_status(format!("Offline messages: {e}")),
|
||||||
(_, Ok(())) => {
|
(_, 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;
|
view.extra.inbox_asked = false;
|
||||||
}
|
}
|
||||||
self.ask_inboxes();
|
self.ask_inboxes();
|
||||||
@@ -830,6 +837,7 @@ impl App {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let ids: Vec<i64> = self
|
let ids: Vec<i64> = self
|
||||||
|
.state
|
||||||
.sessions
|
.sessions
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(_, v)| {
|
.filter(|(_, v)| {
|
||||||
@@ -841,7 +849,7 @@ impl App {
|
|||||||
.collect();
|
.collect();
|
||||||
for id in ids {
|
for id in ids {
|
||||||
let request = self.offline_request(id, "list");
|
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;
|
view.extra.inbox_asked = true;
|
||||||
}
|
}
|
||||||
self.engine.send(Command::ListOfflineMessages { session: id as u64, request });
|
self.engine.send(Command::ListOfflineMessages { session: id as u64, request });
|
||||||
@@ -850,7 +858,7 @@ impl App {
|
|||||||
|
|
||||||
/// Pokes from `uid` as lines of their private chat, among its messages
|
/// Pokes from `uid` as lines of their private chat, among its messages
|
||||||
/// (`lines` and `times` in step, oldest first).
|
/// (`lines` and `times` in step, oldest first).
|
||||||
pub(crate) fn poke_lines(&self, session: i64, uid: &str) -> Vec<(i64, crate::app::ChatLine)> {
|
pub(crate) fn poke_lines(&self, session: i64, uid: &str) -> Vec<(i64, vm::bridge::ChatLine)> {
|
||||||
self.social
|
self.social
|
||||||
.pokes
|
.pokes
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -94,10 +94,13 @@ impl App {
|
|||||||
}
|
}
|
||||||
// The main window may have gone to another server meanwhile: else
|
// The main window may have gone to another server meanwhile: else
|
||||||
// the stream would play on, unseen.
|
// the stream would play on, unseen.
|
||||||
let session =
|
let session = self
|
||||||
self.watch.as_ref().and_then(|w| w.session).filter(|id| self.sessions.contains_key(id));
|
.watch
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|w| w.session)
|
||||||
|
.filter(|id| self.state.sessions.contains_key(id));
|
||||||
if let Some(id) = session
|
if let Some(id) = session
|
||||||
&& self.current != Some(id)
|
&& self.state.current != Some(id)
|
||||||
{
|
{
|
||||||
self.select_server(id);
|
self.select_server(id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,24 +9,18 @@
|
|||||||
//! message shows its address.
|
//! message shows its address.
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use voelin_core::settings::CACHE_FETCH_IMAGES;
|
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 voelin_model::{ChatTarget, FileRef};
|
||||||
|
|
||||||
use crate::app::{App, SessionView};
|
use crate::app::{App, SessionView};
|
||||||
|
use crate::bind::convert;
|
||||||
use crate::settings::UI_IMAGE_PREVIEW_KB;
|
use crate::settings::UI_IMAGE_PREVIEW_KB;
|
||||||
use crate::vm;
|
use crate::vm;
|
||||||
|
use crate::vm::state::Preview;
|
||||||
/// A linked picture.
|
use crate::vm::{ImageRef, ImageSource};
|
||||||
#[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.
|
/// Whether a file name is a picture the chat shows inline.
|
||||||
pub(crate) fn is_previewable(name: &str) -> bool {
|
pub(crate) fn is_previewable(name: &str) -> bool {
|
||||||
@@ -47,12 +41,12 @@ pub(crate) fn link_key(file: &FileRef) -> String {
|
|||||||
|
|
||||||
/// The decoded picture of a link, if it is there (decoded once, kept by
|
/// The decoded picture of a link, if it is there (decoded once, kept by
|
||||||
/// the image cache).
|
/// the image cache).
|
||||||
pub(crate) fn image_of(view: &SessionView, file: &FileRef) -> Option<slint::Image> {
|
pub(crate) fn image_of(view: &SessionView, file: &FileRef) -> Option<ImageRef> {
|
||||||
let key = link_key(file);
|
let key = link_key(file);
|
||||||
match view.extra.previews.get(&key)? {
|
match view.extra.previews.get(&key)? {
|
||||||
Preview::Ready(bytes) => {
|
Preview::Ready(bytes) => {
|
||||||
let image = crate::images::picture(&key, &bytes.0);
|
let image = Arc::new(ImageSource::Memory { key: key.into(), bytes: bytes.0.clone() });
|
||||||
(image.size().width > 0).then_some(image)
|
(!image.is_empty()).then_some(image)
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
@@ -70,7 +64,7 @@ impl App {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.fetch_web_pictures(session, limit);
|
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 {
|
if view.state.voice != VoiceState::Connected || !view.capabilities.file_transfer {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -108,7 +102,7 @@ impl App {
|
|||||||
if !self.prefs.get(&CACHE_FETCH_IMAGES) {
|
if !self.prefs.get(&CACHE_FETCH_IMAGES) {
|
||||||
return;
|
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 };
|
let Some(tab) = view.tabs.get(view.current_tab) else { return };
|
||||||
// The server chat starts with the server's messages.
|
// The server chat starts with the server's messages.
|
||||||
let server = match tab.target {
|
let server = match tab.target {
|
||||||
@@ -142,7 +136,7 @@ impl App {
|
|||||||
state: &TransferState,
|
state: &TransferState,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let limit = u64::from(self.prefs.get(&UI_IMAGE_PREVIEW_KB)) * 1024;
|
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
|
let Some(key) = view
|
||||||
.extra
|
.extra
|
||||||
.previews
|
.previews
|
||||||
@@ -161,7 +155,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
TransferState::Done { data: Some(data), .. } => {
|
TransferState::Done { data: Some(data), .. } => {
|
||||||
view.extra.previews.insert(key, Preview::Ready(data.clone()));
|
view.extra.previews.insert(key, Preview::Ready(data.clone()));
|
||||||
if self.current == Some(session) {
|
if self.state.current == Some(session) {
|
||||||
self.refresh_chat();
|
self.refresh_chat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,7 +182,7 @@ impl App {
|
|||||||
};
|
};
|
||||||
let index = index.max(0) as usize;
|
let index = index.max(0) as usize;
|
||||||
match message.file_refs().get(index) {
|
match message.file_refs().get(index) {
|
||||||
Some(file) => image_of(view, file).unwrap_or_default(),
|
Some(file) => image_of(view, file).map(|i| convert::image(&i)).unwrap_or_default(),
|
||||||
None => vm::chat::picture_link(&message, index)
|
None => vm::chat::picture_link(&message, index)
|
||||||
.and_then(|url| view.pictures.get(&url))
|
.and_then(|url| view.pictures.get(&url))
|
||||||
.map(|path| crate::images::file(path))
|
.map(|path| crate::images::file(path))
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ use voelin_core::{Command, JoinFailure, ObserveState, Source, VoiceOptions, Voic
|
|||||||
use voelin_model::ChannelId;
|
use voelin_model::ChannelId;
|
||||||
use voelin_store::{Bookmark, QueryTransport};
|
use voelin_store::{Bookmark, QueryTransport};
|
||||||
|
|
||||||
use crate::app::{App, BookmarkForm, Bridge, Nav, SessionView, later};
|
use crate::app::{App, Bridge, Nav, SessionView, later};
|
||||||
|
use crate::bind::convert;
|
||||||
use crate::vm;
|
use crate::vm;
|
||||||
|
use crate::vm::bridge::BookmarkForm;
|
||||||
use crate::vm::servers::{AfterConnect, JoinStep};
|
use crate::vm::servers::{AfterConnect, JoinStep};
|
||||||
|
|
||||||
/// The name of the identity the app creates when it has none.
|
/// The name of the identity the app creates when it has none.
|
||||||
@@ -102,8 +104,11 @@ fn observing_stays(
|
|||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub(crate) fn connect_voice(&mut self) {
|
pub(crate) fn connect_voice(&mut self) {
|
||||||
let channel =
|
let channel = self
|
||||||
self.current.and_then(|id| self.bookmark(id)).and_then(|b| b.default_channel.clone());
|
.state
|
||||||
|
.current
|
||||||
|
.and_then(|id| self.bookmark(id))
|
||||||
|
.and_then(|b| b.default_channel.clone());
|
||||||
self.connect_voice_to(channel, None, None);
|
self.connect_voice_to(channel, None, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +121,9 @@ impl App {
|
|||||||
channel_password: Option<String>,
|
channel_password: Option<String>,
|
||||||
token: Option<String>,
|
token: Option<String>,
|
||||||
) -> bool {
|
) -> 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 {
|
if self.demo_ui {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -169,7 +176,7 @@ impl App {
|
|||||||
/// (a gateway that moved, or one typed into an older version, which
|
/// (a gateway that moved, or one typed into an older version, which
|
||||||
/// showed the field). Nothing found keeps what is stored.
|
/// showed the field). Nothing found keeps what is stored.
|
||||||
pub(crate) fn discover_gateway(&mut self, id: i64) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
let Some(b) = self.bookmark(id) else { return };
|
let Some(b) = self.bookmark(id) else { return };
|
||||||
@@ -191,7 +198,8 @@ impl App {
|
|||||||
/// observed through them if it is the one shown. Users never hear of
|
/// observed through them if it is the one shown. Users never hear of
|
||||||
/// them (logged only).
|
/// them (logged only).
|
||||||
fn gateway_found(&mut self, id: i64, address: &str, urls: Vec<String>, elapsed_ms: u64) {
|
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;
|
return;
|
||||||
};
|
};
|
||||||
let previous = b.gateways();
|
let previous = b.gateways();
|
||||||
@@ -204,12 +212,12 @@ impl App {
|
|||||||
warn!(%e, "could not keep the gateway found");
|
warn!(%e, "could not keep the gateway found");
|
||||||
return;
|
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);
|
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");
|
info!(server = %b.address, urls = ?b.gateway_urls, ?previous, kept, elapsed_ms, "gateway found");
|
||||||
self.refresh_toolbar();
|
self.refresh_toolbar();
|
||||||
if kept {
|
if kept {
|
||||||
if self.current == Some(id) && observe == ObserveState::Off {
|
if self.state.current == Some(id) && observe == ObserveState::Off {
|
||||||
self.observe(id);
|
self.observe(id);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -217,18 +225,18 @@ impl App {
|
|||||||
// Observed through the old ones: through these now.
|
// Observed through the old ones: through these now.
|
||||||
if !previous.is_empty() {
|
if !previous.is_empty() {
|
||||||
self.engine.send(Command::StopObserving { session: id as u64 });
|
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;
|
view.state.observe = ObserveState::Off;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.current == Some(id) {
|
if self.state.current == Some(id) {
|
||||||
self.observe(id);
|
self.observe(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The gateway logged in at `url`: it is the one in use from now on.
|
/// 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) {
|
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) {
|
if !b.gateway_in_use(url) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -242,7 +250,8 @@ impl App {
|
|||||||
/// The server told its name: a server still named by its address takes
|
/// The server told its name: a server still named by its address takes
|
||||||
/// it, so the address is all a user has to type.
|
/// it, so the address is all a user has to type.
|
||||||
pub(crate) fn adopt_server_name(&mut self, id: i64, name: &str) {
|
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;
|
return;
|
||||||
};
|
};
|
||||||
if name.trim().is_empty() || self.demo_ui {
|
if name.trim().is_empty() || self.demo_ui {
|
||||||
@@ -267,7 +276,7 @@ impl App {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let session = b.id as u64;
|
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();
|
let urls = b.gateways();
|
||||||
match state {
|
match state {
|
||||||
ObserveState::Observing => return,
|
ObserveState::Observing => return,
|
||||||
@@ -321,7 +330,7 @@ impl App {
|
|||||||
|
|
||||||
/// Show a server, and observe it.
|
/// Show a server, and observe it.
|
||||||
pub(crate) fn select_server(&mut self, id: i64) {
|
pub(crate) fn select_server(&mut self, id: i64) {
|
||||||
self.current = Some(id);
|
self.state.current = Some(id);
|
||||||
self.prefetch_counts();
|
self.prefetch_counts();
|
||||||
self.track_reading();
|
self.track_reading();
|
||||||
self.refresh_all();
|
self.refresh_all();
|
||||||
@@ -337,7 +346,7 @@ impl App {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
let password = self.secrets.get(&b.server_password_key()).ok().flatten();
|
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())
|
vm::servers::form(b, state, password.as_deref().unwrap_or_default())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,13 +379,13 @@ impl App {
|
|||||||
if old.query.is_some() {
|
if old.query.is_some() {
|
||||||
let _ = self.secrets.delete(&old.query_password_key());
|
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 });
|
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;
|
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);
|
self.select_server(bookmark.id);
|
||||||
Some(bookmark.id)
|
Some(bookmark.id)
|
||||||
}
|
}
|
||||||
@@ -403,10 +412,10 @@ impl App {
|
|||||||
}
|
}
|
||||||
let _ = self.store.delete_bookmark(id);
|
let _ = self.store.delete_bookmark(id);
|
||||||
self.save_reads(id);
|
self.save_reads(id);
|
||||||
self.sessions.remove(&id);
|
self.state.sessions.remove(&id);
|
||||||
self.gateways_looked_up.remove(&id);
|
self.state.gateways_looked_up.remove(&id);
|
||||||
self.bookmarks = self.store.bookmarks().unwrap_or_default();
|
self.state.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||||
self.current = self.bookmarks.first().map(|b| b.id);
|
self.state.current = self.state.bookmarks.first().map(|b| b.id);
|
||||||
self.prefetch_counts();
|
self.prefetch_counts();
|
||||||
self.track_reading();
|
self.track_reading();
|
||||||
self.refresh_all();
|
self.refresh_all();
|
||||||
@@ -414,11 +423,11 @@ impl App {
|
|||||||
|
|
||||||
/// Keep only metadata supplied by the bookmark's current server.
|
/// Keep only metadata supplied by the bookmark's current server.
|
||||||
pub(crate) fn remember_server_icon(&mut self, id: i64, address: &str, icon: u32) {
|
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;
|
return;
|
||||||
};
|
};
|
||||||
let changed =
|
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
|
if changed
|
||||||
&& !self.demo_ui
|
&& !self.demo_ui
|
||||||
&& let Err(error) = self.store.update_bookmark(bookmark)
|
&& let Err(error) = self.store.update_bookmark(bookmark)
|
||||||
@@ -427,8 +436,9 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn server_list_icon(&self, bookmark: &Bookmark) -> slint::Image {
|
pub(crate) fn server_list_icon(&self, bookmark: &Bookmark) -> vm::ImageRef {
|
||||||
let current = self
|
let current = self
|
||||||
|
.state
|
||||||
.sessions
|
.sessions
|
||||||
.get(&bookmark.id)
|
.get(&bookmark.id)
|
||||||
.map(|view| view.server_icon_for(&bookmark.address))
|
.map(|view| view.server_icon_for(&bookmark.address))
|
||||||
@@ -441,9 +451,9 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A server's colour, as the rail shows it ([`vm::servers::tints`]).
|
/// A server's colour, as the rail shows it ([`vm::servers::tints`]).
|
||||||
pub(crate) fn server_tint(&self, id: i64) -> slint::Color {
|
pub(crate) fn server_tint(&self, id: i64) -> vm::Rgb {
|
||||||
let tints = vm::servers::tints(&self.bookmarks);
|
let tints = vm::servers::tints(&self.state.bookmarks);
|
||||||
self.bookmarks.iter().position(|b| b.id == id).map(|i| tints[i]).unwrap_or_default()
|
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
|
/// The rail: servers with their state, unread count (without private
|
||||||
@@ -452,13 +462,14 @@ impl App {
|
|||||||
pub(crate) fn refresh_servers(&self) {
|
pub(crate) fn refresh_servers(&self) {
|
||||||
let Some(ui) = self.ui.upgrade() else { return };
|
let Some(ui) = self.ui.upgrade() else { return };
|
||||||
let bridge = ui.global::<Bridge>();
|
let bridge = ui.global::<Bridge>();
|
||||||
let tints = vm::servers::tints(&self.bookmarks);
|
let tints = vm::servers::tints(&self.state.bookmarks);
|
||||||
let items: Vec<_> = self
|
let items: Vec<_> = self
|
||||||
|
.state
|
||||||
.bookmarks
|
.bookmarks
|
||||||
.iter()
|
.iter()
|
||||||
.zip(tints)
|
.zip(tints)
|
||||||
.map(|(b, tint)| {
|
.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 state = view.map(|v| v.state.clone()).unwrap_or_default();
|
||||||
let unread = view.map_or(0, SessionView::channel_unread);
|
let unread = view.map_or(0, SessionView::channel_unread);
|
||||||
let live = view.is_some_and(|v| v.streams_available() && !v.streams.is_empty());
|
let live = view.is_some_and(|v| v.streams_available() && !v.streams.is_empty());
|
||||||
@@ -471,9 +482,9 @@ impl App {
|
|||||||
vm::servers::item(b, &state, unread, live, detail, product, icon, tint)
|
vm::servers::item(b, &state, unread, live, detail, product, icon, tint)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
vm::list::sync(&self.models.servers, &items);
|
self.models.servers.sync(&items);
|
||||||
bridge.set_last_place(self.last_place(&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).
|
// 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_unread_total(self.view().map_or(0, SessionView::channel_unread));
|
||||||
bridge.set_dm_unread(self.dm_unread());
|
bridge.set_dm_unread(self.dm_unread());
|
||||||
@@ -483,10 +494,12 @@ impl App {
|
|||||||
pub(crate) fn refresh_toolbar(&self) {
|
pub(crate) fn refresh_toolbar(&self) {
|
||||||
let Some(ui) = self.ui.upgrade() else { return };
|
let Some(ui) = self.ui.upgrade() else { return };
|
||||||
let bridge = ui.global::<Bridge>();
|
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 view = self.view();
|
||||||
let state = view.map(|v| v.state.clone()).unwrap_or_default();
|
let state = view.map(|v| v.state.clone()).unwrap_or_default();
|
||||||
bridge.set_server_icon(bookmark.map(|b| self.server_list_icon(b)).unwrap_or_default());
|
bridge.set_server_icon(convert::image(
|
||||||
|
&bookmark.map(|b| self.server_list_icon(b)).unwrap_or_default(),
|
||||||
|
));
|
||||||
bridge.set_server_title(
|
bridge.set_server_title(
|
||||||
bookmark.map_or("No server selected".into(), |b| b.name.clone()).into(),
|
bookmark.map_or("No server selected".into(), |b| b.name.clone()).into(),
|
||||||
);
|
);
|
||||||
@@ -500,12 +513,13 @@ impl App {
|
|||||||
);
|
);
|
||||||
bridge.set_nickname(bookmark.map(|b| b.nickname.clone()).unwrap_or_default().into());
|
bridge.set_nickname(bookmark.map(|b| b.nickname.clone()).unwrap_or_default().into());
|
||||||
let own = view.zip(state.own_client).and_then(|(v, c)| v.avatar(c));
|
let own = view.zip(state.own_client).and_then(|(v, c)| v.avatar(c));
|
||||||
bridge.set_own_avatar(vm::avatar::image(own));
|
bridge.set_own_avatar(convert::image(&vm::avatar::image(own)));
|
||||||
let banner = |url: Option<&str>| {
|
let banner = |url: Option<&str>| {
|
||||||
view.map(|v| vm::tree::banner(&v.pictures, url)).unwrap_or_default()
|
view.map(|v| vm::tree::banner(&v.pictures, url)).unwrap_or_default()
|
||||||
};
|
};
|
||||||
let details = view.map(|v| &v.presence.server);
|
let details = view.map(|v| &v.presence.server);
|
||||||
bridge.set_server_banner(banner(details.map(|d| d.banner_gfx_url.as_str())));
|
bridge
|
||||||
|
.set_server_banner(convert::image(&banner(details.map(|d| d.banner_gfx_url.as_str()))));
|
||||||
bridge.set_server_banner_mode(details.map_or(0, |d| vm::tree::banner_mode(d.banner_mode)));
|
bridge.set_server_banner_mode(details.map_or(0, |d| vm::tree::banner_mode(d.banner_mode)));
|
||||||
let own_channel =
|
let own_channel =
|
||||||
view.and_then(|v| state.own_channel.and_then(|c| v.presence.channels.get(&c)));
|
view.and_then(|v| state.own_channel.and_then(|c| v.presence.channels.get(&c)));
|
||||||
@@ -515,8 +529,9 @@ impl App {
|
|||||||
bridge.set_own_channel_topic(
|
bridge.set_own_channel_topic(
|
||||||
own_channel.and_then(|c| c.topic.clone()).unwrap_or_default().into(),
|
own_channel.and_then(|c| c.topic.clone()).unwrap_or_default().into(),
|
||||||
);
|
);
|
||||||
bridge
|
bridge.set_own_channel_banner(convert::image(&banner(
|
||||||
.set_own_channel_banner(banner(own_channel.and_then(|c| c.banner_gfx_url.as_deref())));
|
own_channel.and_then(|c| c.banner_gfx_url.as_deref()),
|
||||||
|
)));
|
||||||
bridge.set_own_channel_banner_mode(
|
bridge.set_own_channel_banner_mode(
|
||||||
own_channel.map_or(0, |c| vm::tree::banner_mode(c.banner_mode)),
|
own_channel.map_or(0, |c| vm::tree::banner_mode(c.banner_mode)),
|
||||||
);
|
);
|
||||||
@@ -548,16 +563,16 @@ impl App {
|
|||||||
/// server.
|
/// server.
|
||||||
pub(crate) fn refresh_tree(&self) {
|
pub(crate) fn refresh_tree(&self) {
|
||||||
let Some(view) = self.view() else {
|
let Some(view) = self.view() else {
|
||||||
vm::list::sync(&self.models.tree, &[]);
|
self.models.tree.sync(&[]);
|
||||||
vm::list::sync(&self.models.members, &[]);
|
self.models.members.sync(&[]);
|
||||||
vm::list::sync(&self.models.server_members, &[]);
|
self.models.server_members.sync(&[]);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let input = vm::tree::TreeInput {
|
let input = vm::tree::TreeInput {
|
||||||
presence: &view.presence,
|
presence: &view.presence,
|
||||||
collapsed: &view.collapsed,
|
collapsed: &view.collapsed,
|
||||||
talking: &view.talking,
|
talking: &view.talking,
|
||||||
playback: &self.playback,
|
playback: &self.state.playback,
|
||||||
own_channel: view.state.own_channel,
|
own_channel: view.state.own_channel,
|
||||||
own_client: view.state.own_client,
|
own_client: view.state.own_client,
|
||||||
filter: "",
|
filter: "",
|
||||||
@@ -567,19 +582,19 @@ impl App {
|
|||||||
groups: &view.server_groups,
|
groups: &view.server_groups,
|
||||||
channel_groups: &view.channel_groups,
|
channel_groups: &view.channel_groups,
|
||||||
};
|
};
|
||||||
vm::list::sync(&self.models.tree, &vm::tree::rows(&input));
|
self.models.tree.sync(&vm::tree::rows(&input));
|
||||||
let connected = view.state.voice == VoiceState::Connected;
|
let connected = view.state.voice == VoiceState::Connected;
|
||||||
let members = if connected { vm::tree::members(&input) } else { Vec::new() };
|
let members = if connected { vm::tree::members(&input) } else { Vec::new() };
|
||||||
vm::list::sync(&self.models.members, &members);
|
self.models.members.sync(&members);
|
||||||
// The people in our channel first while their view is shown (not
|
// The people in our channel first while their view is shown (not
|
||||||
// while the stream plays in a window of its own).
|
// 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 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 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 =
|
let shown =
|
||||||
if filter.is_empty() { everyone } else { vm::tree::matching(everyone, &filter) };
|
if filter.is_empty() { everyone } else { vm::tree::matching(everyone, &filter) };
|
||||||
vm::list::sync(&self.models.server_members, &shown);
|
self.models.server_members.sync(&shown);
|
||||||
if let Some(ui) = self.ui.upgrade() {
|
if let Some(ui) = self.ui.upgrade() {
|
||||||
let total = view.presence.clients.values().filter(|c| !c.is_query).count();
|
let total = view.presence.clients.values().filter(|c| !c.is_query).count();
|
||||||
ui.global::<crate::app::Bridge>().set_member_total(total as i32);
|
ui.global::<crate::app::Bridge>().set_member_total(total as i32);
|
||||||
@@ -588,8 +603,8 @@ impl App {
|
|||||||
|
|
||||||
/// The members panel's search.
|
/// The members panel's search.
|
||||||
pub(crate) fn search_members(&mut self, text: String) {
|
pub(crate) fn search_members(&mut self, text: String) {
|
||||||
if self.member_filter != text {
|
if self.state.member_filter != text {
|
||||||
self.member_filter = text;
|
self.state.member_filter = text;
|
||||||
self.refresh_tree();
|
self.refresh_tree();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -597,7 +612,7 @@ impl App {
|
|||||||
/// The voice channel view was opened or closed: its chat is our
|
/// The voice channel view was opened or closed: its chat is our
|
||||||
/// channel's, and its people lead the members panel.
|
/// channel's, and its people lead the members panel.
|
||||||
pub(crate) fn show_voice_view(&mut self, on: bool) {
|
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) {
|
if on && let Some(channel) = self.view().and_then(|v| v.state.own_channel) {
|
||||||
self.open_chat(voelin_model::ChatTarget::Channel(channel), true);
|
self.open_chat(voelin_model::ChatTarget::Channel(channel), true);
|
||||||
}
|
}
|
||||||
@@ -608,7 +623,8 @@ impl App {
|
|||||||
/// copies it, and the copy's toast names the channel); empty, with a
|
/// copies it, and the copy's toast names the channel); empty, with a
|
||||||
/// note, without one.
|
/// note, without one.
|
||||||
pub(crate) fn invite_link(&mut self) -> String {
|
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 path = self.view().and_then(|v| {
|
||||||
let cid = v.state.own_channel?;
|
let cid = v.state.own_channel?;
|
||||||
let own = v.presence.channels.get(&cid)?;
|
let own = v.presence.channels.get(&cid)?;
|
||||||
@@ -625,7 +641,7 @@ impl App {
|
|||||||
};
|
};
|
||||||
let path: Vec<&str> = path.iter().map(String::as_str).collect();
|
let path: Vec<&str> = path.iter().map(String::as_str).collect();
|
||||||
let link = vm::servers::invite_link(&address, &path);
|
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
|
link
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -633,7 +649,7 @@ impl App {
|
|||||||
/// friend): move there with voice, or connect into it. A locked channel
|
/// friend): move there with voice, or connect into it. A locked channel
|
||||||
/// asks for its password first, unless it was given this connection.
|
/// asks for its password first, unless it was given this connection.
|
||||||
pub(crate) fn join_channel(&mut self, session: i64, channel: ChannelId) {
|
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 Some(info) = view.presence.channels.get(&channel) else { return };
|
||||||
let remembered = view.channel_passwords.get(&channel).map(String::as_str);
|
let remembered = view.channel_passwords.get(&channel).map(String::as_str);
|
||||||
match vm::servers::join_password(info, remembered) {
|
match vm::servers::join_password(info, remembered) {
|
||||||
@@ -644,11 +660,11 @@ impl App {
|
|||||||
|
|
||||||
/// The password dialog's Join.
|
/// The password dialog's Join.
|
||||||
pub(crate) fn join_with_password(&mut self, password: String) {
|
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() {
|
if password.is_empty() {
|
||||||
return;
|
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());
|
view.channel_passwords.insert(channel, password.clone());
|
||||||
}
|
}
|
||||||
self.enter_channel(session, channel, Some(password));
|
self.enter_channel(session, channel, Some(password));
|
||||||
@@ -656,7 +672,7 @@ impl App {
|
|||||||
|
|
||||||
/// Move into a channel; without voice on its server, connect into it.
|
/// Move into a channel; without voice on its server, connect into it.
|
||||||
fn enter_channel(&mut self, session: i64, channel: ChannelId, password: Option<String>) {
|
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 {
|
if view.state.voice != VoiceState::Disconnected {
|
||||||
// Chosen while connecting: no longer the one to join after.
|
// Chosen while connecting: no longer the one to join after.
|
||||||
view.join_after_connect = None;
|
view.join_after_connect = None;
|
||||||
@@ -669,13 +685,13 @@ impl App {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if self.current != Some(session) {
|
if self.state.current != Some(session) {
|
||||||
self.select_server(session);
|
self.select_server(session);
|
||||||
}
|
}
|
||||||
// By id: by its name the server finds only a top-level channel (a
|
// By id: by its name the server finds only a top-level channel (a
|
||||||
// subchannel's name connects into the default channel).
|
// subchannel's name connects into the default channel).
|
||||||
if self.connect_voice_to(Some(format!("/{channel}")), password, None)
|
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);
|
view.join_after_connect = Some(channel);
|
||||||
}
|
}
|
||||||
@@ -687,7 +703,7 @@ impl App {
|
|||||||
/// move says why. Once the channel shows in the voice
|
/// move says why. Once the channel shows in the voice
|
||||||
/// connection's presence, which can come after the own channel.
|
/// connection's presence, which can come after the own channel.
|
||||||
pub(crate) fn join_after_connect(&mut self, session: i64) {
|
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)
|
let (VoiceState::Connected, Some(asked)) = (view.state.voice, view.join_after_connect)
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
@@ -707,12 +723,12 @@ impl App {
|
|||||||
/// given was refused.
|
/// given was refused.
|
||||||
fn ask_channel_password(&mut self, session: i64, channel: ChannelId, wrong: bool) {
|
fn ask_channel_password(&mut self, session: i64, channel: ChannelId, wrong: bool) {
|
||||||
let Some(info) =
|
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 {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let name = vm::tree::channel_title(info).0.to_owned();
|
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 Some(ui) = self.ui.upgrade() else { return };
|
||||||
let nav = ui.global::<Nav>();
|
let nav = ui.global::<Nav>();
|
||||||
nav.set_channel_password_name(name.into());
|
nav.set_channel_password_name(name.into());
|
||||||
@@ -727,6 +743,7 @@ impl App {
|
|||||||
match reason {
|
match reason {
|
||||||
JoinFailure::Password => {
|
JoinFailure::Password => {
|
||||||
let given = self
|
let given = self
|
||||||
|
.state
|
||||||
.sessions
|
.sessions
|
||||||
.get_mut(&session)
|
.get_mut(&session)
|
||||||
.and_then(|v| v.channel_passwords.remove(&channel))
|
.and_then(|v| v.channel_passwords.remove(&channel))
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ use voelin_core::settings::{AUDIO, CRASH_REPORTS};
|
|||||||
use voelin_core::{Command, Source, VoiceState};
|
use voelin_core::{Command, Source, VoiceState};
|
||||||
use voelin_platform::{crash, notices};
|
use voelin_platform::{crash, notices};
|
||||||
|
|
||||||
use crate::app::{App, AudioForm, Bridge, ClientAudio, later, model};
|
use crate::app::{App, Bridge, later, model};
|
||||||
use crate::settings::{self, CLIENT_PLAYBACK, ClientPlayback, DeviceChoices};
|
use crate::settings::{self, CLIENT_PLAYBACK, ClientPlayback, DeviceChoices};
|
||||||
|
use crate::vm::bridge::{AudioForm, ClientAudio};
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub(crate) fn open_settings(&mut self) {
|
pub(crate) fn open_settings(&mut self) {
|
||||||
@@ -28,17 +29,20 @@ impl App {
|
|||||||
};
|
};
|
||||||
let inputs = list(voelin_audio::device::input_devices(), true);
|
let inputs = list(voelin_audio::device::input_devices(), true);
|
||||||
let outputs = list(voelin_audio::device::output_devices(), false);
|
let outputs = list(voelin_audio::device::output_devices(), false);
|
||||||
self.inputs = DeviceChoices::new(&inputs, self.audio.input_device.as_deref());
|
self.state.inputs = DeviceChoices::new(&inputs, self.state.audio.input_device.as_deref());
|
||||||
self.outputs = DeviceChoices::new(&outputs, self.audio.output_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 Some(ui) = self.ui.upgrade() else { return };
|
||||||
let bridge = ui.global::<Bridge>();
|
let bridge = ui.global::<Bridge>();
|
||||||
let names = |c: &DeviceChoices| model(c.names.iter().map(SharedString::from).collect());
|
let names = |c: &DeviceChoices| model(c.names.iter().map(SharedString::from).collect());
|
||||||
bridge.set_input_devices(names(&self.inputs));
|
bridge.set_input_devices(names(&self.state.inputs));
|
||||||
bridge.set_output_devices(names(&self.outputs));
|
bridge.set_output_devices(names(&self.state.outputs));
|
||||||
bridge.set_audio(settings::audio_form(&self.audio, &self.inputs, &self.outputs));
|
bridge.set_audio(
|
||||||
bridge.set_global_ptt(self.settings.global_ptt);
|
settings::audio_form(&self.state.audio, &self.state.inputs, &self.state.outputs).into(),
|
||||||
bridge.set_ptt_key(self.settings.ptt_key.clone().into());
|
);
|
||||||
bridge.set_h264_enabled(self.settings.openh264);
|
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());
|
bridge.set_image_cache_usage(crate::images::usage_text().into());
|
||||||
self.refresh_h264();
|
self.refresh_h264();
|
||||||
self.refresh_identities();
|
self.refresh_identities();
|
||||||
@@ -50,30 +54,35 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn audio_changed(&mut self, form: &AudioForm) {
|
pub(crate) fn audio_changed(&mut self, form: &AudioForm) {
|
||||||
let audio = settings::apply_audio_form(form, &self.audio, &self.inputs, &self.outputs);
|
let audio = settings::apply_audio_form(
|
||||||
if audio == self.audio {
|
form,
|
||||||
|
&self.state.audio,
|
||||||
|
&self.state.inputs,
|
||||||
|
&self.state.outputs,
|
||||||
|
);
|
||||||
|
if audio == self.state.audio {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.audio = audio;
|
self.state.audio = audio;
|
||||||
self.audio_dirty = true;
|
self.state.audio_dirty = true;
|
||||||
self.engine.send(Command::SetAudioSettings(Box::new(self.audio.clone())));
|
self.engine.send(Command::SetAudioSettings(Box::new(self.state.audio.clone())));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn save_audio(&mut self) {
|
pub(crate) fn save_audio(&mut self) {
|
||||||
if !self.audio_dirty {
|
if !self.state.audio_dirty {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.audio_dirty = false;
|
self.state.audio_dirty = false;
|
||||||
if let Err(e) = self.prefs.set(&AUDIO, self.audio.clone()) {
|
if let Err(e) = self.prefs.set(&AUDIO, self.state.audio.clone()) {
|
||||||
warn!(%e, "could not store audio settings");
|
warn!(%e, "could not store audio settings");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_mic_test(&mut self, on: bool) {
|
pub(crate) fn set_mic_test(&mut self, on: bool) {
|
||||||
if self.mic_test == on {
|
if self.state.mic_test == on {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.mic_test = on;
|
self.state.mic_test = on;
|
||||||
self.engine.send(Command::TestMicrophone { on });
|
self.engine.send(Command::TestMicrophone { on });
|
||||||
if let Some(ui) = self.ui.upgrade() {
|
if let Some(ui) = self.ui.upgrade() {
|
||||||
let bridge = ui.global::<Bridge>();
|
let bridge = ui.global::<Bridge>();
|
||||||
@@ -86,9 +95,9 @@ impl App {
|
|||||||
|
|
||||||
pub(crate) fn apply_ptt(&mut self, enabled: bool, key: String) {
|
pub(crate) fn apply_ptt(&mut self, enabled: bool, key: String) {
|
||||||
let key = key.trim().to_owned();
|
let key = key.trim().to_owned();
|
||||||
self.settings.global_ptt = enabled;
|
self.state.settings.global_ptt = enabled;
|
||||||
if !key.is_empty() {
|
if !key.is_empty() {
|
||||||
self.settings.ptt_key = key.clone();
|
self.state.settings.ptt_key = key.clone();
|
||||||
}
|
}
|
||||||
self.store_settings();
|
self.store_settings();
|
||||||
self.ptt.set((enabled && !key.is_empty()).then_some(key));
|
self.ptt.set((enabled && !key.is_empty()).then_some(key));
|
||||||
@@ -101,7 +110,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_h264(&mut self, enabled: bool) {
|
pub(crate) fn set_h264(&mut self, enabled: bool) {
|
||||||
self.settings.openh264 = enabled;
|
self.state.settings.openh264 = enabled;
|
||||||
self.store_settings();
|
self.store_settings();
|
||||||
self.video.set_h264(enabled);
|
self.video.set_h264(enabled);
|
||||||
self.refresh_h264();
|
self.refresh_h264();
|
||||||
@@ -111,7 +120,7 @@ impl App {
|
|||||||
let runtime = self.engine.runtime().clone();
|
let runtime = self.engine.runtime().clone();
|
||||||
self.video.download_h264(&runtime, |download| {
|
self.video.download_h264(&runtime, |download| {
|
||||||
later(move |app| {
|
later(move |app| {
|
||||||
app.video.downloaded(download, app.settings.openh264);
|
app.video.downloaded(download, app.state.settings.openh264);
|
||||||
app.refresh_h264();
|
app.refresh_h264();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -131,9 +140,9 @@ impl App {
|
|||||||
pub(crate) fn refresh_settings_flags(&self) {
|
pub(crate) fn refresh_settings_flags(&self) {
|
||||||
let Some(ui) = self.ui.upgrade() else { return };
|
let Some(ui) = self.ui.upgrade() else { return };
|
||||||
let bridge = ui.global::<Bridge>();
|
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_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
|
/// The transmit mode for the voice controls (Hold to talk shows for
|
||||||
@@ -143,12 +152,12 @@ impl App {
|
|||||||
let Some(ui) = self.ui.upgrade() else { return };
|
let Some(ui) = self.ui.upgrade() else { return };
|
||||||
let bridge = ui.global::<Bridge>();
|
let bridge = ui.global::<Bridge>();
|
||||||
let mut form = bridge.get_audio();
|
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);
|
bridge.set_audio(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_crash_reports(&mut self, enabled: bool) {
|
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.
|
// Also in the blob, for older versions.
|
||||||
self.store_settings();
|
self.store_settings();
|
||||||
if let Err(e) = self.prefs.set(&CRASH_REPORTS, enabled) {
|
if let Err(e) = self.prefs.set(&CRASH_REPORTS, enabled) {
|
||||||
@@ -206,27 +215,34 @@ impl App {
|
|||||||
|
|
||||||
/// Fill the volume dialog for `client` of the current session.
|
/// Fill the volume dialog for `client` of the current session.
|
||||||
pub(crate) fn open_client(&mut self, client: u16) -> bool {
|
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 {
|
let Some(info) = self.view().and_then(|v| v.presence.clients.get(&client)).cloned() else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let playback =
|
let playback = info
|
||||||
info.uid.as_ref().and_then(|uid| self.playback.get(uid)).copied().unwrap_or_default();
|
.uid
|
||||||
self.playback_dialog = Some((id, client, info.uid.clone()));
|
.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() {
|
if let Some(ui) = self.ui.upgrade() {
|
||||||
ui.global::<Bridge>().set_client_audio(ClientAudio {
|
ui.global::<Bridge>().set_client_audio(
|
||||||
id: client as i32,
|
ClientAudio {
|
||||||
name: info.nickname.into(),
|
id: client as i32,
|
||||||
volume: playback.volume * 100.0,
|
name: info.nickname.into(),
|
||||||
muted: playback.muted,
|
volume: playback.volume * 100.0,
|
||||||
streaming: info.streaming == Some(true),
|
muted: playback.muted,
|
||||||
});
|
streaming: info.streaming == Some(true),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn client_playback_changed(&mut self, form: &ClientAudio) {
|
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 =
|
let playback =
|
||||||
ClientPlayback { volume: (form.volume / 100.0).clamp(0.0, 4.0), muted: form.muted };
|
ClientPlayback { volume: (form.volume / 100.0).clamp(0.0, 4.0), muted: form.muted };
|
||||||
let session = session as u64;
|
let session = session as u64;
|
||||||
@@ -235,11 +251,11 @@ impl App {
|
|||||||
// Kept by unique id; clients without one only for this connection.
|
// Kept by unique id; clients without one only for this connection.
|
||||||
if let Some(uid) = uid {
|
if let Some(uid) = uid {
|
||||||
if playback.is_default() {
|
if playback.is_default() {
|
||||||
self.playback.remove(&uid);
|
self.state.playback.remove(&uid);
|
||||||
} else {
|
} 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");
|
warn!(%e, "could not store client volumes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,7 +280,7 @@ impl App {
|
|||||||
|
|
||||||
/// Send the stored volumes of clients that appeared in a voice session.
|
/// Send the stored volumes of clients that appeared in a voice session.
|
||||||
pub(crate) fn apply_client_playback(&mut self, session: i64) {
|
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
|
if view.state.voice != VoiceState::Connected
|
||||||
|| view.state.presence_source != Some(Source::Voice)
|
|| view.state.presence_source != Some(Source::Voice)
|
||||||
{
|
{
|
||||||
@@ -276,7 +292,7 @@ impl App {
|
|||||||
if !view.applied_playback.insert(client.id) {
|
if !view.applied_playback.insert(client.id) {
|
||||||
continue;
|
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 Some(playback) = stored else { continue };
|
||||||
let (s, c) = (session as u64, client.id);
|
let (s, c) = (session as u64, client.id);
|
||||||
self.engine.send(Command::SetClientVolume {
|
self.engine.send(Command::SetClientVolume {
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,801 @@
|
|||||||
|
//! The settings pages on the Bridge: the forms and models are filled from
|
||||||
|
//! the settings (`voelin_ui_vm::settings_pages::logic`), the controls' values
|
||||||
|
//! go back through it, and what a change sets going (the camera, the engine,
|
||||||
|
//! the identity store, threads) runs here.
|
||||||
|
|
||||||
|
use std::collections::HashSet;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
|
use slint::{ComponentHandle, Model, SharedString};
|
||||||
|
use tracing::warn;
|
||||||
|
use voelin_core::settings::{
|
||||||
|
IDENTITY_IMPORT, STREAM_CODEC, STREAM_ENCODER_BACKEND, STREAM_HARDWARE_ACCELERATION,
|
||||||
|
STREAM_SRTP_PROFILES,
|
||||||
|
};
|
||||||
|
use voelin_core::{Command, GatewayRequest};
|
||||||
|
use voelin_gateway_proto::{Action, PermRule, UniqueIds};
|
||||||
|
|
||||||
|
use crate::app::{App, Bridge, later, model};
|
||||||
|
use crate::bind::convert;
|
||||||
|
use crate::settings::{
|
||||||
|
VIDEO_BACKGROUND, VIDEO_CAMERA, VIDEO_MIRROR, VIDEO_RESOLUTION, page_keys, parse_size,
|
||||||
|
};
|
||||||
|
use crate::vm::bridge::{
|
||||||
|
AdvancedForm, AudioSourceItem, LayerItem, NotifyForm, PrivacyForm, StreamingForm, VideoForm,
|
||||||
|
};
|
||||||
|
use crate::vm::settings_pages::logic::{
|
||||||
|
self, Discovered, IdentityFacts, Improving, group_ids, json_of,
|
||||||
|
};
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
/// What storing settings had to say (a refusal, something typed wrong):
|
||||||
|
/// the status line shows it.
|
||||||
|
fn said(&mut self, messages: Vec<String>) {
|
||||||
|
for message in messages {
|
||||||
|
warn!(%message, "setting refused");
|
||||||
|
self.set_status(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A section of the settings was shown: load what it needs.
|
||||||
|
pub(crate) fn settings_section(&mut self, section: i32) {
|
||||||
|
for key in page_keys() {
|
||||||
|
self.prefs.register(key);
|
||||||
|
}
|
||||||
|
match section {
|
||||||
|
0 | 7 => {
|
||||||
|
self.load_cameras();
|
||||||
|
if section == 7 {
|
||||||
|
self.load_capture_sources();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
2 => self.watch_audio_apps(),
|
||||||
|
5 | 6 => self.refresh_identities(),
|
||||||
|
9 => {
|
||||||
|
if self.pages.state.encoders_loading
|
||||||
|
|| self
|
||||||
|
.ui
|
||||||
|
.upgrade()
|
||||||
|
.is_some_and(|ui| ui.global::<Bridge>().get_encoders().row_count() == 0)
|
||||||
|
{
|
||||||
|
self.refresh_encoders();
|
||||||
|
}
|
||||||
|
self.refresh_gateways();
|
||||||
|
}
|
||||||
|
10 => self.refresh_all_settings(),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
if section != 0 && section != 7 {
|
||||||
|
self.stop_camera();
|
||||||
|
}
|
||||||
|
if section != 2 {
|
||||||
|
self.pages.audio_apps = None;
|
||||||
|
}
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every form of the settings pages, from the settings.
|
||||||
|
pub(crate) fn refresh_pages(&self) {
|
||||||
|
let Some(ui) = self.ui.upgrade() else { return };
|
||||||
|
let bridge = ui.global::<Bridge>();
|
||||||
|
let p = &self.prefs;
|
||||||
|
let video = logic::video_form(p, &self.pages.state.cameras, self.pages.camera.is_some());
|
||||||
|
bridge.set_video(video.into());
|
||||||
|
bridge.set_streaming(logic::streaming_form(p).into());
|
||||||
|
self.models.layers.sync(&logic::layer_items(p));
|
||||||
|
self.models.audio_sources.sync(&logic::audio_source_items(p, voelin_platform::APP_NAME));
|
||||||
|
bridge.set_has_studio(true);
|
||||||
|
bridge.set_notify(logic::notify_form(p).into());
|
||||||
|
bridge.set_privacy(logic::privacy_form(p).into());
|
||||||
|
let srtp = p.get(&STREAM_SRTP_PROFILES);
|
||||||
|
bridge.set_srtp_profiles(model(srtp.iter().map(SharedString::from).collect()));
|
||||||
|
bridge.set_srtp_unused(model(
|
||||||
|
logic::srtp_unused(&srtp).into_iter().map(SharedString::from).collect(),
|
||||||
|
));
|
||||||
|
let crash_dir = voelin_platform::crash::dir().map(|d| d.display().to_string());
|
||||||
|
bridge.set_advanced(
|
||||||
|
logic::advanced_form(p, &log_text(), &crash_dir.unwrap_or_default()).into(),
|
||||||
|
);
|
||||||
|
self.refresh_account();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A setting changed anywhere: fill the forms, apply what the engine
|
||||||
|
/// does not read itself.
|
||||||
|
pub(crate) fn page_setting_changed(&mut self, key: &str) {
|
||||||
|
if key == STREAM_SRTP_PROFILES.name() {
|
||||||
|
self.apply_srtp();
|
||||||
|
}
|
||||||
|
if [STREAM_HARDWARE_ACCELERATION.name(), STREAM_ENCODER_BACKEND.name(), STREAM_CODEC.name()]
|
||||||
|
.contains(&key)
|
||||||
|
{
|
||||||
|
self.video.set_encoder_preference(
|
||||||
|
voelin_core::media::encoder_preference(&self.prefs),
|
||||||
|
voelin_core::media::configured_codec(&self.prefs),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if key == VIDEO_CAMERA.name()
|
||||||
|
|| key == VIDEO_BACKGROUND.name()
|
||||||
|
|| key == VIDEO_RESOLUTION.name()
|
||||||
|
{
|
||||||
|
self.restart_camera();
|
||||||
|
}
|
||||||
|
self.refresh_pages();
|
||||||
|
if key.starts_with("stream.")
|
||||||
|
|| key.starts_with("privacy.")
|
||||||
|
|| key.starts_with("chat.")
|
||||||
|
|| key.starts_with("cache.")
|
||||||
|
{
|
||||||
|
self.refresh_all_settings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The SRTP profiles of the setting, for the engine (it does not read
|
||||||
|
/// the setting itself; it takes the names and leaves out the ones its
|
||||||
|
/// stream transport does not know).
|
||||||
|
pub(crate) fn apply_srtp(&self) {
|
||||||
|
let profiles = self.prefs.get(&STREAM_SRTP_PROFILES);
|
||||||
|
self.engine.send(Command::SetSrtpProfiles(profiles.to_vec()));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn video_changed(&mut self, form: &VideoForm) {
|
||||||
|
let messages = logic::apply_video(&self.prefs, &self.pages.state.cameras, form);
|
||||||
|
self.said(messages);
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn streaming_changed(&mut self, form: &StreamingForm) {
|
||||||
|
let messages = logic::apply_streaming(&self.prefs, form);
|
||||||
|
self.said(messages);
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn layer_changed(&mut self, index: i32, item: &LayerItem) {
|
||||||
|
let Some(messages) = logic::apply_layer(&self.prefs, index, item) else { return };
|
||||||
|
self.said(messages);
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn add_layer(&mut self) {
|
||||||
|
let messages = logic::add_layer(&self.prefs);
|
||||||
|
self.said(messages);
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn remove_layer(&mut self, index: i32) {
|
||||||
|
let messages = logic::remove_layer(&self.prefs, index);
|
||||||
|
self.said(messages);
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn audio_source_changed(&mut self, index: i32, item: &AudioSourceItem) {
|
||||||
|
let messages = logic::apply_audio_source(&self.prefs, index, item);
|
||||||
|
self.said(messages);
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn add_audio_source(&mut self, kind: &str, name: &str) {
|
||||||
|
let Some(messages) = logic::add_audio_source(&self.prefs, kind, name) else { return };
|
||||||
|
self.said(messages);
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn remove_audio_source(&mut self, index: i32) {
|
||||||
|
let messages = logic::remove_audio_source(&self.prefs, index);
|
||||||
|
self.said(messages);
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Follow the applications that play audio while the Streaming page is
|
||||||
|
/// open (`tick` checks for changes).
|
||||||
|
fn watch_audio_apps(&mut self) {
|
||||||
|
if self.pages.audio_apps.is_none() && !self.demo_ui {
|
||||||
|
match voelin_core::media::audio_apps() {
|
||||||
|
Ok(apps) => self.pages.audio_apps = Some(apps),
|
||||||
|
Err(e) => warn!("cannot list applications that play audio: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.refresh_audio_apps();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn refresh_audio_apps(&mut self) {
|
||||||
|
let Some(apps) = self.pages.audio_apps.as_mut() else { return };
|
||||||
|
let names: Vec<SharedString> = apps
|
||||||
|
.current()
|
||||||
|
.into_iter()
|
||||||
|
.map(|a| SharedString::from(a.binary.unwrap_or(a.name)))
|
||||||
|
.collect();
|
||||||
|
if let Some(ui) = self.ui.upgrade() {
|
||||||
|
ui.global::<Bridge>().set_audio_apps(model(names));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called once a second: a changed list of audio applications.
|
||||||
|
pub(crate) fn tick_pages(&mut self) {
|
||||||
|
if self.pages.audio_apps.as_ref().is_some_and(|a| a.has_changed()) {
|
||||||
|
self.refresh_audio_apps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn notify_changed(&mut self, form: &NotifyForm) {
|
||||||
|
let messages = logic::apply_notify(&self.prefs, form);
|
||||||
|
self.said(messages);
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn test_notification(&mut self) {
|
||||||
|
let n =
|
||||||
|
voelin_platform::Notification::new(voelin_platform::APP_NAME, "Notifications work.");
|
||||||
|
self.engine.runtime().spawn(async move {
|
||||||
|
let result = voelin_platform::notify(&n).await;
|
||||||
|
later(move |app| {
|
||||||
|
app.set_status(match result {
|
||||||
|
Ok(()) => "A desktop notification was sent.".to_owned(),
|
||||||
|
Err(e) => format!("No desktop notification: {e}"),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn privacy_changed(&mut self, form: &PrivacyForm) {
|
||||||
|
let messages = logic::apply_privacy(&self.prefs, form);
|
||||||
|
self.said(messages);
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn advanced_changed(&mut self, form: &AdvancedForm) {
|
||||||
|
let messages = logic::apply_advanced(&self.prefs, form);
|
||||||
|
self.said(messages);
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Move an SRTP profile up (`-1`) or down (`1`).
|
||||||
|
pub(crate) fn srtp_move(&mut self, index: i32, by: i32) {
|
||||||
|
let Some(messages) = logic::srtp_move(&self.prefs, index, by) else { return };
|
||||||
|
self.said(messages);
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Offer a profile, or stop offering it (one stays).
|
||||||
|
pub(crate) fn srtp_toggle(&mut self, name: &str) {
|
||||||
|
let Some(messages) = logic::srtp_toggle(&self.prefs, name) else { return };
|
||||||
|
self.said(messages);
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every registered setting (Advanced), filtered.
|
||||||
|
pub(crate) fn refresh_all_settings(&self) {
|
||||||
|
let filter = self.pages.state.settings_filter.trim().to_lowercase();
|
||||||
|
self.models.all_settings.sync(&logic::setting_items(&self.prefs, &filter));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn search_settings(&mut self, text: String) {
|
||||||
|
self.pages.state.settings_filter = text;
|
||||||
|
self.refresh_all_settings();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set a key from its JSON text; why not, when it is refused.
|
||||||
|
pub(crate) fn setting_set(&mut self, key: &str, text: &str) -> String {
|
||||||
|
match self.prefs.set_json(key, json_of(text)) {
|
||||||
|
Ok(()) => {
|
||||||
|
self.refresh_all_settings();
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
let message = e.to_string();
|
||||||
|
self.set_status(message.clone());
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn setting_reset(&mut self, key: &str) {
|
||||||
|
if let Err(e) = self.prefs.reset(key) {
|
||||||
|
self.set_status(e.to_string());
|
||||||
|
}
|
||||||
|
self.refresh_all_settings();
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The folder with the log files.
|
||||||
|
pub(crate) fn open_logs(&mut self) {
|
||||||
|
let dir = voelin_platform::logs::current().and_then(std::path::Path::parent);
|
||||||
|
let result = dir.ok_or_else(|| "no log file".to_owned());
|
||||||
|
if let Err(e) = result.and_then(|dir| crate::app::open_path(dir).map_err(|e| e.to_string()))
|
||||||
|
{
|
||||||
|
self.set_status(format!("Cannot open the log folder: {e}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Integrations.
|
||||||
|
|
||||||
|
/// The gateways of our servers and the one being administered.
|
||||||
|
pub(crate) fn refresh_gateways(&self) {
|
||||||
|
let Some(ui) = self.ui.upgrade() else { return };
|
||||||
|
let bridge = ui.global::<Bridge>();
|
||||||
|
bridge.set_gateways(convert::model(&logic::gateway_items(&self.state)));
|
||||||
|
bridge.set_admin_session(self.pages.state.admin.map_or(-1, |s| s as i32));
|
||||||
|
let extra =
|
||||||
|
self.pages.state.admin.and_then(|s| self.state.sessions.get(&s)).map(|v| &v.extra);
|
||||||
|
self.models.gateway_config.sync(&logic::config_items(extra));
|
||||||
|
self.models.gateway_perms.sync(&logic::perm_items(extra));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Administer a gateway (`-1`: close).
|
||||||
|
pub(crate) fn gateway_admin(&mut self, session: i32) {
|
||||||
|
self.pages.state.admin = (session >= 0).then_some(i64::from(session));
|
||||||
|
if let Some(id) = self.pages.state.admin {
|
||||||
|
self.gateway_to(id, GatewayRequest::ConfigList);
|
||||||
|
self.gateway_to(id, GatewayRequest::PermList);
|
||||||
|
}
|
||||||
|
self.refresh_gateways();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn config_set(&mut self, key: &str, text: &str) {
|
||||||
|
if let Some(id) = self.pages.state.admin {
|
||||||
|
self.gateway_to(
|
||||||
|
id,
|
||||||
|
GatewayRequest::ConfigSet { key: key.to_owned(), value: json_of(text) },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn config_reset(&mut self, key: &str) {
|
||||||
|
if let Some(id) = self.pages.state.admin {
|
||||||
|
self.gateway_to(id, GatewayRequest::ConfigReset { key: key.to_owned() });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn config_reload(&mut self) {
|
||||||
|
if let Some(id) = self.pages.state.admin {
|
||||||
|
self.gateway_to(id, GatewayRequest::ConfigReload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn perm_set(&mut self, action: &str, everyone: bool, server: &str, channel: &str) {
|
||||||
|
let (Some(id), Some(action)) = (self.pages.state.admin, Action::parse(action)) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let rule = PermRule {
|
||||||
|
everyone,
|
||||||
|
server_groups: group_ids(server),
|
||||||
|
channel_groups: group_ids(channel),
|
||||||
|
};
|
||||||
|
self.gateway_to(id, GatewayRequest::PermSet { action, rule });
|
||||||
|
self.gateway_to(id, GatewayRequest::PermList);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn perm_reset(&mut self, action: &str) {
|
||||||
|
let (Some(id), Some(action)) = (self.pages.state.admin, Action::parse(action)) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
self.gateway_to(id, GatewayRequest::PermReset { action });
|
||||||
|
self.gateway_to(id, GatewayRequest::PermList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Probe the encoders off the UI thread (FFmpeg's probe can take a
|
||||||
|
/// while).
|
||||||
|
pub(crate) fn refresh_encoders(&mut self) {
|
||||||
|
self.pages.state.encoders_loading = true;
|
||||||
|
if let Some(ui) = self.ui.upgrade() {
|
||||||
|
ui.global::<Bridge>().set_encoders_loading(true);
|
||||||
|
}
|
||||||
|
let codecs = self.video.codecs();
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
let report = codecs.report();
|
||||||
|
later(move |app| app.encoders_ready(report));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encoders_ready(&mut self, report: voelin_core::media::voelin_media::EncoderReport) {
|
||||||
|
self.pages.state.encoders_loading = false;
|
||||||
|
let Some(ui) = self.ui.upgrade() else { return };
|
||||||
|
let bridge = ui.global::<Bridge>();
|
||||||
|
bridge.set_encoders_loading(false);
|
||||||
|
bridge.set_ffmpeg_status(logic::ffmpeg_status(&report.ffmpeg).into());
|
||||||
|
bridge.set_zero_copy_status(logic::zero_copy_status(&report.zero_copy).into());
|
||||||
|
bridge.set_encoders(convert::model(&logic::encoder_items(&report.encoders)));
|
||||||
|
bridge.set_decoders(convert::model(&logic::encoder_items(&report.decoders)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The screens and windows that can be shared (Devices).
|
||||||
|
fn load_capture_sources(&mut self) {
|
||||||
|
let names: Vec<SharedString> =
|
||||||
|
logic::capture_source_names(self.video.sources(false, false))
|
||||||
|
.into_iter()
|
||||||
|
.map(SharedString::from)
|
||||||
|
.collect();
|
||||||
|
if let Some(ui) = self.ui.upgrade() {
|
||||||
|
ui.global::<Bridge>().set_capture_sources(model(names));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Identities (My Account, Profiles).
|
||||||
|
|
||||||
|
/// Our unique ids (every identity, both server generations), to tell
|
||||||
|
/// our own messages.
|
||||||
|
pub(crate) fn load_own_uids(&mut self) {
|
||||||
|
let mut uids = std::collections::HashSet::new();
|
||||||
|
for e in self.store.identities().unwrap_or_default() {
|
||||||
|
if let Ok(identity) = self.store.identity(e.id) {
|
||||||
|
let ids = UniqueIds::from_omega(&identity.key().to_pub().to_ts());
|
||||||
|
uids.insert(ids.ts3);
|
||||||
|
uids.insert(ids.ts6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.social.own_uids = uids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The identity servers see us as on `bookmark` (the one place that
|
||||||
|
/// picks it): the bookmark's own if it names one that exists, else the
|
||||||
|
/// store's default.
|
||||||
|
fn identity_id_for(&self, bookmark: Option<i64>) -> Option<i64> {
|
||||||
|
let entries = self.store.identities().unwrap_or_default();
|
||||||
|
bookmark
|
||||||
|
.and_then(|b| self.bookmark(b))
|
||||||
|
.and_then(|b| b.identity)
|
||||||
|
.filter(|id| entries.iter().any(|e| e.id == *id))
|
||||||
|
.or_else(|| self.default_identity_id())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The identity a connection to `bookmark` uses ([`Self::identity_id_for`]).
|
||||||
|
pub(crate) fn identity_for(&self, bookmark: Option<i64>) -> tsclientlib::Identity {
|
||||||
|
self.identity_id_for(bookmark)
|
||||||
|
.and_then(|id| self.store.identity(id).ok())
|
||||||
|
.unwrap_or_else(|| self.identity.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The store's default identity (`Store::default_identity`).
|
||||||
|
fn default_identity_id(&self) -> Option<i64> {
|
||||||
|
self.store.default_identity().ok().flatten().map(|e| e.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn refresh_account(&self) {
|
||||||
|
let Some(ui) = self.ui.upgrade() else { return };
|
||||||
|
let bridge = ui.global::<Bridge>();
|
||||||
|
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.state.current);
|
||||||
|
let name = self
|
||||||
|
.store
|
||||||
|
.identities()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.into_iter()
|
||||||
|
.find(|e| Some(e.id) == entry_id)
|
||||||
|
.map(|e| e.name)
|
||||||
|
.unwrap_or_default();
|
||||||
|
bridge.set_account(
|
||||||
|
logic::account_form(bookmark, &name, &ids.ts3, &ids.ts6, identity.level()).into(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The identities, the bookmarks' choices, what an import found.
|
||||||
|
pub(crate) fn refresh_identities(&self) {
|
||||||
|
let Some(ui) = self.ui.upgrade() else { return };
|
||||||
|
let bridge = ui.global::<Bridge>();
|
||||||
|
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))))
|
||||||
|
.collect();
|
||||||
|
// What each key says: its unique id on TeamSpeak 6 servers and its level.
|
||||||
|
let keys: Vec<Option<(String, u8)>> = entries
|
||||||
|
.iter()
|
||||||
|
.map(|e| {
|
||||||
|
let identity = self.store.identity(e.id).ok()?;
|
||||||
|
let ids = UniqueIds::from_omega(&identity.key().to_pub().to_ts());
|
||||||
|
Some((ids.ts6, identity.level()))
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let facts: Vec<IdentityFacts> =
|
||||||
|
entries.iter().zip(keys).map(|(entry, key)| IdentityFacts { entry, key }).collect();
|
||||||
|
let improving =
|
||||||
|
|id: i64| self.pages.state.improving.get(&id).map(|i| (i.target, i.reached));
|
||||||
|
self.models.identities.sync(&logic::identity_items(&facts, default, &picks, improving));
|
||||||
|
let names: Vec<SharedString> =
|
||||||
|
logic::identity_names(&entries).into_iter().map(SharedString::from).collect();
|
||||||
|
bridge.set_identity_names(model(names));
|
||||||
|
bridge.set_bookmark_identities(convert::model(&logic::bookmark_identities(
|
||||||
|
&self.state.bookmarks,
|
||||||
|
&entries,
|
||||||
|
)));
|
||||||
|
let known: HashSet<&str> = entries.iter().map(|e| e.uid.as_str()).collect();
|
||||||
|
let found: Vec<Discovered> = self
|
||||||
|
.pages
|
||||||
|
.state
|
||||||
|
.found
|
||||||
|
.iter()
|
||||||
|
.map(|(f, picked)| Discovered {
|
||||||
|
nickname: f.nickname.clone(),
|
||||||
|
uid: f.uid(),
|
||||||
|
level: f.level(),
|
||||||
|
source: f.source.display().to_string(),
|
||||||
|
picked: *picked,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
bridge.set_found_identities(convert::model(&logic::found_items(&found, &known)));
|
||||||
|
bridge.set_identity_import(self.prefs.get(&IDENTITY_IMPORT));
|
||||||
|
self.refresh_account();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// "delete", "export", "stop" (the default: [`Self::use_identity`]).
|
||||||
|
pub(crate) fn identity_action(&mut self, id: i32, action: &str) {
|
||||||
|
let id = i64::from(id);
|
||||||
|
match action {
|
||||||
|
"delete" => {
|
||||||
|
if self.default_identity_id() == Some(id) {
|
||||||
|
self.set_status(
|
||||||
|
"The default identity cannot be deleted; make another one the default first.",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if let Err(e) = self.store.delete_identity(id) {
|
||||||
|
self.set_status(format!("Could not delete the identity: {e}"));
|
||||||
|
}
|
||||||
|
self.load_own_uids();
|
||||||
|
}
|
||||||
|
"export" => self.export_identity(id),
|
||||||
|
"stop" => {
|
||||||
|
if let Some(i) = self.pages.state.improving.remove(&id) {
|
||||||
|
i.cancel.store(true, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
self.refresh_identities();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn export_identity(&mut self, id: i64) {
|
||||||
|
let entries = self.store.identities().unwrap_or_default();
|
||||||
|
let (Some(entry), Ok(identity)) =
|
||||||
|
(entries.iter().find(|e| e.id == id), self.store.identity(id))
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let dir = dirs::download_dir().or_else(dirs::home_dir).unwrap_or_else(|| ".".into());
|
||||||
|
let file = logic::export_file_stem(&entry.name);
|
||||||
|
let path = dir.join(format!("{file}.ini"));
|
||||||
|
match voelin_core::identity::write_export(&path, &entry.name, &identity) {
|
||||||
|
Ok(()) => self.set_identity_status(format!(
|
||||||
|
"Exported to {} (it holds the private key: keep it safe).",
|
||||||
|
path.display()
|
||||||
|
)),
|
||||||
|
Err(e) => self.set_identity_status(format!("Could not export: {e}")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_identity_status(&mut self, text: String) {
|
||||||
|
if let Some(ui) = self.ui.upgrade() {
|
||||||
|
ui.global::<Bridge>().set_identity_status(text.clone().into());
|
||||||
|
}
|
||||||
|
self.set_status(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn rename_identity(&mut self, id: i32, name: &str) {
|
||||||
|
let name = name.trim();
|
||||||
|
if name.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if let Err(e) = self.store.rename_identity(i64::from(id), name) {
|
||||||
|
self.set_status(format!("Could not rename: {e}"));
|
||||||
|
}
|
||||||
|
self.refresh_identities();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Raise an identity's level to `target` on every core, in the
|
||||||
|
/// background.
|
||||||
|
pub(crate) fn improve_identity(&mut self, id: i32, target: i32) {
|
||||||
|
let id = i64::from(id);
|
||||||
|
let Ok(identity) = self.store.identity(id) else { return };
|
||||||
|
let Ok(target) = u8::try_from(target) else { return };
|
||||||
|
if target <= identity.level() || self.pages.state.improving.contains_key(&id) {
|
||||||
|
self.set_identity_status(format!(
|
||||||
|
"The identity is at level {} already.",
|
||||||
|
identity.level()
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let cancel = Arc::new(AtomicBool::new(false));
|
||||||
|
self.pages
|
||||||
|
.state
|
||||||
|
.improving
|
||||||
|
.insert(id, Improving { target, reached: identity.level(), cancel: cancel.clone() });
|
||||||
|
std::thread::Builder::new()
|
||||||
|
.name("identity-level".into())
|
||||||
|
.spawn(move || {
|
||||||
|
let better =
|
||||||
|
voelin_core::identity::improve_level(&identity, target, &cancel, |level| {
|
||||||
|
later(move |app| {
|
||||||
|
if let Some(i) = app.pages.state.improving.get_mut(&id) {
|
||||||
|
i.reached = i.reached.max(level);
|
||||||
|
}
|
||||||
|
app.refresh_identities();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
later(move |app| app.level_reached(id, better));
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
self.refresh_identities();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn level_reached(&mut self, id: i64, better: Option<tsclientlib::Identity>) {
|
||||||
|
self.pages.state.improving.remove(&id);
|
||||||
|
if let Some(identity) = better {
|
||||||
|
match self.store.update_identity(id, &identity) {
|
||||||
|
Ok(()) => {
|
||||||
|
self.set_identity_status(format!(
|
||||||
|
"Security level {} reached.",
|
||||||
|
identity.level()
|
||||||
|
));
|
||||||
|
if self.default_identity_id() == Some(id) {
|
||||||
|
self.identity = identity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => self.set_identity_status(format!("Could not store the identity: {e}")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.refresh_identities();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Look for identities in the official clients' files.
|
||||||
|
pub(crate) fn find_identities(&mut self) {
|
||||||
|
let mut found = Vec::new();
|
||||||
|
let mut errors = Vec::new();
|
||||||
|
for path in voelin_core::identity::discover() {
|
||||||
|
match voelin_core::identity::read(&path) {
|
||||||
|
Ok(list) => found.extend(list),
|
||||||
|
Err(e) => errors.push(e.to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let known: std::collections::HashSet<String> =
|
||||||
|
self.store.identities().unwrap_or_default().into_iter().map(|e| e.uid).collect();
|
||||||
|
let status = logic::found_status(found.len(), errors.first().map(String::as_str));
|
||||||
|
self.pages.state.found = found
|
||||||
|
.into_iter()
|
||||||
|
.map(|f| {
|
||||||
|
let new = !known.contains(&f.uid());
|
||||||
|
(f, new)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
self.set_identity_status(status);
|
||||||
|
self.refresh_identities();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn pick_found(&mut self, index: i32, on: bool) {
|
||||||
|
if let Some(f) = usize::try_from(index).ok().and_then(|i| self.pages.state.found.get_mut(i))
|
||||||
|
{
|
||||||
|
f.1 = on;
|
||||||
|
}
|
||||||
|
self.refresh_identities();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn import_identities(&mut self) {
|
||||||
|
let picked: Vec<_> =
|
||||||
|
self.pages.state.found.iter().filter(|(_, p)| *p).map(|(f, _)| f.clone()).collect();
|
||||||
|
match voelin_core::identity::import(&self.store, &picked) {
|
||||||
|
Ok(results) => {
|
||||||
|
let added = results
|
||||||
|
.iter()
|
||||||
|
.filter(|r| matches!(r, voelin_core::identity::Imported::Added(_)))
|
||||||
|
.count();
|
||||||
|
self.set_identity_status(format!("{added} identities imported."));
|
||||||
|
}
|
||||||
|
Err(e) => self.set_identity_status(format!("Could not import: {e}")),
|
||||||
|
}
|
||||||
|
self.pages.state.found.clear();
|
||||||
|
self.load_own_uids();
|
||||||
|
self.refresh_identities();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The identity a bookmark connects with (0: the default).
|
||||||
|
pub(crate) fn bookmark_identity(&mut self, bookmark: i32, index: i32) {
|
||||||
|
let entries = self.store.identities().unwrap_or_default();
|
||||||
|
let identity = usize::try_from(index - 1).ok().and_then(|i| entries.get(i)).map(|e| e.id);
|
||||||
|
let Some(mut b) = self.bookmark(i64::from(bookmark)).cloned() else { return };
|
||||||
|
b.identity = identity;
|
||||||
|
if let Err(e) = self.store.update_bookmark(&b) {
|
||||||
|
self.set_status(format!("Could not save: {e}"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.state.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||||
|
self.refresh_identities();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Camera (Voice & Video, Devices).
|
||||||
|
|
||||||
|
fn load_cameras(&mut self) {
|
||||||
|
let mut cameras = crate::camera::list();
|
||||||
|
// Sample data never opens a real camera.
|
||||||
|
if self.demo_ui {
|
||||||
|
cameras.retain(|(id, _)| id == "synthetic");
|
||||||
|
}
|
||||||
|
self.pages.state.cameras = cameras.iter().map(|(id, _)| id.clone()).collect();
|
||||||
|
let names: Vec<SharedString> =
|
||||||
|
cameras.into_iter().map(|(_, n)| SharedString::from(n)).collect();
|
||||||
|
if let Some(ui) = self.ui.upgrade() {
|
||||||
|
ui.global::<Bridge>().set_cameras(model(names));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn toggle_camera_preview(&mut self) {
|
||||||
|
if self.pages.camera.is_some() {
|
||||||
|
self.stop_camera();
|
||||||
|
} else {
|
||||||
|
self.start_camera();
|
||||||
|
}
|
||||||
|
self.refresh_pages();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn start_camera(&mut self) {
|
||||||
|
let device =
|
||||||
|
if self.demo_ui { "synthetic".to_owned() } else { self.prefs.get(&VIDEO_CAMERA) };
|
||||||
|
let size = parse_size(&self.prefs.get(&VIDEO_RESOLUTION));
|
||||||
|
let blur = self.prefs.get(&VIDEO_BACKGROUND) == "blur";
|
||||||
|
let mirror = self.prefs.get(&VIDEO_MIRROR);
|
||||||
|
self.pages.camera =
|
||||||
|
Some(crate::camera::Preview::start(self.engine.runtime(), &device, size, blur, mirror));
|
||||||
|
if let Some(ui) = self.ui.upgrade() {
|
||||||
|
ui.global::<Bridge>().set_camera_status("Starting the camera…".into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn stop_camera(&mut self) {
|
||||||
|
if self.pages.camera.take().is_some()
|
||||||
|
&& let Some(ui) = self.ui.upgrade()
|
||||||
|
{
|
||||||
|
let bridge = ui.global::<Bridge>();
|
||||||
|
bridge.set_camera_frame(slint::Image::default());
|
||||||
|
bridge.set_camera_status(SharedString::new());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn restart_camera(&mut self) {
|
||||||
|
if self.pages.camera.is_some() {
|
||||||
|
self.stop_camera();
|
||||||
|
self.start_camera();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The camera preview's newest picture (called by its timer).
|
||||||
|
pub(crate) fn camera_frame(&mut self) {
|
||||||
|
let Some(preview) = &self.pages.camera else { return };
|
||||||
|
let (frame, status) = (preview.take_picture(), preview.status());
|
||||||
|
if let Some(ui) = self.ui.upgrade() {
|
||||||
|
let bridge = ui.global::<Bridge>();
|
||||||
|
if let Some(frame) = frame {
|
||||||
|
bridge.set_camera_frame(frame);
|
||||||
|
}
|
||||||
|
bridge.set_camera_status(status.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Play a short tone on the speakers (the Test Sound button).
|
||||||
|
pub(crate) fn test_sound(&mut self) {
|
||||||
|
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 {
|
||||||
|
later(move |app| app.set_status(format!("Cannot play the test sound: {e}")));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Where the logs go, for the Advanced page.
|
||||||
|
fn log_text() -> String {
|
||||||
|
match voelin_platform::logs::current() {
|
||||||
|
Some(path) => format!(
|
||||||
|
"This run logs to {} (the previous runs' next to it, the last as voelin.1.log). \
|
||||||
|
VOELIN_LOG=voelin_core=debug,voelin_ui=debug logs more; warnings also go to the terminal.",
|
||||||
|
path.display()
|
||||||
|
),
|
||||||
|
None => "Logs go to the terminal the app was started from (standard error); \
|
||||||
|
RUST_LOG=voelin_core=debug,voelin_ui=debug shows more."
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
//! The settings pages added with the new design: My Account, Profiles
|
||||||
|
//! (identities), the camera and stream quality of Voice & Video, Streaming,
|
||||||
|
//! Devices, Notifications, Privacy & Safety, Integrations (gateways,
|
||||||
|
//! gateway administration, encoders) and Advanced. Every control reads and
|
||||||
|
//! writes a setting (`voelin_core::settings`, `crate::settings`) and
|
||||||
|
//! applies at once; the forms are filled again when a setting changes
|
||||||
|
//! anywhere ([`App::page_setting_changed`](crate::app::App)).
|
||||||
|
//!
|
||||||
|
//! What the pages show and what the controls change is
|
||||||
|
//! `voelin_ui_vm::settings_pages::logic`; `bind.rs` puts it on the Bridge
|
||||||
|
//! and runs the side effects (the camera, the engine, the identity store).
|
||||||
|
|
||||||
|
mod bind;
|
||||||
|
|
||||||
|
use crate::vm::settings_pages::logic::PagesState;
|
||||||
|
|
||||||
|
/// State of the settings pages.
|
||||||
|
#[derive(Default)]
|
||||||
|
pub(crate) struct Pages {
|
||||||
|
/// What needs no toolkit.
|
||||||
|
pub state: PagesState,
|
||||||
|
/// The camera preview of Voice & Video and Devices.
|
||||||
|
pub camera: Option<crate::camera::Preview>,
|
||||||
|
/// Applications playing audio (the audio sources picker), while the
|
||||||
|
/// Streaming page is open.
|
||||||
|
pub audio_apps: Option<voelin_core::media::AudioApps>,
|
||||||
|
}
|
||||||
+110
-156
@@ -8,59 +8,24 @@
|
|||||||
//! [`Event::FriendPresence`] adds when a friend came online, for "12m ago"
|
//! [`Event::FriendPresence`] adds when a friend came online, for "12m ago"
|
||||||
//! and the notification.
|
//! and the notification.
|
||||||
|
|
||||||
|
use slint::ComponentHandle;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::rc::Rc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use slint::{ComponentHandle, ModelRc, SharedString, VecModel};
|
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
use voelin_core::{
|
use voelin_core::{
|
||||||
Command, Contact, Event, FriendSpot, HistoryMessage, HistorySource, Relation, VoiceState,
|
Command, Contact, Event, FriendSpot, HistoryMessage, HistorySource, Relation, VoiceState,
|
||||||
};
|
};
|
||||||
use voelin_gateway_proto::{
|
|
||||||
Action, ActivityEntry, ConfigEntry, EventInfo, PermRuleInfo, StreamEntry,
|
|
||||||
};
|
|
||||||
use voelin_model::{ChatMessage, ChatTarget};
|
use voelin_model::{ChatMessage, ChatTarget};
|
||||||
|
|
||||||
use crate::app::{
|
use crate::app::{App, Bridge, Nav, Page, SettingsSection};
|
||||||
App, Bridge, ChatLine, ContactItem, ConversationItem, HappeningItem, LiveItem, Nav, NoticeItem,
|
use crate::bind::rows::Rows;
|
||||||
Page, RecordingItem, SearchItem, SettingsSection,
|
|
||||||
};
|
|
||||||
use crate::settings::{
|
use crate::settings::{
|
||||||
NOTIFY_EVENTS, NOTIFY_FRIENDS, NOTIFY_MENTIONS, NOTIFY_MESSAGES, NOTIFY_POKES, NotifyLevel,
|
NOTIFY_EVENTS, NOTIFY_FRIENDS, NOTIFY_MENTIONS, NOTIFY_MESSAGES, NOTIFY_POKES, NotifyLevel,
|
||||||
};
|
};
|
||||||
use crate::vm;
|
use crate::vm;
|
||||||
|
use crate::vm::bridge::{ContactItem, NoticeItem, SearchItem};
|
||||||
use crate::vm::social::{ago, matches, mentions, plain};
|
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.
|
/// A poke we got.
|
||||||
pub(crate) struct Poke {
|
pub(crate) struct Poke {
|
||||||
pub session: i64,
|
pub session: i64,
|
||||||
@@ -164,57 +129,57 @@ pub(crate) struct Social {
|
|||||||
|
|
||||||
/// The models of these screens, set on the Bridge once.
|
/// The models of these screens, set on the Bridge once.
|
||||||
pub(crate) struct SocialModels {
|
pub(crate) struct SocialModels {
|
||||||
pub friends_online: Rc<VecModel<ContactItem>>,
|
pub friends_online: Rows<vm::bridge::ContactItem>,
|
||||||
pub friend_activity: Rc<VecModel<ContactItem>>,
|
pub friend_activity: Rows<vm::bridge::ContactItem>,
|
||||||
pub contacts: Rc<VecModel<ContactItem>>,
|
pub contacts: Rows<vm::bridge::ContactItem>,
|
||||||
pub blocked: Rc<VecModel<ContactItem>>,
|
pub blocked: Rows<vm::bridge::ContactItem>,
|
||||||
pub live: Rc<VecModel<LiveItem>>,
|
pub live: Rows<vm::bridge::LiveItem>,
|
||||||
pub recent: Rc<VecModel<ConversationItem>>,
|
pub recent: Rows<vm::bridge::ConversationItem>,
|
||||||
pub sidebar_dms: Rc<VecModel<ConversationItem>>,
|
pub sidebar_dms: Rows<vm::bridge::ConversationItem>,
|
||||||
pub conversations: Rc<VecModel<ConversationItem>>,
|
pub conversations: Rows<vm::bridge::ConversationItem>,
|
||||||
pub dm_lines: Rc<VecModel<ChatLine>>,
|
pub dm_lines: Rows<vm::bridge::ChatLine>,
|
||||||
pub happenings: Rc<VecModel<HappeningItem>>,
|
pub happenings: Rows<vm::bridge::HappeningItem>,
|
||||||
pub recordings: Rc<VecModel<RecordingItem>>,
|
pub recordings: Rows<vm::bridge::RecordingItem>,
|
||||||
pub notices: Rc<VecModel<NoticeItem>>,
|
pub notices: Rows<vm::bridge::NoticeItem>,
|
||||||
pub mentions: Rc<VecModel<NoticeItem>>,
|
pub mentions: Rows<vm::bridge::NoticeItem>,
|
||||||
pub search: Rc<VecModel<SearchItem>>,
|
pub search: Rows<vm::bridge::SearchItem>,
|
||||||
pub events: Rc<VecModel<crate::app::EventItem>>,
|
pub events: Rows<vm::bridge::EventItem>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SocialModels {
|
impl SocialModels {
|
||||||
pub fn new(bridge: &Bridge) -> Self {
|
pub fn new(bridge: &Bridge) -> Self {
|
||||||
let m = Self {
|
let m = Self {
|
||||||
friends_online: Rc::default(),
|
friends_online: Rows::default(),
|
||||||
friend_activity: Rc::default(),
|
friend_activity: Rows::default(),
|
||||||
contacts: Rc::default(),
|
contacts: Rows::default(),
|
||||||
blocked: Rc::default(),
|
blocked: Rows::default(),
|
||||||
live: Rc::default(),
|
live: Rows::default(),
|
||||||
recent: Rc::default(),
|
recent: Rows::default(),
|
||||||
sidebar_dms: Rc::default(),
|
sidebar_dms: Rows::default(),
|
||||||
conversations: Rc::default(),
|
conversations: Rows::default(),
|
||||||
dm_lines: Rc::default(),
|
dm_lines: Rows::default(),
|
||||||
happenings: Rc::default(),
|
happenings: Rows::default(),
|
||||||
recordings: Rc::default(),
|
recordings: Rows::default(),
|
||||||
notices: Rc::default(),
|
notices: Rows::default(),
|
||||||
mentions: Rc::default(),
|
mentions: Rows::default(),
|
||||||
search: Rc::default(),
|
search: Rows::default(),
|
||||||
events: Rc::default(),
|
events: Rows::default(),
|
||||||
};
|
};
|
||||||
bridge.set_friends_online(ModelRc::from(m.friends_online.clone()));
|
bridge.set_friends_online(m.friends_online.model());
|
||||||
bridge.set_friend_activity(ModelRc::from(m.friend_activity.clone()));
|
bridge.set_friend_activity(m.friend_activity.model());
|
||||||
bridge.set_contacts(ModelRc::from(m.contacts.clone()));
|
bridge.set_contacts(m.contacts.model());
|
||||||
bridge.set_blocked(ModelRc::from(m.blocked.clone()));
|
bridge.set_blocked(m.blocked.model());
|
||||||
bridge.set_live_rooms(ModelRc::from(m.live.clone()));
|
bridge.set_live_rooms(m.live.model());
|
||||||
bridge.set_recent_chats(ModelRc::from(m.recent.clone()));
|
bridge.set_recent_chats(m.recent.model());
|
||||||
bridge.set_sidebar_dms(ModelRc::from(m.sidebar_dms.clone()));
|
bridge.set_sidebar_dms(m.sidebar_dms.model());
|
||||||
bridge.set_conversations(ModelRc::from(m.conversations.clone()));
|
bridge.set_conversations(m.conversations.model());
|
||||||
bridge.set_dm_messages(ModelRc::from(m.dm_lines.clone()));
|
bridge.set_dm_messages(m.dm_lines.model());
|
||||||
bridge.set_happenings(ModelRc::from(m.happenings.clone()));
|
bridge.set_happenings(m.happenings.model());
|
||||||
bridge.set_recordings(ModelRc::from(m.recordings.clone()));
|
bridge.set_recordings(m.recordings.model());
|
||||||
bridge.set_notifications(ModelRc::from(m.notices.clone()));
|
bridge.set_notifications(m.notices.model());
|
||||||
bridge.set_home_mentions(ModelRc::from(m.mentions.clone()));
|
bridge.set_home_mentions(m.mentions.model());
|
||||||
bridge.set_search_results(ModelRc::from(m.search.clone()));
|
bridge.set_search_results(m.search.model());
|
||||||
bridge.set_events(ModelRc::from(m.events.clone()));
|
bridge.set_events(m.events.model());
|
||||||
m
|
m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,25 +236,31 @@ const SETTING_PAGES: [(&str, &str, SettingsSection); 11] = [
|
|||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
/// The avatar picture of someone by unique id, from any session.
|
/// The avatar picture of someone by unique id, from any session.
|
||||||
pub(crate) fn avatar_of(&self, uid: &str) -> slint::Image {
|
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.
|
/// A server's name: its bookmark's, else what the session calls it.
|
||||||
pub(crate) fn server_name(&self, session: i64) -> String {
|
pub(crate) fn server_name(&self, session: i64) -> String {
|
||||||
self.bookmark(session).map(|b| b.name.clone()).unwrap_or_else(|| {
|
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
|
/// Every session where the client with this unique id is, in bookmark
|
||||||
/// order.
|
/// order.
|
||||||
pub(crate) fn spots_of(&self, uid: &str) -> Vec<Spot> {
|
pub(crate) fn spots_of(&self, uid: &str) -> Vec<Spot> {
|
||||||
let mut ids: Vec<i64> = self.sessions.keys().copied().collect();
|
let mut ids: Vec<i64> = self.state.sessions.keys().copied().collect();
|
||||||
ids.sort_by_key(|id| self.bookmarks.iter().position(|b| b.id == *id).unwrap_or(usize::MAX));
|
ids.sort_by_key(|id| {
|
||||||
|
self.state.bookmarks.iter().position(|b| b.id == *id).unwrap_or(usize::MAX)
|
||||||
|
});
|
||||||
let mut spots = Vec::new();
|
let mut spots = Vec::new();
|
||||||
for id in ids {
|
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))
|
let Some(c) = view.presence.clients.values().find(|c| c.uid.as_deref() == Some(uid))
|
||||||
else {
|
else {
|
||||||
continue;
|
continue;
|
||||||
@@ -314,7 +285,7 @@ impl App {
|
|||||||
/// The title of what someone streams, if a directory or the voice
|
/// The title of what someone streams, if a directory or the voice
|
||||||
/// connection says.
|
/// connection says.
|
||||||
fn stream_title(&self, spot: &Spot, uid: &str) -> Option<String> {
|
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
|
view.streams
|
||||||
.iter()
|
.iter()
|
||||||
.find(|s| s.streamer == spot.client)
|
.find(|s| s.streamer == spot.client)
|
||||||
@@ -331,7 +302,7 @@ impl App {
|
|||||||
let first = spots.first();
|
let first = spots.first();
|
||||||
let name = if contact.nickname.is_empty() {
|
let name = if contact.nickname.is_empty() {
|
||||||
first
|
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())
|
.unwrap_or_else(|| contact.uid.chars().take(8).collect())
|
||||||
} else {
|
} else {
|
||||||
contact.nickname.clone()
|
contact.nickname.clone()
|
||||||
@@ -370,7 +341,7 @@ impl App {
|
|||||||
format!("Contact since {}", t.with_timezone(&chrono::Local).format("%-d %b %Y"))
|
format!("Contact since {}", t.with_timezone(&chrono::Local).format("%-d %b %Y"))
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let spot_texts: Vec<SharedString> = spots
|
let spot_texts: Vec<Arc<str>> = spots
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
if s.channel_title.is_empty() {
|
if s.channel_title.is_empty() {
|
||||||
@@ -397,7 +368,7 @@ impl App {
|
|||||||
volume: contact.volume * 100.0,
|
volume: contact.volume * 100.0,
|
||||||
muted: contact.muted,
|
muted: contact.muted,
|
||||||
since: since.into(),
|
since: since.into(),
|
||||||
spots: crate::app::model(spot_texts),
|
spots: spot_texts,
|
||||||
reachable: spots.iter().any(|s| s.voice),
|
reachable: spots.iter().any(|s| s.voice),
|
||||||
selected: self.social.selected.as_deref() == Some(contact.uid.as_str()),
|
selected: self.social.selected.as_deref() == Some(contact.uid.as_str()),
|
||||||
}
|
}
|
||||||
@@ -407,7 +378,7 @@ impl App {
|
|||||||
/// then away), then by name.
|
/// then away), then by name.
|
||||||
fn sorted_contacts(&self, items: &mut [ContactItem]) {
|
fn sorted_contacts(&self, items: &mut [ContactItem]) {
|
||||||
items.sort_by_key(|c| {
|
items.sort_by_key(|c| {
|
||||||
(!c.online, !c.streaming, c.away, c.relation != "friend", c.name.to_lowercase())
|
(!c.online, !c.streaming, c.away, &*c.relation != "friend", c.name.to_lowercase())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,25 +388,25 @@ impl App {
|
|||||||
let bridge = ui.global::<Bridge>();
|
let bridge = ui.global::<Bridge>();
|
||||||
let m = &self.models.social;
|
let m = &self.models.social;
|
||||||
let mut all: Vec<ContactItem> =
|
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);
|
self.sorted_contacts(&mut all);
|
||||||
let friends: Vec<ContactItem> =
|
let friends: Vec<ContactItem> =
|
||||||
all.iter().filter(|c| c.relation == "friend").cloned().collect();
|
all.iter().filter(|c| &*c.relation == "friend").cloned().collect();
|
||||||
let online: Vec<ContactItem> = friends.iter().filter(|c| c.online).cloned().collect();
|
let online: Vec<ContactItem> = friends.iter().filter(|c| c.online).cloned().collect();
|
||||||
vm::list::sync(&m.friends_online, &online[..online.len().min(20)]);
|
m.friends_online.sync(&online[..online.len().min(20)]);
|
||||||
// Online friends first, then the others by when they were seen.
|
// Online friends first, then the others by when they were seen.
|
||||||
let mut activity = friends.clone();
|
let mut activity = friends.clone();
|
||||||
activity.sort_by_key(|c| {
|
activity.sort_by_key(|c| {
|
||||||
let seen = self.contacts.get(c.uid.as_str()).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_str()).copied().unwrap_or(0);
|
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 }))
|
(!c.online, !c.streaming, std::cmp::Reverse(if c.online { since } else { seen }))
|
||||||
});
|
});
|
||||||
vm::list::sync(&m.friend_activity, &activity[..activity.len().min(7)]);
|
m.friend_activity.sync(&activity[..activity.len().min(7)]);
|
||||||
let blocked: Vec<ContactItem> =
|
let blocked: Vec<ContactItem> =
|
||||||
all.iter().filter(|c| c.relation == "blocked").cloned().collect();
|
all.iter().filter(|c| &*c.relation == "blocked").cloned().collect();
|
||||||
vm::list::sync(&m.blocked, &blocked);
|
m.blocked.sync(&blocked);
|
||||||
bridge.set_contacts_online(
|
bridge.set_contacts_online(
|
||||||
all.iter().filter(|c| c.online && c.relation != "blocked").count() as i32,
|
all.iter().filter(|c| c.online && &*c.relation != "blocked").count() as i32,
|
||||||
);
|
);
|
||||||
bridge.set_contacts_all(all.len() as i32);
|
bridge.set_contacts_all(all.len() as i32);
|
||||||
bridge.set_contacts_blocked(blocked.len() as i32);
|
bridge.set_contacts_blocked(blocked.len() as i32);
|
||||||
@@ -443,22 +414,22 @@ impl App {
|
|||||||
let shown: Vec<ContactItem> = all
|
let shown: Vec<ContactItem> = all
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|c| match self.social.friends_tab {
|
.filter(|c| match self.social.friends_tab {
|
||||||
0 => c.online && c.relation != "blocked",
|
0 => c.online && &*c.relation != "blocked",
|
||||||
2 => c.relation == "blocked",
|
2 => &*c.relation == "blocked",
|
||||||
_ => true,
|
_ => true,
|
||||||
})
|
})
|
||||||
.filter(|c| matches(filter, &[&c.name, &c.uid, &c.note]))
|
.filter(|c| matches(filter, &[&c.name, &c.uid, &c.note]))
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
vm::list::sync(&m.contacts, &shown);
|
m.contacts.sync(&shown);
|
||||||
let selected = self
|
let selected = self
|
||||||
.social
|
.social
|
||||||
.selected
|
.selected
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|uid| all.iter().find(|c| c.uid.as_str() == uid))
|
.and_then(|uid| all.iter().find(|c| c.uid.as_ref() == uid))
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
bridge.set_contact(selected);
|
bridge.set_contact(selected.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn friends_tab(&mut self, tab: i32) {
|
pub(crate) fn friends_tab(&mut self, tab: i32) {
|
||||||
@@ -478,15 +449,15 @@ impl App {
|
|||||||
|
|
||||||
/// Change a contact (or make one of someone we see).
|
/// Change a contact (or make one of someone we see).
|
||||||
fn update_contact(&mut self, uid: &str, f: impl FnOnce(&mut Contact)) {
|
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);
|
let mut c = Contact::new(uid);
|
||||||
if let Some(s) = self.spots_of(uid).first() {
|
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
|
c
|
||||||
});
|
});
|
||||||
f(&mut contact);
|
f(&mut contact);
|
||||||
self.contacts.insert(uid.to_owned(), contact.clone());
|
self.state.contacts.insert(uid.to_owned(), contact.clone());
|
||||||
if !self.demo_ui {
|
if !self.demo_ui {
|
||||||
self.engine.send(Command::SetContact { contact: Box::new(contact) });
|
self.engine.send(Command::SetContact { contact: Box::new(contact) });
|
||||||
}
|
}
|
||||||
@@ -516,7 +487,7 @@ impl App {
|
|||||||
"neutral" => self.update_contact(uid, |c| c.relation = Relation::Neutral),
|
"neutral" => self.update_contact(uid, |c| c.relation = Relation::Neutral),
|
||||||
"mute" => self.update_contact(uid, |c| c.muted = !c.muted),
|
"mute" => self.update_contact(uid, |c| c.muted = !c.muted),
|
||||||
"remove" => {
|
"remove" => {
|
||||||
self.contacts.remove(uid);
|
self.state.contacts.remove(uid);
|
||||||
if self.social.selected.as_deref() == Some(uid) {
|
if self.social.selected.as_deref() == Some(uid) {
|
||||||
self.social.selected = None;
|
self.social.selected = None;
|
||||||
}
|
}
|
||||||
@@ -558,14 +529,14 @@ impl App {
|
|||||||
if s.voice {
|
if s.voice {
|
||||||
self.watch_client(s.client);
|
self.watch_client(s.client);
|
||||||
} else {
|
} else {
|
||||||
self.pending_watch = Some((s.session, s.client));
|
self.state.pending_watch = Some((s.session, s.client));
|
||||||
self.join_person(&[s]);
|
self.join_person(&[s]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The server page of a session.
|
/// The server page of a session.
|
||||||
pub(crate) fn show_server(&mut self, session: i64) {
|
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.select_server(session);
|
||||||
}
|
}
|
||||||
self.navigate(|nav| nav.invoke_show(Page::Server));
|
self.navigate(|nav| nav.invoke_show(Page::Server));
|
||||||
@@ -653,14 +624,14 @@ impl App {
|
|||||||
};
|
};
|
||||||
let notices = &self.social.notices;
|
let notices = &self.social.notices;
|
||||||
let items: Vec<NoticeItem> = notices.iter().map(item).collect();
|
let items: Vec<NoticeItem> = notices.iter().map(item).collect();
|
||||||
vm::list::sync(&self.models.social.notices, &items);
|
self.models.social.notices.sync(&items);
|
||||||
let mentions: Vec<NoticeItem> = notices
|
let mentions: Vec<NoticeItem> = notices
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|n| n.unread && n.kind == NoticeKind::Mention)
|
.filter(|n| n.unread && n.kind == NoticeKind::Mention)
|
||||||
.take(3)
|
.take(3)
|
||||||
.map(item)
|
.map(item)
|
||||||
.collect();
|
.collect();
|
||||||
vm::list::sync(&self.models.social.mentions, &mentions);
|
self.models.social.mentions.sync(&mentions);
|
||||||
let unread = notices.iter().filter(|n| n.unread).count();
|
let unread = notices.iter().filter(|n| n.unread).count();
|
||||||
ui.global::<Bridge>().set_notifications_unread(unread as i32);
|
ui.global::<Bridge>().set_notifications_unread(unread as i32);
|
||||||
}
|
}
|
||||||
@@ -703,7 +674,7 @@ impl App {
|
|||||||
|
|
||||||
/// Our nickname in a session.
|
/// Our nickname in a session.
|
||||||
fn own_nick(&self, session: i64) -> String {
|
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)))
|
view.and_then(|v| v.state.own_client.map(|c| v.nickname(c)))
|
||||||
.or_else(|| self.bookmark(session).map(|b| b.nickname.clone()))
|
.or_else(|| self.bookmark(session).map(|b| b.nickname.clone()))
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@@ -711,7 +682,7 @@ impl App {
|
|||||||
|
|
||||||
/// Whether a message is ours.
|
/// Whether a message is ours.
|
||||||
pub(crate) fn is_own(&self, session: i64, message: &ChatMessage) -> bool {
|
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)
|
own_message(&self.social.own_uids, own_client, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -741,6 +712,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
let place = match target {
|
let place = match target {
|
||||||
ChatTarget::Channel(cid) => self
|
ChatTarget::Channel(cid) => self
|
||||||
|
.state
|
||||||
.sessions
|
.sessions
|
||||||
.get(&session)
|
.get(&session)
|
||||||
.and_then(|v| v.presence.channels.get(cid))
|
.and_then(|v| v.presence.channels.get(cid))
|
||||||
@@ -766,7 +738,7 @@ impl App {
|
|||||||
let mut touched = Touched::default();
|
let mut touched = Touched::default();
|
||||||
match event {
|
match event {
|
||||||
Event::Presence { session, .. } => {
|
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 {
|
if view.extra.presence_since == 0 {
|
||||||
view.extra.presence_since = now_ms();
|
view.extra.presence_since = now_ms();
|
||||||
}
|
}
|
||||||
@@ -775,9 +747,9 @@ impl App {
|
|||||||
}
|
}
|
||||||
Event::State { session, state } => {
|
Event::State { session, state } => {
|
||||||
let id = *session as i64;
|
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 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;
|
view.extra.inbox_asked = false;
|
||||||
}
|
}
|
||||||
} else if was != Some(VoiceState::Connected) {
|
} else if was != Some(VoiceState::Connected) {
|
||||||
@@ -787,7 +759,7 @@ impl App {
|
|||||||
touched.home = true;
|
touched.home = true;
|
||||||
}
|
}
|
||||||
Event::ServerInfo { session, backend, .. } => {
|
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();
|
backend.product.clone();
|
||||||
touched.people = true;
|
touched.people = true;
|
||||||
touched.home = true;
|
touched.home = true;
|
||||||
@@ -832,7 +804,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
Event::Chat { session, message } => {
|
Event::Chat { session, message } => {
|
||||||
let id = *session as i64;
|
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);
|
self.chat_notice(id, message);
|
||||||
touched.chats = true;
|
touched.chats = true;
|
||||||
}
|
}
|
||||||
@@ -841,6 +813,7 @@ impl App {
|
|||||||
let id = *session as i64;
|
let id = *session as i64;
|
||||||
if *source == HistorySource::Live {
|
if *source == HistorySource::Live {
|
||||||
let known: HashSet<i64> = self
|
let known: HashSet<i64> = self
|
||||||
|
.state
|
||||||
.sessions
|
.sessions
|
||||||
.get(&id)
|
.get(&id)
|
||||||
.and_then(|v| v.tabs.iter().find(|t| t.target == *target))
|
.and_then(|v| v.tabs.iter().find(|t| t.target == *target))
|
||||||
@@ -857,7 +830,7 @@ impl App {
|
|||||||
Event::OfflineMessages { session, result, .. } => {
|
Event::OfflineMessages { session, result, .. } => {
|
||||||
match result {
|
match result {
|
||||||
Ok(list) => {
|
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();
|
list.clone();
|
||||||
}
|
}
|
||||||
Err(e) => debug!("offline messages: {e}"),
|
Err(e) => debug!("offline messages: {e}"),
|
||||||
@@ -899,13 +872,14 @@ impl App {
|
|||||||
self.social.online_since.insert(uid.to_owned(), now);
|
self.social.online_since.insert(uid.to_owned(), now);
|
||||||
// Friends found in a session's first presence were there before.
|
// Friends found in a session's first presence were there before.
|
||||||
let new = sessions.iter().all(|s| {
|
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
|
v.extra.presence_since > 0 && now - v.extra.presence_since > 10_000
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
if new {
|
if new {
|
||||||
let s = &sessions[0];
|
let s = &sessions[0];
|
||||||
let channel = self
|
let channel = self
|
||||||
|
.state
|
||||||
.sessions
|
.sessions
|
||||||
.get(&(s.session as i64))
|
.get(&(s.session as i64))
|
||||||
.and_then(|v| v.presence.channels.get(&s.channel))
|
.and_then(|v| v.presence.channels.get(&s.channel))
|
||||||
@@ -951,9 +925,10 @@ impl App {
|
|||||||
};
|
};
|
||||||
if !people_only {
|
if !people_only {
|
||||||
let servers = self
|
let servers = self
|
||||||
|
.state
|
||||||
.bookmarks
|
.bookmarks
|
||||||
.iter()
|
.iter()
|
||||||
.zip(vm::servers::tints(&self.bookmarks))
|
.zip(vm::servers::tints(&self.state.bookmarks))
|
||||||
.filter(|(b, _)| matches(&query, &[&b.name, &b.address]))
|
.filter(|(b, _)| matches(&query, &[&b.name, &b.address]))
|
||||||
.map(|(b, tint)| {
|
.map(|(b, tint)| {
|
||||||
(
|
(
|
||||||
@@ -974,8 +949,8 @@ impl App {
|
|||||||
}
|
}
|
||||||
if !query.is_empty() && !people_only {
|
if !query.is_empty() && !people_only {
|
||||||
let mut channels = Vec::new();
|
let mut channels = Vec::new();
|
||||||
for b in &self.bookmarks {
|
for b in &self.state.bookmarks {
|
||||||
let Some(view) = self.sessions.get(&b.id) else { continue };
|
let Some(view) = self.state.sessions.get(&b.id) else { continue };
|
||||||
for (channel, title) in
|
for (channel, title) in
|
||||||
vm::social::found_channels(view.presence.channels.values(), &query)
|
vm::social::found_channels(view.presence.channels.values(), &query)
|
||||||
{
|
{
|
||||||
@@ -995,8 +970,8 @@ impl App {
|
|||||||
if !query.is_empty() || people_only {
|
if !query.is_empty() || people_only {
|
||||||
let mut people = Vec::new();
|
let mut people = Vec::new();
|
||||||
let mut seen: HashSet<String> = HashSet::new();
|
let mut seen: HashSet<String> = HashSet::new();
|
||||||
for b in &self.bookmarks {
|
for b in &self.state.bookmarks {
|
||||||
let Some(view) = self.sessions.get(&b.id) else { continue };
|
let Some(view) = self.state.sessions.get(&b.id) else { continue };
|
||||||
for c in view.presence.clients.values() {
|
for c in view.presence.clients.values() {
|
||||||
if c.is_query || Some(c.id) == view.state.own_client {
|
if c.is_query || Some(c.id) == view.state.own_client {
|
||||||
continue;
|
continue;
|
||||||
@@ -1026,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]) {
|
if seen.contains(&c.uid) || !matches(&query, &[&c.nickname, &c.note]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1069,7 +1044,7 @@ impl App {
|
|||||||
group(&mut items, "Settings", pages);
|
group(&mut items, "Settings", pages);
|
||||||
}
|
}
|
||||||
self.social.found = found;
|
self.social.found = found;
|
||||||
vm::list::sync(&self.models.social.search, &items);
|
self.models.social.search.sync(&items);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Open a search result.
|
/// Open a search result.
|
||||||
@@ -1103,33 +1078,12 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What a privacy or notification choice is as an index, and back.
|
|
||||||
pub(crate) fn allowed_index(a: voelin_core::settings::Allowed) -> i32 {
|
|
||||||
match a {
|
|
||||||
voelin_core::settings::Allowed::Everyone => 0,
|
|
||||||
voelin_core::settings::Allowed::Friends => 1,
|
|
||||||
voelin_core::settings::Allowed::Nobody => 2,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn allowed_of(index: i32) -> voelin_core::settings::Allowed {
|
|
||||||
match index {
|
|
||||||
1 => voelin_core::settings::Allowed::Friends,
|
|
||||||
2 => voelin_core::settings::Allowed::Nobody,
|
|
||||||
_ => voelin_core::settings::Allowed::Everyone,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn privacy_indices() {
|
fn notice_names_and_setting_pages() {
|
||||||
for i in 0..3 {
|
|
||||||
assert_eq!(allowed_index(allowed_of(i)), i);
|
|
||||||
}
|
|
||||||
assert_eq!(allowed_of(9), voelin_core::settings::Allowed::Everyone);
|
|
||||||
assert_eq!(NoticeKind::Poke.name(), "poke");
|
assert_eq!(NoticeKind::Poke.name(), "poke");
|
||||||
assert!(SETTING_PAGES.iter().any(|(t, _, _)| *t == "Voice & Video"));
|
assert!(SETTING_PAGES.iter().any(|(t, _, _)| *t == "Voice & Video"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
//! viewer. The engine runs the stream sessions; `video.rs` captures,
|
//! viewer. The engine runs the stream sessions; `video.rs` captures,
|
||||||
//! encodes and decodes.
|
//! encodes and decodes.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use slint::{ComponentHandle, Model};
|
use slint::{ComponentHandle, Model};
|
||||||
@@ -15,14 +16,14 @@ use voelin_core::stream::{
|
|||||||
};
|
};
|
||||||
use voelin_core::{Command, Event, StreamState, WatchState};
|
use voelin_core::{Command, Event, StreamState, WatchState};
|
||||||
|
|
||||||
use crate::app::{
|
use crate::app::{App, Bridge, later, with_app};
|
||||||
App, Bridge, ShareForm, SourceItem, StreamItem, ViewerItem, later, model, with_app,
|
use crate::bind::convert;
|
||||||
};
|
|
||||||
use crate::settings::{
|
use crate::settings::{
|
||||||
BITRATE_CHOICES, FPS_CHOICES, LEGACY_BITRATE_CHOICES, LEGACY_FPS_CHOICES, ShareDefaults,
|
BITRATE_CHOICES, FPS_CHOICES, LEGACY_BITRATE_CHOICES, LEGACY_FPS_CHOICES, ShareDefaults,
|
||||||
nearest_choice, parse_positive,
|
nearest_choice, parse_positive,
|
||||||
};
|
};
|
||||||
use crate::video::{self, Capture, CaptureRequest, Decoder};
|
use crate::video::{self, Capture, CaptureRequest, Decoder};
|
||||||
|
use crate::vm::bridge::{ShareForm, SourceItem, StreamItem, ViewerItem};
|
||||||
|
|
||||||
/// Our stream.
|
/// Our stream.
|
||||||
pub(crate) struct Share {
|
pub(crate) struct Share {
|
||||||
@@ -111,11 +112,11 @@ impl Watch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// "Auto" and one entry per layer the streamer offers.
|
/// "Auto" and one entry per layer the streamer offers.
|
||||||
fn qualities(&self) -> Vec<slint::SharedString> {
|
fn qualities(&self) -> Vec<Arc<str>> {
|
||||||
if self.layers.len() < 2 {
|
if self.layers.len() < 2 {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
let mut names = vec![slint::SharedString::from("Auto")];
|
let mut names: Vec<Arc<str>> = vec!["Auto".into()];
|
||||||
names.extend(self.layers.iter().map(|l| layer_name(l).into()));
|
names.extend(self.layers.iter().map(|l| layer_name(l).into()));
|
||||||
names
|
names
|
||||||
}
|
}
|
||||||
@@ -184,17 +185,18 @@ impl App {
|
|||||||
pub(crate) fn stream_event(&mut self, event: Event) {
|
pub(crate) fn stream_event(&mut self, event: Event) {
|
||||||
match event {
|
match event {
|
||||||
Event::StreamsChanged { session, streams } => {
|
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.
|
// Development switch: watch the first stream that shows up.
|
||||||
let autowatch = std::env::var("VOELIN_AUTOWATCH").is_ok_and(|v| v == "1")
|
let autowatch = std::env::var("VOELIN_AUTOWATCH").is_ok_and(|v| v == "1")
|
||||||
&& self.watch.is_none()
|
&& self.watch.is_none()
|
||||||
&& self.current == Some(session as i64);
|
&& self.state.current == Some(session as i64);
|
||||||
let first = streams
|
let first = streams
|
||||||
.iter()
|
.iter()
|
||||||
.find(|s| view.state.own_client != Some(s.streamer))
|
.find(|s| view.state.own_client != Some(s.streamer))
|
||||||
.map(|s| s.id.clone());
|
.map(|s| s.id.clone());
|
||||||
// A client whose stream was asked for while it was looked up.
|
// A client whose stream was asked for while it was looked up.
|
||||||
let pending = self
|
let pending = self
|
||||||
|
.state
|
||||||
.pending_watch
|
.pending_watch
|
||||||
.filter(|(s, _)| *s == session as i64)
|
.filter(|(s, _)| *s == session as i64)
|
||||||
.and_then(|(_, client)| streams.iter().find(|s| s.streamer == client))
|
.and_then(|(_, client)| streams.iter().find(|s| s.streamer == client))
|
||||||
@@ -203,7 +205,7 @@ impl App {
|
|||||||
self.refresh_streams();
|
self.refresh_streams();
|
||||||
self.refresh_servers();
|
self.refresh_servers();
|
||||||
if let Some(id) = pending {
|
if let Some(id) = pending {
|
||||||
self.pending_watch = None;
|
self.state.pending_watch = None;
|
||||||
self.watch_stream(id);
|
self.watch_stream(id);
|
||||||
} else if autowatch && let Some(id) = first {
|
} else if autowatch && let Some(id) = first {
|
||||||
self.watch_stream(id);
|
self.watch_stream(id);
|
||||||
@@ -211,7 +213,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
Event::StreamState { session, state } => self.share_state(session as i64, state),
|
Event::StreamState { session, state } => self.share_state(session as i64, state),
|
||||||
Event::StreamViewerRequest { session, viewer, .. } => {
|
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"));
|
self.set_status(format!("{name} wants to watch your stream"));
|
||||||
}
|
}
|
||||||
Event::StreamViewers { session, viewers } => {
|
Event::StreamViewers { session, viewers } => {
|
||||||
@@ -252,7 +254,8 @@ impl App {
|
|||||||
StreamState::Ended(reason) => {
|
StreamState::Ended(reason) => {
|
||||||
let local = reason == EndReason::Local || share.stopping;
|
let local = reason == EndReason::Local || share.stopping;
|
||||||
self.share = None;
|
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 {
|
self.set_status(if local {
|
||||||
"You stopped sharing".into()
|
"You stopped sharing".into()
|
||||||
} else {
|
} else {
|
||||||
@@ -300,7 +303,7 @@ impl App {
|
|||||||
let Some(ui) = self.ui.upgrade() else { return };
|
let Some(ui) = self.ui.upgrade() else { return };
|
||||||
let bridge = ui.global::<Bridge>();
|
let bridge = ui.global::<Bridge>();
|
||||||
let view = self.view();
|
let view = self.view();
|
||||||
let current = self.current;
|
let current = self.state.current;
|
||||||
let mut items: Vec<StreamItem> = Vec::new();
|
let mut items: Vec<StreamItem> = Vec::new();
|
||||||
if let Some(view) = view.filter(|v| v.streams_available()) {
|
if let Some(view) = view.filter(|v| v.streams_available()) {
|
||||||
// Every channel's streams (they can be watched from anywhere),
|
// Every channel's streams (they can be watched from anywhere),
|
||||||
@@ -362,19 +365,19 @@ impl App {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
bridge.set_streams_available(self.demo || view.is_some_and(|v| v.streams_available()));
|
bridge.set_streams_available(self.demo || view.is_some_and(|v| v.streams_available()));
|
||||||
crate::vm::list::sync(&self.models.streams, &items);
|
self.models.streams.sync(&items);
|
||||||
bridge.set_can_share(video::AVAILABLE);
|
bridge.set_can_share(video::AVAILABLE);
|
||||||
|
|
||||||
let share = self.share.as_ref().filter(|s| Some(s.session) == current);
|
let share = self.share.as_ref().filter(|s| Some(s.session) == current);
|
||||||
let state = match share {
|
let state = match share {
|
||||||
Some(s) if s.live => "live",
|
Some(s) if s.live => "live",
|
||||||
Some(_) => "starting",
|
Some(_) => "starting",
|
||||||
None if self.share_busy => "starting",
|
None if self.state.share_busy => "starting",
|
||||||
None => "",
|
None => "",
|
||||||
};
|
};
|
||||||
bridge.set_share_state(state.into());
|
bridge.set_share_state(state.into());
|
||||||
bridge.set_share_busy(self.share_busy);
|
bridge.set_share_busy(self.state.share_busy);
|
||||||
bridge.set_share_error(self.share_error.clone().into());
|
bridge.set_share_error(self.state.share_error.clone().into());
|
||||||
bridge.set_share_audio(share.is_some_and(|s| s.capture.has_audio()));
|
bridge.set_share_audio(share.is_some_and(|s| s.capture.has_audio()));
|
||||||
let viewers: Vec<ViewerItem> = share
|
let viewers: Vec<ViewerItem> = share
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
@@ -397,13 +400,13 @@ impl App {
|
|||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let requests = viewers.iter().filter(|v| v.state == "requested").count();
|
let requests = viewers.iter().filter(|v| &*v.state == "requested").count();
|
||||||
bridge.set_share_requests(requests as i32);
|
bridge.set_share_requests(requests as i32);
|
||||||
crate::vm::list::sync(&self.models.viewers, &viewers);
|
self.models.viewers.sync(&viewers);
|
||||||
let status = match share {
|
let status = match share {
|
||||||
Some(s) if s.live => s.capture.status(),
|
Some(s) if s.live => s.capture.status(),
|
||||||
Some(s) => format!("Starting the stream of {}…", s.capture.source_name()),
|
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(),
|
None => String::new(),
|
||||||
};
|
};
|
||||||
bridge.set_share_status(status.into());
|
bridge.set_share_status(status.into());
|
||||||
@@ -437,7 +440,7 @@ impl App {
|
|||||||
// The watched stream's server, which the main window may have left
|
// The watched stream's server, which the main window may have left
|
||||||
// while the stream plays in its own.
|
// while the stream plays in its own.
|
||||||
let view = match watch.session {
|
let view = match watch.session {
|
||||||
Some(id) => self.sessions.get(&id),
|
Some(id) => self.state.sessions.get(&id),
|
||||||
None => self.view(),
|
None => self.view(),
|
||||||
};
|
};
|
||||||
let decoded = watch.decoder.as_ref().map(Decoder::info).unwrap_or_default();
|
let decoded = watch.decoder.as_ref().map(Decoder::info).unwrap_or_default();
|
||||||
@@ -455,10 +458,7 @@ impl App {
|
|||||||
);
|
);
|
||||||
// The members are the current server's.
|
// The members are the current server's.
|
||||||
let members = &self.models.members;
|
let members = &self.models.members;
|
||||||
let admin = self.watch_here()
|
let admin = self.watch_here() && members.rows().iter().any(|m| m.id == streamer && m.admin);
|
||||||
&& (0..members.row_count())
|
|
||||||
.filter_map(|i| members.row_data(i))
|
|
||||||
.any(|m| m.id == streamer && m.admin);
|
|
||||||
let channel = u16::try_from(streamer).ok().and_then(|id| {
|
let channel = u16::try_from(streamer).ok().and_then(|id| {
|
||||||
let view = view?;
|
let view = view?;
|
||||||
let channel = view.presence.channels.get(&view.channel_of(id)?)?;
|
let channel = view.presence.channels.get(&view.channel_of(id)?)?;
|
||||||
@@ -472,19 +472,19 @@ impl App {
|
|||||||
.layer
|
.layer
|
||||||
.and_then(|id| watch.layers.iter().position(|l| l.id == id))
|
.and_then(|id| watch.layers.iter().position(|l| l.id == id))
|
||||||
.map_or(0, |i| i as i32 + 1);
|
.map_or(0, |i| i as i32 + 1);
|
||||||
crate::vm::list::sync(&self.models.qualities, &qualities);
|
self.models.qualities.sync(&qualities);
|
||||||
self.viewer_each(|bridge| {
|
self.viewer_each(|bridge| {
|
||||||
bridge.set_viewer_popped(popped);
|
bridge.set_viewer_popped(popped);
|
||||||
bridge.set_viewer_title(watch.title.as_str().into());
|
bridge.set_viewer_title(watch.title.as_str().into());
|
||||||
bridge.set_viewer_status(watch.status.as_str().into());
|
bridge.set_viewer_status(watch.status.as_str().into());
|
||||||
bridge.set_viewer_ended(watch.ended);
|
bridge.set_viewer_ended(watch.ended);
|
||||||
bridge.set_viewer_has_frame(watch.has_frame);
|
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_info(info.as_str().into());
|
||||||
bridge.set_viewer_streamer(watch.streamer.as_str().into());
|
bridge.set_viewer_streamer(watch.streamer.as_str().into());
|
||||||
bridge.set_viewer_streamer_avatar(face.avatar.clone());
|
bridge.set_viewer_streamer_avatar(convert::image(&face.avatar));
|
||||||
bridge.set_viewer_streamer_initials(face.initials.clone());
|
bridge.set_viewer_streamer_initials(face.initials.as_ref().into());
|
||||||
bridge.set_viewer_streamer_tint(face.tint);
|
bridge.set_viewer_streamer_tint(convert::color(face.tint));
|
||||||
bridge.set_viewer_streamer_admin(admin);
|
bridge.set_viewer_streamer_admin(admin);
|
||||||
bridge.set_viewer_channel(channel.clone());
|
bridge.set_viewer_channel(channel.clone());
|
||||||
bridge.set_viewer_elapsed(elapsed.clone());
|
bridge.set_viewer_elapsed(elapsed.clone());
|
||||||
@@ -499,7 +499,7 @@ impl App {
|
|||||||
/// The watched stream is on the server on screen (or is the local test
|
/// The watched stream is on the server on screen (or is the local test
|
||||||
/// stream).
|
/// stream).
|
||||||
pub(crate) fn watch_here(&self) -> bool {
|
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
|
/// A simulcast layer of the watched stream (0: follow the bandwidth
|
||||||
@@ -543,7 +543,7 @@ impl App {
|
|||||||
if self.share.is_some() {
|
if self.share.is_some() {
|
||||||
self.refresh_streams();
|
self.refresh_streams();
|
||||||
}
|
}
|
||||||
// The share dialog's audio mixer (studio.rs).
|
// The share dialog's audio mixer (studio/).
|
||||||
self.mixer_tick();
|
self.mixer_tick();
|
||||||
if self.watch.is_some() {
|
if self.watch.is_some() {
|
||||||
self.refresh_viewer();
|
self.refresh_viewer();
|
||||||
@@ -557,16 +557,16 @@ impl App {
|
|||||||
let test_pattern = cfg!(debug_assertions)
|
let test_pattern = cfg!(debug_assertions)
|
||||||
|| self.demo
|
|| self.demo
|
||||||
|| std::env::var("VOELIN_TEST_PATTERN").is_ok_and(|v| v == "1");
|
|| 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) {
|
let sources = match self.video.sources(test_pattern, restorable) {
|
||||||
Ok(sources) => {
|
Ok(sources) => {
|
||||||
if self.share.is_none() {
|
if self.share.is_none() {
|
||||||
self.share_error.clear();
|
self.state.share_error.clear();
|
||||||
}
|
}
|
||||||
sources
|
sources
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.share_error = e;
|
self.state.share_error = e;
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -575,13 +575,14 @@ impl App {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(name, detail)| SourceItem { name: name.into(), detail: detail.into() })
|
.map(|(name, detail)| SourceItem { name: name.into(), detail: detail.into() })
|
||||||
.collect();
|
.collect();
|
||||||
ui.global::<Bridge>().set_share_sources(model(items));
|
ui.global::<Bridge>().set_share_sources(convert::model(&items));
|
||||||
}
|
}
|
||||||
self.refresh_streams();
|
self.refresh_streams();
|
||||||
// Its audio: the Stream Studio's mixer rows and picker.
|
// Its audio: the Stream Studio's mixer rows and picker.
|
||||||
self.mixer_show();
|
self.mixer_show();
|
||||||
let defaults = &self.settings.share;
|
let defaults = &self.state.settings.share;
|
||||||
let nickname = self.current.and_then(|id| self.bookmark(id)).map(|b| b.nickname.clone());
|
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));
|
let (fps, bitrate) = (self.prefs.get(&STREAM_FPS), self.prefs.get(&STREAM_BITRATE_KBPS));
|
||||||
ShareForm {
|
ShareForm {
|
||||||
source: 0,
|
source: 0,
|
||||||
@@ -630,12 +631,13 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn start_share(&mut self, form: ShareForm) {
|
pub(crate) fn start_share(&mut self, form: ShareForm) {
|
||||||
let Some(session) = self.current else { return };
|
let Some(session) = self.state.current else { return };
|
||||||
if self.share_busy || self.share.is_some() {
|
if self.state.share_busy || self.share.is_some() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if self.studio_streams_to(session) {
|
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();
|
self.refresh_streams();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -663,12 +665,12 @@ impl App {
|
|||||||
};
|
};
|
||||||
// The mixer's sources (the sample studio's with VOELIN_DEMO_UI).
|
// The mixer's sources (the sample studio's with VOELIN_DEMO_UI).
|
||||||
let sources = self.studio_settings().get(&STREAM_AUDIO_SOURCES);
|
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);
|
let request = capture_request(fps, bitrate, form.audio, &sources, token);
|
||||||
self.settings.share = defaults;
|
self.state.settings.share = defaults;
|
||||||
self.store_settings();
|
self.store_settings();
|
||||||
self.share_busy = true;
|
self.state.share_busy = true;
|
||||||
self.share_error.clear();
|
self.state.share_error.clear();
|
||||||
self.refresh_streams();
|
self.refresh_streams();
|
||||||
let setup = StreamSetup {
|
let setup = StreamSetup {
|
||||||
name: form.name.trim().to_owned(),
|
name: form.name.trim().to_owned(),
|
||||||
@@ -692,16 +694,16 @@ impl App {
|
|||||||
auto_accept: bool,
|
auto_accept: bool,
|
||||||
result: Result<Capture, String>,
|
result: Result<Capture, String>,
|
||||||
) {
|
) {
|
||||||
self.share_busy = false;
|
self.state.share_busy = false;
|
||||||
match result {
|
match result {
|
||||||
Err(e) => {
|
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) => {
|
Ok(capture) => {
|
||||||
if let Some(token) = capture.restore_token()
|
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();
|
self.store_settings();
|
||||||
}
|
}
|
||||||
if setup.bitrate == 0 {
|
if setup.bitrate == 0 {
|
||||||
@@ -753,7 +755,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The running share's streamer (the mixer's rows, studio.rs).
|
/// The running share's streamer (the mixer's rows, studio/).
|
||||||
pub(crate) fn share_streamer(&self) -> Option<&Streamer> {
|
pub(crate) fn share_streamer(&self) -> Option<&Streamer> {
|
||||||
self.share.as_ref().map(|s| s.capture.streamer())
|
self.share.as_ref().map(|s| s.capture.streamer())
|
||||||
}
|
}
|
||||||
@@ -793,8 +795,8 @@ impl App {
|
|||||||
self.start_demo();
|
self.start_demo();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let Some(session) = self.current else { return };
|
let Some(session) = self.state.current else { return };
|
||||||
let Some(view) = self.sessions.get(&session) 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 Some(info) = view.streams.iter().find(|s| s.id == stream_id) else { return };
|
||||||
let streamer = view.nickname(info.streamer);
|
let streamer = view.nickname(info.streamer);
|
||||||
let title =
|
let title =
|
||||||
@@ -803,11 +805,11 @@ impl App {
|
|||||||
self.stop_watching();
|
self.stop_watching();
|
||||||
self.engine
|
self.engine
|
||||||
.send(Command::WatchStream { session: session as u64, stream_id: stream_id.clone() });
|
.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 {
|
self.engine.send(Command::SetStreamVolume {
|
||||||
session: session as u64,
|
session: session as u64,
|
||||||
stream_id: stream_id.clone(),
|
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());
|
let wake = || later(|app| app.show_picture());
|
||||||
@@ -838,17 +840,17 @@ impl App {
|
|||||||
/// the lookup brings it (it may have started in another channel or
|
/// the lookup brings it (it may have started in another channel or
|
||||||
/// before we joined).
|
/// before we joined).
|
||||||
pub(crate) fn watch_client(&mut self, client: u16) {
|
pub(crate) fn watch_client(&mut self, client: u16) {
|
||||||
let Some(session) = self.current else { return };
|
let Some(session) = self.state.current else { return };
|
||||||
let Some(view) = self.sessions.get(&session) else { return };
|
let Some(view) = self.state.sessions.get(&session) else { return };
|
||||||
if view.state.own_client == Some(client) {
|
if view.state.own_client == Some(client) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Some(id) = view.streams.iter().find(|s| s.streamer == client).map(|s| s.id.clone()) {
|
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);
|
self.watch_stream(id);
|
||||||
} else if view.presence.clients.get(&client).is_some_and(|c| c.streaming == Some(true)) {
|
} else if view.presence.clients.get(&client).is_some_and(|c| c.streaming == Some(true)) {
|
||||||
let name = view.nickname(client);
|
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…"));
|
self.set_status(format!("Looking up {name}'s stream…"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -974,14 +976,14 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_stream_volume(&mut self, percent: f32) {
|
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
|
if let Some(watch) = &self.watch
|
||||||
&& let Some(session) = watch.session
|
&& let Some(session) = watch.session
|
||||||
{
|
{
|
||||||
self.engine.send(Command::SetStreamVolume {
|
self.engine.send(Command::SetStreamVolume {
|
||||||
session: session as u64,
|
session: session as u64,
|
||||||
stream_id: watch.stream_id.clone(),
|
stream_id: watch.stream_id.clone(),
|
||||||
volume: self.stream_volume / 100.0,
|
volume: self.state.stream_volume / 100.0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,103 @@
|
|||||||
|
//! The Stream Studio: the controller behind its page in the main window, its
|
||||||
|
//! window of its own and the phone layout (ui/screens/studio*.slint,
|
||||||
|
//! ui/studio-window.slint).
|
||||||
|
//!
|
||||||
|
//! The engine's studio (`voelin_core::studio`) composites the scenes; a
|
||||||
|
//! `Streamer` started for it encodes the composite from the start, so the
|
||||||
|
//! recording and the replay buffer need no live stream, and going live
|
||||||
|
//! attaches it to a TeamSpeak stream of our voice channel like any share.
|
||||||
|
//! The studio runs while it is shown, live or recording.
|
||||||
|
//!
|
||||||
|
//! Both windows' StudioBridge globals show the same models (shared
|
||||||
|
//! rows) and get the same values; their callbacks come here
|
||||||
|
//! (bind/studio.rs). Commands go to the studio through one task, in order.
|
||||||
|
//!
|
||||||
|
//! What the studio decides (where the stream goes, what the header says,
|
||||||
|
//! what the controls change) is `voelin_ui_vm::studio::logic`; `bind.rs` runs
|
||||||
|
//! the studio and puts the rows and values on the two windows.
|
||||||
|
|
||||||
|
mod bind;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
|
use slint::{Rgba8Pixel, SharedPixelBuffer};
|
||||||
|
use tokio::sync::mpsc;
|
||||||
|
use voelin_core::media::voelin_media::mix::SourceHandle;
|
||||||
|
use voelin_core::media::{AudioApps, Latest, Streamer};
|
||||||
|
use voelin_core::studio::scene::Source;
|
||||||
|
use voelin_core::studio::{self, Studio};
|
||||||
|
|
||||||
|
use crate::app::StudioWindow;
|
||||||
|
use crate::bind::rows::Rows;
|
||||||
|
use crate::vm;
|
||||||
|
use crate::vm::studio::Overlay;
|
||||||
|
use crate::vm::studio::logic::StudioData;
|
||||||
|
|
||||||
|
type Picture = SharedPixelBuffer<Rgba8Pixel>;
|
||||||
|
|
||||||
|
/// The models both windows show.
|
||||||
|
#[derive(Default)]
|
||||||
|
struct Models {
|
||||||
|
scenes: Rows<vm::studio_bridge::StudioScene>,
|
||||||
|
sources: Rows<vm::studio_bridge::StudioSource>,
|
||||||
|
audio: Rows<vm::studio_bridge::StudioAudio>,
|
||||||
|
layers: Rows<vm::studio_bridge::StudioLayer>,
|
||||||
|
viewers: Rows<vm::studio_bridge::StudioViewer>,
|
||||||
|
destinations: Rows<vm::studio_bridge::StudioPick>,
|
||||||
|
picks: Rows<vm::studio_bridge::StudioPick>,
|
||||||
|
/// The destination channel's chat (`studio_sync_chat`).
|
||||||
|
chat: Rows<vm::bridge::ChatLine>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A change of the scene graph, applied in order by one task.
|
||||||
|
enum Op {
|
||||||
|
Apply(studio::Command),
|
||||||
|
/// A source for the live scene (a new scene if there is none).
|
||||||
|
Add(Source),
|
||||||
|
/// Keep the overlay sources as asked.
|
||||||
|
Overlays(Vec<Overlay>),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A running studio.
|
||||||
|
struct Running {
|
||||||
|
studio: Arc<Studio>,
|
||||||
|
/// Encodes the composite; `None` until it started (or if it failed).
|
||||||
|
streamer: Option<Streamer>,
|
||||||
|
ops: mpsc::UnboundedSender<Op>,
|
||||||
|
/// The newest preview picture, for the UI thread.
|
||||||
|
pictures: Arc<Latest<Picture>>,
|
||||||
|
/// Stops the preview thread.
|
||||||
|
stop: Arc<AtomicBool>,
|
||||||
|
tasks: Vec<tokio::task::JoinHandle<()>>,
|
||||||
|
/// The mixer's meters, about 15 times a second.
|
||||||
|
_meters: slint::Timer,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for Running {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.stop.store(true, Ordering::Relaxed);
|
||||||
|
for task in &self.tasks {
|
||||||
|
task.abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The studio's state on the UI thread (`App::studio`).
|
||||||
|
#[derive(Default)]
|
||||||
|
pub(crate) struct StudioState {
|
||||||
|
models: Models,
|
||||||
|
/// The main window's globals have the models.
|
||||||
|
attached: bool,
|
||||||
|
/// The studio in a window of its own.
|
||||||
|
pub(crate) window: Option<StudioWindow>,
|
||||||
|
run: Option<Running>,
|
||||||
|
starting: bool,
|
||||||
|
/// What the studio knows apart from its running parts.
|
||||||
|
data: StudioData,
|
||||||
|
/// Applications that play audio, for the audio picker.
|
||||||
|
apps: Option<AudioApps>,
|
||||||
|
/// The mixer source of each audio row.
|
||||||
|
meters: Vec<Option<SourceHandle>>,
|
||||||
|
has_preview: bool,
|
||||||
|
}
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
//! Incremental model updates.
|
|
||||||
|
|
||||||
use slint::{Model, VecModel};
|
|
||||||
|
|
||||||
/// Row operations [`sync`] applied (for tests and tracing).
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
|
||||||
pub struct Changes {
|
|
||||||
pub set: usize,
|
|
||||||
pub inserted: usize,
|
|
||||||
pub removed: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Make `model` hold `new` with few row operations: the rows both share at
|
|
||||||
/// the start and the end stay, rows in between are changed in place where
|
|
||||||
/// they differ, and the rest inserted or removed. Views redraw only the
|
|
||||||
/// rows that changed (a client that starts talking is one `set_row_data`).
|
|
||||||
pub fn sync<T: Clone + PartialEq + 'static>(model: &VecModel<T>, new: &[T]) -> Changes {
|
|
||||||
let old_len = model.row_count();
|
|
||||||
let new_len = new.len();
|
|
||||||
let min = old_len.min(new_len);
|
|
||||||
let mut prefix = 0;
|
|
||||||
while prefix < min && model.row_data(prefix).as_ref() == Some(&new[prefix]) {
|
|
||||||
prefix += 1;
|
|
||||||
}
|
|
||||||
let mut suffix = 0;
|
|
||||||
while suffix < min - prefix
|
|
||||||
&& model.row_data(old_len - 1 - suffix).as_ref() == Some(&new[new_len - 1 - suffix])
|
|
||||||
{
|
|
||||||
suffix += 1;
|
|
||||||
}
|
|
||||||
let old_mid = old_len - prefix - suffix;
|
|
||||||
let new_mid = new_len - prefix - suffix;
|
|
||||||
let common = old_mid.min(new_mid);
|
|
||||||
let mut changes = Changes::default();
|
|
||||||
for (i, row) in new.iter().enumerate().skip(prefix).take(common) {
|
|
||||||
if model.row_data(i).as_ref() != Some(row) {
|
|
||||||
model.set_row_data(i, row.clone());
|
|
||||||
changes.set += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let at = prefix + common;
|
|
||||||
for _ in new_mid..old_mid {
|
|
||||||
model.remove(at);
|
|
||||||
changes.removed += 1;
|
|
||||||
}
|
|
||||||
for (k, row) in new[at..at + new_mid.saturating_sub(old_mid)].iter().enumerate() {
|
|
||||||
model.insert(at + k, row.clone());
|
|
||||||
changes.inserted += 1;
|
|
||||||
}
|
|
||||||
changes
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
fn run(old: &[i32], new: &[i32]) -> Changes {
|
|
||||||
let model = VecModel::from(old.to_vec());
|
|
||||||
let changes = sync(&model, new);
|
|
||||||
assert_eq!(model.iter().collect::<Vec<_>>(), new, "{old:?} -> {new:?}");
|
|
||||||
changes
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn minimal_changes() {
|
|
||||||
assert_eq!(run(&[1, 2, 3], &[1, 2, 3]), Changes::default());
|
|
||||||
assert_eq!(run(&[1, 2, 3], &[1, 9, 3]), Changes { set: 1, ..Default::default() });
|
|
||||||
assert_eq!(run(&[1, 2, 3], &[1, 2, 7, 3]), Changes { inserted: 1, ..Default::default() });
|
|
||||||
assert_eq!(run(&[1, 2, 3], &[1, 3]), Changes { removed: 1, ..Default::default() });
|
|
||||||
assert_eq!(run(&[], &[1, 2]), Changes { inserted: 2, ..Default::default() });
|
|
||||||
assert_eq!(run(&[1, 2], &[]), Changes { removed: 2, ..Default::default() });
|
|
||||||
assert_eq!(run(&[1, 2, 3, 4], &[5, 6]).set, 2);
|
|
||||||
run(&[1, 1, 1], &[1, 1]);
|
|
||||||
run(&[1, 2, 1], &[1, 1, 2, 1]);
|
|
||||||
run(&[4, 5, 6], &[1, 2, 3, 4, 5, 6, 7]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
//! View models: engine state turned into the Slint structs the screens
|
|
||||||
//! show. Pure functions (no window, no engine), unit-tested here; the
|
|
||||||
//! models live in `crate::models` and are updated row by row with
|
|
||||||
//! [`list::sync`], so a small change redraws only what changed.
|
|
||||||
|
|
||||||
pub mod avatar;
|
|
||||||
pub mod bbcode;
|
|
||||||
pub mod chat;
|
|
||||||
pub mod home;
|
|
||||||
pub mod list;
|
|
||||||
pub mod servers;
|
|
||||||
pub mod social;
|
|
||||||
pub mod streams;
|
|
||||||
pub mod studio;
|
|
||||||
pub mod tree;
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// The data Rust gives the UI and the callbacks it handles. Models are
|
// The data Rust gives the UI and the callbacks it handles. Models are
|
||||||
// VecModels that Rust updates row by row (src/vm/), so screens can bind to
|
// VecModels that Rust updates row by row (src/bind/rows.rs; the rows are made
|
||||||
// them freely.
|
// by crates/voelin-ui-vm), so screens can bind to them freely.
|
||||||
|
|
||||||
export struct ServerItem {
|
export struct ServerItem {
|
||||||
id: int,
|
id: int,
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
// The Stream Studio's data and callbacks (Rust: src/studio.rs, the view
|
// The Stream Studio's data and callbacks (Rust: src/studio/, the view models
|
||||||
// models in src/vm/studio.rs). The main window and the detached studio
|
// and decisions in crates/voelin-ui-vm/src/studio/). The main window and the
|
||||||
// window each have their own instance of these globals: Rust sets the same
|
// detached studio window each have their own instance of these globals: Rust
|
||||||
// models and values on both, and wires both to the same controller.
|
// sets the same models and values on both, and wires both to the same
|
||||||
|
// controller.
|
||||||
|
|
||||||
import { ChatLine } from "bridge.slint";
|
import { ChatLine } from "bridge.slint";
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,8 @@ fuzz/ cargo-fuzz targets
|
|||||||
| `voelin-audio` | Capture/playback, Opus, echo cancellation, resampling, jitter buffer, mixer, VAD/push-to-talk; the voice packet types (`TalkerId`, `VoicePacket`, `EncodedVoice`), so it depends on no voice transport | v0 (no AEC yet) |
|
| `voelin-audio` | Capture/playback, Opus, echo cancellation, resampling, jitter buffer, mixer, VAD/push-to-talk; the voice packet types (`TalkerId`, `VoicePacket`, `EncodedVoice`), so it depends on no voice transport | v0 (no AEC yet) |
|
||||||
| `voelin-stream` | TS6 stream commands, JSON signalling, str0m peer connections, host/STUN candidates, streamer/viewer sessions, frame-source seam; its frame and simulcast layer types are `voelin-media`'s | sessions + transport |
|
| `voelin-stream` | TS6 stream commands, JSON signalling, str0m peer connections, host/STUN candidates, streamer/viewer sessions, frame-source seam; its frame and simulcast layer types are `voelin-media`'s | sessions + transport |
|
||||||
| `voelin-core` | Engine: runtime, per-server sessions, merge of voice/gateway/query sources, the `ServerLink` seam the voice source sits behind (`link.rs`; `TsLink` is the TeamSpeak implementation, for now in this crate), event bus, command API, chat history, the gateway's features, audio settings and volumes, streams on TS6, files, avatar and icon cache, pokes, offline messages, contacts; `media` module (capture → encoder → stream, stream → decoder); the stream types of its API are its own (`stream_types`, see Streams) | done |
|
| `voelin-core` | Engine: runtime, per-server sessions, merge of voice/gateway/query sources, the `ServerLink` seam the voice source sits behind (`link.rs`; `TsLink` is the TeamSpeak implementation, for now in this crate), event bus, command API, chat history, the gateway's features, audio settings and volumes, streams on TS6, files, avatar and icon cache, pokes, offline messages, contacts; `media` module (capture → encoder → stream, stream → decoder); the stream types of its API are its own (`stream_types`, see Streams) | done |
|
||||||
| `voelin-ui` | Slint UI and the desktop binary: streams panel, viewer, share dialog, audio / hotkey / codec settings | done (desktop) |
|
| `voelin-ui-vm` | The view models, toolkit-free: engine state turned into plain rows and forms (servers, channel tree, chat with its BBCode reader, social, streams, the Stream Studio, the settings pages), the app's state (`AppState`, sessions and chat tabs), `ImageRef`/`Rgb`/`list::diff`, the Twemoji archive. Depends on `voelin-core`, `voelin-model`, `voelin-store`, `voelin-gateway-proto` and `voelin-audio`, on no UI toolkit; a front end converts its rows | done |
|
||||||
|
| `voelin-ui` | Slint UI and the desktop binary: streams panel, viewer, share dialog, audio / hotkey / codec settings; the Slint side of what `voelin-ui-vm` decides (the Bridge and model writes, windows, the engine's tasks) and the conversion of its rows into Slint values (see [ui.md](ui.md), "Two crates") | done (desktop) |
|
||||||
| `voelin-media` | Screen and system-audio capture backends (PipeWire portal, X11, Windows Graphics Capture, Android MediaProjection), video codecs; the frame and simulcast layer types of a stream (`stream::EncodedFrame`, `LayerSpec`, `LayerId`, `LayerSet`) | done (desktop hardware encoders through FFmpeg loaded at runtime, not run on a GPU yet; MediaCodec not run on a device yet) |
|
| `voelin-media` | Screen and system-audio capture backends (PipeWire portal, X11, Windows Graphics Capture, Android MediaProjection), video codecs; the frame and simulcast layer types of a stream (`stream::EncodedFrame`, `LayerSpec`, `LayerId`, `LayerSet`) | done (desktop hardware encoders through FFmpeg loaded at runtime, not run on a GPU yet; MediaCodec not run on a device yet) |
|
||||||
| `voelin-platform` | Global hotkeys, notifications, paths, crash reports, notices | done |
|
| `voelin-platform` | Global hotkeys, notifications, paths, crash reports, notices | done |
|
||||||
| `voelin-android` + `android/` | Android library + Gradle/Kotlin app (foreground services for voice and screen capture); see [android.md](android.md) | builds, not yet run on a device |
|
| `voelin-android` + `android/` | Android library + Gradle/Kotlin app (foreground services for voice and screen capture); see [android.md](android.md) | builds, not yet run on a device |
|
||||||
|
|||||||
+116
-25
@@ -4,14 +4,31 @@
|
|||||||
(`crates/voelin-android` runs the same window). It uses Slint's software
|
(`crates/voelin-android` runs the same window). It uses Slint's software
|
||||||
renderer, the Inter font, Lucide icons and Twemoji; the look follows the
|
renderer, the Inter font, Lucide icons and Twemoji; the look follows the
|
||||||
design mockups (deep navy panels, a blue accent, a server rail, a top bar, a
|
design mockups (deep navy panels, a blue accent, a server rail, a top bar, a
|
||||||
sidebar with the user card, an optional right panel).
|
sidebar with the user card, an optional right panel). What its screens show
|
||||||
|
is made by `crates/voelin-ui-vm`, which knows no UI toolkit ([Two
|
||||||
|
crates](#two-crates)).
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Structure
|
## Structure
|
||||||
|
|
||||||
```
|
```
|
||||||
crates/voelin-ui/
|
crates/voelin-ui-vm/ view models and state, no UI toolkit
|
||||||
|
assets/twemoji.bin the Twemoji SVGs packed by scripts/pack-twemoji.py
|
||||||
|
src/
|
||||||
|
image.rs color.rs ImageRef (a picture by where it comes from), Rgb
|
||||||
|
list.rs list::diff(old, new) → Changes (update, remove, insert by index)
|
||||||
|
bridge.rs the bridge structs as plain values (Arc<str>, ImageRef, Rgb, Vec)
|
||||||
|
studio_bridge.rs the same for the Stream Studio
|
||||||
|
state.rs AppState, SessionView, Tab, Msg: what the client knows apart from
|
||||||
|
the window, generic over the list type of a chat tab's lines
|
||||||
|
servers.rs tree.rs chat.rs social.rs home.rs streams.rs avatar.rs studio/mod.rs
|
||||||
|
pure view models (engine state → bridge structs), unit-tested
|
||||||
|
settings.rs the UI's settings keys, the audio form
|
||||||
|
settings_pages/logic.rs, studio/logic.rs
|
||||||
|
the decisions of the settings pages and of the Stream Studio
|
||||||
|
bbcode.rs emoji.rs chat formatting; the Twemoji archive, text → runs of text and emoji
|
||||||
|
crates/voelin-ui/ the Slint front end
|
||||||
ui/
|
ui/
|
||||||
app.slint MainWindow: picks the shell, puts the page's screens in it, dialogs
|
app.slint MainWindow: picks the shell, puts the page's screens in it, dialogs
|
||||||
theme.slint Theme global: design tokens (colours, radii, spacing, type)
|
theme.slint Theme global: design tokens (colours, radii, spacing, type)
|
||||||
@@ -35,28 +52,98 @@ crates/voelin-ui/
|
|||||||
studio-parts (the studio's pieces), studio (its page, its
|
studio-parts (the studio's pieces), studio (its page, its
|
||||||
phone layout)
|
phone layout)
|
||||||
assets/ fonts/ (Inter, OFL), icons/ (Lucide, ISC), logo.svg
|
assets/ fonts/ (Inter, OFL), icons/ (Lucide, ISC), logo.svg
|
||||||
assets/twemoji.bin the Twemoji SVGs packed by scripts/pack-twemoji.py
|
|
||||||
src/
|
src/
|
||||||
app.rs setup, App state, event dispatch
|
app.rs setup, the Slint models (`Models`), event dispatch; `App` holds
|
||||||
|
a `voelin_ui_vm::state::AppState` and the window
|
||||||
servers.rs chat.rs members.rs streams.rs settings_page.rs appearance.rs
|
servers.rs chat.rs members.rs streams.rs settings_page.rs appearance.rs
|
||||||
home.rs social.rs messages.rs events.rs settings_pages.rs previews.rs
|
home.rs social.rs messages.rs events.rs previews.rs popout.rs
|
||||||
studio.rs popout.rs the logic of each area (social.rs: contacts, the bell and the
|
the Slint side of each area (social.rs: contacts, the bell and the
|
||||||
search; previews.rs: pictures in chat; studio.rs: the Stream
|
search; previews.rs: pictures in chat; popout.rs: the stream's own
|
||||||
Studio's controller; popout.rs: the stream's own window)
|
window)
|
||||||
vm/ pure view models (engine state → Slint structs), unit-tested
|
settings_pages/ mod.rs (Pages), bind.rs: the settings pages on the Bridge
|
||||||
bind/ callbacks of each area, wired once
|
studio/ mod.rs (StudioState), bind.rs: the Stream Studio's windows and engine
|
||||||
|
bind/ callbacks of each area, wired once; convert.rs, convert/items.rs
|
||||||
|
(plain values → Slint values), rows.rs (a Slint model kept in step
|
||||||
|
with a plain list)
|
||||||
images.rs the image cache (LRU, bounded by `ui.image_cache_mb`)
|
images.rs the image cache (LRU, bounded by `ui.image_cache_mb`)
|
||||||
emoji.rs the Twemoji archive, text → runs of text and emoji
|
|
||||||
dev.rs development switches (screenshots, sample data)
|
dev.rs development switches (screenshots, sample data)
|
||||||
```
|
```
|
||||||
|
|
||||||
Models are created once (`app::Models`) and updated row by row with
|
Models are created once (`app::Models`) and updated row by row with
|
||||||
`vm::list::sync`, which keeps the rows shared at both ends and changes,
|
`bind::rows::Rows::sync`, which finds what changed with
|
||||||
|
`voelin_ui_vm::list::diff`, keeps the rows shared at both ends and changes,
|
||||||
inserts or removes the rest: a client that starts talking changes one row of
|
inserts or removes the rest: a client that starts talking changes one row of
|
||||||
the tree. Every chat tab owns a `VecModel` of its lines; the chat view shows
|
the tree. Every chat tab owns a `Rows` of its lines (`app::ChatRows`); the
|
||||||
the selected tab's model, so a new message is one `push` and switching tabs
|
chat view shows the selected tab's model, so a new message is one `push` and
|
||||||
swaps the model. Lists that can grow (channels, messages, notices, the emoji
|
switching tabs swaps the model. Lists that can grow (channels, messages,
|
||||||
grid) use `ListView`, which builds only the visible rows.
|
notices, the emoji grid) use `ListView`, which builds only the visible rows.
|
||||||
|
|
||||||
|
## Two crates
|
||||||
|
|
||||||
|
`voelin-ui-vm` turns engine state into rows and decides what the controls
|
||||||
|
change; it has no `slint` and no `gpui` in its dependency tree, and the
|
||||||
|
Slint crate imports it as `vm` (`use voelin_ui_vm as vm`), so `vm::chat` in
|
||||||
|
this file is `voelin_ui_vm::chat`. The boundary:
|
||||||
|
|
||||||
|
- **Values.** A picture is an `ImageRef` (`Arc<ImageSource>`: a file of the
|
||||||
|
engine's cache with its stamp, decoded RGBA pixels, SVG or memory bytes,
|
||||||
|
or none; `size()` reads a file's header). A colour is an `Rgb(u32)`, a
|
||||||
|
shared string an `Arc<str>`, a list a `Vec`. The bridge structs (51 in
|
||||||
|
`bridge.rs`, 10 in `studio_bridge.rs`) are plain `Clone + PartialEq + Debug`
|
||||||
|
structs with the field names of the Slint structs in `bridge.slint` and
|
||||||
|
`studio-bridge.slint`; `MytsBadge` and `MytsForm`, which have no data source
|
||||||
|
in this build, stay Slint-only.
|
||||||
|
- **Lists.** `list::diff(old, new)` gives `Changes`: updates, removals and
|
||||||
|
insertions by index, in the order to apply them. `bind/rows.rs` applies
|
||||||
|
them to a `VecModel` and converts only the changed rows; a GPUI view
|
||||||
|
re-renders from the list and needs no `Changes`.
|
||||||
|
- **Conversion.** The Slint crate owns the temporary `From` impls from the
|
||||||
|
plain structs to the Slint ones (`bind/convert/items.rs`), the colour,
|
||||||
|
picture and model helpers (`bind/convert.rs`) and the decoded-picture cache
|
||||||
|
(`images.rs`).
|
||||||
|
- **State.** `AppState<L>` (the servers, their sessions, the settings the
|
||||||
|
screens show, the dialogs' targets), `SessionView<L>` and `Tab<L>` live in
|
||||||
|
`voelin_ui_vm::state`, generic over the list type `L` of a chat tab's
|
||||||
|
lines: the Slint app plugs in `Rows<ChatLine>` (`app::ChatRows`), a front
|
||||||
|
end that re-renders can use a `Vec`. `App.state` is the one `AppState`.
|
||||||
|
- **Logic and bind.** An area that interleaves decisions with Bridge writes
|
||||||
|
is split into `<area>/logic.rs` in `voelin-ui-vm` (functions over the
|
||||||
|
settings service, the `AppState` and plain rows; they return rows,
|
||||||
|
commands or messages for the status line, and write no Bridge) and
|
||||||
|
`<area>/bind.rs` in `voelin-ui` (the Bridge and model writes, windows,
|
||||||
|
timers, threads, engine commands). Done: `settings_pages` and `studio`.
|
||||||
|
|
||||||
|
The pure code is tested in `voelin-ui-vm` (`cargo test -p voelin-ui-vm`,
|
||||||
|
no display); the Slint crate's tests are what needs the window types.
|
||||||
|
|
||||||
|
### Controllers still to split
|
||||||
|
|
||||||
|
Counted as `.set_` calls per file (`grep -c '\.set_'`, the status line's
|
||||||
|
`set_status` included) before this round's splits; Bridge writes alone are
|
||||||
|
about four fifths of each. Each one is a slice of the same shape as
|
||||||
|
`settings_pages` and `studio`: move the decisions into
|
||||||
|
`voelin-ui-vm/src/<area>/logic.rs`, keep the writes in
|
||||||
|
`voelin-ui/src/<area>/bind.rs`.
|
||||||
|
|
||||||
|
| File | `.set_` calls | What it mixes |
|
||||||
|
|---|---|---|
|
||||||
|
| `streams.rs` | 45 | the streams panel, viewer and share dialog: what the voice card, the viewer header and the share form say, with the watch and share bookkeeping |
|
||||||
|
| `chat.rs` | 38 | the chat view: lines, the unread divider, pins, topics and downloads, with the engine's history batches |
|
||||||
|
| `app.rs` | 38 | event dispatch and the status line, the toolbar and tree refreshes |
|
||||||
|
| `servers.rs` | 37 | the rail, the server dialog and the channel tree's refresh |
|
||||||
|
| `settings_page.rs` | 26 | the audio settings page and the devices |
|
||||||
|
| `social.rs` | 23 | home's contacts, the bell and the search |
|
||||||
|
| `dev.rs` | 23 | development switches and the sample data (the switches stay with the window; the sample rows can move) |
|
||||||
|
| `images.rs` | 13 | the decoded-picture cache |
|
||||||
|
| `messages.rs` | 12 | direct messages |
|
||||||
|
| `appearance.rs` | 11 | theme, font scale and breakpoints |
|
||||||
|
| `popout.rs` | 8 | the viewer's own window |
|
||||||
|
| `members.rs`, `links.rs`, `inbox.rs`, `home.rs`, `events.rs` | 6, 5, 5, 5, 4 | small; split with their neighbours |
|
||||||
|
|
||||||
|
Before this round: `studio.rs` had 62 and `settings_pages.rs` 52 (the two
|
||||||
|
with the most). Their `bind.rs` files still show 58 and 51 `.set_` calls: the
|
||||||
|
Bridge and model writes stay where the toolkit is, and what each write says
|
||||||
|
now comes from `logic.rs`, which has tests of its own.
|
||||||
|
|
||||||
## Theme tokens
|
## Theme tokens
|
||||||
|
|
||||||
@@ -275,7 +362,7 @@ The studio (mockups 09, 10 and the phone's 04) is a page of the main window
|
|||||||
window, "Stream Studio" for the studio; while a share runs the button opens
|
window, "Stream Studio" for the studio; while a share runs the button opens
|
||||||
its dialog), a window of its own (the button in its
|
its dialog), a window of its own (the button in its
|
||||||
header; closing that window brings it back) and a phone page. Its controller
|
header; closing that window brings it back) and a phone page. Its controller
|
||||||
is `src/studio.rs` on the engine's studio ([studio.md](studio.md)): the
|
is `src/studio/` on the engine's studio ([studio.md](studio.md)), its decisions in `voelin-ui-vm`'s `studio/logic.rs`: the
|
||||||
studio runs while it is shown, live or recording, and a `Streamer` started
|
studio runs while it is shown, live or recording, and a `Streamer` started
|
||||||
for it encodes the composite from the start, so Record Clip and recordings
|
for it encodes the composite from the start, so Record Clip and recordings
|
||||||
work before going live.
|
work before going live.
|
||||||
@@ -400,7 +487,7 @@ without joining; there is no Observe button. Without a gateway, observing
|
|||||||
starts once one is found.
|
starts once one is found.
|
||||||
|
|
||||||
Settings → Profiles (`ProfilesSection` in `screens/settings-pages.slint`;
|
Settings → Profiles (`ProfilesSection` in `screens/settings-pages.slint`;
|
||||||
`settings_pages.rs`, and `identities.rs` for the default and the import
|
`settings_pages/`, and `identities.rs` for the default and the import
|
||||||
switch) lists the stored identities with where they came from, marks the
|
switch) lists the stored identities with where they came from, marks the
|
||||||
store's default and has "Use as default" for the others, plus the switch
|
store's default and has "Use as default" for the others, plus the switch
|
||||||
for importing the official clients' identities on start
|
for importing the official clients' identities on start
|
||||||
@@ -420,10 +507,14 @@ for importing the official clients' identities on start
|
|||||||
`ui/app.slint` put its sidebar and main parts into `DesktopShell` under
|
`ui/app.slint` put its sidebar and main parts into `DesktopShell` under
|
||||||
`if Nav.page == Page.<name>:` (and a case in `MobileShell`). Dialogs go at
|
`if Nav.page == Page.<name>:` (and a case in `MobileShell`). Dialogs go at
|
||||||
the end of `MainWindow` with an `*-open` flag in `Nav`.
|
the end of `MainWindow` with an `*-open` flag in `Nav`.
|
||||||
4. Rust: a pure view model in `src/vm/<name>.rs` (with tests) that turns
|
4. Rust: a pure view model in `voelin-ui-vm/src/<name>.rs` (with tests) that
|
||||||
engine state into the structs; a model in `app::Models` set on the Bridge
|
turns engine state into the plain bridge structs (`bridge.rs`, with a
|
||||||
once and updated with `vm::list::sync`; callbacks in `src/bind/<name>.rs`
|
`From` impl for the Slint struct in `bind/convert/items.rs`); a model in
|
||||||
(call it from `bind::wire`); the logic as `impl App` in `src/<name>.rs`.
|
`app::Models` set on the Bridge once and updated with `Rows::sync`;
|
||||||
|
callbacks in `voelin-ui/src/bind/<name>.rs` (call it from `bind::wire`);
|
||||||
|
the Slint side as `impl App` in `voelin-ui/src/<name>.rs`, with the
|
||||||
|
decisions in the view-model crate (`<name>/logic.rs`, [Two
|
||||||
|
crates](#two-crates)).
|
||||||
5. A development switch to open it (`dev.rs`, `VOELIN_OPEN=<name>`), a
|
5. A development switch to open it (`dev.rs`, `VOELIN_OPEN=<name>`), a
|
||||||
screenshot (below) and a line in this file.
|
screenshot (below) and a line in this file.
|
||||||
|
|
||||||
@@ -453,8 +544,8 @@ In a config file write them as dotted keys at the top level
|
|||||||
|
|
||||||
The software renderer has no colour glyphs, so emoji are images. The 3720
|
The software renderer has no colour glyphs, so emoji are images. The 3720
|
||||||
Twemoji SVGs are packed by `scripts/pack-twemoji.py` into
|
Twemoji SVGs are packed by `scripts/pack-twemoji.py` into
|
||||||
`assets/twemoji.bin` (64 KiB blocks of raw deflate, an index sorted by key,
|
`crates/voelin-ui-vm/assets/twemoji.bin` (64 KiB blocks of raw deflate, an index sorted by key,
|
||||||
picker names and categories; 1.9 MB) and embedded in the binary. `emoji.rs`
|
picker names and categories; 1.9 MB) and embedded in the binary. `voelin-ui-vm`'s `emoji.rs`
|
||||||
splits chat text into grapheme clusters, maps emoji to Twemoji keys (code
|
splits chat text into grapheme clusters, maps emoji to Twemoji keys (code
|
||||||
points in hex; U+FE0F dropped outside ZWJ sequences, as Twemoji names its
|
points in hex; U+FE0F dropped outside ZWJ sequences, as Twemoji names its
|
||||||
files; text-default symbols such as © or digits only with U+FE0F) and makes
|
files; text-default symbols such as © or digits only with U+FE0F) and makes
|
||||||
@@ -471,7 +562,7 @@ code-point ranges) and searches Unicode names. There are no shortcodes yet.
|
|||||||
|
|
||||||
## Formatting
|
## Formatting
|
||||||
|
|
||||||
TeamSpeak clients format chat with BBCode. `vm/bbcode.rs` reads a message
|
TeamSpeak clients format chat with BBCode. `voelin-ui-vm/src/bbcode.rs` reads a message
|
||||||
into a `Doc`: blocks (lines, quote lines, code, list items, rules) of spans
|
into a `Doc`: blocks (lines, quote lines, code, list items, rules) of spans
|
||||||
with a style (bold, italic, underline, strike, code, colour, link) or a
|
with a style (bold, italic, underline, strike, code, colour, link) or a
|
||||||
picture. The Doc does not depend on BBCode, so Markdown (TeamSpeak 6) can be
|
picture. The Doc does not depend on BBCode, so Markdown (TeamSpeak 6) can be
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"""Pack the Twemoji SVGs into one compressed archive for the UI.
|
"""Pack the Twemoji SVGs into one compressed archive for the UI.
|
||||||
|
|
||||||
Colour emoji cannot go through the software renderer's text path, so the UI
|
Colour emoji cannot go through the software renderer's text path, so the UI
|
||||||
shows them as images: `crates/voelin-ui/src/emoji.rs` reads this archive
|
shows them as images: `crates/voelin-ui-vm/src/emoji.rs` reads this archive
|
||||||
(embedded in the binary) and decodes single emoji on demand.
|
(embedded in the binary) and decodes single emoji on demand.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
@@ -11,7 +11,7 @@ Usage:
|
|||||||
The package is @twemoji/svg (15.0.0: `npm pack @twemoji/svg`, unpacked); the
|
The package is @twemoji/svg (15.0.0: `npm pack @twemoji/svg`, unpacked); the
|
||||||
directory holds the SVGs named by code points (`1f600.svg`,
|
directory holds the SVGs named by code points (`1f600.svg`,
|
||||||
`1f468-200d-1f4bb.svg`). `out` defaults to
|
`1f468-200d-1f4bb.svg`). `out` defaults to
|
||||||
crates/voelin-ui/assets/twemoji.bin. Only the Python standard library is
|
crates/voelin-ui-vm/assets/twemoji.bin. Only the Python standard library is
|
||||||
needed; names come from its `unicodedata` plus a table for the emoji newer
|
needed; names come from its `unicodedata` plus a table for the emoji newer
|
||||||
than it (Unicode 15), so any Python 3.11+ gives the same file.
|
than it (Unicode 15), so any Python 3.11+ gives the same file.
|
||||||
|
|
||||||
@@ -247,7 +247,7 @@ def main():
|
|||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
src = sys.argv[1]
|
src = sys.argv[1]
|
||||||
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
out = sys.argv[2] if len(sys.argv) > 2 else os.path.join(root, "crates/voelin-ui/assets/twemoji.bin")
|
out = sys.argv[2] if len(sys.argv) > 2 else os.path.join(root, "crates/voelin-ui-vm/assets/twemoji.bin")
|
||||||
items = []
|
items = []
|
||||||
for file in os.listdir(src):
|
for file in os.listdir(src):
|
||||||
if not file.endswith(".svg"):
|
if not file.endswith(".svg"):
|
||||||
|
|||||||
Reference in new issue
Block a user