mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +08:00
fix: preserve TeamSpeak channel order
This commit is contained in:
1 parent
fae21ec086
commit
883703dd0c
5 files changed
+64
-11
No files matched your search
Generated
+2
-2
@@ -10,7 +10,7 @@
|
||||
"license": "AGPL-3.0-only",
|
||||
"dependencies": {
|
||||
"@discordjs/opus": "^0.10.0",
|
||||
"@echosixhiya/teamspeak-client": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#a145338",
|
||||
"@echosixhiya/teamspeak-client": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#128f9dc779a54258393c85ebfbe65bc9773e7495",
|
||||
"express": "^5.2.1",
|
||||
"pino": "^10.3.1",
|
||||
"werift": "0.24.4",
|
||||
@@ -63,7 +63,7 @@
|
||||
},
|
||||
"node_modules/@echosixhiya/teamspeak-client": {
|
||||
"version": "0.2.4",
|
||||
"resolved": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#a145338c7a83044dee0951c412ad91292b570215",
|
||||
"resolved": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#128f9dc779a54258393c85ebfbe65bc9773e7495",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@noble/curves": "^2.0.1"
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@discordjs/opus": "^0.10.0",
|
||||
"@echosixhiya/teamspeak-client": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#a145338",
|
||||
"@echosixhiya/teamspeak-client": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#128f9dc779a54258393c85ebfbe65bc9773e7495",
|
||||
"express": "^5.2.1",
|
||||
"pino": "^10.3.1",
|
||||
"werift": "0.24.4",
|
||||
|
||||
@@ -1223,6 +1223,7 @@ function mapChannelTree(snapshot: TSDirectorySnapshot): unknown[] {
|
||||
return snapshot.channels.map((channel) => ({
|
||||
id: String(channel.id),
|
||||
parentID: String(channel.parentID),
|
||||
order: String(channel.order),
|
||||
name: channel.name || "未命名频道",
|
||||
description: channel.description || "",
|
||||
members: snapshot.clients
|
||||
|
||||
@@ -72,6 +72,7 @@ type SinkAudioElement = HTMLAudioElement & {
|
||||
export interface ChannelInfo {
|
||||
id: string;
|
||||
parentID: string;
|
||||
order?: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
members?: { id: number; nickname: string; uid?: string; away?: boolean; awayMessage?: string; inputMuted?: boolean; outputMuted?: boolean; channelCommander?: boolean }[];
|
||||
|
||||
@@ -1742,7 +1742,12 @@ const heroBars = [12, 24, 18, 35, 18, 28, 42, 23, 50, 34, 19, 28, 39, 22, 46, 25
|
||||
|
||||
const channelTree = computed<TreeChannel[]>(() => {
|
||||
const source = [...channels];
|
||||
const byId = new Map(source.map((item) => [item.id, item]));
|
||||
const sourceIndex = new Map(source.map((item, index) => [item.id, index]));
|
||||
const enriched = source.map((item) => ({
|
||||
...item,
|
||||
members: (item.members ?? []).map((member) => ({ ...member, isSelf: member.id === voiceState.tsClientId })),
|
||||
}));
|
||||
const byId = new Map(enriched.map((item) => [item.id, item]));
|
||||
const depthCache = new Map<string, number>();
|
||||
|
||||
function depthOf(item: ChannelInfo, visiting = new Set<string>()): number {
|
||||
@@ -1754,13 +1759,59 @@ const channelTree = computed<TreeChannel[]>(() => {
|
||||
return depth;
|
||||
}
|
||||
|
||||
return source
|
||||
.map((item) => ({
|
||||
...item,
|
||||
depth: depthOf(item),
|
||||
members: (item.members ?? []).map((member) => ({ ...member, isSelf: member.id === voiceState.tsClientId })),
|
||||
}))
|
||||
.sort((a, b) => `${a.parentID}/${a.id}`.localeCompare(`${b.parentID}/${b.id}`));
|
||||
const childrenByParent = new Map<string, TreeChannel[]>();
|
||||
for (const item of enriched) {
|
||||
const channel = { ...item, depth: depthOf(item) };
|
||||
const siblings = childrenByParent.get(channel.parentID) ?? [];
|
||||
siblings.push(channel);
|
||||
childrenByParent.set(channel.parentID, siblings);
|
||||
}
|
||||
|
||||
function orderSiblings(siblings: TreeChannel[]): TreeChannel[] {
|
||||
const bySiblingId = new Map(siblings.map((item) => [item.id, item]));
|
||||
const successors = new Map<string, TreeChannel[]>();
|
||||
const roots: TreeChannel[] = [];
|
||||
const sourceOrder = (left: TreeChannel, right: TreeChannel) =>
|
||||
(sourceIndex.get(left.id) ?? Number.MAX_SAFE_INTEGER) - (sourceIndex.get(right.id) ?? Number.MAX_SAFE_INTEGER);
|
||||
|
||||
for (const item of siblings) {
|
||||
const predecessor = item.order && item.order !== "0" && bySiblingId.has(item.order) ? item.order : "";
|
||||
if (!predecessor) roots.push(item);
|
||||
else successors.set(predecessor, [...(successors.get(predecessor) ?? []), item]);
|
||||
}
|
||||
|
||||
roots.sort(sourceOrder);
|
||||
for (const items of successors.values()) items.sort(sourceOrder);
|
||||
|
||||
const ordered: TreeChannel[] = [];
|
||||
const visited = new Set<string>();
|
||||
const append = (item: TreeChannel) => {
|
||||
if (visited.has(item.id)) return;
|
||||
visited.add(item.id);
|
||||
ordered.push(item);
|
||||
for (const successor of successors.get(item.id) ?? []) append(successor);
|
||||
};
|
||||
for (const root of roots) append(root);
|
||||
for (const item of [...siblings].sort(sourceOrder)) append(item);
|
||||
return ordered;
|
||||
}
|
||||
|
||||
const orderedTree: TreeChannel[] = [];
|
||||
const visit = (parentID: string) => {
|
||||
for (const channel of orderSiblings(childrenByParent.get(parentID) ?? [])) {
|
||||
orderedTree.push(channel);
|
||||
visit(channel.id);
|
||||
}
|
||||
};
|
||||
visit("0");
|
||||
for (const channel of enriched) {
|
||||
if (!orderedTree.some((item) => item.id === channel.id)) {
|
||||
const fallback = { ...channel, depth: depthOf(channel) };
|
||||
orderedTree.push(fallback);
|
||||
visit(channel.id);
|
||||
}
|
||||
}
|
||||
return orderedTree;
|
||||
});
|
||||
|
||||
const currentChannel = computed<TreeChannel | undefined>(() => {
|
||||
|
||||
Reference in new issue
Block a user