@alexsun-top/opencode-chat-room 0.8.5 → 0.8.7
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 +23 -2
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/cli.ts +19 -0
- package/dist/cli.js +4058 -1531
- package/package.json +7 -1
- package/packages/chat-room-channeld/README.md +13 -8
- package/packages/chat-room-channeld/src/adapter.ts +52 -0
- package/packages/chat-room-channeld/src/config.ts +6 -1
- package/packages/chat-room-channeld/src/delivery.ts +0 -4
- package/packages/chat-room-channeld/src/host.ts +66 -44
- package/packages/chat-room-channeld/src/inbound.ts +14 -1
- package/packages/chat-room-channeld/src/pg/database.ts +141 -49
- package/packages/chat-room-channeld/src/pg/worker.mjs +46 -5
- package/packages/chat-room-channeld/src/pg/worker.mts +41 -6
- package/packages/chat-room-channeld/src/protocol.ts +38 -1
- package/packages/chat-room-channeld/src/state-rows.ts +132 -0
- package/packages/chat-room-channeld/src/state.ts +129 -157
- package/packages/chat-room-channeld/src/stats.ts +4 -0
- package/plugin.ts +26 -5
- package/server/app.ts +15 -0
- package/server/assets/base.css +22 -2
- package/server/assets/chat/admin.js +13 -0
- package/server/assets/chat/announcements.js +76 -34
- package/server/assets/chat/confirm-dialog.js +3 -0
- package/server/assets/chat/create-room-dialog.js +7 -0
- package/server/assets/chat/diagram-viewer.js +4 -8
- package/server/assets/chat/doc-preview.js +70 -30
- package/server/assets/chat/editor.js +38 -3
- package/server/assets/chat/events.js +11 -2
- package/server/assets/chat/files.js +28 -26
- package/server/assets/chat/history-loader.js +31 -15
- package/server/assets/chat/integration-editor.js +25 -1
- package/server/assets/chat/integrations.js +107 -15
- package/server/assets/chat/join-requests.js +39 -1
- package/server/assets/chat/locales/de.js +5 -3
- package/server/assets/chat/locales/es.js +5 -3
- package/server/assets/chat/locales/fr.js +5 -3
- package/server/assets/chat/locales/it.js +5 -3
- package/server/assets/chat/locales/ja.js +5 -3
- package/server/assets/chat/locales/ko.js +5 -3
- package/server/assets/chat/markdown-footnotes.js +19 -8
- package/server/assets/chat/markdown.js +0 -7
- package/server/assets/chat/members.js +31 -19
- package/server/assets/chat/message-cache.js +8 -2
- package/server/assets/chat/message-polling.js +8 -2
- package/server/assets/chat/message-window.js +57 -0
- package/server/assets/chat/messages.js +79 -40
- package/server/assets/chat/operator.js +624 -0
- package/server/assets/chat/palette.js +2 -7
- package/server/assets/chat/panels.js +31 -8
- package/server/assets/chat/questions.js +72 -56
- package/server/assets/chat/recall.js +14 -5
- package/server/assets/chat/receipts.js +63 -7
- package/server/assets/chat/refresh-timing.js +6 -0
- package/server/assets/chat/reminders.js +44 -13
- package/server/assets/chat/replies.js +33 -22
- package/server/assets/chat/resource-format.js +4 -1
- package/server/assets/chat/room-list.js +202 -3
- package/server/assets/chat/room-watcher.js +3 -1
- package/server/assets/chat/rooms.js +22 -3
- package/server/assets/chat/settings.js +33 -3
- package/server/assets/chat/state.js +21 -7
- package/server/assets/chat/tasks.js +33 -11
- package/server/assets/chat/window-controls.js +25 -16
- package/server/assets/code-highlight.css +0 -13
- package/server/assets/conversation.css +30 -2
- package/server/assets/doc-preview.css +3 -0
- package/server/assets/files.css +4 -0
- package/server/assets/monaco/integration-rules.js +1 -1
- package/server/assets/responsive.css +12 -2
- package/server/assets/settings.css +3 -1
- package/server/assets/tasks.css +6 -1
- package/server/assets/window-controls.css +3 -1
- package/server/channels.ts +24 -6
- package/server/chat-server.ts +4 -0
- package/server/chat.html +7 -2
- package/server/inbox.ts +3 -1
- package/server/join-requests.ts +8 -1
- package/server/mcp-http.ts +88 -0
- package/server/member-routes.ts +16 -2
- package/server/newrooms.ts +2 -13
- package/server/operator-auth.ts +21 -0
- package/server/operator-routes.ts +150 -0
- package/server/operator-state.ts +64 -0
- package/server/operator.css +139 -0
- package/server/room-owner.ts +17 -0
- package/server/routes/inbox.ts +15 -5
- package/server/routes/pages.ts +12 -2
- package/server/routes/room-actions.ts +4 -3
- package/server/system.html +109 -0
- package/server/wake.ts +1 -1
- package/skills/chatroom/SKILL.md +19 -3
- package/src/acp/client.ts +254 -0
- package/src/acp/protocol.ts +300 -0
- package/src/acp/watch.ts +498 -0
- package/src/agent/agent-receipts.ts +87 -5
- package/src/center/center-client.ts +18 -1
- package/src/center/center-inbox.ts +54 -7
- package/src/center/center-wake.ts +57 -3
- package/src/center/forward-client.ts +48 -0
- package/src/center/mentions.ts +16 -3
- package/src/center/notification-delay.ts +139 -0
- package/src/center/queue.ts +3 -0
- package/src/config/file-config.ts +25 -0
- package/src/mcp/server.ts +407 -0
- package/src/protocol/config.ts +7 -0
- package/src/runtime/plugin-notifications.ts +43 -9
- package/src/runtime/v2-plugin.ts +20 -4
- package/src/runtime/v2-receiver.ts +10 -2
- package/src/runtime/watch.ts +5 -1
- package/src/state/pg-database.ts +133 -49
- package/src/state/pg-worker.mjs +46 -5
- package/src/state/pg-worker.mts +41 -6
- package/src/state/receiver-state.ts +47 -0
- package/src/state/sqlite-database.ts +6 -2
- package/src/state/sqlite-members.ts +48 -4
- package/src/state/sqlite-messages.ts +25 -12
- package/src/state/sqlite-schema.ts +4 -1
- package/src/state/sqlite-state.ts +1 -1
- package/src/state/store.ts +10 -4
- package/src/tui/app.mjs +57 -10
- package/src/tui/app.mts +54 -11
- package/src/tui/room-settings-app.mjs +27 -9
- package/src/tui/room-settings-app.mts +26 -9
- package/src/web/integration-rules-editor.ts +25 -2
|
@@ -31,7 +31,7 @@ const EXTENSION_LANGUAGES = {
|
|
|
31
31
|
kt: "kotlin", kts: "kotlin", c: "c", h: "c", cpp: "cpp", hpp: "cpp", cc: "cpp",
|
|
32
32
|
cs: "csharp", php: "php", swift: "swift", sql: "sql",
|
|
33
33
|
html: "xml", htm: "xml", css: "css", scss: "scss", less: "less",
|
|
34
|
-
xml: "xml",
|
|
34
|
+
xml: "xml", vue: "xml", svelte: "xml",
|
|
35
35
|
lua: "lua", r: "r", pl: "perl", pm: "perl", dart: "dart",
|
|
36
36
|
gradle: "groovy", dockerfile: "dockerfile", makefile: "makefile", mk: "makefile",
|
|
37
37
|
};
|
|
@@ -69,6 +69,9 @@ export function docPreviewFormat(resource) {
|
|
|
69
69
|
if (mime === "text/markdown" || mime === "text/x-markdown" || ext === "md" || ext === "markdown") {
|
|
70
70
|
return { kind: "markdown", language: "", label: "" };
|
|
71
71
|
}
|
|
72
|
+
// SVG stays an inert image in the preview; its bytes are never parsed as markup.
|
|
73
|
+
if (mime === "image/svg+xml" || ext === "svg")
|
|
74
|
+
return { kind: "svg", language: "", label: "SVG" };
|
|
72
75
|
// Server sniffing reports Office packages as octet-stream, so the extension counts.
|
|
73
76
|
const office = OFFICE_MIMES[mime] || (OFFICE_KINDS.has(ext) ? ext : "");
|
|
74
77
|
if (office)
|
|
@@ -1,14 +1,132 @@
|
|
|
1
1
|
import { formatRoomPreview } from "./system-messages.js";
|
|
2
|
+
import { iconNode } from "./icons.js";
|
|
3
|
+
const LIST_IDS = ["roomList", "roomListChat"];
|
|
4
|
+
let dragging = null;
|
|
5
|
+
let suppressClickUntil = 0;
|
|
6
|
+
let explicitRefresh = false;
|
|
7
|
+
let busyCount = 0;
|
|
8
|
+
// Only an explicit reorder returns focus to a row; ordinary rerenders must leave the
|
|
9
|
+
// caret in the composer instead of pinning it to the row a click landed on.
|
|
10
|
+
let keepRowFocus = false;
|
|
11
|
+
const clickGuarded = new WeakSet();
|
|
12
|
+
// Capture runs before the refresh button's own click handler, which calls refreshRoomList.
|
|
13
|
+
document.addEventListener("click", (event) => {
|
|
14
|
+
if (event.target instanceof Element && event.target.closest("#btnRefreshRooms"))
|
|
15
|
+
explicitRefresh = true;
|
|
16
|
+
}, true);
|
|
17
|
+
// Escape cancels a drag natively; it must not also close the room drawer.
|
|
18
|
+
document.addEventListener("keydown", (event) => {
|
|
19
|
+
if (dragging && event.key === "Escape")
|
|
20
|
+
event.stopPropagation();
|
|
21
|
+
}, true);
|
|
22
|
+
export function consumeRoomListRefresh() {
|
|
23
|
+
const value = explicitRefresh;
|
|
24
|
+
explicitRefresh = false;
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
export function setRoomListBusy(active) {
|
|
28
|
+
busyCount = Math.max(0, busyCount + (active ? 1 : -1));
|
|
29
|
+
for (const id of LIST_IDS) {
|
|
30
|
+
const list = document.getElementById(id);
|
|
31
|
+
if (!list)
|
|
32
|
+
continue;
|
|
33
|
+
if (busyCount)
|
|
34
|
+
list.setAttribute("aria-busy", "true");
|
|
35
|
+
else
|
|
36
|
+
list.removeAttribute("aria-busy");
|
|
37
|
+
}
|
|
38
|
+
document.getElementById("btnRefreshRooms")?.classList.toggle("is-refreshing", busyCount > 0);
|
|
39
|
+
}
|
|
40
|
+
const joinedRoomIds = (app, rooms) => new Set(rooms.filter((room) => app.state.rooms.has(room.id) || room.joined).map((room) => room.id));
|
|
41
|
+
// Joined rooms stay first; the saved order ranks each group, and rooms without a
|
|
42
|
+
// saved rank keep their incoming order.
|
|
43
|
+
function orderRooms(app, rooms) {
|
|
44
|
+
const joined = joinedRoomIds(app, rooms);
|
|
45
|
+
const rank = new Map(app.LS.roomOrder.map((id, index) => [id, index]));
|
|
46
|
+
const position = new Map(rooms.map((room, index) => [room.id, index]));
|
|
47
|
+
return [...rooms].sort((left, right) => Number(joined.has(right.id)) - Number(joined.has(left.id)) ||
|
|
48
|
+
(rank.get(left.id) ?? Number.MAX_SAFE_INTEGER) - (rank.get(right.id) ?? Number.MAX_SAFE_INTEGER) ||
|
|
49
|
+
position.get(left.id) - position.get(right.id));
|
|
50
|
+
}
|
|
51
|
+
function announce(name) {
|
|
52
|
+
let status = document.getElementById("roomOrderStatus");
|
|
53
|
+
if (!status) {
|
|
54
|
+
status = document.createElement("p");
|
|
55
|
+
status.id = "roomOrderStatus";
|
|
56
|
+
status.className = "room-order-status";
|
|
57
|
+
status.setAttribute("aria-live", "polite");
|
|
58
|
+
document.body.append(status);
|
|
59
|
+
}
|
|
60
|
+
status.textContent = name;
|
|
61
|
+
}
|
|
62
|
+
// Both lists show one order; the renderer keeps focus and scroll on its own.
|
|
63
|
+
function rerender(app) {
|
|
64
|
+
for (const id of LIST_IDS) {
|
|
65
|
+
const list = document.getElementById(id);
|
|
66
|
+
if (list)
|
|
67
|
+
app.renderRoomOptions(list, app.state.availableRooms || []);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function moveRoom(app, roomId, targetId) {
|
|
71
|
+
const ids = (app.state.availableRooms || []).map((room) => room.id);
|
|
72
|
+
const from = ids.indexOf(roomId), to = ids.indexOf(targetId);
|
|
73
|
+
if (from < 0 || to < 0 || from === to)
|
|
74
|
+
return;
|
|
75
|
+
ids.splice(to, 0, ...ids.splice(from, 1));
|
|
76
|
+
app.LS.roomOrder = ids;
|
|
77
|
+
const room = (app.state.availableRooms || []).find((item) => item.id === roomId);
|
|
78
|
+
keepRowFocus = true;
|
|
79
|
+
try {
|
|
80
|
+
rerender(app);
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
keepRowFocus = false;
|
|
84
|
+
}
|
|
85
|
+
if (room)
|
|
86
|
+
announce(app.t("roomMoved", { name: room.name }));
|
|
87
|
+
}
|
|
88
|
+
function stepRoom(app, roomId, joined, step) {
|
|
89
|
+
const rooms = app.state.availableRooms || [], joinedIds = joinedRoomIds(app, rooms);
|
|
90
|
+
const group = rooms.filter((room) => joinedIds.has(room.id) === joined);
|
|
91
|
+
const index = group.findIndex((room) => room.id === roomId);
|
|
92
|
+
const target = group[index + step];
|
|
93
|
+
if (index < 0 || !target)
|
|
94
|
+
return;
|
|
95
|
+
moveRoom(app, roomId, target.id);
|
|
96
|
+
}
|
|
2
97
|
// The room rows in the rail and the mobile drawer share one renderer.
|
|
3
98
|
export function renderRoomOptions(app, list, rooms) {
|
|
4
99
|
if (!list)
|
|
5
100
|
return;
|
|
101
|
+
// Keep the scroll offset across frequent rerenders; focus returns only after a reorder.
|
|
102
|
+
const active = document.activeElement;
|
|
103
|
+
const focusedId = keepRowFocus && active && list.contains(active) ? active.closest("li")?.querySelector(".room-row")?.dataset.roomId : undefined;
|
|
104
|
+
const scrollTop = list.scrollTop;
|
|
105
|
+
if (!clickGuarded.has(list)) {
|
|
106
|
+
clickGuarded.add(list);
|
|
107
|
+
// A drag release can still emit a click that would join or close the drawer.
|
|
108
|
+
list.addEventListener("click", (event) => {
|
|
109
|
+
if (Date.now() >= suppressClickUntil)
|
|
110
|
+
return;
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
event.stopPropagation();
|
|
113
|
+
}, true);
|
|
114
|
+
}
|
|
115
|
+
const ordered = orderRooms(app, rooms);
|
|
116
|
+
if (!document.getElementById("roomOrderStatus"))
|
|
117
|
+
announce("");
|
|
118
|
+
if (rooms === app.state.availableRooms)
|
|
119
|
+
rooms.splice(0, rooms.length, ...ordered);
|
|
120
|
+
const joinedIds = joinedRoomIds(app, rooms);
|
|
121
|
+
const group = (isJoined) => ordered.filter((room) => joinedIds.has(room.id) === isJoined);
|
|
122
|
+
const joinedGroup = group(true), otherGroup = group(false);
|
|
6
123
|
list.textContent = "";
|
|
7
|
-
const ordered = [...rooms].sort((left, right) => Number(app.state.rooms.has(right.id) || right.joined) - Number(app.state.rooms.has(left.id) || left.joined));
|
|
8
124
|
for (const room of ordered) {
|
|
9
125
|
const row = document.createElement("li"), button = document.createElement("button");
|
|
10
126
|
button.type = "button";
|
|
11
127
|
button.dataset.roomId = room.id;
|
|
128
|
+
button.draggable = true;
|
|
129
|
+
button.setAttribute("aria-keyshortcuts", "Alt+Shift+ArrowUp Alt+Shift+ArrowDown");
|
|
12
130
|
const entry = app.state.rooms.get(room.id);
|
|
13
131
|
const joined = Boolean(entry || room.joined);
|
|
14
132
|
const pending = !joined && Boolean(app.state.pendingJoinIds?.has(room.id));
|
|
@@ -37,6 +155,20 @@ export function renderRoomOptions(app, list, rooms) {
|
|
|
37
155
|
button.append(name, kind, meta, preview, status);
|
|
38
156
|
const unread = entry && app.state.room?.id !== room.id ? (entry.unreadOverflow ? 100 : entry.unreadIds.size) : 0;
|
|
39
157
|
const openQuestions = Number(shownRoom.openQuestions) || 0;
|
|
158
|
+
// Joined rooms an admin owns may hold requests; the marker shares the badge
|
|
159
|
+
// corner with question and unread badges instead of replacing them.
|
|
160
|
+
const requests = joined && app.state.pendingJoinRequests.has(room.id);
|
|
161
|
+
const badges = document.createElement("span");
|
|
162
|
+
badges.className = "r-badges";
|
|
163
|
+
if (requests) {
|
|
164
|
+
const attention = document.createElement("span");
|
|
165
|
+
attention.className = "r-badge r-badge-requests";
|
|
166
|
+
attention.textContent = "!";
|
|
167
|
+
const label = app.t("pendingJoinRequests");
|
|
168
|
+
attention.title = label;
|
|
169
|
+
attention.setAttribute("aria-label", label);
|
|
170
|
+
badges.append(attention);
|
|
171
|
+
}
|
|
40
172
|
// Same badge slot as unread: a pending question shows "?" instead of a count.
|
|
41
173
|
if (unread || openQuestions) {
|
|
42
174
|
const badge = document.createElement("span");
|
|
@@ -45,9 +177,13 @@ export function renderRoomOptions(app, list, rooms) {
|
|
|
45
177
|
const label = openQuestions ? app.t("openQuestions", { count: openQuestions }) : app.t("unreadMessages", { count: unread });
|
|
46
178
|
badge.title = label;
|
|
47
179
|
badge.setAttribute("aria-label", label);
|
|
48
|
-
|
|
180
|
+
badges.append(badge);
|
|
49
181
|
}
|
|
182
|
+
if (badges.childElementCount)
|
|
183
|
+
button.append(badges);
|
|
50
184
|
button.addEventListener("click", () => {
|
|
185
|
+
if (Date.now() < suppressClickUntil)
|
|
186
|
+
return;
|
|
51
187
|
const name = app.state.myName || app.$("#inName")?.value.trim() || app.t("guest");
|
|
52
188
|
// A protected room must ask before turning a click into a join request.
|
|
53
189
|
if (!joined && approval && !pending && app.confirmAction) {
|
|
@@ -57,9 +193,72 @@ export function renderRoomOptions(app, list, rooms) {
|
|
|
57
193
|
}
|
|
58
194
|
void app.joinRoom(room.id, name);
|
|
59
195
|
});
|
|
60
|
-
|
|
196
|
+
// Drag only reorders inside one group, so joined rooms stay above the rest.
|
|
197
|
+
button.addEventListener("dragstart", (event) => {
|
|
198
|
+
dragging = { roomId: room.id, joined };
|
|
199
|
+
suppressClickUntil = Date.now() + 500;
|
|
200
|
+
event.dataTransfer?.setData("text/plain", room.id);
|
|
201
|
+
if (event.dataTransfer)
|
|
202
|
+
event.dataTransfer.effectAllowed = "move";
|
|
203
|
+
button.classList.add("dragging");
|
|
204
|
+
});
|
|
205
|
+
button.addEventListener("dragend", () => {
|
|
206
|
+
dragging = null;
|
|
207
|
+
suppressClickUntil = Date.now() + 250;
|
|
208
|
+
button.classList.remove("dragging");
|
|
209
|
+
for (const marked of list.querySelectorAll(".drop-target"))
|
|
210
|
+
marked.classList.remove("drop-target");
|
|
211
|
+
});
|
|
212
|
+
button.addEventListener("dragover", (event) => {
|
|
213
|
+
if (!dragging || dragging.joined !== joined || dragging.roomId === room.id)
|
|
214
|
+
return;
|
|
215
|
+
event.preventDefault();
|
|
216
|
+
if (event.dataTransfer)
|
|
217
|
+
event.dataTransfer.dropEffect = "move";
|
|
218
|
+
button.classList.add("drop-target");
|
|
219
|
+
});
|
|
220
|
+
button.addEventListener("dragleave", (event) => { if (!button.contains(event.relatedTarget))
|
|
221
|
+
button.classList.remove("drop-target"); });
|
|
222
|
+
button.addEventListener("drop", (event) => {
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
button.classList.remove("drop-target");
|
|
225
|
+
const source = dragging;
|
|
226
|
+
dragging = null;
|
|
227
|
+
if (!source || source.joined !== joined || source.roomId === room.id)
|
|
228
|
+
return;
|
|
229
|
+
moveRoom(app, source.roomId, room.id);
|
|
230
|
+
});
|
|
231
|
+
button.addEventListener("keydown", (event) => {
|
|
232
|
+
if (!event.altKey || !event.shiftKey || event.ctrlKey || event.metaKey)
|
|
233
|
+
return;
|
|
234
|
+
const step = event.key === "ArrowUp" ? -1 : event.key === "ArrowDown" ? 1 : 0;
|
|
235
|
+
if (!step)
|
|
236
|
+
return;
|
|
237
|
+
event.preventDefault();
|
|
238
|
+
event.stopPropagation();
|
|
239
|
+
stepRoom(app, room.id, joined, step);
|
|
240
|
+
});
|
|
241
|
+
// Coarse pointers cannot start a native drag: give touch an explicit control.
|
|
242
|
+
const moves = document.createElement("span");
|
|
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);
|
|
61
257
|
list.append(row);
|
|
62
258
|
}
|
|
259
|
+
list.scrollTop = scrollTop;
|
|
260
|
+
if (focusedId)
|
|
261
|
+
list.querySelector(`.room-row[data-room-id="${CSS.escape(focusedId)}"]`)?.focus({ preventScroll: true });
|
|
63
262
|
// Other rooms' unread changes only reach the title through this rerender.
|
|
64
263
|
app.updateTitle();
|
|
65
264
|
const keyHint = document.getElementById("railKeyHint");
|
|
@@ -24,10 +24,12 @@ export async function watchRoom(roomId, app) {
|
|
|
24
24
|
for (const message of result.items) {
|
|
25
25
|
if (message.createdAt > entry.readTs && isUnreadMessage(message, app, entry.room, entry.name) && !entry.unreadIds.has(message.id))
|
|
26
26
|
entry.unreadIds.set(message.id, message);
|
|
27
|
-
if (message.answerToMessageID && entry.unreadIds.get(message.answerToMessageID)?.isQuestion)
|
|
27
|
+
if (message.answerQuestionExcerpt && message.answerToMessageID && entry.unreadIds.get(message.answerToMessageID)?.isQuestion)
|
|
28
28
|
entry.unreadIds.delete(message.answerToMessageID);
|
|
29
29
|
if (!before.has(message.id))
|
|
30
30
|
entry.room.messages.push({ ...message, roomId });
|
|
31
|
+
if (message.answerQuestionExcerpt && message.answerToMessageID)
|
|
32
|
+
app.settleQuestionAnswer?.(roomId, message.answerToMessageID, message);
|
|
31
33
|
if (message.createdAt >= entry.previewAt)
|
|
32
34
|
setRoomPreview(entry, message);
|
|
33
35
|
}
|
|
@@ -3,7 +3,8 @@ import { isUnreadMessage } from "./messages.js";
|
|
|
3
3
|
import { setRoomPreview } from "./system-messages.js";
|
|
4
4
|
import { watchRoom } from "./room-watcher.js";
|
|
5
5
|
import { cacheRoomSoon, deleteCachedRoom, loadCachedRooms } from "./message-cache.js";
|
|
6
|
-
import { renderRoomOptions } from "./room-list.js";
|
|
6
|
+
import { renderRoomOptions, consumeRoomListRefresh, setRoomListBusy } from "./room-list.js";
|
|
7
|
+
import { waitForRefresh } from "./refresh-timing.js";
|
|
7
8
|
import { initPanels } from "./panels.js";
|
|
8
9
|
const statusOf = (error) => error instanceof Error && "status" in error ? error.status : undefined;
|
|
9
10
|
const messageOf = (error) => error instanceof Error ? error.message : "";
|
|
@@ -404,13 +405,16 @@ export function initRooms(app) {
|
|
|
404
405
|
void app.refreshRoomList(true);
|
|
405
406
|
app.renderRoomOptions($("#roomList"), app.state.availableRooms || []);
|
|
406
407
|
app.renderRoomOptions($("#roomListChat"), app.state.availableRooms || []);
|
|
408
|
+
// The marker request must never hold up the ordinary room render.
|
|
409
|
+
void app.refreshPendingJoinBadges?.();
|
|
407
410
|
app.startRoomWatcher();
|
|
408
411
|
}, 5000);
|
|
409
412
|
};
|
|
410
413
|
app.refreshRoomList = (automatic = false) => {
|
|
411
414
|
if (automatic && autoRefresh?.generation === roomListGeneration)
|
|
412
415
|
return autoRefresh.promise;
|
|
413
|
-
const
|
|
416
|
+
const explicit = !automatic && consumeRoomListRefresh();
|
|
417
|
+
const generation = invalidateRoomList(), promise = loadRoomList(generation, explicit);
|
|
414
418
|
if (automatic) {
|
|
415
419
|
autoRefresh = { generation, promise };
|
|
416
420
|
const clear = () => { if (autoRefresh?.promise === promise)
|
|
@@ -419,8 +423,13 @@ export function initRooms(app) {
|
|
|
419
423
|
}
|
|
420
424
|
return promise;
|
|
421
425
|
};
|
|
422
|
-
async function loadRoomList(generation) {
|
|
426
|
+
async function loadRoomList(generation, explicit = false) {
|
|
423
427
|
const empty = $("#roomListEmpty"), chatEmpty = $("#roomListChatEmpty");
|
|
428
|
+
// An explicit refresh keeps the old rows under a steady busy state for 150ms,
|
|
429
|
+
// even when the server answers faster. Errors skip the wait.
|
|
430
|
+
const startedAt = explicit ? performance.now() : 0;
|
|
431
|
+
if (explicit)
|
|
432
|
+
setRoomListBusy(true);
|
|
424
433
|
try {
|
|
425
434
|
const rooms = await app.api(`/rooms?sessionID=${encodeURIComponent(LS.sessionID)}`);
|
|
426
435
|
if (generation !== roomListGeneration)
|
|
@@ -433,12 +442,18 @@ export function initRooms(app) {
|
|
|
433
442
|
syncCachedRooms(rooms, app);
|
|
434
443
|
await app.discoverDirectRooms(rooms, generation);
|
|
435
444
|
}
|
|
445
|
+
if (generation !== roomListGeneration)
|
|
446
|
+
return;
|
|
447
|
+
if (explicit)
|
|
448
|
+
await waitForRefresh(startedAt);
|
|
436
449
|
if (generation !== roomListGeneration)
|
|
437
450
|
return;
|
|
438
451
|
app.renderRoomOptions($("#roomList"), rooms);
|
|
439
452
|
app.renderRoomOptions($("#roomListChat"), rooms);
|
|
440
453
|
empty.hidden = rooms.length > 0;
|
|
441
454
|
chatEmpty.hidden = rooms.length > 0;
|
|
455
|
+
// Fire after the catalog is on screen; the answer re-renders only on change.
|
|
456
|
+
void app.refreshPendingJoinBadges?.();
|
|
442
457
|
}
|
|
443
458
|
catch (error) {
|
|
444
459
|
if (generation !== roomListGeneration)
|
|
@@ -466,6 +481,10 @@ export function initRooms(app) {
|
|
|
466
481
|
app.startRoomWatcher();
|
|
467
482
|
}
|
|
468
483
|
}
|
|
484
|
+
finally {
|
|
485
|
+
if (explicit)
|
|
486
|
+
setRoomListBusy(false);
|
|
487
|
+
}
|
|
469
488
|
}
|
|
470
489
|
app.restoreJoinedRooms = async (rooms, generation = roomListGeneration) => {
|
|
471
490
|
while (app.state.restoring) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { closeOnBackdrop } from "./panels.js";
|
|
2
|
+
import { WCO_VISIBILITY_CHANGE } from "./window-controls.js";
|
|
1
3
|
export const THEMES = ["system", "light", "dark", "forest", "sand", "custom"];
|
|
2
4
|
const DEFAULT_CUSTOM_THEME = "#22695c";
|
|
3
5
|
const validColor = (value) => /^#[0-9a-f]{6}$/i.test(value) ? value : DEFAULT_CUSTOM_THEME;
|
|
@@ -10,6 +12,18 @@ const isDarkColor = (color) => {
|
|
|
10
12
|
const [r = 0, g = 0, b = 0] = channels;
|
|
11
13
|
return 0.2126 * r + 0.7152 * g + 0.0722 * b < 0.4;
|
|
12
14
|
};
|
|
15
|
+
// Use plain RGB for the native caption, even when CSS uses color-mix().
|
|
16
|
+
const toSRGB = (color) => {
|
|
17
|
+
const canvas = document.createElement("canvas");
|
|
18
|
+
canvas.width = canvas.height = 1;
|
|
19
|
+
const context = canvas.getContext("2d");
|
|
20
|
+
if (!context)
|
|
21
|
+
return color;
|
|
22
|
+
context.fillStyle = color;
|
|
23
|
+
context.fillRect(0, 0, 1, 1);
|
|
24
|
+
const [r, g, b] = context.getImageData(0, 0, 1, 1).data;
|
|
25
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
26
|
+
};
|
|
13
27
|
export function initSettings(app) {
|
|
14
28
|
const $ = app.$;
|
|
15
29
|
const dialog = $("#chatSettings");
|
|
@@ -76,11 +90,23 @@ export function initSettings(app) {
|
|
|
76
90
|
};
|
|
77
91
|
const syncThemeColor = () => {
|
|
78
92
|
const meta = document.querySelector('meta[name="theme-color"]');
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
const root = document.documentElement;
|
|
94
|
+
if (!meta)
|
|
95
|
+
return;
|
|
96
|
+
if (root.dataset.wco === "true") {
|
|
97
|
+
// Keep the OS-painted caption area on the exact strip color.
|
|
98
|
+
const strip = getComputedStyle(document.body).backgroundColor;
|
|
99
|
+
if (strip)
|
|
100
|
+
meta.content = toSRGB(strip);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const token = root.dataset.windowFrame === "borderless" ? "--surface" : "--bg";
|
|
104
|
+
const background = root.dataset.theme === "custom" ? customColor() : getComputedStyle(root).getPropertyValue(token).trim();
|
|
105
|
+
if (background)
|
|
82
106
|
meta.content = background;
|
|
83
107
|
};
|
|
108
|
+
// Initial paint syncs through applyTheme below; runtime overlay toggles arrive here.
|
|
109
|
+
document.documentElement.addEventListener(WCO_VISIBILITY_CHANGE, syncThemeColor);
|
|
84
110
|
const syncThemeInputs = () => {
|
|
85
111
|
const stored = THEMES.includes(app.LS.theme) ? app.LS.theme : "system";
|
|
86
112
|
for (const input of dialog.querySelectorAll('input[name="theme"]'))
|
|
@@ -181,6 +207,10 @@ export function initSettings(app) {
|
|
|
181
207
|
dialog.close();
|
|
182
208
|
};
|
|
183
209
|
$("#btnCloseSettings")?.addEventListener("click", close);
|
|
210
|
+
closeOnBackdrop(dialog, () => {
|
|
211
|
+
if (tokenInput.value === app.LS.token && !app.hasIntegrationDraft?.())
|
|
212
|
+
close();
|
|
213
|
+
});
|
|
184
214
|
dialog.addEventListener("cancel", () => opener?.setAttribute("aria-expanded", "false"));
|
|
185
215
|
pageInput?.addEventListener("input", () => {
|
|
186
216
|
app.LS.pageStep = Number(pageInput.value);
|
|
@@ -10,7 +10,7 @@ export const app = {
|
|
|
10
10
|
receiptObservation: null,
|
|
11
11
|
memberApiUnavailable: new Set(), receiptApiUnavailable: new Set(),
|
|
12
12
|
receipts: new Map(), acknowledgedMessages: new Map(), pendingAcknowledgements: new Map(),
|
|
13
|
-
pendingAction: null, watcherTimer: 0, restored: false, resizeScrollAdjusting: false, layoutScrollAdjusting: false,
|
|
13
|
+
pendingAction: null, pendingJoinRequests: new Set(), watcherTimer: 0, restored: false, resizeScrollAdjusting: false, layoutScrollAdjusting: false,
|
|
14
14
|
readAnchorGuard: null, userScrollIntentUntil: 0, listMetrics: { height: 0, top: 0, client: 0 }, followBottom: true, threadPointerDown: false,
|
|
15
15
|
},
|
|
16
16
|
rendered: 0,
|
|
@@ -229,6 +229,16 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
229
229
|
}
|
|
230
230
|
},
|
|
231
231
|
set panelMode(value) { write("chat.panelMode", JSON.stringify(value || {})); },
|
|
232
|
+
get roomOrder() {
|
|
233
|
+
try {
|
|
234
|
+
const ids = JSON.parse(read("chat.roomOrder") || "[]");
|
|
235
|
+
return Array.isArray(ids) ? ids.filter((id) => typeof id === "string") : [];
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
return [];
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
set roomOrder(ids) { write("chat.roomOrder", JSON.stringify([...new Set(ids)])); },
|
|
232
242
|
get pageStep() { const raw = read("chat.pageStep"); const value = Number(raw); return raw !== null && raw !== "" && Number.isFinite(value) ? Math.min(200, Math.max(20, Math.round(value))) : 90; }, set pageStep(value) { const next = Number(value); write("chat.pageStep", Number.isFinite(next) ? String(Math.min(200, Math.max(20, Math.round(next)))) : null); },
|
|
233
243
|
get joinedRoomIds() {
|
|
234
244
|
try {
|
|
@@ -387,7 +397,7 @@ export const messages = {
|
|
|
387
397
|
editRoom: "Edit room", editRoomSections: "Edit room sections", editRoomDetails: "Room details", editRoomJoining: "Joining & approval", editRoomMembers: "Members & roles", editRoomOwnership: "Ownership", roomOwnerOnlyTitle: "Owner or administrator only", roomOwnerOnlyNote: ({ owner }) => `Only the room owner or a room administrator can change these settings. This room belongs to ${owner}.`, roomNameLabel: "Room name", roomDescriptionLabel: "Description", adminAgentLabel: "Administrator agent", roomOwnerBadge: "Owner", roomAdminBadge: "Admin",
|
|
388
398
|
adminIdsLabel: "Human administrators", adminIdsHint: "These members can edit room details, manage members, delete files, and choose a successor. The owner always has the same powers.", adminIdsEmpty: "No other members are in this room yet.", newOwnerLabel: "New owner", newOwnerHint: "Hand the room to another person who is in it. Only the owner can do this; agents cannot own a room.",
|
|
389
399
|
successorLabel: "Successor if the owner leaves", successorNone: "Longest-present member", successorHint: "If the owner leaves, this person becomes owner. If an administrator leaves, this person takes that role. Leave empty to use the longest-present member.", ownerOnlySettingsNote: "Only the owner can change the administrator agent or hand off the room.", adminAgentHint: "The designated agent can use the admin tool to inspect this room and its history. Only the owner can change this; leave empty for none.",
|
|
390
|
-
noAdminAgent: "None", openQuestions: ({ count }) => `${count} unanswered question${count === 1 ? "" : "s"}`,
|
|
400
|
+
noAdminAgent: "None", openQuestions: ({ count }) => `${count} unanswered question${count === 1 ? "" : "s"}`, pendingJoinRequests: "Join requests pending",
|
|
391
401
|
newRoom: "Create a room",
|
|
392
402
|
copyRoomIdTitle: ({ id }) => `Click to copy the full room ID: ${id}`, copied: "Copied",
|
|
393
403
|
members: "Members", membersCount: ({ count }) => `Members (${count})`, noMembers: "No members yet.", profileMenu: "Your profile and settings",
|
|
@@ -486,9 +496,9 @@ export const messages = {
|
|
|
486
496
|
shortcutsOpen: "All shortcuts",
|
|
487
497
|
shortcutsWriting: "Writing", shortcutsSend: "Send the message", shortcutsNewline: "Start a new line",
|
|
488
498
|
shortcutsMention: "Choose a member to mention", shortcutsRooms: "Rooms", shortcutsSearch: "Search and commands", shortcutsOpenPalette: "Open search and commands",
|
|
489
|
-
shortcutsSwitchRoom: "Switch to the previous or next room", shortcutsNumberRoom: "Switch to a joined room by number", shortcutsReading: "Reading",
|
|
499
|
+
shortcutsSwitchRoom: "Switch to the previous or next room", shortcutsNumberRoom: "Switch to a joined room by number", shortcutsMoveRoom: "Move the focused room up or down", shortcutsReading: "Reading",
|
|
490
500
|
shortcutsScroll: "Scroll messages while typing", shortcutsJump: "Jump to the start or end of the conversation", shortcutsMenus: "Menus and dialogs",
|
|
491
|
-
shortcutsClose: "Close the open menu
|
|
501
|
+
shortcutsClose: "Close the open menu or dialog",
|
|
492
502
|
paletteTitle: "Search and commands", paletteSearchLabel: "Search messages",
|
|
493
503
|
palettePlaceholder: "Search messages, or type / for commands", paletteScopeRoom: "This room", paletteScopeAll: "All rooms",
|
|
494
504
|
paletteScopeHint: "Tab switches between this room and all joined rooms", paletteSearchMode: "Search", paletteCommandMode: "Commands",
|
|
@@ -545,6 +555,7 @@ export const messages = {
|
|
|
545
555
|
failedMessages: "Messages not sent", retryFailed: "Retry", discardFailed: "Discard",
|
|
546
556
|
roomListError: "Unable to load rooms. You can enter a room ID directly.", guest: "Guest",
|
|
547
557
|
roomsLabel: "Rooms", refreshRooms: "Refresh rooms", identityLabel: ({ name }) => `Chatting as ${name}`,
|
|
558
|
+
roomMoveUp: ({ name }) => `Move ${name} up`, roomMoveDown: ({ name }) => `Move ${name} down`, roomMoved: ({ name }) => `Moved ${name}`,
|
|
548
559
|
roomsMenu: "Open room list", closeRoomList: "Close room list",
|
|
549
560
|
direct: "Direct", messagePrivately: "Message privately", removeMember: "Remove",
|
|
550
561
|
kickConfirm: ({ name }) => `Remove ${name} from this room? They can rejoin with the room ID.`,
|
|
@@ -563,6 +574,7 @@ export const messages = {
|
|
|
563
574
|
receiptCount: ({ count }) => `Read by ${count}`, receiptNone: "No readers yet", receiptAllRead: "Everyone has read this message", receiptNotLoaded: "Read status not loaded", readerPanelTitle: "Message readers", close: "Close", departedMember: "left",
|
|
564
575
|
confirmTitle: "Please confirm", cancel: "Cancel", confirmAction: "Confirm",
|
|
565
576
|
receiptEvidence_displayed: "Shown on screen", receiptEvidence_tool: "Fetched with room tool", receiptEvidence_context: "In agent context",
|
|
577
|
+
receiptDeliveredCount: ({ count }) => `Delivered to ${count} ${count === 1 ? "agent" : "agents"}; read not confirmed`, receiptDeliveredRow: "Read not confirmed",
|
|
566
578
|
},
|
|
567
579
|
"zh-CN": {
|
|
568
580
|
brand: "OC Chat", documentTitle: "OC Chat", roomTitle: ({ name }) => `${name} · OC Chat`,
|
|
@@ -593,7 +605,7 @@ export const messages = {
|
|
|
593
605
|
editRoom: "编辑房间", editRoomSections: "编辑房间分区", editRoomDetails: "房间信息", editRoomJoining: "加入与审核", editRoomMembers: "成员与角色", editRoomOwnership: "所有权", roomOwnerOnlyTitle: "仅房主或管理员可修改", roomOwnerOnlyNote: ({ owner }) => `只有房主或房间管理员可以修改这些设置。这个房间属于 ${owner}。`, roomNameLabel: "房间名称", roomDescriptionLabel: "描述", adminAgentLabel: "管理员 Agent", roomOwnerBadge: "房主", roomAdminBadge: "管理员",
|
|
594
606
|
adminIdsLabel: "成员管理员", adminIdsHint: "这些成员可以修改房间信息、管理成员、删除文件并指定接任者。房主始终拥有这些权限。", adminIdsEmpty: "房间里暂无其他成员。", newOwnerLabel: "新房主", newOwnerHint: "可以把房间交给房间里的另一个人。只有房主可以操作;Agent 不能成为房主。",
|
|
595
607
|
successorLabel: "房主离开后的接任者", successorNone: "最早加入的成员", successorHint: "房主离开后,此人接任房主;管理员离开后,此人接任管理员。留空则最早加入的成员接任房主。", ownerOnlySettingsNote: "只有房主可以更改管理员 Agent 或移交房间。", adminAgentHint: "被指定的 Agent 可用 admin 工具查看此房间及其历史。只有房主可以更改,留空表示不指定。",
|
|
596
|
-
noAdminAgent: "不指定", openQuestions: ({ count }) => `${count} 个待回答的问题`,
|
|
608
|
+
noAdminAgent: "不指定", openQuestions: ({ count }) => `${count} 个待回答的问题`, pendingJoinRequests: "有待审核的加入申请",
|
|
597
609
|
newRoom: "创建房间",
|
|
598
610
|
copyRoomIdTitle: ({ id }) => `点击复制完整房间 ID:${id}`, copied: "已复制", members: "成员",
|
|
599
611
|
membersCount: ({ count }) => `成员 ${count}`, noMembers: "暂无成员", settings: "设置", profileMenu: "个人资料和设置",
|
|
@@ -688,9 +700,9 @@ export const messages = {
|
|
|
688
700
|
shortcutsOpen: "全部快捷键",
|
|
689
701
|
shortcutsWriting: "输入", shortcutsSend: "发送消息", shortcutsNewline: "换行",
|
|
690
702
|
shortcutsMention: "选择要提及的成员", shortcutsRooms: "房间", shortcutsSearch: "搜索与命令", shortcutsOpenPalette: "打开搜索与命令面板",
|
|
691
|
-
shortcutsSwitchRoom: "切换到上一个或下一个房间", shortcutsNumberRoom: "按编号切换到已加入的房间", shortcutsReading: "阅读",
|
|
703
|
+
shortcutsSwitchRoom: "切换到上一个或下一个房间", shortcutsNumberRoom: "按编号切换到已加入的房间", shortcutsMoveRoom: "上移或下移聚焦的房间", shortcutsReading: "阅读",
|
|
692
704
|
shortcutsScroll: "输入时滚动消息", shortcutsJump: "跳到会话开头或结尾", shortcutsMenus: "菜单和对话框",
|
|
693
|
-
shortcutsClose: "
|
|
705
|
+
shortcutsClose: "关闭当前菜单或对话框",
|
|
694
706
|
paletteTitle: "搜索与命令", paletteSearchLabel: "搜索消息",
|
|
695
707
|
palettePlaceholder: "搜索消息,输入 / 使用命令", paletteScopeRoom: "当前房间", paletteScopeAll: "全部房间",
|
|
696
708
|
paletteScopeHint: "按 Tab 在当前房间和全部已加入房间之间切换", paletteSearchMode: "搜索", paletteCommandMode: "命令",
|
|
@@ -746,6 +758,7 @@ export const messages = {
|
|
|
746
758
|
failedMessages: "未发送的消息", retryFailed: "重试", discardFailed: "删除",
|
|
747
759
|
roomListError: "无法加载房间列表,可直接输入房间 ID 加入。", guest: "访客", roomsLabel: "房间列表",
|
|
748
760
|
refreshRooms: "刷新房间", identityLabel: ({ name }) => `当前昵称:${name}`, roomsMenu: "打开房间列表", closeRoomList: "关闭房间列表", direct: "私聊",
|
|
761
|
+
roomMoveUp: ({ name }) => `上移 ${name}`, roomMoveDown: ({ name }) => `下移 ${name}`, roomMoved: ({ name }) => `已移动 ${name}`,
|
|
749
762
|
messagePrivately: "私聊", removeMember: "移除", kickConfirm: ({ name }) => `确定将 ${name} 移出此房间?对方仍可用房间 ID 重新加入。`,
|
|
750
763
|
leaveRoomConfirm: ({ name }) => `离开“${name}”?你将离开这个房间,之后可以用房间 ID 重新加入。`,
|
|
751
764
|
deleteRoom: "删除房间", deleteConfirm: ({ name }) => `删除“${name}”及全部聊天记录?此操作无法撤销。`,
|
|
@@ -761,6 +774,7 @@ export const messages = {
|
|
|
761
774
|
receiptCount: ({ count }) => `已读 ${count} 人`, receiptNone: "尚无人已读", receiptAllRead: "所有人已读", receiptNotLoaded: "尚未加载已读状态", readerPanelTitle: "消息已读情况", close: "关闭", departedMember: "已离开",
|
|
762
775
|
confirmTitle: "请确认", cancel: "取消", confirmAction: "确认",
|
|
763
776
|
receiptEvidence_displayed: "已显示在屏幕上", receiptEvidence_tool: "通过房间工具读取", receiptEvidence_context: "进入上下文",
|
|
777
|
+
receiptDeliveredCount: ({ count }) => `已投递 ${count} 个 Agent,尚未确认已读`, receiptDeliveredRow: "尚未确认已读",
|
|
764
778
|
},
|
|
765
779
|
...extraLocales,
|
|
766
780
|
};
|
|
@@ -4,6 +4,8 @@ import { LS } from "./state.js";
|
|
|
4
4
|
import { isRoomAdmin } from "./admin-badge.js";
|
|
5
5
|
import { TITLE_MAX, buildTaskForm, createStepsEditor, fillAssignees, fillPeople, readPeople } from "./task-form.js";
|
|
6
6
|
import { buildTaskRow } from "./task-row.js";
|
|
7
|
+
import { waitForRefresh } from "./refresh-timing.js";
|
|
8
|
+
import { closeOnBackdrop } from "./panels.js";
|
|
7
9
|
const STATUSES = ["todo", "doing", "done"];
|
|
8
10
|
const STATUS_LABELS = { todo: "tasksStatusTodo", doing: "tasksStatusDoing", done: "tasksStatusDone" };
|
|
9
11
|
const PANE_QUERY = "(min-width: 1100px) and (min-height: 560px)";
|
|
@@ -41,6 +43,10 @@ export function initTasks(app) {
|
|
|
41
43
|
|| !createStepsHost || !createStepsButton)
|
|
42
44
|
return;
|
|
43
45
|
const createSteps = createStepsEditor(app, createStepsHost, createStepsButton);
|
|
46
|
+
// A form signature lets a backdrop click separate an untouched form from a draft.
|
|
47
|
+
let createBaseline = "", editBaseline = "";
|
|
48
|
+
const formState = (root) => Array.from(root.querySelectorAll("input, select, textarea"))
|
|
49
|
+
.map((field) => field instanceof HTMLInputElement && field.type === "checkbox" ? String(field.checked) : field.value).join("\0");
|
|
44
50
|
let items = [], loading = false, failed = false, generation = 0, editingId = "";
|
|
45
51
|
let taskLimit = null;
|
|
46
52
|
let opener = null, restoreFocus = true, pendingReopen = false;
|
|
@@ -111,6 +117,8 @@ export function initTasks(app) {
|
|
|
111
117
|
const setBusy = (busy) => {
|
|
112
118
|
loading = busy;
|
|
113
119
|
dialog.setAttribute("aria-busy", String(busy));
|
|
120
|
+
// A same-room reload spins the reload glyph in place; nothing else moves.
|
|
121
|
+
refresh.classList.toggle("is-refreshing", busy);
|
|
114
122
|
// A reload that finishes while an editor is open must not re-enable the
|
|
115
123
|
// refresh control the editor has locked.
|
|
116
124
|
refresh.disabled = busy || Boolean(editingId);
|
|
@@ -238,6 +246,7 @@ export function initTasks(app) {
|
|
|
238
246
|
editBody.textContent = "";
|
|
239
247
|
editHeading.textContent = app.t("tasksEditHeading");
|
|
240
248
|
editBody.append(buildTaskForm(view, task));
|
|
249
|
+
editBaseline = formState(editBody);
|
|
241
250
|
refresh.disabled = true;
|
|
242
251
|
editDialog.showModal();
|
|
243
252
|
editBody.querySelector(".task-edit-title")?.focus();
|
|
@@ -324,14 +333,18 @@ export function initTasks(app) {
|
|
|
324
333
|
const roomId = room.id, request = ++generation;
|
|
325
334
|
taskLimit = null;
|
|
326
335
|
setBusy(true);
|
|
327
|
-
|
|
336
|
+
// The rows stay put; a loading label only replaces an empty board.
|
|
328
337
|
if (!items.length)
|
|
329
338
|
summary.textContent = app.t("tasksLoading");
|
|
339
|
+
const started = performance.now();
|
|
330
340
|
try {
|
|
331
341
|
const result = await app.api(`/rooms/${encodeURIComponent(roomId)}/tasks?sessionID=${encodeURIComponent(LS.sessionID)}`);
|
|
342
|
+
await waitForRefresh(started);
|
|
332
343
|
if (request !== generation || !currentRoom(roomId))
|
|
333
344
|
return;
|
|
334
345
|
failed = false;
|
|
346
|
+
// A retry clears an earlier error at the same moment the rows swap.
|
|
347
|
+
hideError();
|
|
335
348
|
const payload = isRecord(result) ? result : {};
|
|
336
349
|
items = (Array.isArray(payload.tasks) ? payload.tasks : []).filter(isTask);
|
|
337
350
|
const limit = Number(payload.limit);
|
|
@@ -339,6 +352,7 @@ export function initTasks(app) {
|
|
|
339
352
|
render();
|
|
340
353
|
}
|
|
341
354
|
catch {
|
|
355
|
+
await waitForRefresh(started);
|
|
342
356
|
if (request !== generation || !currentRoom(roomId))
|
|
343
357
|
return;
|
|
344
358
|
failed = true;
|
|
@@ -393,6 +407,7 @@ export function initTasks(app) {
|
|
|
393
407
|
fillAssignees(app, assigneeSelect, "");
|
|
394
408
|
fillPeople(app, createPeople, []);
|
|
395
409
|
createSteps.reset();
|
|
410
|
+
createBaseline = formState(createForm);
|
|
396
411
|
};
|
|
397
412
|
const show = () => {
|
|
398
413
|
if (app.panelPlacement("tasks") === "pane") {
|
|
@@ -615,21 +630,28 @@ export function initTasks(app) {
|
|
|
615
630
|
}
|
|
616
631
|
});
|
|
617
632
|
$("#btnCloseTaskEdit")?.addEventListener("click", () => closeEdit(true));
|
|
633
|
+
// A backdrop click closes only a clean board or editor; a draft waits for the
|
|
634
|
+
// user's own close control, and a save in flight always holds.
|
|
635
|
+
closeOnBackdrop(dialog, () => {
|
|
636
|
+
if (dialog.classList.contains("is-pane") || editDialog.open || formState(createForm) !== createBaseline)
|
|
637
|
+
return;
|
|
638
|
+
close();
|
|
639
|
+
});
|
|
640
|
+
closeOnBackdrop(editDialog, () => {
|
|
641
|
+
const save = editBody.querySelector('button[type="submit"]');
|
|
642
|
+
if (save?.disabled || formState(editBody) !== editBaseline)
|
|
643
|
+
return;
|
|
644
|
+
closeEdit(true);
|
|
645
|
+
});
|
|
618
646
|
editDialog.addEventListener("cancel", (event) => { event.preventDefault(); closeEdit(true); });
|
|
619
647
|
dialog.addEventListener("cancel", (event) => { event.preventDefault(); close(); });
|
|
648
|
+
// The board's menu is a popup, so Escape closes it; the docked board itself stays.
|
|
620
649
|
document.addEventListener("keydown", (event) => {
|
|
621
|
-
if (event.key !== "Escape" || event.altKey)
|
|
622
|
-
return;
|
|
623
|
-
if (!menu.hidden) {
|
|
624
|
-
event.preventDefault();
|
|
625
|
-
setMenu(false);
|
|
626
|
-
menuButton.focus();
|
|
627
|
-
return;
|
|
628
|
-
}
|
|
629
|
-
if (!dialog.open || !dialog.classList.contains("is-pane") || !dialog.contains(document.activeElement))
|
|
650
|
+
if (event.key !== "Escape" || event.altKey || menu.hidden)
|
|
630
651
|
return;
|
|
631
652
|
event.preventDefault();
|
|
632
|
-
|
|
653
|
+
setMenu(false);
|
|
654
|
+
menuButton.focus();
|
|
633
655
|
});
|
|
634
656
|
document.addEventListener("chat-room-activated", () => {
|
|
635
657
|
closeEdit(false);
|