mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42:49 +08:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
1 parent
bc2d1f65a0
commit
e76278c5b8
8 files changed
+454
-26
No files matched your search
@@ -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;
|
||||
}
|
||||
+238
-21
@@ -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<ChatSettings>) => setChat({ ...chat, ...patch });
|
||||
const restoreRow = (key: "restoreChannelLines" | "restorePrivateLines") => (
|
||||
<div className="ts-chat-restore-row">
|
||||
<label className="ts-options-checkbox">
|
||||
<input type="checkbox" checked={chat[key] > 0} onChange={(e) => set({ [key]: e.target.checked ? 100 : 0 })} />
|
||||
{t(`chatSettings.${key}`)}
|
||||
</label>
|
||||
<select value={chat[key] || 100} disabled={chat[key] === 0} onChange={(e) => set({ [key]: Number(e.target.value) })}>
|
||||
{CHAT_RESTORE_OPTIONS.map((n) => (
|
||||
<option key={n} value={n}>
|
||||
{t("chatSettings.lastLines", { count: String(n) })}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<h3>{t("options.section.chat")}</h3>
|
||||
<p className="ts-options-subtitle">{t("chatSettings.subtitle")}</p>
|
||||
<div className="ts-options-fields">
|
||||
<fieldset className="ts-options-fieldset">
|
||||
<legend>{t("chatSettings.window")}</legend>
|
||||
<label className="ts-options-field">
|
||||
{t("chatSettings.maxLines")}
|
||||
<select value={chat.maxLines} onChange={(e) => set({ maxLines: Number(e.target.value) })}>
|
||||
{CHAT_MAX_LINES_OPTIONS.map((n) => (
|
||||
<option key={n} value={n}>
|
||||
{t("chatSettings.lines", { count: String(n) })}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<div className="ts-chat-font-row">
|
||||
{t("chatSettings.font")}
|
||||
<select value={chat.fontFamily} onChange={(e) => set({ fontFamily: e.target.value })}>
|
||||
<option value="">{t("chatSettings.fontDefault")}</option>
|
||||
{CHAT_FONTS.map((f) => (
|
||||
<option key={f} value={f} style={{ fontFamily: f }}>
|
||||
{f}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<input
|
||||
type="number"
|
||||
min={8}
|
||||
max={32}
|
||||
className="ts-download-number"
|
||||
placeholder={t("chatSettings.fontDefault")}
|
||||
value={chat.fontSize || ""}
|
||||
onChange={(e) => set({ fontSize: Math.min(32, Math.max(0, Number(e.target.value) || 0)) })}
|
||||
/>
|
||||
px
|
||||
<button
|
||||
title={t("chatSettings.fontReset")}
|
||||
aria-label={t("chatSettings.fontReset")}
|
||||
onClick={() => set({ fontFamily: "", fontSize: 0 })}
|
||||
>
|
||||
↻
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
className="ts-chat-font-preview"
|
||||
style={{ fontFamily: chat.fontFamily || undefined, fontSize: chat.fontSize ? `${chat.fontSize}px` : undefined }}
|
||||
>
|
||||
{t("chatSettings.fontPreview")}
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset className="ts-options-fieldset">
|
||||
<legend>{t("chatSettings.autoLog")}</legend>
|
||||
{(["logChannel", "logPrivate", "logServer"] as const).map((key) => (
|
||||
<label key={key} className="ts-options-checkbox">
|
||||
<input type="checkbox" checked={chat[key]} onChange={(e) => set({ [key]: e.target.checked })} />
|
||||
{t(`chatSettings.${key}`)}
|
||||
</label>
|
||||
))}
|
||||
<p className="ts-options-hint">{t("chatSettings.logHint")}</p>
|
||||
</fieldset>
|
||||
<fieldset className="ts-options-fieldset">
|
||||
<legend>{t("chatSettings.restore")}</legend>
|
||||
{restoreRow("restoreChannelLines")}
|
||||
{restoreRow("restorePrivateLines")}
|
||||
</fieldset>
|
||||
<fieldset className="ts-options-fieldset">
|
||||
<legend>{t("chatSettings.notify")}</legend>
|
||||
{(["notifyServer", "notifyChannel", "notifyPrivate"] as const).map((key) => (
|
||||
<label key={key} className="ts-options-checkbox">
|
||||
<input type="checkbox" checked={chat[key]} onChange={(e) => set({ [key]: e.target.checked })} />
|
||||
{t(`chatSettings.${key}`)}
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function DesignPanel({
|
||||
designSelection,
|
||||
onSelectionChange,
|
||||
@@ -7399,6 +7541,8 @@ function OptionsDialog({
|
||||
<WhisperPanel onOpenWhisperLists={onOpenWhisperLists} />
|
||||
) : active.id === "downloads" ? (
|
||||
<DownloadsPanel />
|
||||
) : active.id === "chat" ? (
|
||||
<ChatPanel />
|
||||
) : (
|
||||
<>
|
||||
<h3>{t(`options.section.${active.id}`)}</h3>
|
||||
@@ -7884,6 +8028,11 @@ function AppInner() {
|
||||
const downloadSettingsRef = useRef(downloadSettings);
|
||||
downloadSettingsRef.current = downloadSettings;
|
||||
const [downloadDir, setDownloadDir] = useState<FileSystemDirectoryHandle | null>(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}
|
||||
/>
|
||||
)}
|
||||
<div className="ts-chat-messages">
|
||||
<div
|
||||
className="ts-chat-messages"
|
||||
style={{
|
||||
fontFamily: chatSettings.fontFamily || undefined,
|
||||
fontSize: chatSettings.fontSize ? `${chatSettings.fontSize}px` : undefined,
|
||||
}}
|
||||
>
|
||||
{activeTab === "channel"
|
||||
? chat.map((entry, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className={`ts-chat-line${entry.from === ownClient?.name ? " ts-chat-line-self" : ""}`}
|
||||
className={`ts-chat-line${entry.from === ownClient?.name ? " ts-chat-line-self" : ""}${
|
||||
entry.fromLog ? " ts-chat-line-logged" : ""
|
||||
}`}
|
||||
>
|
||||
<span className="ts-chat-from">{entry.from}:</span>{" "}
|
||||
<span className="ts-chat-bubble">{renderBbcode(entry.message, { images: chatImages, stillImages: !treeOptions.animateImages })}</span>
|
||||
@@ -13280,7 +13488,12 @@ function AppInner() {
|
||||
)
|
||||
)
|
||||
: pmThreads[activeTab]?.messages.map((entry, i) => (
|
||||
<div key={i} className={`ts-chat-line${entry.fromSelf ? " ts-chat-line-self" : ""}`}>
|
||||
<div
|
||||
key={i}
|
||||
className={`ts-chat-line${entry.fromSelf ? " ts-chat-line-self" : ""}${
|
||||
entry.fromLog ? " ts-chat-line-logged" : ""
|
||||
}`}
|
||||
>
|
||||
<span className="ts-chat-from">
|
||||
{entry.fromSelf ? t("chat.you") : pmThreads[activeTab].partnerName}:
|
||||
</span>{" "}
|
||||
@@ -13291,13 +13504,17 @@ function AppInner() {
|
||||
</div>
|
||||
<div className="ts-chat-tabs">
|
||||
<button
|
||||
className={`ts-chat-tab${activeTab === "server" ? " ts-chat-tab-active" : ""}`}
|
||||
className={`ts-chat-tab${activeTab === "server" ? " ts-chat-tab-active" : ""}${
|
||||
chatUnread.server ? " ts-chat-tab-unread" : ""
|
||||
}`}
|
||||
onClick={() => setActiveTab("server")}
|
||||
>
|
||||
{t("chat.server")}
|
||||
</button>
|
||||
<button
|
||||
className={`ts-chat-tab${activeTab === "channel" ? " ts-chat-tab-active" : ""}`}
|
||||
className={`ts-chat-tab${activeTab === "channel" ? " ts-chat-tab-active" : ""}${
|
||||
chatUnread.channel ? " ts-chat-tab-unread" : ""
|
||||
}`}
|
||||
onClick={() => setActiveTab("channel")}
|
||||
>
|
||||
{t("chat.channel")}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/** Options -> Chat ("Chat Fenster", "Automatisch protokollieren", ...). */
|
||||
export interface ChatSettings {
|
||||
/** Lines kept per chat tab. */
|
||||
maxLines: number;
|
||||
/** "" = the design's font. */
|
||||
fontFamily: string;
|
||||
/** px, 0 = the design's size. */
|
||||
fontSize: number;
|
||||
logChannel: boolean;
|
||||
logPrivate: boolean;
|
||||
logServer: boolean;
|
||||
/** Prefill a new channel chat / private chat with this many logged lines (0 = off). */
|
||||
restoreChannelLines: number;
|
||||
restorePrivateLines: number;
|
||||
notifyServer: boolean;
|
||||
notifyChannel: boolean;
|
||||
notifyPrivate: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_CHAT_SETTINGS: ChatSettings = {
|
||||
maxLines: 500,
|
||||
fontFamily: "",
|
||||
fontSize: 0,
|
||||
logChannel: true,
|
||||
logPrivate: true,
|
||||
logServer: true,
|
||||
restoreChannelLines: 100,
|
||||
restorePrivateLines: 100,
|
||||
notifyServer: false,
|
||||
notifyChannel: true,
|
||||
notifyPrivate: true,
|
||||
};
|
||||
|
||||
const SETTINGS_KEY = "webspeak3:chat-settings";
|
||||
|
||||
export function loadChatSettings(): ChatSettings {
|
||||
try {
|
||||
return { ...DEFAULT_CHAT_SETTINGS, ...JSON.parse(localStorage.getItem(SETTINGS_KEY) ?? "{}") };
|
||||
} catch {
|
||||
return DEFAULT_CHAT_SETTINGS;
|
||||
}
|
||||
}
|
||||
|
||||
export function saveChatSettings(settings: ChatSettings): void {
|
||||
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
|
||||
}
|
||||
|
||||
export interface LoggedLine {
|
||||
from: string;
|
||||
message: string;
|
||||
self?: boolean;
|
||||
at: number;
|
||||
}
|
||||
|
||||
// ponytail: localStorage, 1000 lines per chat. Move to IndexedDB if logs outgrow the ~5 MB quota.
|
||||
const MAX_LOGGED = 1000;
|
||||
|
||||
/** kind: "channel" | "server" | "pm:<uid>" */
|
||||
const logKey = (server: string, kind: string) => `webspeak3:chatlog:${server.trim().toLowerCase()}:${kind}`;
|
||||
|
||||
export function readChatLog(server: string, kind: string, lines: number): LoggedLine[] {
|
||||
if (!lines) return [];
|
||||
try {
|
||||
const all: LoggedLine[] = JSON.parse(localStorage.getItem(logKey(server, kind)) ?? "[]");
|
||||
return all.slice(-lines);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function appendChatLog(server: string, kind: string, line: Omit<LoggedLine, "at">): void {
|
||||
try {
|
||||
const all = readChatLog(server, kind, MAX_LOGGED);
|
||||
all.push({ ...line, at: Date.now() });
|
||||
localStorage.setItem(logKey(server, kind), JSON.stringify(all.slice(-MAX_LOGGED)));
|
||||
} catch {
|
||||
// Quota full: logging is best effort.
|
||||
}
|
||||
}
|
||||
|
||||
/** Keeps the newest `max` entries. */
|
||||
export function capLines<T>(lines: T[], max: number): T[] {
|
||||
return lines.length > max ? lines.slice(-max) : lines;
|
||||
}
|
||||
@@ -773,5 +773,26 @@
|
||||
"downloadSettings.maxUploads": "Souběžná nahrávání",
|
||||
"downloadSettings.maxDownloads": "Souběžná stahování",
|
||||
"downloadSettings.unlimited": "Neomezovat",
|
||||
"downloadSettings.limitedTo": "Omezit na"
|
||||
"downloadSettings.limitedTo": "Omezit na",
|
||||
"chatSettings.subtitle": "Nastavení chatu",
|
||||
"chatSettings.window": "Okno chatu",
|
||||
"chatSettings.maxLines": "Maximální počet řádků:",
|
||||
"chatSettings.lines": "{count} řádků",
|
||||
"chatSettings.font": "Písmo:",
|
||||
"chatSettings.fontDefault": "Výchozí",
|
||||
"chatSettings.fontReset": "Obnovit písmo",
|
||||
"chatSettings.fontPreview": "Takto vypadá chat s tímto písmem.",
|
||||
"chatSettings.autoLog": "Automatické protokolování",
|
||||
"chatSettings.logChannel": "Protokolovat chaty kanálu",
|
||||
"chatSettings.logPrivate": "Protokolovat soukromé chaty",
|
||||
"chatSettings.logServer": "Protokolovat chaty serveru",
|
||||
"chatSettings.logHint": "Protokoly se ukládají jen v tomto prohlížeči (posledních 1000 řádků na chat).",
|
||||
"chatSettings.restore": "Načíst protokoly",
|
||||
"chatSettings.restoreChannelLines": "Načíst protokoly chatu kanálu",
|
||||
"chatSettings.restorePrivateLines": "Načíst protokoly soukromých chatů",
|
||||
"chatSettings.lastLines": "posledních {count} řádků",
|
||||
"chatSettings.notify": "Upozornění na příchozí zprávy",
|
||||
"chatSettings.notifyServer": "Server",
|
||||
"chatSettings.notifyChannel": "Kanál",
|
||||
"chatSettings.notifyPrivate": "Soukromé"
|
||||
}
|
||||
+22
-1
@@ -773,5 +773,26 @@
|
||||
"downloadSettings.maxUploads": "Gleichzeitige Uploads",
|
||||
"downloadSettings.maxDownloads": "Gleichzeitige Downloads",
|
||||
"downloadSettings.unlimited": "Nicht limitieren",
|
||||
"downloadSettings.limitedTo": "Limitiert auf"
|
||||
"downloadSettings.limitedTo": "Limitiert auf",
|
||||
"chatSettings.subtitle": "Chat Einstellungen",
|
||||
"chatSettings.window": "Chat Fenster",
|
||||
"chatSettings.maxLines": "Maximale Anzahl an Zeilen:",
|
||||
"chatSettings.lines": "{count} Zeilen",
|
||||
"chatSettings.font": "Schrift:",
|
||||
"chatSettings.fontDefault": "Standard",
|
||||
"chatSettings.fontReset": "Schrift zurücksetzen",
|
||||
"chatSettings.fontPreview": "So sieht der Chat mit dieser Schrift aus.",
|
||||
"chatSettings.autoLog": "Automatisch protokollieren",
|
||||
"chatSettings.logChannel": "Channel Chats protokollieren",
|
||||
"chatSettings.logPrivate": "Private Chats protokollieren",
|
||||
"chatSettings.logServer": "Server Chats protokollieren",
|
||||
"chatSettings.logHint": "Protokolle bleiben nur in diesem Browser gespeichert (letzte 1000 Zeilen je Chat).",
|
||||
"chatSettings.restore": "Protokolle aktualisieren",
|
||||
"chatSettings.restoreChannelLines": "Channel Chat Protokolle aktualisieren",
|
||||
"chatSettings.restorePrivateLines": "Private Chat Protokolle aktualisieren",
|
||||
"chatSettings.lastLines": "letzten {count} Zeilen",
|
||||
"chatSettings.notify": "Hinweis für eingehende Nachrichten",
|
||||
"chatSettings.notifyServer": "Server",
|
||||
"chatSettings.notifyChannel": "Channel",
|
||||
"chatSettings.notifyPrivate": "Privat"
|
||||
}
|
||||
+22
-1
@@ -773,5 +773,26 @@
|
||||
"downloadSettings.maxUploads": "Simultaneous uploads",
|
||||
"downloadSettings.maxDownloads": "Simultaneous downloads",
|
||||
"downloadSettings.unlimited": "Unlimited",
|
||||
"downloadSettings.limitedTo": "Limited to"
|
||||
"downloadSettings.limitedTo": "Limited to",
|
||||
"chatSettings.subtitle": "Chat settings",
|
||||
"chatSettings.window": "Chat window",
|
||||
"chatSettings.maxLines": "Maximum number of lines:",
|
||||
"chatSettings.lines": "{count} lines",
|
||||
"chatSettings.font": "Font:",
|
||||
"chatSettings.fontDefault": "Default",
|
||||
"chatSettings.fontReset": "Reset font",
|
||||
"chatSettings.fontPreview": "This is how the chat looks with this font.",
|
||||
"chatSettings.autoLog": "Automatic logging",
|
||||
"chatSettings.logChannel": "Log channel chats",
|
||||
"chatSettings.logPrivate": "Log private chats",
|
||||
"chatSettings.logServer": "Log server chats",
|
||||
"chatSettings.logHint": "Logs are only stored in this browser (last 1000 lines per chat).",
|
||||
"chatSettings.restore": "Reload logs",
|
||||
"chatSettings.restoreChannelLines": "Reload channel chat logs",
|
||||
"chatSettings.restorePrivateLines": "Reload private chat logs",
|
||||
"chatSettings.lastLines": "last {count} lines",
|
||||
"chatSettings.notify": "Notify on incoming messages",
|
||||
"chatSettings.notifyServer": "Server",
|
||||
"chatSettings.notifyChannel": "Channel",
|
||||
"chatSettings.notifyPrivate": "Private"
|
||||
}
|
||||
+22
-1
@@ -772,5 +772,26 @@
|
||||
"downloadSettings.maxUploads": "آپلودهای همزمان",
|
||||
"downloadSettings.maxDownloads": "دانلودهای همزمان",
|
||||
"downloadSettings.unlimited": "بدون محدودیت",
|
||||
"downloadSettings.limitedTo": "محدود به"
|
||||
"downloadSettings.limitedTo": "محدود به",
|
||||
"chatSettings.subtitle": "تنظیمات چت",
|
||||
"chatSettings.window": "پنجره چت",
|
||||
"chatSettings.maxLines": "حداکثر تعداد خطوط:",
|
||||
"chatSettings.lines": "{count} خط",
|
||||
"chatSettings.font": "قلم:",
|
||||
"chatSettings.fontDefault": "پیشفرض",
|
||||
"chatSettings.fontReset": "بازنشانی قلم",
|
||||
"chatSettings.fontPreview": "چت با این قلم اینگونه دیده میشود.",
|
||||
"chatSettings.autoLog": "ثبت خودکار",
|
||||
"chatSettings.logChannel": "ثبت چتهای کانال",
|
||||
"chatSettings.logPrivate": "ثبت چتهای خصوصی",
|
||||
"chatSettings.logServer": "ثبت چتهای سرور",
|
||||
"chatSettings.logHint": "گزارشها فقط در این مرورگر ذخیره میشوند (۱۰۰۰ خط آخر هر چت).",
|
||||
"chatSettings.restore": "بارگذاری گزارشها",
|
||||
"chatSettings.restoreChannelLines": "بارگذاری گزارش چت کانال",
|
||||
"chatSettings.restorePrivateLines": "بارگذاری گزارش چت خصوصی",
|
||||
"chatSettings.lastLines": "{count} خط آخر",
|
||||
"chatSettings.notify": "اعلان برای پیامهای ورودی",
|
||||
"chatSettings.notifyServer": "سرور",
|
||||
"chatSettings.notifyChannel": "کانال",
|
||||
"chatSettings.notifyPrivate": "خصوصی"
|
||||
}
|
||||
@@ -772,5 +772,26 @@
|
||||
"downloadSettings.maxUploads": "同时上传数",
|
||||
"downloadSettings.maxDownloads": "同时下载数",
|
||||
"downloadSettings.unlimited": "不限制",
|
||||
"downloadSettings.limitedTo": "限制为"
|
||||
"downloadSettings.limitedTo": "限制为",
|
||||
"chatSettings.subtitle": "聊天设置",
|
||||
"chatSettings.window": "聊天窗口",
|
||||
"chatSettings.maxLines": "最大行数:",
|
||||
"chatSettings.lines": "{count} 行",
|
||||
"chatSettings.font": "字体:",
|
||||
"chatSettings.fontDefault": "默认",
|
||||
"chatSettings.fontReset": "重置字体",
|
||||
"chatSettings.fontPreview": "使用此字体时聊天的样子。",
|
||||
"chatSettings.autoLog": "自动记录",
|
||||
"chatSettings.logChannel": "记录频道聊天",
|
||||
"chatSettings.logPrivate": "记录私聊",
|
||||
"chatSettings.logServer": "记录服务器聊天",
|
||||
"chatSettings.logHint": "记录只保存在此浏览器中(每个聊天最近 1000 行)。",
|
||||
"chatSettings.restore": "加载记录",
|
||||
"chatSettings.restoreChannelLines": "加载频道聊天记录",
|
||||
"chatSettings.restorePrivateLines": "加载私聊记录",
|
||||
"chatSettings.lastLines": "最近 {count} 行",
|
||||
"chatSettings.notify": "新消息提示",
|
||||
"chatSettings.notifyServer": "服务器",
|
||||
"chatSettings.notifyChannel": "频道",
|
||||
"chatSettings.notifyPrivate": "私聊"
|
||||
}
|
||||
Reference in new issue
Block a user