Files
VoelinClient/crates/voelin-ui/src/inbox.rs
T
Claude 14ea206521 ui: a colour per server, one letter in small avatars, one channel icon
Servers took their colour from a palette of people's colours by a hash
of the name, so two of the three sample servers were the same blue.
vm::servers::tints gives each server, in the rail's order, a colour
from ten hues around the wheel: its name's, or the next free one when
an earlier server has it. The rail, Home, search, live rooms and the
server chats in the chat lists use it. A server icon at most half as
wide as its avatar (TeamSpeak's 16 px ones) is drawn at twice its size,
sharp, on that colour instead of stretched.

Avatars under 28 px show one letter (Images.first-letter, as Slint
cannot cut a string). Channels show the speaker (Icons.channel)
everywhere the hash or the volume icon stood for one, and tab titles,
notifications and subtitles name them without a '#' (vm::chat::tab_title;
private chats keep '@').

Member rows showed everyone's talk power as a bare number. They now show
a muted hand, "Needs talk power to speak", only on those whose channel
needs more than they have and who are no talker (vm::tree::cannot_talk);
the member card keeps the number. The sample's Raid Night needs 50.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
2026-10-07 20:06:16 +00:00

110 lines
3.7 KiB
Rust

//! Requests from the platform around the window: on Android a tapped
//! notification or something shared to the app ("Share to Voelin"), and a
//! TeamSpeak link to open. They can come from any thread and before the
//! window runs; [`request`] keeps them until the window takes them on its
//! thread.
use std::path::PathBuf;
use std::sync::{Mutex, PoisonError};
use slint::ComponentHandle;
use voelin_model::ChatTarget;
use crate::app::{App, MobileTab, Nav, Page, with_app};
/// What the platform asks the window to do.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Request {
/// Show the voice channel we are in (the phone's voice screen).
ShowVoice,
/// Shared to the app: the text goes into the current chat's composer
/// (to send with one tap, or edit, as a mis-tap in the share sheet
/// should not post into a chat), the files are uploaded to the current
/// channel and linked there, as the composer's attach button does.
Share { text: Option<String>, files: Vec<PathBuf> },
/// Open a TeamSpeak link (`ts3server://`, `teamspeak://`, `tmspk.gg`):
/// the server dialog filled in from it, or a move in voice.
OpenLink(String),
}
static PENDING: Mutex<Vec<Request>> = Mutex::new(Vec::new());
/// Hand `request` to the window: at once if it runs, else when it starts.
pub fn request(request: Request) {
PENDING.lock().unwrap_or_else(PoisonError::into_inner).push(request);
// Fails without an event loop yet; `run` takes them then.
let _ = slint::invoke_from_event_loop(take);
}
/// Handle what is pending, on the window's thread; kept while there is no
/// window.
pub(crate) fn take() {
let Some(ui) = with_app(|app| app.ui.upgrade()).flatten() else { return };
let requests = std::mem::take(&mut *PENDING.lock().unwrap_or_else(PoisonError::into_inner));
// Not inside `with_app`: navigating calls back into Rust, which borrows
// the app again.
let nav = ui.global::<Nav>();
for request in requests {
match request {
Request::ShowVoice => {
nav.invoke_show(Page::Server);
nav.invoke_show_voice(true);
}
Request::Share { text, files } => {
// The phone shows the chat it went to.
nav.set_mobile_tab(MobileTab::Chat);
nav.invoke_show(Page::Server);
with_app(|app| app.share(&nav, text, files));
}
Request::OpenLink(url) => {
with_app(|app| app.open_link(&url));
}
}
}
}
impl App {
fn share(&mut self, nav: &Nav<'_>, text: Option<String>, files: Vec<PathBuf>) {
let current = self.current.and_then(|id| {
let view = self.sessions.get(&id)?;
let tab = &view.tabs[view.current_tab];
// Files go to the channel of the chat, else to ours.
let channel = match tab.target {
ChatTarget::Channel(channel) => Some(channel),
_ => view.state.own_channel,
}
.map(|c| {
let name =
view.presence.channels.get(&c).map(|c| crate::vm::tree::channel_title(c).0);
(c, name.map_or_else(|| "the channel".to_owned(), str::to_owned))
});
Some((id, tab.title.clone(), channel))
});
if let Some(text) = text.filter(|t| !t.trim().is_empty()) {
nav.set_draft(text.into());
self.set_status(match &current {
Some((_, title, _)) => format!("Shared text is ready to send to {title}"),
None => "Shared text is in the composer".to_owned(),
});
}
if files.is_empty() {
return;
}
match current {
Some((id, _, Some((channel, name)))) if !self.demo_ui => {
let count = files.len();
for file in files {
self.upload(id, channel, file);
}
let what = if count == 1 {
"the shared file".to_owned()
} else {
format!("{count} files")
};
self.set_status(format!("Uploading {what} to {name}"));
}
_ => self.set_status("Open a channel's chat (or join a channel) to share files there"),
}
}
}