mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42:49 +08:00
Complete client context menu: channel/server group assignment
Fills out the last two disabled entries in the client right-click menu (#72): "Channel-Gruppe zuweisen" and "Server-Gruppe zuweisen". - Connector: exposes each client's database_id, channel_group, and server_groups (already present in tsclientlib's bookkeeping Client struct, just not threaded through before) on the "channels" snapshot. Adds raw commands for channelgrouplist/servergrouplist (list requests, same InMessage pattern as banlist/complainlist) and setclientchannelgroup/servergroupaddclient/servergroupdelclient (assignment, fire-and-forget like kick/ban). - Gateway: typed passthrough for the new client fields and five new message types (getChannelGroupList, getServerGroupList, setChannelGroup, addServerGroup, removeServerGroup). - Frontend: new GroupAssignDialog reused for both channel groups (single-select, closes after assigning) and server groups (multi-select, checkmarked entries toggle add/remove and the dialog stays open). Demo mode simulates real group membership changes, including live re-render after assignment. Verified against the real server: the client's own database_id/ channel_group/server_groups now flow correctly end-to-end (confirmed via a throwaway gateway test script). The list-request commands are permission-gated for the guest test account and decline silently, same as serverlog/serverconninfo before them - the dialog's existing 6s "unavailable" timeout already covers this. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
203e8fba51
commit
db8b5ea958
7 files changed
+464
-8
No files matched your search
@@ -1121,6 +1121,33 @@
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.ts-group-assign-dialog {
|
||||
width: 420px;
|
||||
}
|
||||
|
||||
.ts-group-assign-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.15rem;
|
||||
}
|
||||
|
||||
.ts-group-assign-list .ts-menu-item {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ts-group-assign-current {
|
||||
background: var(--bg-hover, rgba(255, 255, 255, 0.06));
|
||||
}
|
||||
|
||||
.ts-group-assign-hint {
|
||||
margin-left: auto;
|
||||
color: var(--text-muted);
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.ts-server-protocol-log-line {
|
||||
padding: 0.15rem 0.4rem;
|
||||
border-bottom: 1px solid var(--border-soft);
|
||||
|
||||
+168
-2
@@ -310,6 +310,14 @@ interface ClientInfo {
|
||||
isChannelCommander: boolean;
|
||||
country: string;
|
||||
uid: string;
|
||||
databaseId: number;
|
||||
channelGroup: number;
|
||||
serverGroups: number[];
|
||||
}
|
||||
|
||||
interface GroupEntry {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface ClientConnectionInfoData {
|
||||
@@ -1524,6 +1532,82 @@ function OfflineMessagesDialog({
|
||||
);
|
||||
}
|
||||
|
||||
function GroupAssignDialog({
|
||||
kind,
|
||||
clientName,
|
||||
groups,
|
||||
currentGroupIds,
|
||||
onSelect,
|
||||
onClose,
|
||||
}: {
|
||||
kind: "channel" | "server";
|
||||
clientName: string;
|
||||
groups: GroupEntry[] | null;
|
||||
currentGroupIds: number[];
|
||||
onSelect: (groupId: number, alreadyAssigned: boolean) => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const t = useT();
|
||||
const backdrop = useBackdropDismiss(onClose);
|
||||
const [timedOut, setTimedOut] = useState(false);
|
||||
useEffect(() => {
|
||||
setTimedOut(false);
|
||||
if (groups) return;
|
||||
const id = window.setTimeout(() => setTimedOut(true), 6000);
|
||||
return () => window.clearTimeout(id);
|
||||
}, [groups]);
|
||||
|
||||
return (
|
||||
<div className="ts-dialog-backdrop" {...backdrop}>
|
||||
<div className="ts-dialog ts-group-assign-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="ts-dialog-titlebar">
|
||||
<span>
|
||||
{kind === "channel" ? t("groupAssign.channelTitle") : t("groupAssign.serverTitle")} - {clientName}
|
||||
</span>
|
||||
<button onClick={onClose} title={t("dialog.close")}>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<div className="ts-dialog-body">
|
||||
{!groups ? (
|
||||
<div className="ts-connection-info-loading">
|
||||
{timedOut ? t("connectionInfo.unavailable") : t("connectionInfo.loading")}
|
||||
</div>
|
||||
) : groups.length === 0 ? (
|
||||
<div className="ts-connection-info-loading">{t("groupAssign.empty")}</div>
|
||||
) : (
|
||||
<ul className="ts-group-assign-list">
|
||||
{groups.map((g) => {
|
||||
const assigned = currentGroupIds.includes(g.id);
|
||||
return (
|
||||
<li key={g.id}>
|
||||
<button
|
||||
className={`ts-menu-item${assigned ? " ts-group-assign-current" : ""}`}
|
||||
onClick={() => onSelect(g.id, assigned)}
|
||||
>
|
||||
<span className="ts-menu-item-icon">{assigned ? "✔️" : kind === "channel" ? "🏷️" : "🎖️"}</span>
|
||||
<span className="ts-menu-item-label">{g.name}</span>
|
||||
{kind === "server" && assigned && (
|
||||
<span className="ts-group-assign-hint">{t("groupAssign.clickToRemove")}</span>
|
||||
)}
|
||||
</button>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
<div className="ts-dialog-buttons">
|
||||
<div />
|
||||
<div className="ts-dialog-buttons-right">
|
||||
<button onClick={onClose}>{t("dialog.close")}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ServerProtocolLogDialog({
|
||||
lines,
|
||||
onClose,
|
||||
@@ -3011,6 +3095,13 @@ function AppInner() {
|
||||
const [offlineMessageDetail, setOfflineMessageDetail] = useState<
|
||||
{ messageId: number; clientUid: string; subject: string; message: string; timestamp: string } | null
|
||||
>(null);
|
||||
const [channelGroups, setChannelGroups] = useState<GroupEntry[] | null>(null);
|
||||
const [serverGroups, setServerGroups] = useState<GroupEntry[] | null>(null);
|
||||
const [groupAssignTarget, setGroupAssignTarget] = useState<{
|
||||
kind: "channel" | "server";
|
||||
clientId: number;
|
||||
clientName: string;
|
||||
} | null>(null);
|
||||
const [treeWidth, setTreeWidth] = useState(260);
|
||||
const [upperHeight, setUpperHeight] = useState(340);
|
||||
const [selected, setSelected] = useState<SelectedItem | null>(null);
|
||||
@@ -3597,6 +3688,12 @@ function AppInner() {
|
||||
timestamp: data.timestamp,
|
||||
});
|
||||
break;
|
||||
case "channelGroupList":
|
||||
setChannelGroups(data.entries);
|
||||
break;
|
||||
case "serverGroupList":
|
||||
setServerGroups(data.entries);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4291,6 +4388,48 @@ function AppInner() {
|
||||
setServerContextMenu({ x, y });
|
||||
};
|
||||
|
||||
const handleShowChannelGroupAssign = (clientId: number, clientName: string) => {
|
||||
setGroupAssignTarget({ kind: "channel", clientId, clientName });
|
||||
setChannelGroups(null);
|
||||
socketRef.current?.send(JSON.stringify({ type: "getChannelGroupList" }));
|
||||
};
|
||||
|
||||
const handleShowServerGroupAssign = (clientId: number, clientName: string) => {
|
||||
setGroupAssignTarget({ kind: "server", clientId, clientName });
|
||||
setServerGroups(null);
|
||||
socketRef.current?.send(JSON.stringify({ type: "getServerGroupList" }));
|
||||
};
|
||||
|
||||
const handleSelectGroup = (groupId: number, alreadyAssigned: boolean) => {
|
||||
if (!groupAssignTarget) return;
|
||||
const target = clients.find((c) => c.id === groupAssignTarget.clientId);
|
||||
if (!target) {
|
||||
setGroupAssignTarget(null);
|
||||
return;
|
||||
}
|
||||
if (groupAssignTarget.kind === "channel") {
|
||||
socketRef.current?.send(
|
||||
JSON.stringify({
|
||||
type: "setChannelGroup",
|
||||
channelGroupId: groupId,
|
||||
channelId: target.channel,
|
||||
clientDbId: target.databaseId,
|
||||
})
|
||||
);
|
||||
setGroupAssignTarget(null);
|
||||
} else {
|
||||
socketRef.current?.send(
|
||||
JSON.stringify({
|
||||
type: alreadyAssigned ? "removeServerGroup" : "addServerGroup",
|
||||
serverGroupId: groupId,
|
||||
clientDbId: target.databaseId,
|
||||
})
|
||||
);
|
||||
// Server group membership is multi-select, so keep the dialog open for
|
||||
// further toggling instead of closing after a single action.
|
||||
}
|
||||
};
|
||||
|
||||
const handleSendPoke = () => {
|
||||
if (!pokeTarget) return;
|
||||
socketRef.current?.send(
|
||||
@@ -5099,6 +5238,21 @@ function AppInner() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{groupAssignTarget && (
|
||||
<GroupAssignDialog
|
||||
kind={groupAssignTarget.kind}
|
||||
clientName={groupAssignTarget.clientName}
|
||||
groups={groupAssignTarget.kind === "channel" ? channelGroups : serverGroups}
|
||||
currentGroupIds={(() => {
|
||||
const target = clients.find((c) => c.id === groupAssignTarget.clientId);
|
||||
if (!target) return [];
|
||||
return groupAssignTarget.kind === "channel" ? [target.channelGroup] : target.serverGroups;
|
||||
})()}
|
||||
onSelect={handleSelectGroup}
|
||||
onClose={() => setGroupAssignTarget(null)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{contactsOpen && (
|
||||
<ContactsDialog
|
||||
contacts={contacts}
|
||||
@@ -5347,11 +5501,23 @@ function AppInner() {
|
||||
</button>
|
||||
)}
|
||||
<div className="ts-menu-separator" />
|
||||
<button className="ts-menu-item" disabled title={t("clientContext.notSupported")}>
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
onClick={() => {
|
||||
handleShowChannelGroupAssign(clientContextMenu.clientId, clientContextMenu.clientName);
|
||||
setClientContextMenu(null);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">🏷️</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.assignChannelGroup")}</span>
|
||||
</button>
|
||||
<button className="ts-menu-item" disabled title={t("clientContext.notSupported")}>
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
onClick={() => {
|
||||
handleShowServerGroupAssign(clientContextMenu.clientId, clientContextMenu.clientName);
|
||||
setClientContextMenu(null);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">🎖️</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.assignServerGroup")}</span>
|
||||
</button>
|
||||
|
||||
+59
-4
@@ -30,6 +30,9 @@ interface DemoClient {
|
||||
isChannelCommander: boolean;
|
||||
country: string;
|
||||
uid: string;
|
||||
databaseId: number;
|
||||
channelGroup: number;
|
||||
serverGroups: number[];
|
||||
}
|
||||
|
||||
const DEMO_CHANNELS: DemoChannel[] = [
|
||||
@@ -38,11 +41,25 @@ const DEMO_CHANNELS: DemoChannel[] = [
|
||||
{ id: 3, parent: 0, order: 2, name: "AFK", topic: "", codec: "Opus Voice", maxClients: null, hasPassword: false },
|
||||
];
|
||||
|
||||
const DEMO_CHANNEL_GROUPS = [
|
||||
{ id: 1, name: "Channel Admin" },
|
||||
{ id: 2, name: "Operator" },
|
||||
{ id: 3, name: "Voice" },
|
||||
{ id: 4, name: "Guest" },
|
||||
];
|
||||
|
||||
const DEMO_SERVER_GROUPS = [
|
||||
{ id: 1, name: "Server Admin" },
|
||||
{ id: 2, name: "Moderator" },
|
||||
{ id: 3, name: "Trusted" },
|
||||
{ id: 4, name: "Guest" },
|
||||
];
|
||||
|
||||
const DEMO_NPCS: DemoClient[] = [
|
||||
{ id: 102, channel: 1, name: "Alex", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: true, country: "US", uid: "demo-uid-alex" },
|
||||
{ id: 103, channel: 2, name: "Sam", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "GB", uid: "demo-uid-sam" },
|
||||
{ id: 104, channel: 2, name: "Jordan", inputMuted: true, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "CA", uid: "demo-uid-jordan" },
|
||||
{ id: 105, channel: 3, name: "Riley", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: true, awayMessage: "brb, grabbing coffee", isChannelCommander: false, country: "DE", uid: "demo-uid-riley" },
|
||||
{ id: 102, channel: 1, name: "Alex", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: true, country: "US", uid: "demo-uid-alex", databaseId: 2, channelGroup: 2, serverGroups: [2] },
|
||||
{ id: 103, channel: 2, name: "Sam", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "GB", uid: "demo-uid-sam", databaseId: 3, channelGroup: 4, serverGroups: [4] },
|
||||
{ id: 104, channel: 2, name: "Jordan", inputMuted: true, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "CA", uid: "demo-uid-jordan", databaseId: 4, channelGroup: 4, serverGroups: [4] },
|
||||
{ id: 105, channel: 3, name: "Riley", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: true, awayMessage: "brb, grabbing coffee", isChannelCommander: false, country: "DE", uid: "demo-uid-riley", databaseId: 5, channelGroup: 4, serverGroups: [3, 4] },
|
||||
];
|
||||
|
||||
const SELF_ID = 101;
|
||||
@@ -63,6 +80,8 @@ export class DemoSocket {
|
||||
private closed = false;
|
||||
private timers: number[] = [];
|
||||
private selfChannel = 1;
|
||||
private selfChannelGroup = 4;
|
||||
private selfServerGroups = new Set<number>([4]);
|
||||
|
||||
constructor() {
|
||||
this.after(400, () => {
|
||||
@@ -311,6 +330,39 @@ export class DemoSocket {
|
||||
// No observable effect - the frontend already optimistically updates
|
||||
// its own state for delete/read, and there's no NPC to reply to a send.
|
||||
break;
|
||||
case "getChannelGroupList":
|
||||
this.after(300, () => this.emit({ type: "channelGroupList", entries: DEMO_CHANNEL_GROUPS }));
|
||||
break;
|
||||
case "getServerGroupList":
|
||||
this.after(300, () => this.emit({ type: "serverGroupList", entries: DEMO_SERVER_GROUPS }));
|
||||
break;
|
||||
case "setChannelGroup": {
|
||||
const npc = DEMO_NPCS.find((c) => c.databaseId === msg.clientDbId);
|
||||
if (npc) npc.channelGroup = msg.channelGroupId;
|
||||
else if (msg.clientDbId === 1) this.selfChannelGroup = msg.channelGroupId;
|
||||
this.after(200, () => this.sendChannels(this.lastNickname));
|
||||
break;
|
||||
}
|
||||
case "addServerGroup": {
|
||||
const npc = DEMO_NPCS.find((c) => c.databaseId === msg.clientDbId);
|
||||
if (npc) {
|
||||
if (!npc.serverGroups.includes(msg.serverGroupId)) npc.serverGroups.push(msg.serverGroupId);
|
||||
} else if (msg.clientDbId === 1) {
|
||||
this.selfServerGroups.add(msg.serverGroupId);
|
||||
}
|
||||
this.after(200, () => this.sendChannels(this.lastNickname));
|
||||
break;
|
||||
}
|
||||
case "removeServerGroup": {
|
||||
const npc = DEMO_NPCS.find((c) => c.databaseId === msg.clientDbId);
|
||||
if (npc) {
|
||||
npc.serverGroups = npc.serverGroups.filter((g) => g !== msg.serverGroupId);
|
||||
} else if (msg.clientDbId === 1) {
|
||||
this.selfServerGroups.delete(msg.serverGroupId);
|
||||
}
|
||||
this.after(200, () => this.sendChannels(this.lastNickname));
|
||||
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.
|
||||
@@ -366,6 +418,9 @@ export class DemoSocket {
|
||||
isChannelCommander: false,
|
||||
country: "",
|
||||
uid: "demo-uid-self",
|
||||
databaseId: 1,
|
||||
channelGroup: this.selfChannelGroup,
|
||||
serverGroups: [...this.selfServerGroups],
|
||||
};
|
||||
this.emit({ type: "channels", channels: DEMO_CHANNELS, clients: [self, ...DEMO_NPCS] });
|
||||
}
|
||||
|
||||
@@ -395,6 +395,11 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"offlineMessages.backToList": "Zurück zur Liste",
|
||||
"dialog.cancel": "Abbrechen",
|
||||
|
||||
"groupAssign.channelTitle": "Channel-Gruppe zuweisen",
|
||||
"groupAssign.serverTitle": "Server-Gruppe zuweisen",
|
||||
"groupAssign.empty": "Keine Gruppen vorhanden.",
|
||||
"groupAssign.clickToRemove": "Klicken zum Entfernen",
|
||||
|
||||
"clientContext.privateChat": "Privater Chat",
|
||||
"clientContext.poke": "Anstupsen",
|
||||
"clientContext.copyName": "Namen kopieren",
|
||||
@@ -832,6 +837,11 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"offlineMessages.backToList": "Back to list",
|
||||
"dialog.cancel": "Cancel",
|
||||
|
||||
"groupAssign.channelTitle": "Assign Channel Group",
|
||||
"groupAssign.serverTitle": "Assign Server Group",
|
||||
"groupAssign.empty": "No groups found.",
|
||||
"groupAssign.clickToRemove": "Click to remove",
|
||||
|
||||
"clientContext.privateChat": "Private chat",
|
||||
"clientContext.poke": "Poke",
|
||||
"clientContext.copyName": "Copy name",
|
||||
|
||||
Reference in new issue
Block a user