mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 09:52:50 +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
@@ -68,6 +68,7 @@ struct ClientInfo {
|
|||||||
away: bool,
|
away: bool,
|
||||||
away_message: String,
|
away_message: String,
|
||||||
is_channel_commander: bool,
|
is_channel_commander: bool,
|
||||||
|
country: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Human-facing entries for the Server tab's log-style notifications
|
/// Human-facing entries for the Server tab's log-style notifications
|
||||||
@@ -308,6 +309,7 @@ fn snapshot(con: &data::Connection) -> Event {
|
|||||||
away: c.away_message.is_some(),
|
away: c.away_message.is_some(),
|
||||||
away_message: c.away_message.clone().unwrap_or_default(),
|
away_message: c.away_message.clone().unwrap_or_default(),
|
||||||
is_channel_commander: c.is_channel_commander,
|
is_channel_commander: c.is_channel_commander,
|
||||||
|
country: c.country_code.clone(),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
Event::Channels { channels, clients }
|
Event::Channels { channels, clients }
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export interface ClientInfo {
|
|||||||
away: boolean;
|
away: boolean;
|
||||||
awayMessage: string;
|
awayMessage: string;
|
||||||
isChannelCommander: boolean;
|
isChannelCommander: boolean;
|
||||||
|
country: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ServerLogEntry =
|
export type ServerLogEntry =
|
||||||
@@ -115,6 +116,7 @@ export class Ts3Connection {
|
|||||||
away: boolean;
|
away: boolean;
|
||||||
away_message: string;
|
away_message: string;
|
||||||
is_channel_commander: boolean;
|
is_channel_commander: boolean;
|
||||||
|
country: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RawChannelInfo {
|
interface RawChannelInfo {
|
||||||
@@ -182,6 +184,7 @@ export class Ts3Connection {
|
|||||||
away: c.away,
|
away: c.away,
|
||||||
awayMessage: c.away_message,
|
awayMessage: c.away_message,
|
||||||
isChannelCommander: c.is_channel_commander,
|
isChannelCommander: c.is_channel_commander,
|
||||||
|
country: c.country,
|
||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
} else if (event.type === "privateMessage") {
|
} else if (event.type === "privateMessage") {
|
||||||
|
|||||||
@@ -159,6 +159,16 @@ interface ClientInfo {
|
|||||||
away: boolean;
|
away: boolean;
|
||||||
awayMessage: string;
|
awayMessage: string;
|
||||||
isChannelCommander: boolean;
|
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() {
|
function ChannelIcon() {
|
||||||
@@ -266,6 +276,7 @@ function ChannelTree({
|
|||||||
title={c.id === ownClientId ? undefined : `${t("tree.privateChatWith")} ${c.name}`}
|
title={c.id === ownClientId ? undefined : `${t("tree.privateChatWith")} ${c.name}`}
|
||||||
>
|
>
|
||||||
<ClientIcon />
|
<ClientIcon />
|
||||||
|
{countryFlag(c.country) && <span title={c.country}>{countryFlag(c.country)}</span>}
|
||||||
<span>{c.name}</span>
|
<span>{c.name}</span>
|
||||||
{c.away && c.awayMessage && (
|
{c.away && c.awayMessage && (
|
||||||
<span className="ts-client-away-message">({c.awayMessage})</span>
|
<span className="ts-client-away-message">({c.awayMessage})</span>
|
||||||
|
|||||||
+6
-4
@@ -28,6 +28,7 @@ interface DemoClient {
|
|||||||
away: boolean;
|
away: boolean;
|
||||||
awayMessage: string;
|
awayMessage: string;
|
||||||
isChannelCommander: boolean;
|
isChannelCommander: boolean;
|
||||||
|
country: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEMO_CHANNELS: DemoChannel[] = [
|
const DEMO_CHANNELS: DemoChannel[] = [
|
||||||
@@ -37,10 +38,10 @@ const DEMO_CHANNELS: DemoChannel[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const DEMO_NPCS: DemoClient[] = [
|
const DEMO_NPCS: DemoClient[] = [
|
||||||
{ id: 102, channel: 1, name: "Alex", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: true },
|
{ 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 },
|
{ 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 },
|
{ 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 },
|
{ 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;
|
const SELF_ID = 101;
|
||||||
@@ -218,6 +219,7 @@ export class DemoSocket {
|
|||||||
away: false,
|
away: false,
|
||||||
awayMessage: "",
|
awayMessage: "",
|
||||||
isChannelCommander: false,
|
isChannelCommander: false,
|
||||||
|
country: "",
|
||||||
};
|
};
|
||||||
this.emit({ type: "channels", channels: DEMO_CHANNELS, clients: [self, ...DEMO_NPCS] });
|
this.emit({ type: "channels", channels: DEMO_CHANNELS, clients: [self, ...DEMO_NPCS] });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user