Banners: requests lost on disconnect, spacer rows, tints and repeated decoding

- A picture download sent to the voice connection while it closes (or
  still queued when it ends) was dropped without an answer: its cache
  key stayed in flight and every later fetch of it, in any session,
  waited until the app restarted. The request now fails when dropped
  unanswered (ImageDownload), so the retries fetch it again.
- Only top-level channels are spacers, as in TeamSpeak: a sub-channel
  named [cspacer…] keeps its name, its lock and its member count. Chat
  tabs, the voice headers and "In …" use the same title as the tree.
- A banner covered its row's own background: our channel and the hovered
  row are tinted over the artwork again. A locked centred spacer shows
  its lock.
- A picture that cannot be decoded is remembered as such instead of being
  read again on the UI thread at every refresh (every talking change);
  avatars and icons that arrive again are decoded again.
- Cache::icon no longer opens and touches the file on every refresh of
  the server list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEpqsPES27Eacue91u3d2Q
This commit is contained in:
Claude committed 2026-10-04 16:44:57 +00:00
1 parent e15ee3afb6
commit 742dc6ce94
8 files changed
+125 -20

No files matched your search

+3
View File
@@ -963,6 +963,8 @@ impl App {
// Pictures can arrive after the rows were built: draw them again.
Event::AvatarReady { session, client_uid, path, .. } => {
let view = self.sessions.entry(session as i64).or_default();
// A file that arrives again is decoded again.
crate::images::forget(&path);
view.avatars.insert(client_uid, path);
if self.current == Some(session as i64) {
self.refresh_tree();
@@ -974,6 +976,7 @@ impl App {
}
Event::IconReady { session, icon, path } => {
let view = self.sessions.entry(session as i64).or_default();
crate::images::forget(&path);
view.icons.insert(icon, path);
self.refresh_servers();
if self.current == Some(session as i64) {
+2 -1
View File
@@ -63,7 +63,8 @@ impl App {
let name = self
.sessions
.get(&id)
.and_then(|v| v.presence.channels.get(cid).map(|c| c.name.clone()));
.and_then(|v| v.presence.channels.get(cid))
.map(|c| vm::tree::channel_title(c).0.to_owned());
format!("#{}", name.unwrap_or_else(|| cid.to_string()))
}
ChatTarget::Server => "Server".into(),
+16 -1
View File
@@ -110,6 +110,9 @@ pub fn usage_text() -> String {
})
}
/// What remembering a picture that cannot be decoded costs in the cache.
const UNDECODABLE_COST: usize = 256;
/// A picture the engine put in its cache (avatars, group and client icons),
/// decoded once and kept by its path.
pub fn file(path: &std::path::Path) -> Image {
@@ -121,7 +124,10 @@ pub fn file(path: &std::path::Path) -> Image {
// (`avatars/<md5>`, `icons/<id>`), and servers keep PNG, JPEG
// and SVG icons alike.
let bytes = std::fs::read(path).ok()?;
decode(&bytes)
// One that cannot be shown (too large, not a picture) is
// remembered as such, not read again on every refresh; a
// changed file is forgotten first (`forget`).
Some(decode(&bytes).unwrap_or((Image::default(), UNDECODABLE_COST)))
})
})
.unwrap_or_default()
@@ -328,6 +334,15 @@ mod tests {
assert_eq!(file(&path).size().width, 3, "kept until forgotten");
forget(&path);
assert_eq!(file(&path).size().width, 5);
// A file that is no picture is remembered as such until forgotten,
// not read again on every refresh.
let junk = dir.join("junk");
std::fs::write(&junk, b"<!DOCTYPE html>").unwrap();
assert_eq!(file(&junk).size().width, 0);
std::fs::write(&junk, &png).unwrap();
assert_eq!(file(&junk).size().width, 0, "remembered");
forget(&junk);
assert_eq!(file(&junk).size().width, 3);
std::fs::remove_dir_all(dir).unwrap();
}
+3 -1
View File
@@ -409,7 +409,9 @@ impl App {
bridge.set_server_banner_mode(details.map_or(0, |d| vm::tree::banner_mode(d.banner_mode)));
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(
own_channel.map(|c| vm::tree::channel_title(c).0).unwrap_or_default().into(),
);
bridge.set_own_channel_topic(
own_channel.and_then(|c| c.topic.clone()).unwrap_or_default().into(),
);
+20 -3
View File
@@ -4,7 +4,9 @@
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
use voelin_model::{BannerMode, ChannelId, ClientInfo, GroupInfo, Presence, TreeRow, tree_rows};
use voelin_model::{
BannerMode, ChannelId, ChannelInfo, ClientInfo, GroupInfo, Presence, TreeRow, tree_rows,
};
use crate::app::{MemberItem, TreeItem};
use crate::settings::ClientPlaybackMap;
@@ -113,6 +115,13 @@ fn channel_label(name: &str) -> (&str, bool) {
(name, false)
}
/// A channel's name as shown, and whether it is a centred spacer. Only
/// top-level channels are spacers, as in TeamSpeak: a sub-channel keeps its
/// name as it is.
pub fn channel_title(channel: &ChannelInfo) -> (&str, bool) {
if channel.parent == 0 { channel_label(&channel.name) } else { (&channel.name, false) }
}
/// The rows of the tree, channels with their clients below.
pub fn rows(input: &TreeInput) -> Vec<TreeItem> {
let p = input.presence;
@@ -120,7 +129,7 @@ pub fn rows(input: &TreeInput) -> Vec<TreeItem> {
.into_iter()
.map(|row| match row {
TreeRow::Channel { depth, channel } => {
let (name, centered_spacer) = channel_label(&channel.name);
let (name, centered_spacer) = channel_title(channel);
TreeItem {
centered_spacer,
is_channel: true,
@@ -235,7 +244,7 @@ impl TreeInput<'_> {
&& 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),
Some(channel) if elsewhere => format!("In {}", channel_title(channel).0),
_ => status_of(c, talking),
};
MemberItem {
@@ -510,6 +519,14 @@ mod tests {
for name in ["[cspacerx]Games", "[cspacer2Games", "Games", "[spacer0]Games"] {
assert_eq!(channel_label(name), (name, false));
}
// Only top-level channels are spacers: a sub-channel keeps its name.
p.channels.get_mut(&3).unwrap().name = "[cspacer1]Chess".into();
let (t, c) = (HashSet::new(), HashSet::new());
let found = super::rows(&input(&p, &t, &c, &pb, "Chess", &e));
let chess = found.iter().find(|r| r.is_channel && r.id == 3).unwrap();
assert_eq!((chess.name.as_str(), chess.centered_spacer), ("[cspacer1]Chess", false));
assert_eq!(channel_title(&p.channels[&2]), ("Гамесы", true));
assert_eq!(channel_title(&p.channels[&3]), ("[cspacer1]Chess", false));
}
#[test]