@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,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");
|
|
@@ -266,7 +280,7 @@ export function initPalette(app) {
|
|
|
266
280
|
}
|
|
267
281
|
status.textContent = t("paletteSearching");
|
|
268
282
|
const text = value.trim();
|
|
269
|
-
searchTimer = setTimeout(() => { void executeSearch(text, token); }, SEARCH_DEBOUNCE_MS);
|
|
283
|
+
searchTimer = window.setTimeout(() => { void executeSearch(text, token); }, SEARCH_DEBOUNCE_MS);
|
|
270
284
|
};
|
|
271
285
|
const highlightHit = (item) => {
|
|
272
286
|
if (!item?.messageId)
|
|
@@ -279,7 +293,7 @@ export function initPalette(app) {
|
|
|
279
293
|
if (row) {
|
|
280
294
|
row.scrollIntoView({ block: "center", behavior: matchMedia("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth" });
|
|
281
295
|
row.classList.add("palette-hit");
|
|
282
|
-
hitTimer = setTimeout(() => row.classList.remove("palette-hit"), 4000);
|
|
296
|
+
hitTimer = window.setTimeout(() => row.classList.remove("palette-hit"), 4000);
|
|
283
297
|
return;
|
|
284
298
|
}
|
|
285
299
|
if (++attempts < 50)
|
|
@@ -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.
|
|
@@ -414,7 +428,9 @@ export function initPalette(app) {
|
|
|
414
428
|
if (!items.length || selected < 0)
|
|
415
429
|
return;
|
|
416
430
|
event.preventDefault();
|
|
417
|
-
|
|
431
|
+
const item = items[selected];
|
|
432
|
+
if (item)
|
|
433
|
+
activate(item);
|
|
418
434
|
return;
|
|
419
435
|
}
|
|
420
436
|
if (event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey) {
|
|
@@ -1,7 +1,25 @@
|
|
|
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)";
|
|
4
|
+
// A press and release both on the backdrop closes. The backdrop hit-tests as the
|
|
5
|
+
// dialog itself, so the box check keeps a click on the dialog padding inside, and
|
|
6
|
+
// the press check keeps a drag that started inside from dismissing on release.
|
|
7
|
+
export function closeOnBackdrop(dialog, close) {
|
|
8
|
+
const outside = (event) => {
|
|
9
|
+
const box = dialog.getBoundingClientRect();
|
|
10
|
+
return event.clientX < box.left || event.clientX > box.right || event.clientY < box.top || event.clientY > box.bottom;
|
|
11
|
+
};
|
|
12
|
+
let pressedOutside = false;
|
|
13
|
+
dialog.addEventListener("pointerdown", (event) => {
|
|
14
|
+
pressedOutside = event.target === dialog && outside(event);
|
|
15
|
+
});
|
|
16
|
+
dialog.addEventListener("click", (event) => {
|
|
17
|
+
const dismiss = pressedOutside && event.target === dialog && outside(event);
|
|
18
|
+
pressedOutside = false;
|
|
19
|
+
if (dismiss && dialog.open)
|
|
20
|
+
close();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
5
23
|
export function initPanels(app) {
|
|
6
24
|
const $ = app.$;
|
|
7
25
|
const pane = matchMedia(PANE_QUERY);
|
|
@@ -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";
|
|
@@ -180,9 +182,10 @@ export function initQuestions(app) {
|
|
|
180
182
|
const author = question.senderSessionID
|
|
181
183
|
? members.filter((member) => member.sessionID === question.senderSessionID)
|
|
182
184
|
: members.filter((member) => member.name === question.senderId);
|
|
183
|
-
|
|
185
|
+
const only = author.length === 1 ? author[0] : undefined;
|
|
186
|
+
if (!only || members.filter((member) => member.name === only.name).length !== 1 || only.sessionID === LS.sessionID || only.name === "all")
|
|
184
187
|
return "";
|
|
185
|
-
return autoMentionDraft(
|
|
188
|
+
return autoMentionDraft(only.name);
|
|
186
189
|
}
|
|
187
190
|
async function load(roomId = app.state.room?.id) {
|
|
188
191
|
if (!roomId)
|
|
@@ -217,7 +220,7 @@ export function initQuestions(app) {
|
|
|
217
220
|
catch (error) {
|
|
218
221
|
if (id !== request || app.state.room?.id !== roomId)
|
|
219
222
|
return;
|
|
220
|
-
if (error
|
|
223
|
+
if (statusOf(error) === 404) {
|
|
221
224
|
const member = await roomMembership(roomId);
|
|
222
225
|
if (id !== request || app.state.room?.id !== roomId)
|
|
223
226
|
return;
|
|
@@ -231,7 +234,7 @@ export function initQuestions(app) {
|
|
|
231
234
|
showFailed();
|
|
232
235
|
return;
|
|
233
236
|
}
|
|
234
|
-
if (error
|
|
237
|
+
if (statusOf(error) === 401)
|
|
235
238
|
app.openChatSettings();
|
|
236
239
|
showFailed();
|
|
237
240
|
render(roomId);
|
|
@@ -257,10 +260,9 @@ export function initQuestions(app) {
|
|
|
257
260
|
method: "POST", body: JSON.stringify({ sessionID: LS.sessionID, text }),
|
|
258
261
|
});
|
|
259
262
|
applyAnswer(roomId, questionId, result);
|
|
260
|
-
return result;
|
|
261
263
|
}
|
|
262
264
|
catch (error) {
|
|
263
|
-
if (error
|
|
265
|
+
if (statusOf(error) === 409 || statusOf(error) === 404)
|
|
264
266
|
await load(roomId);
|
|
265
267
|
throw error;
|
|
266
268
|
}
|
|
@@ -285,9 +287,9 @@ export function initQuestions(app) {
|
|
|
285
287
|
void load(roomId);
|
|
286
288
|
}
|
|
287
289
|
catch (error) {
|
|
288
|
-
if (error
|
|
290
|
+
if (statusOf(error) === 409 || statusOf(error) === 404) {
|
|
289
291
|
await load(roomId);
|
|
290
|
-
if (error
|
|
292
|
+
if (statusOf(error) === 409 && app.state.room?.id === roomId && !itemsFor(roomId).some((item) => item.id === questionId)) {
|
|
291
293
|
if (selected.get(roomId) === questionId)
|
|
292
294
|
selected.delete(roomId);
|
|
293
295
|
drafts.delete(`${roomId}\0${questionId}`);
|
|
@@ -297,7 +299,7 @@ export function initQuestions(app) {
|
|
|
297
299
|
render(roomId);
|
|
298
300
|
}
|
|
299
301
|
}
|
|
300
|
-
else if (error
|
|
302
|
+
else if (statusOf(error) === 401 && app.state.room?.id === roomId) {
|
|
301
303
|
app.openChatSettings();
|
|
302
304
|
app.showSendError("sendAuth");
|
|
303
305
|
}
|
|
@@ -313,21 +315,21 @@ export function initQuestions(app) {
|
|
|
313
315
|
}
|
|
314
316
|
}
|
|
315
317
|
function applyAnswer(roomId, questionId, result) {
|
|
316
|
-
const entry = app.state.rooms.get(roomId);
|
|
317
|
-
if (entry &&
|
|
318
|
+
const entry = app.state.rooms.get(roomId), answer = result.answer;
|
|
319
|
+
if (entry && answer) {
|
|
318
320
|
const question = entry.room.messages.find((item) => item.id === questionId);
|
|
319
321
|
if (question)
|
|
320
|
-
question.answeredByMessageID =
|
|
322
|
+
question.answeredByMessageID = answer.id;
|
|
321
323
|
}
|
|
322
|
-
if (entry &&
|
|
323
|
-
entry.room.messages.push({ ...
|
|
324
|
+
if (entry && answer && !entry.room.messages.some((item) => item.id === answer.id)) {
|
|
325
|
+
entry.room.messages.push({ ...answer, roomId });
|
|
324
326
|
entry.room.messages.sort((a, b) => a.createdAt - b.createdAt);
|
|
325
327
|
if (entry.room.messages.length > LOADED_MESSAGE_LIMIT)
|
|
326
328
|
entry.room.messages.splice(0, entry.room.messages.length - LOADED_MESSAGE_LIMIT);
|
|
327
329
|
if (app.state.room?.id === roomId)
|
|
328
330
|
app.renderMessages(true);
|
|
329
331
|
}
|
|
330
|
-
pending.set(roomId, (
|
|
332
|
+
pending.set(roomId, itemsFor(roomId).filter((item) => item.id !== (result.questionID || questionId)));
|
|
331
333
|
if (selected.get(roomId) === questionId)
|
|
332
334
|
selected.delete(roomId);
|
|
333
335
|
drafts.delete(`${roomId}\0${questionId}`);
|
|
@@ -347,8 +349,9 @@ export function initQuestions(app) {
|
|
|
347
349
|
$("#btnRefreshQuestions").addEventListener("click", () => void load());
|
|
348
350
|
list.addEventListener("click", (event) => {
|
|
349
351
|
event.stopPropagation();
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
353
|
+
const card = target?.closest(".question-item[data-question-id]"), select = target?.closest(".question-select");
|
|
354
|
+
if (!card || (!select && target?.closest("a, button, input, textarea, select, [contenteditable=true]")) || !app.state.room)
|
|
352
355
|
return;
|
|
353
356
|
selected.set(app.state.room.id, card.dataset.questionId);
|
|
354
357
|
render(app.state.room.id);
|
|
@@ -6,13 +6,19 @@ import { formatSystemMessage, setRoomPreview } from "./system-messages.js";
|
|
|
6
6
|
import { icon } from "./icons.js";
|
|
7
7
|
const RECALL_ICON = icon("arrow_undo", "message-recall-icon");
|
|
8
8
|
const RECALLED_ICON = icon("arrow_undo", "recalled-icon");
|
|
9
|
+
const chatError = (error) => error instanceof Error ? error : new Error(String(error));
|
|
10
|
+
const closestElement = (target, selector) => {
|
|
11
|
+
const element = target instanceof Element ? target.closest(selector) : null;
|
|
12
|
+
return element instanceof HTMLElement ? element : null;
|
|
13
|
+
};
|
|
9
14
|
// Recall is a soft hide: the server keeps the text and members may reveal it.
|
|
10
15
|
export function initRecall(app) {
|
|
11
16
|
const $ = app.$, base = app.renderMessage;
|
|
12
17
|
app.canRecallMessage = (message) => {
|
|
13
18
|
if (!message || message.recalledAt || message.pending)
|
|
14
19
|
return false;
|
|
15
|
-
const
|
|
20
|
+
const room = app.state.room;
|
|
21
|
+
const self = room ? app.state.memberSessions.get(room.id)?.find((member) => member.sessionID === LS.sessionID) : undefined;
|
|
16
22
|
// Member data may not have loaded yet; the server re-checks the real membership.
|
|
17
23
|
const humanAdmin = (!self || self.type === "human") && isRoomAdmin(app);
|
|
18
24
|
if (message.senderId === "system")
|
|
@@ -32,22 +38,25 @@ export function initRecall(app) {
|
|
|
32
38
|
row.querySelector(".message-actions")?.append(recallButton(message, app));
|
|
33
39
|
return row;
|
|
34
40
|
};
|
|
35
|
-
$("#msgList")
|
|
36
|
-
|
|
41
|
+
const msgList = $("#msgList");
|
|
42
|
+
if (!msgList)
|
|
43
|
+
return;
|
|
44
|
+
msgList.addEventListener("click", (event) => {
|
|
45
|
+
const recallTarget = closestElement(event.target, "[data-recall-message]");
|
|
37
46
|
if (recallTarget && app.state.room) {
|
|
38
47
|
const message = app.state.room.messages.find((item) => item.id === recallTarget.dataset.recallMessage);
|
|
39
48
|
if (message)
|
|
40
49
|
void recall(message, recallTarget, app);
|
|
41
50
|
return;
|
|
42
51
|
}
|
|
43
|
-
const revealTarget = event.target
|
|
52
|
+
const revealTarget = closestElement(event.target, "[data-reveal-message]");
|
|
44
53
|
if (revealTarget && app.state.room) {
|
|
45
54
|
const message = app.state.room.messages.find((item) => item.id === revealTarget.dataset.revealMessage);
|
|
46
55
|
if (message)
|
|
47
56
|
void toggleOriginal(revealTarget, message, app);
|
|
48
57
|
return;
|
|
49
58
|
}
|
|
50
|
-
const reeditTarget = event.target
|
|
59
|
+
const reeditTarget = closestElement(event.target, "[data-reedit-message]");
|
|
51
60
|
if (reeditTarget && app.state.room) {
|
|
52
61
|
const message = app.state.room.messages.find((item) => item.id === reeditTarget.dataset.reeditMessage);
|
|
53
62
|
if (message)
|
|
@@ -64,7 +73,7 @@ async function syncLoadedHistory(roomId, generation, app) {
|
|
|
64
73
|
const entry = app.state.rooms.get(roomId), room = entry?.room;
|
|
65
74
|
if (!entry || !room || entry.historySync)
|
|
66
75
|
return false;
|
|
67
|
-
const seqs = room.messages.map((message) => message.seq).filter(Number.isSafeInteger);
|
|
76
|
+
const seqs = room.messages.map((message) => message.seq).filter((seq) => Number.isSafeInteger(seq));
|
|
68
77
|
if (seqs.length < 2)
|
|
69
78
|
return false;
|
|
70
79
|
const oldest = Math.min(...seqs), newest = Math.max(...seqs);
|
|
@@ -77,7 +86,7 @@ async function syncLoadedHistory(roomId, generation, app) {
|
|
|
77
86
|
if (app.state.room?.id !== roomId || app.state.pollGeneration !== generation)
|
|
78
87
|
return changed;
|
|
79
88
|
const messages = Array.isArray(result.messages) ? result.messages : [];
|
|
80
|
-
const next = Math.min(...messages.map((message) => message.seq).filter(Number.isSafeInteger));
|
|
89
|
+
const next = Math.min(...messages.map((message) => message.seq).filter((seq) => Number.isSafeInteger(seq)));
|
|
81
90
|
for (const message of messages) {
|
|
82
91
|
if (!message.recalledAt)
|
|
83
92
|
continue;
|
|
@@ -118,7 +127,8 @@ function applyRecall(roomId, event, app) {
|
|
|
118
127
|
if (app.replyTargetFor?.(roomId)?.id === messageID)
|
|
119
128
|
app.setReplyTarget(roomId, null);
|
|
120
129
|
if (app.state.room?.id === roomId) {
|
|
121
|
-
const
|
|
130
|
+
const list = app.$("#msgList");
|
|
131
|
+
const row = list?.querySelector(`[data-msg-id="${CSS.escape(messageID)}"]`);
|
|
122
132
|
if (row) {
|
|
123
133
|
const keepFocus = row.contains(document.activeElement);
|
|
124
134
|
renderTombstone(row, message, app, changed);
|
|
@@ -127,7 +137,7 @@ function applyRecall(roomId, event, app) {
|
|
|
127
137
|
row.querySelector("[data-reveal-message]")?.focus({ preventScroll: true });
|
|
128
138
|
}
|
|
129
139
|
// Replies that quoted this message must not keep showing its text.
|
|
130
|
-
const quote =
|
|
140
|
+
const quote = list?.querySelector(`.reply-quote[data-reply-target-id="${CSS.escape(messageID)}"]`);
|
|
131
141
|
if (quote)
|
|
132
142
|
quote.textContent = app.t("replyOriginalRecalled");
|
|
133
143
|
if (hadUnread || changed) {
|
|
@@ -137,8 +147,11 @@ function applyRecall(roomId, event, app) {
|
|
|
137
147
|
}
|
|
138
148
|
}
|
|
139
149
|
if (hadUnread || changed) {
|
|
140
|
-
|
|
141
|
-
|
|
150
|
+
for (const selector of ["#roomList", "#roomListChat"]) {
|
|
151
|
+
const list = app.$(selector);
|
|
152
|
+
if (list)
|
|
153
|
+
app.renderRoomOptions?.(list, app.state.availableRooms || []);
|
|
154
|
+
}
|
|
142
155
|
}
|
|
143
156
|
return changed;
|
|
144
157
|
}
|
|
@@ -177,19 +190,20 @@ async function recall(message, button, app) {
|
|
|
177
190
|
const result = await app.api(`/rooms/${encodeURIComponent(roomId)}/messages/${encodeURIComponent(message.id)}/recall`, {
|
|
178
191
|
method: "POST", body: JSON.stringify({ sessionID: LS.sessionID }),
|
|
179
192
|
});
|
|
180
|
-
const detail = result?.message
|
|
193
|
+
const detail = result?.message;
|
|
181
194
|
app.applyRecall(roomId, {
|
|
182
195
|
messageID: typeof result?.messageID === "string" ? result.messageID : message.id,
|
|
183
|
-
recalledAt: Number(result?.recalledAt ?? detail
|
|
196
|
+
recalledAt: Number(result?.recalledAt ?? detail?.recalledAt) || Date.now(),
|
|
184
197
|
recalledBy: typeof result?.recalledBy === "string" ? result.recalledBy
|
|
185
|
-
: typeof detail
|
|
198
|
+
: typeof detail?.recalledBy === "string" ? detail.recalledBy : app.state.myName,
|
|
186
199
|
});
|
|
187
200
|
}
|
|
188
201
|
catch (error) {
|
|
202
|
+
const failure = chatError(error);
|
|
189
203
|
button.disabled = false;
|
|
190
|
-
if (
|
|
204
|
+
if (failure.status === 401)
|
|
191
205
|
app.openChatSettings();
|
|
192
|
-
app.showSendError(
|
|
206
|
+
app.showSendError(failure.status === 401 ? "sendAuth" : "recallFailed", { message: failure.message });
|
|
193
207
|
}
|
|
194
208
|
}
|
|
195
209
|
function renderTombstone(row, message, app, live) {
|
|
@@ -287,6 +301,7 @@ function fillRevealed(body, message, text, app) {
|
|
|
287
301
|
body.textContent = "";
|
|
288
302
|
if (message.senderId === "system")
|
|
289
303
|
body.textContent = formatSystemMessage({ senderId: "system", text }, app);
|
|
304
|
+
// app-types declares markdown's preview/layout callbacks narrower than the runtime ones.
|
|
290
305
|
else
|
|
291
306
|
renderMarkdown(body, text, app);
|
|
292
307
|
}
|
|
@@ -326,6 +341,8 @@ async function loadOriginalText(message, app) {
|
|
|
326
341
|
if (message._revealedText !== undefined)
|
|
327
342
|
return message._revealedText;
|
|
328
343
|
const roomId = app.state.room?.id;
|
|
344
|
+
if (!roomId)
|
|
345
|
+
throw new Error(app.t("revealFailed"));
|
|
329
346
|
const result = await app.api(`/rooms/${encodeURIComponent(roomId)}/messages/${encodeURIComponent(message.id)}/content?sessionID=${encodeURIComponent(LS.sessionID)}`);
|
|
330
347
|
const text = typeof result?.message?.text === "string" ? result.message.text : typeof result?.text === "string" ? result.text : undefined;
|
|
331
348
|
if (text === undefined)
|
|
@@ -346,9 +363,9 @@ async function reedit(message, button, app) {
|
|
|
346
363
|
return;
|
|
347
364
|
input.draftValue = text;
|
|
348
365
|
app.saveDraft(roomId, text);
|
|
349
|
-
app.autoGrow(input);
|
|
350
|
-
app.updateDraftCount();
|
|
351
|
-
app.updateSendState();
|
|
366
|
+
app.autoGrow?.(input);
|
|
367
|
+
app.updateDraftCount?.();
|
|
368
|
+
app.updateSendState?.();
|
|
352
369
|
// A click is explicit intent, so focus the editor even on touch layouts.
|
|
353
370
|
if (!app.focusChatComposer({ force: true })) {
|
|
354
371
|
input.focus({ preventScroll: true });
|
|
@@ -356,9 +373,10 @@ async function reedit(message, button, app) {
|
|
|
356
373
|
}
|
|
357
374
|
}
|
|
358
375
|
catch (error) {
|
|
359
|
-
|
|
376
|
+
const failure = chatError(error);
|
|
377
|
+
if (failure.status === 401)
|
|
360
378
|
app.openChatSettings();
|
|
361
|
-
app.showSendError(
|
|
379
|
+
app.showSendError(failure.status === 401 ? "sendAuth" : "revealFailed", { message: failure.message });
|
|
362
380
|
}
|
|
363
381
|
finally {
|
|
364
382
|
button.disabled = false;
|
|
@@ -40,17 +40,18 @@ export function initReceipts(app) {
|
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
$("#msgList").addEventListener("click", (event) => {
|
|
43
|
-
const button = event.target.closest(".message-readers");
|
|
43
|
+
const button = event.target instanceof Element ? event.target.closest(".message-readers") : null;
|
|
44
44
|
if (!button)
|
|
45
45
|
return;
|
|
46
46
|
if (selectedID === button.dataset.messageId)
|
|
47
47
|
close(true);
|
|
48
48
|
else
|
|
49
|
-
open(button.dataset.messageId, button);
|
|
49
|
+
open(button.dataset.messageId || "", button);
|
|
50
50
|
});
|
|
51
51
|
$("#btnCloseReaders").addEventListener("click", () => close(true));
|
|
52
52
|
document.addEventListener("click", (event) => {
|
|
53
|
-
|
|
53
|
+
const target = event.target;
|
|
54
|
+
if (selectedID && !(target instanceof Element && target.closest("#readerPanel, .message-readers")))
|
|
54
55
|
close(false);
|
|
55
56
|
});
|
|
56
57
|
document.addEventListener("keydown", (event) => {
|
|
@@ -102,14 +103,15 @@ export function initReceipts(app) {
|
|
|
102
103
|
panel.style.top = `${top}px`;
|
|
103
104
|
}
|
|
104
105
|
function renderPanel() {
|
|
105
|
-
const
|
|
106
|
-
|
|
106
|
+
const room = app.state.room;
|
|
107
|
+
const message = room?.messages.find((item) => item.id === selectedID);
|
|
108
|
+
if (!room || !message)
|
|
107
109
|
return close(false);
|
|
108
110
|
const readers = readersFor(message);
|
|
109
111
|
$("#readerCount").textContent = readerStatus(message, readers);
|
|
110
112
|
const list = $("#readerList");
|
|
111
113
|
list.textContent = "";
|
|
112
|
-
const members = app.state.memberSessions.get(
|
|
114
|
+
const members = app.state.memberSessions.get(room.id) || [];
|
|
113
115
|
for (const reader of readers) {
|
|
114
116
|
const row = document.createElement("li"), name = document.createElement("span"), evidence = document.createElement("span");
|
|
115
117
|
const duplicates = members.filter((member) => member.name === reader.name).length > 1 || readers.filter((item) => item.name === reader.name).length > 1;
|
|
@@ -136,7 +138,7 @@ export function initReceipts(app) {
|
|
|
136
138
|
}
|
|
137
139
|
function readByEveryone(message, readers) {
|
|
138
140
|
const senderID = message.senderSessionID || (app.state.room?.kind === "direct" ? message.senderId : "");
|
|
139
|
-
const eligible = (app.state.memberSessions.get(app.state.room?.id) || []).filter((member) => member.sessionID && member.sessionID !== senderID);
|
|
141
|
+
const eligible = (app.state.memberSessions.get(app.state.room?.id ?? "") || []).filter((member) => member.sessionID && member.sessionID !== senderID);
|
|
140
142
|
if (!eligible.length)
|
|
141
143
|
return false;
|
|
142
144
|
const seen = new Set(readers.map((reader) => reader.sessionID));
|