@alexsun-top/opencode-chat-room 0.8.3 → 0.8.5
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 +7 -1
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/cli.ts +1 -1
- package/dist/cli.js +35 -16
- package/package.json +15 -9
- package/packages/chat-room-channeld/README.md +3 -2
- package/packages/chat-room-channeld/src/inbound.ts +3 -6
- 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 +107 -99
- package/packages/chat-room-channeld/src/pg/worker.mts +166 -0
- package/plugin.ts +1 -1
- package/server/assets/chat/admin-badge.js +1 -1
- package/server/assets/chat/admin.js +16 -10
- package/server/assets/chat/announcements.js +12 -2
- package/server/assets/chat/attachment-store.js +15 -6
- package/server/assets/chat/attachments.js +48 -33
- 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 +1 -2
- package/server/assets/chat/diagram-viewer.js +7 -9
- package/server/assets/chat/doc-preview.js +19 -12
- package/server/assets/chat/editor.js +87 -61
- package/server/assets/chat/events.js +49 -34
- package/server/assets/chat/files.js +45 -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 +2 -2
- package/server/assets/chat/integration-values.js +17 -11
- package/server/assets/chat/integrations.js +138 -81
- package/server/assets/chat/join-requests.js +20 -13
- package/server/assets/chat/markdown-footnotes.js +8 -8
- package/server/assets/chat/markdown.js +48 -38
- package/server/assets/chat/members.js +48 -25
- package/server/assets/chat/mentions.js +39 -12
- package/server/assets/chat/message-cache.js +2 -2
- package/server/assets/chat/message-polling.js +40 -21
- package/server/assets/chat/message-window.js +10 -6
- package/server/assets/chat/messages.js +70 -46
- package/server/assets/chat/office-preview.js +3 -3
- package/server/assets/chat/palette.js +45 -29
- package/server/assets/chat/panels.js +19 -1
- package/server/assets/chat/pwa.js +5 -4
- package/server/assets/chat/questions.js +25 -22
- package/server/assets/chat/recall.js +39 -21
- package/server/assets/chat/receipts.js +9 -7
- package/server/assets/chat/reminders.js +25 -8
- package/server/assets/chat/replies.js +34 -15
- package/server/assets/chat/resource-format.js +2 -2
- package/server/assets/chat/room-list.js +2 -2
- package/server/assets/chat/room-watcher.js +8 -4
- package/server/assets/chat/rooms.js +51 -40
- package/server/assets/chat/search.js +8 -6
- package/server/assets/chat/settings.js +16 -14
- package/server/assets/chat/shiki.js +1 -1
- package/server/assets/chat/shortcuts.js +3 -3
- package/server/assets/chat/side-pane.js +4 -3
- package/server/assets/chat/state.js +65 -37
- package/server/assets/chat/system-events.js +6 -5
- package/server/assets/chat/system-messages.js +15 -15
- package/server/assets/chat/task-form.js +5 -5
- package/server/assets/chat/task-row.js +1 -1
- package/server/assets/chat/tasks.js +41 -28
- package/server/assets/chat/window-controls.js +3 -2
- package/server/assets/conversation.css +14 -2
- package/server/assets/doc-preview.css +6 -0
- 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/chat.html +1 -0
- package/server/sw.js +3 -1
- package/skills/chatroom/SKILL.md +9 -0
- package/src/README.md +1 -1
- package/src/agent/agent-receipts.ts +12 -4
- package/src/center/center-client.ts +1 -1
- package/src/state/pg-sql.mjs +157 -142
- package/src/state/pg-sql.mts +175 -0
- package/src/state/pg-worker.mjs +107 -99
- package/src/state/pg-worker.mts +166 -0
- package/src/state/store.ts +21 -7
- package/src/tui/app-types.mjs +1 -0
- package/src/tui/app-types.mts +175 -0
- package/src/tui/app.mjs +426 -423
- package/src/tui/app.mts +500 -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 +257 -242
- package/src/tui/room-settings-app.mts +301 -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
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { LS, LOADED_MESSAGE_LIMIT } from "./state.js";
|
|
2
2
|
import { setRoomPreview } from "./system-messages.js";
|
|
3
|
+
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
4
|
+
const errorStatus = (error) => error instanceof Error && "status" in error && typeof error.status === "number" ? error.status : undefined;
|
|
5
|
+
const errorNetwork = (error) => error instanceof Error && "network" in error && error.network === true;
|
|
3
6
|
// Inbox polling, room-meta refresh, and reconciliation live apart from rendering.
|
|
4
7
|
export function initMessagePolling(app, isUnreadMessage) {
|
|
5
8
|
const $ = app.$;
|
|
@@ -29,7 +32,7 @@ export function initMessagePolling(app, isUnreadMessage) {
|
|
|
29
32
|
stopRecovery();
|
|
30
33
|
recoveryRoom = roomId;
|
|
31
34
|
recoveryGeneration = app.state.pollGeneration;
|
|
32
|
-
recoveryTimer = setTimeout(() => { void probeRecovery(roomId, recoveryGeneration); }, immediate ? 0 : 2000);
|
|
35
|
+
recoveryTimer = window.setTimeout(() => { void probeRecovery(roomId, recoveryGeneration); }, immediate ? 0 : 2000);
|
|
33
36
|
}
|
|
34
37
|
async function probeRecovery(roomId, generation) {
|
|
35
38
|
recoveryTimer = null;
|
|
@@ -55,19 +58,20 @@ export function initMessagePolling(app, isUnreadMessage) {
|
|
|
55
58
|
stopRecovery();
|
|
56
59
|
return;
|
|
57
60
|
}
|
|
58
|
-
|
|
61
|
+
const status = errorStatus(error);
|
|
62
|
+
if (status === 404) {
|
|
59
63
|
stopRecovery();
|
|
60
64
|
void app.removeJoinedRoom(roomId, { reason: true });
|
|
61
65
|
return;
|
|
62
66
|
}
|
|
63
|
-
if (
|
|
67
|
+
if (status === 401) {
|
|
64
68
|
stopRecovery();
|
|
65
69
|
app.setOnline(false);
|
|
66
|
-
if (!app.settingsOpen())
|
|
70
|
+
if (!app.settingsOpen?.())
|
|
67
71
|
app.openChatSettings();
|
|
68
72
|
return;
|
|
69
73
|
}
|
|
70
|
-
recoveryTimer = setTimeout(() => { void probeRecovery(roomId, generation); }, 2000);
|
|
74
|
+
recoveryTimer = window.setTimeout(() => { void probeRecovery(roomId, generation); }, 2000);
|
|
71
75
|
}
|
|
72
76
|
finally {
|
|
73
77
|
clearTimeout(timer);
|
|
@@ -128,7 +132,7 @@ export function initMessagePolling(app, isUnreadMessage) {
|
|
|
128
132
|
clearTimeout(timer);
|
|
129
133
|
signal.removeEventListener("abort", abort);
|
|
130
134
|
}
|
|
131
|
-
if (!isCurrentPoll(roomId, generation))
|
|
135
|
+
if (!isCurrentPoll(roomId, generation) || !isRecord(data))
|
|
132
136
|
return;
|
|
133
137
|
if (data.member === false) {
|
|
134
138
|
void app.removeJoinedRoom(roomId, { reason: true });
|
|
@@ -136,7 +140,10 @@ export function initMessagePolling(app, isUnreadMessage) {
|
|
|
136
140
|
}
|
|
137
141
|
if (data.member !== true || !Array.isArray(data.items))
|
|
138
142
|
return;
|
|
139
|
-
const
|
|
143
|
+
const active = app.state.room;
|
|
144
|
+
if (!active)
|
|
145
|
+
return;
|
|
146
|
+
const items = data.items, previousReceivedTs = entry?.receivedTs || 0, messages = active.messages;
|
|
140
147
|
const known = new Set(messages.map((message) => message.id));
|
|
141
148
|
const previousUnreadOverflow = Boolean(entry?.unreadOverflow);
|
|
142
149
|
let sawSystem = false, sawQuestion = false, added = 0, unreadChanged = false;
|
|
@@ -176,7 +183,7 @@ export function initMessagePolling(app, isUnreadMessage) {
|
|
|
176
183
|
if (entry)
|
|
177
184
|
entry.unreadOverflow = Boolean(data.hasMore);
|
|
178
185
|
if (messages.length > LOADED_MESSAGE_LIMIT) {
|
|
179
|
-
const
|
|
186
|
+
const position = app.state.positions.get(roomId), anchorId = typeof position === "object" ? position?.messageId : undefined, anchor = anchorId && messages.find((item) => item.id === anchorId);
|
|
180
187
|
messages.splice(0, messages.length - LOADED_MESSAGE_LIMIT);
|
|
181
188
|
if (anchor && !messages.includes(anchor))
|
|
182
189
|
messages.unshift(anchor);
|
|
@@ -195,11 +202,14 @@ export function initMessagePolling(app, isUnreadMessage) {
|
|
|
195
202
|
}
|
|
196
203
|
if (rendered.skipped === 0)
|
|
197
204
|
void app.markActiveRoomRead();
|
|
198
|
-
|
|
199
|
-
|
|
205
|
+
const roomList = $("#roomList"), roomListChat = $("#roomListChat");
|
|
206
|
+
if (roomList)
|
|
207
|
+
app.renderRoomOptions(roomList, app.state.availableRooms || []);
|
|
208
|
+
if (roomListChat)
|
|
209
|
+
app.renderRoomOptions(roomListChat, app.state.availableRooms || []);
|
|
200
210
|
if (!app.lastReconcileAt || Date.now() - app.lastReconcileAt > 120000) {
|
|
201
211
|
app.lastReconcileAt = Date.now();
|
|
202
|
-
void app.reconcileRoom(roomId, generation);
|
|
212
|
+
void app.reconcileRoom?.(roomId, generation);
|
|
203
213
|
}
|
|
204
214
|
app.setOnline(true);
|
|
205
215
|
stopRecovery();
|
|
@@ -208,20 +218,22 @@ export function initMessagePolling(app, isUnreadMessage) {
|
|
|
208
218
|
catch (error) {
|
|
209
219
|
if (!isCurrentPoll(roomId, generation))
|
|
210
220
|
return;
|
|
211
|
-
|
|
221
|
+
const status = errorStatus(error);
|
|
222
|
+
if (status === 401) {
|
|
212
223
|
stopRecovery();
|
|
213
224
|
app.setOnline(false);
|
|
214
|
-
if (!app.settingsOpen())
|
|
225
|
+
if (!app.settingsOpen?.())
|
|
215
226
|
app.openChatSettings();
|
|
216
227
|
pollDelay = Math.min(pollDelay * 2, 30000);
|
|
217
228
|
}
|
|
218
|
-
else if (
|
|
229
|
+
else if (status === 404) {
|
|
219
230
|
void app.removeJoinedRoom(roomId, { reason: true });
|
|
220
231
|
}
|
|
221
232
|
else {
|
|
222
233
|
app.setOnline(false);
|
|
223
234
|
pollDelay = 2000;
|
|
224
|
-
|
|
235
|
+
const name = error instanceof Error ? error.name : "";
|
|
236
|
+
if (errorNetwork(error) || name === "AbortError" || name === "TimeoutError")
|
|
225
237
|
scheduleRecovery();
|
|
226
238
|
}
|
|
227
239
|
}
|
|
@@ -233,13 +245,16 @@ export function initMessagePolling(app, isUnreadMessage) {
|
|
|
233
245
|
const room = await app.api(`/rooms/${encodeURIComponent(roomId)}`);
|
|
234
246
|
if (!isCurrentPoll(roomId, generation))
|
|
235
247
|
return;
|
|
248
|
+
const active = app.state.room;
|
|
249
|
+
if (!active)
|
|
250
|
+
return;
|
|
236
251
|
app.setOnline(true);
|
|
237
|
-
const before = JSON.stringify([
|
|
252
|
+
const before = JSON.stringify([active.ownerId, active.adminIds ?? [], active.successorId ?? null, active.adminSessionID ?? null]);
|
|
238
253
|
const openQuestions = Number(room.openQuestions);
|
|
239
|
-
Object.assign(
|
|
254
|
+
Object.assign(active, { participants: room.participants, ownerId: room.ownerId ?? active.ownerId, adminIds: room.adminIds ?? [], successorId: room.successorId ?? null, adminSessionID: room.adminSessionID ?? null, openQuestions: Number.isFinite(openQuestions) ? Math.max(0, openQuestions) : active.openQuestions });
|
|
240
255
|
if (Number.isFinite(openQuestions))
|
|
241
256
|
app.updateQuestionBadge?.(openQuestions);
|
|
242
|
-
if (JSON.stringify([
|
|
257
|
+
if (JSON.stringify([active.ownerId, active.adminIds ?? [], active.successorId ?? null, active.adminSessionID ?? null]) !== before) {
|
|
243
258
|
app.renderHead();
|
|
244
259
|
app.rerenderMessages();
|
|
245
260
|
}
|
|
@@ -253,15 +268,19 @@ export function initMessagePolling(app, isUnreadMessage) {
|
|
|
253
268
|
const room = await app.api(`/rooms/${encodeURIComponent(roomId)}`);
|
|
254
269
|
if (!isCurrentPoll(roomId, generation))
|
|
255
270
|
return;
|
|
271
|
+
const active = app.state.room;
|
|
272
|
+
if (!active)
|
|
273
|
+
return;
|
|
256
274
|
app.setOnline(true);
|
|
257
275
|
if (entry && Number.isFinite(Number(room.recallVersion)))
|
|
258
276
|
entry.recallVersion = Number(room.recallVersion);
|
|
259
|
-
const current =
|
|
277
|
+
const current = active.messages;
|
|
278
|
+
const fetched = room.messages ?? [];
|
|
260
279
|
const ids = new Set(current.map((message) => message.id));
|
|
261
|
-
const missing =
|
|
280
|
+
const missing = fetched.filter((message) => !ids.has(message.id));
|
|
262
281
|
// History carries recall state; patch rows whose live recall event was missed.
|
|
263
282
|
let recalled = false;
|
|
264
|
-
for (const message of
|
|
283
|
+
for (const message of fetched) {
|
|
265
284
|
if (message.recalledAt && app.applyRecall?.(roomId, { messageID: message.id, recalledAt: message.recalledAt, recalledBy: message.recalledBy }))
|
|
266
285
|
recalled = true;
|
|
267
286
|
}
|
|
@@ -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.
|
|
@@ -40,7 +42,7 @@ export function flashMessageRow(app, row) {
|
|
|
40
42
|
row.classList.remove("jump-flash");
|
|
41
43
|
void row.offsetWidth;
|
|
42
44
|
row.classList.add("jump-flash");
|
|
43
|
-
row._jumpFlashTimer = setTimeout(() => row.classList.remove("jump-flash"), 900);
|
|
45
|
+
row._jumpFlashTimer = window.setTimeout(() => row.classList.remove("jump-flash"), 900);
|
|
44
46
|
app.updateJump?.();
|
|
45
47
|
}
|
|
46
48
|
// Resolve app.state.focusMessageId against the loaded state and rendered rows.
|
|
@@ -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() || "?";
|
|
@@ -258,8 +264,12 @@ export function initMessages(app) {
|
|
|
258
264
|
const content = document.createElement("div");
|
|
259
265
|
content.className = "msg-content";
|
|
260
266
|
content.append(body);
|
|
261
|
-
if (!message.pending)
|
|
262
|
-
|
|
267
|
+
if (!message.pending) {
|
|
268
|
+
const stack = document.createElement("div");
|
|
269
|
+
stack.className = "msg-receipt-stack";
|
|
270
|
+
stack.append(app.createReceiptButton(message, own));
|
|
271
|
+
content.append(stack);
|
|
272
|
+
}
|
|
263
273
|
row.append(meta, content);
|
|
264
274
|
}
|
|
265
275
|
if (message.senderId !== "system") {
|
|
@@ -291,7 +301,10 @@ export function initMessages(app) {
|
|
|
291
301
|
return row;
|
|
292
302
|
};
|
|
293
303
|
app.renderMessages = (live = false, tailLimit = 0) => {
|
|
294
|
-
const
|
|
304
|
+
const room = app.state.room;
|
|
305
|
+
if (!room)
|
|
306
|
+
return { skipped: 0 };
|
|
307
|
+
const thread = $("#thread"), list = $("#msgList"), messages = room.messages;
|
|
295
308
|
// A palette jump renders a window around the target instead of the newest
|
|
296
309
|
// tail. While that window is up, live appends stay off screen so the target
|
|
297
310
|
// is not trimmed away.
|
|
@@ -304,8 +317,8 @@ export function initMessages(app) {
|
|
|
304
317
|
let skipped = 0;
|
|
305
318
|
let anchorId = null, anchorOffset = 0, oldTop = thread.scrollTop;
|
|
306
319
|
const viewport = thread.getBoundingClientRect();
|
|
307
|
-
const firstVisible = [...list.children].find((node) => node.
|
|
308
|
-
anchorId = firstVisible?.
|
|
320
|
+
const firstVisible = [...list.children].find((node) => node.getAttribute("data-msg-id") && node.getBoundingClientRect().bottom > viewport.top);
|
|
321
|
+
anchorId = firstVisible?.getAttribute("data-msg-id") || null;
|
|
309
322
|
anchorOffset = firstVisible ? firstVisible.getBoundingClientRect().top - viewport.top : 0;
|
|
310
323
|
if (focus) {
|
|
311
324
|
// Start a fresh window containing the target, wherever it sits in the
|
|
@@ -320,7 +333,7 @@ export function initMessages(app) {
|
|
|
320
333
|
const lastId = [...list.querySelectorAll("[data-msg-id]")].at(-1)?.dataset.msgId;
|
|
321
334
|
if (lastId)
|
|
322
335
|
for (let index = messages.length - 1; index >= 0; index--)
|
|
323
|
-
if (messages[index]
|
|
336
|
+
if (messages[index]?.id === lastId) {
|
|
324
337
|
startIndex = index + 1;
|
|
325
338
|
break;
|
|
326
339
|
}
|
|
@@ -328,11 +341,13 @@ export function initMessages(app) {
|
|
|
328
341
|
const renderEnd = focus ? Math.min(messages.length, focus.index + 120) : messages.length;
|
|
329
342
|
for (let index = renderStart; index < renderEnd; index++) {
|
|
330
343
|
const message = messages[index];
|
|
344
|
+
if (!message)
|
|
345
|
+
break;
|
|
331
346
|
if (renderedIds.has(message.id) || app.failedRenderIds.has(message.id))
|
|
332
347
|
continue;
|
|
333
348
|
try {
|
|
334
349
|
const day = new Date(message.createdAt).toDateString();
|
|
335
|
-
if (!last || last.
|
|
350
|
+
if (!last || last.getAttribute("data-day") !== day) {
|
|
336
351
|
const separator = document.createElement("li");
|
|
337
352
|
separator.className = "day-sep";
|
|
338
353
|
separator.dataset.day = day;
|
|
@@ -342,9 +357,17 @@ export function initMessages(app) {
|
|
|
342
357
|
}
|
|
343
358
|
const row = app.renderMessage(message, live);
|
|
344
359
|
row.dataset.day = day;
|
|
345
|
-
if (last.classList.contains("msg") && last.
|
|
346
|
-
&& message.createdAt - Number(last.
|
|
360
|
+
if (last.classList.contains("msg") && last.getAttribute("data-sender") === message.senderId
|
|
361
|
+
&& message.createdAt - Number(last.getAttribute("data-ts")) < 8 * 60 * 1000)
|
|
347
362
|
row.classList.add("repeat");
|
|
363
|
+
if (row.classList.contains("repeat")) {
|
|
364
|
+
// A grouped row shows its own clock beside the badge, not a meta line.
|
|
365
|
+
const time = row.querySelector(".msg-time"), stack = row.querySelector(".msg-receipt-stack");
|
|
366
|
+
if (time && stack) {
|
|
367
|
+
time.textContent = app.timeHM(message.createdAt);
|
|
368
|
+
stack.prepend(time);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
348
371
|
list.append(row);
|
|
349
372
|
last = row;
|
|
350
373
|
renderedIds.add(message.id);
|
|
@@ -407,7 +430,7 @@ export function initMessages(app) {
|
|
|
407
430
|
app.firstMessageId = null;
|
|
408
431
|
app.failedRenderIds.clear();
|
|
409
432
|
const result = app.renderMessages(false);
|
|
410
|
-
const nextAnchor = anchorId
|
|
433
|
+
const nextAnchor = anchorId ? list.querySelector(`[data-msg-id="${CSS.escape(anchorId)}"]`) : null;
|
|
411
434
|
if (atBottom)
|
|
412
435
|
thread.scrollTop = thread.scrollHeight;
|
|
413
436
|
else if (nextAnchor)
|
|
@@ -417,7 +440,7 @@ export function initMessages(app) {
|
|
|
417
440
|
return result;
|
|
418
441
|
};
|
|
419
442
|
app.send = async () => {
|
|
420
|
-
const
|
|
443
|
+
const room = app.state.room, replyTarget = room && app.replyTargetFor?.(room.id);
|
|
421
444
|
if (!room || app.state.sendingRooms?.has(room.id))
|
|
422
445
|
return false;
|
|
423
446
|
const message = app.prepareMessage?.(room.id, input.value) || { text: input.value.trim(), ids: [], ready: Boolean(input.value.trim()) };
|
|
@@ -431,14 +454,14 @@ export function initMessages(app) {
|
|
|
431
454
|
const thread = $("#thread"), followedBottom = thread.scrollHeight - thread.scrollTop - thread.clientHeight < 80;
|
|
432
455
|
const revision = app.state.draftRevision.get(room.id) || 0;
|
|
433
456
|
app.state.sendingRooms ||= new Set();
|
|
434
|
-
app.state.sendingRooms
|
|
457
|
+
app.state.sendingRooms?.add(room.id);
|
|
435
458
|
app.closeMention();
|
|
436
459
|
app.clearReplyTarget?.(room.id);
|
|
437
460
|
input.value = "";
|
|
438
461
|
app.clearDraft(room.id);
|
|
439
|
-
|
|
440
|
-
app.updateDraftCount();
|
|
441
|
-
app.updateSendState();
|
|
462
|
+
autoGrow(input);
|
|
463
|
+
app.updateDraftCount?.();
|
|
464
|
+
app.updateSendState?.();
|
|
442
465
|
app.hideSendError();
|
|
443
466
|
const pending = {
|
|
444
467
|
id: `pending-${createRandomId()}`, roomId: room.id, text,
|
|
@@ -501,6 +524,7 @@ export function initMessages(app) {
|
|
|
501
524
|
return true;
|
|
502
525
|
}
|
|
503
526
|
catch (error) {
|
|
527
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
504
528
|
const pendingIndex = room.messages.findIndex((item) => item.id === pending.id);
|
|
505
529
|
if (pendingIndex >= 0)
|
|
506
530
|
room.messages.splice(pendingIndex, 1);
|
|
@@ -509,13 +533,13 @@ export function initMessages(app) {
|
|
|
509
533
|
const unchanged = (app.state.draftRevision.get(room.id) || 0) === revision;
|
|
510
534
|
// Someone answered the question first; retrying the answer can never succeed,
|
|
511
535
|
// so keep the text as a draft instead of a failed message.
|
|
512
|
-
const staleReply = Boolean(replyTarget?.isQuestion) && (
|
|
536
|
+
const staleReply = Boolean(replyTarget?.isQuestion) && (failure.status === 409 || failure.status === 404);
|
|
513
537
|
if (staleReply)
|
|
514
538
|
app.saveDraft(room.id, text);
|
|
515
539
|
else {
|
|
516
540
|
const failures = app.state.failedMessages.get(room.id) || [];
|
|
517
541
|
app.saveFailedMessages(room.id, [...failures, { id: createRandomId(), text, clientMessageID, ...(replyTarget ? { replyToMessageID: replyTarget.id, replyTarget } : {}) }]);
|
|
518
|
-
app.renderFailedMessages();
|
|
542
|
+
app.renderFailedMessages?.();
|
|
519
543
|
}
|
|
520
544
|
app.completeAttachments?.(room.id, message.ids);
|
|
521
545
|
if (app.state.room?.id !== room.id)
|
|
@@ -524,21 +548,21 @@ export function initMessages(app) {
|
|
|
524
548
|
app.clearDraft(room.id);
|
|
525
549
|
if (staleReply)
|
|
526
550
|
input.draftValue = text;
|
|
527
|
-
|
|
528
|
-
app.updateSendState();
|
|
529
|
-
app.updateDraftCount();
|
|
530
|
-
if (
|
|
551
|
+
autoGrow(input);
|
|
552
|
+
app.updateSendState?.();
|
|
553
|
+
app.updateDraftCount?.();
|
|
554
|
+
if (failure.status === 401) {
|
|
531
555
|
app.openChatSettings();
|
|
532
556
|
app.showSendError("sendAuth");
|
|
533
557
|
}
|
|
534
558
|
else
|
|
535
|
-
app.showSendError(
|
|
559
|
+
app.showSendError(failure.network ? "sendNetwork" : "sendFailed", { message: failure.message });
|
|
536
560
|
return false;
|
|
537
561
|
}
|
|
538
562
|
finally {
|
|
539
|
-
app.state.sendingRooms
|
|
563
|
+
app.state.sendingRooms?.delete(room.id);
|
|
540
564
|
if (app.state.room?.id === room.id)
|
|
541
|
-
app.updateSendState();
|
|
565
|
+
app.updateSendState?.();
|
|
542
566
|
}
|
|
543
567
|
};
|
|
544
568
|
function failedAction(key, roomId, failedId, app) {
|
|
@@ -562,8 +586,8 @@ export function isUnreadMessage(message, app, room = app.state.room, myName = ap
|
|
|
562
586
|
return message.senderId !== "system" && !isOwnMessage(message, app, room, myName);
|
|
563
587
|
}
|
|
564
588
|
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);
|
|
589
|
+
const direct = room?.kind === "direct";
|
|
590
|
+
const sameName = room ? app.state.memberSessions.get(room.id)?.filter((member) => member.name === message.senderId) : undefined;
|
|
567
591
|
return direct ? message.senderId === LS.sessionID
|
|
568
592
|
: message.senderSessionID ? message.senderSessionID === LS.sessionID
|
|
569
593
|
// Without a recorded sender session, fall back to the name unless a namesake is known.
|
|
@@ -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) {
|