mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42:49 +08:00
Add Bannliste and Beschwerdeliste management dialogs
Implements #91 (ban list) and #92 (complaint list), reusing the StreamItem::MessageEvent handling infrastructure added for #94. Connector: - New raw commands: banlist, bandel, bandelall, complainlist, complaindel, complaindelall (no typed builders exist for these). - New pending_ban_list/pending_complain_list flags + MessageEvent match arms parsing InMessage::BanList/ComplainList replies into BanListEntry/ComplainListEntry structs, emitted as banList/ complainList events. - Unlike serverlog/serverconninfo, the test server actually replies with an error return code for these (surfaced as a "permission error" Server-tab log line) rather than staying silent - the connector already handles that path via the existing pending message result matching. Gateway: getBanList/deleteBan/deleteAllBans/getComplainList/ deleteComplaint/deleteAllComplaintsFor methods and message cases, plus camelCase remapping for the two new event types. Frontend: BanListDialog and ComplainListDialog components (table view, per-row delete + delete-all for bans, optimistic local removal on delete), wired into the Extras menu (previously disabled placeholders), with the same 6s timeout-to-"unavailable" fallback pattern used by the other async-reply dialogs. Demo mode gets fake ban/complaint entries. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4318ce359f
commit
bd0122812d
7 files changed
+678
-13
No files matched your search
@@ -1058,6 +1058,35 @@
|
||||
width: 640px;
|
||||
}
|
||||
|
||||
.ts-ban-list-dialog,
|
||||
.ts-complain-list-dialog {
|
||||
width: 720px;
|
||||
}
|
||||
|
||||
.ts-ban-list-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.ts-ban-list-table th,
|
||||
.ts-ban-list-table td {
|
||||
text-align: left;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-bottom: 1px solid var(--border-soft);
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.ts-ban-list-table th {
|
||||
color: var(--text-muted);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.ts-dialog-buttons-left {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.ts-server-protocol-log-line {
|
||||
padding: 0.15rem 0.4rem;
|
||||
border-bottom: 1px solid var(--border-soft);
|
||||
|
||||
+269
-11
@@ -181,6 +181,28 @@ interface WhisperLogEntry {
|
||||
description: string;
|
||||
}
|
||||
|
||||
interface BanListEntry {
|
||||
banId: number;
|
||||
ip: string;
|
||||
name: string;
|
||||
uid: string;
|
||||
lastNickname: string;
|
||||
created: string;
|
||||
durationSecs: number;
|
||||
invokerName: string;
|
||||
reason: string;
|
||||
enforcements: number;
|
||||
}
|
||||
|
||||
interface ComplainListEntry {
|
||||
targetClientDbId: number;
|
||||
targetName: string;
|
||||
fromClientDbId: number;
|
||||
fromName: string;
|
||||
message: string;
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
type ContactCategory = "acquaintance" | "blocked" | "friend";
|
||||
|
||||
interface Contact {
|
||||
@@ -1198,6 +1220,165 @@ function ClientLogDialog({ entries, onClose }: { entries: ClientLogEntry[]; onCl
|
||||
);
|
||||
}
|
||||
|
||||
function BanListDialog({
|
||||
entries,
|
||||
onDelete,
|
||||
onDeleteAll,
|
||||
onClose,
|
||||
}: {
|
||||
entries: BanListEntry[] | null;
|
||||
onDelete: (banId: number) => void;
|
||||
onDeleteAll: () => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const t = useT();
|
||||
const backdrop = useBackdropDismiss(onClose);
|
||||
// Same silent-decline story as connection-info/server-log: a guest account
|
||||
// without b_virtualserver_client_dblist/banlist permission never gets a reply.
|
||||
const [timedOut, setTimedOut] = useState(false);
|
||||
useEffect(() => {
|
||||
setTimedOut(false);
|
||||
if (entries) return;
|
||||
const id = window.setTimeout(() => setTimedOut(true), 6000);
|
||||
return () => window.clearTimeout(id);
|
||||
}, [entries]);
|
||||
|
||||
return (
|
||||
<div className="ts-dialog-backdrop" {...backdrop}>
|
||||
<div className="ts-dialog ts-ban-list-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="ts-dialog-titlebar">
|
||||
<span>{t("banList.title")}</span>
|
||||
<button onClick={onClose} title={t("dialog.close")}>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<div className="ts-dialog-body">
|
||||
{!entries ? (
|
||||
<div className="ts-connection-info-loading">
|
||||
{timedOut ? t("connectionInfo.unavailable") : t("connectionInfo.loading")}
|
||||
</div>
|
||||
) : entries.length === 0 ? (
|
||||
<div className="ts-connection-info-loading">{t("banList.empty")}</div>
|
||||
) : (
|
||||
<table className="ts-ban-list-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{t("banList.name")}</th>
|
||||
<th>{t("banList.ip")}</th>
|
||||
<th>{t("banList.created")}</th>
|
||||
<th>{t("banList.duration")}</th>
|
||||
<th>{t("banList.invoker")}</th>
|
||||
<th>{t("banList.reason")}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{entries.map((e) => (
|
||||
<tr key={e.banId}>
|
||||
<td>{e.name || e.lastNickname || "-"}</td>
|
||||
<td>{e.ip || "-"}</td>
|
||||
<td>{e.created}</td>
|
||||
<td>{e.durationSecs === 0 ? t("banList.permanent") : `${e.durationSecs}s`}</td>
|
||||
<td>{e.invokerName}</td>
|
||||
<td>{e.reason}</td>
|
||||
<td>
|
||||
<button onClick={() => onDelete(e.banId)}>{t("banList.delete")}</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</div>
|
||||
<div className="ts-dialog-buttons">
|
||||
<div className="ts-dialog-buttons-left">
|
||||
{entries && entries.length > 0 && (
|
||||
<button onClick={onDeleteAll}>{t("banList.deleteAll")}</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="ts-dialog-buttons-right">
|
||||
<button onClick={onClose}>{t("dialog.close")}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ComplainListDialog({
|
||||
entries,
|
||||
onDelete,
|
||||
onClose,
|
||||
}: {
|
||||
entries: ComplainListEntry[] | null;
|
||||
onDelete: (targetClientDbId: number, fromClientDbId: number) => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const t = useT();
|
||||
const backdrop = useBackdropDismiss(onClose);
|
||||
const [timedOut, setTimedOut] = useState(false);
|
||||
useEffect(() => {
|
||||
setTimedOut(false);
|
||||
if (entries) return;
|
||||
const id = window.setTimeout(() => setTimedOut(true), 6000);
|
||||
return () => window.clearTimeout(id);
|
||||
}, [entries]);
|
||||
|
||||
return (
|
||||
<div className="ts-dialog-backdrop" {...backdrop}>
|
||||
<div className="ts-dialog ts-complain-list-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="ts-dialog-titlebar">
|
||||
<span>{t("complainList.title")}</span>
|
||||
<button onClick={onClose} title={t("dialog.close")}>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<div className="ts-dialog-body">
|
||||
{!entries ? (
|
||||
<div className="ts-connection-info-loading">
|
||||
{timedOut ? t("connectionInfo.unavailable") : t("connectionInfo.loading")}
|
||||
</div>
|
||||
) : entries.length === 0 ? (
|
||||
<div className="ts-connection-info-loading">{t("complainList.empty")}</div>
|
||||
) : (
|
||||
<table className="ts-ban-list-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{t("complainList.target")}</th>
|
||||
<th>{t("complainList.from")}</th>
|
||||
<th>{t("complainList.message")}</th>
|
||||
<th>{t("complainList.timestamp")}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{entries.map((e, i) => (
|
||||
<tr key={i}>
|
||||
<td>{e.targetName}</td>
|
||||
<td>{e.fromName}</td>
|
||||
<td>{e.message}</td>
|
||||
<td>{e.timestamp}</td>
|
||||
<td>
|
||||
<button onClick={() => onDelete(e.targetClientDbId, e.fromClientDbId)}>
|
||||
{t("banList.delete")}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</div>
|
||||
<div className="ts-dialog-buttons">
|
||||
<div className="ts-dialog-buttons-right">
|
||||
<button onClick={onClose}>{t("dialog.close")}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ServerProtocolLogDialog({
|
||||
lines,
|
||||
onClose,
|
||||
@@ -2676,6 +2857,10 @@ function AppInner() {
|
||||
const [serverEditOpen, setServerEditOpen] = useState(false);
|
||||
const [serverProtocolLogOpen, setServerProtocolLogOpen] = useState(false);
|
||||
const [serverProtocolLog, setServerProtocolLog] = useState<string[] | null>(null);
|
||||
const [banListOpen, setBanListOpen] = useState(false);
|
||||
const [banList, setBanList] = useState<BanListEntry[] | null>(null);
|
||||
const [complainListOpen, setComplainListOpen] = useState(false);
|
||||
const [complainList, setComplainList] = useState<ComplainListEntry[] | null>(null);
|
||||
const [treeWidth, setTreeWidth] = useState(260);
|
||||
const [upperHeight, setUpperHeight] = useState(340);
|
||||
const [selected, setSelected] = useState<SelectedItem | null>(null);
|
||||
@@ -3240,6 +3425,12 @@ function AppInner() {
|
||||
case "serverProtocolLog":
|
||||
setServerProtocolLog(data.lines);
|
||||
break;
|
||||
case "banList":
|
||||
setBanList(data.entries);
|
||||
break;
|
||||
case "complainList":
|
||||
setComplainList(data.entries);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3816,6 +4007,41 @@ function AppInner() {
|
||||
socketRef.current?.send(JSON.stringify({ type: "getServerLog" }));
|
||||
};
|
||||
|
||||
const handleShowBanList = () => {
|
||||
setBanListOpen(true);
|
||||
setBanList(null);
|
||||
socketRef.current?.send(JSON.stringify({ type: "getBanList" }));
|
||||
};
|
||||
|
||||
const handleDeleteBan = (banId: number) => {
|
||||
socketRef.current?.send(JSON.stringify({ type: "deleteBan", banId }));
|
||||
setBanList((prev) => (prev ? prev.filter((e) => e.banId !== banId) : prev));
|
||||
};
|
||||
|
||||
const handleDeleteAllBans = () => {
|
||||
socketRef.current?.send(JSON.stringify({ type: "deleteAllBans" }));
|
||||
setBanList([]);
|
||||
};
|
||||
|
||||
const handleShowComplainList = () => {
|
||||
setComplainListOpen(true);
|
||||
setComplainList(null);
|
||||
socketRef.current?.send(JSON.stringify({ type: "getComplainList" }));
|
||||
};
|
||||
|
||||
const handleDeleteComplaint = (targetClientDbId: number, fromClientDbId: number) => {
|
||||
socketRef.current?.send(
|
||||
JSON.stringify({ type: "deleteComplaint", targetClientDbId, fromClientDbId })
|
||||
);
|
||||
setComplainList((prev) =>
|
||||
prev
|
||||
? prev.filter(
|
||||
(e) => !(e.targetClientDbId === targetClientDbId && e.fromClientDbId === fromClientDbId)
|
||||
)
|
||||
: prev
|
||||
);
|
||||
};
|
||||
|
||||
const handleClientContextMenu = (
|
||||
e: React.MouseEvent,
|
||||
clientId: number,
|
||||
@@ -4174,17 +4400,32 @@ function AppInner() {
|
||||
<span className="ts-menu-item-shortcut">Strg+L</span>
|
||||
</button>
|
||||
<div className="ts-menu-separator" />
|
||||
{[
|
||||
{ icon: "🚫", label: t("menu.extras.banList"), shortcut: "Strg+Umschalt+B" },
|
||||
{ icon: "⚠️", label: t("menu.extras.complaintList"), shortcut: "Strg+Umschalt+C" },
|
||||
{ icon: "🔑", label: t("menu.extras.serverQueryLogin") },
|
||||
].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"
|
||||
onClick={() => {
|
||||
handleShowBanList();
|
||||
setExtrasMenuOpen(false);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">🚫</span>
|
||||
<span className="ts-menu-item-label">{t("menu.extras.banList")}</span>
|
||||
<span className="ts-menu-item-shortcut">Strg+Umschalt+B</span>
|
||||
</button>
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
onClick={() => {
|
||||
handleShowComplainList();
|
||||
setExtrasMenuOpen(false);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">⚠️</span>
|
||||
<span className="ts-menu-item-label">{t("menu.extras.complaintList")}</span>
|
||||
<span className="ts-menu-item-shortcut">Strg+Umschalt+C</span>
|
||||
</button>
|
||||
<button className="ts-menu-item" disabled>
|
||||
<span className="ts-menu-item-icon">🔑</span>
|
||||
<span className="ts-menu-item-label">{t("menu.extras.serverQueryLogin")}</span>
|
||||
</button>
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
onClick={() => {
|
||||
@@ -4545,6 +4786,23 @@ function AppInner() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{banListOpen && (
|
||||
<BanListDialog
|
||||
entries={banList}
|
||||
onDelete={handleDeleteBan}
|
||||
onDeleteAll={handleDeleteAllBans}
|
||||
onClose={() => setBanListOpen(false)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{complainListOpen && (
|
||||
<ComplainListDialog
|
||||
entries={complainList}
|
||||
onDelete={handleDeleteComplaint}
|
||||
onClose={() => setComplainListOpen(false)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{contactsOpen && (
|
||||
<ContactsDialog
|
||||
contacts={contacts}
|
||||
|
||||
@@ -215,6 +215,66 @@ export class DemoSocket {
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "getBanList": {
|
||||
this.after(400, () =>
|
||||
this.emit({
|
||||
type: "banList",
|
||||
entries: [
|
||||
{
|
||||
banId: 1,
|
||||
ip: "203.0.113.42",
|
||||
name: "TrollUser",
|
||||
uid: "demo-uid-troll",
|
||||
lastNickname: "TrollUser",
|
||||
created: "2026-07-28 14:02:11",
|
||||
durationSecs: 0,
|
||||
invokerName: "Alex",
|
||||
reason: "Spamming the server chat",
|
||||
enforcements: 0,
|
||||
},
|
||||
{
|
||||
banId: 2,
|
||||
ip: "198.51.100.7",
|
||||
name: "",
|
||||
uid: "demo-uid-annoying",
|
||||
lastNickname: "AnnoyingGuest",
|
||||
created: "2026-08-01 09:44:53",
|
||||
durationSecs: 3600,
|
||||
invokerName: "Sam",
|
||||
reason: "Repeated channel spam",
|
||||
enforcements: 1,
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "deleteBan":
|
||||
case "deleteAllBans":
|
||||
// No observable effect - the frontend already optimistically removes
|
||||
// the deleted row(s) from its own state.
|
||||
break;
|
||||
case "getComplainList": {
|
||||
this.after(400, () =>
|
||||
this.emit({
|
||||
type: "complainList",
|
||||
entries: [
|
||||
{
|
||||
targetClientDbId: 104,
|
||||
targetName: "Jordan",
|
||||
fromClientDbId: 103,
|
||||
fromName: "Sam",
|
||||
message: "Kept talking over everyone in voice chat.",
|
||||
timestamp: "2026-08-02 18:21:07",
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "deleteComplaint":
|
||||
case "deleteAllComplaintsFor":
|
||||
break;
|
||||
// "disconnect" is intentionally unhandled here: handleDisconnect() in
|
||||
// App.tsx always calls socket.close() right after sending it, and
|
||||
// close() already emits the "disconnected" event below.
|
||||
|
||||
@@ -358,6 +358,23 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
|
||||
"serverProtocolLog.title": "Server Protokoll",
|
||||
"serverProtocolLog.empty": "Keine Protokolleinträge vorhanden.",
|
||||
"banList.title": "Bannliste",
|
||||
"banList.empty": "Keine Bans vorhanden.",
|
||||
"banList.name": "Name",
|
||||
"banList.ip": "IP",
|
||||
"banList.created": "Erstellt",
|
||||
"banList.duration": "Dauer",
|
||||
"banList.invoker": "Von",
|
||||
"banList.reason": "Grund",
|
||||
"banList.permanent": "Permanent",
|
||||
"banList.delete": "Löschen",
|
||||
"banList.deleteAll": "Alle löschen",
|
||||
"complainList.title": "Beschwerdeliste",
|
||||
"complainList.empty": "Keine Beschwerden vorhanden.",
|
||||
"complainList.target": "Ziel",
|
||||
"complainList.from": "Von",
|
||||
"complainList.message": "Nachricht",
|
||||
"complainList.timestamp": "Zeitpunkt",
|
||||
|
||||
"clientContext.privateChat": "Privater Chat",
|
||||
"clientContext.poke": "Anstupsen",
|
||||
@@ -754,6 +771,23 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
|
||||
"serverProtocolLog.title": "Server Log",
|
||||
"serverProtocolLog.empty": "No log entries.",
|
||||
"banList.title": "Ban List",
|
||||
"banList.empty": "No bans found.",
|
||||
"banList.name": "Name",
|
||||
"banList.ip": "IP",
|
||||
"banList.created": "Created",
|
||||
"banList.duration": "Duration",
|
||||
"banList.invoker": "By",
|
||||
"banList.reason": "Reason",
|
||||
"banList.permanent": "Permanent",
|
||||
"banList.delete": "Delete",
|
||||
"banList.deleteAll": "Delete all",
|
||||
"complainList.title": "Complaint List",
|
||||
"complainList.empty": "No complaints found.",
|
||||
"complainList.target": "Target",
|
||||
"complainList.from": "From",
|
||||
"complainList.message": "Message",
|
||||
"complainList.timestamp": "Timestamp",
|
||||
|
||||
"clientContext.privateChat": "Private chat",
|
||||
"clientContext.poke": "Poke",
|
||||
|
||||
Reference in new issue
Block a user