Add Kontakte (contacts) feature

Threads the client's persistent unique identifier through the
connector/gateway/frontend pipeline (previously only the ephemeral
session client id was exposed) so contacts can be keyed by the same
person across reconnects, not by name. The Kontakte dialog supports
adding currently-online clients, per-contact category/phonetic name,
ignoring (filters their chat messages), and quick-whisper/show actions
that reuse existing whisper and channel-selection logic.
This commit is contained in:
Moepchi committed 2026-08-04 18:37:49 +02:00
1 parent f5cb4dd160
commit 7bcced06fd
6 files changed
+375 -14

No files matched your search

+90
View File
@@ -783,6 +783,96 @@
width: 560px;
}
.ts-contacts-dialog {
width: 640px;
}
.ts-contacts-body {
display: flex;
gap: 0.75rem;
padding: 0.75rem;
}
.ts-contacts-list-col {
flex: 1;
display: flex;
flex-direction: column;
gap: 0.4rem;
min-width: 0;
}
.ts-contacts-fields-col {
flex: 1;
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.ts-contacts-list {
list-style: none;
margin: 0;
padding: 0;
border: 1px solid var(--border-soft);
border-radius: 3px;
height: 220px;
overflow-y: auto;
}
.ts-contacts-list-item {
padding: 0.3rem 0.5rem;
cursor: pointer;
font-size: 12px;
border-bottom: 1px solid var(--border-soft);
}
.ts-contacts-list-item:hover {
background: var(--hover-bg, rgba(255, 255, 255, 0.05));
}
.ts-contacts-list-item-selected {
background: var(--accent-soft, rgba(78, 161, 247, 0.2));
}
.ts-contacts-list-empty {
padding: 1rem;
text-align: center;
color: var(--text-muted);
}
.ts-contacts-online-dot {
display: inline-block;
width: 6px;
height: 6px;
border-radius: 50%;
background: #4caf50;
margin-right: 0.4rem;
}
.ts-contacts-category-acquaintance {
color: var(--text);
}
.ts-contacts-category-friend {
color: #4caf50;
}
.ts-contacts-category-blocked {
color: #e5534b;
}
.ts-contacts-category-group {
display: flex;
gap: 0.75rem;
font-size: 12px;
}
.ts-contacts-actions {
display: flex;
gap: 0.4rem;
padding-top: 0.4rem;
border-top: 1px solid var(--border-soft);
}
.ts-whisper-history-list {
height: 260px;
overflow-y: auto;
+242 -10
View File
@@ -146,6 +146,27 @@ interface WhisperLogEntry {
description: string;
}
type ContactCategory = "acquaintance" | "blocked" | "friend";
interface Contact {
uid: string;
customName: string;
category: ContactCategory;
phoneticName: string;
ignored: boolean;
}
const CONTACTS_KEY = "webspeak3:contacts";
function loadContacts(): Contact[] {
try {
const raw = localStorage.getItem(CONTACTS_KEY);
return raw ? (JSON.parse(raw) as Contact[]) : [];
} catch {
return [];
}
}
interface MessagePreset {
name: string;
message: string;
@@ -202,6 +223,7 @@ interface ClientInfo {
awayMessage: string;
isChannelCommander: boolean;
country: string;
uid: string;
}
/** Converts an ISO 3166-1 alpha-2 country code (e.g. "DE") to its flag emoji
@@ -1106,6 +1128,181 @@ function WhisperHistoryDialog({
);
}
function ContactsDialog({
contacts,
onlineClients,
onSave,
onWhisper,
onShow,
onClose,
}: {
contacts: Contact[];
onlineClients: ClientInfo[];
onSave: (contacts: Contact[]) => void;
onWhisper: (clientId: number) => void;
onShow: (clientId: number) => void;
onClose: () => void;
}) {
const t = useT();
const backdrop = useBackdropDismiss(onClose);
const [draft, setDraft] = useState<Contact[]>(() => contacts.map((c) => ({ ...c })));
const [selectedUid, setSelectedUid] = useState<string | null>(draft[0]?.uid ?? null);
const [addClientId, setAddClientId] = useState("");
const selected = draft.find((c) => c.uid === selectedUid) ?? null;
const displayName = (c: Contact) => {
const online = onlineClients.find((cl) => cl.uid === c.uid);
return c.customName || online?.name || c.uid;
};
const updateSelected = (patch: Partial<Contact>) => {
if (!selectedUid) return;
setDraft((prev) => prev.map((c) => (c.uid === selectedUid ? { ...c, ...patch } : c)));
};
const save = (next: Contact[]) => {
setDraft(next);
onSave(next);
};
const handleAdd = () => {
const client = onlineClients.find((c) => String(c.id) === addClientId);
if (!client || !client.uid || draft.some((c) => c.uid === client.uid)) return;
const contact: Contact = {
uid: client.uid,
customName: client.name,
category: "acquaintance",
phoneticName: "",
ignored: false,
};
save([...draft, contact]);
setSelectedUid(contact.uid);
setAddClientId("");
};
const handleRemove = () => {
if (!selectedUid) return;
save(draft.filter((c) => c.uid !== selectedUid));
setSelectedUid(null);
};
const addableClients = onlineClients.filter(
(c) => c.uid && !draft.some((contact) => contact.uid === c.uid)
);
const selectedOnlineClient = selected ? onlineClients.find((c) => c.uid === selected.uid) : undefined;
return (
<div className="ts-dialog-backdrop" {...backdrop}>
<div className="ts-dialog ts-contacts-dialog" onClick={(e) => e.stopPropagation()}>
<div className="ts-dialog-titlebar">
<span>{t("contacts.title")}</span>
<button onClick={onClose} title={t("dialog.close")}>
✕
</button>
</div>
<div className="ts-contacts-body">
<div className="ts-contacts-list-col">
<div className="ts-dialog-row">
<select value={addClientId} onChange={(e) => setAddClientId(e.target.value)}>
<option value="">{t("contacts.addOnlineClient")}</option>
{addableClients.map((c) => (
<option key={c.id} value={c.id}>
{c.name}
</option>
))}
</select>
<button disabled={!addClientId} onClick={handleAdd}>
{t("contacts.add")}
</button>
</div>
<ul className="ts-contacts-list">
{draft.map((c) => (
<li
key={c.uid}
className={`ts-contacts-list-item ts-contacts-category-${c.category}${c.uid === selectedUid ? " ts-contacts-list-item-selected" : ""}`}
onClick={() => setSelectedUid(c.uid)}
>
{onlineClients.some((cl) => cl.uid === c.uid) && <span className="ts-contacts-online-dot" />}
{displayName(c)}
{c.ignored && " 🚫"}
</li>
))}
{draft.length === 0 && <li className="ts-contacts-list-empty">{t("contacts.empty")}</li>}
</ul>
</div>
<div className="ts-contacts-fields-col">
<label className="ts-dialog-field">
{t("contacts.customName")}
<input
disabled={!selected}
value={selected?.customName ?? ""}
onChange={(e) => updateSelected({ customName: e.target.value })}
/>
</label>
<div className="ts-contacts-category-group">
{(["acquaintance", "blocked", "friend"] as ContactCategory[]).map((cat) => (
<label key={cat} className="ts-dialog-checkbox">
<input
type="radio"
name="contact-category"
disabled={!selected}
checked={selected?.category === cat}
onChange={() => updateSelected({ category: cat })}
/>
{t(`contacts.category.${cat}`)}
</label>
))}
</div>
<label className="ts-dialog-field">
{t("contacts.phoneticName")}
<input
disabled={!selected}
value={selected?.phoneticName ?? ""}
onChange={(e) => updateSelected({ phoneticName: e.target.value })}
/>
</label>
<div className="ts-contacts-actions">
<button
disabled={!selectedOnlineClient}
onClick={() => selectedOnlineClient && onShow(selectedOnlineClient.id)}
>
{t("contacts.show")}
</button>
<button disabled={!selected} onClick={() => updateSelected({ ignored: !selected?.ignored })}>
{selected?.ignored ? t("contacts.unignore") : t("contacts.ignore")}
</button>
<button
disabled={!selectedOnlineClient}
onClick={() => selectedOnlineClient && onWhisper(selectedOnlineClient.id)}
>
{t("contacts.whisper")}
</button>
</div>
</div>
</div>
<div className="ts-dialog-buttons">
<button onClick={handleRemove} disabled={!selected}>
{t("contacts.remove")}
</button>
<div className="ts-dialog-buttons-right">
<button disabled title={t("clientContext.notSupported")}>
{t("contacts.preferences")}
</button>
<button
onClick={() => {
onSave(draft);
onClose();
}}
>
{t("dialog.close")}
</button>
</div>
</div>
</div>
</div>
);
}
function AwayDialog({
message,
presets,
@@ -1850,6 +2047,8 @@ function AppInner() {
const [changeNicknameOpen, setChangeNicknameOpen] = useState(false);
const [nicknameDraft, setNicknameDraft] = useState("");
const nicknameBackdrop = useBackdropDismiss(() => setChangeNicknameOpen(false));
const [contacts, setContacts] = useState<Contact[]>(() => loadContacts());
const [contactsOpen, setContactsOpen] = useState(false);
const whisperLogIdRef = useRef(0);
const prevWhisperTargetsRef = useRef<{ channels: Set<number>; clients: Set<number> } | null>(null);
@@ -1888,6 +2087,16 @@ function AppInner() {
localStorage.setItem(COLLECTED_URLS_KEY, JSON.stringify(collectedUrls));
}, [collectedUrls]);
useEffect(() => {
localStorage.setItem(CONTACTS_KEY, JSON.stringify(contacts));
}, [contacts]);
const isSenderIgnored = (senderName: string) => {
const senderClient = clients.find((c) => c.name === senderName);
if (!senderClient?.uid) return false;
return contacts.some((c) => c.uid === senderClient.uid && c.ignored);
};
const recordUrlsFromMessage = (message: string, sender: string) => {
const found = message.match(URL_REGEX);
if (!found) return;
@@ -2137,16 +2346,19 @@ function AppInner() {
break;
}
case "chatMessage":
if (isSenderIgnored(data.from)) break;
setChat((prev) => [...prev, { from: data.from, message: data.message }]);
recordUrlsFromMessage(data.message, data.from);
if (data.from !== connectNickname) void playSound("message");
break;
case "serverMessage":
if (isSenderIgnored(data.from)) break;
setServerChat((prev) => [...prev, { from: data.from, message: data.message }]);
recordUrlsFromMessage(data.message, data.from);
if (data.from !== connectNickname) void playSound("message");
break;
case "privateMessage":
if (!data.fromSelf && isSenderIgnored(data.partnerName)) break;
setPmThreads((prev) => {
const existing = prev[data.partnerId];
const thread: PmThread = existing ?? {
@@ -2938,16 +3150,22 @@ function AppInner() {
</span>
{extrasMenuOpen && (
<div className="ts-menu">
{[
{ icon: "🪪", label: t("menu.extras.identities"), shortcut: "Strg+I" },
{ icon: "📇", label: t("menu.extras.contacts"), shortcut: "Strg+Umschalt+O" },
].map((item) => (
<button key={item.label} className="ts-menu-item" disabled>
<span className="ts-menu-item-icon">{item.icon}</span>
<span className="ts-menu-item-label">{item.label}</span>
{item.shortcut && <span className="ts-menu-item-shortcut">{item.shortcut}</span>}
</button>
))}
<button className="ts-menu-item" disabled>
<span className="ts-menu-item-icon">🪪</span>
<span className="ts-menu-item-label">{t("menu.extras.identities")}</span>
<span className="ts-menu-item-shortcut">Strg+I</span>
</button>
<button
className="ts-menu-item"
onClick={() => {
setContactsOpen(true);
setExtrasMenuOpen(false);
}}
>
<span className="ts-menu-item-icon">📇</span>
<span className="ts-menu-item-label">{t("menu.extras.contacts")}</span>
<span className="ts-menu-item-shortcut">Strg+Umschalt+O</span>
</button>
<button
className="ts-menu-item"
onClick={() => {
@@ -3277,6 +3495,20 @@ function AppInner() {
/>
)}
{contactsOpen && (
<ContactsDialog
contacts={contacts}
onlineClients={clients}
onSave={setContacts}
onWhisper={toggleWhisperClient}
onShow={(clientId) => {
const client = clients.find((c) => c.id === clientId);
if (client) setSelected({ type: "channel", id: client.channel });
}}
onClose={() => setContactsOpen(false)}
/>
)}
{awayDialogOpen && (
<AwayDialog
message={awayDialogMessage}
+6 -4
View File
@@ -29,6 +29,7 @@ interface DemoClient {
awayMessage: string;
isChannelCommander: boolean;
country: string;
uid: string;
}
const DEMO_CHANNELS: DemoChannel[] = [
@@ -38,10 +39,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, 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" },
{ id: 102, channel: 1, name: "Alex", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: true, country: "US", uid: "demo-uid-alex" },
{ id: 103, channel: 2, name: "Sam", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "GB", uid: "demo-uid-sam" },
{ id: 104, channel: 2, name: "Jordan", inputMuted: true, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "CA", uid: "demo-uid-jordan" },
{ id: 105, channel: 3, name: "Riley", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: true, awayMessage: "brb, grabbing coffee", isChannelCommander: false, country: "DE", uid: "demo-uid-riley" },
];
const SELF_ID = 101;
@@ -220,6 +221,7 @@ export class DemoSocket {
awayMessage: "",
isChannelCommander: false,
country: "",
uid: "demo-uid-self",
};
this.emit({ type: "channels", channels: DEMO_CHANNELS, clients: [self, ...DEMO_NPCS] });
}
+32
View File
@@ -127,6 +127,22 @@ const translations: Record<Lang, Record<string, string>> = {
"menu.self.setPhoneticNickname": "Phonetischen Nicknamen setzen",
"menu.self.connectionInfo": "Verbindungsinformationen",
"contacts.title": "Kontakte",
"contacts.addOnlineClient": "Online-Client auswählen...",
"contacts.add": "Hinzufügen",
"contacts.remove": "Entfernen",
"contacts.empty": "Noch keine Kontakte.",
"contacts.customName": "Benutzerdefinierter Name:",
"contacts.category.acquaintance": "Bekannter",
"contacts.category.blocked": "Blockiert",
"contacts.category.friend": "Freund",
"contacts.phoneticName": "Phonetischer Name:",
"contacts.show": "Anzeige",
"contacts.ignore": "Ignorieren",
"contacts.unignore": "Nicht mehr ignorieren",
"contacts.whisper": "Whispern",
"contacts.preferences": "Voreinstellungen",
"favorites.title": "🔖 myTeamSpeak Favoriten",
"favorites.synced": "Synchronisierte Favoriten",
"favorites.notLoggedIn": "Nicht angemeldet",
@@ -418,6 +434,22 @@ const translations: Record<Lang, Record<string, string>> = {
"menu.self.setPhoneticNickname": "Set Phonetic Nickname",
"menu.self.connectionInfo": "Connection Info",
"contacts.title": "Contacts",
"contacts.addOnlineClient": "Select an online client...",
"contacts.add": "Add",
"contacts.remove": "Remove",
"contacts.empty": "No contacts yet.",
"contacts.customName": "Custom Name:",
"contacts.category.acquaintance": "Acquaintance",
"contacts.category.blocked": "Blocked",
"contacts.category.friend": "Friend",
"contacts.phoneticName": "Phonetic Name:",
"contacts.show": "Show",
"contacts.ignore": "Ignore",
"contacts.unignore": "Unignore",
"contacts.whisper": "Whisper",
"contacts.preferences": "Preferences",
"favorites.title": "🔖 myTeamSpeak Bookmarks",
"favorites.synced": "Synced Bookmarks",
"favorites.notLoggedIn": "Not logged in",