diff --git a/connector/src/main.rs b/connector/src/main.rs index c18ae4f..1db0fad 100644 --- a/connector/src/main.rs +++ b/connector/src/main.rs @@ -75,6 +75,7 @@ struct ClientInfo { away_message: String, is_channel_commander: bool, country: String, + uid: String, } /// Human-facing entries for the Server tab's log-style notifications @@ -319,6 +320,7 @@ fn snapshot(con: &data::Connection) -> Event { away_message: c.away_message.clone().unwrap_or_default(), is_channel_commander: c.is_channel_commander, country: c.country_code.clone(), + uid: c.uid.as_ref().map(|u| u.to_string()).unwrap_or_default(), }) .collect(); Event::Channels { channels, clients } diff --git a/gateway/src/ts3/connection.ts b/gateway/src/ts3/connection.ts index f330dd0..c54bb65 100644 --- a/gateway/src/ts3/connection.ts +++ b/gateway/src/ts3/connection.ts @@ -32,6 +32,7 @@ export interface ClientInfo { awayMessage: string; isChannelCommander: boolean; country: string; + uid: string; } export type ServerLogEntry = @@ -122,6 +123,7 @@ export class Ts3Connection { away_message: string; is_channel_commander: boolean; country: string; + uid: string; } interface RawChannelInfo { @@ -192,6 +194,7 @@ export class Ts3Connection { awayMessage: c.away_message, isChannelCommander: c.is_channel_commander, country: c.country, + uid: c.uid, })), }); } else if (event.type === "privateMessage") { diff --git a/web/src/App.css b/web/src/App.css index f15ff4c..56213eb 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -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; diff --git a/web/src/App.tsx b/web/src/App.tsx index fd54d25..a06fc30 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -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(() => contacts.map((c) => ({ ...c }))); + const [selectedUid, setSelectedUid] = useState(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) => { + 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 ( +
+
e.stopPropagation()}> +
+ {t("contacts.title")} + +
+
+
+
+ + +
+
    + {draft.map((c) => ( +
  • setSelectedUid(c.uid)} + > + {onlineClients.some((cl) => cl.uid === c.uid) && } + {displayName(c)} + {c.ignored && " 🚫"} +
  • + ))} + {draft.length === 0 &&
  • {t("contacts.empty")}
  • } +
+
+
+ +
+ {(["acquaintance", "blocked", "friend"] as ContactCategory[]).map((cat) => ( + + ))} +
+ +
+ + + +
+
+
+
+ +
+ + +
+
+
+
+ ); +} + 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(() => loadContacts()); + const [contactsOpen, setContactsOpen] = useState(false); const whisperLogIdRef = useRef(0); const prevWhisperTargetsRef = useRef<{ channels: Set; clients: Set } | 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() { {extrasMenuOpen && (
- {[ - { icon: "🪪", label: t("menu.extras.identities"), shortcut: "Strg+I" }, - { icon: "📇", label: t("menu.extras.contacts"), shortcut: "Strg+Umschalt+O" }, - ].map((item) => ( - - ))} + +