Files
VoelinClient/crates/voelin-ui-vm/src/streams.rs
T
faumarayandClaude Sonnet 5.5 ce7ec3afb7 Move the view models into voelin-ui-vm; the Slint models take plain rows
vm/{avatar,tree,servers,streams,home,chat,social,studio} and the UI
settings (settings.rs: keys, UiSettings, LastVoice, ClientPlaybackMap,
the audio form) move into voelin-ui-vm with their tests (102 there now;
the 86 view-model tests of voelin-ui all survive, the old list::sync test
became the list::diff tests). They produce the plain bridge structs, with
Rgb for colours and ImageRef for pictures:

- a file picture is ImageSource::File { path, stamp }: the engine writes
  a picture that arrives again into the same file, so the length and
  write time are part of the reference and a changed file redraws its
  row; size() reads the header once per stamp (no toolkit decoder);
- pictures held in memory (chat previews) are ImageSource::Memory;
- the line cache of the chat no longer keeps Slint models alive for
  pointer equality: plain lines compare by value, so an unchanged
  message makes the same line with or without the cache.

voelin-ui keeps every model as bind::rows::Rows<T>: the plain rows last
shown plus the VecModel, synced with list::diff, converting only the rows
that changed (bind/convert has the From impls). The controllers hand the
view-model rows to Rows::sync and convert forms at the bridge
(`.into()`); crate::vm is now `voelin_ui_vm as vm`, so paths stay.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-20 10:20:55 +03:00

71 lines
2.1 KiB
Rust

//! Streams on the voice view, the phone's Activity tab and Home: what is
//! shared, and who shares it.
use std::path::PathBuf;
use voelin_core::stream::StreamKind;
use crate::avatar;
use crate::bridge::StreamItem;
/// "Screen", "Window", "Camera"; "" for a kind we do not know.
pub fn kind_label(kind: &StreamKind) -> &'static str {
match kind {
StreamKind::Screen => "Screen",
StreamKind::Window => "Window",
StreamKind::Camera => "Camera",
StreamKind::Other(_) => "",
}
}
/// A gateway directory's kind as a label: "screen" → "Screen".
pub fn directory_kind_label(kind: &str) -> String {
let mut chars = kind.chars();
chars.next().map(|c| c.to_uppercase().chain(chars).collect()).unwrap_or_default()
}
/// A stream with its streamer: the name, and the avatar as the members
/// show it (the picture from the engine's cache, else the initials on the
/// name's colour). The caller fills in the rest.
pub fn streamer(name: &str, picture: Option<&PathBuf>) -> StreamItem {
StreamItem {
streamer: name.into(),
initials: avatar::initials(name).into(),
tint: avatar::tint(name),
avatar: avatar::image(picture),
..StreamItem::default()
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::Size;
#[test]
fn kinds_have_labels() {
assert_eq!(kind_label(&StreamKind::Screen), "Screen");
assert_eq!(kind_label(&StreamKind::Window), "Window");
assert_eq!(kind_label(&StreamKind::Camera), "Camera");
assert_eq!(kind_label(&StreamKind::Other(9)), "");
assert_eq!(kind_label(&StreamKind::from_u8(2)), "Camera");
}
#[test]
fn directory_kinds_are_capitalised() {
assert_eq!(directory_kind_label("screen"), "Screen");
assert_eq!(directory_kind_label("Camera"), "Camera");
assert_eq!(directory_kind_label(""), "");
}
#[test]
fn streamers_look_as_in_the_members() {
let item = streamer("Nova Star", None);
assert_eq!(&*item.streamer, "Nova Star");
assert_eq!(&*item.initials, "NS");
assert_eq!(item.tint, avatar::tint("Nova Star"));
assert_eq!(item.avatar.size(), Size::default());
assert!(item.id.is_empty() && !item.own && !item.studio);
}
}