@alexsun-top/opencode-chat-room 0.6.9 → 0.7.1

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +5 -4
  3. package/README.zh-CN.md +5 -4
  4. package/package.json +1 -1
  5. package/plugin.ts +49 -27
  6. package/server/assets/HIGHLIGHT-LICENSE +29 -0
  7. package/server/assets/NOTICE.txt +2 -1
  8. package/server/assets/base.css +6 -50
  9. package/server/assets/chat/editor.js +97 -16
  10. package/server/assets/chat/events.js +49 -8
  11. package/server/assets/chat/history-loader.js +1 -0
  12. package/server/assets/chat/index.js +4 -0
  13. package/server/assets/chat/join-requests.js +37 -17
  14. package/server/assets/chat/locales/de.js +115 -0
  15. package/server/assets/chat/locales/es.js +115 -0
  16. package/server/assets/chat/locales/fr.js +115 -0
  17. package/server/assets/chat/locales/index.js +8 -0
  18. package/server/assets/chat/locales/it.js +115 -0
  19. package/server/assets/chat/locales/ja.js +115 -0
  20. package/server/assets/chat/locales/ko.js +115 -0
  21. package/server/assets/chat/markdown.js +100 -0
  22. package/server/assets/chat/members.js +1 -1
  23. package/server/assets/chat/mentions.js +1 -0
  24. package/server/assets/chat/message-polling.js +28 -5
  25. package/server/assets/chat/messages.js +20 -2
  26. package/server/assets/chat/panels.js +0 -9
  27. package/server/assets/chat/questions.js +11 -3
  28. package/server/assets/chat/recall.js +3 -3
  29. package/server/assets/chat/replies.js +1 -1
  30. package/server/assets/chat/room-list.js +9 -1
  31. package/server/assets/chat/room-watcher.js +4 -0
  32. package/server/assets/chat/rooms.js +7 -0
  33. package/server/assets/chat/settings.js +72 -0
  34. package/server/assets/chat/shortcuts.js +64 -6
  35. package/server/assets/chat/state.js +45 -23
  36. package/server/assets/chat/viewport.js +26 -0
  37. package/server/assets/code-highlight.css +124 -0
  38. package/server/assets/conversation.css +16 -3
  39. package/server/assets/highlight-10.7.3.min.js +1358 -0
  40. package/server/assets/responsive.css +11 -5
  41. package/server/assets/settings.css +138 -0
  42. package/server/chat-server.ts +4 -1
  43. package/server/chat.html +96 -30
  44. package/server/join-requests.ts +11 -0
  45. package/server/sw.js +3 -0
  46. package/skills/chatroom/SKILL.md +3 -1
  47. package/src/agent/admin-client.ts +13 -5
  48. package/src/agent/announcement-tool.ts +6 -6
  49. package/src/center/center-client.ts +17 -17
  50. package/src/center/reminder-client.ts +5 -5
  51. package/src/rooms/resource-read.ts +16 -9
  52. package/src/rooms/resource-upload.ts +2 -2
