Merge PR #11: myTeamSpeak avatar, badges and User Tag; banners; gateway speed and logs
Conflicts and how they were resolved: - CHANGELOG.md: both sides' lines kept under [Unreleased], each in its section; the badges line says TeamSpeak 6's verified badges come first. - crates/proto/UPSTREAM.md: #11's myTeamSpeak presentation stays patch 15; this branch's privilege key (default_token) patch becomes 16. - voelin-core web.rs: #11's downloader (retry hints, revalidation, proxies, per-host limits) as it is. The chat pictures' size limit sits on top as web::fetch_chat_picture, which narrows #11's Limits; fetch_within takes them by value. The badge pictures go through #11's fetch like banners. - voelin-core session.rs: both sides' fields kept (chat_pictures and unfetchable). Chat pictures ([img]) are an ImageRequest of their own (ChatPicture) instead of sharing Picture with banners, so #11's banner policy (retried every 15 minutes while shown, logged by address) does not apply to them: they keep the 1, 4, 16 s retries and are checked against the size they were asked for; their failures are logged by host at debug level. Badge pictures stay Pictures next to #11's banner loop (with its unfetchable-scheme log). - voelin-ui servers.rs: #11's imports (Instant, debug) with this branch's (no SharedString). Where the two badge features meet: the presence's badges are now voelin_model::shown_badges, TeamSpeak 6's client_signed_badges (what #11 sends for our account, and other TS6 users' verified badges) first, then client_badges, each once; so the badges chosen in Settings → My Account show in the tree and on the member card like other people's. Also: docs/ui.md describes My Account's badge choice and User Tag, the new ui.image_cache_mb default (256), and the picture downloads as #11 left them (16 at once, 6 per host, 128 MiB, the new timeouts, banner and badge retries, proxies, BMP and ICO, scaling down past 4096 pixels) with the chat pictures' own retries; the demo's login:account switch fills in a badge choice and a User Tag for screenshots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
This commit is contained in:
commit
7ab43bbf60
71 files changed
+9022
-763
No files matched your search
@@ -15,7 +15,7 @@ pub use chat::{ChatMessage, ChatTarget, FileRef, parse_file_links, relay_text, s
|
||||
pub use link::{Link, ServerLink, channel_path_id, join_channel_path, split_channel_path};
|
||||
pub use presence::{
|
||||
ChannelId, ChannelInfo, ClientId, ClientInfo, GroupId, GroupInfo, GroupNamingMode, GroupType,
|
||||
Presence, PresenceDelta, PresenceSnapshot, parse_badges,
|
||||
Presence, PresenceDelta, PresenceSnapshot, myts_avatar_url, parse_badges, shown_badges,
|
||||
};
|
||||
pub use server::{
|
||||
BannerMode, Capabilities, HostMessageMode, ServerDetails, ServerFlavor, ServerVersion,
|
||||
|
||||
@@ -98,6 +98,11 @@ pub struct ClientInfo {
|
||||
/// no avatar. A new hash means a new avatar.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub avatar: Option<String>,
|
||||
/// The myTeamSpeak avatar's picture (TeamSpeak 6, an HTTPS link from
|
||||
/// `client_myteamspeak_avatar`, [`myts_avatar_url`]): shown where the
|
||||
/// server has no avatar for the client.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub myts_avatar: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "is_zero_i32")]
|
||||
@@ -107,7 +112,7 @@ pub struct ClientInfo {
|
||||
pub talker: bool,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub channel_group: Option<GroupId>,
|
||||
/// Badge GUIDs (`client_badges`), in display order.
|
||||
/// Badge GUIDs, in display order ([`shown_badges`]).
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub badges: Vec<String>,
|
||||
/// Icon id (`client_icon_id`); 0: none.
|
||||
@@ -136,6 +141,48 @@ pub fn parse_badges(value: &str) -> Vec<String> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The badges a client shows: those a TeamSpeak 6 server verified
|
||||
/// (`client_signed_badges`, ids joined by `,`) first, then those of its
|
||||
/// `client_badges` ([`parse_badges`]), each once.
|
||||
pub fn shown_badges(badges: &str, signed: &str) -> Vec<String> {
|
||||
let signed = signed.split(',').map(str::trim).filter(|g| !g.is_empty()).map(str::to_owned);
|
||||
let mut shown: Vec<String> = Vec::new();
|
||||
for guid in signed.chain(parse_badges(badges)) {
|
||||
if !shown.iter().any(|g| g.eq_ignore_ascii_case(&guid)) {
|
||||
shown.push(guid);
|
||||
}
|
||||
}
|
||||
shown
|
||||
}
|
||||
|
||||
/// The picture to show of a `client_myteamspeak_avatar` value (TeamSpeak
|
||||
/// 6): `<state>,<url>;<state>,<url>…`, states as myTeamSpeak's
|
||||
/// `AvatarState` (1 do not disturb, 2 online, 3 away, 4 offline). As the
|
||||
/// official client reads it: an entry that is not `<number>,<url>` (an
|
||||
/// empty one too, from a trailing `;`) makes the whole value no avatar;
|
||||
/// the "online" picture is shown whatever the client's state (an unknown
|
||||
/// state counts as online), else away, do not disturb, offline, the first
|
||||
/// of a kind. Only an HTTPS link of at most 4 KiB.
|
||||
pub fn myts_avatar_url(value: &str) -> Option<String> {
|
||||
let mut best: Option<(u8, &str)> = None;
|
||||
for entry in value.split(';') {
|
||||
let mut parts = entry.split(',');
|
||||
let state: u32 = parts.next()?.trim().parse().ok()?;
|
||||
let url = parts.next()?.trim();
|
||||
let rank = match state {
|
||||
3 => 1,
|
||||
1 => 2,
|
||||
4 => 3,
|
||||
_ => 0,
|
||||
};
|
||||
if best.is_none_or(|(r, _)| rank < r) {
|
||||
best = Some((rank, url));
|
||||
}
|
||||
}
|
||||
let url = best?.1;
|
||||
(url.starts_with("https://") && url.len() <= 4096).then(|| url.to_owned())
|
||||
}
|
||||
|
||||
/// How a group's name is shown next to its members.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
@@ -348,6 +395,38 @@ mod tests {
|
||||
assert!(new.diff(&new).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn myts_avatars_as_the_official_client_reads_them() {
|
||||
let on = "https://a.example.test/on.png";
|
||||
assert_eq!(myts_avatar_url(&format!("3,https://a/away;2,{on}")).as_deref(), Some(on));
|
||||
// Away before do not disturb before offline; the first of a kind.
|
||||
assert_eq!(
|
||||
myts_avatar_url("4,https://a/off;1,https://a/dnd;3,https://a/away;3,https://a/b")
|
||||
.as_deref(),
|
||||
Some("https://a/away")
|
||||
);
|
||||
assert_eq!(
|
||||
myts_avatar_url("1,https://a/dnd;4,https://a/off").as_deref(),
|
||||
Some("https://a/dnd")
|
||||
);
|
||||
// An unknown state counts as online.
|
||||
assert_eq!(
|
||||
myts_avatar_url("3,https://a/away;9,https://a/x").as_deref(),
|
||||
Some("https://a/x")
|
||||
);
|
||||
// One bad entry spoils the value.
|
||||
for bad in ["", "2", "x,https://a/on", "2,https://a/on;", "2,https://a/on;;3,https://a/b"] {
|
||||
assert_eq!(myts_avatar_url(bad), None, "{bad:?}");
|
||||
}
|
||||
// Only HTTPS, and not endless.
|
||||
assert_eq!(myts_avatar_url("2,http://a/on"), None);
|
||||
assert_eq!(myts_avatar_url(&format!("2,https://a/{}", "x".repeat(4096))), None);
|
||||
// Older JSON without the field still loads.
|
||||
let client: ClientInfo =
|
||||
serde_json::from_str(r#"{"id":1,"nickname":"a","channel":1}"#).unwrap();
|
||||
assert_eq!(client.myts_avatar, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn badges_and_groups() {
|
||||
assert_eq!(
|
||||
@@ -358,6 +437,19 @@ mod tests {
|
||||
);
|
||||
assert!(parse_badges("").is_empty());
|
||||
assert!(parse_badges("Overwolf=1").is_empty());
|
||||
// TeamSpeak 6's verified badges first, each once.
|
||||
assert_eq!(
|
||||
shown_badges(
|
||||
"Overwolf=0:badges=c9e97536-5a2d-4c8e-a135-af404587a472,450f81c1-ab41-4211-a338-222fa94ed157",
|
||||
"450F81C1-AB41-4211-A338-222FA94ED157,1cb07348-34a4-4741-b50f-c41e584370f7"
|
||||
),
|
||||
[
|
||||
"450F81C1-AB41-4211-A338-222FA94ED157",
|
||||
"1cb07348-34a4-4741-b50f-c41e584370f7",
|
||||
"c9e97536-5a2d-4c8e-a135-af404587a472"
|
||||
]
|
||||
);
|
||||
assert!(shown_badges("", "").is_empty());
|
||||
let group = |id, sort_id| GroupInfo { id, sort_id, ..Default::default() };
|
||||
let groups = BTreeMap::from([(1, group(1, 20)), (2, group(2, 10)), (3, group(3, 10))]);
|
||||
let order: Vec<_> = Presence::sorted_groups(&groups).iter().map(|g| g.id).collect();
|
||||
|
||||
Reference in new issue
Block a user