mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42:49 +08:00
Show country flags next to client nicknames
Threads TeamSpeak's per-client country_code field through the connector snapshot and gateway relay, then renders it as a flag emoji (regional indicator symbols, no image assets needed) next to the nickname. Renders nothing when the server has no geo-IP data for a client (most common on non-official/self-hosted servers).
This commit is contained in:
1 parent
0529ab72f1
commit
3644ae7c41
4 files changed
+22
-4
No files matched your search
@@ -159,6 +159,16 @@ interface ClientInfo {
|
||||
away: boolean;
|
||||
awayMessage: string;
|
||||
isChannelCommander: boolean;
|
||||
country: string;
|
||||
}
|
||||
|
||||
/** Converts an ISO 3166-1 alpha-2 country code (e.g. "DE") to its flag emoji
|
||||
* via Unicode regional indicator symbols. Returns null for codes the server
|
||||
* doesn't report (empty string - common when geo-IP isn't configured). */
|
||||
function countryFlag(code: string): string | null {
|
||||
if (!/^[A-Za-z]{2}$/.test(code)) return null;
|
||||
const codePoints = [...code.toUpperCase()].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65);
|
||||
return String.fromCodePoint(...codePoints);
|
||||
}
|
||||
|
||||
function ChannelIcon() {
|
||||
@@ -266,6 +276,7 @@ function ChannelTree({
|
||||
title={c.id === ownClientId ? undefined : `${t("tree.privateChatWith")} ${c.name}`}
|
||||
>
|
||||
<ClientIcon />
|
||||
{countryFlag(c.country) && <span title={c.country}>{countryFlag(c.country)}</span>}
|
||||
<span>{c.name}</span>
|
||||
{c.away && c.awayMessage && (
|
||||
<span className="ts-client-away-message">({c.awayMessage})</span>
|
||||
|
||||
+6
-4
@@ -28,6 +28,7 @@ interface DemoClient {
|
||||
away: boolean;
|
||||
awayMessage: string;
|
||||
isChannelCommander: boolean;
|
||||
country: string;
|
||||
}
|
||||
|
||||
const DEMO_CHANNELS: DemoChannel[] = [
|
||||
@@ -37,10 +38,10 @@ const DEMO_CHANNELS: DemoChannel[] = [
|
||||
];
|
||||
|
||||
const DEMO_NPCS: DemoClient[] = [
|
||||
{ id: 102, channel: 1, name: "Alex", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: true },
|
||||
{ id: 103, channel: 2, name: "Sam", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false },
|
||||
{ id: 104, channel: 2, name: "Jordan", inputMuted: true, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false },
|
||||
{ id: 105, channel: 3, name: "Riley", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: true, awayMessage: "brb, grabbing coffee", isChannelCommander: false },
|
||||
{ id: 102, channel: 1, name: "Alex", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: true, country: "US" },
|
||||
{ id: 103, channel: 2, name: "Sam", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "GB" },
|
||||
{ id: 104, channel: 2, name: "Jordan", inputMuted: true, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "CA" },
|
||||
{ id: 105, channel: 3, name: "Riley", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: true, awayMessage: "brb, grabbing coffee", isChannelCommander: false, country: "DE" },
|
||||
];
|
||||
|
||||
const SELF_ID = 101;
|
||||
@@ -218,6 +219,7 @@ export class DemoSocket {
|
||||
away: false,
|
||||
awayMessage: "",
|
||||
isChannelCommander: false,
|
||||
country: "",
|
||||
};
|
||||
this.emit({ type: "channels", channels: DEMO_CHANNELS, clients: [self, ...DEMO_NPCS] });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user