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:
1 parent
68dd48d607
commit
9e0f0e05ad
19 files changed
+554
-30
No files matched your search
@@ -219,7 +219,8 @@ pub(crate) struct SessionView {
|
||||
pub avatars: HashMap<String, PathBuf>,
|
||||
/// Icons in the engine's cache, by icon id ([`Event::IconReady`]).
|
||||
pub icons: HashMap<u32, PathBuf>,
|
||||
/// Banners in the engine's cache, by address ([`Event::PictureReady`]).
|
||||
/// Banners and badges in the engine's cache, by address
|
||||
/// ([`Event::PictureReady`]).
|
||||
pub pictures: HashMap<String, PathBuf>,
|
||||
/// The server's icon id as its voice connection last told it
|
||||
/// ([`Event::ServerDetails`]); kept while disconnected, for the rail.
|
||||
@@ -1062,6 +1063,7 @@ impl App {
|
||||
self.refresh_toolbar();
|
||||
self.refresh_tree();
|
||||
self.refresh_chat();
|
||||
self.refresh_member_card();
|
||||
}
|
||||
}
|
||||
Event::Transfer { session, transfer, state } => {
|
||||
|
||||
@@ -536,6 +536,9 @@ fn demo_ui(app: &mut App) {
|
||||
clients[5].server_groups = vec![GROUP_MEMBER];
|
||||
clients[6].server_groups = vec![GROUP_GUEST];
|
||||
clients[7].server_groups = vec![GROUP_GUEST];
|
||||
// myTeamSpeak badges; their pictures arrive below.
|
||||
clients[0].badges = DEMO_BADGES[..2].iter().map(|g| g.to_string()).collect();
|
||||
clients[1].badges = DEMO_BADGES[2..].iter().map(|g| g.to_string()).collect();
|
||||
for c in clients {
|
||||
p.clients.insert(c.id, c);
|
||||
}
|
||||
@@ -1095,9 +1098,18 @@ const DEMO_SERVER_ICON: u32 = 3_120_211_001;
|
||||
const DEMO_ADMIN_ICON: u32 = 3_120_211_002;
|
||||
const DEMO_MOD_ICON: u32 = 3_120_211_003;
|
||||
const DEMO_MUSIC_ICON: u32 = 3_120_211_004;
|
||||
/// Real badge GUIDs: 20th Anniversary, TeamSpeak Jedi (Nova's), Gamescom
|
||||
/// 2019, Pride and Year of the Tiger 2022 (Lumen's).
|
||||
const DEMO_BADGES: [&str; 5] = [
|
||||
"4b27be5a-b92a-4b30-8b2d-14b59653f427",
|
||||
"64221fd1-706c-4bb2-ba55-996c39effa79",
|
||||
"b82a45a5-b235-4926-be77-de102222e5eb",
|
||||
"ceee2445-4fbf-4f06-9421-286f0f4e875a",
|
||||
"92356386-0451-4a97-87d9-10ff4f43260c",
|
||||
];
|
||||
|
||||
/// Avatars, icons and banners as the engine reports them once they are in
|
||||
/// its cache (here a folder of synthetic pictures in the temporary
|
||||
/// Avatars, icons, banners and badges as the engine reports them once they
|
||||
/// are in its cache (here a folder of synthetic pictures in the temporary
|
||||
/// directory).
|
||||
fn demo_pictures(app: &mut App) {
|
||||
let session = DEMO as u64;
|
||||
@@ -1134,6 +1146,19 @@ fn demo_pictures(app: &mut App) {
|
||||
let path = save(&icon.to_string(), demo_icon(color, shape));
|
||||
events.push(Event::IconReady { session, icon, path });
|
||||
}
|
||||
// Stand-ins for the badges' pictures on TeamSpeak's server.
|
||||
let badge_looks = [
|
||||
([242, 178, 44], Shape::Ring),
|
||||
([90, 170, 255], Shape::Moon),
|
||||
([45, 196, 132], Shape::Diamond),
|
||||
([240, 110, 160], Shape::Disc),
|
||||
([255, 140, 90], Shape::Diamond),
|
||||
];
|
||||
for (guid, (color, shape)) in DEMO_BADGES.into_iter().zip(badge_looks) {
|
||||
let Some(url) = voelin_model::badges::icon_url(guid) else { continue };
|
||||
let path = save(&format!("badge-{guid}"), demo_icon(color, shape));
|
||||
events.push(Event::PictureReady { session, url, path });
|
||||
}
|
||||
// Some people have pictures, the rest initials.
|
||||
for (sample_session, uid, seed) in [
|
||||
(session, "demo-2", 1),
|
||||
|
||||
@@ -53,6 +53,7 @@ impl App {
|
||||
.filter_map(|g| view.server_groups.iter().find(|i| i.id == *g))
|
||||
.map(|g| g.name.clone().into())
|
||||
.collect();
|
||||
let badges = vm::tree::badge_items(&client.badges, &view.pictures);
|
||||
Some(MemberCard {
|
||||
open: true,
|
||||
id: i32::from(id),
|
||||
@@ -63,6 +64,7 @@ impl App {
|
||||
status: vm::tree::status_of(client, view.talking.contains(&id)).into(),
|
||||
description: client.description.clone().unwrap_or_default().into(),
|
||||
groups: crate::app::model(groups),
|
||||
badges: crate::app::model(badges),
|
||||
country: client.country.clone().unwrap_or_default().into(),
|
||||
talk_power: client.talk_power,
|
||||
friend: contact.is_some_and(|c| c.relation == Relation::Friend),
|
||||
|
||||
@@ -6,10 +6,11 @@ use std::path::PathBuf;
|
||||
|
||||
pub use voelin_model::channel_title;
|
||||
use voelin_model::{
|
||||
BannerMode, ChannelId, ChannelInfo, ClientInfo, GroupInfo, Presence, Spacer, TreeRow, tree_rows,
|
||||
BannerMode, ChannelId, ChannelInfo, ClientInfo, GroupInfo, Presence, Spacer, TreeRow, badges,
|
||||
tree_rows,
|
||||
};
|
||||
|
||||
use crate::app::{MemberItem, TreeItem};
|
||||
use crate::app::{BadgeItem, MemberItem, TreeItem};
|
||||
use crate::settings::ClientPlaybackMap;
|
||||
use crate::vm::avatar;
|
||||
|
||||
@@ -27,6 +28,31 @@ pub fn banner(pictures: &HashMap<String, PathBuf>, url: Option<&str>) -> slint::
|
||||
avatar::image(url.and_then(|u| pictures.get(u)))
|
||||
}
|
||||
|
||||
/// A badge's picture, if the engine fetched it.
|
||||
fn badge_icon(pictures: &HashMap<String, PathBuf>, guid: &str) -> slint::Image {
|
||||
avatar::image(badges::icon_url(guid).and_then(|url| pictures.get(&url)))
|
||||
}
|
||||
|
||||
/// A client's badges for the member card: the first three in its order.
|
||||
/// One the app does not know is "Badge", with its GUID as description.
|
||||
pub fn badge_items(guids: &[String], pictures: &HashMap<String, PathBuf>) -> Vec<BadgeItem> {
|
||||
guids
|
||||
.iter()
|
||||
.take(badges::SHOWN)
|
||||
.map(|guid| {
|
||||
let (name, description) = match badges::info(guid) {
|
||||
Some(info) => (info.name.as_str(), info.description.as_str()),
|
||||
None => ("Badge", guid.as_str()),
|
||||
};
|
||||
BadgeItem {
|
||||
name: name.into(),
|
||||
description: description.into(),
|
||||
icon: badge_icon(pictures, guid),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// What the tree shows besides the presence.
|
||||
pub struct TreeInput<'a> {
|
||||
pub presence: &'a Presence,
|
||||
@@ -43,7 +69,7 @@ pub struct TreeInput<'a> {
|
||||
/// Icons in the engine's cache, by icon id (channel, group and client
|
||||
/// icons).
|
||||
pub icons: &'a HashMap<u32, PathBuf>,
|
||||
/// Banner pictures in the engine's cache, by address.
|
||||
/// Banners and badges in the engine's cache, by address.
|
||||
pub pictures: &'a HashMap<String, PathBuf>,
|
||||
/// The server groups in display order; members are grouped by the
|
||||
/// first one each client is in.
|
||||
@@ -77,6 +103,18 @@ impl TreeInput<'_> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The pictures of the badges a client shows that arrived, in its
|
||||
/// order; empty slots last.
|
||||
fn badges(&self, client: &ClientInfo) -> [slint::Image; badges::SHOWN] {
|
||||
let mut icons = client
|
||||
.badges
|
||||
.iter()
|
||||
.take(badges::SHOWN)
|
||||
.map(|guid| badge_icon(self.pictures, guid))
|
||||
.filter(|i| i.size().width > 0);
|
||||
std::array::from_fn(|_| icons.next().unwrap_or_default())
|
||||
}
|
||||
|
||||
/// The group a client is sorted under: the first of its server groups
|
||||
/// in display order.
|
||||
fn group_of(&self, client: &ClientInfo) -> Option<&GroupInfo> {
|
||||
@@ -178,6 +216,7 @@ pub fn rows(input: &TreeInput) -> Vec<TreeItem> {
|
||||
.copied()
|
||||
.unwrap_or_default();
|
||||
let mut icons = input.client_icons(client).into_iter();
|
||||
let [badge, badge_2, badge_3] = input.badges(client);
|
||||
TreeItem {
|
||||
is_channel: false,
|
||||
depth: depth as i32,
|
||||
@@ -197,6 +236,9 @@ pub fn rows(input: &TreeInput) -> Vec<TreeItem> {
|
||||
icon: icons.next().unwrap_or_default(),
|
||||
icon_2: icons.next().unwrap_or_default(),
|
||||
icon_3: icons.next().unwrap_or_default(),
|
||||
badge,
|
||||
badge_2,
|
||||
badge_3,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
@@ -279,6 +321,7 @@ impl TreeInput<'_> {
|
||||
Some(channel) if elsewhere => format!("In {}", channel_title(channel).0),
|
||||
_ => status_of(c, talking),
|
||||
};
|
||||
let [badge, badge_2, badge_3] = self.badges(c);
|
||||
MemberItem {
|
||||
id: c.id as i32,
|
||||
name: c.nickname.clone().into(),
|
||||
@@ -303,6 +346,9 @@ impl TreeInput<'_> {
|
||||
commander: c.channel_commander,
|
||||
recording: c.recording,
|
||||
talk_power: c.talk_power,
|
||||
badge,
|
||||
badge_2,
|
||||
badge_3,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -536,6 +582,46 @@ mod tests {
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
/// A client's badges: the first three in its order, on the card by name
|
||||
/// ("Badge" for one the app does not know), in the rows the pictures
|
||||
/// that arrived.
|
||||
#[test]
|
||||
fn badges_on_the_card_and_in_rows() {
|
||||
let dir = std::env::temp_dir().join(format!("voelin-tree-badges-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let guids: Vec<String> = [
|
||||
"4b27be5a-b92a-4b30-8b2d-14b59653f427",
|
||||
"00000000-0000-0000-0000-000000000000",
|
||||
"05114019-6b46-4b13-b5a1-e5179ef69fb5",
|
||||
"2bf80270-8efe-46dc-a472-3280a0479145",
|
||||
]
|
||||
.map(String::from)
|
||||
.into();
|
||||
let picture = |i: usize, width| {
|
||||
(badges::icon_url(&guids[i]).unwrap(), picture_file(&dir, &format!("badge-{i}"), width))
|
||||
};
|
||||
let e = Extras {
|
||||
pictures: HashMap::from([picture(0, 3), picture(2, 5), picture(3, 7)]),
|
||||
..Default::default()
|
||||
};
|
||||
let width = |i: &slint::Image| i.size().width;
|
||||
let card = badge_items(&guids, &e.pictures);
|
||||
let names: Vec<_> = card.iter().map(|b| b.name.as_str()).collect();
|
||||
assert_eq!(names, ["20th Anniversary", "Badge", "April Fools!"]);
|
||||
assert_eq!(card[1].description.as_str(), guids[1]);
|
||||
assert_eq!(card.iter().map(|b| width(&b.icon)).collect::<Vec<_>>(), [3, 0, 5]);
|
||||
|
||||
let mut p = presence();
|
||||
p.clients.get_mut(&11).unwrap().badges = guids;
|
||||
let (t, c, pb) = (HashSet::new(), HashSet::new(), ClientPlaybackMap::new());
|
||||
let tree = input(&p, &t, &c, &pb, "", &e);
|
||||
let bob = rows(&tree).into_iter().find(|r| !r.is_channel && r.id == 11).unwrap();
|
||||
assert_eq!([&bob.badge, &bob.badge_2, &bob.badge_3].map(width), [3, 5, 0]);
|
||||
let bob = members(&tree).into_iter().find(|m| m.id == 11).unwrap();
|
||||
assert_eq!([&bob.badge, &bob.badge_2, &bob.badge_3].map(width), [3, 5, 0]);
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spacer_rows_keep_tree_identity() {
|
||||
let mut p = presence();
|
||||
|
||||
Reference in new issue
Block a user