@@ -19,7 +19,7 @@ export function editorText(editor, draft = false) {
19
19
  if (node.dataset?.chatAutoSeparator) value += draft && node.textContent.startsWith(" ")
20
20
  ? autoSeparator + encodeDraftText(node.textContent.slice(1)) : draft ? encodeDraftText(node.textContent) : node.textContent;
21
21
  else if (mention !== null) value += `<at>@${mention}</at>`;
22
- else if (node.tagName === "BR") value += "\n";
22
+ else if (node.tagName === "BR") { if (!node.dataset?.chatTail) value += "\n"; }
23
23
  else node.childNodes.forEach((child, index, all) => {
24
24
  if (index && (block(child) || block(all[index - 1]))) value += "\n";
25
25
  if (!(block(child) && child.childNodes.length === 1 && child.firstChild.nodeName === "BR")) walk(child);
@@ -37,19 +37,26 @@ export const editorDraftText = (editor) => editorText(editor, true);
37
37
  export const autoMentionDraft = (name) => `<at>@${name}</at>${autoSeparator}`;
38
38
  const literalMention = /<at>@([^<]+)<\/at>/g;
39
39
  function encodeDraftText(text) { return String(text).replace(/\uE000/g, "\uE000\uE000").replace(literalMention, "\uE000$&"); }
40
+ function appendText(editor, text) {
41
+ String(text).split("\n").forEach((line, index) => {
42
+ if (index) editor.append(document.createElement("br"));
43
+ if (line) editor.append(document.createTextNode(line));
44
+ });
45
+ }
40
46
 
41
47
  export function setEditorText(editor, value, draft = false) {
42
48
  editor.replaceChildren();
43
49
  const pattern = draft ? /\uE000\uE001|\uE000\uE000|\uE000<at>@([^<]+)<\/at>|<at>@([^<]+)<\/at>/g : /<at>@([^<]+)<\/at>/g;
44
50
  let offset = 0, match;
45
51
  while ((match = pattern.exec(String(value))) !== null) {
46
- editor.append(document.createTextNode(String(value).slice(offset, match.index)));
52
+ appendText(editor, String(value).slice(offset, match.index));
47
53
  if (draft && match[0] === autoSeparator) { editor.append(createAutoSeparator()); offset = pattern.lastIndex; continue; }
48
- if (draft && match[0] === "\uE000\uE000") { editor.append(document.createTextNode("\uE000")); offset = pattern.lastIndex; continue; }
49
- if (draft && match[0].startsWith("\uE000")) { editor.append(document.createTextNode(match[0].slice(1))); offset = pattern.lastIndex; continue; }
54
+ if (draft && match[0] === "\uE000\uE000") { appendText(editor, "\uE000"); offset = pattern.lastIndex; continue; }
55
+ if (draft && match[0].startsWith("\uE000")) { appendText(editor, match[0].slice(1)); offset = pattern.lastIndex; continue; }
50
56
  editor.append(createMention(draft ? match[2] : match[1])); offset = pattern.lastIndex;
51
57
  }
52
- editor.append(document.createTextNode(String(value).slice(offset)));
58
+ appendText(editor, String(value).slice(offset));
59
+ editor.dataset.empty = value ? "false" : "true";
53
60
  pruneTrustedChipNames();
54
61
  }
55
62
 
@@ -76,7 +83,7 @@ function lengthBefore(root, target, position) {
76
83
  const block = (node) => node.nodeType === Node.ELEMENT_NODE && node.tagName === "DIV";
77
84
  const length = (node) => node.nodeType === Node.TEXT_NODE ? node.length
78
85
  : mentionName(node) !== null ? `<at>@${mentionName(node)}</at>`.length
79
- : node.tagName === "BR" ? 1 : childrenLength(node);
86
+ : node.tagName === "BR" ? (node.dataset?.chatTail ? 0 : 1) : childrenLength(node);
80
87
  const childrenLength = (parent, until = parent.childNodes.length) => {
81
88
  let sum = 0;
82
89
  for (let index = 0; index < until; index++) {
@@ -113,6 +120,10 @@ export function setCaret(editor, offset) {
113
120
  function textPoint([container, offset]) {
114
121
  if (container.nodeType !== Node.ELEMENT_NODE) return [container, offset];
115
122
  const child = container.childNodes[offset], previous = container.childNodes[offset - 1];
123
+ if (child?.nodeType === Node.TEXT_NODE && child.length === 0) {
124
+ const next = child.nextSibling;
125
+ if (next?.nodeType === Node.TEXT_NODE) { child.remove(); return [next, 0]; }
126
+ }
116
127
  if (child?.nodeType === Node.TEXT_NODE) return [child, 0];
117
128
  if (previous?.nodeType === Node.TEXT_NODE) return [previous, previous.length];
118
129
  const text = document.createTextNode("");
@@ -128,12 +139,19 @@ export function setEditorSelection(editor, start, end = start) {
128
139
  }
129
140
 
130
141
  function editorPoint(editor, offset) {
142
+ const atEnd = offset === editorText(editor).length;
143
+ if (atEnd && editor.lastChild?.nodeType === Node.TEXT_NODE && editor.lastChild.nodeValue === "") editor.lastChild.remove();
131
144
  const last = editor.lastElementChild;
132
- if (offset === editorText(editor).length && editor.lastChild === last && last?.tagName === "DIV" && last.firstChild?.nodeName === "BR") {
145
+ if (atEnd && editor.lastChild === last && last?.tagName === "DIV" && last.firstChild?.nodeName === "BR") {
133
146
  const text = last.appendChild(document.createTextNode("")); return [text, 0];
134
147
  }
135
- if (offset === editorText(editor).length && editor.lastChild?.nodeName === "BR") {
136
- const text = editor.appendChild(document.createTextNode("")); return [text, 0];
148
+ if (atEnd && editor.lastChild?.nodeName === "BR") {
149
+ if (!editor.lastChild.dataset?.chatTail) {
150
+ const tail = document.createElement("br");
151
+ tail.dataset.chatTail = "true";
152
+ editor.append(tail);
153
+ }
154
+ return [editor, editor.childNodes.length - 1];
137
155
  }
138
156
  const block = (node) => node.nodeType === Node.ELEMENT_NODE && node.tagName === "DIV";
139
157
  let left = offset, point = null;
@@ -161,8 +179,13 @@ function editorPoint(editor, offset) {
161
179
  }
162
180
 
163
181
  export function replaceEditorRange(editor, start, end, value, parseMentions = true) {
182
+ const emptyBefore = !editorText(editor);
164
183
  setEditorSelection(editor, start, end);
165
- if (!parseMentions && document.execCommand("insertText", false, String(value))) return;
184
+ if (!parseMentions && document.execCommand("insertText", false, String(value))) {
185
+ if (emptyBefore && !String(value).endsWith("\n")) trimTrailingBreak(editor);
186
+ editor.dataset.empty = editorText(editor) ? "false" : "true";
187
+ return;
188
+ }
166
189
  const marker = `chat-insert-${createRandomId()}`;
167
190
  const source = String(value), generatedSpace = parseMentions && source.endsWith(" "), content = generatedSpace ? source.slice(0, -1) : source;
168
191
  const token = parseMentions ? /<at>@([^<]+)<\/at>/g : null;
@@ -178,6 +201,7 @@ export function replaceEditorRange(editor, start, end, value, parseMentions = tr
178
201
  if (generatedSpace) html += `<span data-chat-auto-separator="true"> </span>`;
179
202
  if (document.execCommand("insertHTML", false, html)) {
180
203
  editor.querySelectorAll(`[data-insert-marker="${marker}"]`).forEach((chip) => chip.removeAttribute("data-insert-marker"));
204
+ if (emptyBefore && !String(value).endsWith("\n")) trimTrailingBreak(editor);
181
205
  setCaret(editor, start + source.length);
182
206
  pruneTrustedChipNames();
183
207
  } else {
@@ -187,6 +211,31 @@ export function replaceEditorRange(editor, start, end, value, parseMentions = tr
187
211
  setCaret(editor, start + value.length);
188
212
  pruneTrustedChipNames();
189
213
  }
214
+ editor.dataset.empty = editorText(editor) ? "false" : "true";
215
+ }
216
+
217
+ function trimTrailingBreak(editor) {
218
+ let last = editor.lastChild;
219
+ if (last?.nodeName === "BR" && last.dataset?.chatTail) last = last.previousSibling;
220
+ if (last?.nodeName === "BR") last.remove();
221
+ }
222
+
223
+ function sanitizeEditor(editor) {
224
+ for (const node of editor.querySelectorAll("*")) {
225
+ if (node.tagName === "BR" || node.classList.contains("editor-mention") || node.hasAttribute("data-chat-auto-separator")) continue;
226
+ const selection = getSelection(), range = selection?.rangeCount ? selection.getRangeAt(0) : null;
227
+ const [start, end] = editorSelectionOffsets(editor), text = editorText(editor);
228
+ let atEnd = false;
229
+ if (range?.collapsed && editor.contains(range.endContainer)) {
230
+ const tail = document.createRange();
231
+ tail.setStart(range.endContainer, range.endOffset);
232
+ tail.setEnd(editor, editor.childNodes.length);
233
+ atEnd = tail.toString().length === 0;
234
+ }
235
+ setEditorText(editor, text);
236
+ setEditorSelection(editor, atEnd ? text.length : start, atEnd ? text.length : end);
237
+ return;
238
+ }
190
239
  }
191
240
 
192
241
  function escapeHTML(text) { return String(text).replace(/[&<>"']/g, (char) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[char]); }
@@ -211,18 +260,24 @@ function wrapAutoSeparator(editor, offset) {
211
260
  }
212
261
 
213
262
  function deleteMentionAtCaret(editor, event) {
214
- if (event.isComposing || event.keyCode === 229 || event.key !== "Backspace") return;
263
+ if (event.isComposing) return;
264
+ const backward = event.inputType === "deleteContentBackward" || (event.key === "Backspace" && event.keyCode !== 229);
265
+ if (!backward) return;
215
266
  const [caret, end] = editorSelectionOffsets(editor);
216
267
  if (caret !== end) return;
268
+ const chips = [...editor.querySelectorAll(".editor-mention")];
217
269
  const separator = [...editor.querySelectorAll("[data-chat-auto-separator]")].find((node) => {
218
- const start = lengthBefore(editor, node, 0); return node.textContent === " " && caret === start + 1;
270
+ const start = lengthBefore(editor, node, 0);
271
+ return caret === start + 1 && node.previousElementSibling?.classList.contains("editor-mention");
219
272
  });
220
- const mention = separator?.previousElementSibling || [...editor.querySelectorAll(".editor-mention")].find((node) => {
221
- return caret === lengthBefore(editor, node, 0) + `<at>@${mentionName(node)}</at>`.length;
273
+ const mention = separator?.previousElementSibling || chips.find((node) => {
274
+ const start = lengthBefore(editor, node, 0);
275
+ return caret > start && caret <= start + `<at>@${mentionName(node)}</at>`.length;
222
276
  });
223
- if (!mention || (separator && separator.previousElementSibling !== mention)) return;
277
+ if (!mention) return;
224
278
  const start = lengthBefore(editor, mention, 0);
225
- event.preventDefault(); mention.remove(); separator?.remove(); setCaret(editor, start);
279
+ const autoSeparator = mention.nextElementSibling?.dataset.chatAutoSeparator ? mention.nextElementSibling : null;
280
+ event.preventDefault(); mention.remove(); autoSeparator?.remove(); setCaret(editor, start);
226
281
  editor.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "deleteContentBackward" }));
227
282
  }
228
283
 
@@ -246,10 +301,34 @@ export function installEditor(editor) {
246
301
  });
247
302
  editor.getSelectionOffsets = () => editorSelectionOffsets(editor);
248
303
  editor.setCaret = (offset) => setCaret(editor, offset);
304
+ editor.moveCaretToLineEdge = (end) => {
305
+ const [start, finish] = editorSelectionOffsets(editor);
306
+ const text = editorText(editor);
307
+ const caret = end ? finish : start;
308
+ const next = text.indexOf("\n", caret);
309
+ // A native Home next to a non-editable chip can land inside the chip, where
310
+ // the caret is invisible. Re-seat all line-edge moves in a real text node.
311
+ const lineStart = end ? caret : text.lastIndexOf("\n", caret - 1) + 1;
312
+ const target = end ? (next === -1 ? text.length : next) : lineStart;
313
+ // A caret before a leading mention chip can render invisibly in Chromium.
314
+ // Home starts at the first editable character after that chip instead.
315
+ const leading = !end ? text.slice(lineStart).match(/^(?:<at>@[^<]+<\/at>)+/) : null;
316
+ setCaret(editor, leading ? lineStart + leading[0].length : target);
317
+ };
249
318
  editor.setSelectionRange = (start, end = start) => setEditorSelection(editor, start, end);
250
319
  editor.replaceTextRange = (start, end, value) => replaceEditorRange(editor, start, end, value);
251
320
  editor.addEventListener("input", pruneTrustedChipNames);
252
321
  editor.addEventListener("keydown", (event) => deleteMentionAtCaret(editor, event));
322
+ editor.addEventListener("beforeinput", (event) => deleteMentionAtCaret(editor, event));
323
+ editor.addEventListener("pointerdown", (event) => {
324
+ const chip = event.target.closest?.(".editor-mention");
325
+ if (!chip || !editor.contains(chip)) return;
326
+ event.preventDefault();
327
+ editor.focus({ preventScroll: true });
328
+ // A tap on a chip is usually followed by Backspace/Delete. Place the caret
329
+ // after it so a narrow or rounded chip cannot trap the caret before it.
330
+ setCaret(editor, lengthBefore(editor, chip, 0) + `<at>@${mentionName(chip)}</at>`.length);
331
+ });
253
332
  editor.addEventListener("copy", (event) => {
254
333
  const [start, end] = editorSelectionOffsets(editor);
255
334
  if (start === end) return;
@@ -269,6 +348,7 @@ export function installEditor(editor) {
269
348
  // and keeps the native insert path, which handles newlines correctly.
270
349
  const marked = (event.clipboardData?.getData("text/html") || "").includes("data-chatroom-mentions");
271
350
  replaceEditorRange(editor, start, end, text, marked && /<at>@[^<]+<\/at>/.test(text));
351
+ sanitizeEditor(editor);
272
352
  editor.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertFromPaste" }));
273
353
  });
274
354
  editor.addEventListener("drop", (event) => {
@@ -281,6 +361,7 @@ export function installEditor(editor) {
281
361
  if (range && editor.contains(range.startContainer)) { selection.removeAllRanges(); selection.addRange(range); }
282
362
  const [start, end] = editorSelectionOffsets(editor);
283
363
  replaceEditorRange(editor, start, end, text, html.includes("data-chatroom-mentions") && /<at>@[^<]+<\/at>/.test(text));
364
+ sanitizeEditor(editor);
284
365
  editor.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertFromDrop" }));
285
366
  });
286
367
  }
@@ -28,17 +28,25 @@ export function initEvents(app) {
28
28
  const root = document.documentElement, editor = app.$("#msgInput");
29
29
  // A restored draft or staged files must not become the idle height people see on load.
30
30
  const idleComposer = () => !editor?.textContent?.trim()
31
- && !["#sendError", "#replyPreview", "#mentionPicker", "#attachmentTray"].some((selector) => { const node = app.$(selector); return node && !node.hidden; })
31
+ && !["#joinNotice", "#sendError", "#replyPreview", "#mentionPicker", "#attachmentTray"].some((selector) => { const node = app.$(selector); return node && !node.hidden; })
32
32
  && !composer.querySelector(".failed-messages:not([hidden])");
33
33
  const syncComposerBlock = () => {
34
34
  const height = composer.getBoundingClientRect().height;
35
35
  if (!height || !idleComposer()) return;
36
- const idle = parseFloat(getComputedStyle(root).getPropertyValue("--composer-block")) || 0;
37
- if (idle && height > idle + 2) return;
38
36
  root.style.setProperty("--composer-block", `${Math.round(height)}px`);
39
37
  };
40
38
  new ResizeObserver(syncComposerBlock).observe(composer);
41
39
  syncComposerBlock();
40
+ window.addEventListener("resize", syncComposerBlock);
41
+ let lastComposerHeight = composer.getBoundingClientRect().height;
42
+ new ResizeObserver(() => {
43
+ const height = composer.getBoundingClientRect().height;
44
+ if (height > lastComposerHeight + 1 && followsBottom(app)) {
45
+ const thread = $("#thread");
46
+ thread.scrollTop = thread.scrollHeight;
47
+ }
48
+ lastComposerHeight = height;
49
+ }).observe(composer);
42
50
  }
43
51
  // Images, diagrams and attachments grow the list after the first paint and the browser
44
52
  // answers with a scroll that looks like the reader moving. Subtract the growth: only a
@@ -48,6 +56,12 @@ export function initEvents(app) {
48
56
  const thread = $("#thread");
49
57
  app.state.listMetrics = { height: messageList.offsetHeight, top: thread.scrollTop, client: thread.clientHeight };
50
58
  };
59
+ const scrollThread = $("#thread");
60
+ if (scrollThread) {
61
+ new ResizeObserver(() => {
62
+ if (followsBottom(app) && scrollThread.scrollHeight - scrollThread.scrollTop - scrollThread.clientHeight > 1) scrollThread.scrollTop = scrollThread.scrollHeight;
63
+ }).observe(scrollThread);
64
+ }
51
65
  new ResizeObserver(() => {
52
66
  const thread = $("#thread"), previous = app.state.listMetrics;
53
67
  const grew = messageList.offsetHeight > previous.height, sameBox = thread.clientHeight === previous.client;
@@ -158,6 +172,7 @@ export function initEvents(app) {
158
172
  });
159
173
  }
160
174
  syncRoomDrawer();
175
+ window.addEventListener("pageshow", () => { if (app.state.followBottom) $("#thread").scrollTop = $("#thread").scrollHeight; });
161
176
  window.addEventListener("resize", preserveReadingPosition);
162
177
  window.addEventListener("pagehide", () => { captureReadingPosition(); app.flushReadOnHide?.(); });
163
178
  document.addEventListener("visibilitychange", () => { if (document.hidden) { captureReadingPosition(); app.flushReadOnHide?.(); } });
@@ -197,7 +212,6 @@ export function initEvents(app) {
197
212
  $("#btnLeave").addEventListener("click", () => app.leaveRoom(false));
198
213
  $("#btnDeleteRoom").addEventListener("click", () => void app.deleteRoom());
199
214
  $("#btnMembers").addEventListener("click", () => app.togglePanel("#memberPanel"));
200
- $("#btnSettings").addEventListener("click", () => app.togglePanel("#chatSettings"));
201
215
  $("#btnRoomOptions").addEventListener("click", () => {
202
216
  const panel = $("#roomOptions"), open = panel.hidden;
203
217
  app.closePanels(); panel.hidden = !open;
@@ -236,6 +250,7 @@ export function initEvents(app) {
236
250
  app.autoGrow(input);
237
251
  app.updateSendState();
238
252
  app.updateDraftCount();
253
+ if (app.state.followBottom) { const thread = $("#thread"); if (thread) thread.scrollTop = thread.scrollHeight; }
239
254
  if (app.state.room) {
240
255
  const id = app.state.room.id;
241
256
  app.state.draftRevision.set(id, (app.state.draftRevision.get(id) || 0) + 1);
@@ -252,11 +267,19 @@ export function initEvents(app) {
252
267
  app.recomputeMention(input);
253
268
  });
254
269
  input.addEventListener("keydown", (event) => {
255
- if ((event.key === "PageUp" || event.key === "PageDown")
270
+ if ((event.key === "Home" || event.key === "End")
256
271
  && !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey && !event.isComposing) {
257
272
  event.preventDefault();
273
+ input.moveCaretToLineEdge?.(event.key === "End");
274
+ return;
275
+ }
276
+ if ((event.key === "PageUp" || event.key === "PageDown")
277
+ && !event.ctrlKey && !event.metaKey && !event.shiftKey && !event.isComposing) {
278
+ event.preventDefault();
258
279
  markScrollIntent();
259
- thread.scrollTop += (event.key === "PageDown" ? 1 : -1) * Math.max(80, thread.clientHeight * 0.9);
280
+ const delta = (event.key === "PageDown" ? 1 : -1) * Math.max(80, thread.clientHeight * 0.9);
281
+ if (app.animateThreadScrollBy) app.animateThreadScrollBy(delta);
282
+ else thread.scrollTop += delta;
260
283
  return;
261
284
  }
262
285
  handleMessageKey(event, app);
@@ -324,6 +347,23 @@ export function initEvents(app) {
324
347
  const messageButton = event.target.closest("[data-copy-message]");
325
348
  if (messageButton) void copyTextToClipboard(messageButton._copyText, true).then((copied) => app.flash(messageButton, copied ? "copiedMessage" : "copyMessageFailed"));
326
349
  });
350
+ $("#msgList").addEventListener("copy", (event) => {
351
+ // A plain browser copy of rendered messages loses the mention tokens. Rebuild
352
+ // them only for chips inside the copied range, so external @text stays literal.
353
+ const selection = getSelection(), list = $("#msgList");
354
+ if (!selection || selection.isCollapsed || !selection.rangeCount) return;
355
+ const range = selection.getRangeAt(0);
356
+ if (!list.contains(range.startContainer) || !list.contains(range.endContainer)) return;
357
+ const fragment = range.cloneContents();
358
+ const chips = fragment.querySelectorAll(".mention-chip");
359
+ if (!chips.length) return;
360
+ chips.forEach((chip) => chip.replaceWith(document.createTextNode(`<at>@${chip.textContent?.slice(1) ?? ""}</at>`)));
361
+ const text = fragment.textContent ?? "";
362
+ const html = `<div data-chatroom-mentions>${text.replace(/[&<>"]/g, (char) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[char])}</div>`;
363
+ event.clipboardData?.setData("text/plain", text);
364
+ event.clipboardData?.setData("text/html", html);
365
+ event.preventDefault();
366
+ });
327
367
  ["#inRoomId", "#inName", "#inRoomName"].forEach((selector) => {
328
368
  $(selector).addEventListener("input", app.hideJoinError);
329
369
  });
@@ -361,7 +401,7 @@ export function initEvents(app) {
361
401
  if (event.key === "Escape" && roomRail.classList.contains("drawer-open")) { event.preventDefault(); closeRoomDrawer(); return; }
362
402
  if (event.key === "Escape" && app.mentionActive) app.closeMention();
363
403
  if (event.key === "Escape" && !$("#railRoomForm").hidden) $("#railRoomForm").hidden = true;
364
- if (event.key === "Escape" && (!$("#memberPanel").hidden || !$("#chatSettings").hidden)) {
404
+ if (event.key === "Escape" && !$("#memberPanel").hidden) {
365
405
  app.closePanels();
366
406
  app.lastFocus?.focus();
367
407
  }
@@ -373,6 +413,7 @@ export function initEvents(app) {
373
413
  event.preventDefault();
374
414
  const step = event.key === "ArrowDown" ? 1 : -1;
375
415
  app.activateRoom(joined[(index + step + joined.length) % joined.length].id);
416
+ app.animateRoomSwitch?.(step);
376
417
  }
377
418
  });
378
419
 
@@ -417,7 +458,7 @@ function handleMessageKey(event, app) {
417
458
  if (event.key === "Tab") return;
418
459
  }
419
460
  }
420
- if (event.key === "Enter" && !event.isComposing && event.keyCode !== 229 && (event.ctrlKey || !event.shiftKey)) {
461
+ if (event.key === "Enter" && !event.isComposing && event.keyCode !== 229 && (event.ctrlKey || (!event.shiftKey && !matchMedia("(pointer: coarse)").matches))) {
421
462
  event.preventDefault();
422
463
  void app.send();
423
464
  }
@@ -54,6 +54,7 @@ export function initHistoryLoader(app) {
54
54
  if (tailSep?.classList.contains("day-sep") && new Date(older.at(-1).createdAt).toDateString() === tailSep.dataset.day) tailSep.remove();
55
55
  entry.room.messages = [...older, ...entry.room.messages].sort((left, right) => left.createdAt - right.createdAt);
56
56
  if (entry.room.messages.length > LOADED_MESSAGE_LIMIT) entry.room.messages.splice(0, entry.room.messages.length - LOADED_MESSAGE_LIMIT);
57
+ app.cancelThreadScrollAnimation?.();
57
58
  thread.scrollTop = beforeTop + (thread.scrollHeight - beforeHeight);
58
59
  app.cacheRoomSoon?.(room.id);
59
60
  app.queueReceiptRefresh?.();
@@ -19,7 +19,10 @@ import { initReminders } from "./reminders.js";
19
19
  import { initPwa } from "./pwa.js";
20
20
  import { initInstallPrompt } from "./install-prompt.js";
21
21
  import { initShortcuts } from "./shortcuts.js";
22
+ import { initViewport } from "./viewport.js";
23
+ import { initSettings } from "./settings.js";
22
24
 
25
+ initSettings(app);
23
26
  initConfirmDialog(app);
24
27
  initMentions(app);
25
28
  initMessages(app);
@@ -39,4 +42,5 @@ initReminders(app);
39
42
  initAdmin(app);
40
43
  initImageZoom(app);
41
44
  initPwa();
45
+ initViewport();
42
46
  initInstallPrompt(app);
@@ -5,7 +5,7 @@ import { isRoomAdmin } from "./admin-badge.js";
5
5
  export function initJoinRequests(app) {
6
6
  const $ = app.$;
7
7
  const pendingIds = (app.state.pendingJoinIds ??= new Set());
8
- let pending = { roomId: "", name: "", status: "", timer: 0, generation: 0, checking: false };
8
+ let pending = { roomId: "", name: "", status: "", timer: 0, generation: 0, checking: false, cancelling: false };
9
9
  let requests = [], requestsRoomId = "", requestsGeneration = 0, requestsLoading = false, deniedRoomId = "";
10
10
  let requestSignature = "";
11
11
 
@@ -19,7 +19,7 @@ export function initJoinRequests(app) {
19
19
 
20
20
  app.showJoinPending = (roomId, name) => {
21
21
  clearTimeout(pending.timer);
22
- pending = { roomId, name, status: "pending", timer: 0, generation: pending.generation + 1, checking: false };
22
+ pending = { roomId, name, status: "pending", timer: 0, generation: pending.generation + 1, checking: false, cancelling: false };
23
23
  pendingIds.add(roomId);
24
24
  const roomName = roomNameFor(roomId);
25
25
  app.setText(title, "joinPendingTitle");
@@ -42,17 +42,18 @@ export function initJoinRequests(app) {
42
42
  function renderPendingActions() {
43
43
  const waiting = pending.status === "pending";
44
44
  const gone = pending.status === "gone";
45
- $("#btnJoinPendingCheck").hidden = !waiting;
46
45
  $("#btnJoinPendingStop").hidden = !waiting;
47
46
  $("#btnJoinPendingAgain").hidden = waiting || gone;
48
- $("#btnJoinNoticeCheck").hidden = !waiting;
49
47
  $("#btnJoinNoticeStop").hidden = !waiting;
50
48
  $("#btnJoinNoticeAgain").hidden = waiting || gone;
49
+ $("#btnJoinPendingStop").disabled = Boolean(pending.cancelling);
50
+ $("#btnJoinNoticeStop").disabled = Boolean(pending.cancelling);
51
51
  }
52
52
 
53
53
  function closePending(keepWaiting = false) {
54
54
  clearTimeout(pending.timer);
55
55
  pending.timer = 0;
56
+ pending.cancelling = false;
56
57
  pending.generation++;
57
58
  card.hidden = true;
58
59
  notice.hidden = true;
@@ -69,12 +70,11 @@ export function initJoinRequests(app) {
69
70
  pending.timer = setTimeout(() => void checkPending(), delay);
70
71
  }
71
72
 
72
- async function checkPending(manual = false) {
73
+ async function checkPending() {
73
74
  if (pending.checking || !pending.roomId || pending.status !== "pending") return;
74
75
  if (document.hidden) { scheduleCheck(); return; }
75
76
  const generation = pending.generation, roomId = pending.roomId;
76
77
  pending.checking = true;
77
- if (manual) { $("#btnJoinPendingCheck").disabled = true; $("#btnJoinNoticeCheck").disabled = true; }
78
78
  try {
79
79
  const result = await app.api(`/rooms/${encodeURIComponent(roomId)}/join-requests/status?sessionID=${encodeURIComponent(LS.sessionID)}`);
80
80
  if (generation !== pending.generation) return;
@@ -120,8 +120,6 @@ export function initJoinRequests(app) {
120
120
  }
121
121
  } finally {
122
122
  pending.checking = false;
123
- $("#btnJoinPendingCheck").disabled = false;
124
- $("#btnJoinNoticeCheck").disabled = false;
125
123
  }
126
124
  }
127
125
 
@@ -296,7 +294,6 @@ export function initJoinRequests(app) {
296
294
  function updateBadge(count) {
297
295
  const badge = $("#joinRequestBadge"), button = $("#btnMembers");
298
296
  $("#joinRequestBadgeCount").textContent = count > 99 ? "99+" : String(count);
299
- $("#joinRequestBadgeWord").textContent = count === 1 ? app.t("joinRequestBadgeOne") : app.t("joinRequestBadgeMany");
300
297
  badge.title = count ? app.t("membersWithRequests", { count }) : "";
301
298
  badge.hidden = !count;
302
299
  button.setAttribute("aria-label", count ? app.t("membersWithRequests", { count }) : app.t("members"));
@@ -307,20 +304,43 @@ export function initJoinRequests(app) {
307
304
  app.renderRoomOptions($("#roomListChat"), app.state.availableRooms || []);
308
305
  }
309
306
 
310
- function stopWaiting() {
311
- closePending(true);
312
- pending.status = "dismissed";
313
- ($("#joinView").hidden ? $("#msgInput") : $("#inRoomId"))?.focus();
307
+ async function cancelPending() {
308
+ if (!pending.roomId || pending.status !== "pending" || pending.cancelling) return;
309
+ const generation = pending.generation, roomId = pending.roomId;
310
+ pending.cancelling = true;
311
+ renderPendingActions();
312
+ try {
313
+ await app.api(`/rooms/${encodeURIComponent(roomId)}/join-requests?sessionID=${encodeURIComponent(LS.sessionID)}`, { method: "DELETE", body: "{}" });
314
+ if (generation !== pending.generation) return;
315
+ pendingIds.delete(roomId);
316
+ closePending();
317
+ ($("#joinView").hidden ? $("#msgInput") : $("#inRoomId"))?.focus({ preventScroll: true });
318
+ } catch (error) {
319
+ if (generation !== pending.generation) return;
320
+ if (error.status === 404) {
321
+ pendingIds.delete(roomId);
322
+ closePending();
323
+ ($("#joinView").hidden ? $("#msgInput") : $("#inRoomId"))?.focus({ preventScroll: true });
324
+ return;
325
+ }
326
+ app.setText(hint, "joinPendingCancelError");
327
+ hint.hidden = false;
328
+ app.setText(noticeText, "joinPendingCancelError");
329
+ notice.hidden = $("#chatView").hidden;
330
+ } finally {
331
+ if (generation === pending.generation) {
332
+ pending.cancelling = false;
333
+ renderPendingActions();
334
+ }
335
+ }
314
336
  }
315
337
 
316
338
  function requestAgain() {
317
339
  if (pending.roomId) void app.joinRoom(pending.roomId, pending.name || LS.name);
318
340
  }
319
341
 
320
- $("#btnJoinPendingCheck").addEventListener("click", () => void checkPending(true));
321
- $("#btnJoinNoticeCheck").addEventListener("click", () => void checkPending(true));
322
- $("#btnJoinPendingStop").addEventListener("click", stopWaiting);
323
- $("#btnJoinNoticeStop").addEventListener("click", stopWaiting);
342
+ $("#btnJoinPendingStop").addEventListener("click", () => void cancelPending());
343
+ $("#btnJoinNoticeStop").addEventListener("click", () => void cancelPending());
324
344
  $("#btnJoinPendingAgain").addEventListener("click", requestAgain);
325
345
  $("#btnJoinNoticeAgain").addEventListener("click", requestAgain);
326
346
  $("#btnMembers").addEventListener("click", () => {