@alexsun-top/opencode-chat-room 0.8.3 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -1
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/package.json +6 -3
- package/server/assets/chat/admin-badge.js +1 -1
- package/server/assets/chat/admin.js +12 -9
- package/server/assets/chat/announcements.js +9 -2
- package/server/assets/chat/attachment-store.js +15 -6
- package/server/assets/chat/attachments.js +46 -31
- package/server/assets/chat/chat-background.js +8 -14
- package/server/assets/chat/clipboard.js +2 -1
- package/server/assets/chat/confirm-dialog.js +3 -3
- package/server/assets/chat/copy-action.js +0 -1
- package/server/assets/chat/diagram-viewer.js +7 -9
- package/server/assets/chat/doc-preview.js +18 -11
- package/server/assets/chat/editor.js +80 -58
- package/server/assets/chat/events.js +43 -30
- package/server/assets/chat/files.js +41 -13
- package/server/assets/chat/history-loader.js +5 -3
- package/server/assets/chat/image-zoom.js +21 -17
- package/server/assets/chat/install-prompt.js +10 -9
- package/server/assets/chat/integration-account-schema.js +5 -3
- package/server/assets/chat/integration-editor.js +0 -2
- package/server/assets/chat/integration-values.js +17 -11
- package/server/assets/chat/integrations.js +137 -80
- package/server/assets/chat/join-requests.js +19 -12
- package/server/assets/chat/markdown-footnotes.js +0 -1
- package/server/assets/chat/markdown.js +43 -34
- package/server/assets/chat/members.js +45 -22
- package/server/assets/chat/mentions.js +31 -7
- package/server/assets/chat/message-cache.js +1 -1
- package/server/assets/chat/message-polling.js +38 -19
- package/server/assets/chat/message-window.js +9 -5
- package/server/assets/chat/messages.js +53 -43
- package/server/assets/chat/palette.js +40 -26
- package/server/assets/chat/panels.js +0 -1
- package/server/assets/chat/pwa.js +5 -4
- package/server/assets/chat/questions.js +22 -20
- package/server/assets/chat/recall.js +39 -21
- package/server/assets/chat/receipts.js +9 -7
- package/server/assets/chat/reminders.js +22 -8
- package/server/assets/chat/replies.js +28 -12
- package/server/assets/chat/room-list.js +2 -2
- package/server/assets/chat/room-watcher.js +8 -4
- package/server/assets/chat/rooms.js +44 -36
- package/server/assets/chat/search.js +8 -6
- package/server/assets/chat/settings.js +12 -11
- package/server/assets/chat/shiki.js +1 -1
- package/server/assets/chat/shortcuts.js +0 -2
- package/server/assets/chat/side-pane.js +3 -2
- package/server/assets/chat/state.js +35 -26
- package/server/assets/chat/system-events.js +4 -4
- package/server/assets/chat/task-form.js +5 -5
- package/server/assets/chat/task-row.js +1 -1
- package/server/assets/chat/tasks.js +37 -25
- package/server/chat.html +1 -0
|
@@ -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));
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { LS } from "./state.js";
|
|
2
2
|
export function initReminders(app) {
|
|
3
|
-
const $ =
|
|
3
|
+
const $ = (selector) => {
|
|
4
|
+
const element = app.$(selector);
|
|
5
|
+
if (!element)
|
|
6
|
+
throw new Error(`Missing element: ${selector}`);
|
|
7
|
+
return element;
|
|
8
|
+
};
|
|
9
|
+
const surface = $("#remindersDialog"), trigger = $("#btnReminders"), list = $("#reminderList");
|
|
4
10
|
const dialog = $("#reminderDialog"), newButton = $("#btnNewReminder");
|
|
5
11
|
const heading = $("#reminderDialogHeading"), panelHeading = $("#reminderHeading"), submit = $("#btnSubmitReminder");
|
|
6
12
|
const chatView = $("#chatView");
|
|
@@ -91,7 +97,10 @@ export function initReminders(app) {
|
|
|
91
97
|
}
|
|
92
98
|
const current = (id, context) => roomId() === id && roomGeneration === context;
|
|
93
99
|
const invalidateLoads = () => { generation++; };
|
|
94
|
-
const errorText = (error) =>
|
|
100
|
+
const errorText = (error) => {
|
|
101
|
+
const failure = error instanceof Error ? error : null;
|
|
102
|
+
return failure?.message || app.t("requestFailed", { status: failure?.status || "?" });
|
|
103
|
+
};
|
|
95
104
|
function formDraft() {
|
|
96
105
|
return { type: $("#reminderType").value, at: $("#reminderAt").value, cron: $("#reminderCron").value, timezone: $("#reminderTimezone").value, text: $("#reminderText").value };
|
|
97
106
|
}
|
|
@@ -106,7 +115,7 @@ export function initReminders(app) {
|
|
|
106
115
|
// datetime-local has no zone; format the stored instant in its own zone so saving reproduces it.
|
|
107
116
|
function inputValue(iso, timezone) {
|
|
108
117
|
const parts = Object.fromEntries(new Intl.DateTimeFormat("en-CA", { timeZone: timezone, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", hourCycle: "h23" })
|
|
109
|
-
.formatToParts(new Date(iso)).map((part) => [part.type, part.value]));
|
|
118
|
+
.formatToParts(new Date(iso ?? "")).map((part) => [part.type, part.value]));
|
|
110
119
|
return `${parts.year}-${parts.month}-${parts.day}T${parts.hour}:${parts.minute}`;
|
|
111
120
|
}
|
|
112
121
|
function editDraft(reminder) {
|
|
@@ -117,7 +126,7 @@ export function initReminders(app) {
|
|
|
117
126
|
}
|
|
118
127
|
function formatTime(value, timezone) {
|
|
119
128
|
const effectiveZone = timezone || "UTC";
|
|
120
|
-
const formatted = new Intl.DateTimeFormat(undefined, { timeZone: effectiveZone, dateStyle: "medium", timeStyle: "short" }).format(new Date(value));
|
|
129
|
+
const formatted = new Intl.DateTimeFormat(undefined, { timeZone: effectiveZone, dateStyle: "medium", timeStyle: "short" }).format(new Date(value ?? ""));
|
|
121
130
|
return `${formatted} · ${effectiveZone}`;
|
|
122
131
|
}
|
|
123
132
|
function render() {
|
|
@@ -193,6 +202,8 @@ export function initReminders(app) {
|
|
|
193
202
|
}
|
|
194
203
|
async function update(reminder, paused) {
|
|
195
204
|
const id = roomId(), context = roomGeneration;
|
|
205
|
+
if (!id)
|
|
206
|
+
return;
|
|
196
207
|
try {
|
|
197
208
|
await app.api(`/rooms/${encodeURIComponent(id)}/reminders/${encodeURIComponent(reminder.id)}`, { method: "PATCH", body: JSON.stringify({ sessionID: LS.sessionID, paused }) });
|
|
198
209
|
if (current(id, context)) {
|
|
@@ -212,6 +223,8 @@ export function initReminders(app) {
|
|
|
212
223
|
}
|
|
213
224
|
async function erase(reminder) {
|
|
214
225
|
const id = roomId(), context = roomGeneration;
|
|
226
|
+
if (!id)
|
|
227
|
+
return;
|
|
215
228
|
try {
|
|
216
229
|
await app.api(`/rooms/${encodeURIComponent(id)}/reminders/${encodeURIComponent(reminder.id)}`, { method: "DELETE", body: JSON.stringify({ sessionID: LS.sessionID }) });
|
|
217
230
|
if (current(id, context)) {
|
|
@@ -242,7 +255,7 @@ export function initReminders(app) {
|
|
|
242
255
|
const schedule = type.value === "once"
|
|
243
256
|
? { type: "once", at: `${date.value}:00`, ...(zone ? { timezone: zone } : {}) }
|
|
244
257
|
: { type: "cron", expression: cron.value.trim(), ...(zone ? { timezone: zone } : {}) };
|
|
245
|
-
if (!id || !text || text.length > 2000 || !validZone(zone) || type.value === "once" && !date.value || type.value === "cron" && !validCron(schedule.expression))
|
|
258
|
+
if (!id || !text || text.length > 2000 || !validZone(zone) || type.value === "once" && !date.value || type.value === "cron" && !validCron(schedule.expression || ""))
|
|
246
259
|
return formStatus(app.t("reminderInvalid"));
|
|
247
260
|
if (saving)
|
|
248
261
|
return;
|
|
@@ -252,9 +265,10 @@ export function initReminders(app) {
|
|
|
252
265
|
// Keep the stored schedule when only the text changed, so a fired one-time reminder stays editable.
|
|
253
266
|
try {
|
|
254
267
|
const editingId = editing?.id;
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
&& (
|
|
268
|
+
const editingSchedule = editing?.schedule;
|
|
269
|
+
const sameSchedule = editingSchedule ? editingSchedule.type === type.value
|
|
270
|
+
&& (type.value === "once" ? inputValue(editingSchedule.at, zone || "UTC") === date.value : editingSchedule.expression === schedule.expression)
|
|
271
|
+
&& (editingSchedule.timezone || "UTC") === (zone || "UTC") : false;
|
|
258
272
|
const result = await app.api(`/rooms/${encodeURIComponent(id)}/reminders${editingId ? `/${encodeURIComponent(editingId)}` : ""}`, { method: editingId ? "PATCH" : "POST", body: JSON.stringify({ sessionID: LS.sessionID, text, ...(sameSchedule ? {} : { schedule }) }) });
|
|
259
273
|
if (current(id, context)) {
|
|
260
274
|
invalidateLoads();
|
|
@@ -2,7 +2,13 @@ import { LS } from "./state.js";
|
|
|
2
2
|
import { replaceEditorRange, setEditorSelection, setCaret } from "./editor.js";
|
|
3
3
|
import { icon } from "./icons.js";
|
|
4
4
|
export function initReplies(app) {
|
|
5
|
-
const $ =
|
|
5
|
+
const $ = (selector) => {
|
|
6
|
+
const node = app.$(selector);
|
|
7
|
+
if (!node)
|
|
8
|
+
throw new Error(`Missing ${selector}`);
|
|
9
|
+
return node;
|
|
10
|
+
};
|
|
11
|
+
const targets = new Map(Object.entries(LS.replyDrafts || {}).filter(([, item]) => validTarget(item)));
|
|
6
12
|
$("#replyCancel").textContent = app.t("cancelReply");
|
|
7
13
|
app.replyTargetFor = (roomId) => targets.get(roomId);
|
|
8
14
|
app.setReplyTarget = (roomId, target) => {
|
|
@@ -12,7 +18,7 @@ export function initReplies(app) {
|
|
|
12
18
|
targets.delete(roomId);
|
|
13
19
|
LS.replyDrafts = Object.fromEntries(targets);
|
|
14
20
|
if (app.state.room?.id === roomId)
|
|
15
|
-
app.renderReplyPreview();
|
|
21
|
+
app.renderReplyPreview?.();
|
|
16
22
|
};
|
|
17
23
|
app.clearReplyTarget = (roomId) => app.setReplyTarget(roomId, null);
|
|
18
24
|
app.renderReplyPreview = () => {
|
|
@@ -27,7 +33,7 @@ export function initReplies(app) {
|
|
|
27
33
|
bindMessageActions(app);
|
|
28
34
|
}
|
|
29
35
|
function validTarget(item) {
|
|
30
|
-
return item && typeof item.id === "string" && typeof item.text === "string" && typeof item.senderId === "string";
|
|
36
|
+
return Boolean(item && typeof item.id === "string" && typeof item.text === "string" && typeof item.senderId === "string");
|
|
31
37
|
}
|
|
32
38
|
function excerpt(text) { return String(text).replace(/<at>@([^<]+)<\/at>/g, "@$1").replace(/\s+/g, " ").trim().slice(0, 180); }
|
|
33
39
|
function bindMessageActions(app) {
|
|
@@ -54,11 +60,17 @@ function bindMessageActions(app) {
|
|
|
54
60
|
}
|
|
55
61
|
return row;
|
|
56
62
|
};
|
|
57
|
-
$("#msgList")
|
|
58
|
-
|
|
63
|
+
const list = $("#msgList");
|
|
64
|
+
if (!list)
|
|
65
|
+
return;
|
|
66
|
+
list.addEventListener("click", (event) => {
|
|
67
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
68
|
+
const button = target?.closest("[data-reply-message], [data-reply-target-id]");
|
|
59
69
|
if (!button || !app.state.room)
|
|
60
70
|
return;
|
|
61
71
|
const room = app.state.room, id = button.dataset.replyMessage || button.dataset.replyTargetId;
|
|
72
|
+
if (!id)
|
|
73
|
+
return;
|
|
62
74
|
if (button.dataset.replyMessage)
|
|
63
75
|
selectReply(app.state.room.messages.find((item) => item.id === id), app);
|
|
64
76
|
else
|
|
@@ -68,11 +80,13 @@ function bindMessageActions(app) {
|
|
|
68
80
|
function selectReply(message, app) {
|
|
69
81
|
if (!message || !app.state.room)
|
|
70
82
|
return;
|
|
83
|
+
const input = app.$("#msgInput");
|
|
84
|
+
if (!input)
|
|
85
|
+
return;
|
|
71
86
|
const roomId = app.state.room.id;
|
|
72
|
-
removeAutoMention(app.replyTargetFor(roomId),
|
|
87
|
+
removeAutoMention(app.replyTargetFor?.(roomId), input);
|
|
73
88
|
const target = { id: message.id, text: message.text, senderId: message.senderId, senderSessionID: message.senderSessionID, isQuestion: Boolean(message.isQuestion) };
|
|
74
89
|
const name = uniqueAuthor(message, app);
|
|
75
|
-
const input = app.$("#msgInput");
|
|
76
90
|
if (name && !input.value.includes(`<at>@${name}</at>`)) {
|
|
77
91
|
const prefix = `<at>@${name}</at> `;
|
|
78
92
|
target.autoMention = name;
|
|
@@ -84,23 +98,25 @@ function selectReply(message, app) {
|
|
|
84
98
|
input.focus({ preventScroll: true });
|
|
85
99
|
}
|
|
86
100
|
function cancelReply(app) {
|
|
87
|
-
const roomId = app.state.room?.id, target = roomId && app.replyTargetFor(roomId);
|
|
101
|
+
const roomId = app.state.room?.id, target = roomId && app.replyTargetFor?.(roomId);
|
|
88
102
|
if (!roomId || !target)
|
|
89
103
|
return;
|
|
90
104
|
removeAutoMention(target, app.$("#msgInput"));
|
|
91
105
|
app.clearReplyTarget(roomId);
|
|
92
106
|
}
|
|
93
107
|
function removeAutoMention(target, input) {
|
|
108
|
+
if (!input)
|
|
109
|
+
return;
|
|
94
110
|
const prefix = target?.autoMention && `<at>@${target.autoMention}</at> `;
|
|
95
111
|
if (prefix && input.value.startsWith(prefix)) {
|
|
96
112
|
setEditorSelection(input, 0, prefix.length);
|
|
97
|
-
getSelection()
|
|
113
|
+
getSelection()?.deleteFromDocument();
|
|
98
114
|
setCaret(input, 0);
|
|
99
115
|
input.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "deleteContentBackward" }));
|
|
100
116
|
}
|
|
101
117
|
}
|
|
102
118
|
function uniqueAuthor(message, app) {
|
|
103
|
-
const members = app.state.memberSessions.get(app.state.room?.id) || [];
|
|
119
|
+
const members = app.state.memberSessions.get(app.state.room?.id ?? "") || [];
|
|
104
120
|
const matches = message.senderSessionID ? members.filter((item) => item.sessionID === message.senderSessionID)
|
|
105
121
|
: members.filter((item) => item.name === message.senderId);
|
|
106
122
|
const name = matches[0]?.name;
|
|
@@ -109,7 +125,7 @@ function uniqueAuthor(message, app) {
|
|
|
109
125
|
function senderName(message, app) {
|
|
110
126
|
if (message.senderSessionID === LS.sessionID)
|
|
111
127
|
return app.t("you");
|
|
112
|
-
const members = app.state.memberSessions.get(app.state.room?.id) || [];
|
|
128
|
+
const members = app.state.memberSessions.get(app.state.room?.id ?? "") || [];
|
|
113
129
|
const match = message.senderSessionID && members.find((item) => item.sessionID === message.senderSessionID);
|
|
114
130
|
if (match)
|
|
115
131
|
return match.name;
|
|
@@ -117,7 +133,7 @@ function senderName(message, app) {
|
|
|
117
133
|
}
|
|
118
134
|
function quoteButton(message, app) {
|
|
119
135
|
const button = document.createElement("button"), targetId = message.answerToMessageID;
|
|
120
|
-
const original = app.state.room
|
|
136
|
+
const original = app.state.room?.messages.find((item) => item.id === targetId);
|
|
121
137
|
button.type = "button";
|
|
122
138
|
button.className = "reply-quote";
|
|
123
139
|
button.dataset.replyTargetId = targetId;
|
|
@@ -27,7 +27,7 @@ export function renderRoomOptions(app, list, rooms) {
|
|
|
27
27
|
const meta = document.createElement("span");
|
|
28
28
|
meta.className = "r-meta";
|
|
29
29
|
const shownRoom = entry?.room || room;
|
|
30
|
-
meta.textContent = app.t("roomMeta", { members: shownRoom.participants.length, count: shownRoom.messages.length });
|
|
30
|
+
meta.textContent = app.t("roomMeta", { members: (shownRoom.participants || []).length, count: shownRoom.messages.length });
|
|
31
31
|
const preview = document.createElement("span");
|
|
32
32
|
preview.className = "r-preview";
|
|
33
33
|
preview.textContent = entry ? formatRoomPreview(entry, shownRoom.messages.at(-1), app) : "";
|
|
@@ -48,7 +48,7 @@ export function renderRoomOptions(app, list, rooms) {
|
|
|
48
48
|
button.append(badge);
|
|
49
49
|
}
|
|
50
50
|
button.addEventListener("click", () => {
|
|
51
|
-
const name = app.state.myName || app.$("#inName")
|
|
51
|
+
const name = app.state.myName || app.$("#inName")?.value.trim() || app.t("guest");
|
|
52
52
|
// A protected room must ask before turning a click into a join request.
|
|
53
53
|
if (!joined && approval && !pending && app.confirmAction) {
|
|
54
54
|
void app.confirmAction(app.t("joinApprovalPrompt", { name: room.name })).then((ok) => { if (ok)
|
|
@@ -44,8 +44,11 @@ export async function watchRoom(roomId, app) {
|
|
|
44
44
|
entry.room.participants = latest.participants;
|
|
45
45
|
entry.room.openQuestions = latest.openQuestions;
|
|
46
46
|
if (sawQuestion) {
|
|
47
|
-
app
|
|
48
|
-
|
|
47
|
+
const roomList = app.$("#roomList"), roomListChat = app.$("#roomListChat");
|
|
48
|
+
if (roomList)
|
|
49
|
+
app.renderRoomOptions(roomList, app.state.availableRooms || []);
|
|
50
|
+
if (roomListChat)
|
|
51
|
+
app.renderRoomOptions(roomListChat, app.state.availableRooms || []);
|
|
49
52
|
}
|
|
50
53
|
entry.room.messages = [...new Map([...entry.room.messages, ...latest.messages].map((message) => [message.id, message])).values()].sort((a, b) => a.createdAt - b.createdAt).slice(-LOADED_MESSAGE_LIMIT);
|
|
51
54
|
for (const message of latest.messages)
|
|
@@ -71,9 +74,10 @@ export async function watchRoom(roomId, app) {
|
|
|
71
74
|
await watchRoom(roomId, app);
|
|
72
75
|
}
|
|
73
76
|
catch (error) {
|
|
74
|
-
|
|
77
|
+
const status = error instanceof Error && "status" in error ? error.status : undefined;
|
|
78
|
+
if (status === 401)
|
|
75
79
|
app.openChatSettings();
|
|
76
|
-
else if (
|
|
80
|
+
else if (status === 404)
|
|
77
81
|
await app.removeJoinedRoom(roomId, { reason: false });
|
|
78
82
|
}
|
|
79
83
|
}
|