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:
MoepchiandClaude Sonnet 5 committed 2026-08-05 20:40:52 +02:00
1 parent 203e8fba51
commit db8b5ea958
7 files changed
+464 -8

No files matched your search

+168 -2
View File
@@ -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>