feat(skin): render voice members under channels

This commit is contained in:
illusia committed 2026-10-10 15:53:49 +08:00
1 parent 54c77bcb27
commit dd0d779e49
13 files changed
+257 -32

No files matched your search

+30 -1
View File
@@ -139,10 +139,13 @@ test("KAAK v3 example splits validated channel and member data by component", as
const memberSidebar = parsed.components.find((component) => component.id === "kaak-members-sidebar");
assert.ok(channelSidebar);
assert.ok(memberSidebar);
assert.deepEqual(channelSidebar.permissions, ["session.channels.read", "session.channel.join"]);
assert.deepEqual(channelSidebar.permissions, ["session.channels.read", "session.members.read", "session.channel.join"]);
assert.equal(channelSidebar.actions["join-channel"].type, "voice.joinChannel");
assert.equal(channelSidebar.root.children?.[1].children?.[0].children?.[0].events?.dblclick, "join-channel");
assert.equal(channelSidebar.root.children?.[1].children?.[0].repeat?.path, "session.channels");
const nestedMembers = channelSidebar.root.children?.[1].children?.[0].children?.[1].children?.[0];
assert.equal(nestedMembers?.repeat?.path, "channel.members");
assert.equal(nestedMembers?.children?.[1].children?.[0].text, "{{member.name}}");
assert.deepEqual(memberSidebar.permissions, ["session.members.read"]);
assert.equal(memberSidebar.root.children?.[2].children?.[0].repeat?.path, "session.members");
});
@@ -188,6 +191,32 @@ test("skin plugin restricts repeated fields to the selected collection", () => {
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_BINDING_INVALID");
});
test("skin plugins can repeat channel members only under a channel alias and with member permission", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].permissions.push("session.members.read");
document.components[0].root.children = [{
tag: "ul",
children: [{
tag: "li",
repeat: { path: "channel.members", as: "member" },
children: [{ text: "{{channel.name}} — {{member.name}}" }],
}],
}];
const parsed = parseSkinPluginDocument(document);
const nestedMember = parsed.components[0].root.children?.[0].children?.[0];
assert.deepEqual(nestedMember?.repeat, { path: "channel.members", as: "member" });
const missingPermission = structuredClone(document);
missingPermission.components[0].permissions = ["session.channels.read", "session.channel.join"];
errorCode(() => parseSkinPluginDocument(missingPermission), "SKIN_PLUGIN_PERMISSION_MISSING");
const outsideChannel = structuredClone(document);
outsideChannel.components[0].root.repeat = undefined;
outsideChannel.components[0].root.children = [{ tag: "ul", repeat: { path: "channel.members", as: "member" } }];
errorCode(() => parseSkinPluginDocument(outsideChannel), "SKIN_PLUGIN_REPEAT_INVALID");
});
test("skin plugin never dispatches host actions from typing or selection changes", () => {
const document = validDocument();
document.components[0].root.children![0].events = { change: "join" };
+10 -4
View File
@@ -9,6 +9,7 @@ export const SKIN_PLUGIN_COMPONENT_LIMIT = 128;
export const SKIN_PLUGIN_NODE_LIMIT = 2048;
export const SKIN_PLUGIN_TREE_DEPTH_LIMIT = 32;
export const SKIN_PLUGIN_REPEAT_LIMIT = 250;
export const SKIN_PLUGIN_RENDER_NODE_LIMIT = 8192;
export const SKIN_PLUGIN_PERMISSIONS = Object.freeze({
"ui.surface.replace": Object.freeze({ policyVersion: 1, description: "Replace the built-in public page with a custom skin surface; the host recovery controls remain available." }),
@@ -411,9 +412,14 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument {
if (!isRecord(rawNode.repeat)) fail("SKIN_PLUGIN_REPEAT_INVALID", "A repeat declaration must be an object.");
onlyKeys(rawNode.repeat, new Set(["path", "as"]), "Repeat declaration");
const path = boundedText(rawNode.repeat.path, "repeat.path", 120);
if (!(path === "session.channels" || path === "session.members" || path === "favorites.items" || path === "servers.quickList" || path === "chat.messages" || path === "screenShare.streams")) fail("SKIN_PLUGIN_REPEAT_INVALID", "A component may repeat only a registered public collection.");
const permission = COLLECTION_PERMISSION[path];
if (!permissions.includes(permission)) fail("SKIN_PLUGIN_PERMISSION_MISSING", `Repeating ${path} requires ${permission}.`);
const nestedChannelMembers = path.split(".").length === 2
&& path.endsWith(".members")
&& aliases.get(path.slice(0, path.lastIndexOf("."))) === "session.channels";
if (!(path === "session.channels" || path === "session.members" || path === "favorites.items" || path === "servers.quickList" || path === "chat.messages" || path === "screenShare.streams" || nestedChannelMembers)) {
fail("SKIN_PLUGIN_REPEAT_INVALID", "A component may repeat only a registered public collection or the members of a repeated channel.");
}
const permission = nestedChannelMembers ? "session.members.read" : COLLECTION_PERMISSION[path];
if (!permission || !permissions.includes(permission)) fail("SKIN_PLUGIN_PERMISSION_MISSING", `Repeating ${path} requires ${permission ?? "a registered collection permission"}.`);
const alias = identifier(rawNode.repeat.as, "repeat.as");
if (aliases.has(alias)) fail("SKIN_PLUGIN_REPEAT_INVALID", "Repeat aliases cannot shadow an existing alias.");
node.repeat = { path, as: alias };
@@ -453,7 +459,7 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument {
if (!Array.isArray(rawNode.children) || rawNode.children.length > (inputSchemaVersion >= 3 ? 256 : 100)) fail("SKIN_PLUGIN_TREE_INVALID", "A component node contains too many children.");
if (node.tag && VOID_ELEMENTS.has(node.tag) && rawNode.children.length) fail("SKIN_PLUGIN_TREE_INVALID", "A void element cannot contain child nodes.");
const childAliases = new Map(aliases);
if (node.repeat) childAliases.set(node.repeat.as, node.repeat.path);
if (node.repeat) childAliases.set(node.repeat.as, node.repeat.path.endsWith(".members") ? "session.members" : node.repeat.path);
node.children = rawNode.children.map((child) => walk(child, depth + 1, childAliases));
}
return node;