diff --git a/crates/voelin-ui/src/app.rs b/crates/voelin-ui/src/app.rs index 7d2456b..2b44e19 100644 --- a/crates/voelin-ui/src/app.rs +++ b/crates/voelin-ui/src/app.rs @@ -282,6 +282,7 @@ pub(crate) struct Models { pub servers: Rc>, pub tree: Rc>, pub members: Rc>, + pub server_members: Rc>, pub tabs: Rc>, pub streams: Rc>, pub viewers: Rc>, @@ -300,6 +301,7 @@ impl Models { servers: Rc::default(), tree: Rc::default(), members: Rc::default(), + server_members: Rc::default(), tabs: Rc::default(), streams: Rc::default(), viewers: Rc::default(), @@ -312,6 +314,7 @@ impl Models { bridge.set_servers(ModelRc::from(models.servers.clone())); bridge.set_tree(ModelRc::from(models.tree.clone())); bridge.set_members(ModelRc::from(models.members.clone())); + bridge.set_server_members(ModelRc::from(models.server_members.clone())); bridge.set_tabs(ModelRc::from(models.tabs.clone())); bridge.set_streams(ModelRc::from(models.streams.clone())); bridge.set_share_viewers(ModelRc::from(models.viewers.clone())); @@ -337,6 +340,13 @@ pub(crate) struct App { pub status: String, /// The top bar's search: filters the channel tree. pub tree_filter: 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, @@ -544,6 +554,9 @@ pub fn run(options: RunOptions) -> Result<()> { models, status: String::new(), tree_filter: String::new(), + member_filter: String::new(), + topic_filter: String::new(), + voice_view: false, prefs, settings, audio, @@ -801,6 +814,8 @@ impl App { Event::Groups { session, server_groups, .. } => { let view = self.sessions.entry(session as i64).or_default(); view.server_groups = (*server_groups).clone(); + // Display order, as TeamSpeak sorts them. + view.server_groups.sort_by_key(|g| (g.sort_id, g.id)); if self.current == Some(session as i64) { self.refresh_tree(); } diff --git a/crates/voelin-ui/src/bind/chat.rs b/crates/voelin-ui/src/bind/chat.rs index 88c7b39..54d1ecb 100644 --- a/crates/voelin-ui/src/bind/chat.rs +++ b/crates/voelin-ui/src/bind/chat.rs @@ -7,6 +7,9 @@ use crate::app::{App, Bridge, MainWindow, with_app}; pub(super) fn wire(ui: &MainWindow) { let bridge = ui.global::(); + bridge.on_search_topics(|text| { + with_app(|app| app.search_topics(text.to_string())); + }); bridge.on_open_channel_chat(|cid| { with_app(|app| app.open_chat(ChatTarget::Channel(cid as ChannelId), true)); }); diff --git a/crates/voelin-ui/src/bind/servers.rs b/crates/voelin-ui/src/bind/servers.rs index be9dc6a..a5100ce 100644 --- a/crates/voelin-ui/src/bind/servers.rs +++ b/crates/voelin-ui/src/bind/servers.rs @@ -14,6 +14,12 @@ pub(super) fn wire(ui: &MainWindow) { bridge.on_search(|text| { with_app(|app| app.search(text.to_string())); }); + bridge.on_search_members(|text| { + with_app(|app| app.search_members(text.to_string())); + }); + bridge.on_show_voice_view(|on| { + with_app(|app| app.show_voice_view(on)); + }); bridge.on_connect_voice(|| { with_app(|app| app.connect_voice()); }); diff --git a/crates/voelin-ui/src/chat.rs b/crates/voelin-ui/src/chat.rs index 0d4fab0..b2a8ba6 100644 --- a/crates/voelin-ui/src/chat.rs +++ b/crates/voelin-ui/src/chat.rs @@ -55,12 +55,6 @@ fn ago(ts_ms: i64) -> String { } } -fn time_of(ts_ms: i64) -> String { - chrono::DateTime::from_timestamp_millis(ts_ms) - .map(|t| t.with_timezone(&chrono::Local).format("%H:%M").to_string()) - .unwrap_or_default() -} - impl App { pub(crate) fn open_chat(&mut self, target: ChatTarget, focus: bool) { let Some(id) = self.current else { return }; @@ -396,25 +390,30 @@ impl App { }; PinItem { line: vm::chat::history_line(&p.message, None, &ctx), - by: format!("pinned by {} · {}", p.by, time_of(p.ts_ms)).into(), + by: format!("Pinned by {} · {}", p.by, vm::chat::time_of(p.ts_ms)).into(), } }) .collect(); vm::list::sync(&self.models.pins, &pins); + let filter = self.topic_filter.trim().to_lowercase(); + let now = chrono::Utc::now().timestamp_millis(); let topics: Vec = tab .topics .iter() + .filter(|t| filter.is_empty() || t.title.to_lowercase().contains(&filter)) .map(|t| crate::app::TopicItem { id: t.id as i32, title: t.title.clone().into(), creator: t.creator.name.clone().into(), detail: format!( - "{} {} · {}", + "{} {} · by {}", t.message_count, if t.message_count == 1 { "message" } else { "messages" }, - ago(t.last_activity_ms) + t.creator.name ) .into(), + activity: format!("Last active {}", ago(t.last_activity_ms)).into(), + recent: now - t.last_activity_ms < 3_600_000, archived: t.archived, }) .collect(); @@ -553,6 +552,14 @@ impl App { self.refresh_chat(); } + /// The topics drawer's search. + pub(crate) fn search_topics(&mut self, text: String) { + if self.topic_filter != text { + self.topic_filter = text; + self.refresh_chat(); + } + } + pub(crate) fn open_topics(&mut self) { let Some(view) = self.view() else { return }; let tab = &view.tabs[view.current_tab]; diff --git a/crates/voelin-ui/src/dev.rs b/crates/voelin-ui/src/dev.rs index 6d861c0..86ba1af 100644 --- a/crates/voelin-ui/src/dev.rs +++ b/crates/voelin-ui/src/dev.rs @@ -145,7 +145,7 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running { "panel" => nav.set_right_panel_open(true), "no-panel" => nav.set_right_panel_open(false), "tab" => nav.set_mobile_tab(mobile_tab(arg)), - "voice" => nav.set_voice_grid(true), + "voice" => nav.invoke_show_voice(true), "pins" => nav.invoke_show_pins(true), "topics" => nav.invoke_show_topics(true), "topic" => { diff --git a/crates/voelin-ui/src/servers.rs b/crates/voelin-ui/src/servers.rs index 3235e9e..d405f30 100644 --- a/crates/voelin-ui/src/servers.rs +++ b/crates/voelin-ui/src/servers.rs @@ -226,11 +226,15 @@ impl App { .into(), ); bridge.set_nickname(bookmark.map(|b| b.nickname.clone()).unwrap_or_default().into()); - let own_channel = view - .and_then(|v| state.own_channel.and_then(|c| v.presence.channels.get(&c))) - .map(|c| c.name.clone()) - .unwrap_or_default(); - bridge.set_own_channel(own_channel.into()); + let own_channel = + view.and_then(|v| state.own_channel.and_then(|c| v.presence.channels.get(&c))); + bridge.set_own_channel(own_channel.map(|c| c.name.clone()).unwrap_or_default().into()); + bridge.set_own_channel_topic( + own_channel.and_then(|c| c.topic.clone()).unwrap_or_default().into(), + ); + bridge.set_own_channel_limit( + own_channel.and_then(|c| c.max_clients).filter(|m| *m >= 0).unwrap_or(-1), + ); bridge.set_voice_connected(state.voice == VoiceState::Connected); bridge.set_voice_connecting(state.voice == VoiceState::Connecting); bridge.set_observing(state.observe != ObserveState::Off); @@ -255,11 +259,13 @@ impl App { } } - /// The channel tree and the members of our channel. + /// The channel tree, the members of our channel and everyone on the + /// server. pub(crate) fn refresh_tree(&self) { let Some(view) = self.view() else { vm::list::sync(&self.models.tree, &[]); vm::list::sync(&self.models.members, &[]); + vm::list::sync(&self.models.server_members, &[]); return; }; let input = vm::tree::TreeInput { @@ -275,12 +281,39 @@ impl App { groups: &view.server_groups, }; vm::list::sync(&self.models.tree, &vm::tree::rows(&input)); - let members = if view.state.voice == VoiceState::Connected { - vm::tree::members(&input) - } else { - Vec::new() - }; + let connected = view.state.voice == VoiceState::Connected; + let members = if connected { vm::tree::members(&input) } else { Vec::new() }; vm::list::sync(&self.models.members, &members); + // The people in our channel first while their view is shown. + let watching = self.watch.as_ref().is_some_and(|w| w.shown); + let voice_first = connected && (self.voice_view || watching); + let everyone = vm::tree::server_members(&input, voice_first); + let filter = self.member_filter.trim().to_lowercase(); + let shown = + if filter.is_empty() { everyone } else { vm::tree::matching(everyone, &filter) }; + vm::list::sync(&self.models.server_members, &shown); + if let Some(ui) = self.ui.upgrade() { + let total = view.presence.clients.values().filter(|c| !c.is_query).count(); + ui.global::().set_member_total(total as i32); + } + } + + /// The members panel's search. + pub(crate) fn search_members(&mut self, text: String) { + if self.member_filter != text { + self.member_filter = text; + self.refresh_tree(); + } + } + + /// The voice channel view was opened or closed: its chat is our + /// channel's, and its people lead the members panel. + pub(crate) fn show_voice_view(&mut self, on: bool) { + self.voice_view = on; + if on && let Some(channel) = self.view().and_then(|v| v.state.own_channel) { + self.open_chat(voelin_model::ChatTarget::Channel(channel), true); + } + self.refresh_tree(); } pub(crate) fn toggle_collapse(&mut self, channel: u64) { diff --git a/crates/voelin-ui/src/streams.rs b/crates/voelin-ui/src/streams.rs index 73aba54..99f2310 100644 --- a/crates/voelin-ui/src/streams.rs +++ b/crates/voelin-ui/src/streams.rs @@ -7,7 +7,7 @@ use tracing::warn; use voelin_core::media::audio_source_specs; use voelin_core::settings::{STREAM_AUDIO_SOURCES, STREAM_BITRATE_KBPS, STREAM_FPS}; use voelin_core::stream::{ - EndReason, LayerId, LayerSpec, LeaveReason, StreamSetup, ViewerInfo, ViewerState, + EndReason, LayerId, LayerSpec, LeaveReason, StreamKind, StreamSetup, ViewerInfo, ViewerState, }; use voelin_core::{Command, Event, StreamState, WatchState}; @@ -42,7 +42,7 @@ pub(crate) struct Watch { ended: bool, has_frame: bool, /// Shown instead of the chat. - shown: bool, + pub(crate) shown: bool, decoder: Option, /// When the picture started, for the elapsed time. since: Option, @@ -105,6 +105,16 @@ fn share_end_text(reason: &EndReason) -> String { } } +/// "8 Mbit/s", "640 kbit/s" (the stream's announced bitrate, kbit/s); "" for 0. +fn bitrate_text(kbps: u32) -> String { + match kbps { + 0 => String::new(), + 1..=999 => format!("{kbps} kbit/s"), + _ if kbps.is_multiple_of(1000) => format!("{} Mbit/s", kbps / 1000), + _ => format!("{:.1} Mbit/s", f64::from(kbps) / 1000.0), + } +} + impl App { pub(crate) fn stream_event(&mut self, event: Event) { match event { @@ -216,9 +226,18 @@ impl App { id: s.id.clone().into(), name: s.name.clone().into(), streamer: view.nickname(s.streamer.0).into(), + streamer_id: i32::from(s.streamer.0), audio: s.audio, watching, own: view.state.own_client == Some(s.streamer.0), + kind: match s.kind { + StreamKind::Screen => "Screen", + StreamKind::Window => "Window", + StreamKind::Camera => "Camera", + StreamKind::Other(_) => "", + } + .into(), + bitrate: bitrate_text(s.bitrate).into(), }); } // Streams that started before we joined: the server did not @@ -235,6 +254,7 @@ impl App { items.push(StreamItem { name: c.nickname.clone().into(), streamer: c.nickname.clone().into(), + streamer_id: i32::from(c.id), ..StreamItem::default() }); } @@ -248,6 +268,7 @@ impl App { audio: false, watching: self.watch.as_ref().is_some_and(|w| w.session.is_none() && !w.ended), own: false, + ..StreamItem::default() }); } bridge.set_streams_available(self.demo || view.is_some_and(|v| v.streams_available())); @@ -601,6 +622,8 @@ impl App { }); self.refresh_viewer(); self.refresh_streams(); + // The people in our channel lead the members panel beside the viewer. + self.refresh_tree(); } /// `VOELIN_OPEN=watch`: watch the first stream of our channel. @@ -651,6 +674,8 @@ impl App { }); self.refresh_viewer(); self.refresh_streams(); + // The people in our channel lead the members panel beside the viewer. + self.refresh_tree(); } /// A decoded picture is waiting. @@ -681,6 +706,8 @@ impl App { } self.refresh_viewer(); self.refresh_streams(); + // The people in our channel lead the members panel beside the viewer. + self.refresh_tree(); } /// Stop watching and close the viewer. @@ -695,6 +722,8 @@ impl App { self.set_fullscreen(false); self.refresh_viewer(); self.refresh_streams(); + // The people in our channel lead the members panel beside the viewer. + self.refresh_tree(); } pub(crate) fn set_stream_volume(&mut self, percent: f32) { @@ -726,3 +755,14 @@ impl App { ui.window().set_fullscreen(full); } } + +#[cfg(test)] +mod tests { + #[test] + fn bitrates() { + assert_eq!(super::bitrate_text(0), ""); + assert_eq!(super::bitrate_text(640), "640 kbit/s"); + assert_eq!(super::bitrate_text(8000), "8 Mbit/s"); + assert_eq!(super::bitrate_text(4608), "4.6 Mbit/s"); + } +} diff --git a/crates/voelin-ui/src/vm/chat.rs b/crates/voelin-ui/src/vm/chat.rs index f60d832..10daedb 100644 --- a/crates/voelin-ui/src/vm/chat.rs +++ b/crates/voelin-ui/src/vm/chat.rs @@ -49,12 +49,29 @@ pub struct LineCtx { pub downloads: Vec<(usize, FileItem)>, } -fn time_of(ts_ms: i64) -> String { +/// When a message was sent, for its header (see [`stamp`]). +pub fn time_of(ts_ms: i64) -> String { chrono::DateTime::from_timestamp_millis(ts_ms) - .map(|t| t.with_timezone(&chrono::Local).format("%H:%M").to_string()) + .map(|t| { + stamp(t.with_timezone(&chrono::Local).naive_local(), chrono::Local::now().naive_local()) + }) .unwrap_or_default() } +/// "Today at 10:14", "Yesterday at 10:14", "12 Mar at 10:14", and the year +/// when it is not this one. +pub fn stamp(then: chrono::NaiveDateTime, now: chrono::NaiveDateTime) -> String { + use chrono::Datelike; + let time = then.format("%H:%M"); + let days = (now.date() - then.date()).num_days(); + match days { + 0 => format!("Today at {time}"), + 1 => format!("Yesterday at {time}"), + _ if then.year() == now.year() => format!("{} at {time}", then.format("%-d %b")), + _ => format!("{} at {time}", then.format("%-d %b %Y")), + } +} + /// "2.4 MB", "912 kB", "48 B". pub fn size_text(bytes: u64) -> String { const UNITS: [(u64, &str); 3] = [(1 << 30, "GB"), (1 << 20, "MB"), (1 << 10, "kB")]; @@ -272,6 +289,16 @@ mod tests { assert!(line.text.starts_with("here you go")); } + #[test] + fn stamps() { + let at = |d: &str| chrono::NaiveDateTime::parse_from_str(d, "%Y-%m-%d %H:%M").unwrap(); + let now = at("2026-10-03 09:00"); + assert_eq!(stamp(at("2026-10-03 08:05"), now), "Today at 08:05"); + assert_eq!(stamp(at("2026-10-02 23:59"), now), "Yesterday at 23:59"); + assert_eq!(stamp(at("2026-03-12 10:14"), now), "12 Mar at 10:14"); + assert_eq!(stamp(at("2025-12-31 10:14"), now), "31 Dec 2025 at 10:14"); + } + #[test] fn sizes() { assert_eq!(size_text(48), "48 B"); diff --git a/crates/voelin-ui/src/vm/tree.rs b/crates/voelin-ui/src/vm/tree.rs index 0d79ae5..bac0197 100644 --- a/crates/voelin-ui/src/vm/tree.rs +++ b/crates/voelin-ui/src/vm/tree.rs @@ -1,4 +1,5 @@ -//! The channel tree and the members of our channel. +//! The channel tree, the members of our channel and everyone on the +//! server for the members panel. use std::collections::{HashMap, HashSet}; use std::path::PathBuf; @@ -147,58 +148,166 @@ pub fn stats(p: &Presence) -> String { /// admins). TeamSpeak has no flag for it, so the usual names are matched. fn is_admin_group(name: &str) -> bool { let lower = name.to_lowercase(); - ["admin", "owner", "operator", "moderator", "leiter"].iter().any(|w| lower.contains(w)) + ["admin", "owner", "operator", "leiter"].iter().any(|w| lower.contains(w)) +} + +/// Moderator groups, shown as a role next to the name. +fn is_moderator_group(name: &str) -> bool { + name.to_lowercase().contains("mod") +} + +impl TreeInput<'_> { + /// The position of a client's group in display order (no group last). + fn group_rank(&self, client: &ClientInfo) -> usize { + self.groups.iter().position(|g| client.server_groups.contains(&g.id)).unwrap_or(usize::MAX) + } + + /// One row of the members panel or the voice channel, under `section`. + fn member(&self, c: &ClientInfo, section: &Section) -> MemberItem { + let talking = talking(self, c); + let group = self.group_of(c).map_or("", |g| g.name.as_str()); + let admin = is_admin_group(group); + // Someone elsewhere on the server: where they are says more than + // "Listening". + let elsewhere = self.own_channel != Some(c.channel) + && !talking + && c.streaming != Some(true) + && c.away.is_none(); + let status = match self.presence.channels.get(&c.channel) { + Some(channel) if elsewhere => format!("In {}", channel.name), + _ => status_of(c, talking), + }; + MemberItem { + id: c.id as i32, + name: c.nickname.clone().into(), + initials: avatar::initials(&c.nickname).into(), + tint: avatar::tint(&c.nickname), + avatar: self.avatar(c), + talking, + muted: c.input_muted, + sound_off: c.output_muted, + away: c.away.is_some(), + streaming: c.streaming == Some(true), + myself: self.own_client == Some(c.id), + status: status.into(), + away_message: c.away.clone().unwrap_or_default().into(), + group: section.title.clone().into(), + group_icon: section.icon.clone(), + first_in_group: false, + group_count: 0, + admin, + role: if !admin && is_moderator_group(group) { group.into() } else { "".into() }, + priority: c.priority_speaker, + commander: c.channel_commander, + recording: c.recording, + talk_power: c.talk_power, + } + } +} + +/// A heading of the members panel. +#[derive(Clone, Default)] +struct Section { + title: String, + icon: slint::Image, +} + +/// Rows in sections: each section's first row carries the heading and how +/// many rows follow. +fn sectioned( + input: &TreeInput, + mut clients: Vec<(Section, usize, &ClientInfo)>, +) -> Vec { + clients.sort_by_key(|(_, rank, c)| (*rank, c.nickname.to_lowercase(), c.id)); + let mut rows: Vec = clients.iter().map(|(s, _, c)| input.member(c, s)).collect(); + let mut start = 0; + while start < rows.len() { + let rank = clients[start].1; + let count = clients[start..].iter().take_while(|(_, r, _)| *r == rank).count(); + rows[start].first_in_group = true; + rows[start].group_count = count as i32; + start += count; + } + rows +} + +/// The section of a client's server group. +fn group_section(input: &TreeInput, client: &ClientInfo) -> (Section, usize) { + match input.group_of(client) { + Some(g) => ( + Section { + title: g.name.clone(), + icon: avatar::image( + Some(g.icon).filter(|i| *i != 0).and_then(|i| input.icons.get(&i)), + ), + }, + 1 + input.group_rank(client), + ), + None => (Section { title: "Online".into(), ..Default::default() }, usize::MAX), + } } /// The clients in our channel, grouped by server group (in the server's /// display order) and by name inside a group. pub fn members(input: &TreeInput) -> Vec { let Some(channel) = input.own_channel else { return Vec::new() }; - let mut clients: Vec<&ClientInfo> = input.presence.members(channel).collect(); - clients.sort_by_key(|c| { - let group = input.group_of(c); - ( - group.map_or(i32::MAX, |g| g.sort_id), - group.map_or(String::new(), |g| g.name.clone()), - c.nickname.to_lowercase(), - ) - }); - let mut previous: Option = None; - clients - .into_iter() + let clients = input + .presence + .members(channel) .map(|c| { - let talking = talking(input, c); - let group = input.group_of(c); - let name = group.map(|g| g.name.clone()).unwrap_or_default(); - let first = previous.as_deref() != Some(name.as_str()); - previous = Some(name.clone()); - MemberItem { - id: c.id as i32, - name: c.nickname.clone().into(), - initials: avatar::initials(&c.nickname).into(), - tint: avatar::tint(&c.nickname), - avatar: input.avatar(c), - talking, - muted: c.input_muted, - sound_off: c.output_muted, - away: c.away.is_some(), - streaming: c.streaming == Some(true), - myself: input.own_client == Some(c.id), - status: status_of(c, talking).into(), - away_message: c.away.clone().unwrap_or_default().into(), - group: name.into(), - group_icon: avatar::image( - group.map(|g| g.icon).filter(|i| *i != 0).and_then(|i| input.icons.get(&i)), - ), - first_in_group: first, - admin: group.is_some_and(|g| is_admin_group(&g.name)), - priority: c.priority_speaker, - commander: c.channel_commander, - recording: c.recording, - talk_power: c.talk_power, + let (section, rank) = group_section(input, c); + (section, rank, c) + }) + .collect(); + sectioned(input, clients) +} + +/// The rows whose name contains `filter` (lower case), in sections +/// counted again. +pub fn matching(rows: Vec, filter: &str) -> Vec { + let mut rows: Vec = + rows.into_iter().filter(|m| m.name.to_lowercase().contains(filter)).collect(); + let mut start = 0; + while start < rows.len() { + let group = rows[start].group.clone(); + let count = rows[start..].iter().take_while(|m| m.group == group).count(); + for (i, row) in rows[start..start + count].iter_mut().enumerate() { + row.first_in_group = i == 0; + row.group_count = if i == 0 { count as i32 } else { 0 }; + } + start += count; + } + rows +} + +/// Everyone on the server for the members panel: first the people in our +/// voice channel (`voice_first`, in the voice channel and stream views) or +/// those streaming, then each server group in the server's order. +pub fn server_members(input: &TreeInput, voice_first: bool) -> Vec { + let first = Section { + title: if voice_first { "In Voice" } else { "Streaming" }.into(), + icon: slint::Image::default(), + }; + let clients = input + .presence + .clients + .values() + .filter(|c| !c.is_query) + .map(|c| { + let lead = if voice_first { + input.own_channel == Some(c.channel) + } else { + c.streaming == Some(true) + }; + if lead { + (first.clone(), 0, c) + } else { + let (section, rank) = group_section(input, c); + (section, rank, c) } }) - .collect() + .collect(); + sectioned(input, clients) } #[cfg(test)] @@ -328,4 +437,64 @@ mod tests { assert_eq!(rows, [("Carol", "Server Admin", true), ("bob", "Guest", true)]); assert!(members[0].admin && !members[1].admin); } + + #[test] + fn everyone_in_sections() { + let mut p = presence(); + p.clients.get_mut(&10).unwrap().server_groups = vec![7]; + p.clients.get_mut(&12).unwrap().server_groups = vec![7]; + p.clients.get_mut(&12).unwrap().streaming = Some(true); + p.clients.get_mut(&11).unwrap().server_groups = vec![6]; + let group = |id, sort_id, name: &str| GroupInfo { + id, + name: name.into(), + icon: 0, + sort_id, + ..Default::default() + }; + let e = Extras { + groups: vec![group(6, 10, "Moderator"), group(7, 20, "Guest")], + ..Default::default() + }; + let (t, c, pb) = (HashSet::new(), HashSet::new(), ClientPlaybackMap::new()); + let rows = |voice_first| { + server_members(&input(&p, &t, &c, &pb, "", &e), voice_first) + .iter() + .map(|m| { + ( + m.name.to_string(), + m.first_in_group.then(|| format!("{} — {}", m.group, m.group_count)), + m.status.to_string(), + ) + }) + .collect::>() + }; + let row = |name: &str, head: Option<&str>, status: &str| { + (name.to_owned(), head.map(str::to_owned), status.to_owned()) + }; + // The query client is left out; people elsewhere show their channel. + assert_eq!( + rows(false), + [ + row("Carol", Some("Streaming — 1"), "Streaming"), + row("bob", Some("Moderator — 1"), "Listening"), + row("Alice", Some("Guest — 1"), "In Lobby"), + ] + ); + assert_eq!( + rows(true), + [ + row("bob", Some("In Voice — 1"), "Listening"), + row("Alice", Some("Guest — 2"), "In Lobby"), + row("Carol", None, "Streaming"), + ] + ); + let all = server_members(&input(&p, &t, &c, &pb, "", &e), false); + assert_eq!(all[1].role, "Moderator"); + assert!(!all[1].admin); + // The search keeps the sections of what it finds. + let found = matching(all, "al"); + assert_eq!(found.len(), 1); + assert!(found[0].first_in_group && found[0].group == "Guest" && found[0].group_count == 1); + } } diff --git a/crates/voelin-ui/ui/app.slint b/crates/voelin-ui/ui/app.slint index 3b94cdb..fafa48e 100644 --- a/crates/voelin-ui/ui/app.slint +++ b/crates/voelin-ui/ui/app.slint @@ -20,8 +20,9 @@ import { Panel } from "shells/common.slint"; import { ServerHeader, ConnectActions, ChannelTree } from "screens/channels.slint"; import { ChatView } from "screens/chat.slint"; import { PinsDrawer, TopicsDrawer, TopicDialog } from "screens/drawers.slint"; -import { MemberCardPopup, VoiceGrid } from "screens/members.slint"; -import { StreamsPanel, StreamViewer } from "screens/streams.slint"; +import { MemberCardPopup, MembersPanel } from "screens/members.slint"; +import { VoiceView } from "screens/voice.slint"; +import { StreamViewer } from "screens/streams.slint"; import { SettingsNav, SettingsPage } from "screens/settings.slint"; import { HomeNav, HomePage } from "screens/home.slint"; import { MobileServers, ActivityPage, YouPage } from "screens/mobile.slint"; @@ -82,6 +83,9 @@ export component MainWindow inherits Window { property status: Bridge.status-text; changed status => { toast.shown = status != ""; } + // The right column: members, pins or topics. + property side-panel: Nav.right-panel-open || Nav.pins-open || Nav.topics-open; + // Dragging the members panel stores its width (`ui.members_width`). property panel-width: Nav.right-panel-width; changed panel-width => { Bridge.panel-resized(panel-width / 1px); } @@ -129,34 +133,22 @@ export component MainWindow inherits Window { if Nav.page == Page.server: Panel { horizontal-stretch: 1; if Bridge.viewer-open: StreamViewer { } - if !Bridge.viewer-open && Nav.voice-grid && Bridge.voice-connected: VoiceGrid { } - if !Bridge.viewer-open && !(Nav.voice-grid && Bridge.voice-connected): ChatView { } - // The pins and the topics slide in over the chat. - if !Bridge.viewer-open && (Nav.pins-open || Nav.topics-open): Rectangle { - x: parent.width - self.width - 12px; - y: 12px; - width: min(parent.width - 24px, 400px); - height: parent.height - 24px; - if Nav.pins-open: PinsDrawer { - width: parent.width; - height: parent.height; - } - if Nav.topics-open: TopicsDrawer { - width: parent.width; - height: parent.height; - } - } + if !Bridge.viewer-open && Nav.voice-view && Bridge.voice-connected: VoiceView { } + if !Bridge.viewer-open && !(Nav.voice-view && Bridge.voice-connected): ChatView { } } - if Nav.page == Page.server && Nav.right-panel-open: ResizeHandle { + // The members panel, or the pins or the topics in its place. + if Nav.page == Page.server && root.side-panel: ResizeHandle { size <=> Nav.right-panel-width; minimum: Theme.right-panel-min; maximum: Theme.right-panel-max; left: false; } - if Nav.page == Page.server && Nav.right-panel-open: Panel { + if Nav.page == Page.server && root.side-panel: Panel { width: Nav.right-panel-width; horizontal-stretch: 0; - StreamsPanel { } + if Nav.pins-open: PinsDrawer { } + if Nav.topics-open && !Nav.pins-open: TopicsDrawer { } + if !Nav.pins-open && !Nav.topics-open: MembersPanel { } } if Nav.page == Page.settings: Sidebar { SettingsNav { } @@ -205,7 +197,7 @@ export component MainWindow inherits Window { clicked => { Bridge.open-member(-1); } } MemberCardPopup { - x: max(8px, parent.width - self.width - (Nav.narrow ? 8px : Nav.right-panel-open && Nav.page == Page.server ? Nav.right-panel-width + 24px : 32px)); + x: max(8px, parent.width - self.width - (Nav.narrow ? 8px : root.side-panel && Nav.page == Page.server ? Nav.right-panel-width + 24px : 32px)); y: max(8px, min(parent.height - self.height - 8px, 120px)); } } @@ -216,7 +208,7 @@ export component MainWindow inherits Window { clicked => { Nav.emoji-open = false; } } EmojiPicker { - x: max(8px, parent.width - self.width - (Nav.narrow ? 8px : Nav.right-panel-open && Nav.page == Page.server ? Nav.right-panel-width + 40px : 32px)); + x: max(8px, parent.width - self.width - (Nav.narrow ? 8px : root.side-panel && Nav.page == Page.server ? Nav.right-panel-width + 40px : 32px)); y: max(8px, parent.height - self.height - (Nav.narrow ? 150px : 90px)); // Picked for a message: a reaction; otherwise the composer. picked(cell) => { diff --git a/crates/voelin-ui/ui/assets/icons/book-open.svg b/crates/voelin-ui/ui/assets/icons/book-open.svg new file mode 100644 index 0000000..0cfe3ab --- /dev/null +++ b/crates/voelin-ui/ui/assets/icons/book-open.svg @@ -0,0 +1,16 @@ + + + + + diff --git a/crates/voelin-ui/ui/bridge.slint b/crates/voelin-ui/ui/bridge.slint index fd97c71..eef0105 100644 --- a/crates/voelin-ui/ui/bridge.slint +++ b/crates/voelin-ui/ui/bridge.slint @@ -46,7 +46,8 @@ export struct TreeItem { max-members: int, } -// A client in our channel, for the members panel and the voice grid. +// A client for the members panel (everyone on the server) and the voice +// channel view (our channel). export struct MemberItem { id: int, name: string, @@ -63,13 +64,18 @@ export struct MemberItem { status: string, // The away message, empty without one. away-message: string, - // The server group the row is sorted under, and its icon. + // The section the row is in (a server group, "In Voice", + // "Streaming"), and the group's icon. group: string, group-icon: image, - // The first row of its group draws the group header. + // The first row of its section draws the heading, with the number of + // rows in the section. first-in-group: bool, + group-count: int, // Badges: a crown for the server's admin groups. admin: bool, + // A moderator group's name, shown as a role next to the name. + role: string, priority: bool, commander: bool, recording: bool, @@ -190,8 +196,11 @@ export struct TopicItem { id: int, title: string, creator: string, - // "12 messages · 3 min ago" + // "12 messages · by Nova" detail: string, + // "Last active 3 min ago", and whether that was within the hour. + activity: string, + recent: bool, archived: bool, } @@ -214,7 +223,12 @@ export struct StreamItem { id: string, name: string, streamer: string, + // The streamer's client id (their avatar in the members). + streamer-id: int, audio: bool, + // "Screen", "Window", "Camera"; and the announced bitrate ("8 Mbit/s"). + kind: string, + bitrate: string, // Shown in the viewer. watching: bool, // Our own stream. @@ -295,6 +309,10 @@ export global Bridge { in property <[TreeItem]> tree; // Clients in our channel. in property <[MemberItem]> members; + // Everyone on the server, in sections, for the members panel. + in property <[MemberItem]> server-members; + // How many people are on the server (not counting query clients). + in property member-total; in property <[ChatTab]> tabs; in-out property current-tab: 0; in property <[ChatLine]> messages; @@ -327,6 +345,9 @@ export global Bridge { // Our nickname on the current server, and the channel we are in. in property nickname; in property own-channel; + // Its topic, and how many people it takes (-1: no limit). + in property own-channel-topic; + in property own-channel-limit: -1; in property voice-connected; in property voice-connecting; in property observing; @@ -465,6 +486,12 @@ export global Bridge { callback appearance-changed(AppearanceForm); // The members panel was dragged to another width (pixels). callback panel-resized(float); + // The voice channel view was opened or closed. + callback show-voice-view(bool); + // The members panel's search field. + callback search-members(string); + // The topics drawer's search field. + callback search-topics(string); callback open-client(int) -> bool; callback client-audio-changed(ClientAudio); callback set-crash-reports(bool); diff --git a/crates/voelin-ui/ui/components/button.slint b/crates/voelin-ui/ui/components/button.slint index f988021..493e66d 100644 --- a/crates/voelin-ui/ui/components/button.slint +++ b/crates/voelin-ui/ui/components/button.slint @@ -46,11 +46,12 @@ export component Button inherits Rectangle { property fill: kind == ButtonKind.primary ? (active ? Theme.accent-pressed : touch.has-hover ? Theme.accent-hover : Theme.accent) : kind == ButtonKind.danger ? (active ? Theme.danger : touch.has-hover ? Theme.danger-soft.brighter(0.3) : Theme.danger-soft) : kind == ButtonKind.ghost ? (active ? Theme.surface-4 : touch.has-hover ? Theme.surface-3 : transparent) + : checked ? (touch.has-hover ? Theme.accent-soft-hover : Theme.accent-soft) : (active ? Theme.surface-4 : touch.has-hover ? Theme.surface-3 : Theme.surface-2); property ink: kind == ButtonKind.primary ? Theme.on-accent : !enabled ? Theme.text-disabled : kind == ButtonKind.danger ? (active ? Theme.on-accent : Theme.danger) - : checked ? Theme.accent-text : Theme.text; + : Theme.text; min-width: self.min-height; min-height: small ? Theme.control-height-sm : Theme.control-height; diff --git a/crates/voelin-ui/ui/icons.slint b/crates/voelin-ui/ui/icons.slint index 8bc4ac5..60ea2ca 100644 --- a/crates/voelin-ui/ui/icons.slint +++ b/crates/voelin-ui/ui/icons.slint @@ -10,6 +10,7 @@ export global Icons { out property at-sign: @image-url("assets/icons/at-sign.svg"); out property audio-lines: @image-url("assets/icons/audio-lines.svg"); out property bell: @image-url("assets/icons/bell.svg"); + out property book-open: @image-url("assets/icons/book-open.svg"); out property bookmark: @image-url("assets/icons/bookmark.svg"); out property calendar: @image-url("assets/icons/calendar.svg"); out property camera: @image-url("assets/icons/camera.svg"); diff --git a/crates/voelin-ui/ui/nav.slint b/crates/voelin-ui/ui/nav.slint index b87c549..27055cc 100644 --- a/crates/voelin-ui/ui/nav.slint +++ b/crates/voelin-ui/ui/nav.slint @@ -42,9 +42,10 @@ export global Nav { in-out property right-panel-width: 280px; // Incremented to focus the search field (Ctrl+K). in-out property search-requests; - // The voice channel's grid instead of the chat. - in-out property voice-grid: false; - // Drawers over the chat (gateway features). + // The voice channel we are in (people, streams, its chat) instead of + // the plain chat. + in-out property voice-view: false; + // Drawers in place of the members panel (gateway features). in-out property pins-open; in-out property topics-open; // The message the emoji picker reacts to; 0: it fills the composer. @@ -133,6 +134,24 @@ export global Nav { } } + // The members button: back from a drawer, or the panel on and off. + public function toggle-members() { + if pins-open || topics-open { + pins-open = false; + topics-open = false; + right-panel-open = true; + } else { + right-panel-open = !right-panel-open; + } + } + + // The voice channel view, or back to the chat (Rust opens the + // channel's chat and puts the people in it first in the panel). + public function show-voice(on: bool) { + voice-view = on; + Bridge.show-voice-view(on); + } + public function start-topic(key: int) { topic-form-key = key; topic-form-title = ""; diff --git a/crates/voelin-ui/ui/screens/chat.slint b/crates/voelin-ui/ui/screens/chat.slint index 994e582..a761942 100644 --- a/crates/voelin-ui/ui/screens/chat.slint +++ b/crates/voelin-ui/ui/screens/chat.slint @@ -6,7 +6,7 @@ import { Theme } from "../theme.slint"; import { Icons } from "../icons.slint"; import { Bridge, ChatLine, ReactionItem, FileItem, Images } from "../bridge.slint"; import { Nav } from "../nav.slint"; -import { Icon, IconButton, Avatar, Chip, TabItem, TextField, RichText, Banner, Button, ButtonKind, Spinner, Tooltip, SpeakingBars, ListView } from "../components/index.slint"; +import { Icon, IconButton, Avatar, Chip, TabItem, TextField, RichText, Banner, Button, ButtonKind, Spinner, Tooltip, ListView } from "../components/index.slint"; // The header of the main area: an icon, a title and a description, and // actions (@children) at the right. @@ -58,186 +58,101 @@ export component PageHeader inherits Rectangle { } } -// The voice connection as one strip: where we are, who talks, and the -// controls. Shown over the chat while voice is connected. -export component VoiceBar inherits Rectangle { - height: 46px; - background: Theme.surface-2.transparentize(0.25); - accessible-role: AccessibleRole.groupbox; - accessible-label: @tr("Voice"); - Rectangle { - y: parent.height - 1px; - height: 1px; - background: Theme.border; - } - HorizontalLayout { - padding-left: Theme.space-5; - padding-right: Theme.space-3; - spacing: Theme.space-3; - Rectangle { - width: 8px; - height: 8px; - y: (parent.height - self.height) / 2; - border-radius: 4px; - background: Bridge.voice-connected ? Theme.success : Theme.warning; - } - VerticalLayout { - alignment: center; - Text { - text: Bridge.voice-connected ? @tr("Voice connected") : @tr("Connecting…"); - color: Bridge.voice-connected ? Theme.success : Theme.warning; - font-size: Theme.font-xs; - font-weight: Theme.weight-semibold; - } - Text { - text: Bridge.own-channel != "" ? Bridge.own-channel + " / " + Bridge.server-title : Bridge.server-title; - color: Theme.text-muted; - font-size: Theme.font-xs; - overflow: elide; - } - } - // Who is talking right now. - Rectangle { - horizontal-stretch: 1; - HorizontalLayout { - alignment: start; - padding-left: Theme.space-3; - spacing: -6px; - for member in Bridge.members: Rectangle { - width: member.talking ? 28px : 0px; - visible: member.talking; - Avatar { - size: 26px; - initials: member.initials; - tint: member.tint; - image: member.avatar; - speaking: true; - label: member.name; - } - } - } - } - if Bridge.transmitting: VerticalLayout { - alignment: center; - SpeakingBars { } - } - IconButton { - icon: Bridge.input-muted ? Icons.mic-off : Icons.mic; - label: Bridge.input-muted ? @tr("Microphone off") : @tr("Microphone on"); - checked: Bridge.input-muted; - danger: true; - size: 32px; - icon-size: Theme.icon-sm; - y: (parent.height - self.height) / 2; - clicked => { Bridge.set-input-muted(!Bridge.input-muted); } - } - IconButton { - icon: Bridge.output-muted ? Icons.headphone-off : Icons.headphones; - label: Bridge.output-muted ? @tr("Sound off") : @tr("Sound on"); - checked: Bridge.output-muted; - danger: true; - size: 32px; - icon-size: Theme.icon-sm; - y: (parent.height - self.height) / 2; - clicked => { Bridge.set-output-muted(!Bridge.output-muted); } - } - if Bridge.streams-available && Bridge.can-share: IconButton { - icon: Icons.monitor-up; - label: Bridge.share-state == "live" ? @tr("Sharing") : @tr("Share screen"); - checked: Bridge.share-state == "live"; - size: 32px; - icon-size: Theme.icon-sm; - y: (parent.height - self.height) / 2; - clicked => { Nav.open-share(); } - } - IconButton { - icon: Icons.layout-grid; - label: @tr("Voice channel"); - checked: Nav.voice-grid; - size: 32px; - icon-size: Theme.icon-sm; - y: (parent.height - self.height) / 2; - clicked => { Nav.voice-grid = !Nav.voice-grid; } - } - IconButton { - icon: Icons.phone-off; - label: @tr("Disconnect"); - size: 32px; - icon-size: Theme.icon-sm; - tint: Theme.danger; - y: (parent.height - self.height) / 2; - clicked => { Bridge.disconnect-voice(); } - } - } -} - -// The emoji under a message; clicking one adds or removes ours. -component Reactions inherits HorizontalLayout { +// The emoji under a message; clicking one adds or removes ours, the last +// pill picks another. +export component Reactions inherits HorizontalLayout { in property key; in property <[ReactionItem]> model; - spacing: Theme.space-2; + spacing: Theme.space-3; alignment: start; for reaction in root.model: Rectangle { - width: pill.preferred-width + 16px; - height: 24px; + width: pill.preferred-width + 22px; + height: 30px; border-radius: Theme.radius-pill; - background: reaction.me ? Theme.accent-soft : Theme.surface-2; + background: reaction.me ? Theme.accent-soft : area.has-hover ? Theme.surface-3 : Theme.surface-2; border-width: 1px; - border-color: reaction.me ? Theme.accent : Theme.border; + border-color: reaction.me ? Theme.accent : Theme.border-strong; accessible-role: AccessibleRole.button; accessible-label: @tr("{} reacted {} times", reaction.text, reaction.count); accessible-checkable: true; accessible-checked: reaction.me; accessible-action-default => { Bridge.react(root.key, reaction.text); } - TouchArea { + area := TouchArea { mouse-cursor: MouseCursor.pointer; clicked => { Bridge.react(root.key, reaction.text); } } pill := HorizontalLayout { - spacing: Theme.space-2; + spacing: Theme.space-3; alignment: center; if reaction.key != "": Image { - width: 15px; - height: 15px; + width: 18px; + height: 18px; source: Images.emoji(reaction.key); y: (parent.height - self.height) / 2; } if reaction.key == "": Text { text: reaction.text; - font-size: Theme.font-sm; + font-size: Theme.font-body; vertical-alignment: center; } Text { text: reaction.count; color: reaction.me ? Theme.accent-text : Theme.text-secondary; - font-size: Theme.font-xs; + font-size: Theme.font-sm; font-weight: Theme.weight-semibold; vertical-alignment: center; } } } + if Bridge.has-reactions: Rectangle { + width: 40px; + height: 30px; + border-radius: Theme.radius-pill; + background: add.has-hover ? Theme.surface-3 : Theme.surface-2; + border-width: 1px; + border-color: Theme.border-strong; + accessible-role: AccessibleRole.button; + accessible-label: @tr("Add a reaction"); + accessible-action-default => { + Nav.react-key = root.key; + Nav.emoji-open = true; + } + Icon { + source: Icons.smile-plus; + size: 18px; + tint: Theme.text-secondary; + } + add := TouchArea { + mouse-cursor: MouseCursor.pointer; + clicked => { + Nav.react-key = root.key; + Nav.emoji-open = true; + } + } + } } // A file a message links: name, size or progress, and a download button. component FileCard inherits Rectangle { in property key; in property file; - height: 56px; - border-radius: Theme.radius-md; + height: 64px; + border-radius: Theme.radius-lg; background: Theme.surface-2; border-width: 1px; - border-color: file.state == "failed" ? Theme.danger : Theme.border; + border-color: file.state == "failed" ? Theme.danger : Theme.border-strong; accessible-role: AccessibleRole.groupbox; accessible-label: file.name; HorizontalLayout { padding: Theme.space-3; - spacing: Theme.space-3; + padding-left: Theme.space-4; + spacing: Theme.space-4; Rectangle { - width: 34px; - height: 34px; + width: 40px; + height: 40px; y: (parent.height - self.height) / 2; - border-radius: Theme.radius-sm; - background: Theme.accent-soft; + border-radius: 20px; + background: Theme.surface-4; Icon { source: file.picture ? Icons.image : Icons.file-text; size: Theme.icon-md; @@ -251,13 +166,14 @@ component FileCard inherits Rectangle { Text { text: file.name; color: Theme.text; + font-size: Theme.font-md; font-weight: Theme.weight-medium; overflow: elide; } Text { text: file.detail; - color: file.state == "failed" ? Theme.danger : Theme.text-muted; - font-size: Theme.font-xs; + color: file.state == "failed" ? Theme.danger : Theme.text-secondary; + font-size: Theme.font-sm; overflow: elide; } if file.state == "running": Rectangle { @@ -351,7 +267,7 @@ export component MessageRow inherits Rectangle { in property line; // The pins and topic lists show messages without their actions. in property actions: true; - property avatar: 40px; + property avatar: 44px; min-height: body.preferred-height; background: line.marked ? Theme.accent-soft : hover.has-hover ? Theme.surface-2.transparentize(0.6) : transparent; accessible-role: AccessibleRole.list-item; @@ -364,8 +280,8 @@ export component MessageRow inherits Rectangle { body := HorizontalLayout { padding-left: Theme.space-6; padding-right: Theme.space-6; - padding-top: line.continued ? 1px : Theme.space-4; - padding-bottom: 1px; + padding-top: line.continued ? 2px : Theme.space-5; + padding-bottom: 2px; spacing: Theme.space-4; VerticalLayout { width: root.avatar; @@ -387,14 +303,14 @@ export component MessageRow inherits Rectangle { Text { text: line.author; color: line.relayed ? Theme.accent-text : Theme.name-text; - font-size: Theme.font-md; - font-weight: Theme.weight-semibold; + font-size: Theme.font-lg; + font-weight: Theme.weight-medium; vertical-alignment: center; } Text { text: line.time; color: Theme.text-muted; - font-size: Theme.font-xs; + font-size: Theme.font-sm; vertical-alignment: center; } if line.relayed: Chip { @@ -425,11 +341,13 @@ export component MessageRow inherits Rectangle { if !line.blocked && !line.rich && line.text != "": Text { text: line.text; color: Theme.text; + font-size: Theme.font-md; wrap: word-wrap; } if !line.blocked && line.rich: RichText { runs: line.runs; - emoji-size: line.jumbo ? 44px : Theme.font-body * 1.4; + font-size: Theme.font-md; + emoji-size: line.jumbo ? 44px : Theme.font-md * 1.4; } if line.files.length > 0 && !line.blocked: VerticalLayout { padding-top: Theme.space-2; @@ -438,7 +356,7 @@ export component MessageRow inherits Rectangle { for file in line.files: FileCard { key: line.key; file: file; - max-width: 420px; + max-width: 440px; } } if line.reactions.length > 0: VerticalLayout { @@ -460,7 +378,7 @@ export component MessageRow inherits Rectangle { } // The messages of the current chat (or of an open topic). -component MessageList inherits VerticalLayout { +export component MessageList inherits VerticalLayout { in property <[ChatLine]> model; in property older; if Bridge.local-history: Rectangle { @@ -508,31 +426,36 @@ component MessageList inherits VerticalLayout { } } -// The composer: emoji, attachment and the text field. -component Composer inherits HorizontalLayout { +// The composer: a round attach button, the text field with the emoji +// picker and send. +export component Composer inherits HorizontalLayout { in property placeholder; in property topic; padding: Theme.space-4; padding-left: Theme.space-5; padding-right: Theme.space-5; spacing: Theme.space-3; + // Files go to the channel's file browser and a link into the chat. + if !root.topic: IconButton { + icon: Icons.plus; + label: @tr("Attach a file"); + round: true; + filled: true; + size: 44px; + y: (parent.height - self.height) / 2; + clicked => { Bridge.attach-file(); } + } Rectangle { horizontal-stretch: 1; min-height: 48px; border-radius: Theme.radius-lg; background: Theme.surface-2; border-width: 1px; - border-color: input.has-focus ? Theme.accent : Theme.border; + border-color: input.has-focus ? Theme.accent : Theme.border-strong; HorizontalLayout { - padding-left: Theme.space-3; + padding-left: Theme.space-5; padding-right: Theme.space-2; spacing: Theme.space-2; - IconButton { - icon: Icons.paperclip; - label: @tr("Attach a file"); - y: (parent.height - self.height) / 2; - clicked => { Bridge.attach-file(); } - } input := TextField { text <=> Nav.draft; bare: true; @@ -564,7 +487,7 @@ component Composer inherits HorizontalLayout { label: @tr("Send"); round: true; enabled: input.text != ""; - tint: input.text != "" ? Theme.on-accent : Theme.text-muted; + tint: input.text != "" ? Theme.on-accent : Theme.accent-text; filled: input.text != ""; y: (parent.height - self.height) / 2; clicked => { @@ -595,39 +518,41 @@ export component ChatView inherits VerticalLayout { icon: root.tab-kind == 1 ? Icons.hash : root.tab-kind == 2 ? Icons.at-sign : Icons.message-square; title: root.tab-name; description: root.tab-topic != "" ? root.tab-topic : Bridge.server-title; - if Bridge.presence-source != "": Chip { + // Only when the chat does not come through our voice connection + // (an invisible observer or a relay). + if Bridge.presence-source != "" && !Bridge.voice-connected: Chip { text: Bridge.presence-source; icon: Icons.radio; tint: Theme.accent-text; y: (parent.height - self.height) / 2; } - if Bridge.has-pins: IconButton { + if Bridge.has-pins: Button { icon: Icons.pin; - label: @tr("Pinned messages"); + text: @tr("Pinned Messages"); checked: Nav.pins-open; y: (parent.height - self.height) / 2; clicked => { Nav.show-pins(!Nav.pins-open); } } - if Bridge.has-topics: IconButton { - icon: Icons.messages-square; - label: @tr("Topics"); + if Bridge.has-topics: Button { + icon: Icons.book-open; + text: @tr("Topics"); checked: Nav.topics-open; y: (parent.height - self.height) / 2; clicked => { Nav.show-topics(!Nav.topics-open); } } - if !Bridge.viewer-open && !Nav.right-panel-open && Bridge.streams.length > 0: Button { - small: true; - icon: Icons.monitor-up; - text: @tr("Streams ({})", Bridge.streams.length); + // The voice channel we are in, with the people and the streams. + if Bridge.voice-connected: IconButton { + icon: Icons.volume-2; + label: @tr("Voice channel"); y: (parent.height - self.height) / 2; - clicked => { Nav.right-panel-open = true; } + clicked => { Nav.show-voice(true); } } IconButton { icon: Icons.users; - label: @tr("Members and streams"); - checked: Nav.right-panel-open; + label: @tr("Members"); + checked: Nav.right-panel-open && !Nav.pins-open && !Nav.topics-open; y: (parent.height - self.height) / 2; - clicked => { Nav.right-panel-open = !Nav.right-panel-open; } + clicked => { Nav.toggle-members(); } } } if Bridge.crash-notice != "": Rectangle { @@ -683,7 +608,6 @@ export component ChatView inherits VerticalLayout { } } } - if Bridge.voice-connected || Bridge.voice-connecting: VoiceBar { } // The open topic replaces the chat. if Bridge.current-topic >= 0: Rectangle { height: 44px; diff --git a/crates/voelin-ui/ui/screens/drawers.slint b/crates/voelin-ui/ui/screens/drawers.slint index dfbcdaf..e51bdcb 100644 --- a/crates/voelin-ui/ui/screens/drawers.slint +++ b/crates/voelin-ui/ui/screens/drawers.slint @@ -1,74 +1,161 @@ -// Drawers that slide over the chat: the pinned messages and the topics -// (threads). Both need a gateway; the chat header hides their buttons when -// the gateway does not offer them. +// The pinned messages and the topics (threads) of the current chat. They +// take the place of the members panel; both need a gateway, and the chat +// header hides their buttons when the gateway does not offer them. import { Theme } from "../theme.slint"; import { Icons } from "../icons.slint"; -import { Bridge, TopicItem } from "../bridge.slint"; +import { Bridge, PinItem, TopicItem, Images } from "../bridge.slint"; import { Nav } from "../nav.slint"; -import { Icon, IconButton, Button, ButtonKind, TextField, Spinner, Modal, ListView } from "../components/index.slint"; -import { MessageRow } from "chat.slint"; +import { Icon, IconButton, Button, ButtonKind, TextField, SearchBox, Avatar, RichText, Spinner, Modal, ListView } from "../components/index.slint"; +import { Reactions } from "chat.slint"; -// The frame both drawers share: a title bar and the content (@children). -component Drawer inherits Rectangle { +// The title row both drawers share, above their content (@children). +component Drawer inherits VerticalLayout { in property title; in property icon; - in property count; callback closed(); - background: Theme.surface; - border-width: 1px; - border-color: Theme.border-strong; - border-radius: Theme.radius-lg; - clip: true; + padding-top: Theme.space-4; + spacing: Theme.space-3; accessible-role: AccessibleRole.groupbox; accessible-label: title; - VerticalLayout { - Rectangle { - height: 52px; - background: Theme.surface-2; - Rectangle { - y: parent.height - 1px; - height: 1px; - background: Theme.border; + HorizontalLayout { + padding-left: Theme.space-5; + padding-right: Theme.space-3; + spacing: Theme.space-3; + if root.icon.width > 0: Icon { + source: root.icon; + size: Theme.icon-md; + tint: Theme.accent-text; + y: (parent.height - self.height) / 2; + } + Text { + text: root.title; + color: Theme.text; + font-size: Theme.font-lg; + font-weight: Theme.weight-semibold; + vertical-alignment: center; + horizontal-stretch: 1; + overflow: elide; + } + IconButton { + icon: Icons.x; + label: @tr("Close"); + size: 32px; + icon-size: Theme.icon-md; + y: (parent.height - self.height) / 2; + clicked => { root.closed(); } + } + } + @children +} + +// A pinned message as a card: who and when, the pin (unpin), the text and +// its reactions. Clicking the card jumps to the message in the chat. +component PinCard inherits Rectangle { + in property pin; + min-height: body.preferred-height; + border-radius: Theme.radius-lg; + background: area.has-hover ? Theme.surface-3 : Theme.surface-2; + border-width: 1px; + border-color: Theme.border-strong; + accessible-role: AccessibleRole.list-item; + accessible-label: pin.line.author + ": " + pin.line.text; + accessible-description: pin.by; + accessible-action-default => { + Bridge.jump-to-pin(pin.line.key); + Nav.pins-open = false; + } + area := TouchArea { + mouse-cursor: MouseCursor.pointer; + clicked => { + Bridge.jump-to-pin(pin.line.key); + Nav.pins-open = false; + } + } + body := VerticalLayout { + padding: Theme.space-4; + padding-right: Theme.space-3; + spacing: Theme.space-2; + HorizontalLayout { + spacing: Theme.space-3; + Avatar { + size: 28px; + initials: pin.line.initials; + tint: pin.line.tint; + image: pin.line.avatar; + label: pin.line.author; + y: (parent.height - self.height) / 2; } - HorizontalLayout { - padding-left: Theme.space-5; - padding-right: Theme.space-3; - spacing: Theme.space-3; - Icon { - source: root.icon; - size: Theme.icon-md; - tint: Theme.accent-text; - y: (parent.height - self.height) / 2; - } - Text { - text: root.count > 0 ? root.title + " — " + root.count : root.title; - color: Theme.text; - font-size: Theme.font-md; - font-weight: Theme.weight-semibold; - vertical-alignment: center; - horizontal-stretch: 1; - overflow: elide; - } - IconButton { - icon: Icons.x; - label: @tr("Close"); - size: 28px; - icon-size: Theme.icon-sm; - y: (parent.height - self.height) / 2; - clicked => { root.closed(); } - } + Text { + text: pin.line.author; + color: Theme.name-text; + font-size: Theme.font-md; + font-weight: Theme.weight-medium; + vertical-alignment: center; + overflow: elide; + } + Text { + text: pin.line.time; + color: Theme.text-muted; + font-size: Theme.font-sm; + vertical-alignment: center; + horizontal-stretch: 1; + overflow: elide; + } + IconButton { + icon: Icons.pin; + label: @tr("Unpin"); + tint: Theme.accent-text; + size: 28px; + icon-size: Theme.icon-sm; + y: (parent.height - self.height) / 2; + clicked => { Bridge.pin(pin.line.key, false); } } } - @children + if !pin.line.rich && pin.line.text != "": Text { + text: pin.line.text; + color: Theme.text; + wrap: word-wrap; + } + if pin.line.rich: RichText { + runs: pin.line.runs; + } + for file in pin.line.files: HorizontalLayout { + spacing: Theme.space-2; + Icon { + source: file.picture ? Icons.image : Icons.file-text; + size: Theme.icon-sm; + tint: Theme.accent-text; + y: (parent.height - self.height) / 2; + } + Text { + text: file.name; + color: Theme.accent-text; + font-size: Theme.font-sm; + vertical-alignment: center; + overflow: elide; + } + } + if pin.line.reactions.length > 0: VerticalLayout { + padding-top: Theme.space-2; + Reactions { + key: pin.line.key; + model: pin.line.reactions; + } + } + Text { + text: pin.by; + color: Theme.text-muted; + font-size: Theme.font-xs; + overflow: elide; + } } } -// The pinned messages of the current chat: jump to one or unpin it. +// The pinned messages of the current chat. export component PinsDrawer inherits Drawer { - title: @tr("Pinned"); + title: @tr("Pinned Messages"); icon: Icons.pin; - count: Bridge.pins.length; closed => { Nav.pins-open = false; } if Bridge.pins-loading: HorizontalLayout { padding: Theme.space-6; @@ -95,61 +182,32 @@ export component PinsDrawer inherits Drawer { ListView { vertical-stretch: 1; accessible-label: @tr("Pinned messages"); - for pin in Bridge.pins: Rectangle { - min-height: entry.preferred-height; - entry := VerticalLayout { - padding-bottom: Theme.space-3; - MessageRow { - line: pin.line; - actions: false; - } - HorizontalLayout { - padding-left: 78px; - padding-right: Theme.space-5; - spacing: Theme.space-2; - Text { - text: pin.by; - color: Theme.text-muted; - font-size: Theme.font-xs; - vertical-alignment: center; - horizontal-stretch: 1; - overflow: elide; - } - Button { - small: true; - icon: Icons.arrow-right; - text: @tr("Jump"); - clicked => { - Bridge.jump-to-pin(pin.line.key); - Nav.pins-open = false; - } - } - Button { - small: true; - kind: ButtonKind.danger; - icon: Icons.pin; - text: @tr("Unpin"); - clicked => { Bridge.pin(pin.line.key, false); } - } - } - Rectangle { - height: 1px; - background: Theme.border; - } + for pin in Bridge.pins: VerticalLayout { + padding-left: Theme.space-3; + padding-right: Theme.space-3; + padding-bottom: Theme.space-3; + PinCard { + pin: pin; } } } } -component TopicRow inherits Rectangle { +// A topic: its icon, title, what is in it and when it was last active. +component TopicCard inherits Rectangle { in property topic; - height: 62px; - border-radius: Theme.radius-md; - background: Bridge.current-topic == topic.id ? Theme.accent-soft : area.has-hover ? Theme.surface-3 : transparent; + min-height: body.preferred-height; + border-radius: Theme.radius-lg; + background: Bridge.current-topic == topic.id ? Theme.accent-soft : area.has-hover ? Theme.surface-3 : Theme.surface-2; + border-width: 1px; + border-color: Bridge.current-topic == topic.id ? Theme.accent : Theme.border-strong; accessible-role: AccessibleRole.list-item; accessible-label: topic.title; accessible-description: topic.detail; - accessible-action-default => { Bridge.open-topic(topic.id); } + accessible-action-default => { + Bridge.open-topic(topic.id); + Nav.topics-open = false; + } area := TouchArea { mouse-cursor: MouseCursor.pointer; clicked => { @@ -157,54 +215,75 @@ component TopicRow inherits Rectangle { Nav.topics-open = false; } } - HorizontalLayout { - padding-left: Theme.space-3; - padding-right: Theme.space-3; - spacing: Theme.space-3; - Rectangle { - width: 34px; - height: 34px; - y: (parent.height - self.height) / 2; - border-radius: Theme.radius-sm; - background: Theme.surface-3; - Icon { - source: topic.archived ? Icons.bookmark : Icons.messages-square; - size: Theme.icon-sm; - tint: topic.archived ? Theme.text-muted : Theme.accent-text; + body := HorizontalLayout { + padding: Theme.space-4; + spacing: Theme.space-4; + VerticalLayout { + alignment: start; + Rectangle { + width: 40px; + height: 40px; + border-radius: Theme.radius-md; + background: Theme.surface-4; + Icon { + source: topic.archived ? Icons.bookmark : Icons.messages-square; + size: 22px; + tint: topic.archived ? Theme.text-muted : Theme.text-secondary; + } } } VerticalLayout { - alignment: center; horizontal-stretch: 1; - spacing: 2px; + spacing: Theme.space-1; Text { text: topic.title; color: Theme.text; + font-size: Theme.font-md; font-weight: Theme.weight-medium; overflow: elide; } Text { text: topic.detail; - color: Theme.text-muted; - font-size: Theme.font-xs; + color: Theme.text-secondary; + font-size: Theme.font-sm; overflow: elide; } - } - Icon { - source: Icons.chevron-right; - size: Theme.icon-sm; - tint: Theme.text-muted; - y: (parent.height - self.height) / 2; + HorizontalLayout { + spacing: Theme.space-2; + padding-top: Theme.space-1; + Rectangle { + width: 7px; + height: 7px; + y: (parent.height - self.height) / 2; + border-radius: 3.5px; + background: topic.recent ? Theme.success : Theme.offline; + } + Text { + text: topic.activity; + color: Theme.text-muted; + font-size: Theme.font-sm; + overflow: elide; + } + } } } } -// The topics (threads) of the current chat. +// The topics (threads) of the current chat: search, open, create. export component TopicsDrawer inherits Drawer { title: @tr("Topics"); - icon: Icons.messages-square; - count: Bridge.topics.length; closed => { Nav.topics-open = false; } + HorizontalLayout { + padding-left: Theme.space-3; + padding-right: Theme.space-3; + SearchBox { + height: 40px; + show-shortcut: false; + placeholder: @tr("Search topics…"); + label: @tr("Search topics"); + edited(text) => { Bridge.search-topics(text); } + } + } if Bridge.topics-loading: HorizontalLayout { padding: Theme.space-6; alignment: center; @@ -230,16 +309,23 @@ export component TopicsDrawer inherits Drawer { ListView { vertical-stretch: 1; accessible-label: @tr("Topics"); - for topic in Bridge.topics: TopicRow { - topic: topic; + for topic in Bridge.topics: VerticalLayout { + padding-left: Theme.space-3; + padding-right: Theme.space-3; + padding-bottom: Theme.space-3; + TopicCard { + topic: topic; + } } } HorizontalLayout { padding: Theme.space-3; + padding-bottom: Theme.space-4; Button { horizontal-stretch: 1; + kind: ButtonKind.primary; icon: Icons.plus; - text: @tr("New topic"); + text: @tr("Create Topic"); clicked => { Nav.start-topic(-1); } } } diff --git a/crates/voelin-ui/ui/screens/members.slint b/crates/voelin-ui/ui/screens/members.slint index 1fa85da..f17eab5 100644 --- a/crates/voelin-ui/ui/screens/members.slint +++ b/crates/voelin-ui/ui/screens/members.slint @@ -1,11 +1,12 @@ -// The members panel: who is in our voice channel, grouped by server group, -// with a card for one person; and the voice channel as a grid of tiles. +// The members panel: everyone on the server in sections (the people in our +// voice channel or those streaming first, then each server group), a +// search, and a card for one person. import { Theme } from "../theme.slint"; import { Icons } from "../icons.slint"; import { Bridge, MemberItem } from "../bridge.slint"; import { Nav } from "../nav.slint"; -import { Icon, IconButton, Button, ButtonKind, Avatar, Status, LiveBadge, Chip, Divider, Slider, SpeakingBars, Tooltip, ListView } from "../components/index.slint"; +import { Icon, IconButton, Button, ButtonKind, Avatar, Status, LiveBadge, Chip, Divider, Slider, SpeakingBars, Tooltip, SearchBox, ListView } from "../components/index.slint"; // Crown, priority speaker, channel commander, recording. component MemberBadges inherits HorizontalLayout { @@ -42,41 +43,35 @@ component MemberBadges inherits HorizontalLayout { } } -// The header above the first member of a server group. +// The heading above the first member of a section: "Moderator — 3". export component GroupHeader inherits HorizontalLayout { in property member; - padding-top: Theme.space-4; - padding-bottom: Theme.space-1; + padding-top: Theme.space-5; + padding-bottom: Theme.space-2; padding-left: Theme.space-2; spacing: Theme.space-2; if member.group-icon.width > 0: Image { - width: 14px; - height: 14px; + width: 16px; + height: 16px; source: member.group-icon; y: (parent.height - self.height) / 2; } - if member.group-icon.width == 0: Icon { - source: member.admin ? Icons.shield-check : Icons.users; - size: 13px; - tint: Theme.text-muted; - y: (parent.height - self.height) / 2; - } Text { - text: member.group != "" ? member.group : @tr("Others"); - color: Theme.text-muted; - font-size: Theme.font-xs; - font-weight: Theme.weight-semibold; - letter-spacing: 0.4px; + text: member.group-count > 0 ? @tr("{} — {}", member.group, member.group-count) : member.group; + color: Theme.text-secondary; + font-size: Theme.font-md; + font-weight: Theme.weight-medium; vertical-alignment: center; horizontal-stretch: 1; overflow: elide; } } -// One person in the panel. +// One person in the panel: avatar, name with badges and role, what they +// are doing. export component MemberRow inherits Rectangle { in property member; - height: 48px * Theme.font-scale; + height: 52px * Theme.font-scale; border-radius: Theme.radius-md; background: Bridge.member-card.open && Bridge.member-card.id == member.id ? Theme.accent-soft : area.has-hover ? Theme.surface-3 : transparent; @@ -88,6 +83,7 @@ export component MemberRow inherits Rectangle { mouse-cursor: MouseCursor.pointer; clicked => { Bridge.open-member(member.id); } } + opacity: member.away ? 0.6 : 1.0; HorizontalLayout { padding-left: Theme.space-2; padding-right: Theme.space-2; @@ -95,12 +91,11 @@ export component MemberRow inherits Rectangle { VerticalLayout { alignment: center; Avatar { - size: 34px; + size: 40px; initials: member.initials; tint: member.tint; image: member.avatar; speaking: member.talking; - crown: member.admin; status: member.away ? Status.idle : member.sound-off ? Status.dnd : Status.online; label: member.name; } @@ -108,11 +103,14 @@ export component MemberRow inherits Rectangle { VerticalLayout { alignment: center; horizontal-stretch: 1; + spacing: 1px; HorizontalLayout { spacing: Theme.space-2; + alignment: start; Text { text: member.name; - color: member.myself ? Theme.accent-text : Theme.name-text; + color: member.myself ? Theme.accent-text : member.role != "" ? Theme.name-text : Theme.text; + font-size: Theme.font-md; font-weight: Theme.weight-medium; overflow: elide; } @@ -120,13 +118,10 @@ export component MemberRow inherits Rectangle { member: member; y: (parent.height - self.height) / 2; } - if member.streaming: VerticalLayout { - alignment: center; - LiveBadge { } - } } HorizontalLayout { spacing: Theme.space-2; + alignment: start; Text { text: member.status; color: member.talking ? Theme.success : Theme.text-muted; @@ -138,14 +133,29 @@ export component MemberRow inherits Rectangle { height: 12px; y: (parent.height - self.height) / 2; } + if member.streaming: Icon { + source: Icons.monitor; + size: 14px; + tint: Theme.text-secondary; + y: (parent.height - self.height) / 2; + } } } - if member.talk-power > 0: Text { - text: member.talk-power; - color: Theme.text-muted; - font-size: Theme.font-xs; - vertical-alignment: center; - accessible-label: @tr("talk power"); + if member.role != "": Icon { + source: Icons.shield-check; + size: 18px; + tint: #c06cff; + y: (parent.height - self.height) / 2; + } + if member.role != "": Chip { + text: member.role; + fill: Theme.surface-3; + outlined: true; + y: (parent.height - self.height) / 2; + } + if member.streaming: VerticalLayout { + alignment: center; + LiveBadge { } } if member.muted: Icon { source: Icons.mic-off; @@ -159,6 +169,13 @@ export component MemberRow inherits Rectangle { tint: Theme.danger; y: (parent.height - self.height) / 2; } + if member.talk-power > 0: Text { + text: member.talk-power; + color: Theme.text-disabled; + font-size: Theme.font-xs; + vertical-alignment: center; + accessible-label: @tr("talk power {}", member.talk-power); + } } } @@ -333,19 +350,69 @@ export component MemberCardPopup inherits Rectangle { } } -// The members of our channel, grouped by server group. -export component MembersList inherits VerticalLayout { - if Bridge.members.length == 0: Text { - text: @tr("Join a channel with voice to see who is there."); - color: Theme.text-muted; - font-size: Theme.font-sm; - wrap: word-wrap; +// The right panel of a server: "Members — 412", a search, everyone in +// sections. Its width is the setting `ui.members_width`. +export component MembersPanel inherits VerticalLayout { + property searching; + padding-top: Theme.space-4; + padding-bottom: Theme.space-2; + spacing: Theme.space-2; + HorizontalLayout { + padding-left: Theme.space-5; + padding-right: Theme.space-3; + spacing: Theme.space-2; + Text { + text: @tr("Members — {}", Bridge.member-total); + color: Theme.text; + font-size: Theme.font-lg; + font-weight: Theme.weight-medium; + vertical-alignment: center; + horizontal-stretch: 1; + overflow: elide; + } + IconButton { + icon: Icons.search; + label: @tr("Search members"); + checked: root.searching; + size: 32px; + icon-size: Theme.icon-sm; + clicked => { + root.searching = !root.searching; + if !root.searching { + Bridge.search-members(""); + } + } + } + } + if root.searching: HorizontalLayout { + padding-left: Theme.space-4; + padding-right: Theme.space-4; + SearchBox { + height: 36px; + show-shortcut: false; + placeholder: @tr("Search members…"); + label: @tr("Search members"); + init => { self.focus(); } + edited(text) => { Bridge.search-members(text); } + } + } + if Bridge.server-members.length == 0: HorizontalLayout { + padding-left: Theme.space-5; + padding-right: Theme.space-5; + Text { + text: @tr("Connect or observe to see who is here."); + color: Theme.text-muted; + font-size: Theme.font-sm; + wrap: word-wrap; + } } ListView { vertical-stretch: 1; accessible-role: AccessibleRole.list; accessible-label: @tr("Members"); - for member in Bridge.members: VerticalLayout { + for member in Bridge.server-members: VerticalLayout { + padding-left: Theme.space-3; + padding-right: Theme.space-3; if member.first-in-group: GroupHeader { member: member; } @@ -355,223 +422,3 @@ export component MembersList inherits VerticalLayout { } } } - -// One person as a tile of the voice grid. -component VoiceTile inherits Rectangle { - in property member; - - border-radius: Theme.radius-lg; - background: Theme.surface-2; - border-width: member.talking ? 2px : 1px; - border-color: member.talking ? Theme.success : Theme.border; - accessible-role: AccessibleRole.list-item; - accessible-label: member.name; - accessible-description: member.status; - accessible-action-default => { Bridge.open-member(member.id); } - TouchArea { - mouse-cursor: MouseCursor.pointer; - clicked => { Bridge.open-member(member.id); } - } - VerticalLayout { - padding: Theme.space-4; - spacing: Theme.space-3; - alignment: center; - HorizontalLayout { - alignment: center; - Avatar { - size: 64px; - initials: member.initials; - tint: member.tint; - image: member.avatar; - speaking: member.talking; - crown: member.admin; - label: member.name; - } - } - HorizontalLayout { - alignment: center; - spacing: Theme.space-2; - Text { - text: member.name; - color: member.myself ? Theme.accent-text : Theme.text; - font-weight: Theme.weight-semibold; - overflow: elide; - } - MemberBadges { - member: member; - y: (parent.height - self.height) / 2; - } - } - HorizontalLayout { - alignment: center; - spacing: Theme.space-2; - if member.muted: Icon { - source: Icons.mic-off; - size: 15px; - tint: Theme.danger; - } - if member.sound-off: Icon { - source: Icons.headphone-off; - size: 15px; - tint: Theme.danger; - } - if member.streaming: LiveBadge { } - if !member.muted && !member.sound-off && !member.streaming: Text { - text: member.status; - color: member.talking ? Theme.success : Theme.text-muted; - font-size: Theme.font-sm; - overflow: elide; - } - } - } -} - -// A stream in the channel as a tile next to the people. -component StreamTile inherits Rectangle { - in property name; - in property streamer; - in property id; - in property watching; - - border-radius: Theme.radius-lg; - clip: true; - background: @linear-gradient(135deg, #2b1f6e 0%, #0f2a66 100%); - border-width: root.watching ? 2px : 1px; - border-color: root.watching ? Theme.accent : Theme.border; - accessible-role: AccessibleRole.groupbox; - accessible-label: root.name; - LiveBadge { - x: Theme.space-3; - y: Theme.space-3; - large: true; - } - VerticalLayout { - padding: Theme.space-4; - spacing: Theme.space-2; - alignment: center; - Icon { - source: Icons.monitor-up; - size: 34px; - tint: #ffffffd0; - } - Text { - text: root.name != "" ? root.name : @tr("Untitled stream"); - color: #ffffff; - font-weight: Theme.weight-semibold; - horizontal-alignment: center; - overflow: elide; - } - Text { - text: @tr("by {}", root.streamer); - color: #ffffffb0; - font-size: Theme.font-sm; - horizontal-alignment: center; - overflow: elide; - } - if root.id != "": HorizontalLayout { - padding-top: Theme.space-2; - alignment: center; - Button { - small: true; - kind: root.watching ? ButtonKind.secondary : ButtonKind.primary; - icon: root.watching ? Icons.monitor : Icons.eye; - text: root.watching ? @tr("Show") : @tr("Watch"); - clicked => { - if root.watching { - Bridge.show-viewer(); - } else { - Bridge.watch-stream(root.id); - } - } - } - } - } -} - -// The voice channel as tiles: the people in it and the streams there. -export component VoiceGrid inherits VerticalLayout { - // How many tiles fit; the grid wraps into rows of that many. - property columns: max(1, min(4, floor((root.width - 32px) / 250px))); - property total: Bridge.members.length + Bridge.streams.length; - property rows: ceil(total / columns); - Rectangle { - height: 56px; - HorizontalLayout { - padding-left: Theme.space-6; - padding-right: Theme.space-4; - spacing: Theme.space-3; - Icon { - source: Icons.volume-2; - size: 22px; - tint: Theme.text-secondary; - y: (parent.height - self.height) / 2; - } - Text { - text: Bridge.own-channel != "" ? Bridge.own-channel : @tr("Voice"); - color: Theme.text; - font-size: Theme.font-xl; - font-weight: Theme.weight-semibold; - vertical-alignment: center; - } - Text { - text: @tr("{} in voice", Bridge.members.length); - color: Theme.text-muted; - font-size: Theme.font-sm; - vertical-alignment: center; - horizontal-stretch: 1; - } - Button { - small: true; - icon: Icons.message-square; - text: @tr("Chat"); - y: (parent.height - self.height) / 2; - clicked => { Nav.voice-grid = false; } - } - } - Rectangle { - y: parent.height - 1px; - height: 1px; - background: Theme.border; - } - } - if root.total == 0: VerticalLayout { - padding: Theme.space-8; - alignment: center; - Text { - text: @tr("Nobody is in this channel."); - color: Theme.text-muted; - horizontal-alignment: center; - } - } - ListView { - vertical-stretch: 1; - accessible-label: @tr("Voice channel"); - for row in root.rows: HorizontalLayout { - padding: Theme.space-3; - padding-left: Theme.space-5; - padding-right: Theme.space-5; - spacing: Theme.space-4; - // One cell per column; the last row's empty cells stay blank. - for column in root.columns: Rectangle { - property index: row * root.columns + column; - horizontal-stretch: 1; - // The cell sizes the tile, never the other way round. - min-width: 200px; - height: 176px; - if index < Bridge.members.length: VoiceTile { - width: parent.width; - height: parent.height; - member: Bridge.members[index]; - } - if index >= Bridge.members.length && index < root.total: StreamTile { - width: parent.width; - height: parent.height; - name: Bridge.streams[index - Bridge.members.length].name; - streamer: Bridge.streams[index - Bridge.members.length].streamer; - id: Bridge.streams[index - Bridge.members.length].id; - watching: Bridge.streams[index - Bridge.members.length].watching; - } - } - } - } -} diff --git a/crates/voelin-ui/ui/screens/voice.slint b/crates/voelin-ui/ui/screens/voice.slint new file mode 100644 index 0000000..b5a0bb7 --- /dev/null +++ b/crates/voelin-ui/ui/screens/voice.slint @@ -0,0 +1,316 @@ +// The voice channel we are in: who is there (and who talks), the streams +// in it, and the channel's chat below. + +import { Theme } from "../theme.slint"; +import { Icons } from "../icons.slint"; +import { Bridge, MemberItem, StreamItem } from "../bridge.slint"; +import { Nav, SettingsSection } from "../nav.slint"; +import { Icon, IconButton, Button, ButtonKind, Avatar, LiveBadge, Chip, SpeakingBars } from "../components/index.slint"; +import { MessageList, Composer } from "chat.slint"; + +// One person: a large avatar with a ring (green while talking, blue while +// streaming), the muted mark, the name and what they do. +component Participant inherits VerticalLayout { + in property member; + property size: 80px; + width: 120px; + spacing: Theme.space-2; + accessible-role: AccessibleRole.list-item; + accessible-label: member.name; + accessible-description: member.status; + accessible-action-default => { Bridge.open-member(member.id); } + HorizontalLayout { + alignment: center; + Rectangle { + width: root.size + 8px; + height: root.size + 8px; + border-radius: self.width / 2; + border-width: member.talking || member.streaming ? 3px : 2px; + border-color: member.talking ? Theme.success : member.streaming ? Theme.accent : Theme.border-strong; + Avatar { + size: root.size; + initials: member.initials; + tint: member.tint; + image: member.avatar; + label: member.name; + } + // Talking, or the microphone off, at the bottom right. + if member.talking || member.muted || member.sound-off: Rectangle { + x: parent.width - self.width - 2px; + y: parent.height - self.height - 2px; + width: 26px; + height: 26px; + border-radius: 13px; + background: Theme.surface; + border-width: 2px; + border-color: Theme.surface; + if member.talking: SpeakingBars { + width: 14px; + height: 14px; + } + if !member.talking: Icon { + source: member.sound-off ? Icons.headphone-off : Icons.mic-off; + size: 15px; + tint: Theme.danger; + } + } + TouchArea { + mouse-cursor: MouseCursor.pointer; + clicked => { Bridge.open-member(member.id); } + } + } + } + HorizontalLayout { + alignment: center; + spacing: Theme.space-2; + Text { + text: member.name; + color: member.myself ? Theme.accent-text : Theme.text; + font-size: Theme.font-md; + font-weight: Theme.weight-medium; + overflow: elide; + } + if member.admin: Icon { + source: Icons.crown; + size: 15px; + tint: Theme.gold; + y: (parent.height - self.height) / 2; + } + } + HorizontalLayout { + alignment: center; + spacing: Theme.space-2; + if member.talking: SpeakingBars { + width: 12px; + height: 12px; + y: (parent.height - self.height) / 2; + } + Text { + text: member.talking ? @tr("Speaking") : member.streaming ? @tr("Streaming") : member.away ? @tr("Away") : ""; + color: member.talking ? Theme.success : Theme.text-secondary; + font-size: Theme.font-sm; + overflow: elide; + } + if member.streaming && !member.talking: Icon { + source: Icons.monitor; + size: 14px; + tint: Theme.text-secondary; + y: (parent.height - self.height) / 2; + } + } +} + +// A stream in the channel as a large card: LIVE, the title, who streams +// what, and Watch. +component StreamCard inherits Rectangle { + in property stream; + height: 236px; + border-radius: Theme.radius-lg; + clip: true; + background: @linear-gradient(160deg, #1b2a6b 0%, #2a1b5e 45%, #0c1430 100%); + border-width: 1px; + border-color: stream.watching ? Theme.accent : Theme.border-strong; + accessible-role: AccessibleRole.groupbox; + accessible-label: stream.name; + // The picture while we watch it (the viewer hidden behind the chat). + if stream.watching && Bridge.viewer-has-frame: Image { + width: parent.width; + height: parent.height; + source: Bridge.viewer-frame; + image-fit: cover; + } + if !(stream.watching && Bridge.viewer-has-frame): Icon { + source: stream.kind == "Camera" ? Icons.video : Icons.monitor-up; + size: 72px; + tint: #ffffff22; + } + // Darker at the bottom, for the text. + Rectangle { + y: parent.height * 0.4; + height: parent.height * 0.6; + background: @linear-gradient(180deg, #00000000 0%, #060a18e0 100%); + } + HorizontalLayout { + x: Theme.space-4; + y: Theme.space-4; + height: 28px; + spacing: Theme.space-3; + LiveBadge { + large: true; + y: (parent.height - self.height) / 2; + } + if stream.watching && Bridge.viewer-count > 0: Chip { + text: @tr("{} watching", Bridge.viewer-count); + icon: Icons.eye; + tint: #ffffff; + fill: #060a18a0; + y: (parent.height - self.height) / 2; + } + } + HorizontalLayout { + padding: Theme.space-4; + padding-top: 0px; + spacing: Theme.space-3; + alignment: stretch; + VerticalLayout { + alignment: end; + horizontal-stretch: 1; + spacing: Theme.space-1; + Text { + text: stream.id == "" ? @tr("{} is streaming", stream.streamer) : stream.name != "" ? stream.name : @tr("Untitled stream"); + color: #ffffff; + font-size: Theme.font-lg; + font-weight: Theme.weight-semibold; + overflow: elide; + } + Text { + text: stream.kind != "" ? stream.streamer + " • " + stream.kind : stream.streamer; + color: #ffffffc0; + font-size: Theme.font-body; + overflow: elide; + } + HorizontalLayout { + padding-top: Theme.space-2; + spacing: Theme.space-2; + alignment: start; + if stream.bitrate != "": Chip { + text: stream.bitrate; + tint: #ffffffe0; + fill: #ffffff1a; + } + if stream.audio: Chip { + text: @tr("Sound"); + icon: Icons.volume-2; + tint: #ffffffe0; + fill: #ffffff1a; + } + if stream.own: Chip { + text: @tr("Your stream"); + tint: #ffffffe0; + fill: #ffffff1a; + } + } + } + if stream.id != "" && !stream.own: VerticalLayout { + alignment: end; + Button { + icon: stream.watching ? Icons.monitor : Icons.external-link; + text: stream.watching ? @tr("Show Stream") : @tr("Watch Stream"); + checked: true; + clicked => { + if stream.watching { + Bridge.show-viewer(); + } else { + Bridge.watch-stream(stream.id); + } + } + } + } + } +} + +// The voice channel view (desktop): header, people, streams, chat. +export component VoiceView inherits VerticalLayout { + HorizontalLayout { + padding-left: Theme.space-7; + padding-right: Theme.space-5; + padding-top: Theme.space-5; + padding-bottom: Theme.space-3; + spacing: Theme.space-5; + Icon { + source: Icons.volume-2; + size: 40px; + tint: Theme.text-secondary; + y: Theme.space-1; + } + VerticalLayout { + horizontal-stretch: 1; + spacing: Theme.space-1; + Text { + text: Bridge.own-channel; + color: Theme.text; + font-size: Theme.font-3xl; + font-weight: Theme.weight-semibold; + overflow: elide; + } + if Bridge.own-channel-topic != "": Text { + text: Bridge.own-channel-topic; + color: Theme.text-secondary; + font-size: Theme.font-md; + overflow: elide; + } + HorizontalLayout { + spacing: Theme.space-2; + alignment: start; + Icon { + source: Icons.users; + size: 16px; + tint: Theme.text-secondary; + y: (parent.height - self.height) / 2; + } + Text { + text: Bridge.own-channel-limit >= 0 + ? @tr("{} in voice / {} total", Bridge.members.length, Bridge.own-channel-limit) + : @tr("{} in voice", Bridge.members.length); + color: Theme.text-secondary; + font-size: Theme.font-body; + } + } + } + IconButton { + icon: Icons.message-square; + label: @tr("Chat only"); + y: Theme.space-1; + clicked => { Nav.show-voice(false); } + } + Button { + icon: Icons.settings; + text: @tr("Voice Settings"); + y: Theme.space-1; + clicked => { Nav.open-settings(SettingsSection.voice); } + } + Button { + kind: ButtonKind.danger; + icon: Icons.phone-off; + text: @tr("Leave"); + y: Theme.space-1; + clicked => { + Nav.show-voice(false); + Bridge.disconnect-voice(); + } + } + } + // The people, centred, wrapping into more rows when there are many. + FlexboxLayout { + padding-left: Theme.space-6; + padding-right: Theme.space-6; + padding-top: Theme.space-3; + padding-bottom: Theme.space-4; + alignment: center; + spacing-horizontal: Theme.space-6; + spacing-vertical: Theme.space-4; + accessible-role: AccessibleRole.list; + accessible-label: @tr("In voice"); + for member in Bridge.members: Participant { + member: member; + } + } + if Bridge.streams.length > 0: HorizontalLayout { + padding-left: Theme.space-6; + padding-right: Theme.space-6; + padding-bottom: Theme.space-3; + spacing: Theme.space-4; + for stream in Bridge.streams: StreamCard { + horizontal-stretch: 1; + stream: stream; + } + } + MessageList { + vertical-stretch: 1; + model: Bridge.messages; + older: true; + } + Composer { + placeholder: @tr("Message {}", Bridge.own-channel); + } +} diff --git a/crates/voelin-ui/ui/shells/common.slint b/crates/voelin-ui/ui/shells/common.slint index 5f2d3cd..d068f40 100644 --- a/crates/voelin-ui/ui/shells/common.slint +++ b/crates/voelin-ui/ui/shells/common.slint @@ -58,7 +58,8 @@ export component HoldToTalk inherits Rectangle { } } -// "Voice Connected — channel / server", disconnect, and hold-to-talk. +// "Voice Connected — channel / server", disconnect, and hold-to-talk +// with push-to-talk. export component VoiceCard inherits Rectangle { border-radius: Theme.radius-lg; background: Theme.surface-2; @@ -104,7 +105,7 @@ export component VoiceCard inherits Rectangle { clicked => { Bridge.disconnect-voice(); } } } - if Bridge.voice-connected: HoldToTalk { } + if Bridge.voice-connected && Bridge.audio.transmit == 0: HoldToTalk { } } }