feat(channels): render TeamSpeak spacers across skins

This commit is contained in:
illusia committed 2026-10-24 18:16:01 +08:00
1 parent 4bff2133b6
commit b9fccb8757
21 files changed
+240 -17

No files matched your search

+14
View File
@@ -9,6 +9,20 @@ const directory = (): TSDirectorySnapshot => ({
clients: [{ id: 2, channelID: 1n, nickname: "Member", uid: "uid-2", type: 0, serverGroups: [], away: true, inputMuted: true }],
});
test("permanent channel flags survive the gateway wire, without guessing omitted flags", () => {
const source = directory();
source.channels[0] = { ...source.channels[0], name: "[cspacer0]Section", isPermanent: true };
source.channels[1] = { ...source.channels[1], isPermanent: false };
const channels = mapChannelTree(source);
const message = parseServerMessage(JSON.parse(JSON.stringify({ type: "channelList", channels })));
assert.ok(message?.type === "channelList");
assert.equal(message.channels[0].name, "[cspacer0]Section");
assert.equal(message.channels[0].isPermanent, true);
assert.equal(message.channels[1].isPermanent, false);
assert.equal(Object.hasOwn(mapChannelTree(directory())[0], "isPermanent"), false);
assert.equal(parseServerMessage({ type: "channelList", channels: [{ ...channels[0], isPermanent: "true" }] }), null);
});
test("self restoration uses the connected channel before a snapshot or requested channel", () => {
const source = directory();
const result = normalizeDirectorySnapshot(source, 2, 18446744073709551615n, "Self", "Lobby");
+1
View File
@@ -12,6 +12,7 @@ export function mapChannelTree(snapshot: TSDirectorySnapshot, avatarCache = new
? { maxClients: channel.maxClients, maxClientsLimited: channel.maxClientsLimited }
: {}),
...(typeof channel.passwordProtected === "boolean" ? { passwordProtected: channel.passwordProtected } : {}),
...(typeof channel.isPermanent === "boolean" ? { isPermanent: channel.isPermanent } : {}),
members: snapshot.clients
.filter((client) => client.channelID === channel.id)
.map((client) => {
+5 -3
View File
@@ -10,7 +10,7 @@ const identity = generateIdentitySync(8);
const uid = "AAAAAAAAAAAAAAAAAAAAAAAAAAA=";
function channel(id = 1): Channel {
return { id: asChannelID(BigInt(id)), parentID: asChannelID(0n), order: asChannelID(0n), name: "Lobby",
description: "", hasPassword: true, maxClients: 12, isMaxClientsUnlimited: false } as Channel;
description: "", hasPassword: true, isPermanent: true, maxClients: 12, isMaxClientsUnlimited: false } as Channel;
}
function member(id = 1): ClientEntry {
return { id: asClientID(id), nickname: `Member ${id}`, uid: asUID(uid), channelID: asChannelID(1n), type: 0,
@@ -43,7 +43,7 @@ function fixture() {
test("ordinary-client directories and avatar metadata use the live view without list permissions", async () => {
const { sdk, native } = fixture();
assert.deepEqual(await sdk.listDirectoryChannels(), [{ id: 1n, parentID: 0n, order: 0n, name: "Lobby", description: "",
passwordProtected: true, maxClients: 12, maxClientsLimited: true }]);
passwordProtected: true, isPermanent: true, maxClients: 12, maxClientsLimited: true }]);
assert.deepEqual(await sdk.listDirectoryClients(), [{ id: 1, nickname: "Member 1", uid, channelID: 1n, type: 0,
serverGroups: [], away: true, awayMessage: "Away", inputMuted: true, outputMuted: false, channelCommander: true }]);
assert.deepEqual(await sdk.getClientAvatarMetadata(1), { uid, cacheKey: "avatar-hash", path: `/${avatarFileName(uid)}` });
@@ -62,11 +62,13 @@ test("live-view snapshots include channel edits and remove clients that went out
assert.equal(snapshots.length, 1, "an unchanged revision does not duplicate the directory");
assert.equal(snapshots[0]?.complete, true);
native.view.clients.clear();
native.view.channels.set(asChannelID(1n), { ...channel(), name: "Renamed", hasPassword: false, maxClients: 20 });
native.view.channels.set(asChannelID(1n), { ...channel(), name: "Renamed", hasPassword: false, isPermanent: false, maxClients: 20 });
native.view.revision++;
native.emit("viewChanged");
assert.equal(snapshots.at(-1)?.channels[0]?.name, "Renamed");
assert.equal(snapshots.at(-1)?.channels[0]?.passwordProtected, false);
assert.equal(snapshots[0]?.channels[0]?.isPermanent, true);
assert.equal(snapshots.at(-1)?.channels[0]?.isPermanent, false);
assert.equal(snapshots.at(-1)?.channels[0]?.maxClients, 20);
assert.deepEqual(snapshots.at(-1)?.clients, []);
assert.equal(snapshots[0]?.clients.length, 1, "earlier snapshots stay independent");
+2
View File
@@ -48,6 +48,7 @@ export interface DirectoryChannelInfo {
name: string;
description: string;
passwordProtected?: boolean;
isPermanent?: boolean;
maxClients?: number;
maxClientsLimited?: boolean;
}
@@ -315,6 +316,7 @@ function toDirectoryChannel(channel: Channel): DirectoryChannelInfo {
name: channel.name,
description: channel.description,
passwordProtected: channel.hasPassword,
...(typeof channel.isPermanent === "boolean" ? { isPermanent: channel.isPermanent } : {}),
...(Number.isInteger(channel.maxClients) && channel.maxClients >= 0 && channel.maxClients <= 65_535
&& typeof channel.isMaxClientsUnlimited === "boolean"
? { maxClients: channel.maxClients, maxClientsLimited: !channel.isMaxClientsUnlimited }