diff --git a/web/src/App.css b/web/src/App.css index eaa36c5..7c6b56f 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -4851,3 +4851,24 @@ .ts-notify-tree select { font-size: 1em; } +.ts-notify-text { + position: relative; +} +.ts-notify-text > summary { + cursor: pointer; + list-style: none; +} +.ts-notify-text > summary::after { + content: " ▾"; + opacity: 0.6; +} +.ts-notify-text-menu { + position: absolute; + right: 0; + z-index: 2; + display: flex; + flex-direction: column; + padding: 4px 8px; + background: var(--bg-toolbar-1); + border: 1px solid var(--border); +} diff --git a/web/src/App.tsx b/web/src/App.tsx index bd23303..b316876 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -150,17 +150,18 @@ import { importSoundPack, isSpecialKey, loadSoundPacks, - notificationTextPosition, + notificationTextPositions, notify, packScript, runSoundScript, saveNotificationSettings, setNotificationPlaybackMuted, setSessionSoundPack, + textPositionChoices, type NotificationNode, + type NotificationOverride, type NotificationSettings, type SoundPack, - type TextPosition, } from "./notifications"; import { iconPackCss, @@ -1982,6 +1983,8 @@ interface PmMessage { fromSelf: boolean; message: string; fromLog?: boolean; + /** Notification text (Options -> Meldungen -> Text Position "Client"). */ + isLog?: boolean; } interface PmThread { @@ -6735,14 +6738,14 @@ function MeldungenPanel({ setSettings(next); }; const defaultScript = (key: string) => packScript(pack, settings.pack, key); - const override = (keys: string[], patch: { off?: boolean; script?: string; text?: TextPosition }) => { + const override = (keys: string[], patch: NotificationOverride) => { const overrides = { ...settings.overrides }; for (const key of keys) { const merged = { ...overrides[key], ...patch }; // Values equal to the default aren't overrides (that's what makes a row bold). if (!merged.off) delete merged.off; if (merged.script === defaultScript(key)) delete merged.script; - if (merged.text === "server") delete merged.text; + if (merged.text?.join() === "server") delete merged.text; if (Object.keys(merged).length) overrides[key] = merged; else delete overrides[key]; } @@ -6766,6 +6769,7 @@ function MeldungenPanel({ const key = node.key; const o = settings.overrides[key]; const script = o?.script ?? defaultScript(key); + const text = Array.isArray(o?.text) ? o.text : ["server"]; return ( @@ -6792,14 +6796,25 @@ function MeldungenPanel({ {!special && ( - +
+ {text.map((p) => t(`notify.text.${p}`)).join(", ") || "—"} +
+ {textPositionChoices(key).map((p) => ( + + ))} +
+
)} @@ -6892,6 +6907,7 @@ function MeldungenPanel({ onChange={(e) => save({ ...settings, whenMuted: e.target.value as NotificationSettings["whenMuted"] })} > + @@ -9658,11 +9674,22 @@ function AppInner() { const key = SERVER_LOG_NOTIFICATIONS[data.kind as keyof typeof SERVER_LOG_NOTIFICATIONS]; // Join/leave/switch sounds come from the channel diff above; these only place the text. if (!["clientJoin", "clientLeave", "clientChannelSwitch"].includes(data.kind)) void notify(key); - const position = notificationTextPosition(key); - if (position !== "none") - (position === "channel" ? setChat : setServerChat)((prev) => - capLines([...prev, { from: "", message, isLog: true }], chatSettingsRef.current.maxLines) - ); + const maxLines = chatSettingsRef.current.maxLines; + for (const position of notificationTextPositions(key)) { + if (position === "client") { + // Into an open private chat with that client, if there is one. + const client = "client" in data ? data.client : undefined; + setPmThreads((prev) => { + const thread = Object.values(prev).find((th) => th.partnerName === client); + if (!thread) return prev; + const messages = capLines([...thread.messages, { fromSelf: false, message, isLog: true }], maxLines); + return { ...prev, [thread.partnerId]: { ...thread, messages } }; + }); + } else + (position === "channel" ? setChat : setServerChat)((prev) => + capLines([...prev, { from: "", message, isLog: true }], maxLines) + ); + } break; } case "disconnected": { @@ -13957,7 +13984,11 @@ function AppInner() { }} > {activeTab === "channel" - ? chat.map((entry, i) => ( + ? chat.map((entry, i) => entry.isLog ? ( +
+ {entry.message} +
+ ) : (
) ) - : pmThreads[activeTab]?.messages.map((entry, i) => ( + : pmThreads[activeTab]?.messages.map((entry, i) => entry.isLog ? ( +
+ {entry.message} +
+ ) : (
; } -export type TextPosition = "none" | "server" | "channel"; +/** Where an event's text line goes; several at once, like native's multiple choice. + * "client" = the private chat with the client it's about. */ +export type TextPosition = "server" | "channel" | "client"; export interface NotificationOverride { off?: boolean; script?: string; - text?: TextPosition; + text?: TextPosition[]; } export interface NotificationSettings { pack: string; - whenMuted: "all" | "none"; + /** "important": only IMPORTANT_KEYS while the output is muted. */ + whenMuted: "all" | "important" | "none"; overrides: Record; } @@ -269,12 +272,24 @@ export function packScript(pack: SoundPack | undefined, packId: string, key: str return pack?.scripts[key] ?? ""; } +/** Text positions native offers for a key: everything gets Server, events about + * channels/yourself also Channel, events about another client also Client. */ +export function textPositionChoices(key: string): TextPosition[] { + if (key.startsWith("CLIENT_") || key === "OTHER_RECEIVED_POKE") return ["server", "channel", "client"]; + if (/^(CHANNEL|YOU|CHAT)_/.test(key)) return ["server", "channel"]; + return ["server"]; +} + +// ponytail: guessed set, native doesn't document which sounds count as "wichtig". +const IMPORTANT_KEYS = /^(CONNECTION_|YOU_WERE_|SOUND_|OTHER_RECEIVED_POKE$|SERVER_ERROR$)/; + export const isNotificationEnabled = (key: string) => isSpecialKey(key) || !settings.overrides[key]?.off; -/** Where the event's text goes; "none" also when the row is unticked. */ -export function notificationTextPosition(key: string): TextPosition { - if (!isNotificationEnabled(key)) return "none"; - return settings.overrides[key]?.text ?? "server"; +/** Where the event's text goes; nowhere when the row is unticked. */ +export function notificationTextPositions(key: string): TextPosition[] { + if (!isNotificationEnabled(key)) return []; + const text = settings.overrides[key]?.text; + return Array.isArray(text) ? text : ["server"]; } export type NotificationVars = Record; @@ -298,7 +313,8 @@ export async function runSoundScript(script: string, packId: string, vars: Notif /** Plays the sound for a TS3 notification key, honouring the Meldungen settings. */ export async function notify(key: string, vars?: NotificationVars): Promise { if (!isNotificationEnabled(key)) return; - if (playbackMuted && settings.whenMuted === "none") return; + if (playbackMuted && (settings.whenMuted === "none" || (settings.whenMuted === "important" && !IMPORTANT_KEYS.test(key)))) + return; const packId = sessionPack ?? settings.pack; const override = settings.overrides[key]?.script; const pack = packId.startsWith("pack:") ? (await loadSoundPacks()).find((p) => p.id === packId) : undefined;