@alexsun-top/opencode-chat-room 0.8.6 → 0.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/cli.js +1029 -415
- package/package.json +2 -1
- package/packages/chat-room-channeld/src/adapter.ts +52 -0
- package/packages/chat-room-channeld/src/config.ts +10 -2
- package/packages/chat-room-channeld/src/host.ts +26 -8
- package/packages/chat-room-channeld/src/inbound.ts +14 -1
- package/packages/chat-room-channeld/src/protocol.ts +38 -1
- package/packages/chat-room-channeld/src/stats.ts +4 -0
- package/plugin.ts +7 -2
- package/server/addressing-routes.ts +5 -1
- package/server/app.ts +6 -0
- package/server/assets/chat/events.js +5 -1
- package/server/assets/chat/operator-api.js +131 -0
- package/server/assets/chat/operator-i18n.js +219 -0
- package/server/assets/chat/operator-manage.js +221 -0
- package/server/assets/chat/operator.js +87 -130
- package/server/assets/chat/room-list.js +102 -38
- package/server/assets/conversation.css +10 -11
- package/server/channels.ts +60 -7
- package/server/chat-server.ts +4 -0
- package/server/mcp-http.ts +88 -0
- package/server/operator-routes.ts +195 -3
- package/server/operator-state.ts +72 -8
- package/server/operator.css +29 -0
- package/server/system.html +75 -31
- package/skills/chatroom/SKILL.md +20 -3
- package/src/center/center-client.ts +14 -2
- package/src/mcp/server.ts +177 -102
- package/src/runtime/v2-plugin.ts +7 -2
- package/src/state/sqlite-schema.ts +3 -1
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
const en = {
|
|
2
|
+
pageTitle: "Server administration · OC Chat",
|
|
3
|
+
eyebrow: "Server administration",
|
|
4
|
+
heading: "Room ownership",
|
|
5
|
+
lock: "Lock",
|
|
6
|
+
gateTitle: "Open server administration",
|
|
7
|
+
gateLead: "Review room owners and recover ownership when the current owner cannot hand over the room. This page is separate from room owners, room administrators, and the management agent.",
|
|
8
|
+
keyLabel: "Server access key",
|
|
9
|
+
keyHint: "Kept in this tab only. Reloading asks again.",
|
|
10
|
+
continue: "Continue",
|
|
11
|
+
roomsTitle: "Rooms",
|
|
12
|
+
roomsLead: "Select a room to review its owner, members, and recent changes.",
|
|
13
|
+
refresh: "Refresh rooms",
|
|
14
|
+
searchPlaceholder: "Search rooms",
|
|
15
|
+
searchEmpty: "No rooms match.",
|
|
16
|
+
noRooms: "No rooms are available on this server.",
|
|
17
|
+
back: "Back to rooms",
|
|
18
|
+
roomEyebrow: "Room",
|
|
19
|
+
owner: "Owner",
|
|
20
|
+
admin: "Admin",
|
|
21
|
+
member: "Member",
|
|
22
|
+
agent: "Agent",
|
|
23
|
+
membersTitle: "Members",
|
|
24
|
+
noMembers: "No members.",
|
|
25
|
+
pendingTitle: "Pending join requests",
|
|
26
|
+
noPending: "No pending join requests.",
|
|
27
|
+
approve: "Approve",
|
|
28
|
+
deny: "Deny",
|
|
29
|
+
remove: "Remove",
|
|
30
|
+
makeAdmin: "Make admin",
|
|
31
|
+
revokeAdmin: "Revoke admin",
|
|
32
|
+
renameTitle: "Rename room",
|
|
33
|
+
renameLabel: "Room name",
|
|
34
|
+
rename: "Rename room",
|
|
35
|
+
deleteTitle: "Delete room",
|
|
36
|
+
deleteHint: "Deleting removes the room, its messages, and its files. This cannot be undone.",
|
|
37
|
+
deleteLabel: "Type the room name to confirm",
|
|
38
|
+
delete: "Delete room",
|
|
39
|
+
deleteMismatch: "Type the room name exactly to enable deletion.",
|
|
40
|
+
recoverTitle: "Recover ownership",
|
|
41
|
+
recoverLead: "Use this when the current owner cannot hand over the room. The new owner must already be in the room. The current owner loses control immediately; messages, files, and settings stay as they are.",
|
|
42
|
+
newOwner: "New owner",
|
|
43
|
+
noCandidates: "No other people are in this room, so nobody can take ownership.",
|
|
44
|
+
reasonLabel: "Reason for recovery",
|
|
45
|
+
reasonHint: "Stored in the server audit log. Room members only see that ownership changed.",
|
|
46
|
+
review: "Review recovery",
|
|
47
|
+
auditTitle: "Recent ownership changes",
|
|
48
|
+
noAudit: "No ownership changes recorded.",
|
|
49
|
+
actionsTitle: "Recent administrator actions",
|
|
50
|
+
noActions: "No administrator actions recorded.",
|
|
51
|
+
confirmTitle: "Confirm ownership recovery",
|
|
52
|
+
confirmRoom: "Room",
|
|
53
|
+
confirmFrom: "Current owner:",
|
|
54
|
+
confirmTo: "New owner:",
|
|
55
|
+
confirmReason: "Reason:",
|
|
56
|
+
confirmWarning: "The current owner loses control immediately. This cannot be undone from this page.",
|
|
57
|
+
cancel: "Cancel",
|
|
58
|
+
confirm: "Confirm recovery",
|
|
59
|
+
ownerLine: "Owner: {owner}",
|
|
60
|
+
noOwner: "No owner",
|
|
61
|
+
roomLine: "Room {id}",
|
|
62
|
+
roomOwnerLine: "Room {id} · Owner: {owner}",
|
|
63
|
+
roomNoOwnerLine: "Room {id} · No owner",
|
|
64
|
+
countMembers: "{n} members",
|
|
65
|
+
countAgents: "{n} agents",
|
|
66
|
+
lastActive: "Last active {time}",
|
|
67
|
+
unknownTime: "Unknown time",
|
|
68
|
+
refreshing: "Refreshing rooms…",
|
|
69
|
+
loading: "Loading room…",
|
|
70
|
+
refreshingRoom: "Refreshing room…",
|
|
71
|
+
checking: "Checking access…",
|
|
72
|
+
recovered: "Ownership recovered.",
|
|
73
|
+
noChange: "No change was needed; that person already owned the room.",
|
|
74
|
+
unconfirmed: "The server did not confirm the change. The latest owner is shown below; review it before trying again.",
|
|
75
|
+
conflict: "The room or its members changed while you were reviewing it. The latest details are shown below; review them and confirm again.",
|
|
76
|
+
conflictFail: "The room or its members changed while you were reviewing it. The latest details could not be loaded.",
|
|
77
|
+
recoveredFail: "Ownership was reported as recovered, but the latest details could not be loaded.",
|
|
78
|
+
noChangeFail: "No change was reported, but the latest details could not be loaded.",
|
|
79
|
+
unconfirmedFail: "The server did not confirm the change, and the latest details could not be loaded.",
|
|
80
|
+
invalidateSuffix: "Back to rooms and open this room again to review the latest owner.",
|
|
81
|
+
invalidateDetail: "The server returned an invalid or different room detail. Back to rooms and open this room again.",
|
|
82
|
+
goneRoom: "This room is no longer available. Back to rooms and refresh the list.",
|
|
83
|
+
detailUnexpected: "The server did not answer as expected. Back to rooms and try again.",
|
|
84
|
+
detailOffline: "The server did not answer. Check the address and try again, or go back to rooms.",
|
|
85
|
+
keyRejected: "The server key was rejected. Enter it again.",
|
|
86
|
+
disabled: "Operator access is not enabled on this server.",
|
|
87
|
+
listUnexpected: "The server did not answer as expected. Try again.",
|
|
88
|
+
listInvalid: "The server returned an unexpected room list.",
|
|
89
|
+
offline: "The server did not answer. Check the address and try again.",
|
|
90
|
+
keyMissing: "Enter the server access key.",
|
|
91
|
+
keyRefused: "That key was not accepted. Check it and try again.",
|
|
92
|
+
chooseOwner: "Choose who should own this room.",
|
|
93
|
+
reasonMissing: "Enter a reason for the recovery.",
|
|
94
|
+
reasonLong: "Keep the reason under 200 characters.",
|
|
95
|
+
requestFailed: "The server did not accept that change.",
|
|
96
|
+
actionDone: "Done.",
|
|
97
|
+
langLabel: "中文",
|
|
98
|
+
};
|
|
99
|
+
const zh = {
|
|
100
|
+
pageTitle: "服务器管理 · OC Chat",
|
|
101
|
+
eyebrow: "服务器管理",
|
|
102
|
+
heading: "房间所有权",
|
|
103
|
+
lock: "锁定",
|
|
104
|
+
gateTitle: "打开服务器管理",
|
|
105
|
+
gateLead: "查看房间所有者,并在现任所有者无法交接时恢复所有权。此页面与房间所有者、房间管理员和管理 Agent 相互独立。",
|
|
106
|
+
keyLabel: "服务器访问密钥",
|
|
107
|
+
keyHint: "仅保存在当前标签页,刷新后需要重新输入。",
|
|
108
|
+
continue: "继续",
|
|
109
|
+
roomsTitle: "房间",
|
|
110
|
+
roomsLead: "选择一个房间,查看所有者、成员和最近变更。",
|
|
111
|
+
refresh: "刷新房间",
|
|
112
|
+
searchPlaceholder: "搜索房间",
|
|
113
|
+
searchEmpty: "没有匹配的房间。",
|
|
114
|
+
noRooms: "此服务器上没有房间。",
|
|
115
|
+
back: "返回房间列表",
|
|
116
|
+
roomEyebrow: "房间",
|
|
117
|
+
owner: "所有者",
|
|
118
|
+
admin: "管理员",
|
|
119
|
+
member: "成员",
|
|
120
|
+
agent: "Agent",
|
|
121
|
+
membersTitle: "成员",
|
|
122
|
+
noMembers: "没有成员。",
|
|
123
|
+
pendingTitle: "待审批的加入请求",
|
|
124
|
+
noPending: "没有待审批的加入请求。",
|
|
125
|
+
approve: "通过",
|
|
126
|
+
deny: "拒绝",
|
|
127
|
+
remove: "移出",
|
|
128
|
+
makeAdmin: "设为管理员",
|
|
129
|
+
revokeAdmin: "取消管理员",
|
|
130
|
+
renameTitle: "重命名房间",
|
|
131
|
+
renameLabel: "房间名称",
|
|
132
|
+
rename: "重命名",
|
|
133
|
+
deleteTitle: "删除房间",
|
|
134
|
+
deleteHint: "删除会移除房间、消息和文件,且无法恢复。",
|
|
135
|
+
deleteLabel: "输入房间名称以确认",
|
|
136
|
+
delete: "删除房间",
|
|
137
|
+
deleteMismatch: "请完整输入房间名称后才能删除。",
|
|
138
|
+
recoverTitle: "恢复所有权",
|
|
139
|
+
recoverLead: "当现任所有者无法交接时使用。新所有者必须已经在房间内。现任所有者会立即失去控制权;消息、文件和设置保持不变。",
|
|
140
|
+
newOwner: "新所有者",
|
|
141
|
+
noCandidates: "房间内没有其他人可以接管所有权。",
|
|
142
|
+
reasonLabel: "恢复原因",
|
|
143
|
+
reasonHint: "记录在服务器审计日志中,房间成员只会看到所有权发生了变更。",
|
|
144
|
+
review: "确认恢复",
|
|
145
|
+
auditTitle: "最近的所有权变更",
|
|
146
|
+
noAudit: "没有所有权变更记录。",
|
|
147
|
+
actionsTitle: "最近的管理员操作",
|
|
148
|
+
noActions: "没有管理员操作记录。",
|
|
149
|
+
confirmTitle: "确认恢复所有权",
|
|
150
|
+
confirmRoom: "房间",
|
|
151
|
+
confirmFrom: "现任所有者:",
|
|
152
|
+
confirmTo: "新所有者:",
|
|
153
|
+
confirmReason: "原因:",
|
|
154
|
+
confirmWarning: "现任所有者会立即失去控制权,此页面无法撤销。",
|
|
155
|
+
cancel: "取消",
|
|
156
|
+
confirm: "确认恢复",
|
|
157
|
+
ownerLine: "所有者:{owner}",
|
|
158
|
+
noOwner: "无所有者",
|
|
159
|
+
roomLine: "房间 {id}",
|
|
160
|
+
roomOwnerLine: "房间 {id} · 所有者:{owner}",
|
|
161
|
+
roomNoOwnerLine: "房间 {id} · 无所有者",
|
|
162
|
+
countMembers: "{n} 名成员",
|
|
163
|
+
countAgents: "{n} 个 Agent",
|
|
164
|
+
lastActive: "最近活跃 {time}",
|
|
165
|
+
unknownTime: "时间未知",
|
|
166
|
+
refreshing: "正在刷新房间…",
|
|
167
|
+
loading: "正在加载房间…",
|
|
168
|
+
refreshingRoom: "正在刷新房间…",
|
|
169
|
+
checking: "正在验证访问权限…",
|
|
170
|
+
recovered: "所有权已恢复。",
|
|
171
|
+
noChange: "无需变更,该用户已经是房间所有者。",
|
|
172
|
+
unconfirmed: "服务器未确认变更。下方显示最新所有者,请核对后再试。",
|
|
173
|
+
conflict: "在你确认期间房间或成员发生了变化。下方是最新信息,请重新确认。",
|
|
174
|
+
conflictFail: "在你确认期间房间或成员发生了变化,且无法加载最新信息。",
|
|
175
|
+
recoveredFail: "服务器报告已恢复所有权,但无法加载最新信息。",
|
|
176
|
+
noChangeFail: "服务器报告无需变更,但无法加载最新信息。",
|
|
177
|
+
unconfirmedFail: "服务器未确认变更,且无法加载最新信息。",
|
|
178
|
+
invalidateSuffix: "请返回房间列表并重新打开该房间,查看最新所有者。",
|
|
179
|
+
invalidateDetail: "服务器返回了无效或不匹配的房间信息。请返回房间列表并重新打开。",
|
|
180
|
+
goneRoom: "该房间已不存在。请返回房间列表并刷新。",
|
|
181
|
+
detailUnexpected: "服务器未按预期响应。请返回房间列表后重试。",
|
|
182
|
+
detailOffline: "服务器无响应。请检查地址后重试,或返回房间列表。",
|
|
183
|
+
keyRejected: "服务器密钥被拒绝,请重新输入。",
|
|
184
|
+
disabled: "此服务器未启用管理入口。",
|
|
185
|
+
listUnexpected: "服务器未按预期响应,请重试。",
|
|
186
|
+
listInvalid: "服务器返回了无法识别的房间列表。",
|
|
187
|
+
offline: "服务器无响应,请检查地址后重试。",
|
|
188
|
+
keyMissing: "请输入服务器访问密钥。",
|
|
189
|
+
keyRefused: "密钥未被接受,请检查后重试。",
|
|
190
|
+
chooseOwner: "请选择新的房间所有者。",
|
|
191
|
+
reasonMissing: "请输入恢复原因。",
|
|
192
|
+
reasonLong: "原因不能超过 200 个字符。",
|
|
193
|
+
requestFailed: "服务器未接受该变更。",
|
|
194
|
+
actionDone: "已完成。",
|
|
195
|
+
langLabel: "EN",
|
|
196
|
+
};
|
|
197
|
+
const dict = { en, zh };
|
|
198
|
+
let lang = "en";
|
|
199
|
+
export const getLang = () => lang;
|
|
200
|
+
export function setLang(next) {
|
|
201
|
+
lang = next;
|
|
202
|
+
}
|
|
203
|
+
export function t(key, vars) {
|
|
204
|
+
const template = dict[lang][key];
|
|
205
|
+
if (!vars)
|
|
206
|
+
return template;
|
|
207
|
+
return template.replace(/\{(\w+)\}/g, (match, name) => (name in vars ? String(vars[name]) : match));
|
|
208
|
+
}
|
|
209
|
+
/** Fills every data-i18n element from the active language. */
|
|
210
|
+
export function applyStatic(root = document) {
|
|
211
|
+
for (const node of root.querySelectorAll("[data-i18n]")) {
|
|
212
|
+
node.textContent = t(node.dataset.i18n);
|
|
213
|
+
}
|
|
214
|
+
for (const node of root.querySelectorAll("[data-i18n-placeholder]")) {
|
|
215
|
+
node.placeholder = t(node.dataset.i18nPlaceholder);
|
|
216
|
+
}
|
|
217
|
+
document.title = t("pageTitle");
|
|
218
|
+
document.documentElement.lang = lang === "zh" ? "zh-CN" : "en";
|
|
219
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// Member, join-request, rename, delete, and action-log controls for the operator panel.
|
|
2
|
+
import { t } from "./operator-i18n.js";
|
|
3
|
+
const byId = (id) => {
|
|
4
|
+
const node = document.getElementById(id);
|
|
5
|
+
if (!node)
|
|
6
|
+
throw new Error(`Missing element: ${id}`);
|
|
7
|
+
return node;
|
|
8
|
+
};
|
|
9
|
+
const memberList = byId("memberList"), memberEmpty = byId("memberEmpty");
|
|
10
|
+
const joinList = byId("joinList"), joinEmpty = byId("joinEmpty");
|
|
11
|
+
const actionList = byId("actionList"), actionEmpty = byId("actionEmpty");
|
|
12
|
+
const renameForm = byId("renameForm"), renameInput = byId("renameInput"), btnRename = byId("btnRename");
|
|
13
|
+
const deleteForm = byId("deleteForm"), deleteInput = byId("deleteInput"), btnDelete = byId("btnDelete");
|
|
14
|
+
let host = null;
|
|
15
|
+
let current = null;
|
|
16
|
+
let joins = [];
|
|
17
|
+
let busy = false;
|
|
18
|
+
const el = (tag, className = "", text = "") => {
|
|
19
|
+
const node = document.createElement(tag);
|
|
20
|
+
if (className)
|
|
21
|
+
node.className = className;
|
|
22
|
+
if (text)
|
|
23
|
+
node.textContent = text;
|
|
24
|
+
return node;
|
|
25
|
+
};
|
|
26
|
+
function actionButton(label, action, className = "btn ghost small") {
|
|
27
|
+
const button = el("button", className, label);
|
|
28
|
+
button.type = "button";
|
|
29
|
+
button.addEventListener("click", () => {
|
|
30
|
+
if (!busy)
|
|
31
|
+
action();
|
|
32
|
+
});
|
|
33
|
+
return button;
|
|
34
|
+
}
|
|
35
|
+
async function mutate(path, init, failure, reloadAfter = true) {
|
|
36
|
+
if (!host || busy)
|
|
37
|
+
return false;
|
|
38
|
+
busy = true;
|
|
39
|
+
renameForm.setAttribute("aria-busy", "true");
|
|
40
|
+
deleteForm.setAttribute("aria-busy", "true");
|
|
41
|
+
host.setError("");
|
|
42
|
+
try {
|
|
43
|
+
const response = await host.request(path, init);
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
const body = await host.readJson(response);
|
|
46
|
+
const message = body && typeof body === "object" && typeof body.error === "string"
|
|
47
|
+
? body.error
|
|
48
|
+
: failure;
|
|
49
|
+
host.setError(message);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (reloadAfter)
|
|
53
|
+
await host.reload(t("actionDone"), failure);
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
host.setError(failure);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
busy = false;
|
|
62
|
+
renameForm.removeAttribute("aria-busy");
|
|
63
|
+
deleteForm.removeAttribute("aria-busy");
|
|
64
|
+
syncDelete();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function renderMembers(detail) {
|
|
68
|
+
memberList.replaceChildren();
|
|
69
|
+
const members = [...detail.room.members].sort((left, right) => {
|
|
70
|
+
const rank = (member) => (member.role === "owner" ? 0 : member.role === "admin" ? 1 : 2);
|
|
71
|
+
return rank(left) - rank(right) || left.name.localeCompare(right.name);
|
|
72
|
+
});
|
|
73
|
+
for (const member of members) {
|
|
74
|
+
const row = el("li", "member-row");
|
|
75
|
+
const name = el("span", "member-name", member.name);
|
|
76
|
+
const badges = el("span", "member-badges");
|
|
77
|
+
badges.append(el("span", `badge role-${member.role}`, t(member.role)));
|
|
78
|
+
if (member.isAgent)
|
|
79
|
+
badges.append(el("span", "badge agent", t("agent")));
|
|
80
|
+
const seen = el("span", "member-seen", t("lastActive", { time: host.formatTime(member.lastSeenAt) }));
|
|
81
|
+
const controls = el("span", "member-controls");
|
|
82
|
+
if (member.role !== "owner") {
|
|
83
|
+
const nextRole = member.role === "admin" ? "member" : "admin";
|
|
84
|
+
controls.append(actionButton(member.role === "admin" ? t("revokeAdmin") : t("makeAdmin"), () => {
|
|
85
|
+
void mutate(`/system/rooms/${encodeURIComponent(detail.room.id)}/members/role`, {
|
|
86
|
+
method: "POST",
|
|
87
|
+
body: JSON.stringify({ name: member.name, role: nextRole }),
|
|
88
|
+
}, t("requestFailed"));
|
|
89
|
+
}));
|
|
90
|
+
controls.append(actionButton(t("remove"), () => {
|
|
91
|
+
void mutate(`/system/rooms/${encodeURIComponent(detail.room.id)}/members/remove`, {
|
|
92
|
+
method: "POST",
|
|
93
|
+
body: JSON.stringify({ name: member.name }),
|
|
94
|
+
}, t("requestFailed"));
|
|
95
|
+
}, "btn danger small"));
|
|
96
|
+
}
|
|
97
|
+
const head = el("span", "member-head");
|
|
98
|
+
head.append(name, badges);
|
|
99
|
+
row.append(head, seen, controls);
|
|
100
|
+
memberList.append(row);
|
|
101
|
+
}
|
|
102
|
+
memberEmpty.hidden = members.length > 0;
|
|
103
|
+
}
|
|
104
|
+
async function loadJoins(roomId) {
|
|
105
|
+
if (!host)
|
|
106
|
+
return;
|
|
107
|
+
const response = await host.request(`/system/rooms/${encodeURIComponent(roomId)}/join-requests`).catch(() => null);
|
|
108
|
+
if (!response || !response.ok) {
|
|
109
|
+
joins = [];
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const body = await host.readJson(response);
|
|
113
|
+
const list = body && typeof body === "object" ? body.requests : null;
|
|
114
|
+
joins = Array.isArray(list) ? list.filter((item) => !!item && typeof item === "object" &&
|
|
115
|
+
typeof item.sessionID === "string" &&
|
|
116
|
+
typeof item.name === "string") : [];
|
|
117
|
+
}
|
|
118
|
+
function renderJoins(detail) {
|
|
119
|
+
joinList.replaceChildren();
|
|
120
|
+
for (const request of joins) {
|
|
121
|
+
const row = el("li", "join-row");
|
|
122
|
+
const head = el("span", "join-head");
|
|
123
|
+
head.append(el("span", "join-name", request.name), el("span", "badge", request.isAgent ? t("agent") : t("member")));
|
|
124
|
+
const when = el("span", "join-time", t("lastActive", { time: host.formatTime(request.createdAt) }));
|
|
125
|
+
const controls = el("span", "join-controls");
|
|
126
|
+
for (const [label, decision, className] of [[t("approve"), "approve", "btn primary small"], [t("deny"), "deny", "btn ghost small"]]) {
|
|
127
|
+
controls.append(actionButton(label, () => {
|
|
128
|
+
void mutate(`/system/rooms/${encodeURIComponent(detail.room.id)}/join-requests/${encodeURIComponent(request.sessionID)}/${decision}`, {
|
|
129
|
+
method: "POST",
|
|
130
|
+
body: JSON.stringify({}),
|
|
131
|
+
}, t("requestFailed"));
|
|
132
|
+
}, className));
|
|
133
|
+
}
|
|
134
|
+
row.append(head, when, controls);
|
|
135
|
+
joinList.append(row);
|
|
136
|
+
}
|
|
137
|
+
joinEmpty.hidden = joins.length > 0;
|
|
138
|
+
}
|
|
139
|
+
function renderActions(detail) {
|
|
140
|
+
actionList.replaceChildren();
|
|
141
|
+
const entries = [...detail.actions].sort((left, right) => right.createdAt - left.createdAt);
|
|
142
|
+
for (const entry of entries) {
|
|
143
|
+
const row = el("li", "audit-row");
|
|
144
|
+
const head = el("p", "audit-head");
|
|
145
|
+
const when = el("time");
|
|
146
|
+
if (Number.isFinite(entry.createdAt) && entry.createdAt > 0)
|
|
147
|
+
when.dateTime = new Date(entry.createdAt).toISOString();
|
|
148
|
+
when.textContent = host.formatTime(entry.createdAt);
|
|
149
|
+
head.append(when, el("span", "", `${entry.action}${entry.target ? ` · ${entry.target}` : ""}`));
|
|
150
|
+
const detailLine = el("p", "audit-reason", entry.detail || "");
|
|
151
|
+
row.append(head);
|
|
152
|
+
if (entry.detail)
|
|
153
|
+
row.append(detailLine);
|
|
154
|
+
actionList.append(row);
|
|
155
|
+
}
|
|
156
|
+
actionEmpty.hidden = entries.length > 0;
|
|
157
|
+
}
|
|
158
|
+
function syncDelete() {
|
|
159
|
+
const name = current?.room.name ?? "";
|
|
160
|
+
btnDelete.disabled = !name || deleteInput.value !== name || busy;
|
|
161
|
+
deleteInput.placeholder = name;
|
|
162
|
+
}
|
|
163
|
+
export function initManage(next) {
|
|
164
|
+
host = next;
|
|
165
|
+
renameForm.addEventListener("submit", (event) => {
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
const detail = current;
|
|
168
|
+
const name = renameInput.value.trim();
|
|
169
|
+
if (!detail || !name)
|
|
170
|
+
return;
|
|
171
|
+
void mutate(`/system/rooms/${encodeURIComponent(detail.room.id)}/rename`, {
|
|
172
|
+
method: "POST",
|
|
173
|
+
body: JSON.stringify({ name }),
|
|
174
|
+
}, t("requestFailed"));
|
|
175
|
+
});
|
|
176
|
+
deleteForm.addEventListener("submit", (event) => {
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
const detail = current;
|
|
179
|
+
if (!detail || busy || deleteInput.value !== detail.room.name) {
|
|
180
|
+
syncDelete();
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
void mutate(`/system/rooms/${encodeURIComponent(detail.room.id)}`, {
|
|
184
|
+
method: "DELETE",
|
|
185
|
+
body: JSON.stringify({ name: deleteInput.value }),
|
|
186
|
+
}, t("requestFailed"), false).then((done) => { if (done)
|
|
187
|
+
host.deleted(); });
|
|
188
|
+
});
|
|
189
|
+
deleteInput.addEventListener("input", syncDelete);
|
|
190
|
+
return {
|
|
191
|
+
render(detail) {
|
|
192
|
+
current = detail;
|
|
193
|
+
renameInput.value = detail.room.name;
|
|
194
|
+
deleteInput.value = "";
|
|
195
|
+
host.setError("");
|
|
196
|
+
renderMembers(detail);
|
|
197
|
+
renderActions(detail);
|
|
198
|
+
joins = [];
|
|
199
|
+
renderJoins(detail);
|
|
200
|
+
syncDelete();
|
|
201
|
+
void loadJoins(detail.room.id).then(() => {
|
|
202
|
+
if (current?.room.id === detail.room.id) {
|
|
203
|
+
renderJoins(detail);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
reset() {
|
|
208
|
+
current = null;
|
|
209
|
+
joins = [];
|
|
210
|
+
memberList.replaceChildren();
|
|
211
|
+
joinList.replaceChildren();
|
|
212
|
+
actionList.replaceChildren();
|
|
213
|
+
memberEmpty.hidden = false;
|
|
214
|
+
joinEmpty.hidden = false;
|
|
215
|
+
actionEmpty.hidden = false;
|
|
216
|
+
renameInput.value = "";
|
|
217
|
+
deleteInput.value = "";
|
|
218
|
+
btnDelete.disabled = true;
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
}
|