@alexsun-top/opencode-chat-room 0.8.3 → 0.8.4
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 +3 -1
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/package.json +6 -3
- package/server/assets/chat/admin-badge.js +1 -1
- package/server/assets/chat/admin.js +12 -9
- package/server/assets/chat/announcements.js +9 -2
- package/server/assets/chat/attachment-store.js +15 -6
- package/server/assets/chat/attachments.js +46 -31
- package/server/assets/chat/chat-background.js +8 -14
- package/server/assets/chat/clipboard.js +2 -1
- package/server/assets/chat/confirm-dialog.js +3 -3
- package/server/assets/chat/copy-action.js +0 -1
- package/server/assets/chat/diagram-viewer.js +7 -9
- package/server/assets/chat/doc-preview.js +18 -11
- package/server/assets/chat/editor.js +80 -58
- package/server/assets/chat/events.js +43 -30
- package/server/assets/chat/files.js +41 -13
- package/server/assets/chat/history-loader.js +5 -3
- package/server/assets/chat/image-zoom.js +21 -17
- package/server/assets/chat/install-prompt.js +10 -9
- package/server/assets/chat/integration-account-schema.js +5 -3
- package/server/assets/chat/integration-editor.js +0 -2
- package/server/assets/chat/integration-values.js +17 -11
- package/server/assets/chat/integrations.js +137 -80
- package/server/assets/chat/join-requests.js +19 -12
- package/server/assets/chat/markdown-footnotes.js +0 -1
- package/server/assets/chat/markdown.js +43 -34
- package/server/assets/chat/members.js +45 -22
- package/server/assets/chat/mentions.js +31 -7
- package/server/assets/chat/message-cache.js +1 -1
- package/server/assets/chat/message-polling.js +38 -19
- package/server/assets/chat/message-window.js +9 -5
- package/server/assets/chat/messages.js +53 -43
- package/server/assets/chat/palette.js +40 -26
- package/server/assets/chat/panels.js +0 -1
- package/server/assets/chat/pwa.js +5 -4
- package/server/assets/chat/questions.js +22 -20
- package/server/assets/chat/recall.js +39 -21
- package/server/assets/chat/receipts.js +9 -7
- package/server/assets/chat/reminders.js +22 -8
- package/server/assets/chat/replies.js +28 -12
- package/server/assets/chat/room-list.js +2 -2
- package/server/assets/chat/room-watcher.js +8 -4
- package/server/assets/chat/rooms.js +44 -36
- package/server/assets/chat/search.js +8 -6
- package/server/assets/chat/settings.js +12 -11
- package/server/assets/chat/shiki.js +1 -1
- package/server/assets/chat/shortcuts.js +0 -2
- package/server/assets/chat/side-pane.js +3 -2
- package/server/assets/chat/state.js +35 -26
- package/server/assets/chat/system-events.js +4 -4
- package/server/assets/chat/task-form.js +5 -5
- package/server/assets/chat/task-row.js +1 -1
- package/server/assets/chat/tasks.js +37 -25
- package/server/chat.html +1 -0
|
@@ -5,8 +5,11 @@ import { watchRoom } from "./room-watcher.js";
|
|
|
5
5
|
import { cacheRoomSoon, deleteCachedRoom, loadCachedRooms } from "./message-cache.js";
|
|
6
6
|
import { renderRoomOptions } from "./room-list.js";
|
|
7
7
|
import { initPanels } from "./panels.js";
|
|
8
|
+
const statusOf = (error) => error instanceof Error && "status" in error ? error.status : undefined;
|
|
9
|
+
const messageOf = (error) => error instanceof Error ? error.message : "";
|
|
10
|
+
const isNetworkError = (error) => error instanceof Error && "network" in error && Boolean(error.network);
|
|
8
11
|
export function initRooms(app) {
|
|
9
|
-
const $ = app
|
|
12
|
+
const $ = (selector) => app.$(selector);
|
|
10
13
|
initPanels(app);
|
|
11
14
|
let roomListGeneration = 0;
|
|
12
15
|
let autoRefresh;
|
|
@@ -50,20 +53,23 @@ export function initRooms(app) {
|
|
|
50
53
|
$("#chatView").hidden = false;
|
|
51
54
|
};
|
|
52
55
|
app.renderHead = () => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
const room = app.state.room;
|
|
57
|
+
if (!room)
|
|
58
|
+
return;
|
|
59
|
+
$("#roomName").textContent = room.name;
|
|
60
|
+
$("#roomIdShort").textContent = room.id.slice(0, 8);
|
|
61
|
+
$("#btnCopyId").title = app.t("copyRoomIdTitle", { id: room.id });
|
|
56
62
|
$("#btnCopyId").setAttribute("aria-label", app.t("copyRoomId"));
|
|
57
63
|
$("#railIdentity").textContent = app.state.myName;
|
|
58
64
|
$("#profileAvatar").textContent = Array.from(app.state.myName.trim())[0]?.toLocaleUpperCase() || "?";
|
|
59
|
-
const description =
|
|
65
|
+
const description = room.description || "";
|
|
60
66
|
$("#roomDescription").textContent = description;
|
|
61
67
|
$("#roomDescription").hidden = !description;
|
|
62
|
-
$("#roomPolicy").hidden =
|
|
68
|
+
$("#roomPolicy").hidden = room.joinPolicy !== "approval";
|
|
63
69
|
// Everyone sees the settings entry; people who cannot manage the room get a
|
|
64
70
|
// secondary style and an explanation. Dissolving the room stays the owner's call.
|
|
65
|
-
const owner = app.state.myName ===
|
|
66
|
-
const admin = owner || (
|
|
71
|
+
const owner = app.state.myName === room.ownerId;
|
|
72
|
+
const admin = owner || (room.adminIds ?? []).includes(app.state.myName);
|
|
67
73
|
$("#btnEditRoom").classList.toggle("menu-secondary", !admin);
|
|
68
74
|
$("#btnDeleteRoom").hidden = !owner;
|
|
69
75
|
app.updateTitle();
|
|
@@ -84,7 +90,7 @@ export function initRooms(app) {
|
|
|
84
90
|
};
|
|
85
91
|
app.ensureJoinedRoom = (room, name) => {
|
|
86
92
|
const existing = app.state.rooms.get(room.id);
|
|
87
|
-
const entry = existing || { unreadIds: new Map(), unreadOverflow: false, preview: "", previewAt: 0, position: 0, readTs: 0, receivedTs: room.messages.at(-1)?.createdAt ?? 0, recallVersion: 0 };
|
|
93
|
+
const entry = existing || { room, name, unreadIds: new Map(), unreadOverflow: false, preview: "", previewAt: 0, position: 0, readTs: 0, receivedTs: room.messages.at(-1)?.createdAt ?? 0, recallVersion: 0 };
|
|
88
94
|
entry.unreadIds ||= new Map();
|
|
89
95
|
entry.unreadOverflow ||= false;
|
|
90
96
|
const latest = room.messages.at(-1), savedReadTs = app.state.lastReadTs.get(room.id) ?? (typeof room.lastReadTs === "number" ? room.lastReadTs : undefined);
|
|
@@ -155,7 +161,7 @@ export function initRooms(app) {
|
|
|
155
161
|
// Cached history can hold thousands of messages. Render the newest window
|
|
156
162
|
// first so switching stays immediate; older rows are prepended on demand.
|
|
157
163
|
app.renderMessages(false, 300);
|
|
158
|
-
app.restoreReadingPosition?.(
|
|
164
|
+
app.restoreReadingPosition?.();
|
|
159
165
|
app.state.readAnchorGuard = null;
|
|
160
166
|
app.startPolling();
|
|
161
167
|
if (entry.recallStale) {
|
|
@@ -168,8 +174,8 @@ export function initRooms(app) {
|
|
|
168
174
|
$("#msgInput").tabIndex = 0;
|
|
169
175
|
$("#msgInput").draftValue = app.state.drafts.get(roomId) || "";
|
|
170
176
|
app.renderReplyPreview?.();
|
|
171
|
-
app.renderFailedMessages();
|
|
172
|
-
app.autoGrow($("#msgInput"));
|
|
177
|
+
app.renderFailedMessages?.();
|
|
178
|
+
app.autoGrow?.($("#msgInput"));
|
|
173
179
|
// A restored draft and late layout can resize the composer after the initial bottom
|
|
174
180
|
// pin. Keep following for a few frames instead of sampling one fragile moment.
|
|
175
181
|
let settleFrames = 0;
|
|
@@ -183,8 +189,8 @@ export function initRooms(app) {
|
|
|
183
189
|
requestAnimationFrame(settleBottom);
|
|
184
190
|
};
|
|
185
191
|
requestAnimationFrame(settleBottom);
|
|
186
|
-
app.updateDraftCount();
|
|
187
|
-
app.updateSendState();
|
|
192
|
+
app.updateDraftCount?.();
|
|
193
|
+
app.updateSendState?.();
|
|
188
194
|
app.hideSendError();
|
|
189
195
|
app.updateBadge();
|
|
190
196
|
app.updateJump();
|
|
@@ -219,7 +225,7 @@ export function initRooms(app) {
|
|
|
219
225
|
app.enterRoom(room, name, intent);
|
|
220
226
|
}
|
|
221
227
|
catch (error) {
|
|
222
|
-
if (error
|
|
228
|
+
if (statusOf(error) === 401) {
|
|
223
229
|
app.state.pendingAction = { type: "join", roomId, name };
|
|
224
230
|
if (app.state.room) {
|
|
225
231
|
app.openChatSettings();
|
|
@@ -230,12 +236,12 @@ export function initRooms(app) {
|
|
|
230
236
|
app.showJoinError("authRetry");
|
|
231
237
|
}
|
|
232
238
|
}
|
|
233
|
-
else if (error
|
|
239
|
+
else if (statusOf(error) === 409) {
|
|
234
240
|
app.showJoinError("joinNameTaken");
|
|
235
241
|
void app.refreshRoomList();
|
|
236
242
|
}
|
|
237
243
|
else {
|
|
238
|
-
app.showJoinError(error
|
|
244
|
+
app.showJoinError(isNetworkError(error) ? "networkRetry" : "joinFailed", { message: messageOf(error) });
|
|
239
245
|
void app.refreshRoomList();
|
|
240
246
|
}
|
|
241
247
|
}
|
|
@@ -246,10 +252,11 @@ export function initRooms(app) {
|
|
|
246
252
|
app.createRoom = async (pending) => {
|
|
247
253
|
if (app.state.joinBusy)
|
|
248
254
|
return;
|
|
249
|
-
const
|
|
250
|
-
const
|
|
251
|
-
const
|
|
252
|
-
const
|
|
255
|
+
const action = pending;
|
|
256
|
+
const fromChat = action?.fromChat ?? Boolean(app.state.room);
|
|
257
|
+
const name = action?.name || (fromChat ? app.state.myName : $("#inName").value.trim()) || LS.name || app.t("guest");
|
|
258
|
+
const roomName = action?.roomName || $(fromChat ? "#inRoomNameChat" : "#inRoomName").value.trim();
|
|
259
|
+
const joinPolicy = action?.joinPolicy ?? ((fromChat ? $("#inApprovalRequiredChat").checked : $("#inApprovalRequired").checked) ? "approval" : "open");
|
|
253
260
|
if (!roomName) {
|
|
254
261
|
if (!fromChat)
|
|
255
262
|
return app.showJoinError("roomNameRequired");
|
|
@@ -282,7 +289,7 @@ export function initRooms(app) {
|
|
|
282
289
|
app.enterRoom(room, name, intent);
|
|
283
290
|
}
|
|
284
291
|
catch (error) {
|
|
285
|
-
if (error
|
|
292
|
+
if (statusOf(error) === 401) {
|
|
286
293
|
app.state.pendingAction = { type: "create", name, roomName, fromChat, joinPolicy };
|
|
287
294
|
if (fromChat) {
|
|
288
295
|
app.closeCreateRoomDialog(false);
|
|
@@ -296,13 +303,13 @@ export function initRooms(app) {
|
|
|
296
303
|
}
|
|
297
304
|
else if (fromChat) {
|
|
298
305
|
if ($("#createRoomDialog")?.open)
|
|
299
|
-
app.showCreateRoomError("createFailed", { message: error
|
|
306
|
+
app.showCreateRoomError("createFailed", { message: messageOf(error) });
|
|
300
307
|
else
|
|
301
|
-
app.showSendError("createFailed", { message: error
|
|
308
|
+
app.showSendError("createFailed", { message: messageOf(error) });
|
|
302
309
|
void app.refreshRoomList();
|
|
303
310
|
}
|
|
304
311
|
else {
|
|
305
|
-
app.showJoinError("createFailed", { message: error
|
|
312
|
+
app.showJoinError("createFailed", { message: messageOf(error) });
|
|
306
313
|
void app.refreshRoomList();
|
|
307
314
|
}
|
|
308
315
|
}
|
|
@@ -436,7 +443,7 @@ export function initRooms(app) {
|
|
|
436
443
|
catch (error) {
|
|
437
444
|
if (generation !== roomListGeneration)
|
|
438
445
|
return;
|
|
439
|
-
if (error
|
|
446
|
+
if (statusOf(error) === 401) {
|
|
440
447
|
if (!app.state.room && !app.state.restored) {
|
|
441
448
|
app.showJoin(false);
|
|
442
449
|
app.openTokenBox();
|
|
@@ -455,7 +462,7 @@ export function initRooms(app) {
|
|
|
455
462
|
}
|
|
456
463
|
if (!app.state.restored) {
|
|
457
464
|
app.state.restoreRetry = true;
|
|
458
|
-
app.state.restorePending = new Set([...app.state.joinedIds, LS.roomId].filter(Boolean));
|
|
465
|
+
app.state.restorePending = new Set([...app.state.joinedIds, LS.roomId].filter((id) => Boolean(id)));
|
|
459
466
|
app.startRoomWatcher();
|
|
460
467
|
}
|
|
461
468
|
}
|
|
@@ -472,7 +479,7 @@ export function initRooms(app) {
|
|
|
472
479
|
try {
|
|
473
480
|
const activeId = LS.roomId;
|
|
474
481
|
const directIds = rooms.filter((room) => room.kind === "direct" && room.directSessionIDs?.includes(LS.sessionID)).map((room) => room.id);
|
|
475
|
-
const candidates = [...new Set([activeId, ...rooms.filter((room) => room.joined).map((room) => room.id), ...app.state.joinedIds, ...directIds].filter(Boolean))];
|
|
482
|
+
const candidates = [...new Set([activeId, ...rooms.filter((room) => room.joined).map((room) => room.id), ...app.state.joinedIds, ...directIds].filter((id) => Boolean(id)))];
|
|
476
483
|
const valid = new Set();
|
|
477
484
|
const unresolved = new Set();
|
|
478
485
|
let authFailed = false;
|
|
@@ -495,11 +502,11 @@ export function initRooms(app) {
|
|
|
495
502
|
catch (error) {
|
|
496
503
|
if (generation !== roomListGeneration)
|
|
497
504
|
return;
|
|
498
|
-
if (error
|
|
505
|
+
if (statusOf(error) !== 404) {
|
|
499
506
|
unresolved.add(roomId);
|
|
500
|
-
if (error
|
|
507
|
+
if (statusOf(error) === 401)
|
|
501
508
|
authFailed = true;
|
|
502
|
-
if (error
|
|
509
|
+
if (statusOf(error) === 401)
|
|
503
510
|
app.state.room ? app.openChatSettings() : app.openTokenBox();
|
|
504
511
|
}
|
|
505
512
|
}
|
|
@@ -553,13 +560,13 @@ export function initRooms(app) {
|
|
|
553
560
|
catch (error) {
|
|
554
561
|
if (generation !== roomListGeneration)
|
|
555
562
|
return;
|
|
556
|
-
if (error
|
|
563
|
+
if (statusOf(error) !== 404) {
|
|
557
564
|
app.state.restorePending ||= new Set();
|
|
558
565
|
app.state.restorePending.add(room.id);
|
|
559
566
|
app.state.joinedIds.add(room.id);
|
|
560
567
|
app.saveJoinedIds();
|
|
561
568
|
app.state.restored = false;
|
|
562
|
-
if (error
|
|
569
|
+
if (statusOf(error) === 401)
|
|
563
570
|
app.state.room ? app.openChatSettings() : app.openTokenBox();
|
|
564
571
|
}
|
|
565
572
|
}
|
|
@@ -584,13 +591,14 @@ export function initRooms(app) {
|
|
|
584
591
|
app.saveFailedMessages(room.id, []);
|
|
585
592
|
}
|
|
586
593
|
catch (error) {
|
|
587
|
-
app.showSendError("sendFailed", { message: error
|
|
594
|
+
app.showSendError("sendFailed", { message: messageOf(error) });
|
|
588
595
|
}
|
|
589
596
|
};
|
|
590
597
|
app.copyRoomId = async () => {
|
|
591
598
|
const button = $("#btnCopyId");
|
|
599
|
+
const roomId = app.state.room.id;
|
|
592
600
|
try {
|
|
593
|
-
await navigator.clipboard.writeText(
|
|
601
|
+
await navigator.clipboard.writeText(roomId);
|
|
594
602
|
// Swap a class so the ID span survives; flash() would overwrite the whole
|
|
595
603
|
// button and then restore it to "undefined" (the button has no data-i18n).
|
|
596
604
|
clearTimeout(button._copiedTimer);
|
|
@@ -598,7 +606,7 @@ export function initRooms(app) {
|
|
|
598
606
|
button._copiedTimer = setTimeout(() => button.classList.remove("copied"), 1200);
|
|
599
607
|
}
|
|
600
608
|
catch {
|
|
601
|
-
app.showSendError("copyFailed", { id:
|
|
609
|
+
app.showSendError("copyFailed", { id: roomId });
|
|
602
610
|
}
|
|
603
611
|
};
|
|
604
612
|
app.autoJoin = async () => {
|
|
@@ -6,6 +6,7 @@ export const SEARCH_RESULT_LIMIT = 100;
|
|
|
6
6
|
export const SEARCH_MESSAGE_LIMIT = LOADED_MESSAGE_LIMIT;
|
|
7
7
|
const PAGE_LIMIT = 100;
|
|
8
8
|
const MAX_PAGES_PER_ROOM = Math.ceil(SEARCH_MESSAGE_LIMIT / PAGE_LIMIT);
|
|
9
|
+
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
9
10
|
export function initSearch(app) {
|
|
10
11
|
app.searchMessages = (query, scope = "room") => searchMessages(app, query, scope);
|
|
11
12
|
app.openSearchHit = (hit) => openSearchHit(app, hit);
|
|
@@ -48,14 +49,14 @@ export async function openSearchHit(app, hit) {
|
|
|
48
49
|
return false;
|
|
49
50
|
try {
|
|
50
51
|
const page = await app.api(`/rooms/${encodeURIComponent(roomId)}/history?beforeSeq=${seq + 1}&limit=${PAGE_LIMIT}`);
|
|
51
|
-
if (app.state.rooms.get(roomId) !== entry)
|
|
52
|
+
if (app.state.rooms.get(roomId) !== entry || !isRecord(page))
|
|
52
53
|
return false;
|
|
53
54
|
const messages = Array.isArray(page.messages) ? page.messages : [];
|
|
54
55
|
mergeHistory(entry, roomId, messages);
|
|
55
56
|
if (page.hasMore) {
|
|
56
57
|
// Continue upward pagination from the oldest message now loaded.
|
|
57
58
|
const oldest = entry.room.messages.find((message) => Number.isSafeInteger(message.seq))?.seq;
|
|
58
|
-
if (Number.isSafeInteger(oldest))
|
|
59
|
+
if (typeof oldest === "number" && Number.isSafeInteger(oldest))
|
|
59
60
|
entry.historyBeforeSeq = oldest;
|
|
60
61
|
}
|
|
61
62
|
else {
|
|
@@ -80,7 +81,7 @@ export async function openSearchHit(app, hit) {
|
|
|
80
81
|
app.state.readAnchorGuard = null;
|
|
81
82
|
app.renderMessages(false);
|
|
82
83
|
const row = document.querySelector(`[data-msg-id="${CSS.escape(messageId)}"]`);
|
|
83
|
-
if (!row)
|
|
84
|
+
if (!(row instanceof HTMLElement))
|
|
84
85
|
return false;
|
|
85
86
|
flashMessageRow(app, row);
|
|
86
87
|
return true;
|
|
@@ -117,8 +118,9 @@ async function collectRoomHits(app, roomId, needle, hits) {
|
|
|
117
118
|
while (!entry.historyComplete && Number.isSafeInteger(entry.historyBeforeSeq)
|
|
118
119
|
&& entry.room.messages.length < SEARCH_MESSAGE_LIMIT && pages++ < MAX_PAGES_PER_ROOM) {
|
|
119
120
|
try {
|
|
120
|
-
const
|
|
121
|
-
|
|
121
|
+
const beforeSeq = typeof entry.historyBeforeSeq === "number" ? entry.historyBeforeSeq : 0;
|
|
122
|
+
const page = await app.api(`/rooms/${encodeURIComponent(roomId)}/history?beforeSeq=${beforeSeq}&limit=${PAGE_LIMIT}`);
|
|
123
|
+
if (app.state.rooms.get(roomId) !== entry || !isRecord(page))
|
|
122
124
|
return;
|
|
123
125
|
const messages = Array.isArray(page.messages) ? page.messages : [];
|
|
124
126
|
scan(messages);
|
|
@@ -127,7 +129,7 @@ async function collectRoomHits(app, roomId, needle, hits) {
|
|
|
127
129
|
entry.historyComplete = !page.hasMore;
|
|
128
130
|
if (entry.historyComplete)
|
|
129
131
|
entry.historyBeforeSeq = null;
|
|
130
|
-
else if (next === null || next >=
|
|
132
|
+
else if (next === null || next >= beforeSeq)
|
|
131
133
|
break;
|
|
132
134
|
else
|
|
133
135
|
entry.historyBeforeSeq = next;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
// Browser settings shared by the join page and the chat: language, theme, window frame, and the optional token.
|
|
2
1
|
export const THEMES = ["system", "light", "dark", "forest", "sand", "custom"];
|
|
3
2
|
const DEFAULT_CUSTOM_THEME = "#22695c";
|
|
4
3
|
const validColor = (value) => /^#[0-9a-f]{6}$/i.test(value) ? value : DEFAULT_CUSTOM_THEME;
|
|
5
4
|
// Relative luminance, so a dark choice gets the dark palette instead of dark text on it.
|
|
6
5
|
const isDarkColor = (color) => {
|
|
7
|
-
const channels = color.slice(1).match(/../g).map((part) => {
|
|
6
|
+
const channels = (color.slice(1).match(/../g) || []).map((part) => {
|
|
8
7
|
const value = parseInt(part, 16) / 255;
|
|
9
8
|
return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
10
9
|
});
|
|
@@ -16,6 +15,8 @@ export function initSettings(app) {
|
|
|
16
15
|
if (!dialog)
|
|
17
16
|
return;
|
|
18
17
|
const tokenInput = $("#inTokenChat"), tokenHint = $("#tokenHint");
|
|
18
|
+
if (!tokenInput)
|
|
19
|
+
return;
|
|
19
20
|
const contentInput = $("#inContentTransition");
|
|
20
21
|
const pageInput = $("#inPageStep"), pageValue = $("#pageStepValue");
|
|
21
22
|
const frameSelect = $("#inWindowFrame");
|
|
@@ -88,7 +89,7 @@ export function initSettings(app) {
|
|
|
88
89
|
};
|
|
89
90
|
const syncPanelInputs = () => {
|
|
90
91
|
for (const select of panelInputs)
|
|
91
|
-
select.value = app.panelMode(select.dataset.panelMode);
|
|
92
|
+
select.value = app.panelMode(select.dataset.panelMode || "");
|
|
92
93
|
};
|
|
93
94
|
const applyTheme = (value, persist) => {
|
|
94
95
|
clearCustomSchedules();
|
|
@@ -119,7 +120,7 @@ export function initSettings(app) {
|
|
|
119
120
|
const selected = tab.dataset.settingsTab === name;
|
|
120
121
|
tab.setAttribute("aria-selected", String(selected));
|
|
121
122
|
tab.tabIndex = selected ? 0 : -1;
|
|
122
|
-
const panel = document.getElementById(tab.getAttribute("aria-controls"));
|
|
123
|
+
const panel = document.getElementById(tab.getAttribute("aria-controls") || "");
|
|
123
124
|
if (panel)
|
|
124
125
|
panel.hidden = !selected;
|
|
125
126
|
if (selected && focus)
|
|
@@ -129,7 +130,7 @@ export function initSettings(app) {
|
|
|
129
130
|
app.loadIntegrations?.();
|
|
130
131
|
};
|
|
131
132
|
const onTabKey = (event) => {
|
|
132
|
-
const index = tabs.indexOf(event.target);
|
|
133
|
+
const index = event.target instanceof HTMLElement ? tabs.indexOf(event.target) : -1;
|
|
133
134
|
if (index < 0)
|
|
134
135
|
return;
|
|
135
136
|
const step = event.key === "ArrowUp" || event.key === "ArrowLeft" ? -1 : event.key === "ArrowDown" || event.key === "ArrowRight" ? 1 : 0;
|
|
@@ -181,7 +182,7 @@ export function initSettings(app) {
|
|
|
181
182
|
$("#btnCloseSettings")?.addEventListener("click", close);
|
|
182
183
|
dialog.addEventListener("cancel", () => opener?.setAttribute("aria-expanded", "false"));
|
|
183
184
|
pageInput?.addEventListener("input", () => {
|
|
184
|
-
app.LS.pageStep = pageInput.value;
|
|
185
|
+
app.LS.pageStep = Number(pageInput.value);
|
|
185
186
|
pageInput.value = String(app.LS.pageStep);
|
|
186
187
|
if (pageValue)
|
|
187
188
|
pageValue.textContent = `${app.LS.pageStep}%`;
|
|
@@ -202,15 +203,15 @@ export function initSettings(app) {
|
|
|
202
203
|
dialog.addEventListener("change", (event) => {
|
|
203
204
|
if (event.target instanceof HTMLInputElement && event.target.name === "theme")
|
|
204
205
|
app.setTheme(event.target.value);
|
|
205
|
-
if (event.target === frameSelect)
|
|
206
|
-
app.setWindowFrame(frameSelect.value);
|
|
206
|
+
if (frameSelect && event.target === frameSelect)
|
|
207
|
+
app.setWindowFrame(frameSelect.value === "borderless" ? "borderless" : "framed");
|
|
207
208
|
if (event.target instanceof HTMLSelectElement && event.target.dataset.panelMode) {
|
|
208
209
|
app.setPanelMode(event.target.dataset.panelMode, event.target.value);
|
|
209
210
|
}
|
|
210
|
-
if (event.target === contentInput)
|
|
211
|
+
if (contentInput && event.target === contentInput)
|
|
211
212
|
app.LS.contentTransition = contentInput.checked;
|
|
212
|
-
if (event.target === pageInput) {
|
|
213
|
-
app.LS.pageStep = pageInput.value;
|
|
213
|
+
if (pageInput && event.target === pageInput) {
|
|
214
|
+
app.LS.pageStep = Number(pageInput.value);
|
|
214
215
|
pageInput.value = String(app.LS.pageStep);
|
|
215
216
|
if (pageValue)
|
|
216
217
|
pageValue.textContent = `${app.LS.pageStep}%`;
|
|
@@ -128,9 +128,10 @@ export function initSidePaneSplitter(app) {
|
|
|
128
128
|
handle.addEventListener("pointerup", endDrag);
|
|
129
129
|
handle.addEventListener("pointercancel", endDrag);
|
|
130
130
|
handle.addEventListener("keydown", (event) => {
|
|
131
|
-
|
|
131
|
+
const pane = activePane();
|
|
132
|
+
if (!pane?.open)
|
|
132
133
|
return;
|
|
133
|
-
const current = applied ||
|
|
134
|
+
const current = applied || pane.getBoundingClientRect().width;
|
|
134
135
|
const step = event.shiftKey ? 64 : 16;
|
|
135
136
|
let next;
|
|
136
137
|
if (event.key === "ArrowRight")
|
|
@@ -20,6 +20,12 @@ export const app = {
|
|
|
20
20
|
copyTimer: 0,
|
|
21
21
|
failedRenderIds: new Set(),
|
|
22
22
|
};
|
|
23
|
+
const $ = (selector) => {
|
|
24
|
+
const element = app.$(selector);
|
|
25
|
+
if (!element)
|
|
26
|
+
throw new Error(`Missing element: ${selector}`);
|
|
27
|
+
return element;
|
|
28
|
+
};
|
|
23
29
|
// Phones and tablets lack the hardware keyboard the shortcut hint assumes.
|
|
24
30
|
// iPadOS reports a desktop Macintosh UA, so touch points identify it there.
|
|
25
31
|
export function isMobileDevice() {
|
|
@@ -53,7 +59,7 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
53
59
|
const validSessionID = (id) => typeof id === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(id);
|
|
54
60
|
const parseIdentity = (value) => {
|
|
55
61
|
try {
|
|
56
|
-
const identity = JSON.parse(value);
|
|
62
|
+
const identity = JSON.parse(value ?? "null");
|
|
57
63
|
return validSessionID(identity?.sessionID) && typeof identity.name === "string" && identity.name.length <= 64
|
|
58
64
|
? { sessionID: identity.sessionID, name: identity.name } : undefined;
|
|
59
65
|
}
|
|
@@ -103,9 +109,9 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
103
109
|
}
|
|
104
110
|
catch { /* Tab-scoped state is best effort. */ }
|
|
105
111
|
};
|
|
106
|
-
const syncTabIdentity = () => {
|
|
107
|
-
writeSession("chat.sessionID",
|
|
108
|
-
writeSession("chat.name",
|
|
112
|
+
const syncTabIdentity = (identity) => {
|
|
113
|
+
writeSession("chat.sessionID", identity.sessionID);
|
|
114
|
+
writeSession("chat.name", identity.name || null);
|
|
109
115
|
};
|
|
110
116
|
const ensureIdentity = () => {
|
|
111
117
|
if (browserIdentity)
|
|
@@ -122,7 +128,7 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
122
128
|
clearMediaCache();
|
|
123
129
|
void postMediaIdentity();
|
|
124
130
|
}
|
|
125
|
-
syncTabIdentity();
|
|
131
|
+
syncTabIdentity(canonical);
|
|
126
132
|
return canonical;
|
|
127
133
|
}
|
|
128
134
|
}
|
|
@@ -132,7 +138,7 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
132
138
|
clearMediaCache();
|
|
133
139
|
void postMediaIdentity();
|
|
134
140
|
}
|
|
135
|
-
syncTabIdentity();
|
|
141
|
+
syncTabIdentity(browserIdentity);
|
|
136
142
|
try {
|
|
137
143
|
store ||= storage ?? globalThis.localStorage;
|
|
138
144
|
store.setItem(identityKey, JSON.stringify(browserIdentity));
|
|
@@ -153,12 +159,12 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
153
159
|
return error;
|
|
154
160
|
};
|
|
155
161
|
const assertIdentity = () => {
|
|
156
|
-
ensureIdentity();
|
|
162
|
+
const identity = ensureIdentity();
|
|
157
163
|
if (identityConflict)
|
|
158
164
|
throw identityError();
|
|
159
165
|
try {
|
|
160
166
|
const current = parseIdentity((storage ?? globalThis.localStorage).getItem(identityKey));
|
|
161
|
-
if (current && current.sessionID !==
|
|
167
|
+
if (current && current.sessionID !== identity.sessionID || identityPersistent && !current) {
|
|
162
168
|
identityConflict = true;
|
|
163
169
|
throw identityError();
|
|
164
170
|
}
|
|
@@ -166,23 +172,24 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
166
172
|
identityPersistent = true;
|
|
167
173
|
}
|
|
168
174
|
catch (error) {
|
|
169
|
-
if (error
|
|
175
|
+
if (error instanceof Error && "identityConflict" in error && error.identityConflict)
|
|
170
176
|
throw error;
|
|
171
177
|
identityPersistent = false;
|
|
172
178
|
}
|
|
173
179
|
};
|
|
174
180
|
const saveIdentity = () => {
|
|
175
|
-
if (!identityPersistent)
|
|
181
|
+
if (!identityPersistent || !browserIdentity)
|
|
176
182
|
return;
|
|
183
|
+
const identity = browserIdentity;
|
|
177
184
|
try {
|
|
178
185
|
const store = storage ?? globalThis.localStorage;
|
|
179
186
|
const current = parseIdentity(store.getItem(identityKey));
|
|
180
|
-
if (current?.sessionID !==
|
|
187
|
+
if (current?.sessionID !== identity.sessionID) {
|
|
181
188
|
identityConflict = true;
|
|
182
189
|
return;
|
|
183
190
|
}
|
|
184
|
-
store.setItem(identityKey, JSON.stringify(
|
|
185
|
-
if (parseIdentity(store.getItem(identityKey))?.sessionID !==
|
|
191
|
+
store.setItem(identityKey, JSON.stringify(identity));
|
|
192
|
+
if (parseIdentity(store.getItem(identityKey))?.sessionID !== identity.sessionID)
|
|
186
193
|
identityConflict = true;
|
|
187
194
|
}
|
|
188
195
|
catch { /* Keep the preferred name in memory when persistence is blocked. */ }
|
|
@@ -202,7 +209,7 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
202
209
|
},
|
|
203
210
|
set roomId(value) { writeSession("chat.roomId", value || null); write("chat.roomId", null); },
|
|
204
211
|
get name() { return ensureIdentity().name; },
|
|
205
|
-
set name(value) { ensureIdentity();
|
|
212
|
+
set name(value) { const identity = ensureIdentity(); identity.name = String(value ?? "").slice(0, 64); writeSession("chat.name", identity.name || null); saveIdentity(); },
|
|
206
213
|
get token() { return read("chat.token") || ""; }, set token(value) { write("chat.token", value || null); },
|
|
207
214
|
get locale() { return read("chat.locale") || "en"; }, set locale(value) { write("chat.locale", value || null); },
|
|
208
215
|
get theme() { return read("chat.theme") || "system"; }, set theme(value) { write("chat.theme", value || null); },
|
|
@@ -748,7 +755,7 @@ for (const dictionary of Object.values(messages)) {
|
|
|
748
755
|
app.t = (key, values = {}) => {
|
|
749
756
|
const entry = messages[app.locale][key] ?? messages.en[key] ?? key;
|
|
750
757
|
const text = typeof entry === "function" ? entry(values) : entry;
|
|
751
|
-
return String(text).replace(/\{(\w+)\}/g, (_, name) => values[name] ?? "");
|
|
758
|
+
return String(text).replace(/\{(\w+)\}/g, (_, name) => String(values[name] ?? ""));
|
|
752
759
|
};
|
|
753
760
|
export const { LS, saveToken, api, apiBlob } = createAuth(undefined, undefined, (key, values) => app.t(key, values));
|
|
754
761
|
app.LS = LS;
|
|
@@ -820,7 +827,7 @@ app.applyLocale = () => {
|
|
|
820
827
|
document.querySelectorAll("[data-i18n]").forEach((element) => {
|
|
821
828
|
const text = element._flashKey
|
|
822
829
|
? app.t(element._flashKey)
|
|
823
|
-
: app.t(element.dataset.i18n, element._i18nValues || {});
|
|
830
|
+
: app.t(element.dataset.i18n ?? "", element._i18nValues || {});
|
|
824
831
|
// Controls with icons keep the graphic and swap only the text label.
|
|
825
832
|
const label = element.querySelector(":scope > .i18n-label");
|
|
826
833
|
if (label)
|
|
@@ -830,11 +837,13 @@ app.applyLocale = () => {
|
|
|
830
837
|
});
|
|
831
838
|
for (const attribute of ["aria-label", "aria-placeholder", "title", "placeholder"]) {
|
|
832
839
|
document.querySelectorAll(`[data-i18n-${attribute}]`).forEach((element) => {
|
|
833
|
-
element.setAttribute(attribute, app.t(element.getAttribute(`data-i18n-${attribute}`), element._i18nValues || {}));
|
|
840
|
+
element.setAttribute(attribute, app.t(element.getAttribute(`data-i18n-${attribute}`) ?? "", element._i18nValues || {}));
|
|
834
841
|
});
|
|
835
842
|
}
|
|
836
843
|
document.querySelectorAll(".locale-select").forEach((select) => { select.value = app.locale; });
|
|
837
|
-
app
|
|
844
|
+
const msgInput = app.$("#msgInput");
|
|
845
|
+
if (msgInput)
|
|
846
|
+
app.autoGrow?.(msgInput);
|
|
838
847
|
app.updateDraftCount?.();
|
|
839
848
|
app.updateMentionList?.();
|
|
840
849
|
app.renderFailedMessages?.();
|
|
@@ -890,13 +899,13 @@ app.flash = (button, key) => {
|
|
|
890
899
|
if (output) {
|
|
891
900
|
delete output._flashKey;
|
|
892
901
|
output.hidden = true;
|
|
893
|
-
output.textContent = app.t(output.dataset.i18n, output._i18nValues || {});
|
|
902
|
+
output.textContent = app.t(output.dataset.i18n ?? "", output._i18nValues || {});
|
|
894
903
|
button.classList.remove("is-flashing");
|
|
895
904
|
if (button.dataset.i18nAriaLabel)
|
|
896
905
|
button.setAttribute("aria-label", app.t(button.dataset.i18nAriaLabel));
|
|
897
906
|
}
|
|
898
907
|
else
|
|
899
|
-
button.textContent = app.t(button.dataset.i18n, button._i18nValues || {});
|
|
908
|
+
button.textContent = app.t(button.dataset.i18n ?? "", button._i18nValues || {});
|
|
900
909
|
}, 1200);
|
|
901
910
|
};
|
|
902
911
|
app.updateTitle = () => {
|
|
@@ -908,27 +917,27 @@ app.updateTitle = () => {
|
|
|
908
917
|
document.title = total ? `(${total}) ${title}` : title;
|
|
909
918
|
};
|
|
910
919
|
app.setOnline = (online) => {
|
|
911
|
-
|
|
920
|
+
$("#connBar").hidden = online;
|
|
912
921
|
// A recovered connection makes the network send warning stale, but an auth
|
|
913
922
|
// or validation error still needs the user's attention.
|
|
914
923
|
if (online)
|
|
915
924
|
app.hideSendError("sendNetwork");
|
|
916
925
|
};
|
|
917
926
|
app.showSendError = (key, values = {}) => {
|
|
918
|
-
const node =
|
|
927
|
+
const node = $("#sendError");
|
|
919
928
|
app.setText(node, key, values);
|
|
920
929
|
node.dataset.errorKey = key;
|
|
921
930
|
node.hidden = false;
|
|
922
931
|
};
|
|
923
932
|
app.hideSendError = (key) => {
|
|
924
|
-
const node =
|
|
933
|
+
const node = $("#sendError");
|
|
925
934
|
if (key && node.dataset.errorKey !== key)
|
|
926
935
|
return;
|
|
927
936
|
node.hidden = true;
|
|
928
937
|
delete node.dataset.errorKey;
|
|
929
938
|
};
|
|
930
939
|
app.showJoinError = (key, values = {}) => {
|
|
931
|
-
app.setText(
|
|
932
|
-
|
|
940
|
+
app.setText($("#joinError"), key, values);
|
|
941
|
+
$("#joinError").hidden = false;
|
|
933
942
|
};
|
|
934
|
-
app.hideJoinError = () => {
|
|
943
|
+
app.hideJoinError = () => { $("#joinError").hidden = true; };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// Room notices are inline events: a small icon, a tinted chip, and the time.
|
|
2
1
|
import { iconNode } from "./icons.js";
|
|
3
2
|
import { formatRelayMessage, formatSystemMessage, systemMessageKind } from "./system-messages.js";
|
|
4
3
|
import { renderMarkdown, renderResourceText } from "./markdown.js";
|
|
@@ -35,15 +34,16 @@ function bindNoticeResize() {
|
|
|
35
34
|
}
|
|
36
35
|
export function renderSystemRow(row, message, app) {
|
|
37
36
|
row.className = "sys";
|
|
38
|
-
|
|
37
|
+
const kind = systemMessageKind(message);
|
|
38
|
+
row.dataset.kind = kind;
|
|
39
39
|
const event = document.createElement("span"), mark = document.createElement("span");
|
|
40
40
|
const text = document.createElement("span"), time = document.createElement("time");
|
|
41
41
|
event.className = "sys-event";
|
|
42
42
|
event.setAttribute("role", "note");
|
|
43
43
|
mark.className = "sys-icon";
|
|
44
|
-
mark.append(iconNode(icons[
|
|
44
|
+
mark.append(iconNode(icons[kind] || icons.notice, "sys-icon-glyph"));
|
|
45
45
|
text.className = "sys-text";
|
|
46
|
-
if (
|
|
46
|
+
if (kind === "relay")
|
|
47
47
|
renderResourceText(text, formatRelayMessage(message, app), app);
|
|
48
48
|
else
|
|
49
49
|
renderMarkdown(text, formatSystemMessage(message, app), app);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
// Task form fields shared by the create and edit forms: people pickers and steps.
|
|
2
1
|
import { icon } from "./icons.js";
|
|
3
2
|
export const TITLE_MAX = 200, TEXT_MAX = 5000, STEP_MAX = 300, STEPS_MAX = 30;
|
|
4
3
|
export const roomPeople = (app) => {
|
|
5
4
|
const room = app.state.room;
|
|
5
|
+
const members = (room ? app.state.memberSessions.get(room.id) : undefined) ?? [];
|
|
6
6
|
return [...new Set([
|
|
7
7
|
...(room?.participants || []).map((person) => person.name),
|
|
8
|
-
...
|
|
9
|
-
].filter(Boolean))]
|
|
8
|
+
...members.map((member) => member.name),
|
|
9
|
+
].filter((name) => Boolean(name)))]
|
|
10
10
|
.sort((left, right) => String(left).localeCompare(String(right), app.intlLocale()));
|
|
11
11
|
};
|
|
12
12
|
export const fillAssignees = (app, select, value) => {
|
|
@@ -90,10 +90,10 @@ export function createStepsEditor(app, container, addButton, initial = []) {
|
|
|
90
90
|
return row;
|
|
91
91
|
};
|
|
92
92
|
const read = () => rows
|
|
93
|
-
.map((row) => ({ text: row.querySelector(".task-step-text")
|
|
93
|
+
.map((row) => ({ text: row.querySelector(".task-step-text")?.value.trim() ?? "", done: row.querySelector(".task-step-done")?.checked === true }))
|
|
94
94
|
.filter((step) => step.text);
|
|
95
95
|
const reset = () => { rows.splice(0).forEach((row) => row.remove()); sync(); };
|
|
96
|
-
addButton.addEventListener("click", () => addRow()?.querySelector(".task-step-text")
|
|
96
|
+
addButton.addEventListener("click", () => addRow()?.querySelector(".task-step-text")?.focus());
|
|
97
97
|
initial.forEach((step) => addRow(step));
|
|
98
98
|
return { addRow, read, reset };
|
|
99
99
|
}
|
|
@@ -86,7 +86,7 @@ export const buildTaskRow = (view, task, index) => {
|
|
|
86
86
|
const toggle = document.createElement("input");
|
|
87
87
|
toggle.type = "checkbox";
|
|
88
88
|
toggle.className = "task-step-toggle";
|
|
89
|
-
toggle.checked = step.done;
|
|
89
|
+
toggle.checked = step.done === true;
|
|
90
90
|
toggle.disabled = !view.canStatus(task) || view.isLocked();
|
|
91
91
|
toggle.dataset.stepIndex = String(position);
|
|
92
92
|
toggle.setAttribute("aria-label", `${app.t("tasksStepDoneLabel")}: ${step.text}`);
|