@alexsun-top/opencode-chat-room 0.8.7 → 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 +9 -0
- package/dist/cli.js +447 -56
- package/package.json +1 -1
- package/packages/chat-room-channeld/src/config.ts +4 -1
- package/packages/chat-room-channeld/src/host.ts +8 -1
- package/server/addressing-routes.ts +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 +7 -8
- package/server/channels.ts +39 -3
- 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 +3 -2
- package/src/mcp/server.ts +106 -49
- package/src/state/sqlite-schema.ts +3 -1
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// Server-operator console. The access token lives in this module only.
|
|
2
|
+
import { applyStatic, getLang, setLang, t } from "./operator-i18n.js";
|
|
3
|
+
import { initManage } from "./operator-manage.js";
|
|
4
|
+
import { createApi, parseDetail, parseRooms } from "./operator-api.js";
|
|
2
5
|
const byId = (id) => {
|
|
3
6
|
const node = document.getElementById(id);
|
|
4
7
|
if (!node)
|
|
@@ -12,9 +15,14 @@ const btnRefresh = byId("btnRefresh"), btnLock = byId("btnLock"), detailView = b
|
|
|
12
15
|
const detailMeta = byId("detailMeta"), detailStatus = byId("detailStatus"), detailError = byId("detailError"), btnBack = byId("btnBack");
|
|
13
16
|
const recoverForm = byId("recoverForm"), candidateList = byId("candidateList"), candidateEmpty = byId("candidateEmpty"), reasonInput = byId("reasonInput");
|
|
14
17
|
const reasonCount = byId("reasonCount"), recoverError = byId("recoverError"), btnReview = byId("btnReview"), auditList = byId("auditList");
|
|
18
|
+
const roomSearch = byId("roomSearch"), btnLang = byId("btnLang");
|
|
15
19
|
const auditEmpty = byId("auditEmpty"), confirmDialog = byId("confirmDialog"), confirmRoom = byId("confirmRoom"), confirmFrom = byId("confirmFrom");
|
|
16
20
|
const confirmTo = byId("confirmTo"), confirmReason = byId("confirmReason"), btnCancelConfirm = byId("btnCancelConfirm"), btnConfirm = byId("btnConfirm");
|
|
17
21
|
let token = "";
|
|
22
|
+
const api = createApi(() => token);
|
|
23
|
+
const request = api.request;
|
|
24
|
+
const readJson = api.readJson;
|
|
25
|
+
let searchTerm = "";
|
|
18
26
|
let rooms = [];
|
|
19
27
|
let detail = null;
|
|
20
28
|
let selectedRoomId = "";
|
|
@@ -34,97 +42,9 @@ const show = (node, visible) => { node.hidden = !visible; };
|
|
|
34
42
|
const setText = (node, value) => { node.textContent = value; };
|
|
35
43
|
const setError = (node, message) => { setText(node, message); node.hidden = !message; };
|
|
36
44
|
const setStatus = (node, message) => { setText(node, message); node.hidden = !message; };
|
|
37
|
-
async function request(path, init = {}) {
|
|
38
|
-
const headers = new Headers(init.headers);
|
|
39
|
-
if (token)
|
|
40
|
-
headers.set("Authorization", `Bearer ${token}`);
|
|
41
|
-
if (init.body)
|
|
42
|
-
headers.set("Content-Type", "application/json");
|
|
43
|
-
return fetch(path, {
|
|
44
|
-
...init,
|
|
45
|
-
headers,
|
|
46
|
-
cache: "no-store",
|
|
47
|
-
credentials: "omit",
|
|
48
|
-
redirect: "error",
|
|
49
|
-
referrerPolicy: "no-referrer",
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
async function readJson(response) {
|
|
53
|
-
try {
|
|
54
|
-
return await response.json();
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function parseRooms(value) {
|
|
61
|
-
if (!value || typeof value !== "object")
|
|
62
|
-
return null;
|
|
63
|
-
const list = value.rooms;
|
|
64
|
-
if (!Array.isArray(list))
|
|
65
|
-
return null;
|
|
66
|
-
const result = [];
|
|
67
|
-
for (const item of list) {
|
|
68
|
-
if (!item || typeof item !== "object")
|
|
69
|
-
continue;
|
|
70
|
-
const room = item;
|
|
71
|
-
if (typeof room.id !== "string" || typeof room.name !== "string")
|
|
72
|
-
continue;
|
|
73
|
-
result.push({
|
|
74
|
-
id: room.id,
|
|
75
|
-
name: room.name,
|
|
76
|
-
ownerId: typeof room.ownerId === "string" ? room.ownerId : "",
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
function parseDetail(value, roomId) {
|
|
82
|
-
if (!value || typeof value !== "object")
|
|
83
|
-
return null;
|
|
84
|
-
const root = value;
|
|
85
|
-
const raw = root.room;
|
|
86
|
-
if (!raw || typeof raw !== "object")
|
|
87
|
-
return null;
|
|
88
|
-
const room = raw;
|
|
89
|
-
if (typeof room.id !== "string" || typeof room.name !== "string" || room.id !== roomId)
|
|
90
|
-
return null;
|
|
91
|
-
const candidates = [];
|
|
92
|
-
if (Array.isArray(root.candidates))
|
|
93
|
-
for (const item of root.candidates) {
|
|
94
|
-
if (!item || typeof item !== "object")
|
|
95
|
-
continue;
|
|
96
|
-
const candidate = item;
|
|
97
|
-
if (typeof candidate.name === "string" && typeof candidate.membershipID === "string" && candidate.membershipID) {
|
|
98
|
-
candidates.push({ name: candidate.name, membershipID: candidate.membershipID });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const audit = [];
|
|
102
|
-
if (Array.isArray(root.audit))
|
|
103
|
-
for (const item of root.audit) {
|
|
104
|
-
if (!item || typeof item !== "object")
|
|
105
|
-
continue;
|
|
106
|
-
const entry = item;
|
|
107
|
-
audit.push({
|
|
108
|
-
createdAt: typeof entry.createdAt === "number" ? entry.createdAt : 0,
|
|
109
|
-
previousOwner: typeof entry.previousOwner === "string" ? entry.previousOwner : "",
|
|
110
|
-
targetName: typeof entry.targetName === "string" ? entry.targetName : "",
|
|
111
|
-
reason: typeof entry.reason === "string" ? entry.reason : "",
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
room: {
|
|
116
|
-
id: room.id,
|
|
117
|
-
name: room.name,
|
|
118
|
-
ownerId: typeof room.ownerId === "string" ? room.ownerId : "",
|
|
119
|
-
ownerMembershipID: typeof room.ownerMembershipID === "string" ? room.ownerMembershipID : null,
|
|
120
|
-
},
|
|
121
|
-
candidates,
|
|
122
|
-
audit,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
45
|
const timeFormat = new Intl.DateTimeFormat(undefined, { dateStyle: "medium", timeStyle: "short" });
|
|
126
46
|
function formatTime(value) {
|
|
127
|
-
return Number.isFinite(value) && value > 0 ? timeFormat.format(new Date(value)) : "
|
|
47
|
+
return Number.isFinite(value) && value > 0 ? timeFormat.format(new Date(value)) : t("unknownTime");
|
|
128
48
|
}
|
|
129
49
|
const el = (tag, className = "", text = "") => {
|
|
130
50
|
const node = document.createElement(tag);
|
|
@@ -134,7 +54,17 @@ const el = (tag, className = "", text = "") => {
|
|
|
134
54
|
node.textContent = text;
|
|
135
55
|
return node;
|
|
136
56
|
};
|
|
57
|
+
const manage = initManage({
|
|
58
|
+
request,
|
|
59
|
+
readJson,
|
|
60
|
+
detail: () => detail,
|
|
61
|
+
reload: reloadDetail,
|
|
62
|
+
deleted: () => { back(); void refreshRooms(); },
|
|
63
|
+
setError: (message) => setError(detailError, message),
|
|
64
|
+
formatTime,
|
|
65
|
+
});
|
|
137
66
|
function clearDetail() {
|
|
67
|
+
manage.reset();
|
|
138
68
|
setText(detailHeading, "");
|
|
139
69
|
setText(detailMeta, "");
|
|
140
70
|
candidateList.replaceChildren();
|
|
@@ -160,8 +90,8 @@ function invalidateDetail(failure) {
|
|
|
160
90
|
detail = null;
|
|
161
91
|
clearDetail();
|
|
162
92
|
setText(detailHeading, roomName);
|
|
163
|
-
setText(detailMeta, roomId ?
|
|
164
|
-
failDetail(`${failure}
|
|
93
|
+
setText(detailMeta, roomId ? t("roomLine", { id: roomId }) : "");
|
|
94
|
+
failDetail(`${failure} ${t("invalidateSuffix")}`);
|
|
165
95
|
}
|
|
166
96
|
function closeConfirm(focusReview) {
|
|
167
97
|
focusReviewOnClose = focusReview;
|
|
@@ -208,17 +138,30 @@ function lock(message = "", focus = true) {
|
|
|
208
138
|
}
|
|
209
139
|
function renderRooms() {
|
|
210
140
|
roomList.replaceChildren();
|
|
211
|
-
|
|
141
|
+
const term = searchTerm.trim().toLowerCase();
|
|
142
|
+
const visible = term ? rooms.filter((room) => room.name.toLowerCase().includes(term) || room.ownerId.toLowerCase().includes(term)) : rooms;
|
|
143
|
+
for (const room of visible) {
|
|
212
144
|
const button = el("button", "room-row");
|
|
213
145
|
button.type = "button";
|
|
214
146
|
button.dataset.roomId = room.id;
|
|
215
|
-
|
|
147
|
+
const main = el("span", "room-main");
|
|
148
|
+
const owner = el("span", "room-owner", room.ownerId ? t("ownerLine", { owner: room.ownerId }) : t("noOwner"));
|
|
149
|
+
const meta = el("span", "room-meta");
|
|
150
|
+
const counts = [t("countMembers", { n: room.memberCount })];
|
|
151
|
+
if (room.agentCount > 0)
|
|
152
|
+
counts.push(t("countAgents", { n: room.agentCount }));
|
|
153
|
+
if (room.lastActiveAt > 0)
|
|
154
|
+
counts.push(t("lastActive", { time: formatTime(room.lastActiveAt) }));
|
|
155
|
+
meta.textContent = counts.join(" · ");
|
|
156
|
+
main.append(el("span", "room-name", room.name), owner);
|
|
157
|
+
button.append(main, meta);
|
|
216
158
|
button.addEventListener("click", () => void openRoom(room.id));
|
|
217
159
|
const item = el("li");
|
|
218
160
|
item.append(button);
|
|
219
161
|
roomList.append(item);
|
|
220
162
|
}
|
|
221
|
-
|
|
163
|
+
roomsEmpty.textContent = rooms.length === 0 ? t("noRooms") : t("searchEmpty");
|
|
164
|
+
show(roomsEmpty, visible.length === 0);
|
|
222
165
|
}
|
|
223
166
|
function renderAudit() {
|
|
224
167
|
auditList.replaceChildren();
|
|
@@ -243,8 +186,8 @@ function renderDetail() {
|
|
|
243
186
|
return;
|
|
244
187
|
detailHeading.textContent = detail.room.name;
|
|
245
188
|
detailMeta.textContent = detail.room.ownerId
|
|
246
|
-
?
|
|
247
|
-
:
|
|
189
|
+
? t("roomOwnerLine", { id: detail.room.id, owner: detail.room.ownerId })
|
|
190
|
+
: t("roomNoOwnerLine", { id: detail.room.id });
|
|
248
191
|
// The current owner is not a recovery target; membership ID guards name reuse.
|
|
249
192
|
const ownerMembershipID = detail.room.ownerMembershipID;
|
|
250
193
|
const candidates = ownerMembershipID
|
|
@@ -267,6 +210,7 @@ function renderDetail() {
|
|
|
267
210
|
btnReview.disabled = candidates.length === 0;
|
|
268
211
|
recoverForm.hidden = false;
|
|
269
212
|
renderAudit();
|
|
213
|
+
manage.render(detail);
|
|
270
214
|
}
|
|
271
215
|
const roomRow = (id) => [...roomList.querySelectorAll(".room-row")].find((button) => button.dataset.roomId === id);
|
|
272
216
|
async function refreshRooms() {
|
|
@@ -280,7 +224,7 @@ async function refreshRooms() {
|
|
|
280
224
|
roomList.setAttribute("aria-busy", "true");
|
|
281
225
|
statusSlot.dataset.busy = "true";
|
|
282
226
|
setError(roomsError, "");
|
|
283
|
-
setStatus(roomsStatus, "
|
|
227
|
+
setStatus(roomsStatus, t("refreshing"));
|
|
284
228
|
const settle = async () => {
|
|
285
229
|
const remaining = REFRESH_MIN_MS - (performance.now() - started);
|
|
286
230
|
if (remaining > 0)
|
|
@@ -290,12 +234,12 @@ async function refreshRooms() {
|
|
|
290
234
|
const response = await request("/system/rooms");
|
|
291
235
|
if (response.status === 401) {
|
|
292
236
|
if (authGen === authGeneration)
|
|
293
|
-
lock("
|
|
237
|
+
lock(t("keyRejected"));
|
|
294
238
|
return;
|
|
295
239
|
}
|
|
296
240
|
if (response.status === 404) {
|
|
297
241
|
if (authGen === authGeneration)
|
|
298
|
-
lock("
|
|
242
|
+
lock(t("disabled"));
|
|
299
243
|
return;
|
|
300
244
|
}
|
|
301
245
|
const data = response.ok ? await readJson(response) : null;
|
|
@@ -304,13 +248,13 @@ async function refreshRooms() {
|
|
|
304
248
|
return;
|
|
305
249
|
if (!response.ok) {
|
|
306
250
|
setStatus(roomsStatus, "");
|
|
307
|
-
setError(roomsError, "
|
|
251
|
+
setError(roomsError, t("listUnexpected"));
|
|
308
252
|
return;
|
|
309
253
|
}
|
|
310
254
|
const next = parseRooms(data);
|
|
311
255
|
if (!next) {
|
|
312
256
|
setStatus(roomsStatus, "");
|
|
313
|
-
setError(roomsError, "
|
|
257
|
+
setError(roomsError, t("listInvalid"));
|
|
314
258
|
return;
|
|
315
259
|
}
|
|
316
260
|
const focused = document.activeElement instanceof HTMLElement ? document.activeElement.closest(".room-row")?.dataset.roomId : undefined;
|
|
@@ -324,7 +268,7 @@ async function refreshRooms() {
|
|
|
324
268
|
await settle();
|
|
325
269
|
if (gen === generation && authGen === authGeneration) {
|
|
326
270
|
setStatus(roomsStatus, "");
|
|
327
|
-
setError(roomsError, "
|
|
271
|
+
setError(roomsError, t("offline"));
|
|
328
272
|
}
|
|
329
273
|
}
|
|
330
274
|
finally {
|
|
@@ -341,7 +285,7 @@ async function unlock() {
|
|
|
341
285
|
return;
|
|
342
286
|
const candidateToken = tokenInput.value;
|
|
343
287
|
if (!candidateToken.trim()) {
|
|
344
|
-
setError(gateError, "
|
|
288
|
+
setError(gateError, t("keyMissing"));
|
|
345
289
|
tokenInput.focus();
|
|
346
290
|
return;
|
|
347
291
|
}
|
|
@@ -352,25 +296,25 @@ async function unlock() {
|
|
|
352
296
|
const busyId = beginBusy();
|
|
353
297
|
btnUnlock.disabled = true;
|
|
354
298
|
setError(gateError, "");
|
|
355
|
-
setStatus(gateStatus, "
|
|
299
|
+
setStatus(gateStatus, t("checking"));
|
|
356
300
|
try {
|
|
357
301
|
const response = await request("/system/rooms");
|
|
358
302
|
if (gen !== generation)
|
|
359
303
|
return;
|
|
360
304
|
if (response.status === 404) {
|
|
361
305
|
token = "";
|
|
362
|
-
setError(gateError, "
|
|
306
|
+
setError(gateError, t("disabled"));
|
|
363
307
|
return;
|
|
364
308
|
}
|
|
365
309
|
if (response.status === 401) {
|
|
366
310
|
token = "";
|
|
367
|
-
setError(gateError, "
|
|
311
|
+
setError(gateError, t("keyRefused"));
|
|
368
312
|
tokenInput.focus();
|
|
369
313
|
return;
|
|
370
314
|
}
|
|
371
315
|
if (!response.ok) {
|
|
372
316
|
token = "";
|
|
373
|
-
setError(gateError, "
|
|
317
|
+
setError(gateError, t("listUnexpected"));
|
|
374
318
|
return;
|
|
375
319
|
}
|
|
376
320
|
const data = await readJson(response);
|
|
@@ -379,7 +323,7 @@ async function unlock() {
|
|
|
379
323
|
const next = parseRooms(data);
|
|
380
324
|
if (!next) {
|
|
381
325
|
token = "";
|
|
382
|
-
setError(gateError, "
|
|
326
|
+
setError(gateError, t("listInvalid"));
|
|
383
327
|
return;
|
|
384
328
|
}
|
|
385
329
|
rooms = next;
|
|
@@ -393,7 +337,7 @@ async function unlock() {
|
|
|
393
337
|
catch {
|
|
394
338
|
if (gen === generation) {
|
|
395
339
|
token = "";
|
|
396
|
-
setError(gateError, "
|
|
340
|
+
setError(gateError, t("offline"));
|
|
397
341
|
}
|
|
398
342
|
}
|
|
399
343
|
finally {
|
|
@@ -418,25 +362,25 @@ async function openRoom(roomId) {
|
|
|
418
362
|
const gen = ++generation;
|
|
419
363
|
clearDetail();
|
|
420
364
|
setText(detailHeading, room.name);
|
|
421
|
-
setText(detailMeta,
|
|
365
|
+
setText(detailMeta, t("roomLine", { id: room.id }));
|
|
422
366
|
show(roomsView, false);
|
|
423
367
|
show(detailView, true);
|
|
424
|
-
setStatus(detailStatus, "
|
|
368
|
+
setStatus(detailStatus, t("loading"));
|
|
425
369
|
try {
|
|
426
370
|
const response = await request(`/system/rooms/${encodeURIComponent(roomId)}`);
|
|
427
371
|
if (response.status === 401) {
|
|
428
372
|
if (authGen === authGeneration)
|
|
429
|
-
lock("
|
|
373
|
+
lock(t("keyRejected"));
|
|
430
374
|
return;
|
|
431
375
|
}
|
|
432
376
|
if (gen !== generation || selectedRoomId !== roomId)
|
|
433
377
|
return;
|
|
434
378
|
if (response.status === 404) {
|
|
435
|
-
failDetail("
|
|
379
|
+
failDetail(t("goneRoom"));
|
|
436
380
|
return;
|
|
437
381
|
}
|
|
438
382
|
if (!response.ok) {
|
|
439
|
-
failDetail("
|
|
383
|
+
failDetail(t("detailUnexpected"));
|
|
440
384
|
return;
|
|
441
385
|
}
|
|
442
386
|
const data = await readJson(response);
|
|
@@ -444,7 +388,7 @@ async function openRoom(roomId) {
|
|
|
444
388
|
return;
|
|
445
389
|
const next = parseDetail(data, roomId);
|
|
446
390
|
if (!next) {
|
|
447
|
-
failDetail("
|
|
391
|
+
failDetail(t("invalidateDetail"));
|
|
448
392
|
return;
|
|
449
393
|
}
|
|
450
394
|
detail = next;
|
|
@@ -454,7 +398,7 @@ async function openRoom(roomId) {
|
|
|
454
398
|
}
|
|
455
399
|
catch {
|
|
456
400
|
if (gen === generation && selectedRoomId === roomId)
|
|
457
|
-
failDetail("
|
|
401
|
+
failDetail(t("detailOffline"));
|
|
458
402
|
}
|
|
459
403
|
}
|
|
460
404
|
async function reloadDetail(notice, failure) {
|
|
@@ -464,12 +408,12 @@ async function reloadDetail(notice, failure) {
|
|
|
464
408
|
const authGen = authGeneration;
|
|
465
409
|
const gen = ++generation;
|
|
466
410
|
setError(detailError, "");
|
|
467
|
-
setStatus(detailStatus, "
|
|
411
|
+
setStatus(detailStatus, t("refreshingRoom"));
|
|
468
412
|
try {
|
|
469
413
|
const response = await request(`/system/rooms/${encodeURIComponent(roomId)}`);
|
|
470
414
|
if (response.status === 401) {
|
|
471
415
|
if (authGen === authGeneration)
|
|
472
|
-
lock("
|
|
416
|
+
lock(t("keyRejected"));
|
|
473
417
|
return;
|
|
474
418
|
}
|
|
475
419
|
if (gen !== generation || selectedRoomId !== roomId)
|
|
@@ -498,30 +442,30 @@ function review(event) {
|
|
|
498
442
|
return;
|
|
499
443
|
const checked = candidateList.querySelector('input[name="candidate"]:checked');
|
|
500
444
|
if (!checked) {
|
|
501
|
-
setError(recoverError, "
|
|
445
|
+
setError(recoverError, t("chooseOwner"));
|
|
502
446
|
candidateList.querySelector("input")?.focus();
|
|
503
447
|
return;
|
|
504
448
|
}
|
|
505
449
|
const reason = reasonInput.value.trim();
|
|
506
450
|
if (!reason) {
|
|
507
|
-
setError(recoverError, "
|
|
451
|
+
setError(recoverError, t("reasonMissing"));
|
|
508
452
|
reasonInput.focus();
|
|
509
453
|
return;
|
|
510
454
|
}
|
|
511
455
|
if (reason.length > 200) {
|
|
512
|
-
setError(recoverError, "
|
|
456
|
+
setError(recoverError, t("reasonLong"));
|
|
513
457
|
reasonInput.focus();
|
|
514
458
|
return;
|
|
515
459
|
}
|
|
516
460
|
const candidate = detail.candidates.find((item) => item.membershipID === checked.value);
|
|
517
461
|
if (!candidate) {
|
|
518
|
-
setError(recoverError, "
|
|
462
|
+
setError(recoverError, t("chooseOwner"));
|
|
519
463
|
return;
|
|
520
464
|
}
|
|
521
465
|
setError(recoverError, "");
|
|
522
466
|
pending = { roomId: detail.room.id, membershipID: candidate.membershipID, expectedOwnerId: detail.room.ownerId, expectedOwnerMembershipID: detail.room.ownerMembershipID, reason };
|
|
523
467
|
setText(confirmRoom, detail.room.name);
|
|
524
|
-
setText(confirmFrom, detail.room.ownerId || "
|
|
468
|
+
setText(confirmFrom, detail.room.ownerId || t("noOwner"));
|
|
525
469
|
setText(confirmTo, candidate.name);
|
|
526
470
|
setText(confirmReason, reason);
|
|
527
471
|
btnConfirm.disabled = false;
|
|
@@ -547,7 +491,7 @@ async function confirmRecovery() {
|
|
|
547
491
|
if (response.status === 401) {
|
|
548
492
|
if (authGen === authGeneration) {
|
|
549
493
|
closeConfirm(false);
|
|
550
|
-
lock("
|
|
494
|
+
lock(t("keyRejected"));
|
|
551
495
|
}
|
|
552
496
|
return;
|
|
553
497
|
}
|
|
@@ -556,7 +500,7 @@ async function confirmRecovery() {
|
|
|
556
500
|
closeConfirm(false);
|
|
557
501
|
pending = null;
|
|
558
502
|
if (response.status === 409) {
|
|
559
|
-
await reloadDetail("
|
|
503
|
+
await reloadDetail(t("conflict"), t("conflictFail"));
|
|
560
504
|
return;
|
|
561
505
|
}
|
|
562
506
|
const data = response.ok ? await readJson(response) : null;
|
|
@@ -564,17 +508,17 @@ async function confirmRecovery() {
|
|
|
564
508
|
return;
|
|
565
509
|
const changed = data && typeof data === "object" && typeof data.changed === "boolean" ? data.changed : null;
|
|
566
510
|
if (changed === true)
|
|
567
|
-
await reloadDetail("
|
|
511
|
+
await reloadDetail(t("recovered"), t("recoveredFail"));
|
|
568
512
|
else if (changed === false)
|
|
569
|
-
await reloadDetail("
|
|
513
|
+
await reloadDetail(t("noChange"), t("noChangeFail"));
|
|
570
514
|
else
|
|
571
|
-
await reloadDetail("
|
|
515
|
+
await reloadDetail(t("unconfirmed"), t("unconfirmedFail"));
|
|
572
516
|
}
|
|
573
517
|
catch {
|
|
574
518
|
if (gen === generation) {
|
|
575
519
|
closeConfirm(false);
|
|
576
520
|
pending = null;
|
|
577
|
-
await reloadDetail("
|
|
521
|
+
await reloadDetail(t("unconfirmed"), t("unconfirmedFail"));
|
|
578
522
|
}
|
|
579
523
|
}
|
|
580
524
|
finally {
|
|
@@ -598,6 +542,17 @@ function back() {
|
|
|
598
542
|
(roomRow(target) ?? roomsHeading).focus();
|
|
599
543
|
}
|
|
600
544
|
gateForm.addEventListener("submit", (event) => { event.preventDefault(); void unlock(); });
|
|
545
|
+
roomSearch.addEventListener("input", () => { searchTerm = roomSearch.value; renderRooms(); });
|
|
546
|
+
btnLang.addEventListener("click", () => {
|
|
547
|
+
const next = getLang() === "en" ? "zh" : "en";
|
|
548
|
+
setLang(next);
|
|
549
|
+
applyStatic();
|
|
550
|
+
btnLang.textContent = t("langLabel");
|
|
551
|
+
if (!detailView.hidden && detail)
|
|
552
|
+
renderDetail();
|
|
553
|
+
else if (!roomsView.hidden)
|
|
554
|
+
renderRooms();
|
|
555
|
+
});
|
|
601
556
|
btnLock.addEventListener("click", () => lock());
|
|
602
557
|
btnRefresh.addEventListener("click", () => void refreshRooms());
|
|
603
558
|
btnBack.addEventListener("click", back);
|
|
@@ -618,6 +573,8 @@ confirmDialog.addEventListener("close", () => {
|
|
|
618
573
|
if (shouldFocus && !detailView.hidden)
|
|
619
574
|
btnReview.focus();
|
|
620
575
|
});
|
|
576
|
+
applyStatic();
|
|
577
|
+
btnLang.textContent = t("langLabel");
|
|
621
578
|
window.addEventListener("pageshow", (event) => { if (event.persisted)
|
|
622
579
|
lock(); });
|
|
623
580
|
window.addEventListener("pagehide", () => lock("", false));
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { formatRoomPreview } from "./system-messages.js";
|
|
2
|
-
import { iconNode } from "./icons.js";
|
|
3
2
|
const LIST_IDS = ["roomList", "roomListChat"];
|
|
4
3
|
let dragging = null;
|
|
5
4
|
let suppressClickUntil = 0;
|
|
@@ -67,12 +66,25 @@ function rerender(app) {
|
|
|
67
66
|
app.renderRoomOptions(list, app.state.availableRooms || []);
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
|
-
function
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
69
|
+
function rankedIds(app) {
|
|
70
|
+
const rooms = app.state.availableRooms || [];
|
|
71
|
+
const rank = new Map(app.LS.roomOrder.map((id, index) => [id, index]));
|
|
72
|
+
return [...rooms]
|
|
73
|
+
.sort((left, right) => (rank.get(left.id) ?? 1e9) - (rank.get(right.id) ?? 1e9))
|
|
74
|
+
.map((room) => room.id);
|
|
75
|
+
}
|
|
76
|
+
function moveRoom(app, roomId, targetId, after = false) {
|
|
77
|
+
const ids = rankedIds(app);
|
|
78
|
+
const from = ids.indexOf(roomId);
|
|
79
|
+
if (from < 0)
|
|
80
|
+
return;
|
|
81
|
+
const source = ids.splice(from, 1)[0];
|
|
82
|
+
const to = ids.indexOf(targetId);
|
|
83
|
+
if (to < 0)
|
|
84
|
+
return;
|
|
85
|
+
ids.splice(to + (after ? 1 : 0), 0, source);
|
|
86
|
+
if (ids.every((id, index) => id === rankedIds(app)[index]))
|
|
74
87
|
return;
|
|
75
|
-
ids.splice(to, 0, ...ids.splice(from, 1));
|
|
76
88
|
app.LS.roomOrder = ids;
|
|
77
89
|
const room = (app.state.availableRooms || []).find((item) => item.id === roomId);
|
|
78
90
|
keepRowFocus = true;
|
|
@@ -87,13 +99,37 @@ function moveRoom(app, roomId, targetId) {
|
|
|
87
99
|
}
|
|
88
100
|
function stepRoom(app, roomId, joined, step) {
|
|
89
101
|
const rooms = app.state.availableRooms || [], joinedIds = joinedRoomIds(app, rooms);
|
|
90
|
-
|
|
102
|
+
// The saved order is the rendered order; the state array may still be raw.
|
|
103
|
+
const rank = new Map(app.LS.roomOrder.map((id, index) => [id, index]));
|
|
104
|
+
const ordered = [...rooms].sort((left, right) => (rank.get(left.id) ?? Number.MAX_SAFE_INTEGER) - (rank.get(right.id) ?? Number.MAX_SAFE_INTEGER));
|
|
105
|
+
const group = ordered.filter((room) => joinedIds.has(room.id) === joined);
|
|
91
106
|
const index = group.findIndex((room) => room.id === roomId);
|
|
92
107
|
const target = group[index + step];
|
|
93
108
|
if (index < 0 || !target)
|
|
94
109
|
return;
|
|
95
110
|
moveRoom(app, roomId, target.id);
|
|
96
111
|
}
|
|
112
|
+
let dropMarked = null;
|
|
113
|
+
let dropAfter = false;
|
|
114
|
+
function clearDropMark() {
|
|
115
|
+
dropMarked?.classList.remove("drop-before", "drop-after");
|
|
116
|
+
dropMarked = null;
|
|
117
|
+
}
|
|
118
|
+
function markDrop(element, after) {
|
|
119
|
+
if (dropMarked === element && dropAfter === after)
|
|
120
|
+
return;
|
|
121
|
+
clearDropMark();
|
|
122
|
+
dropMarked = element;
|
|
123
|
+
dropAfter = after;
|
|
124
|
+
element.classList.add(after ? "drop-after" : "drop-before");
|
|
125
|
+
}
|
|
126
|
+
function dropTargetAt(x, y) {
|
|
127
|
+
const row = document.elementFromPoint(x, y)?.closest(".room-row");
|
|
128
|
+
if (!row || !row.dataset.roomId)
|
|
129
|
+
return null;
|
|
130
|
+
const rect = row.getBoundingClientRect();
|
|
131
|
+
return { el: row, roomId: row.dataset.roomId, after: y > rect.top + rect.height / 2 };
|
|
132
|
+
}
|
|
97
133
|
// The room rows in the rail and the mobile drawer share one renderer.
|
|
98
134
|
export function renderRoomOptions(app, list, rooms) {
|
|
99
135
|
if (!list)
|
|
@@ -193,7 +229,18 @@ export function renderRoomOptions(app, list, rooms) {
|
|
|
193
229
|
}
|
|
194
230
|
void app.joinRoom(room.id, name);
|
|
195
231
|
});
|
|
196
|
-
|
|
232
|
+
button.addEventListener("keydown", (event) => {
|
|
233
|
+
if (!event.altKey || !event.shiftKey || event.ctrlKey || event.metaKey)
|
|
234
|
+
return;
|
|
235
|
+
const step = event.key === "ArrowUp" ? -1 : event.key === "ArrowDown" ? 1 : 0;
|
|
236
|
+
if (!step)
|
|
237
|
+
return;
|
|
238
|
+
event.preventDefault();
|
|
239
|
+
event.stopPropagation();
|
|
240
|
+
stepRoom(app, room.id, joined, step);
|
|
241
|
+
});
|
|
242
|
+
// Drag reorders inside one group; the target shows a line so a drag has
|
|
243
|
+
// one unambiguous insertion point. Coarse pointers get a hold-to-drag.
|
|
197
244
|
button.addEventListener("dragstart", (event) => {
|
|
198
245
|
dragging = { roomId: room.id, joined };
|
|
199
246
|
suppressClickUntil = Date.now() + 500;
|
|
@@ -205,9 +252,8 @@ export function renderRoomOptions(app, list, rooms) {
|
|
|
205
252
|
button.addEventListener("dragend", () => {
|
|
206
253
|
dragging = null;
|
|
207
254
|
suppressClickUntil = Date.now() + 250;
|
|
255
|
+
clearDropMark();
|
|
208
256
|
button.classList.remove("dragging");
|
|
209
|
-
for (const marked of list.querySelectorAll(".drop-target"))
|
|
210
|
-
marked.classList.remove("drop-target");
|
|
211
257
|
});
|
|
212
258
|
button.addEventListener("dragover", (event) => {
|
|
213
259
|
if (!dragging || dragging.joined !== joined || dragging.roomId === room.id)
|
|
@@ -215,45 +261,63 @@ export function renderRoomOptions(app, list, rooms) {
|
|
|
215
261
|
event.preventDefault();
|
|
216
262
|
if (event.dataTransfer)
|
|
217
263
|
event.dataTransfer.dropEffect = "move";
|
|
218
|
-
button.
|
|
264
|
+
markDrop(button, event.clientY > button.getBoundingClientRect().top + button.offsetHeight / 2);
|
|
219
265
|
});
|
|
220
|
-
button.addEventListener("dragleave",
|
|
221
|
-
button.classList.remove("drop-target"); });
|
|
266
|
+
button.addEventListener("dragleave", clearDropMark);
|
|
222
267
|
button.addEventListener("drop", (event) => {
|
|
223
268
|
event.preventDefault();
|
|
224
|
-
button.classList.remove("drop-target");
|
|
225
269
|
const source = dragging;
|
|
270
|
+
const after = dropAfter;
|
|
226
271
|
dragging = null;
|
|
272
|
+
clearDropMark();
|
|
227
273
|
if (!source || source.joined !== joined || source.roomId === room.id)
|
|
228
274
|
return;
|
|
229
|
-
moveRoom(app, source.roomId, room.id);
|
|
275
|
+
moveRoom(app, source.roomId, room.id, after);
|
|
230
276
|
});
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
277
|
+
// A coarse pointer cannot start an HTML5 drag, so the grip runs a pointer drag.
|
|
278
|
+
const grip = document.createElement("span");
|
|
279
|
+
grip.className = "room-grip";
|
|
280
|
+
grip.setAttribute("aria-hidden", "true");
|
|
281
|
+
grip.textContent = "⠿";
|
|
282
|
+
grip.addEventListener("pointerdown", (event) => {
|
|
283
|
+
if (event.button !== 0)
|
|
236
284
|
return;
|
|
237
285
|
event.preventDefault();
|
|
238
|
-
|
|
239
|
-
|
|
286
|
+
dragging = { roomId: room.id, joined };
|
|
287
|
+
suppressClickUntil = Date.now() + 500;
|
|
288
|
+
button.classList.add("dragging");
|
|
289
|
+
const finish = (up) => {
|
|
290
|
+
window.removeEventListener("pointermove", move);
|
|
291
|
+
window.removeEventListener("pointerup", finish);
|
|
292
|
+
window.removeEventListener("pointercancel", cancel, true);
|
|
293
|
+
dragging = null;
|
|
294
|
+
suppressClickUntil = Date.now() + 350;
|
|
295
|
+
button.classList.remove("dragging");
|
|
296
|
+
const target = dropTargetAt(up.clientX, up.clientY);
|
|
297
|
+
const after = dropAfter;
|
|
298
|
+
clearDropMark();
|
|
299
|
+
if (target && target.roomId !== room.id)
|
|
300
|
+
moveRoom(app, room.id, target.roomId, after);
|
|
301
|
+
};
|
|
302
|
+
const cancel = () => {
|
|
303
|
+
window.removeEventListener("pointermove", move);
|
|
304
|
+
window.removeEventListener("pointerup", finish);
|
|
305
|
+
window.removeEventListener("pointercancel", cancel, true);
|
|
306
|
+
dragging = null;
|
|
307
|
+
button.classList.remove("dragging");
|
|
308
|
+
clearDropMark();
|
|
309
|
+
};
|
|
310
|
+
const move = (point) => {
|
|
311
|
+
const target = dropTargetAt(point.clientX, point.clientY);
|
|
312
|
+
if (target)
|
|
313
|
+
markDrop(target.el, target.after);
|
|
314
|
+
};
|
|
315
|
+
window.addEventListener("pointermove", move, { passive: true });
|
|
316
|
+
window.addEventListener("pointerup", finish);
|
|
317
|
+
window.addEventListener("pointercancel", cancel, true);
|
|
240
318
|
});
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
moves.className = "room-move";
|
|
244
|
-
for (const step of [-1, 1]) {
|
|
245
|
-
const move = document.createElement("button");
|
|
246
|
-
move.type = "button";
|
|
247
|
-
move.className = "room-move-btn";
|
|
248
|
-
move.setAttribute("aria-label", app.t(step < 0 ? "roomMoveUp" : "roomMoveDown", { name: room.name }));
|
|
249
|
-
move.append(iconNode(step < 0 ? "chevron_up" : "chevron_down"));
|
|
250
|
-
const peers = joined ? joinedGroup : otherGroup;
|
|
251
|
-
const index = peers.findIndex((item) => item.id === room.id);
|
|
252
|
-
move.disabled = index < 0 || index + step < 0 || index + step >= peers.length;
|
|
253
|
-
move.addEventListener("click", () => stepRoom(app, room.id, joined, step));
|
|
254
|
-
moves.append(move);
|
|
255
|
-
}
|
|
256
|
-
row.append(button, moves);
|
|
319
|
+
button.append(grip);
|
|
320
|
+
row.append(button);
|
|
257
321
|
list.append(row);
|
|
258
322
|
}
|
|
259
323
|
list.scrollTop = scrollTop;
|