From e76278c5b84a8898502d8827116aa0187e44535e Mon Sep 17 00:00:00 2001 From: Moepchi Date: Fri, 23 Oct 2026 19:54:13 +0000 Subject: [PATCH] Options: Chat tab (line limit, font, chat logs, unread hints) Max lines per chat tab, chat font family/size, per-server local chat logs (channel/private/server, last 1000 lines each, also for background tabs), reloading the last N logged lines into channel/private chats (shown dimmed), and unread highlighting for server/channel/private tabs. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU --- web/src/App.css | 22 ++++ web/src/App.tsx | 259 ++++++++++++++++++++++++++++++++++--- web/src/chatlog.ts | 84 ++++++++++++ web/src/locales/cs-CZ.json | 23 +++- web/src/locales/de.json | 23 +++- web/src/locales/en.json | 23 +++- web/src/locales/fa.json | 23 +++- web/src/locales/zh-CN.json | 23 +++- 8 files changed, 454 insertions(+), 26 deletions(-) create mode 100644 web/src/chatlog.ts diff --git a/web/src/App.css b/web/src/App.css index 4466451..fb97b8d 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -4737,3 +4737,25 @@ border-radius: 4px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); } + +/* Options -> Chat */ +.ts-chat-line-logged { + opacity: 0.6; +} +.ts-chat-font-row, +.ts-chat-restore-row { + display: flex; + align-items: center; + gap: 6px; + flex-wrap: wrap; + margin-top: 6px; +} +.ts-chat-restore-row .ts-options-checkbox { + flex: 1; +} +.ts-chat-font-preview { + margin-top: 6px; + padding: 4px 6px; + border: 1px solid var(--border-soft); + border-radius: 4px; +} diff --git a/web/src/App.tsx b/web/src/App.tsx index 42b537c..11083d1 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -164,6 +164,15 @@ import { type DownloadSettings, type SaveTarget, } from "./downloads"; +import { + DEFAULT_CHAT_SETTINGS, + appendChatLog, + capLines, + loadChatSettings, + readChatLog, + saveChatSettings, + type ChatSettings, +} from "./chatlog"; import { GREENTEASPEAK_THEME_ID, GreenteaSpeakChrome, @@ -705,6 +714,8 @@ const DisplayPrefsContext = createContext<{ setDownloads: (next: DownloadSettings) => void; downloadDir: FileSystemDirectoryHandle | null; setDownloadDir: (dir: FileSystemDirectoryHandle | null) => void; + chat: ChatSettings; + setChat: (next: ChatSettings) => void; }>({ tree: DEFAULT_TREE_OPTIONS, setTree: () => {}, @@ -718,6 +729,8 @@ const DisplayPrefsContext = createContext<{ setDownloads: () => {}, downloadDir: null, setDownloadDir: () => {}, + chat: DEFAULT_CHAT_SETTINGS, + setChat: () => {}, }); const DISCONNECT_MESSAGE_KEY = "webspeak3:disconnect-message"; const COLLECTED_URLS_KEY = "webspeak3:collected-urls"; @@ -1863,11 +1876,14 @@ interface ChatEntry { /** Set for server-log notifications (join/leave/switch/etc.) so they render * without a "from:" prefix, like the native client's server tab. */ isLog?: boolean; + /** Restored from the chat log (Options -> Chat), shown dimmed. */ + fromLog?: boolean; } interface PmMessage { fromSelf: boolean; message: string; + fromLog?: boolean; } interface PmThread { @@ -1879,6 +1895,15 @@ interface PmThread { type ActiveTab = "channel" | "server" | number; +/** Private chat logs are keyed by the partner's identity, falling back to the nickname. */ +function pmLogKind(uid: string | undefined, name: string): string { + return `pm:${uid || name}`; +} + +function loggedPmMessages(server: string, kind: string, lines: number): PmMessage[] { + return readChatLog(server, kind, lines).map((l) => ({ fromSelf: !!l.self, message: l.message, fromLog: true })); +} + interface PokeNotice { id: number; from: string; @@ -6368,6 +6393,123 @@ function DownloadsPanel() { ); } +const CHAT_MAX_LINES_OPTIONS = [100, 200, 500, 1000, 2000]; +const CHAT_RESTORE_OPTIONS = [10, 50, 100, 500]; +const CHAT_FONTS = [ + "Arial", + "Verdana", + "Tahoma", + "Segoe UI", + "Trebuchet MS", + "Georgia", + "Times New Roman", + "Courier New", + "Consolas", + "sans-serif", + "serif", + "monospace", +]; + +function ChatPanel() { + const t = useT(); + const { chat, setChat } = useContext(DisplayPrefsContext); + const set = (patch: Partial) => setChat({ ...chat, ...patch }); + const restoreRow = (key: "restoreChannelLines" | "restorePrivateLines") => ( +
+ + +
+ ); + return ( + <> +

{t("options.section.chat")}

+

{t("chatSettings.subtitle")}

+
+
+ {t("chatSettings.window")} + +
+ {t("chatSettings.font")} + + set({ fontSize: Math.min(32, Math.max(0, Number(e.target.value) || 0)) })} + /> + px + +
+
+ {t("chatSettings.fontPreview")} +
+
+
+ {t("chatSettings.autoLog")} + {(["logChannel", "logPrivate", "logServer"] as const).map((key) => ( + + ))} +

{t("chatSettings.logHint")}

+
+
+ {t("chatSettings.restore")} + {restoreRow("restoreChannelLines")} + {restoreRow("restorePrivateLines")} +
+
+ {t("chatSettings.notify")} + {(["notifyServer", "notifyChannel", "notifyPrivate"] as const).map((key) => ( + + ))} +
+
+ + ); +} + function DesignPanel({ designSelection, onSelectionChange, @@ -7399,6 +7541,8 @@ function OptionsDialog({ ) : active.id === "downloads" ? ( + ) : active.id === "chat" ? ( + ) : ( <>

{t(`options.section.${active.id}`)}

@@ -7884,6 +8028,11 @@ function AppInner() { const downloadSettingsRef = useRef(downloadSettings); downloadSettingsRef.current = downloadSettings; const [downloadDir, setDownloadDir] = useState(null); + const [chatSettings, setChatSettings] = useState(loadChatSettings); + const chatSettingsRef = useRef(chatSettings); + chatSettingsRef.current = chatSettings; + // "Hinweis für eingehende Nachrichten" for the two fixed tabs (private chats have their own flag). + const [chatUnread, setChatUnread] = useState({ channel: false, server: false }); useEffect(() => { void loadDownloadDir().then(setDownloadDir); }, []); @@ -7918,8 +8067,13 @@ function AppInner() { }, downloadDir, setDownloadDir, + chat: chatSettings, + setChat: (next: ChatSettings) => { + setChatSettings(next); + saveChatSettings(next); + }, }), - [treeOptions, iconPacks, iconPackId, whisperSettings, downloadSettings, downloadDir] + [treeOptions, iconPacks, iconPackId, whisperSettings, downloadSettings, downloadDir, chatSettings] ); const iconPackStyle = iconPackCss(iconPacks.find((p) => p.id === iconPackId)); const [micOn, setMicOn] = useState(false); @@ -8282,6 +8436,8 @@ function AppInner() { useEffect(() => { activeTabRef.current = activeTab; + if (activeTab === "channel" || activeTab === "server") + setChatUnread((prev) => (prev[activeTab] ? { ...prev, [activeTab]: false } : prev)); if (typeof activeTab === "number") { setPmThreads((prev) => { const thread = prev[activeTab]; @@ -8529,6 +8685,7 @@ function AppInner() { setChat([]); setServerChat([]); setPmThreads({}); + setChatUnread({ channel: false, server: false }); setPokes([]); setActiveTab("channel"); talkersRef.current = new Set(); @@ -8767,6 +8924,18 @@ function AppInner() { void playSound("disconnect"); return; } + // Background tabs get logged too (Options -> Chat). + const chatPrefs = chatSettingsRef.current; + if (data.type === "chatMessage" && chatPrefs.logChannel) + appendChatLog(connectHost, "channel", { from: data.from, message: data.message, self: data.from === connectNickname }); + else if (data.type === "serverMessage" && chatPrefs.logServer) + appendChatLog(connectHost, "server", { from: data.from, message: data.message, self: data.from === connectNickname }); + else if (data.type === "privateMessage" && chatPrefs.logPrivate) + appendChatLog( + connectHost, + pmLogKind(rec.parked.clients.find((c) => c.id === data.partnerId)?.uid, data.partnerName), + { from: data.partnerName, message: data.message, self: data.fromSelf } + ); const result = applyParkedGatewayEvent(rec.parked, data, { connectNickname, chatTab: rec.parked.chatTab, @@ -8795,6 +8964,13 @@ function AppInner() { setConnecting(false); setConnectError(null); setConnected(true); + setChat( + readChatLog(connectHost, "channel", chatSettingsRef.current.restoreChannelLines).map((l) => ({ + from: l.from, + message: l.message, + fromLog: true, + })) + ); updateTabMeta(sessionId, { label: String(data.serverName || connectHost), connected: true, @@ -8822,7 +8998,7 @@ function AppInner() { setServerBannerUrl(data.serverBannerUrl); setServerWelcomeMessage(data.welcomeMessage); setSelected({ type: "server" }); - setServerChat((prev) => [...prev, { from: "Server", message: data.welcomeMessage }]); + setServerChat((prev) => capLines([...prev, { from: "Server", message: data.welcomeMessage }], chatSettingsRef.current.maxLines)); previousClientsRef.current = null; void playSound("connect"); break; @@ -8861,25 +9037,36 @@ function AppInner() { break; } case "chatMessage": + case "serverMessage": { if (isSenderIgnored(data.from)) break; - setChat((prev) => [...prev, { from: data.from, message: data.message }]); + const tab = data.type === "chatMessage" ? "channel" : "server"; + const settings = chatSettingsRef.current; + const fromSelf = data.from === connectNickname || data.from === ownNameRef.current; + const entry = { from: data.from, message: data.message }; + (tab === "channel" ? setChat : setServerChat)((prev) => capLines([...prev, entry], settings.maxLines)); + if (tab === "channel" ? settings.logChannel : settings.logServer) + appendChatLog(connectHost, tab, { ...entry, self: fromSelf }); + if (!fromSelf && activeTabRef.current !== tab && (tab === "channel" ? settings.notifyChannel : settings.notifyServer)) + setChatUnread((prev) => ({ ...prev, [tab]: true })); recordUrlsFromMessage(data.message, data.from); - if (data.from !== connectNickname && data.from !== ownNameRef.current) void playSound("message"); + if (!fromSelf) 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 && data.from !== ownNameRef.current) void playSound("message"); - break; - case "privateMessage": + } + case "privateMessage": { if (!data.fromSelf && isSenderIgnored(data.partnerName)) break; + const settings = chatSettingsRef.current; + const logKind = pmLogKind( + previousClientsRef.current?.find((c) => c.id === data.partnerId)?.uid, + data.partnerName + ); + // Read before appending this message, so a new thread's history doesn't contain it twice. + const history = loggedPmMessages(connectHost, logKind, settings.restorePrivateLines); setPmThreads((prev) => { const existing = prev[data.partnerId]; const thread: PmThread = existing ?? { partnerId: data.partnerId, partnerName: data.partnerName, - messages: [], + messages: history, unread: false, }; return { @@ -8887,14 +9074,22 @@ function AppInner() { [data.partnerId]: { ...thread, partnerName: data.partnerName, - messages: [...thread.messages, { fromSelf: data.fromSelf, message: data.message }], - unread: thread.unread || (!data.fromSelf && activeTabRef.current !== data.partnerId), + messages: capLines( + [...thread.messages, { fromSelf: data.fromSelf, message: data.message }], + settings.maxLines + ), + unread: + thread.unread || + (settings.notifyPrivate && !data.fromSelf && activeTabRef.current !== data.partnerId), }, }; }); + if (settings.logPrivate) + appendChatLog(connectHost, logKind, { from: data.partnerName, message: data.message, self: data.fromSelf }); recordUrlsFromMessage(data.message, data.fromSelf ? connectNickname : data.partnerName); if (!data.fromSelf) void playSound("message"); break; + } case "audioOut": // Audio only for the active session tab. if (!outputMutedRef.current) audioPlayerRef.current?.playFrame(data.pcm); @@ -9000,7 +9195,7 @@ function AppInner() { message = t("serverLog.permissionError", { action: data.action }); break; } - setServerChat((prev) => [...prev, { from: "", message, isLog: true }]); + setServerChat((prev) => capLines([...prev, { from: "", message, isLog: true }], chatSettingsRef.current.maxLines)); break; } case "disconnected": { @@ -10411,9 +10606,14 @@ function AppInner() { }; const handleOpenPrivateChat = (clientId: number, clientName: string) => { + const history = loggedPmMessages( + host, + pmLogKind(clients.find((c) => c.id === clientId)?.uid, clientName), + chatSettings.restorePrivateLines + ); setPmThreads((prev) => ({ ...prev, - [clientId]: prev[clientId] ?? { partnerId: clientId, partnerName: clientName, messages: [], unread: false }, + [clientId]: prev[clientId] ?? { partnerId: clientId, partnerName: clientName, messages: history, unread: false }, })); setActiveTab(clientId); }; @@ -13252,12 +13452,20 @@ function AppInner() { onContextMenu={handleClientContextMenu} /> )} -
+
{activeTab === "channel" ? chat.map((entry, i) => (
{entry.from}:{" "} {renderBbcode(entry.message, { images: chatImages, stillImages: !treeOptions.animateImages })} @@ -13280,7 +13488,12 @@ function AppInner() { ) ) : pmThreads[activeTab]?.messages.map((entry, i) => ( -
+
{entry.fromSelf ? t("chat.you") : pmThreads[activeTab].partnerName}: {" "} @@ -13291,13 +13504,17 @@ function AppInner() {