ui: other people's badges, named on the member card and drawn after their name

Clients only send badge GUIDs. voelin-model names them from tsclientlib's
table plus the newer entries of TeamSpeak's own list, and the engine fetches
the first three pictures of each client from TeamSpeak's badge server
(<guid>/<filename>.svg, checked to answer) with the banners, under
cache.fetch_images.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
This commit is contained in:
Claude committed 2026-10-06 20:16:37 +00:00
1 parent 68dd48d607
commit 9e0f0e05ad
19 files changed
+554 -30

No files matched your search

+6 -5
View File
@@ -39,9 +39,9 @@
//! [`Event::Poke`]), private messages to any client (a
//! [`ChatTarget::Private`] chat, stored under the peer's unique id), the
//! channels' file browsers, avatars and icons ([`files`], cached in
//! [`cache`]) and offline messages ([`offline`]). The host banner and
//! channel banners are pictures on the web, fetched into the same cache
//! ([`Event::PictureReady`]). Contacts (friends, blocked people, per-person
//! [`cache`]) and offline messages ([`offline`]). The host banner, channel
//! banners and the clients' badges are pictures on the web, fetched into the
//! same cache ([`Event::PictureReady`]). Contacts (friends, blocked people, per-person
//! volume) are engine-wide ([`contacts`]).
mod audio;
@@ -679,8 +679,9 @@ pub enum Event {
path: PathBuf,
},
/// A picture on the web is in the cache: the host banner
/// ([`ServerDetails::banner_gfx_url`]) or a channel's
/// ([`voelin_model::ChannelInfo::banner_gfx_url`]) at `url` (setting
/// ([`ServerDetails::banner_gfx_url`]), a channel's
/// ([`voelin_model::ChannelInfo::banner_gfx_url`]) or a badge's
/// ([`voelin_model::badges::icon_url`]) at `url` (setting
/// `cache.fetch_images`). Comes again when the host banner was reloaded
/// (`banner_gfx_interval_s`, at least a minute): the file at `path`
/// changed.
+59 -7
View File
@@ -19,7 +19,7 @@ use tracing::{debug, warn};
use tsclientlib::ClientId;
use voelin_audio::AudioSettings;
use voelin_gateway_proto::{ErrorCode, HistoryEntry, StreamEntry, StreamSpec, feature};
use voelin_model::{ChatMessage, ChatTarget, GroupInfo, Presence, ServerDetails};
use voelin_model::{ChatMessage, ChatTarget, GroupInfo, Presence, ServerDetails, badges};
use voelin_stream::ClientState;
use crate::audio::{self, AudioEvent, AudioHandle, AudioIn};
@@ -224,7 +224,8 @@ struct Session {
avatars: HashMap<String, String>,
/// Icons reported or being fetched, voice only.
icons: HashSet<u32>,
/// Pictures on the web (banners) reported or being fetched, by address.
/// Pictures on the web (banners, badges) reported or being fetched, by
/// address.
pictures: HashSet<String>,
image_epoch: u64,
images_enabled: bool,
@@ -1007,8 +1008,9 @@ impl Session {
|| (self.voice_presence.is_some() && files::server_image(url).is_some())
}
/// Fetch the banners of the presence shown (any source) that are new,
/// and have the host banner reloaded as often as the server asks.
/// Fetch the banners and the clients' badges of the presence shown (any
/// source) that are new, and have the host banner reloaded as often as
/// the server asks.
fn fetch_pictures(&mut self, p: &Presence) {
let enabled = self.settings.current().get(&CACHE_FETCH_IMAGES);
let reload = Some((&p.server.banner_gfx_url, p.server.banner_gfx_interval_s))
@@ -1039,10 +1041,16 @@ impl Session {
if !enabled {
return;
}
let urls: HashSet<_> = std::iter::once(&p.server.banner_gfx_url)
.chain(p.channels.values().filter_map(|c| c.banner_gfx_url.as_ref()))
// The badges shown, from TeamSpeak's server.
let badge_urls = p
.clients
.values()
.flat_map(|c| c.badges.iter().take(badges::SHOWN))
.filter_map(|guid| badges::icon_url(guid));
let urls: HashSet<String> = std::iter::once(p.server.banner_gfx_url.clone())
.chain(p.channels.values().filter_map(|c| c.banner_gfx_url.clone()))
.chain(badge_urls)
.filter(|u| self.can_fetch_picture(u))
.cloned()
.collect();
self.pictures.retain(|url| urls.contains(url));
for url in &urls {
@@ -2293,6 +2301,50 @@ mod banner_tests {
assert!(timer.is_finished());
}
/// The pictures of the badges clients show (the first three of each, the
/// known ones) come with the presence, and only with
/// `cache.fetch_images`.
#[tokio::test]
async fn badge_pictures_come_with_the_presence() {
let (mut session, _) = session("badges");
let guids = [
"4b27be5a-b92a-4b30-8b2d-14b59653f427",
"00000000-0000-0000-0000-000000000000",
"2bf80270-8efe-46dc-a472-3280a0479145",
"05114019-6b46-4b13-b5a1-e5179ef69fb5",
];
let mut presence = Presence::default();
let client = voelin_model::ClientInfo {
id: 1,
badges: guids.iter().map(|g| g.to_string()).collect(),
..Default::default()
};
presence.clients.insert(1, client);
// Own the downloads, so none goes to the network.
let cache = session.cache.current();
let urls: Vec<String> = guids.iter().filter_map(|g| badges::icon_url(g)).collect();
for url in &urls {
let _pending = cache.fetch(&cache::picture_key(url).unwrap(), false, Box::new(|_| {}));
}
session.settings.current().set(&CACHE_FETCH_IMAGES, false).unwrap();
session.fetch_pictures(&presence);
assert!(session.pictures.is_empty());
session.settings.current().set(&CACHE_FETCH_IMAGES, true).unwrap();
session.fetch_pictures(&presence);
let mut fetched: Vec<_> = session.pictures.iter().cloned().collect();
fetched.sort();
let mut shown = urls[..2].to_vec();
shown.sort();
assert_eq!(
fetched, shown,
"the unknown second badge has no picture; the fourth is not shown"
);
// Gone with the client.
session.fetch_pictures(&Presence::default());
assert!(session.pictures.is_empty());
let _ = std::fs::remove_dir_all(cache.dir());
}
/// The priority speakers and the server's dimming reach the audio thread
/// once, and again when either changes.
#[tokio::test]
+2 -2
View File
@@ -1125,11 +1125,11 @@ pub static CACHE_MAX_MB: Key<u64> = Key::new(
|| 256,
);
/// Download the avatars, icons and banners of servers we are on.
/// Download the avatars, icons, banners and badges of servers we are on.
pub static CACHE_FETCH_IMAGES: Key<bool> = Key::new(
"cache.fetch_images",
Kind::Bool,
"Download avatars, icons and banners of the servers we are on.",
"Download avatars, icons, banners and badges of the servers we are on.",
|| true,
);
+3 -1
View File
@@ -1,5 +1,7 @@
//! Pictures from the web: the host banner and TeamSpeak 6 channel banners,
//! which servers give as `http(s)` addresses on any host.
//! which servers give as `http(s)` addresses on any host, and the pictures
//! of the clients' badges on TeamSpeak's server
//! ([`voelin_model::badges::icon_url`]).
//!
//! They go into the engine's cache ([`crate::cache`], named by the MD5 hash
//! of the address) like avatars and icons, and only with