mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +08:00
feat(channels): render TeamSpeak spacers across skins
This commit is contained in:
1 parent
4bff2133b6
commit
b9fccb8757
21 files changed
+240
-17
No files matched your search
@@ -189,6 +189,10 @@ components.json 顶层接受 schemaVersion 1、2 或 3 和 components 数组。s
|
||||
|
||||
申请 `session.channels.read` 的 `session.channels` 列表还提供 `memberCount`、两位数显示用的 `memberCountLabel`、`maxClients` 和 `maxClientsLimited`。后两个字段仅在 TeamSpeak 返回有效上限数据时出现;`maxClientsLimited: false` 表示频道不限人数。它们与频道树一起属于公开只读数据,不会授予服务器写入能力。
|
||||
|
||||
频道显示接口增补(0.2.8):同一权限下新增 `displayName`、`isSpacer`、`spacerAlignment` 与 `spacerStyle`,声明式 v3 和 Wasm v4 均可读取。`name` 始终保留服务器原名,`displayName` 仅对永久、顶层且名称以 `[spacer…]`、`[lspacer…]`、`[cspacer…]`、`[rspacer…]` 或 `[*spacer…]` 开头的频道移除前缀(大小写不敏感,省略或自定义标识均可)。分隔栏的 `spacerAlignment` 为 `left`、`center`、`right` 或 `repeat`;`spacerStyle` 为 `text`、`solid`、`dashed`、`dotted`、`dash-dot` 或 `dash-dot-dot`,五种线型对应 `___`、`---`、`...`、`-.-`、`-..`。普通频道的 `displayName` 等于 `name`、`isSpacer: false`、两个格式字段为空字符串。旧运行时可能不含新增字段;兼容包应回退到 `name`,不能只凭相同的 0.2.8 版本号推断字段存在。分隔栏仍为真实 TS 频道,不增加加入限制,不隐藏其中的成员或子频道;管理编辑继续使用原名。
|
||||
|
||||
宿主 `voice.channel-tree` 与 `voice.channel-panel` 自动使用上述显示规则;分隔栏隐藏普通频道图标和人数,不显示空成员提示。新增稳定部件 `voice.channel-spacer`,提供 `data-alignment` 与 `data-spacer-style` 属性;频道树行 `voice.channel-tree.row` 和成员面板标题 `voice.channel-group.heading` 在分隔栏上提供 `data-spacer="true"`。颜色和字体继承皮肤,文字及重复填充在可用宽度内裁剪,空文本保留分隔间距。皮肤无需新增权限或修改传输逻辑。
|
||||
|
||||
```json
|
||||
{
|
||||
"schemaVersion": 2,
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { ChannelInfo } from "./voice-models.js";
|
||||
|
||||
export interface ChannelSpacer {
|
||||
text: string;
|
||||
alignment: "left" | "center" | "right" | "repeat";
|
||||
style: "text" | "solid" | "dashed" | "dotted" | "dash-dot" | "dash-dot-dot";
|
||||
}
|
||||
|
||||
const LINE_STYLES: Readonly<Record<string, ChannelSpacer["style"]>> = {
|
||||
"___": "solid", "---": "dashed", "...": "dotted", "-.-": "dash-dot", "-..": "dash-dot-dot",
|
||||
};
|
||||
|
||||
/** Spacers are a presentation convention for permanent, root-level TS channels. */
|
||||
export function getChannelSpacer(channel: Pick<ChannelInfo, "name" | "parentID" | "isPermanent">): ChannelSpacer | null {
|
||||
if (channel.parentID !== "0" || channel.isPermanent !== true) return null;
|
||||
const match = /^\[([clr*]?)spacer[^\]\r\n]*\]([\s\S]*)$/i.exec(channel.name);
|
||||
if (!match) return null;
|
||||
const text = match[2];
|
||||
const alignment = ({ c: "center", r: "right", "*": "repeat" } as const)[match[1].toLowerCase() as "c" | "r" | "*"] ?? "left";
|
||||
return { text, alignment, style: Object.hasOwn(LINE_STYLES, text) ? LINE_STYLES[text] : "text" };
|
||||
}
|
||||
|
||||
export function channelDisplayName(channel: Pick<ChannelInfo, "name" | "parentID" | "isPermanent">): string {
|
||||
return getChannelSpacer(channel)?.text ?? channel.name;
|
||||
}
|
||||
@@ -73,6 +73,7 @@ function channel(value: unknown): value is ChannelInfo {
|
||||
&& optional(value.maxClients, maximum => finite(maximum) && Number.isInteger(maximum) && maximum >= 0 && maximum <= 65_535)
|
||||
&& optional(value.maxClientsLimited, boolean)
|
||||
&& optional(value.passwordProtected, boolean)
|
||||
&& optional(value.isPermanent, boolean)
|
||||
&& (value.maxClients === undefined) === (value.maxClientsLimited === undefined)
|
||||
&& optional(value.members, members => arrayOf(members, member));
|
||||
}
|
||||
|
||||
@@ -192,6 +192,7 @@ const PUBLIC_PART_IDS = new Set<string>([
|
||||
"voice.breadcrumbs",
|
||||
"voice.channel-group",
|
||||
"voice.channel-group.heading",
|
||||
"voice.channel-spacer",
|
||||
"voice.channel-group.members",
|
||||
"voice.channel-tree.avatar",
|
||||
"voice.channel-tree.branch",
|
||||
|
||||
@@ -276,7 +276,7 @@ const COLLECTION_PERMISSION: Record<string, SkinPluginPermission> = {
|
||||
"screenShare.streams": "voice.screenShare.read",
|
||||
};
|
||||
const COLLECTION_FIELDS: Record<string, ReadonlySet<string>> = {
|
||||
"session.channels": new Set(["id", "name", "parentId", "depth", "memberCount", "memberCountLabel", "maxClients", "maxClientsLimited", "current"]),
|
||||
"session.channels": new Set(["id", "name", "displayName", "isSpacer", "spacerAlignment", "spacerStyle", "parentId", "depth", "memberCount", "memberCountLabel", "maxClients", "maxClientsLimited", "current"]),
|
||||
"session.members": new Set(["id", "name", "avatarInitial", "channelId", "status", "speaking", "self", "screenSharing", "screenShareStreamId"]),
|
||||
"favorites.items": new Set(["id", "label", "current", "kind"]),
|
||||
"servers.quickList": new Set(["id", "label", "monogram", "icon", "tone", "current", "switchRestricted", "switchTitle", "kind", "favorite"]),
|
||||
|
||||
@@ -5,6 +5,15 @@ import {
|
||||
SKIN_RUNTIME_PLUGIN_CONTEXT_LIMIT_BYTES,
|
||||
} from "./skin-runtime-plugin-context.js";
|
||||
|
||||
test("channel spacer metadata is available to custom skins only with channel read permission", () => {
|
||||
const item = { id: "4", name: "[cspacer0]Section", displayName: "Section", isSpacer: true, spacerAlignment: "center", spacerStyle: "text", secret: "hidden" };
|
||||
const context = { session: { channels: [item] } };
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(projectSkinRuntimePluginContext([], context))), {});
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(projectSkinRuntimePluginContext(["session.channels.read"], context))), {
|
||||
session: { channels: [{ id: "4", name: item.name, displayName: "Section", isSpacer: true, spacerAlignment: "center", spacerStyle: "text" }] },
|
||||
});
|
||||
});
|
||||
|
||||
test("runtime context exposes only fields covered by declared read permissions", () => {
|
||||
const projected = projectSkinRuntimePluginContext(["session.channels.read"], {
|
||||
session: {
|
||||
|
||||
@@ -26,7 +26,7 @@ interface CollectionProjection {
|
||||
}
|
||||
|
||||
const COLLECTIONS: readonly CollectionProjection[] = Object.freeze([
|
||||
{ path: ["session", "channels"], permission: "session.channels.read", fields: new Set(["id", "name", "parentId", "depth", "memberCount", "memberCountLabel", "maxClients", "maxClientsLimited", "current"]), maxItems: 128 },
|
||||
{ path: ["session", "channels"], permission: "session.channels.read", fields: new Set(["id", "name", "displayName", "isSpacer", "spacerAlignment", "spacerStyle", "parentId", "depth", "memberCount", "memberCountLabel", "maxClients", "maxClientsLimited", "current"]), maxItems: 128 },
|
||||
{
|
||||
path: ["session", "members"],
|
||||
permission: "session.members.read",
|
||||
@@ -54,7 +54,7 @@ const CONTEXTS: readonly ContextProjection[] = Object.freeze([
|
||||
{ path: ["screenShare", "status"], permission: "voice.screenShare.status.read", fields: new Set(["active", "starting", "viewing"]) },
|
||||
]);
|
||||
|
||||
const BOOLEAN_FIELDS = new Set(["connected", "connecting", "current", "favorite", "speaking", "self", "screenSharing", "audio", "microphoneMuted", "outputMuted", "noiseSuppressionEnabled", "accompanimentActive", "active", "starting", "viewing", "maxClientsLimited", "panelOpen"]);
|
||||
const BOOLEAN_FIELDS = new Set(["connected", "connecting", "current", "favorite", "speaking", "self", "screenSharing", "audio", "microphoneMuted", "outputMuted", "noiseSuppressionEnabled", "accompanimentActive", "active", "starting", "viewing", "maxClientsLimited", "panelOpen", "isSpacer"]);
|
||||
const NUMBER_FIELDS = new Set(["depth", "memberCount", "targetCount", "ownerClientId", "viewerCount", "maxClients"]);
|
||||
const TEXT_LIMITS: Readonly<Record<string, number>> = Object.freeze({
|
||||
id: 128,
|
||||
@@ -63,6 +63,9 @@ const TEXT_LIMITS: Readonly<Record<string, number>> = Object.freeze({
|
||||
channelId: 128,
|
||||
parentId: 128,
|
||||
name: 160,
|
||||
displayName: 160,
|
||||
spacerAlignment: 8,
|
||||
spacerStyle: 12,
|
||||
label: 160,
|
||||
channelName: 160,
|
||||
userName: 160,
|
||||
|
||||
@@ -25,6 +25,8 @@ export interface ChannelInfo {
|
||||
maxClientsLimited?: boolean;
|
||||
/** TeamSpeak's public channel flag; absent when the connected server omits it. */
|
||||
passwordProtected?: boolean;
|
||||
/** Required to recognize TeamSpeak's permanent, root-level spacer channels. */
|
||||
isPermanent?: boolean;
|
||||
members?: ChannelMember[];
|
||||
}
|
||||
|
||||
|
||||
@@ -60,16 +60,19 @@
|
||||
<button
|
||||
class="member-channel-heading"
|
||||
data-ws-part="voice.channel-group.heading"
|
||||
:data-spacer="getChannelSpacer(channelItem) ? 'true' : undefined"
|
||||
:data-ws-state="channelItem.id === currentChannelId ? 'current' : 'idle'"
|
||||
:title="t('switchChannel')"
|
||||
@click="emit('selectChannel', channelItem)"
|
||||
>
|
||||
<Icon
|
||||
v-if="!getChannelSpacer(channelItem)"
|
||||
:name="channelItem.passwordProtected ? 'lock' : 'speaker'"
|
||||
:size="16"
|
||||
/>
|
||||
<span>{{ channelItem.name }}</span>
|
||||
<small>{{ channelItem.members.length }}</small>
|
||||
<ChannelSpacer v-if="getChannelSpacer(channelItem)" :spacer="getChannelSpacer(channelItem)!" />
|
||||
<span v-else>{{ channelItem.name }}</span>
|
||||
<small v-if="!getChannelSpacer(channelItem)">{{ channelItem.members.length }}</small>
|
||||
</button>
|
||||
<div
|
||||
v-if="channelItem.members.length"
|
||||
@@ -170,7 +173,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
v-else-if="!getChannelSpacer(channelItem)"
|
||||
class="channel-no-members"
|
||||
>{{ t("noMembersInChannel") }}</div
|
||||
>
|
||||
@@ -188,6 +191,8 @@
|
||||
<script setup lang="ts">
|
||||
import type { CSSProperties } from "vue";
|
||||
import Icon from "../Icon.vue";
|
||||
import ChannelSpacer from "./ChannelSpacer.vue";
|
||||
import { getChannelSpacer } from "../../../../src/shared/channel-spacer.js";
|
||||
import { memberPresenceKey } from "../../services/member-presence.js";
|
||||
import type { TreeChannel } from "../../composables/useWebClientChannels.js";
|
||||
import type { useWebClientMembers } from "../../composables/useWebClientMembers.js";
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<template>
|
||||
<span
|
||||
class="ws-channel-spacer"
|
||||
data-ws-part="voice.channel-spacer"
|
||||
:data-alignment="spacer.alignment"
|
||||
:data-spacer-style="spacer.style"
|
||||
:aria-label="spacer.text || undefined"
|
||||
><span :aria-hidden="spacer.alignment === 'repeat' || spacer.style !== 'text' ? 'true' : undefined">{{ displayText }}</span></span>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import type { ChannelSpacer } from "../../../../src/shared/channel-spacer.js";
|
||||
|
||||
const props = defineProps<{ spacer: ChannelSpacer }>();
|
||||
const displayText = computed(() => {
|
||||
if (props.spacer.style !== "text") return "";
|
||||
const text = props.spacer.text;
|
||||
// Clip a bounded run in CSS rather than measuring DOM or growing with viewport width.
|
||||
return props.spacer.alignment === "repeat" && text
|
||||
? text.repeat(Math.max(1, Math.floor(1024 / text.length)))
|
||||
: text;
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.ws-channel-spacer {
|
||||
display: block;
|
||||
flex: 1 1 0;
|
||||
min-width: 0;
|
||||
width: 100%;
|
||||
min-height: 1.3em;
|
||||
overflow: hidden;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
line-height: 1.3;
|
||||
text-align: left;
|
||||
}
|
||||
.ws-channel-spacer > span { white-space: pre; }
|
||||
.ws-channel-spacer[data-alignment="center"] { text-align: center; }
|
||||
.ws-channel-spacer[data-alignment="right"] { text-align: right; }
|
||||
.ws-channel-spacer:where(:not([data-spacer-style="text"]))::before {
|
||||
content: "";
|
||||
display: block;
|
||||
margin-block: .6em;
|
||||
border-top: 1px solid currentColor;
|
||||
opacity: .55;
|
||||
}
|
||||
.ws-channel-spacer[data-spacer-style="dashed"]::before { border-top-style: dashed; }
|
||||
.ws-channel-spacer[data-spacer-style="dotted"]::before { border-top-style: dotted; }
|
||||
.ws-channel-spacer[data-spacer-style="dash-dot"]::before,
|
||||
.ws-channel-spacer[data-spacer-style="dash-dot-dot"]::before {
|
||||
height: 1px;
|
||||
border: 0;
|
||||
background: repeating-linear-gradient(to right, currentColor 0 6px, transparent 6px 9px, currentColor 9px 11px, transparent 11px 14px);
|
||||
}
|
||||
.ws-channel-spacer[data-spacer-style="dash-dot-dot"]::before {
|
||||
background: repeating-linear-gradient(to right, currentColor 0 6px, transparent 6px 9px, currentColor 9px 11px, transparent 11px 14px, currentColor 14px 16px, transparent 16px 19px);
|
||||
}
|
||||
</style>
|
||||
@@ -16,7 +16,7 @@
|
||||
type="button"
|
||||
class="ws-voice-channel-expander"
|
||||
data-ws-part="voice.channel-tree.expander"
|
||||
:aria-label="`${expanded ? '收起' : '展开'} ${node.channel.name} / ${expanded ? 'Collapse' : 'Expand'} channel`"
|
||||
:aria-label="`${expanded ? '收起' : '展开'} ${displayName} / ${expanded ? 'Collapse' : 'Expand'} channel`"
|
||||
:aria-expanded="expanded"
|
||||
@click.stop="emit('toggle', node.channel.id)"
|
||||
><Icon :name="expanded ? 'chevron-down' : 'chevron-right'" :size="13" /></button>
|
||||
@@ -24,8 +24,9 @@
|
||||
type="button"
|
||||
class="ws-voice-channel-row"
|
||||
data-ws-part="voice.channel-tree.row"
|
||||
:data-spacer="spacer ? 'true' : undefined"
|
||||
:data-drag-over="memberDragDrop && dragOverChannelId === node.channel.id ? 'true' : undefined"
|
||||
:title="`双击或按 Enter 加入 ${node.channel.name} / Double-click or press Enter to join${node.channel.passwordProtected ? ' · 需要频道密码 / Channel password required' : ''}`"
|
||||
:title="`双击或按 Enter 加入 ${displayName} / Double-click or press Enter to join${node.channel.passwordProtected ? ' · 需要频道密码 / Channel password required' : ''}`"
|
||||
:data-password-protected="node.channel.passwordProtected ? 'true' : undefined"
|
||||
@click="emit('select', node.channel.id)"
|
||||
@dblclick.stop.prevent="join"
|
||||
@@ -35,15 +36,17 @@
|
||||
@drop="handleChannelDrop($event)"
|
||||
>
|
||||
<Icon
|
||||
v-if="!spacer"
|
||||
class="ws-voice-channel-type"
|
||||
data-ws-part="voice.channel-tree.icon"
|
||||
:name="node.channel.passwordProtected ? 'lock' : 'speaker'"
|
||||
:data-password-protected="node.channel.passwordProtected ? 'true' : 'false'"
|
||||
:size="14"
|
||||
/>
|
||||
<span class="ws-voice-channel-name" data-ws-part="voice.channel-tree.name">{{ node.channel.name }}</span>
|
||||
<span v-if="selected && !current" class="ws-voice-channel-join-hint" data-ws-part="voice.channel-tree.join-hint">双击加入</span>
|
||||
<span class="ws-voice-channel-count" data-ws-part="voice.channel-tree.count">
|
||||
<ChannelSpacer v-if="spacer" :spacer="spacer" />
|
||||
<span v-else class="ws-voice-channel-name" data-ws-part="voice.channel-tree.name">{{ node.channel.name }}</span>
|
||||
<span v-if="!spacer && selected && !current" class="ws-voice-channel-join-hint" data-ws-part="voice.channel-tree.join-hint">双击加入</span>
|
||||
<span v-if="!spacer" class="ws-voice-channel-count" data-ws-part="voice.channel-tree.count">
|
||||
{{ memberCount }}<template v-if="node.channel.maxClientsLimited && typeof node.channel.maxClients === 'number'">/{{ node.channel.maxClients }}</template>
|
||||
</span>
|
||||
</button>
|
||||
@@ -230,6 +233,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, type CSSProperties } from "vue";
|
||||
import Icon from "../Icon.vue";
|
||||
import ChannelSpacer from "./ChannelSpacer.vue";
|
||||
import { channelDisplayName, getChannelSpacer } from "../../../../src/shared/channel-spacer.js";
|
||||
import type { ChannelMember } from "../../composables/useVoiceWebSocket.js";
|
||||
import type { TreeChannel } from "../../composables/useWebClientChannels.js";
|
||||
import type { VoiceChannelTreeNode } from "../../services/voice-channel-tree.js";
|
||||
@@ -267,6 +272,8 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
|
||||
const expanded = computed(() => props.expandedIds.has(props.node.channel.id));
|
||||
const spacer = computed(() => getChannelSpacer(props.node.channel));
|
||||
const displayName = computed(() => channelDisplayName(props.node.channel));
|
||||
const hasChildren = computed(() => props.node.children.length > 0);
|
||||
const hasContents = computed(() => hasChildren.value || props.node.channel.members.length > 0);
|
||||
const isExpandable = computed(() => props.layout === "server-sidebar" ? hasChildren.value : hasContents.value);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { computed, watch, type Ref } from "vue";
|
||||
import type { ChannelInfo, ChannelMember } from "./useVoiceWebSocket.js";
|
||||
import { channelDisplayName } from "../../../src/shared/channel-spacer.js";
|
||||
|
||||
export interface TreeChannel extends ChannelInfo {
|
||||
depth: number;
|
||||
@@ -108,7 +109,7 @@ export function useWebClientChannels({
|
||||
if (fromSelf) return fromSelf;
|
||||
return channelTree.value.find((item) => item.name === channelName.value) ?? channelTree.value[0];
|
||||
});
|
||||
const currentChannelName = computed(() => (currentChannel.value?.name ?? channelName.value) || t("voiceLobby"));
|
||||
const currentChannelName = computed(() => (currentChannel.value ? channelDisplayName(currentChannel.value) : channelName.value) || t("voiceLobby"));
|
||||
const currentChannelDescription = computed(() => currentChannel.value?.description ?? "");
|
||||
const currentMembers = computed<ChannelMember[]>(() => {
|
||||
const source = currentChannel.value ? currentChannel.value.members : members;
|
||||
|
||||
@@ -27,6 +27,19 @@ function surfaceDocument(): SkinPluginDocument {
|
||||
};
|
||||
}
|
||||
|
||||
test("declarative skins can read channel spacer presentation without new permissions", () => {
|
||||
const document = {
|
||||
schemaVersion: 3,
|
||||
components: [{ id: "channel-labels", name: "Channel labels", page: "voice", accessibleName: "Channel labels", permissions: ["session.channels.read"], actions: {},
|
||||
root: { tag: "div", repeat: { path: "session.channels", as: "channel" }, children: [
|
||||
{ tag: "span", children: [{ text: "{{channel.displayName}} {{channel.spacerAlignment}} {{channel.spacerStyle}}" }], when: { path: "channel.isSpacer", equals: true } },
|
||||
] },
|
||||
}],
|
||||
};
|
||||
assert.doesNotThrow(() => parseSkinPluginDocument(document));
|
||||
assert.throws(() => parseSkinPluginDocument({ ...document, components: [{ ...document.components[0], permissions: [] }] }));
|
||||
});
|
||||
|
||||
test("page replacement stays disabled until local approval and returns to the host after revocation", () => {
|
||||
const storage = new Map<string, string>();
|
||||
const previousStorage = Object.getOwnPropertyDescriptor(globalThis, "localStorage");
|
||||
|
||||
@@ -5,6 +5,34 @@ import type { ChannelMember } from "../composables/useVoiceWebSocket.js";
|
||||
import { useWebClientMembers } from "../composables/useWebClientMembers.js";
|
||||
import { buildVoiceChannelTree, filterVoiceChannelTree } from "./voice-channel-tree.js";
|
||||
import { memberPresenceKey } from "./member-presence.js";
|
||||
import { channelDisplayName, getChannelSpacer } from "../../../src/shared/channel-spacer.js";
|
||||
|
||||
test("TeamSpeak spacers require a leading marker on a permanent root channel", () => {
|
||||
const channel = { name: "[cspacer0]🏔 后山 🏔", parentID: "0", isPermanent: true };
|
||||
assert.deepEqual(getChannelSpacer(channel), { text: "🏔 后山 🏔", alignment: "center", style: "text" });
|
||||
assert.equal(channelDisplayName(channel), "🏔 后山 🏔");
|
||||
for (const ordinary of [
|
||||
{ ...channel, isPermanent: false }, { ...channel, isPermanent: undefined }, { ...channel, parentID: "1" },
|
||||
{ ...channel, name: "prefix [cspacer0]Title" }, { ...channel, name: "[cspacer0Title" },
|
||||
{ ...channel, name: "[xspacer0]Title" }, { ...channel, name: "General" },
|
||||
]) {
|
||||
assert.equal(getChannelSpacer(ordinary), null);
|
||||
assert.equal(channelDisplayName(ordinary), ordinary.name);
|
||||
}
|
||||
});
|
||||
|
||||
test("spacer display supports blank labels, arbitrary IDs, case, alignment and standard line patterns", () => {
|
||||
const base = { parentID: "0", isPermanent: true };
|
||||
for (const [name, alignment, text] of [
|
||||
["[spacer]", "left", ""], ["[CSPACER0]", "center", ""],
|
||||
["[lspacerstaff]Staff", "left", "Staff"], ["[rspacer42]Right", "right", "Right"],
|
||||
["[*spacer0]★·", "repeat", "★·"], ["[cspacer1]A]B", "center", "A]B"],
|
||||
["[cspacer]__proto__", "center", "__proto__"],
|
||||
]) assert.deepEqual(getChannelSpacer({ ...base, name }), { text, alignment, style: "text" });
|
||||
for (const [text, style] of [["___", "solid"], ["---", "dashed"], ["...", "dotted"], ["-.-", "dash-dot"], ["-..", "dash-dot-dot"]]) {
|
||||
assert.deepEqual(getChannelSpacer({ ...base, name: `[*spacer0]${text}` }), { text, alignment: "repeat", style });
|
||||
}
|
||||
});
|
||||
|
||||
test("channel search keeps matching nested channels and only their ancestors", () => {
|
||||
const tree = buildVoiceChannelTree([
|
||||
|
||||
@@ -144,7 +144,7 @@ const skinPluginContext = computed(() => ({
|
||||
skin: { locale: language.value, messages: skinMessages.value },
|
||||
session: {
|
||||
status: { connected: true, connecting: false, channelId: selectedChannel.value.id, channelName: selectedChannel.value.name, userName: "illusia" },
|
||||
channels: channels.map((channel, depth) => ({ id: channel.id, name: channel.name, parentId: "", depth, memberCount: channel.members.length, current: channel.id === selectedChannel.value.id })),
|
||||
channels: channels.map((channel, depth) => ({ id: channel.id, name: channel.name, displayName: channel.name, isSpacer: false, spacerAlignment: "", spacerStyle: "", parentId: "", depth, memberCount: channel.members.length, current: channel.id === selectedChannel.value.id })),
|
||||
members: selectedChannel.value.members.map((member) => ({
|
||||
id: member.id,
|
||||
name: member.name,
|
||||
|
||||
@@ -972,6 +972,7 @@ import SkinLoadRecoveryNotice from "../components/SkinLoadRecoveryNotice.vue";
|
||||
import VoiceMemberCards from "../components/web-client/VoiceMemberCards.vue";
|
||||
import VoicePerformancePanel from "../components/web-client/VoicePerformancePanel.vue";
|
||||
import VoiceChannelTree from "../components/web-client/VoiceChannelTree.vue";
|
||||
import { channelDisplayName, getChannelSpacer } from "../../../src/shared/channel-spacer.js";
|
||||
import VoiceServerSwitcher from "../components/web-client/VoiceServerSwitcher.vue";
|
||||
import VoiceServerHeader from "../components/web-client/VoiceServerHeader.vue";
|
||||
import VoiceServerBanner from "../components/web-client/VoiceServerBanner.vue";
|
||||
@@ -1649,9 +1650,14 @@ const skinPluginContext = computed(() => ({
|
||||
},
|
||||
channels: channelTree.value.map((item) => {
|
||||
const members = skinPluginMembers.value.filter((member) => member.channelId === item.id);
|
||||
const spacer = getChannelSpacer(item);
|
||||
return {
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
displayName: channelDisplayName(item),
|
||||
isSpacer: Boolean(spacer),
|
||||
spacerAlignment: spacer?.alignment ?? "",
|
||||
spacerStyle: spacer?.style ?? "",
|
||||
parentId: item.parentID,
|
||||
depth: item.depth,
|
||||
memberCount: item.members.length,
|
||||
|
||||
@@ -6,15 +6,54 @@ import vue from "@vitejs/plugin-vue";
|
||||
import { createServer } from "vite";
|
||||
import { createRenderer, createSSRApp, nextTick, shallowRef, markRaw } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
let vite, useWebClientScreenShare, VoiceMemberCards, VoiceChannelTree;
|
||||
let vite, useWebClientScreenShare, VoiceMemberCards, VoiceChannelTree, ChannelMemberPanel;
|
||||
const renderer = createRenderer({ createComment: text => ({ text }), createText: text => ({ text }), createElement: () => ({}), insert() {}, remove() {}, setText() {}, setElementText() {}, patchProp() {}, parentNode: () => null, nextSibling: () => null });
|
||||
before(async () => {
|
||||
vite = await createServer({ configFile: false, plugins: [vue()], root: fileURLToPath(new URL("../", import.meta.url)), server: { middlewareMode: true, hmr: false, ws: false, watch: null }, optimizeDeps: { noDiscovery: true, include: [] }, appType: "custom" });
|
||||
({ useWebClientScreenShare } = await vite.ssrLoadModule("/src/composables/useWebClientScreenShare.ts"));
|
||||
({ default: VoiceMemberCards } = await vite.ssrLoadModule("/src/components/web-client/VoiceMemberCards.vue"));
|
||||
({ default: VoiceChannelTree } = await vite.ssrLoadModule("/src/components/web-client/VoiceChannelTree.vue"));
|
||||
({ default: ChannelMemberPanel } = await vite.ssrLoadModule("/src/components/web-client/ChannelMemberPanel.vue"));
|
||||
});
|
||||
after(async () => { await vite?.close(); });
|
||||
|
||||
test("both tree layouts render spacer labels without channel icons/counts, and preserve children and members", async () => {
|
||||
const channels = [
|
||||
{ id: "1", parentID: "0", depth: 0, name: "[cspacer0]🏔 后山 🏔", isPermanent: true, members: [{ id: 7, nickname: "Visible member" }] },
|
||||
{ id: "2", parentID: "1", depth: 1, name: "[cspacer1]Nested ordinary", isPermanent: true, members: [] },
|
||||
{ id: "3", parentID: "0", depth: 0, name: "[*spacer3]★", isPermanent: true, members: [] },
|
||||
{ id: "4", parentID: "0", depth: 0, name: "[cspacer4]", isPermanent: true, members: [] },
|
||||
{ id: "5", parentID: "0", depth: 0, name: "[cspacer5]<img src=x onerror=alert(1)>", isPermanent: true, members: [] },
|
||||
];
|
||||
for (const layout of ["default", "server-sidebar"]) {
|
||||
const html = await renderToString(createSSRApp(VoiceChannelTree, {
|
||||
channels, layout, avatarStyle: () => ({}), avatarInitial: name => name[0], isSpeaking: () => false, t: key => key,
|
||||
}));
|
||||
assert.equal((html.match(/data-ws-part="voice.channel-spacer"/g) ?? []).length, 4);
|
||||
assert.equal((html.match(/data-ws-part="voice.channel-tree.icon"/g) ?? []).length, 1);
|
||||
assert.equal((html.match(/data-ws-part="voice.channel-tree.count"/g) ?? []).length, 1);
|
||||
assert.match(html, /Visible member/);
|
||||
assert.match(html, /\[cspacer1\]Nested ordinary/);
|
||||
assert.doesNotMatch(html, /\[cspacer0\]|\[\*spacer3\]|\[cspacer4\]|<img/);
|
||||
assert.match(html, /<img/);
|
||||
}
|
||||
});
|
||||
|
||||
test("the standard member panel uses the same spacer display and hides only empty spacer hints", async () => {
|
||||
const html = await renderToString(createSSRApp(ChannelMemberPanel, {
|
||||
model: { memberDisplayName: member => member.nickname, isSpeaking: () => false }, query: "",
|
||||
filteredMemberChannels: [
|
||||
{ id: "1", parentID: "0", depth: 0, name: "[rspacer0]右侧标题", isPermanent: true, members: [] },
|
||||
{ id: "2", parentID: "0", depth: 0, name: "Ordinary", members: [] },
|
||||
],
|
||||
mobileVisible: true, isMobileViewport: false, volumes: {}, avatarStyle: () => ({}), avatarInitial: name => name[0], rangeStyle: () => ({}), t: key => key,
|
||||
}));
|
||||
assert.match(html, /data-alignment="right"/);
|
||||
assert.match(html, /右侧标题/);
|
||||
assert.doesNotMatch(html, /\[rspacer0\]/);
|
||||
assert.equal((html.match(/noMembersInChannel/g) ?? []).length, 1);
|
||||
});
|
||||
|
||||
function mount(t, initialStream = null, memberAvatar = () => "") {
|
||||
const listeners = new Set(), starts = [], storage = new Map(); let exits = 0, ui;
|
||||
class Element {}
|
||||
|
||||
Reference in new issue
Block a user