voelin-gpui: the tree model keeps the people of our voice channel
TreeView::members was built with every tree build and thrown away. The model keeps it now and emits it as TreeEvent::Voice (the whole list, as it is now) when it differs from the last: the voice page of the next commits takes its people from the same build as the tree and the members panel, not from one of its own, so a talker is still one build for three lists. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
42d74b9594
commit
6e866b95f6
4 files changed
+102
-6
No files matched your search
@@ -76,7 +76,7 @@ impl ChannelTree {
|
||||
}
|
||||
this.emptiness = emptiness;
|
||||
}
|
||||
TreeEvent::People(..) | TreeEvent::Card => return,
|
||||
TreeEvent::People(..) | TreeEvent::Voice(_) | TreeEvent::Card => return,
|
||||
}
|
||||
cx.notify();
|
||||
});
|
||||
|
||||
@@ -84,7 +84,7 @@ impl MembersPane {
|
||||
(this.total, this.emptiness) = now;
|
||||
}
|
||||
TreeEvent::Card => this.open = model.read(cx).card().map(|card| card.id),
|
||||
TreeEvent::Rows(..) | TreeEvent::Selection => return,
|
||||
TreeEvent::Rows(..) | TreeEvent::Voice(_) | TreeEvent::Selection => return,
|
||||
}
|
||||
cx.notify();
|
||||
}),
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
//! inserted, not a list that starts again at the top. A change that moves none
|
||||
//! of what a pane shows emits nothing.
|
||||
//!
|
||||
//! The people of our voice channel (`TreeView::members`, the voice page's
|
||||
//! rows) come out of the same build as the other two lists: the model keeps
|
||||
//! them and emits them when they differ ([`TreeEvent::Voice`]), so the voice
|
||||
//! page needs no build of its own.
|
||||
//!
|
||||
//! **The tree marks who is talking**, as the Slint tree does (the ring on the
|
||||
//! avatar and the speaking bars on the row): someone who starts or stops
|
||||
//! talking changes one row of the tree and one of the members panel, so each
|
||||
@@ -93,6 +98,10 @@ pub enum TreeEvent {
|
||||
/// The members panel's rows: the operations from the rows the pane has to
|
||||
/// the rows carried (the model's [`TreeModel::people`] when it made them).
|
||||
People(Changes, Arc<Vec<MemberItem>>),
|
||||
/// The people of our voice channel, the voice page's rows, as they are
|
||||
/// now (the whole list: the page lays its people out in a wrapping row, not
|
||||
/// a virtual list, and takes them as they come).
|
||||
Voice(Arc<Vec<MemberItem>>),
|
||||
/// The card over a member row opened, changed or closed
|
||||
/// ([`TreeModel::card`]).
|
||||
Card,
|
||||
@@ -125,6 +134,7 @@ pub struct TreeModel {
|
||||
refreshes: u64,
|
||||
rows: Arc<Vec<TreeItem>>,
|
||||
people: Arc<Vec<MemberItem>>,
|
||||
voice: Arc<Vec<MemberItem>>,
|
||||
total: i32,
|
||||
card: Option<MemberCard>,
|
||||
selected: Option<ChannelId>,
|
||||
@@ -153,6 +163,7 @@ pub(super) fn debug_check(old: usize, changes: &Changes, new: usize) {
|
||||
struct Snapshot {
|
||||
rows: Vec<TreeItem>,
|
||||
people: Vec<MemberItem>,
|
||||
voice: Vec<MemberItem>,
|
||||
total: i32,
|
||||
card: Option<MemberCard>,
|
||||
selected: Option<ChannelId>,
|
||||
@@ -164,14 +175,15 @@ impl Snapshot {
|
||||
fn of(app: &AppState) -> Self {
|
||||
let vm = &app.vm;
|
||||
let view = vm.current.and_then(|id| vm.sessions.get(&id));
|
||||
let (rows, people, total) = match logic::tree_view(vm, false) {
|
||||
Some(tree) => (tree.rows, tree.server_members, tree.member_total),
|
||||
None => (Vec::new(), Vec::new(), 0),
|
||||
let (rows, people, voice, total) = match logic::tree_view(vm, false) {
|
||||
Some(tree) => (tree.rows, tree.server_members, tree.members, tree.member_total),
|
||||
None => (Vec::new(), Vec::new(), Vec::new(), 0),
|
||||
};
|
||||
Self {
|
||||
people_emptiness: Emptiness::of_people(vm, people.len(), total),
|
||||
rows,
|
||||
people,
|
||||
voice,
|
||||
total,
|
||||
card: view
|
||||
.and_then(|view| view.member_card.map(|id| (view, id)))
|
||||
@@ -197,6 +209,7 @@ impl TreeModel {
|
||||
refreshes: 0,
|
||||
rows: Arc::new(snapshot.rows),
|
||||
people: Arc::new(snapshot.people),
|
||||
voice: Arc::new(snapshot.voice),
|
||||
total: snapshot.total,
|
||||
card: snapshot.card,
|
||||
selected: snapshot.selected,
|
||||
@@ -216,6 +229,12 @@ impl TreeModel {
|
||||
&self.people
|
||||
}
|
||||
|
||||
/// The people of our voice channel, in the voice page's order (empty while
|
||||
/// voice is not connected).
|
||||
pub fn voice(&self) -> &Arc<Vec<MemberItem>> {
|
||||
&self.voice
|
||||
}
|
||||
|
||||
/// How many are on the server (the query clients not counted).
|
||||
pub fn total(&self) -> i32 {
|
||||
self.total
|
||||
@@ -266,6 +285,10 @@ impl TreeModel {
|
||||
if !people.is_empty() {
|
||||
self.people = Arc::new(new.people);
|
||||
}
|
||||
let voice = *self.voice != new.voice;
|
||||
if voice {
|
||||
self.voice = Arc::new(new.voice);
|
||||
}
|
||||
let lists = (self.emptiness, self.people_emptiness, self.total)
|
||||
!= (new.emptiness, new.people_emptiness, new.total);
|
||||
(self.emptiness, self.people_emptiness, self.total) =
|
||||
@@ -280,6 +303,9 @@ impl TreeModel {
|
||||
if !people.is_empty() {
|
||||
cx.emit(TreeEvent::People(people, self.people.clone()));
|
||||
}
|
||||
if voice {
|
||||
cx.emit(TreeEvent::Voice(self.voice.clone()));
|
||||
}
|
||||
if lists {
|
||||
cx.emit(TreeEvent::Lists);
|
||||
}
|
||||
|
||||
@@ -525,7 +525,7 @@ mod tests {
|
||||
use tokio::sync::mpsc::{self, UnboundedSender};
|
||||
use voelin_core::{Command, Event, SessionState, VoiceState};
|
||||
use voelin_store::{Bookmark, MemorySecrets};
|
||||
use voelin_ui_vm::bridge::{BookmarkForm, TreeItem};
|
||||
use voelin_ui_vm::bridge::{BookmarkForm, MemberItem, TreeItem};
|
||||
use voelin_ui_vm::dev::logic as sample;
|
||||
use voelin_ui_vm::list::{Change, Changes};
|
||||
use voelin_ui_vm::settings::{TreeState, TreeStates, UI_TREE, UI_WINDOW};
|
||||
@@ -1440,6 +1440,76 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// The people of our voice channel are the model's too, out of the same
|
||||
/// build as the tree's rows and the members panel's: they come with the
|
||||
/// connected voice, a talker or a mute changes just that person's row, a
|
||||
/// change elsewhere on the server tells nobody of them, and the model
|
||||
/// builds once for each change, not once more for the voice page.
|
||||
#[gpui::test]
|
||||
fn the_model_keeps_the_people_of_our_channel_out_of_the_same_build(cx: &mut TestAppContext) {
|
||||
let (shell, cx) = open(cx, Backend::in_memory().unwrap(), Switches::default());
|
||||
let model = shell.view.read_with(cx, |view, _| view.tree_model().clone());
|
||||
assert!(model.read_with(cx, |model, _| model.voice().is_empty()), "no server");
|
||||
sample_server(&shell, cx);
|
||||
let people = |cx: &mut VisualTestContext| model.read_with(cx, |m, _| m.voice().clone());
|
||||
let names = |rows: &[MemberItem]| {
|
||||
rows.iter().map(|m| (m.name.to_string(), m.talking, m.muted)).collect::<Vec<_>>()
|
||||
};
|
||||
assert_eq!(
|
||||
names(&people(cx)),
|
||||
[
|
||||
("Lumen".to_owned(), false, false),
|
||||
("Kairo".to_owned(), true, false),
|
||||
("Nova".to_owned(), false, false),
|
||||
("dex".to_owned(), false, true),
|
||||
("Mira".to_owned(), false, false),
|
||||
],
|
||||
"our channel's people, by group and name; Kairo talks, dex's microphone is off"
|
||||
);
|
||||
|
||||
let (log, _subscription) = tree_events(&shell, cx);
|
||||
let voice_told = |log: &Rc<RefCell<Vec<TreeEvent>>>| -> Vec<Arc<Vec<MemberItem>>> {
|
||||
log.borrow()
|
||||
.iter()
|
||||
.filter_map(|e| match e {
|
||||
TreeEvent::Voice(rows) => Some(rows.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
let refreshes = |cx: &mut VisualTestContext| model.read_with(cx, |m, _| m.refreshes());
|
||||
let before = refreshes(cx);
|
||||
shell
|
||||
.events
|
||||
.send(Event::Talking { session: sample::DEMO as u64, client: 3, talking: false })
|
||||
.unwrap();
|
||||
frame(cx);
|
||||
let told = voice_told(&log);
|
||||
let [rows] = &told[..] else { panic!("{:?}", log.borrow()) };
|
||||
assert!(!rows.iter().find(|m| m.id == 3).unwrap().talking, "Kairo stopped");
|
||||
assert_eq!(*rows, people(cx), "the rows the event carries are the model's");
|
||||
assert_eq!(refreshes(cx), before + 1, "one build for the tree, the panel and the page");
|
||||
|
||||
// Someone in another channel talks: the tree and the panel change, the
|
||||
// page has nothing new.
|
||||
log.borrow_mut().clear();
|
||||
shell
|
||||
.events
|
||||
.send(Event::Talking { session: sample::DEMO as u64, client: 6, talking: true })
|
||||
.unwrap();
|
||||
frame(cx);
|
||||
assert!(voice_told(&log).is_empty(), "{:?}", log.borrow());
|
||||
assert!(!rows_told(&log).is_empty(), "though the tree has a row to change");
|
||||
|
||||
// Voice gone: nobody is in our channel.
|
||||
log.borrow_mut().clear();
|
||||
let gone = SessionState { voice: VoiceState::Disconnected, ..Default::default() };
|
||||
shell.events.send(Event::State { session: sample::DEMO as u64, state: gone }).unwrap();
|
||||
frame(cx);
|
||||
let told = voice_told(&log);
|
||||
assert!(matches!(&told[..], [rows] if rows.is_empty()), "{told:?}");
|
||||
}
|
||||
|
||||
/// The members panel as the pane has it: the rows' names, `H` before the
|
||||
/// first of a section with its heading.
|
||||
fn members_shape(shell: &Shell, cx: &mut VisualTestContext) -> Vec<String> {
|
||||
|
||||
Reference in new issue
Block a user