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
@@ -77,6 +77,9 @@ struct ClientInfo {
|
||||
is_channel_commander: bool,
|
||||
country: String,
|
||||
uid: String,
|
||||
database_id: u64,
|
||||
channel_group: u64,
|
||||
server_groups: Vec<u64>,
|
||||
}
|
||||
|
||||
/// Payload for the "serveredit " stdin command - every field is optional so
|
||||
@@ -256,6 +259,12 @@ enum Event {
|
||||
message: String,
|
||||
timestamp: String,
|
||||
},
|
||||
/// Reply to a "channelgrouplist" request.
|
||||
#[serde(rename = "channelGroupList")]
|
||||
ChannelGroupList { entries: Vec<GroupEntry> },
|
||||
/// Reply to a "servergrouplist" request.
|
||||
#[serde(rename = "serverGroupList")]
|
||||
ServerGroupList { entries: Vec<GroupEntry> },
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -294,6 +303,13 @@ struct OfflineMessageListEntry {
|
||||
is_read: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GroupEntry {
|
||||
id: u64,
|
||||
name: String,
|
||||
}
|
||||
|
||||
fn emit(event: &Event) {
|
||||
println!("{}", serde_json::to_string(event).unwrap());
|
||||
}
|
||||
@@ -467,6 +483,9 @@ fn snapshot(con: &data::Connection) -> Event {
|
||||
is_channel_commander: c.is_channel_commander,
|
||||
country: c.country_code.clone(),
|
||||
uid: c.uid.as_ref().map(|u| u.to_string()).unwrap_or_default(),
|
||||
database_id: c.database_id.0,
|
||||
channel_group: c.channel_group.0,
|
||||
server_groups: c.server_groups.iter().map(|g| g.0).collect(),
|
||||
})
|
||||
.collect();
|
||||
Event::Channels { channels, clients }
|
||||
@@ -611,6 +630,8 @@ async fn run(args: Args) -> Result<()> {
|
||||
let mut pending_complain_list = false;
|
||||
let mut pending_offline_message_list = false;
|
||||
let mut pending_offline_message_get = false;
|
||||
let mut pending_channel_group_list = false;
|
||||
let mut pending_server_group_list = false;
|
||||
|
||||
enum LoopOutcome {
|
||||
StdinLine(std::io::Result<Option<String>>),
|
||||
@@ -1127,6 +1148,105 @@ async fn run(args: Args) -> Result<()> {
|
||||
}
|
||||
Err(_) => emit(&Event::Error { message: format!("Invalid message id: {rest}") }),
|
||||
}
|
||||
} else if l == "channelgrouplist" {
|
||||
let packet = OutCommand::new(
|
||||
Direction::C2S,
|
||||
Flags::empty(),
|
||||
PacketType::Command,
|
||||
"channelgrouplist",
|
||||
);
|
||||
match packet.send_with_result(&mut con) {
|
||||
Ok(handle) => {
|
||||
pending_channel_group_list = true;
|
||||
pending_messages.insert(handle, "Channel group list".into());
|
||||
}
|
||||
Err(e) => emit(&Event::Error { message: e.to_string() }),
|
||||
}
|
||||
} else if l == "servergrouplist" {
|
||||
let packet = OutCommand::new(
|
||||
Direction::C2S,
|
||||
Flags::empty(),
|
||||
PacketType::Command,
|
||||
"servergrouplist",
|
||||
);
|
||||
match packet.send_with_result(&mut con) {
|
||||
Ok(handle) => {
|
||||
pending_server_group_list = true;
|
||||
pending_messages.insert(handle, "Server group list".into());
|
||||
}
|
||||
Err(e) => emit(&Event::Error { message: e.to_string() }),
|
||||
}
|
||||
} else if let Some(rest) = l.strip_prefix("setchannelgroup ") {
|
||||
let mut parts = rest.trim().splitn(3, ' ');
|
||||
let cgid_str = parts.next().unwrap_or("");
|
||||
let cid_str = parts.next().unwrap_or("");
|
||||
let cldbid_str = parts.next().unwrap_or("");
|
||||
match (cgid_str.parse::<u64>(), cid_str.parse::<u64>(), cldbid_str.parse::<u64>()) {
|
||||
(Ok(cgid), Ok(cid), Ok(cldbid)) => {
|
||||
let mut packet = OutCommand::new(
|
||||
Direction::C2S,
|
||||
Flags::empty(),
|
||||
PacketType::Command,
|
||||
"setclientchannelgroup",
|
||||
);
|
||||
packet.write_arg("cgid", &cgid);
|
||||
packet.write_arg("cid", &cid);
|
||||
packet.write_arg("cldbid", &cldbid);
|
||||
match packet.send_with_result(&mut con) {
|
||||
Ok(handle) => {
|
||||
pending_messages.insert(handle, "Assign channel group".into());
|
||||
}
|
||||
Err(e) => emit(&Event::Error { message: e.to_string() }),
|
||||
}
|
||||
}
|
||||
_ => emit(&Event::Error { message: format!("Invalid setchannelgroup args: {rest}") }),
|
||||
}
|
||||
} else if let Some(rest) = l.strip_prefix("addservergroup ") {
|
||||
let mut parts = rest.trim().splitn(2, ' ');
|
||||
let sgid_str = parts.next().unwrap_or("");
|
||||
let cldbid_str = parts.next().unwrap_or("");
|
||||
match (sgid_str.parse::<u64>(), cldbid_str.parse::<u64>()) {
|
||||
(Ok(sgid), Ok(cldbid)) => {
|
||||
let mut packet = OutCommand::new(
|
||||
Direction::C2S,
|
||||
Flags::empty(),
|
||||
PacketType::Command,
|
||||
"servergroupaddclient",
|
||||
);
|
||||
packet.write_arg("sgid", &sgid);
|
||||
packet.write_arg("cldbid", &cldbid);
|
||||
match packet.send_with_result(&mut con) {
|
||||
Ok(handle) => {
|
||||
pending_messages.insert(handle, "Assign server group".into());
|
||||
}
|
||||
Err(e) => emit(&Event::Error { message: e.to_string() }),
|
||||
}
|
||||
}
|
||||
_ => emit(&Event::Error { message: format!("Invalid addservergroup args: {rest}") }),
|
||||
}
|
||||
} else if let Some(rest) = l.strip_prefix("delservergroup ") {
|
||||
let mut parts = rest.trim().splitn(2, ' ');
|
||||
let sgid_str = parts.next().unwrap_or("");
|
||||
let cldbid_str = parts.next().unwrap_or("");
|
||||
match (sgid_str.parse::<u64>(), cldbid_str.parse::<u64>()) {
|
||||
(Ok(sgid), Ok(cldbid)) => {
|
||||
let mut packet = OutCommand::new(
|
||||
Direction::C2S,
|
||||
Flags::empty(),
|
||||
PacketType::Command,
|
||||
"servergroupdelclient",
|
||||
);
|
||||
packet.write_arg("sgid", &sgid);
|
||||
packet.write_arg("cldbid", &cldbid);
|
||||
match packet.send_with_result(&mut con) {
|
||||
Ok(handle) => {
|
||||
pending_messages.insert(handle, "Remove server group".into());
|
||||
}
|
||||
Err(e) => emit(&Event::Error { message: e.to_string() }),
|
||||
}
|
||||
}
|
||||
_ => emit(&Event::Error { message: format!("Invalid delservergroup args: {rest}") }),
|
||||
}
|
||||
} else if let Some(b64) = l.strip_prefix("audio ") {
|
||||
match base64::engine::general_purpose::STANDARD.decode(b64.trim()) {
|
||||
Ok(bytes) => {
|
||||
@@ -1376,6 +1496,26 @@ async fn run(args: Args) -> Result<()> {
|
||||
pending_offline_message_get = false;
|
||||
}
|
||||
}
|
||||
if pending_channel_group_list {
|
||||
if let InMessage::ChannelGroupList(list) = &msg {
|
||||
let entries: Vec<GroupEntry> = list
|
||||
.iter()
|
||||
.map(|part| GroupEntry { id: part.channel_group.0, name: part.name.clone() })
|
||||
.collect();
|
||||
emit(&Event::ChannelGroupList { entries });
|
||||
pending_channel_group_list = false;
|
||||
}
|
||||
}
|
||||
if pending_server_group_list {
|
||||
if let InMessage::ServerGroupList(list) = &msg {
|
||||
let entries: Vec<GroupEntry> = list
|
||||
.iter()
|
||||
.map(|part| GroupEntry { id: part.server_group_id.0, name: part.name.clone() })
|
||||
.collect();
|
||||
emit(&Event::ServerGroupList { entries });
|
||||
pending_server_group_list = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(Ok(_)) => {}
|
||||
Some(Err(e)) => {
|
||||
|
||||
@@ -194,6 +194,26 @@ wss.on("connection", (socket: WebSocket) => {
|
||||
await connection?.markOfflineMessageRead(msg.messageId);
|
||||
break;
|
||||
}
|
||||
case "getChannelGroupList": {
|
||||
await connection?.getChannelGroupList();
|
||||
break;
|
||||
}
|
||||
case "getServerGroupList": {
|
||||
await connection?.getServerGroupList();
|
||||
break;
|
||||
}
|
||||
case "setChannelGroup": {
|
||||
await connection?.setChannelGroup(msg.channelGroupId, msg.channelId, msg.clientDbId);
|
||||
break;
|
||||
}
|
||||
case "addServerGroup": {
|
||||
await connection?.addServerGroup(msg.serverGroupId, msg.clientDbId);
|
||||
break;
|
||||
}
|
||||
case "removeServerGroup": {
|
||||
await connection?.removeServerGroup(msg.serverGroupId, msg.clientDbId);
|
||||
break;
|
||||
}
|
||||
case "disconnect": {
|
||||
await connection?.disconnect(msg.message ?? "");
|
||||
break;
|
||||
|
||||
@@ -33,6 +33,14 @@ export interface ClientInfo {
|
||||
isChannelCommander: boolean;
|
||||
country: string;
|
||||
uid: string;
|
||||
databaseId: number;
|
||||
channelGroup: number;
|
||||
serverGroups: number[];
|
||||
}
|
||||
|
||||
export interface GroupEntry {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface BanListEntry {
|
||||
@@ -132,7 +140,9 @@ export type Ts3ConnectionEvent =
|
||||
subject: string;
|
||||
message: string;
|
||||
timestamp: string;
|
||||
};
|
||||
}
|
||||
| { type: "channelGroupList"; entries: GroupEntry[] }
|
||||
| { type: "serverGroupList"; entries: GroupEntry[] };
|
||||
|
||||
export interface Ts3ConnectOptions {
|
||||
host: string;
|
||||
@@ -190,6 +200,9 @@ export class Ts3Connection {
|
||||
is_channel_commander: boolean;
|
||||
country: string;
|
||||
uid: string;
|
||||
database_id: number;
|
||||
channel_group: number;
|
||||
server_groups: number[];
|
||||
}
|
||||
|
||||
interface RawChannelInfo {
|
||||
@@ -292,7 +305,9 @@ export class Ts3Connection {
|
||||
subject: string;
|
||||
message: string;
|
||||
timestamp: string;
|
||||
};
|
||||
}
|
||||
| { type: "channelGroupList"; entries: { id: number; name: string }[] }
|
||||
| { type: "serverGroupList"; entries: { id: number; name: string }[] };
|
||||
|
||||
if (event.type === "connected") {
|
||||
this.emit({
|
||||
@@ -330,6 +345,9 @@ export class Ts3Connection {
|
||||
isChannelCommander: c.is_channel_commander,
|
||||
country: c.country,
|
||||
uid: c.uid,
|
||||
databaseId: c.database_id,
|
||||
channelGroup: c.channel_group,
|
||||
serverGroups: c.server_groups,
|
||||
})),
|
||||
});
|
||||
} else if (event.type === "privateMessage") {
|
||||
@@ -535,6 +553,26 @@ export class Ts3Connection {
|
||||
this.child?.stdin.write(`messageupdateflag ${messageId} 1\n`);
|
||||
}
|
||||
|
||||
async getChannelGroupList(): Promise<void> {
|
||||
this.child?.stdin.write(`channelgrouplist\n`);
|
||||
}
|
||||
|
||||
async getServerGroupList(): Promise<void> {
|
||||
this.child?.stdin.write(`servergrouplist\n`);
|
||||
}
|
||||
|
||||
async setChannelGroup(channelGroupId: number, channelId: number, clientDbId: number): Promise<void> {
|
||||
this.child?.stdin.write(`setchannelgroup ${channelGroupId} ${channelId} ${clientDbId}\n`);
|
||||
}
|
||||
|
||||
async addServerGroup(serverGroupId: number, clientDbId: number): Promise<void> {
|
||||
this.child?.stdin.write(`addservergroup ${serverGroupId} ${clientDbId}\n`);
|
||||
}
|
||||
|
||||
async removeServerGroup(serverGroupId: number, clientDbId: number): Promise<void> {
|
||||
this.child?.stdin.write(`delservergroup ${serverGroupId} ${clientDbId}\n`);
|
||||
}
|
||||
|
||||
async sendChatMessage(message: string): Promise<void> {
|
||||
const sanitized = message.replace(/[\r\n]+/g, " ").trim();
|
||||
if (sanitized) this.child?.stdin.write(`chat ${sanitized}\n`);
|
||||
|
||||
@@ -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