@alexsun-top/opencode-chat-room 0.8.4 → 0.8.6
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 +17 -3
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/cli.ts +20 -1
- package/dist/cli.js +3785 -1462
- package/package.json +19 -11
- package/packages/chat-room-channeld/README.md +16 -10
- package/packages/chat-room-channeld/src/delivery.ts +0 -4
- package/packages/chat-room-channeld/src/host.ts +48 -37
- package/packages/chat-room-channeld/src/inbound.ts +3 -6
- package/packages/chat-room-channeld/src/pg/database.ts +141 -49
- package/packages/chat-room-channeld/src/pg/sql.mjs +157 -142
- package/packages/chat-room-channeld/src/pg/sql.mts +175 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +148 -99
- package/packages/chat-room-channeld/src/pg/worker.mts +201 -0
- package/packages/chat-room-channeld/src/state-rows.ts +132 -0
- package/packages/chat-room-channeld/src/state.ts +129 -157
- package/plugin.ts +21 -5
- package/server/app.ts +9 -0
- package/server/assets/base.css +22 -2
- package/server/assets/chat/admin.js +17 -1
- package/server/assets/chat/announcements.js +79 -34
- package/server/assets/chat/attachments.js +3 -3
- package/server/assets/chat/clipboard.js +1 -1
- package/server/assets/chat/confirm-dialog.js +3 -0
- package/server/assets/chat/copy-action.js +1 -1
- 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 +71 -31
- package/server/assets/chat/editor.js +49 -10
- package/server/assets/chat/events.js +13 -6
- package/server/assets/chat/files.js +33 -27
- package/server/assets/chat/history-loader.js +31 -15
- package/server/assets/chat/integration-editor.js +27 -1
- package/server/assets/chat/integrations.js +108 -16
- package/server/assets/chat/join-requests.js +40 -2
- 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 +27 -15
- package/server/assets/chat/markdown.js +6 -12
- package/server/assets/chat/members.js +34 -22
- package/server/assets/chat/mentions.js +8 -5
- package/server/assets/chat/message-cache.js +9 -3
- package/server/assets/chat/message-polling.js +10 -4
- package/server/assets/chat/message-window.js +58 -1
- package/server/assets/chat/messages.js +90 -37
- package/server/assets/chat/office-preview.js +3 -3
- package/server/assets/chat/operator.js +624 -0
- package/server/assets/chat/palette.js +7 -10
- package/server/assets/chat/panels.js +42 -0
- package/server/assets/chat/questions.js +75 -58
- 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 +47 -13
- package/server/assets/chat/replies.js +39 -25
- package/server/assets/chat/resource-format.js +6 -3
- package/server/assets/chat/room-list.js +202 -3
- package/server/assets/chat/room-watcher.js +3 -1
- package/server/assets/chat/rooms.js +29 -7
- package/server/assets/chat/settings.js +37 -6
- package/server/assets/chat/shortcuts.js +3 -1
- package/server/assets/chat/side-pane.js +1 -1
- package/server/assets/chat/state.js +51 -18
- package/server/assets/chat/system-events.js +3 -2
- package/server/assets/chat/system-messages.js +15 -15
- package/server/assets/chat/tasks.js +37 -14
- package/server/assets/chat/window-controls.js +25 -15
- package/server/assets/code-highlight.css +0 -13
- package/server/assets/conversation.css +45 -5
- package/server/assets/doc-preview.css +9 -0
- package/server/assets/files.css +4 -0
- package/server/assets/monaco/integration-rules.js +1 -1
- package/server/assets/office/THIRD-PARTY-NOTICES.txt +23 -1
- package/server/assets/office/licenses/docx-preview-HEADER.txt +6 -0
- package/server/assets/office/licenses/echarts-LICENSE-d3.txt +27 -0
- package/server/assets/office/licenses/echarts-NOTICE.txt +5 -0
- package/server/assets/office/licenses/immediate-LICENSE.txt +20 -0
- package/server/assets/office/licenses/lie-LICENSE.txt +7 -0
- package/server/assets/office/licenses/pako-LICENSE.txt +21 -0
- package/server/assets/office/licenses/pako-ZLIB.txt +18 -0
- package/server/assets/office/licenses/setimmediate-LICENSE.txt +20 -0
- 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 +3 -2
- package/server/chat.html +7 -2
- package/server/inbox.ts +3 -1
- package/server/join-requests.ts +8 -1
- 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/sw.js +3 -1
- package/server/system.html +109 -0
- package/server/wake.ts +1 -1
- package/skills/chatroom/SKILL.md +9 -0
- package/src/README.md +1 -1
- 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 +98 -8
- package/src/center/center-client.ts +6 -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 +389 -0
- package/src/protocol/config.ts +7 -0
- package/src/runtime/plugin-notifications.ts +43 -9
- package/src/runtime/v2-plugin.ts +14 -3
- 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-sql.mjs +157 -142
- package/src/state/pg-sql.mts +175 -0
- package/src/state/pg-worker.mjs +148 -99
- package/src/state/pg-worker.mts +201 -0
- 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 +31 -11
- package/src/tui/app-types.mjs +1 -0
- package/src/tui/app-types.mts +175 -0
- package/src/tui/app.mjs +473 -423
- package/src/tui/app.mts +543 -0
- package/src/tui/config.mjs +166 -158
- package/src/tui/config.mts +247 -0
- package/src/tui/http.mjs +239 -206
- package/src/tui/http.mts +412 -0
- package/src/tui/i18n.mjs +17 -20
- package/src/tui/i18n.mts +42 -0
- package/src/tui/info-app.mjs +431 -427
- package/src/tui/info-app.mts +500 -0
- package/src/tui/info-content.mjs +205 -199
- package/src/tui/info-content.mts +341 -0
- package/src/tui/join-app.mjs +75 -64
- package/src/tui/join-app.mts +99 -0
- package/src/tui/locales/en.mjs +302 -320
- package/src/tui/locales/en.mts +349 -0
- package/src/tui/locales/zh-CN.mjs +302 -320
- package/src/tui/locales/zh-CN.mts +349 -0
- package/src/tui/main.mjs +219 -213
- package/src/tui/main.mts +255 -0
- package/src/tui/markdown.mjs +128 -272
- package/src/tui/markdown.mts +152 -0
- package/src/tui/mentions.mjs +181 -184
- package/src/tui/mentions.mts +251 -0
- package/src/tui/message-app.mjs +181 -173
- package/src/tui/message-app.mts +213 -0
- package/src/tui/message-view.mjs +90 -111
- package/src/tui/message-view.mts +151 -0
- package/src/tui/messages.mjs +55 -49
- package/src/tui/messages.mts +106 -0
- package/src/tui/palette-app.mjs +364 -344
- package/src/tui/palette-app.mts +388 -0
- package/src/tui/palette.mjs +100 -98
- package/src/tui/palette.mts +176 -0
- package/src/tui/prefs.mjs +56 -63
- package/src/tui/prefs.mts +126 -0
- package/src/tui/reminder-app.mjs +191 -181
- package/src/tui/reminder-app.mts +228 -0
- package/src/tui/room-settings-app.mjs +275 -242
- package/src/tui/room-settings-app.mts +318 -0
- package/src/tui/session.mjs +30 -29
- package/src/tui/session.mts +51 -0
- package/src/tui/settings-app.mjs +151 -138
- package/src/tui/settings-app.mts +179 -0
- package/src/tui/ui-content.mjs +426 -421
- package/src/tui/ui-content.mts +499 -0
- package/src/tui/ui-help.mjs +58 -67
- package/src/tui/ui-help.mts +87 -0
- package/src/tui/ui-mentions.mjs +34 -36
- package/src/tui/ui-mentions.mts +60 -0
- package/src/tui/ui-overlay-view.mjs +259 -267
- package/src/tui/ui-overlay-view.mts +322 -0
- package/src/tui/ui-suggest-view.mjs +54 -57
- package/src/tui/ui-suggest-view.mts +78 -0
- package/src/tui/ui-suggest.mjs +164 -167
- package/src/tui/ui-suggest.mts +248 -0
- package/src/tui/ui-theme.mjs +52 -57
- package/src/tui/ui-theme.mts +98 -0
- package/src/tui/ui-view.mjs +267 -275
- package/src/tui/ui-view.mts +308 -0
- package/src/tui/ui.mjs +372 -359
- package/src/tui/ui.mts +440 -0
- package/src/tui/wire.mjs +215 -0
- package/src/tui/wire.mts +383 -0
- package/src/web/integration-rules-editor.ts +25 -2
|
@@ -31,7 +31,11 @@ async function withStore(mode, run) {
|
|
|
31
31
|
}
|
|
32
32
|
export async function loadCachedRooms() {
|
|
33
33
|
try {
|
|
34
|
-
|
|
34
|
+
const records = (await withStore("readonly", (store) => store.getAll())) || [];
|
|
35
|
+
// Older snapshots may still carry optimistic rows that no server can confirm.
|
|
36
|
+
return records.map((record) => Array.isArray(record?.room?.messages)
|
|
37
|
+
? { ...record, room: { ...record.room, messages: record.room.messages.filter((message) => !message.pending) } }
|
|
38
|
+
: record);
|
|
35
39
|
}
|
|
36
40
|
catch {
|
|
37
41
|
return [];
|
|
@@ -47,12 +51,14 @@ const pending = new Map();
|
|
|
47
51
|
export function cacheRoomSoon(app, roomId) {
|
|
48
52
|
if (pending.has(roomId))
|
|
49
53
|
return;
|
|
50
|
-
pending.set(roomId, setTimeout(() => {
|
|
54
|
+
pending.set(roomId, window.setTimeout(() => {
|
|
51
55
|
pending.delete(roomId);
|
|
52
56
|
const entry = app.state.rooms.get(roomId);
|
|
53
57
|
if (!entry?.room)
|
|
54
58
|
return;
|
|
55
|
-
|
|
59
|
+
// Optimistic rows only live in this session; on reload they could never be confirmed.
|
|
60
|
+
const messages = entry.room.messages.filter((message) => !message.pending).slice(-CACHE_LIMIT);
|
|
61
|
+
const snapshot = { ...entry.room, messages };
|
|
56
62
|
void withStore("readwrite", (store) => store.put({ roomId, name: entry.name, savedAt: Date.now(), room: snapshot })).catch(() => { });
|
|
57
63
|
}, 800));
|
|
58
64
|
}
|
|
@@ -32,7 +32,7 @@ export function initMessagePolling(app, isUnreadMessage) {
|
|
|
32
32
|
stopRecovery();
|
|
33
33
|
recoveryRoom = roomId;
|
|
34
34
|
recoveryGeneration = app.state.pollGeneration;
|
|
35
|
-
recoveryTimer = setTimeout(() => { void probeRecovery(roomId, recoveryGeneration); }, immediate ? 0 : 2000);
|
|
35
|
+
recoveryTimer = window.setTimeout(() => { void probeRecovery(roomId, recoveryGeneration); }, immediate ? 0 : 2000);
|
|
36
36
|
}
|
|
37
37
|
async function probeRecovery(roomId, generation) {
|
|
38
38
|
recoveryTimer = null;
|
|
@@ -71,7 +71,7 @@ export function initMessagePolling(app, isUnreadMessage) {
|
|
|
71
71
|
app.openChatSettings();
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
|
-
recoveryTimer = setTimeout(() => { void probeRecovery(roomId, generation); }, 2000);
|
|
74
|
+
recoveryTimer = window.setTimeout(() => { void probeRecovery(roomId, generation); }, 2000);
|
|
75
75
|
}
|
|
76
76
|
finally {
|
|
77
77
|
clearTimeout(timer);
|
|
@@ -164,11 +164,14 @@ export function initMessagePolling(app, isUnreadMessage) {
|
|
|
164
164
|
entry.unreadIds.set(item.id, item);
|
|
165
165
|
unreadChanged = true;
|
|
166
166
|
}
|
|
167
|
-
//
|
|
168
|
-
|
|
167
|
+
// The excerpt is attached only when answered_by points at this message,
|
|
168
|
+
// so later replies do not clear the question again.
|
|
169
|
+
if (entry && item.answerQuestionExcerpt && item.answerToMessageID && entry.unreadIds.get(item.answerToMessageID)?.isQuestion) {
|
|
169
170
|
entry.unreadIds.delete(item.answerToMessageID);
|
|
170
171
|
unreadChanged = true;
|
|
171
172
|
}
|
|
173
|
+
if (item.answerQuestionExcerpt && item.answerToMessageID)
|
|
174
|
+
app.settleQuestionAnswer?.(roomId, item.answerToMessageID, item);
|
|
172
175
|
}
|
|
173
176
|
// A changed recall version means rows were hidden since the last look; refetch
|
|
174
177
|
// the newest page and patch the rows already on screen.
|
|
@@ -188,6 +191,9 @@ export function initMessagePolling(app, isUnreadMessage) {
|
|
|
188
191
|
if (anchor && !messages.includes(anchor))
|
|
189
192
|
messages.unshift(anchor);
|
|
190
193
|
}
|
|
194
|
+
// An own message that arrives here before its send resolves keeps the
|
|
195
|
+
// optimistic bubble instead of adding a second row.
|
|
196
|
+
app.settlePendingEcho?.(messages);
|
|
191
197
|
app.cacheRoomSoon?.(roomId);
|
|
192
198
|
const rendered = app.renderMessages(true);
|
|
193
199
|
if (sawSystem || sawQuestion) {
|
|
@@ -1,3 +1,60 @@
|
|
|
1
|
+
// Turn an optimistic bubble into its confirmed self without replacing the row, so
|
|
2
|
+
// confirming a send is a style change instead of a re-render that moves the scroll.
|
|
3
|
+
function confirmRow(app, row, message) {
|
|
4
|
+
row.dataset.msgId = message.id;
|
|
5
|
+
row.dataset.ts = String(message.createdAt);
|
|
6
|
+
row.classList.remove("pending");
|
|
7
|
+
const stack = row.querySelector(".msg-receipt-stack");
|
|
8
|
+
if (stack && !stack.querySelector(".message-readers"))
|
|
9
|
+
stack.append(app.createReceiptButton(message, row.classList.contains("own")));
|
|
10
|
+
const time = row.querySelector(".msg-time");
|
|
11
|
+
// A grouped row keeps its clock in the receipt column instead of the meta line.
|
|
12
|
+
if (time)
|
|
13
|
+
time.textContent = stack?.contains(time) ? app.timeHM(message.createdAt) : app.messageTime(message.createdAt);
|
|
14
|
+
// Reply, recall and other per-message controls need the server id, so they land now.
|
|
15
|
+
app.decorateRow?.(row, message);
|
|
16
|
+
}
|
|
17
|
+
// Patch an optimistic bubble onto the server's copy of the same message. The row
|
|
18
|
+
// survives only when the stored body and reply target are unchanged, so the DOM
|
|
19
|
+
// keeps the exact content the reader already sees.
|
|
20
|
+
function keepRow(app, placeholder, message) {
|
|
21
|
+
const row = app.$("#msgList")?.querySelector(`[data-msg-id="${CSS.escape(placeholder.id)}"]`);
|
|
22
|
+
if (!row || message.text !== placeholder.text)
|
|
23
|
+
return false;
|
|
24
|
+
if ((message.answerToMessageID ?? "") !== (placeholder.replyToMessageID ?? ""))
|
|
25
|
+
return false;
|
|
26
|
+
confirmRow(app, row, message);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
// A poll echo carries the sender's retry key only on its own message, so the pair
|
|
30
|
+
// is exact even when another tab or member sent the same body.
|
|
31
|
+
export function settlePendingEcho(app, messages) {
|
|
32
|
+
const list = app.$("#msgList");
|
|
33
|
+
if (!list || !messages.some((message) => message.pending))
|
|
34
|
+
return;
|
|
35
|
+
const shown = new Set([...list.querySelectorAll("[data-msg-id]")].map((row) => row.dataset.msgId));
|
|
36
|
+
for (const placeholder of messages.filter((message) => message.pending && message.clientMessageID)) {
|
|
37
|
+
const index = messages.findIndex((message) => !message.pending && !shown.has(message.id)
|
|
38
|
+
&& message.clientMessageID === placeholder.clientMessageID);
|
|
39
|
+
if (index < 0)
|
|
40
|
+
continue;
|
|
41
|
+
shown.add(messages[index].id);
|
|
42
|
+
keepRow(app, placeholder, messages[index]);
|
|
43
|
+
messages.splice(messages.indexOf(placeholder), 1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// The send response names the stored message id: only that message may replace
|
|
47
|
+
// the placeholder. A changed body or reply target leaves the row to re-render.
|
|
48
|
+
export function settleSentMessage(app, messages, sentID, clientMessageID) {
|
|
49
|
+
const index = messages.findIndex((item) => item.pending && item.clientMessageID === clientMessageID);
|
|
50
|
+
if (index < 0)
|
|
51
|
+
return;
|
|
52
|
+
const placeholder = messages[index];
|
|
53
|
+
messages.splice(index, 1);
|
|
54
|
+
const message = messages.find((item) => item.id === sentID);
|
|
55
|
+
if (message)
|
|
56
|
+
keepRow(app, placeholder, message);
|
|
57
|
+
}
|
|
1
58
|
export function pruneMessageRows(list, messages) {
|
|
2
59
|
const ids = new Set(messages.map((message) => message.id));
|
|
3
60
|
for (const row of list.querySelectorAll("[data-msg-id]"))
|
|
@@ -42,7 +99,7 @@ export function flashMessageRow(app, row) {
|
|
|
42
99
|
row.classList.remove("jump-flash");
|
|
43
100
|
void row.offsetWidth;
|
|
44
101
|
row.classList.add("jump-flash");
|
|
45
|
-
row._jumpFlashTimer = setTimeout(() => row.classList.remove("jump-flash"), 900);
|
|
102
|
+
row._jumpFlashTimer = window.setTimeout(() => row.classList.remove("jump-flash"), 900);
|
|
46
103
|
app.updateJump?.();
|
|
47
104
|
}
|
|
48
105
|
// Resolve app.state.focusMessageId against the loaded state and rendered rows.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRandomId, LS, LOADED_MESSAGE_LIMIT } from "./state.js";
|
|
2
2
|
import { renderMarkdown } from "./markdown.js";
|
|
3
|
-
import { pruneMessageRows, trimMessages, focusedMessage } from "./message-window.js";
|
|
3
|
+
import { pruneMessageRows, trimMessages, focusedMessage, settlePendingEcho, settleSentMessage } from "./message-window.js";
|
|
4
4
|
import { setRoomPreview } from "./system-messages.js";
|
|
5
5
|
import { renderSystemRow } from "./system-events.js";
|
|
6
6
|
import { installEditor } from "./editor.js";
|
|
@@ -89,12 +89,11 @@ export function initMessages(app) {
|
|
|
89
89
|
app.state.retryingFailedIds.add(failedId);
|
|
90
90
|
app.renderFailedMessages?.();
|
|
91
91
|
try {
|
|
92
|
-
const
|
|
93
|
-
const updated =
|
|
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 } : {}) }) });
|
|
92
|
+
const entry = app.state.rooms.get(roomId);
|
|
93
|
+
const updated = 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 } : {}) }) });
|
|
95
94
|
app.completeAttachmentsFromText?.(roomId, item.text);
|
|
96
95
|
if (entry) {
|
|
97
|
-
if (
|
|
96
|
+
if (updated)
|
|
98
97
|
entry.room = mergeRoom(entry.room, updated);
|
|
99
98
|
const latest = entry.room.messages.at(-1);
|
|
100
99
|
if (latest && latest.createdAt >= entry.previewAt)
|
|
@@ -136,12 +135,39 @@ export function initMessages(app) {
|
|
|
136
135
|
app.updateJump();
|
|
137
136
|
void app.markActiveRoomRead(true);
|
|
138
137
|
};
|
|
138
|
+
// Resizing or zooming rescales the thread under the pointer, so intermediate scroll
|
|
139
|
+
// positions would flicker the button. Stay hidden while the settle timer is armed,
|
|
140
|
+
// judge the final position when it fires, then fade in only if the reader is away.
|
|
141
|
+
const JUMP_SETTLE_MS = 2000;
|
|
142
|
+
let jumpHoldTimer = 0;
|
|
139
143
|
app.updateJump = () => {
|
|
140
144
|
const thread = $("#thread");
|
|
145
|
+
const button = $("#btnJump");
|
|
146
|
+
// The armed timer is the hold, so even a delayed callback cannot reveal it early.
|
|
147
|
+
if (jumpHoldTimer) {
|
|
148
|
+
button.hidden = true;
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
141
151
|
// Match the distance that already counts as read, so unread never hides the button.
|
|
142
|
-
|
|
143
|
-
|
|
152
|
+
button.hidden = thread.scrollHeight - thread.scrollTop - thread.clientHeight <= 80;
|
|
153
|
+
if (button.hidden)
|
|
154
|
+
button.classList.remove("is-settling");
|
|
155
|
+
};
|
|
156
|
+
const holdJumpWhileResizing = () => {
|
|
157
|
+
const button = $("#btnJump");
|
|
158
|
+
button.classList.remove("is-settling");
|
|
159
|
+
button.hidden = true;
|
|
160
|
+
clearTimeout(jumpHoldTimer);
|
|
161
|
+
jumpHoldTimer = window.setTimeout(() => {
|
|
162
|
+
jumpHoldTimer = 0;
|
|
163
|
+
app.updateJump();
|
|
164
|
+
if (!button.hidden)
|
|
165
|
+
button.classList.add("is-settling");
|
|
166
|
+
}, JUMP_SETTLE_MS);
|
|
144
167
|
};
|
|
168
|
+
window.addEventListener("resize", holdJumpWhileResizing);
|
|
169
|
+
// Pinch zoom changes the visual viewport without a layout resize.
|
|
170
|
+
window.visualViewport?.addEventListener("resize", holdJumpWhileResizing);
|
|
145
171
|
app.updateBadge = () => {
|
|
146
172
|
const badge = $("#jumpBadge");
|
|
147
173
|
badge.textContent = app.state.unread > 99 ? "99+" : String(app.state.unread);
|
|
@@ -263,9 +289,13 @@ export function initMessages(app) {
|
|
|
263
289
|
renderMarkdown(body, message.text, app);
|
|
264
290
|
const content = document.createElement("div");
|
|
265
291
|
content.className = "msg-content";
|
|
266
|
-
|
|
292
|
+
const stack = document.createElement("div");
|
|
293
|
+
stack.className = "msg-receipt-stack";
|
|
294
|
+
// An optimistic row already reserves the receipt column, so confirming it
|
|
295
|
+
// never reflows the bubble; only the button arrives with the server copy.
|
|
267
296
|
if (!message.pending)
|
|
268
|
-
|
|
297
|
+
stack.append(app.createReceiptButton(message, own));
|
|
298
|
+
content.append(body, stack);
|
|
269
299
|
row.append(meta, content);
|
|
270
300
|
}
|
|
271
301
|
if (message.senderId !== "system") {
|
|
@@ -296,6 +326,9 @@ export function initMessages(app) {
|
|
|
296
326
|
row.classList.add("in");
|
|
297
327
|
return row;
|
|
298
328
|
};
|
|
329
|
+
// Confirms an optimistic bubble in place, by exact correlation only.
|
|
330
|
+
app.settlePendingEcho = (messages) => settlePendingEcho(app, messages);
|
|
331
|
+
app.settleSentMessage = (messages, sentID, key) => settleSentMessage(app, messages, sentID, key);
|
|
299
332
|
app.renderMessages = (live = false, tailLimit = 0) => {
|
|
300
333
|
const room = app.state.room;
|
|
301
334
|
if (!room)
|
|
@@ -329,7 +362,7 @@ export function initMessages(app) {
|
|
|
329
362
|
const lastId = [...list.querySelectorAll("[data-msg-id]")].at(-1)?.dataset.msgId;
|
|
330
363
|
if (lastId)
|
|
331
364
|
for (let index = messages.length - 1; index >= 0; index--)
|
|
332
|
-
if (messages[index]
|
|
365
|
+
if (messages[index]?.id === lastId) {
|
|
333
366
|
startIndex = index + 1;
|
|
334
367
|
break;
|
|
335
368
|
}
|
|
@@ -337,6 +370,8 @@ export function initMessages(app) {
|
|
|
337
370
|
const renderEnd = focus ? Math.min(messages.length, focus.index + 120) : messages.length;
|
|
338
371
|
for (let index = renderStart; index < renderEnd; index++) {
|
|
339
372
|
const message = messages[index];
|
|
373
|
+
if (!message)
|
|
374
|
+
break;
|
|
340
375
|
if (renderedIds.has(message.id) || app.failedRenderIds.has(message.id))
|
|
341
376
|
continue;
|
|
342
377
|
try {
|
|
@@ -354,6 +389,14 @@ export function initMessages(app) {
|
|
|
354
389
|
if (last.classList.contains("msg") && last.getAttribute("data-sender") === message.senderId
|
|
355
390
|
&& message.createdAt - Number(last.getAttribute("data-ts")) < 8 * 60 * 1000)
|
|
356
391
|
row.classList.add("repeat");
|
|
392
|
+
if (row.classList.contains("repeat")) {
|
|
393
|
+
// A grouped row shows its own clock beside the badge, not a meta line.
|
|
394
|
+
const time = row.querySelector(".msg-time"), stack = row.querySelector(".msg-receipt-stack");
|
|
395
|
+
if (time && stack) {
|
|
396
|
+
time.textContent = app.timeHM(message.createdAt);
|
|
397
|
+
stack.prepend(time);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
357
400
|
list.append(row);
|
|
358
401
|
last = row;
|
|
359
402
|
renderedIds.add(message.id);
|
|
@@ -452,7 +495,7 @@ export function initMessages(app) {
|
|
|
452
495
|
const pending = {
|
|
453
496
|
id: `pending-${createRandomId()}`, roomId: room.id, text,
|
|
454
497
|
senderId: room.kind === "direct" ? LS.sessionID : app.state.myName,
|
|
455
|
-
senderSessionID: LS.sessionID, createdAt: Date.now(), pending: true,
|
|
498
|
+
senderSessionID: LS.sessionID, createdAt: Date.now(), pending: true, clientMessageID,
|
|
456
499
|
...(replyTarget ? { replyToMessageID: replyTarget.id } : {}),
|
|
457
500
|
};
|
|
458
501
|
room.messages.push(pending);
|
|
@@ -460,33 +503,41 @@ export function initMessages(app) {
|
|
|
460
503
|
if (followedBottom)
|
|
461
504
|
thread.scrollTop = thread.scrollHeight;
|
|
462
505
|
try {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
updated = app.state.rooms.get(room.id)?.room || room;
|
|
467
|
-
}
|
|
468
|
-
else
|
|
469
|
-
updated = await app.api(`/rooms/${encodeURIComponent(room.id)}/messages`, {
|
|
470
|
-
method: "POST", body: JSON.stringify({ sessionID: LS.sessionID, text, clientMessageID, ...(replyTarget ? { replyToMessageID: replyTarget.id } : {}) }),
|
|
471
|
-
});
|
|
506
|
+
const updated = await app.api(`/rooms/${encodeURIComponent(room.id)}/messages`, {
|
|
507
|
+
method: "POST", body: JSON.stringify({ sessionID: LS.sessionID, text, clientMessageID, ...(replyTarget ? { replyToMessageID: replyTarget.id } : {}) }),
|
|
508
|
+
});
|
|
472
509
|
// A successful request proves the connection is usable, even if a stale
|
|
473
510
|
// long-poll is still waiting to time out.
|
|
474
511
|
app.setOnline(true);
|
|
475
512
|
app.completeAttachments?.(room.id, message.ids);
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
513
|
+
if (app.state.room?.id !== room.id) {
|
|
514
|
+
const pendingIndex = room.messages.findIndex((item) => item.id === pending.id);
|
|
515
|
+
if (pendingIndex >= 0)
|
|
516
|
+
room.messages.splice(pendingIndex, 1);
|
|
480
517
|
return true;
|
|
518
|
+
}
|
|
481
519
|
const entry = app.state.rooms.get(room.id);
|
|
482
520
|
// The POST snapshot is older than anything polling received while it was
|
|
483
|
-
// in flight; merge instead of dropping those messages.
|
|
521
|
+
// in flight; merge instead of dropping those messages. The optimistic
|
|
522
|
+
// placeholder rides through so its bubble is confirmed in place.
|
|
484
523
|
let current = updated;
|
|
485
524
|
if (entry) {
|
|
486
|
-
const merged = new Map([...entry.room.messages, ...updated.messages].
|
|
525
|
+
const merged = new Map([...entry.room.messages, ...updated.messages].map((item) => [item.id, { ...item, roomId: updated.id }]));
|
|
487
526
|
const messages = [...merged.values()].sort((a, b) => a.createdAt - b.createdAt);
|
|
488
527
|
if (messages.length > LOADED_MESSAGE_LIMIT)
|
|
489
528
|
messages.splice(0, messages.length - LOADED_MESSAGE_LIMIT);
|
|
529
|
+
// Only the id the server named may confirm the row; an older server that
|
|
530
|
+
// returns no id falls back to a normal render below.
|
|
531
|
+
const sent = updated;
|
|
532
|
+
const sentMessageID = sent.sentMessageID;
|
|
533
|
+
delete sent.sentMessageID;
|
|
534
|
+
if (typeof sentMessageID === "string" && sentMessageID)
|
|
535
|
+
app.settleSentMessage?.(messages, sentMessageID, clientMessageID);
|
|
536
|
+
// Nothing claimed the placeholder (changed body, older response, trimmed
|
|
537
|
+
// window): keep it out of the room state either way.
|
|
538
|
+
const stale = messages.findIndex((item) => item.pending);
|
|
539
|
+
if (stale >= 0)
|
|
540
|
+
messages.splice(stale, 1);
|
|
490
541
|
app.cacheRoomSoon?.(room.id);
|
|
491
542
|
current = { ...updated, messages };
|
|
492
543
|
}
|
|
@@ -498,9 +549,11 @@ export function initMessages(app) {
|
|
|
498
549
|
setRoomPreview(entry, latest);
|
|
499
550
|
}
|
|
500
551
|
app.renderMessages(true);
|
|
501
|
-
//
|
|
502
|
-
|
|
503
|
-
|
|
552
|
+
// A reader who scrolled away while the send was in flight keeps their place;
|
|
553
|
+
// the tail is only pinned when they are still following it.
|
|
554
|
+
const threadEl = $("#thread");
|
|
555
|
+
if (followedBottom && threadEl.scrollHeight - threadEl.scrollTop - threadEl.clientHeight <= 80)
|
|
556
|
+
threadEl.scrollTop = threadEl.scrollHeight;
|
|
504
557
|
app.renderMembers();
|
|
505
558
|
app.state.unread = entry ? entry.unreadIds.size + (entry.unreadOverflow ? 100 : 0) : 0;
|
|
506
559
|
app.updateBadge();
|
|
@@ -516,12 +569,12 @@ export function initMessages(app) {
|
|
|
516
569
|
room.messages.splice(pendingIndex, 1);
|
|
517
570
|
if (app.state.room?.id === room.id)
|
|
518
571
|
app.renderMessages(false);
|
|
572
|
+
// An echo that already carries this retry key is proof the server stored
|
|
573
|
+
// the message: a lost response must not turn it into a failed or twin send.
|
|
574
|
+
const stored = (app.state.rooms.get(room.id)?.room ?? room).messages
|
|
575
|
+
.some((item) => !item.pending && item.clientMessageID === clientMessageID);
|
|
519
576
|
const unchanged = (app.state.draftRevision.get(room.id) || 0) === revision;
|
|
520
|
-
|
|
521
|
-
// so keep the text as a draft instead of a failed message.
|
|
522
|
-
const staleReply = Boolean(replyTarget?.isQuestion) && (failure.status === 409 || failure.status === 404);
|
|
523
|
-
if (staleReply)
|
|
524
|
-
app.saveDraft(room.id, text);
|
|
577
|
+
if (stored) { /* delivered; nothing to retry */ }
|
|
525
578
|
else {
|
|
526
579
|
const failures = app.state.failedMessages.get(room.id) || [];
|
|
527
580
|
app.saveFailedMessages(room.id, [...failures, { id: createRandomId(), text, clientMessageID, ...(replyTarget ? { replyToMessageID: replyTarget.id, replyTarget } : {}) }]);
|
|
@@ -530,13 +583,13 @@ export function initMessages(app) {
|
|
|
530
583
|
app.completeAttachments?.(room.id, message.ids);
|
|
531
584
|
if (app.state.room?.id !== room.id)
|
|
532
585
|
return false;
|
|
533
|
-
if (unchanged
|
|
586
|
+
if (unchanged)
|
|
534
587
|
app.clearDraft(room.id);
|
|
535
|
-
if (staleReply)
|
|
536
|
-
input.draftValue = text;
|
|
537
588
|
autoGrow(input);
|
|
538
589
|
app.updateSendState?.();
|
|
539
590
|
app.updateDraftCount?.();
|
|
591
|
+
if (stored)
|
|
592
|
+
return false;
|
|
540
593
|
if (failure.status === 401) {
|
|
541
594
|
app.openChatSettings();
|
|
542
595
|
app.showSendError("sendAuth");
|
|
@@ -10,10 +10,10 @@ const loaded = new Map();
|
|
|
10
10
|
export class OfficePreviewError extends Error {
|
|
11
11
|
name = "OfficePreviewError";
|
|
12
12
|
}
|
|
13
|
-
function load(kind) {
|
|
13
|
+
function load(kind, url) {
|
|
14
14
|
let pending = loaded.get(kind);
|
|
15
15
|
if (!pending) {
|
|
16
|
-
pending = import(
|
|
16
|
+
pending = import(url);
|
|
17
17
|
pending.catch(() => loaded.delete(kind));
|
|
18
18
|
loaded.set(kind, pending);
|
|
19
19
|
}
|
|
@@ -55,7 +55,7 @@ export async function renderOffice(kind, blob, container, options = {}) {
|
|
|
55
55
|
container.classList.add("office-preview");
|
|
56
56
|
container.setAttribute("aria-busy", "true");
|
|
57
57
|
try {
|
|
58
|
-
const bundle = await load(kind);
|
|
58
|
+
const bundle = await load(kind, format.url);
|
|
59
59
|
await bundle.render(blob, container, options);
|
|
60
60
|
}
|
|
61
61
|
catch (error) {
|