@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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export function pruneMessageRows(list, messages) {
|
|
2
2
|
const ids = new Set(messages.map((message) => message.id));
|
|
3
3
|
for (const row of list.querySelectorAll("[data-msg-id]"))
|
|
4
|
-
if (!ids.has(row.dataset.msgId))
|
|
4
|
+
if (!row.dataset.msgId || !ids.has(row.dataset.msgId))
|
|
5
5
|
row.remove();
|
|
6
|
-
const days = new Set([...list.querySelectorAll("[data-msg-id]")].map((row) => row.dataset.day));
|
|
6
|
+
const days = new Set([...list.querySelectorAll("[data-msg-id]")].map((row) => row.dataset.day ?? ""));
|
|
7
7
|
for (const separator of list.querySelectorAll(".day-sep"))
|
|
8
|
-
if (!days.has(separator.dataset.day))
|
|
8
|
+
if (!days.has(separator.dataset.day ?? ""))
|
|
9
9
|
separator.remove();
|
|
10
10
|
if (!days.size)
|
|
11
11
|
list.querySelectorAll(".gap").forEach((gap) => gap.remove());
|
|
@@ -32,6 +32,8 @@ export function followsBottom(app, threshold = -1) {
|
|
|
32
32
|
// A search jump parks one row near the top of the thread and flashes it briefly.
|
|
33
33
|
export function flashMessageRow(app, row) {
|
|
34
34
|
const thread = document.querySelector("#thread");
|
|
35
|
+
if (!thread)
|
|
36
|
+
return;
|
|
35
37
|
thread.scrollTop += row.getBoundingClientRect().top - (thread.getBoundingClientRect().top + thread.clientTop) - 12;
|
|
36
38
|
app.state.followBottom = false;
|
|
37
39
|
// Keep a programmatic search jump from being mistaken for the reader returning to the tail.
|
|
@@ -63,7 +65,9 @@ export function trimMessages(list, app) {
|
|
|
63
65
|
const thread = document.querySelector("#thread");
|
|
64
66
|
if (thread && thread.scrollHeight - thread.scrollTop - thread.clientHeight > 80)
|
|
65
67
|
return;
|
|
66
|
-
const
|
|
68
|
+
const position = app.state.positions.get(app.state.room?.id ?? "");
|
|
69
|
+
const saved = position && typeof position === "object" ? position : undefined;
|
|
70
|
+
const rows = [...list.querySelectorAll("[data-msg-id]")];
|
|
67
71
|
const anchor = saved?.messageId && rows.find((row) => row.dataset.msgId === saved.messageId);
|
|
68
72
|
if (anchor && rows.indexOf(anchor) < rows.length - 280) {
|
|
69
73
|
const recent = rows.at(-300);
|
|
@@ -81,7 +85,7 @@ export function trimMessages(list, app) {
|
|
|
81
85
|
anchor.after(gap);
|
|
82
86
|
return;
|
|
83
87
|
}
|
|
84
|
-
while (list.children.length > 300)
|
|
88
|
+
while (list.children.length > 300 && list.firstChild)
|
|
85
89
|
list.removeChild(list.firstChild);
|
|
86
90
|
if (list.firstElementChild && !list.firstElementChild.classList.contains("gap")) {
|
|
87
91
|
const gap = document.createElement("li");
|
|
@@ -9,10 +9,12 @@ import { initMessagePolling } from "./message-polling.js";
|
|
|
9
9
|
import { iconNode } from "./icons.js";
|
|
10
10
|
export function initMessages(app) {
|
|
11
11
|
const $ = app.$;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const input = $("#msgInput");
|
|
13
|
+
installEditor(input);
|
|
14
|
+
input.isKnownMention = (name) => app.mentionExists(name);
|
|
15
|
+
input.mentionLabel = (name) => name === "all" ? app.t("allMembers") : name;
|
|
16
|
+
const autoGrow = (editor) => {
|
|
17
|
+
const textarea = editor;
|
|
16
18
|
const thread = $("#thread"), atBottom = Boolean(app.state.room && Math.abs(thread.scrollHeight - thread.clientHeight - thread.scrollTop) < 1);
|
|
17
19
|
const scrollTop = textarea.scrollTop;
|
|
18
20
|
textarea.dataset.empty = textarea.value ? "false" : "true";
|
|
@@ -37,10 +39,13 @@ export function initMessages(app) {
|
|
|
37
39
|
if (atBottom)
|
|
38
40
|
thread.scrollTop = thread.scrollHeight;
|
|
39
41
|
};
|
|
40
|
-
app.
|
|
41
|
-
app.
|
|
42
|
+
app.autoGrow = autoGrow;
|
|
43
|
+
app.updateSendState = () => { $("#btnSend").disabled = !input.value.trim(); };
|
|
44
|
+
app.updateDraftCount = () => app.setText($("#draftCount"), "messageCount", { count: input.value.length });
|
|
42
45
|
app.renderFailedMessages = () => {
|
|
43
|
-
const composer =
|
|
46
|
+
const composer = input.closest(".composer");
|
|
47
|
+
if (!composer)
|
|
48
|
+
return;
|
|
44
49
|
let panel = composer.querySelector(".failed-messages");
|
|
45
50
|
if (!panel) {
|
|
46
51
|
panel = document.createElement("section");
|
|
@@ -48,10 +53,10 @@ export function initMessages(app) {
|
|
|
48
53
|
panel.setAttribute("aria-live", "polite");
|
|
49
54
|
composer.insertBefore(panel, $(".composer-row"));
|
|
50
55
|
}
|
|
51
|
-
const roomId = app.state.room?.id, items = roomId
|
|
56
|
+
const roomId = app.state.room?.id, items = roomId ? app.state.failedMessages.get(roomId) || [] : [];
|
|
52
57
|
panel.textContent = "";
|
|
53
58
|
panel.hidden = !items.length;
|
|
54
|
-
if (!items.length)
|
|
59
|
+
if (!roomId || !items.length)
|
|
55
60
|
return;
|
|
56
61
|
const heading = document.createElement("h3");
|
|
57
62
|
heading.textContent = app.t("failedMessages");
|
|
@@ -63,7 +68,7 @@ export function initMessages(app) {
|
|
|
63
68
|
const context = document.createElement("small");
|
|
64
69
|
context.className = "failed-reply-context";
|
|
65
70
|
context.textContent = `${item.replyTarget.senderId}: ${String(item.replyTarget.text).slice(0, 120)}`;
|
|
66
|
-
row.dataset.replyTargetId = item.replyToMessageID;
|
|
71
|
+
row.dataset.replyTargetId = item.replyToMessageID ?? "";
|
|
67
72
|
row.append(context);
|
|
68
73
|
}
|
|
69
74
|
text.textContent = item.text;
|
|
@@ -73,7 +78,7 @@ export function initMessages(app) {
|
|
|
73
78
|
};
|
|
74
79
|
app.discardFailedMessage = (roomId, failedId) => {
|
|
75
80
|
app.saveFailedMessages(roomId, (app.state.failedMessages.get(roomId) || []).filter((item) => item.id !== failedId));
|
|
76
|
-
app.renderFailedMessages();
|
|
81
|
+
app.renderFailedMessages?.();
|
|
77
82
|
};
|
|
78
83
|
// A retry reuses the first attempt's clientMessageID so a lost response
|
|
79
84
|
// cannot create a twin.
|
|
@@ -82,14 +87,14 @@ export function initMessages(app) {
|
|
|
82
87
|
if (!item || app.state.retryingFailedIds.has(failedId))
|
|
83
88
|
return;
|
|
84
89
|
app.state.retryingFailedIds.add(failedId);
|
|
85
|
-
app.renderFailedMessages();
|
|
90
|
+
app.renderFailedMessages?.();
|
|
86
91
|
try {
|
|
87
92
|
const questionTarget = item.replyTarget?.isQuestion, entry = app.state.rooms.get(roomId);
|
|
88
|
-
const updated = questionTarget ? (await app.answerQuestionFromReply(roomId, item.replyToMessageID, item.text), entry?.room)
|
|
93
|
+
const updated = questionTarget ? (await app.answerQuestionFromReply(roomId, item.replyToMessageID ?? "", item.text), entry?.room)
|
|
89
94
|
: await app.api(`/rooms/${encodeURIComponent(roomId)}/messages`, { method: "POST", body: JSON.stringify({ sessionID: LS.sessionID, text: item.text, isQuestion: Boolean(item.isQuestion), ...(item.clientMessageID ? { clientMessageID: item.clientMessageID } : {}), ...(item.replyToMessageID ? { replyToMessageID: item.replyToMessageID } : {}) }) });
|
|
90
95
|
app.completeAttachmentsFromText?.(roomId, item.text);
|
|
91
96
|
if (entry) {
|
|
92
|
-
if (!questionTarget)
|
|
97
|
+
if (!questionTarget && updated)
|
|
93
98
|
entry.room = mergeRoom(entry.room, updated);
|
|
94
99
|
const latest = entry.room.messages.at(-1);
|
|
95
100
|
if (latest && latest.createdAt >= entry.previewAt)
|
|
@@ -100,18 +105,19 @@ export function initMessages(app) {
|
|
|
100
105
|
app.state.room = entry.room;
|
|
101
106
|
app.renderMessages(true);
|
|
102
107
|
app.renderMembers();
|
|
103
|
-
app.markActiveRoomRead();
|
|
108
|
+
void app.markActiveRoomRead();
|
|
104
109
|
app.renderRoomOptions($("#roomList"), app.state.availableRooms || []);
|
|
105
110
|
app.renderRoomOptions($("#roomListChat"), app.state.availableRooms || []);
|
|
106
111
|
}
|
|
107
112
|
}
|
|
108
113
|
catch (error) {
|
|
114
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
109
115
|
if (app.state.room?.id === roomId)
|
|
110
|
-
app.showSendError(
|
|
116
|
+
app.showSendError(failure.status === 401 ? "sendAuth" : failure.network ? "sendNetwork" : "sendFailed", { message: failure.message });
|
|
111
117
|
}
|
|
112
118
|
finally {
|
|
113
119
|
app.state.retryingFailedIds.delete(failedId);
|
|
114
|
-
app.renderFailedMessages();
|
|
120
|
+
app.renderFailedMessages?.();
|
|
115
121
|
}
|
|
116
122
|
};
|
|
117
123
|
app.jumpToBottom = () => {
|
|
@@ -229,16 +235,16 @@ export function initMessages(app) {
|
|
|
229
235
|
app.renderMessage = (message, live) => {
|
|
230
236
|
const row = document.createElement("li");
|
|
231
237
|
row.dataset.sender = message.senderId;
|
|
232
|
-
row.dataset.ts = message.createdAt;
|
|
238
|
+
row.dataset.ts = String(message.createdAt);
|
|
233
239
|
row.dataset.msgId = message.id;
|
|
234
240
|
if (message.senderId === "system") {
|
|
235
241
|
renderSystemRow(row, message, app);
|
|
236
242
|
}
|
|
237
243
|
else {
|
|
238
|
-
const direct = app.state.room
|
|
244
|
+
const direct = app.state.room?.kind === "direct";
|
|
239
245
|
const own = isOwnMessage(message, app);
|
|
240
246
|
const sender = direct
|
|
241
|
-
? app.state.room
|
|
247
|
+
? app.state.room?.participants?.find((person) => person.id === message.senderId)?.name || app.t("guest")
|
|
242
248
|
: message.senderId;
|
|
243
249
|
row.className = `msg${own ? " own" : ""}`;
|
|
244
250
|
row.dataset.initial = Array.from((own ? app.state.myName : sender).trim())[0]?.toLocaleUpperCase() || "?";
|
|
@@ -291,7 +297,10 @@ export function initMessages(app) {
|
|
|
291
297
|
return row;
|
|
292
298
|
};
|
|
293
299
|
app.renderMessages = (live = false, tailLimit = 0) => {
|
|
294
|
-
const
|
|
300
|
+
const room = app.state.room;
|
|
301
|
+
if (!room)
|
|
302
|
+
return { skipped: 0 };
|
|
303
|
+
const thread = $("#thread"), list = $("#msgList"), messages = room.messages;
|
|
295
304
|
// A palette jump renders a window around the target instead of the newest
|
|
296
305
|
// tail. While that window is up, live appends stay off screen so the target
|
|
297
306
|
// is not trimmed away.
|
|
@@ -304,8 +313,8 @@ export function initMessages(app) {
|
|
|
304
313
|
let skipped = 0;
|
|
305
314
|
let anchorId = null, anchorOffset = 0, oldTop = thread.scrollTop;
|
|
306
315
|
const viewport = thread.getBoundingClientRect();
|
|
307
|
-
const firstVisible = [...list.children].find((node) => node.
|
|
308
|
-
anchorId = firstVisible?.
|
|
316
|
+
const firstVisible = [...list.children].find((node) => node.getAttribute("data-msg-id") && node.getBoundingClientRect().bottom > viewport.top);
|
|
317
|
+
anchorId = firstVisible?.getAttribute("data-msg-id") || null;
|
|
309
318
|
anchorOffset = firstVisible ? firstVisible.getBoundingClientRect().top - viewport.top : 0;
|
|
310
319
|
if (focus) {
|
|
311
320
|
// Start a fresh window containing the target, wherever it sits in the
|
|
@@ -332,7 +341,7 @@ export function initMessages(app) {
|
|
|
332
341
|
continue;
|
|
333
342
|
try {
|
|
334
343
|
const day = new Date(message.createdAt).toDateString();
|
|
335
|
-
if (!last || last.
|
|
344
|
+
if (!last || last.getAttribute("data-day") !== day) {
|
|
336
345
|
const separator = document.createElement("li");
|
|
337
346
|
separator.className = "day-sep";
|
|
338
347
|
separator.dataset.day = day;
|
|
@@ -342,8 +351,8 @@ export function initMessages(app) {
|
|
|
342
351
|
}
|
|
343
352
|
const row = app.renderMessage(message, live);
|
|
344
353
|
row.dataset.day = day;
|
|
345
|
-
if (last.classList.contains("msg") && last.
|
|
346
|
-
&& message.createdAt - Number(last.
|
|
354
|
+
if (last.classList.contains("msg") && last.getAttribute("data-sender") === message.senderId
|
|
355
|
+
&& message.createdAt - Number(last.getAttribute("data-ts")) < 8 * 60 * 1000)
|
|
347
356
|
row.classList.add("repeat");
|
|
348
357
|
list.append(row);
|
|
349
358
|
last = row;
|
|
@@ -407,7 +416,7 @@ export function initMessages(app) {
|
|
|
407
416
|
app.firstMessageId = null;
|
|
408
417
|
app.failedRenderIds.clear();
|
|
409
418
|
const result = app.renderMessages(false);
|
|
410
|
-
const nextAnchor = anchorId
|
|
419
|
+
const nextAnchor = anchorId ? list.querySelector(`[data-msg-id="${CSS.escape(anchorId)}"]`) : null;
|
|
411
420
|
if (atBottom)
|
|
412
421
|
thread.scrollTop = thread.scrollHeight;
|
|
413
422
|
else if (nextAnchor)
|
|
@@ -417,7 +426,7 @@ export function initMessages(app) {
|
|
|
417
426
|
return result;
|
|
418
427
|
};
|
|
419
428
|
app.send = async () => {
|
|
420
|
-
const
|
|
429
|
+
const room = app.state.room, replyTarget = room && app.replyTargetFor?.(room.id);
|
|
421
430
|
if (!room || app.state.sendingRooms?.has(room.id))
|
|
422
431
|
return false;
|
|
423
432
|
const message = app.prepareMessage?.(room.id, input.value) || { text: input.value.trim(), ids: [], ready: Boolean(input.value.trim()) };
|
|
@@ -431,14 +440,14 @@ export function initMessages(app) {
|
|
|
431
440
|
const thread = $("#thread"), followedBottom = thread.scrollHeight - thread.scrollTop - thread.clientHeight < 80;
|
|
432
441
|
const revision = app.state.draftRevision.get(room.id) || 0;
|
|
433
442
|
app.state.sendingRooms ||= new Set();
|
|
434
|
-
app.state.sendingRooms
|
|
443
|
+
app.state.sendingRooms?.add(room.id);
|
|
435
444
|
app.closeMention();
|
|
436
445
|
app.clearReplyTarget?.(room.id);
|
|
437
446
|
input.value = "";
|
|
438
447
|
app.clearDraft(room.id);
|
|
439
|
-
|
|
440
|
-
app.updateDraftCount();
|
|
441
|
-
app.updateSendState();
|
|
448
|
+
autoGrow(input);
|
|
449
|
+
app.updateDraftCount?.();
|
|
450
|
+
app.updateSendState?.();
|
|
442
451
|
app.hideSendError();
|
|
443
452
|
const pending = {
|
|
444
453
|
id: `pending-${createRandomId()}`, roomId: room.id, text,
|
|
@@ -501,6 +510,7 @@ export function initMessages(app) {
|
|
|
501
510
|
return true;
|
|
502
511
|
}
|
|
503
512
|
catch (error) {
|
|
513
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
504
514
|
const pendingIndex = room.messages.findIndex((item) => item.id === pending.id);
|
|
505
515
|
if (pendingIndex >= 0)
|
|
506
516
|
room.messages.splice(pendingIndex, 1);
|
|
@@ -509,13 +519,13 @@ export function initMessages(app) {
|
|
|
509
519
|
const unchanged = (app.state.draftRevision.get(room.id) || 0) === revision;
|
|
510
520
|
// Someone answered the question first; retrying the answer can never succeed,
|
|
511
521
|
// so keep the text as a draft instead of a failed message.
|
|
512
|
-
const staleReply = Boolean(replyTarget?.isQuestion) && (
|
|
522
|
+
const staleReply = Boolean(replyTarget?.isQuestion) && (failure.status === 409 || failure.status === 404);
|
|
513
523
|
if (staleReply)
|
|
514
524
|
app.saveDraft(room.id, text);
|
|
515
525
|
else {
|
|
516
526
|
const failures = app.state.failedMessages.get(room.id) || [];
|
|
517
527
|
app.saveFailedMessages(room.id, [...failures, { id: createRandomId(), text, clientMessageID, ...(replyTarget ? { replyToMessageID: replyTarget.id, replyTarget } : {}) }]);
|
|
518
|
-
app.renderFailedMessages();
|
|
528
|
+
app.renderFailedMessages?.();
|
|
519
529
|
}
|
|
520
530
|
app.completeAttachments?.(room.id, message.ids);
|
|
521
531
|
if (app.state.room?.id !== room.id)
|
|
@@ -524,21 +534,21 @@ export function initMessages(app) {
|
|
|
524
534
|
app.clearDraft(room.id);
|
|
525
535
|
if (staleReply)
|
|
526
536
|
input.draftValue = text;
|
|
527
|
-
|
|
528
|
-
app.updateSendState();
|
|
529
|
-
app.updateDraftCount();
|
|
530
|
-
if (
|
|
537
|
+
autoGrow(input);
|
|
538
|
+
app.updateSendState?.();
|
|
539
|
+
app.updateDraftCount?.();
|
|
540
|
+
if (failure.status === 401) {
|
|
531
541
|
app.openChatSettings();
|
|
532
542
|
app.showSendError("sendAuth");
|
|
533
543
|
}
|
|
534
544
|
else
|
|
535
|
-
app.showSendError(
|
|
545
|
+
app.showSendError(failure.network ? "sendNetwork" : "sendFailed", { message: failure.message });
|
|
536
546
|
return false;
|
|
537
547
|
}
|
|
538
548
|
finally {
|
|
539
|
-
app.state.sendingRooms
|
|
549
|
+
app.state.sendingRooms?.delete(room.id);
|
|
540
550
|
if (app.state.room?.id === room.id)
|
|
541
|
-
app.updateSendState();
|
|
551
|
+
app.updateSendState?.();
|
|
542
552
|
}
|
|
543
553
|
};
|
|
544
554
|
function failedAction(key, roomId, failedId, app) {
|
|
@@ -562,8 +572,8 @@ export function isUnreadMessage(message, app, room = app.state.room, myName = ap
|
|
|
562
572
|
return message.senderId !== "system" && !isOwnMessage(message, app, room, myName);
|
|
563
573
|
}
|
|
564
574
|
export function isOwnMessage(message, app, room = app.state.room, myName = app.state.myName) {
|
|
565
|
-
const direct = room
|
|
566
|
-
const sameName = app.state.memberSessions.get(room.id)?.filter((member) => member.name === message.senderId);
|
|
575
|
+
const direct = room?.kind === "direct";
|
|
576
|
+
const sameName = room ? app.state.memberSessions.get(room.id)?.filter((member) => member.name === message.senderId) : undefined;
|
|
567
577
|
return direct ? message.senderId === LS.sessionID
|
|
568
578
|
: message.senderSessionID ? message.senderSessionID === LS.sessionID
|
|
569
579
|
// Without a recorded sender session, fall back to the name unless a namesake is known.
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { icon } from "./icons.js";
|
|
2
2
|
// Alt+Space or Ctrl+P opens one keyboard-first surface: message search plus common room commands.
|
|
3
3
|
const SEARCH_DEBOUNCE_MS = 120;
|
|
4
|
+
function isRecord(value) {
|
|
5
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6
|
+
}
|
|
4
7
|
export function initPalette(app) {
|
|
5
8
|
const dialog = app.$("#paletteDialog");
|
|
6
9
|
if (!dialog)
|
|
7
10
|
return;
|
|
8
11
|
const input = app.$("#paletteInput"), list = app.$("#paletteList"), status = app.$("#paletteStatus");
|
|
9
12
|
const scopeButton = app.$("#paletteScope"), scopeLabel = app.$("#paletteScopeLabel"), modeLabel = app.$("#paletteMode");
|
|
13
|
+
if (!input || !list || !status || !scopeButton || !scopeLabel || !modeLabel)
|
|
14
|
+
return;
|
|
10
15
|
let scope = "room", items = [], selected = -1, sequence = 0, searchTimer = 0, suppressComposerFocus = false, hitTimer = 0;
|
|
11
16
|
const t = (key, values) => app.t(key, values);
|
|
12
17
|
const room = () => app.state.room;
|
|
@@ -22,8 +27,9 @@ export function initPalette(app) {
|
|
|
22
27
|
run: () => room() ? app.openCreateRoomDialog?.() : app.$("#inRoomName")?.focus({ preventScroll: true }) },
|
|
23
28
|
{ id: "settings", label: t("settings"), en: "Settings", icon: "options", keywords: "preferences theme language", focusComposer: false, run: () => app.openSettings?.() },
|
|
24
29
|
];
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
const activeRoom = room();
|
|
31
|
+
if (activeRoom)
|
|
32
|
+
available.push({ id: "members", label: t("members"), en: "Members", icon: "people", keywords: "people roster", focusComposer: false, run: () => app.$("#btnMembers")?.click() }, { id: "questions", label: t("questions"), en: "Questions", icon: "question_circle", keywords: "answers", focusComposer: false, run: () => app.$("#btnQuestions")?.click() }, { id: "announcements", label: t("announcements"), en: "Announcements", icon: "megaphone", keywords: "notice board", focusComposer: false, run: () => app.$("#btnAnnouncements")?.click() }, ...(activeRoom.kind === "direct" ? [] : [{ id: "tasks", label: t("tasksTitle"), en: "Tasks", icon: "checkmark", keywords: "todo checklist work", focusComposer: false, run: () => app.openTasksDialog?.() }]), { id: "reminders", label: t("reminders"), en: "Reminders", icon: "alert", keywords: "schedule alarm", focusComposer: false, run: () => app.$("#btnReminders")?.click() }, { id: "leave", label: t("paletteLeaveRoom"), en: "Leave room", icon: "arrow_exit", keywords: "exit quit", focusComposer: false, run: () => app.leaveRoom?.(false) }, { id: "latest", label: t("paletteJumpLatest"), en: "Jump to latest", icon: "arrow_down", keywords: "bottom newest", run: () => app.jumpToBottom?.() });
|
|
27
33
|
return available;
|
|
28
34
|
};
|
|
29
35
|
const scopeText = () => t(scope === "all" ? "paletteScopeAll" : "paletteScopeRoom");
|
|
@@ -164,9 +170,10 @@ export function initPalette(app) {
|
|
|
164
170
|
};
|
|
165
171
|
const localSearch = (text, searchScope) => {
|
|
166
172
|
const needle = text.toLowerCase();
|
|
173
|
+
const activeId = app.state.room?.id;
|
|
167
174
|
const entries = searchScope === "all"
|
|
168
175
|
? [...app.state.rooms.values()]
|
|
169
|
-
: [app.state.rooms.get(
|
|
176
|
+
: activeId ? [app.state.rooms.get(activeId)].filter((entry) => Boolean(entry)) : [];
|
|
170
177
|
const hits = [];
|
|
171
178
|
for (const entry of entries) {
|
|
172
179
|
const source = entry.room;
|
|
@@ -192,25 +199,31 @@ export function initPalette(app) {
|
|
|
192
199
|
hits.sort((a, b) => b.createdAt - a.createdAt);
|
|
193
200
|
return hits.slice(0, 80);
|
|
194
201
|
};
|
|
195
|
-
const normalizeHits = (raw) =>
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
202
|
+
const normalizeHits = (raw) => {
|
|
203
|
+
const hits = [];
|
|
204
|
+
for (const item of raw) {
|
|
205
|
+
if (!isRecord(item))
|
|
206
|
+
continue;
|
|
207
|
+
const message = isRecord(item.message) ? item.message : {};
|
|
208
|
+
const source = isRecord(item.room) ? item.room : {};
|
|
209
|
+
const roomId = String(item.roomId ?? item.roomID ?? source.id ?? "");
|
|
210
|
+
const messageId = String(item.messageId ?? item.messageID ?? message.id ?? item.id ?? "");
|
|
211
|
+
if (!messageId)
|
|
212
|
+
continue;
|
|
213
|
+
const seq = Number(item.seq ?? message.seq);
|
|
214
|
+
hits.push({
|
|
215
|
+
kind: "hit",
|
|
216
|
+
raw: { roomId, messageId, seq: Number.isSafeInteger(seq) ? seq : undefined },
|
|
217
|
+
roomId,
|
|
218
|
+
messageId,
|
|
219
|
+
roomName: String(item.roomName ?? source.name ?? app.state.roomNames.get(roomId) ?? app.state.rooms.get(roomId)?.room?.name ?? ""),
|
|
220
|
+
sender: String(item.senderName ?? item.sender ?? item.senderId ?? message.senderId ?? ""),
|
|
221
|
+
createdAt: Number(item.createdAt ?? message.createdAt ?? item.ts ?? 0) || 0,
|
|
222
|
+
text: String(item.text ?? item.snippet ?? item.preview ?? message.text ?? ""),
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
return hits;
|
|
226
|
+
};
|
|
214
227
|
const failSearch = () => {
|
|
215
228
|
dialog.dataset.state = "ready";
|
|
216
229
|
list.setAttribute("aria-busy", "false");
|
|
@@ -229,10 +242,11 @@ export function initPalette(app) {
|
|
|
229
242
|
}
|
|
230
243
|
if (token !== sequence)
|
|
231
244
|
return;
|
|
245
|
+
const record = isRecord(result) ? result : {};
|
|
232
246
|
const raw = Array.isArray(result) ? result
|
|
233
|
-
: Array.isArray(
|
|
234
|
-
: Array.isArray(
|
|
235
|
-
: Array.isArray(
|
|
247
|
+
: Array.isArray(record.hits) ? record.hits
|
|
248
|
+
: Array.isArray(record.results) ? record.results
|
|
249
|
+
: Array.isArray(record.items) ? record.items : [];
|
|
236
250
|
const hits = normalizeHits(raw).slice(0, 80);
|
|
237
251
|
dialog.dataset.state = "ready";
|
|
238
252
|
list.setAttribute("aria-busy", "false");
|
|
@@ -350,7 +364,7 @@ export function initPalette(app) {
|
|
|
350
364
|
input.focus();
|
|
351
365
|
};
|
|
352
366
|
app.openPalette = openPalette;
|
|
353
|
-
input.addEventListener("input", (event) => { if (!event.isComposing)
|
|
367
|
+
input.addEventListener("input", (event) => { if (!(event instanceof InputEvent && event.isComposing))
|
|
354
368
|
scheduleSearch(); });
|
|
355
369
|
// IME commits (Chinese, Japanese, Korean) may fire no plain input event after
|
|
356
370
|
// composition ends, so filter the committed text here as well.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// Panel and key-dialog plumbing: every overlay closes the same way.
|
|
2
1
|
const PANEL_DEFAULTS = { announcements: "dialog", files: "dialog", tasks: "pane", reminders: "dialog" };
|
|
3
2
|
const PANEL_MODES = ["dialog", "pane"];
|
|
4
3
|
const PANE_QUERY = "(min-width: 1100px) and (min-height: 560px)";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// A waiting worker means a new release is ready. Never reload on our own: a page can
|
|
2
|
-
// hold a draft or a reply in progress, so the person decides when to apply it.
|
|
3
1
|
const UPDATE_CHECK_MS = 30 * 60 * 1000;
|
|
2
|
+
function isPrecacheMessage(value) {
|
|
3
|
+
return typeof value === "object" && value !== null;
|
|
4
|
+
}
|
|
4
5
|
export function initPwa(app) {
|
|
5
6
|
if (!("serviceWorker" in navigator) || !window.isSecureContext)
|
|
6
7
|
return;
|
|
@@ -75,7 +76,7 @@ export function initPwa(app) {
|
|
|
75
76
|
dismissed = false;
|
|
76
77
|
waiting = null;
|
|
77
78
|
render("downloading");
|
|
78
|
-
watchWorker(
|
|
79
|
+
watchWorker(next.installing);
|
|
79
80
|
});
|
|
80
81
|
};
|
|
81
82
|
const checkForUpdate = () => {
|
|
@@ -107,7 +108,7 @@ export function initPwa(app) {
|
|
|
107
108
|
});
|
|
108
109
|
navigator.serviceWorker.addEventListener("message", (event) => {
|
|
109
110
|
const data = event.data;
|
|
110
|
-
if (!data || data.type !== "OC_PRECACHE")
|
|
111
|
+
if (!isPrecacheMessage(data) || data.type !== "OC_PRECACHE")
|
|
111
112
|
return;
|
|
112
113
|
if (data.phase === "downloading")
|
|
113
114
|
render("downloading");
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { LS, LOADED_MESSAGE_LIMIT } from "./state.js";
|
|
2
2
|
import { autoMentionDraft, installEditor } from "./editor.js";
|
|
3
3
|
import { copyTextToClipboard, renderMarkdown } from "./markdown.js";
|
|
4
|
+
const statusOf = (error) => error instanceof Error && "status" in error ? error.status : undefined;
|
|
4
5
|
export function initQuestions(app) {
|
|
5
6
|
const $ = app.$, pending = new Map(), selected = new Map(), drafts = new Map(), submitting = new Set(), unsupported = new Set();
|
|
7
|
+
const itemsFor = (roomId) => (roomId ? pending.get(roomId) : undefined) || [];
|
|
6
8
|
let request = 0;
|
|
7
9
|
const panel = $("#questionPanel"), trigger = $("#btnQuestions"), list = $("#questionList"), status = $("#questionStatus");
|
|
8
10
|
// Undefined until the server list for this room has loaded; callers must not
|
|
9
11
|
// treat that as "no open questions".
|
|
10
|
-
app.unansweredQuestionIds = (roomId = app.state.room?.id) => pending.has(roomId)
|
|
11
|
-
? new Set((
|
|
12
|
+
app.unansweredQuestionIds = (roomId = app.state.room?.id) => roomId && pending.has(roomId)
|
|
13
|
+
? new Set(itemsFor(roomId).map((item) => item.id)) : undefined;
|
|
12
14
|
const renderMessage = app.renderMessage;
|
|
13
15
|
app.renderMessage = (message, live) => {
|
|
14
16
|
const row = renderMessage(message, live);
|
|
@@ -30,7 +32,7 @@ export function initQuestions(app) {
|
|
|
30
32
|
}
|
|
31
33
|
app.updateQuestionBadge = renderBadge;
|
|
32
34
|
function render(roomId) {
|
|
33
|
-
const items =
|
|
35
|
+
const items = itemsFor(roomId);
|
|
34
36
|
const entry = app.state.rooms.get(roomId);
|
|
35
37
|
// Keep the room's question-mark badge in sync with the loaded question list.
|
|
36
38
|
if (entry && pending.has(roomId) && Number(entry.room.openQuestions) !== items.length) {
|
|
@@ -79,7 +81,7 @@ export function initQuestions(app) {
|
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
function renderReply(roomId) {
|
|
82
|
-
const box = $("#questionReply"), question = (
|
|
84
|
+
const box = $("#questionReply"), question = itemsFor(roomId).find((item) => item.id === selected.get(roomId));
|
|
83
85
|
if (question && box.dataset.roomId === roomId && box.dataset.questionId === question.id) {
|
|
84
86
|
const key = `${roomId}\0${question.id}`, input = box.querySelector("[contenteditable]"), send = box.querySelector("button[type=submit]"), copy = box.querySelector(".question-copy"), feedback = box.querySelector(".question-copy-feedback");
|
|
85
87
|
box.hidden = false;
|
|
@@ -130,7 +132,7 @@ export function initQuestions(app) {
|
|
|
130
132
|
input.isKnownMention = (name) => app.mentionExists(name);
|
|
131
133
|
input.mentionLabel = (name) => name === "all" ? app.t("allMembers") : name;
|
|
132
134
|
const key = `${roomId}\0${question.id}`;
|
|
133
|
-
input.draftValue = drafts.
|
|
135
|
+
input.draftValue = drafts.get(key) ?? questionAuthorMention(question, roomId, app);
|
|
134
136
|
input.dataset.empty = input.value ? "false" : "true";
|
|
135
137
|
send.type = "submit";
|
|
136
138
|
send.className = "btn primary small";
|
|
@@ -217,7 +219,7 @@ export function initQuestions(app) {
|
|
|
217
219
|
catch (error) {
|
|
218
220
|
if (id !== request || app.state.room?.id !== roomId)
|
|
219
221
|
return;
|
|
220
|
-
if (error
|
|
222
|
+
if (statusOf(error) === 404) {
|
|
221
223
|
const member = await roomMembership(roomId);
|
|
222
224
|
if (id !== request || app.state.room?.id !== roomId)
|
|
223
225
|
return;
|
|
@@ -231,7 +233,7 @@ export function initQuestions(app) {
|
|
|
231
233
|
showFailed();
|
|
232
234
|
return;
|
|
233
235
|
}
|
|
234
|
-
if (error
|
|
236
|
+
if (statusOf(error) === 401)
|
|
235
237
|
app.openChatSettings();
|
|
236
238
|
showFailed();
|
|
237
239
|
render(roomId);
|
|
@@ -257,10 +259,9 @@ export function initQuestions(app) {
|
|
|
257
259
|
method: "POST", body: JSON.stringify({ sessionID: LS.sessionID, text }),
|
|
258
260
|
});
|
|
259
261
|
applyAnswer(roomId, questionId, result);
|
|
260
|
-
return result;
|
|
261
262
|
}
|
|
262
263
|
catch (error) {
|
|
263
|
-
if (error
|
|
264
|
+
if (statusOf(error) === 409 || statusOf(error) === 404)
|
|
264
265
|
await load(roomId);
|
|
265
266
|
throw error;
|
|
266
267
|
}
|
|
@@ -285,9 +286,9 @@ export function initQuestions(app) {
|
|
|
285
286
|
void load(roomId);
|
|
286
287
|
}
|
|
287
288
|
catch (error) {
|
|
288
|
-
if (error
|
|
289
|
+
if (statusOf(error) === 409 || statusOf(error) === 404) {
|
|
289
290
|
await load(roomId);
|
|
290
|
-
if (error
|
|
291
|
+
if (statusOf(error) === 409 && app.state.room?.id === roomId && !itemsFor(roomId).some((item) => item.id === questionId)) {
|
|
291
292
|
if (selected.get(roomId) === questionId)
|
|
292
293
|
selected.delete(roomId);
|
|
293
294
|
drafts.delete(`${roomId}\0${questionId}`);
|
|
@@ -297,7 +298,7 @@ export function initQuestions(app) {
|
|
|
297
298
|
render(roomId);
|
|
298
299
|
}
|
|
299
300
|
}
|
|
300
|
-
else if (error
|
|
301
|
+
else if (statusOf(error) === 401 && app.state.room?.id === roomId) {
|
|
301
302
|
app.openChatSettings();
|
|
302
303
|
app.showSendError("sendAuth");
|
|
303
304
|
}
|
|
@@ -313,21 +314,21 @@ export function initQuestions(app) {
|
|
|
313
314
|
}
|
|
314
315
|
}
|
|
315
316
|
function applyAnswer(roomId, questionId, result) {
|
|
316
|
-
const entry = app.state.rooms.get(roomId);
|
|
317
|
-
if (entry &&
|
|
317
|
+
const entry = app.state.rooms.get(roomId), answer = result.answer;
|
|
318
|
+
if (entry && answer) {
|
|
318
319
|
const question = entry.room.messages.find((item) => item.id === questionId);
|
|
319
320
|
if (question)
|
|
320
|
-
question.answeredByMessageID =
|
|
321
|
+
question.answeredByMessageID = answer.id;
|
|
321
322
|
}
|
|
322
|
-
if (entry &&
|
|
323
|
-
entry.room.messages.push({ ...
|
|
323
|
+
if (entry && answer && !entry.room.messages.some((item) => item.id === answer.id)) {
|
|
324
|
+
entry.room.messages.push({ ...answer, roomId });
|
|
324
325
|
entry.room.messages.sort((a, b) => a.createdAt - b.createdAt);
|
|
325
326
|
if (entry.room.messages.length > LOADED_MESSAGE_LIMIT)
|
|
326
327
|
entry.room.messages.splice(0, entry.room.messages.length - LOADED_MESSAGE_LIMIT);
|
|
327
328
|
if (app.state.room?.id === roomId)
|
|
328
329
|
app.renderMessages(true);
|
|
329
330
|
}
|
|
330
|
-
pending.set(roomId, (
|
|
331
|
+
pending.set(roomId, itemsFor(roomId).filter((item) => item.id !== (result.questionID || questionId)));
|
|
331
332
|
if (selected.get(roomId) === questionId)
|
|
332
333
|
selected.delete(roomId);
|
|
333
334
|
drafts.delete(`${roomId}\0${questionId}`);
|
|
@@ -347,8 +348,9 @@ export function initQuestions(app) {
|
|
|
347
348
|
$("#btnRefreshQuestions").addEventListener("click", () => void load());
|
|
348
349
|
list.addEventListener("click", (event) => {
|
|
349
350
|
event.stopPropagation();
|
|
350
|
-
const
|
|
351
|
-
|
|
351
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
352
|
+
const card = target?.closest(".question-item[data-question-id]"), select = target?.closest(".question-select");
|
|
353
|
+
if (!card || (!select && target?.closest("a, button, input, textarea, select, [contenteditable=true]")) || !app.state.room)
|
|
352
354
|
return;
|
|
353
355
|
selected.set(app.state.room.id, card.dataset.questionId);
|
|
354
356
|
render(app.state.room.id);
|