@alexsun-top/opencode-chat-room 0.8.1 → 0.8.3

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 (125) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +18 -62
  3. package/README.zh-CN.md +25 -69
  4. package/dist/cli.js +1008 -274
  5. package/package.json +10 -7
  6. package/packages/chat-room-channeld/README.md +42 -15
  7. package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
  8. package/packages/chat-room-channeld/src/adapter.ts +150 -7
  9. package/packages/chat-room-channeld/src/cli.ts +72 -5
  10. package/packages/chat-room-channeld/src/host.ts +41 -11
  11. package/packages/chat-room-channeld/src/inbound.ts +13 -4
  12. package/packages/chat-room-channeld/src/pg/database.ts +187 -0
  13. package/packages/chat-room-channeld/src/pg/migrate.ts +150 -0
  14. package/packages/chat-room-channeld/src/pg/schema.ts +60 -0
  15. package/packages/chat-room-channeld/src/pg/sql.mjs +175 -0
  16. package/packages/chat-room-channeld/src/pg/sqlite.ts +100 -0
  17. package/packages/chat-room-channeld/src/pg/worker.mjs +133 -0
  18. package/packages/chat-room-channeld/src/protocol.ts +53 -1
  19. package/packages/chat-room-channeld/src/rules.ts +7 -2
  20. package/packages/chat-room-channeld/src/state.ts +73 -97
  21. package/packages/chat-room-channeld/src/stats.ts +140 -109
  22. package/plugin.ts +1 -1
  23. package/server/assets/base.css +11 -3
  24. package/server/assets/chat/admin-badge.js +32 -30
  25. package/server/assets/chat/admin.js +198 -163
  26. package/server/assets/chat/announcements.js +295 -210
  27. package/server/assets/chat/attachment-store.js +106 -75
  28. package/server/assets/chat/attachments.js +686 -441
  29. package/server/assets/chat/chat-background.js +206 -0
  30. package/server/assets/chat/clipboard.js +44 -25
  31. package/server/assets/chat/confirm-dialog.js +36 -34
  32. package/server/assets/chat/copy-action.js +40 -40
  33. package/server/assets/chat/create-room-dialog.js +50 -48
  34. package/server/assets/chat/diagram-viewer.js +293 -228
  35. package/server/assets/chat/doc-preview.js +510 -388
  36. package/server/assets/chat/editor.js +423 -335
  37. package/server/assets/chat/events.js +637 -502
  38. package/server/assets/chat/files.js +476 -426
  39. package/server/assets/chat/history-loader.js +79 -73
  40. package/server/assets/chat/icons.js +9 -11
  41. package/server/assets/chat/image-zoom.js +239 -169
  42. package/server/assets/chat/index.js +6 -5
  43. package/server/assets/chat/install-prompt.js +86 -66
  44. package/server/assets/chat/integration-account-schema.js +101 -0
  45. package/server/assets/chat/integration-editor.js +162 -153
  46. package/server/assets/chat/integration-values.js +109 -100
  47. package/server/assets/chat/integrations.js +696 -479
  48. package/server/assets/chat/join-requests.js +408 -358
  49. package/server/assets/chat/locales/de.js +193 -194
  50. package/server/assets/chat/locales/es.js +193 -194
  51. package/server/assets/chat/locales/fr.js +193 -194
  52. package/server/assets/chat/locales/index.js +1 -2
  53. package/server/assets/chat/locales/it.js +193 -194
  54. package/server/assets/chat/locales/ja.js +193 -193
  55. package/server/assets/chat/locales/ko.js +193 -193
  56. package/server/assets/chat/markdown-footnotes.js +134 -102
  57. package/server/assets/chat/markdown.js +553 -386
  58. package/server/assets/chat/members.js +236 -197
  59. package/server/assets/chat/mentions.js +157 -133
  60. package/server/assets/chat/message-cache.js +40 -33
  61. package/server/assets/chat/message-polling.js +280 -227
  62. package/server/assets/chat/message-window.js +74 -55
  63. package/server/assets/chat/messages.js +552 -479
  64. package/server/assets/chat/office-preview.js +46 -45
  65. package/server/assets/chat/palette.js +450 -412
  66. package/server/assets/chat/panels.js +94 -58
  67. package/server/assets/chat/pwa.js +144 -73
  68. package/server/assets/chat/questions.js +372 -302
  69. package/server/assets/chat/recall.js +320 -273
  70. package/server/assets/chat/receipts.js +149 -122
  71. package/server/assets/chat/reminders.js +331 -216
  72. package/server/assets/chat/replies.js +165 -136
  73. package/server/assets/chat/resource-format.js +59 -62
  74. package/server/assets/chat/room-list.js +58 -55
  75. package/server/assets/chat/room-watcher.js +72 -50
  76. package/server/assets/chat/rooms.js +623 -505
  77. package/server/assets/chat/search.js +136 -114
  78. package/server/assets/chat/settings.js +229 -140
  79. package/server/assets/chat/shiki.js +61 -62
  80. package/server/assets/chat/shortcuts.js +212 -190
  81. package/server/assets/chat/side-pane.js +166 -131
  82. package/server/assets/chat/state.js +851 -707
  83. package/server/assets/chat/system-events.js +55 -27
  84. package/server/assets/chat/system-messages.js +59 -49
  85. package/server/assets/chat/task-form.js +178 -182
  86. package/server/assets/chat/task-row.js +158 -155
  87. package/server/assets/chat/tasks.js +653 -593
  88. package/server/assets/chat/viewport.js +32 -29
  89. package/server/assets/chat/window-controls.js +37 -0
  90. package/server/assets/code-highlight.css +22 -6
  91. package/server/assets/conversation.css +65 -16
  92. package/server/assets/doc-preview.css +6 -1
  93. package/server/assets/files.css +3 -0
  94. package/server/assets/monaco/integration-rules.css +1 -1
  95. package/server/assets/monaco/integration-rules.js +841 -533
  96. package/server/assets/responsive.css +32 -2
  97. package/server/assets/settings.css +117 -13
  98. package/server/assets/window-controls.css +36 -0
  99. package/server/channel-attachments.ts +133 -0
  100. package/server/channel-integration.ts +79 -26
  101. package/server/channels.ts +15 -5
  102. package/server/chat-server.ts +9 -1
  103. package/server/chat.html +73 -38
  104. package/server/manifest.webmanifest +1 -0
  105. package/server/routes/pages.ts +7 -5
  106. package/server/sw.js +346 -267
  107. package/src/center/center-client.ts +1 -1
  108. package/src/state/pg-database.ts +5 -5
  109. package/src/state/pg-migrate.ts +7 -7
  110. package/src/state/pg-worker.mjs +2 -17
  111. package/src/state/sqlite-database.ts +14 -5
  112. package/src/state/sqlite-rooms.ts +130 -23
  113. package/src/state/sqlite-state-store.ts +6 -5
  114. package/src/state/sqlite.ts +3 -3
  115. package/src/web/integration-rules-editor.ts +141 -5
  116. package/src/web/integration-rules.ts +6 -2
  117. package/src/web/integration-schema.ts +7 -6
  118. package/packages/chat-room-channeld/dist/feishu-adapter.js +0 -1262
  119. package/packages/chat-room-channeld/src/feishu-adapter.ts +0 -303
  120. package/packages/chat-room-channeld/src/feishu-card.ts +0 -27
  121. package/packages/chat-room-channeld/src/feishu-inbound.ts +0 -158
  122. package/packages/chat-room-channeld/src/feishu-live.ts +0 -355
  123. package/packages/chat-room-channeld/src/feishu-send.ts +0 -342
  124. package/packages/chat-room-channeld/src/feishu-ws-frames.ts +0 -173
  125. package/server/assets/chat/forward.js +0 -69
@@ -1,164 +1,193 @@
1
1
  import { LS } from "./state.js";
2
2
  import { replaceEditorRange, setEditorSelection, setCaret } from "./editor.js";
3
3
  import { icon } from "./icons.js";
4
-
5
4
  export function initReplies(app) {
6
- const $ = app.$, targets = new Map(Object.entries(LS.replyDrafts || {}).filter(([, item]) => validTarget(item)));
7
- $("#replyCancel").textContent = app.t("cancelReply");
8
- app.replyTargetFor = (roomId) => targets.get(roomId);
9
- app.setReplyTarget = (roomId, target) => {
10
- if (validTarget(target)) targets.set(roomId, target); else targets.delete(roomId);
11
- LS.replyDrafts = Object.fromEntries(targets);
12
- if (app.state.room?.id === roomId) app.renderReplyPreview();
13
- };
14
- app.clearReplyTarget = (roomId) => app.setReplyTarget(roomId, null);
15
- app.renderReplyPreview = () => {
16
- const roomId = app.state.room?.id, target = roomId && targets.get(roomId), box = $("#replyPreview");
17
- box.hidden = !target;
18
- if (!target) return;
19
- $("#replyPreviewName").textContent = senderName(target, app);
20
- $("#replyPreviewText").textContent = excerpt(target.text);
21
- };
22
- $("#replyCancel").addEventListener("click", () => cancelReply(app));
23
- bindMessageActions(app);
5
+ const $ = app.$, targets = new Map(Object.entries(LS.replyDrafts || {}).filter(([, item]) => validTarget(item)));
6
+ $("#replyCancel").textContent = app.t("cancelReply");
7
+ app.replyTargetFor = (roomId) => targets.get(roomId);
8
+ app.setReplyTarget = (roomId, target) => {
9
+ if (validTarget(target))
10
+ targets.set(roomId, target);
11
+ else
12
+ targets.delete(roomId);
13
+ LS.replyDrafts = Object.fromEntries(targets);
14
+ if (app.state.room?.id === roomId)
15
+ app.renderReplyPreview();
16
+ };
17
+ app.clearReplyTarget = (roomId) => app.setReplyTarget(roomId, null);
18
+ app.renderReplyPreview = () => {
19
+ const roomId = app.state.room?.id, target = roomId && targets.get(roomId), box = $("#replyPreview");
20
+ box.hidden = !target;
21
+ if (!target)
22
+ return;
23
+ $("#replyPreviewName").textContent = senderName(target, app);
24
+ $("#replyPreviewText").textContent = excerpt(target.text);
25
+ };
26
+ $("#replyCancel").addEventListener("click", () => cancelReply(app));
27
+ bindMessageActions(app);
24
28
  }
25
-
26
29
  function validTarget(item) {
27
- return item && typeof item.id === "string" && typeof item.text === "string" && typeof item.senderId === "string";
30
+ return item && typeof item.id === "string" && typeof item.text === "string" && typeof item.senderId === "string";
28
31
  }
29
32
  function excerpt(text) { return String(text).replace(/<at>@([^<]+)<\/at>/g, "@$1").replace(/\s+/g, " ").trim().slice(0, 180); }
30
-
31
33
  function bindMessageActions(app) {
32
- const $ = app.$;
33
- const render = app.renderMessage;
34
- app.renderMessage = (message, live) => {
35
- const row = render(message, live);
36
- if (message.senderId === "system" || message.pending || message.recalledAt) return row;
37
- if (message.answerToMessageID) row.querySelector(".msg-meta")?.after(quoteButton(message, app));
38
- const copy = row.querySelector("[data-copy-message]");
39
- if (copy) {
40
- const actions = document.createElement("div"), reply = document.createElement("button");
41
- actions.className = "message-actions";
42
- reply.type = "button"; reply.className = "message-reply"; reply.innerHTML = icon("arrow_reply", "message-reply-icon");
43
- reply.setAttribute("aria-label", app.t("replyMessage")); reply.dataset.i18nAriaLabel = "replyMessage"; reply.dataset.replyMessage = message.id;
44
- copy.before(actions); actions.append(copy, reply);
45
- if (document.body.dataset.channeld === "on") {
46
- const forward = document.createElement("button");
47
- forward.type = "button"; forward.className = "message-reply message-forward"; forward.innerHTML = icon("arrow_right", "message-reply-icon");
48
- forward.setAttribute("aria-label", app.t("forwardMessage")); forward.dataset.i18nAriaLabel = "forwardMessage"; forward.dataset.forwardMessage = message.id;
49
- actions.append(forward);
50
- }
51
- }
52
- return row;
53
- };
54
- $("#msgList").addEventListener("click", (event) => {
55
- const button = event.target.closest?.("[data-reply-message], [data-reply-target-id]");
56
- if (!button || !app.state.room) return;
57
- const room = app.state.room, id = button.dataset.replyMessage || button.dataset.replyTargetId;
58
- if (button.dataset.replyMessage) selectReply(app.state.room.messages.find((item) => item.id === id), app);
59
- else void jumpToOriginal(room.id, id, app);
60
- });
34
+ const $ = app.$;
35
+ const render = app.renderMessage;
36
+ app.renderMessage = (message, live) => {
37
+ const row = render(message, live);
38
+ if (message.senderId === "system" || message.pending || message.recalledAt)
39
+ return row;
40
+ if (message.answerToMessageID)
41
+ row.querySelector(".msg-meta")?.after(quoteButton(message, app));
42
+ const copy = row.querySelector("[data-copy-message]");
43
+ if (copy) {
44
+ const actions = document.createElement("div"), reply = document.createElement("button");
45
+ actions.className = "message-actions";
46
+ reply.type = "button";
47
+ reply.className = "message-reply";
48
+ reply.innerHTML = icon("arrow_reply", "message-reply-icon");
49
+ reply.setAttribute("aria-label", app.t("replyMessage"));
50
+ reply.dataset.i18nAriaLabel = "replyMessage";
51
+ reply.dataset.replyMessage = message.id;
52
+ copy.before(actions);
53
+ actions.append(copy, reply);
54
+ }
55
+ return row;
56
+ };
57
+ $("#msgList").addEventListener("click", (event) => {
58
+ const button = event.target.closest?.("[data-reply-message], [data-reply-target-id]");
59
+ if (!button || !app.state.room)
60
+ return;
61
+ const room = app.state.room, id = button.dataset.replyMessage || button.dataset.replyTargetId;
62
+ if (button.dataset.replyMessage)
63
+ selectReply(app.state.room.messages.find((item) => item.id === id), app);
64
+ else
65
+ void jumpToOriginal(room.id, id, app);
66
+ });
61
67
  }
62
-
63
68
  function selectReply(message, app) {
64
- if (!message || !app.state.room) return;
65
- const roomId = app.state.room.id;
66
- removeAutoMention(app.replyTargetFor(roomId), app.$("#msgInput"));
67
- const target = { id: message.id, text: message.text, senderId: message.senderId, senderSessionID: message.senderSessionID, isQuestion: Boolean(message.isQuestion) };
68
- const name = uniqueAuthor(message, app);
69
- const input = app.$("#msgInput");
70
- if (name && !input.value.includes(`<at>@${name}</at>`)) {
71
- const prefix = `<at>@${name}</at> `;
72
- target.autoMention = name;
73
- replaceEditorRange(input, 0, 0, prefix); input.setCaret(prefix.length);
74
- input.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertText" }));
75
- }
76
- app.setReplyTarget(roomId, target);
77
- input.focus({ preventScroll: true });
69
+ if (!message || !app.state.room)
70
+ return;
71
+ const roomId = app.state.room.id;
72
+ removeAutoMention(app.replyTargetFor(roomId), app.$("#msgInput"));
73
+ const target = { id: message.id, text: message.text, senderId: message.senderId, senderSessionID: message.senderSessionID, isQuestion: Boolean(message.isQuestion) };
74
+ const name = uniqueAuthor(message, app);
75
+ const input = app.$("#msgInput");
76
+ if (name && !input.value.includes(`<at>@${name}</at>`)) {
77
+ const prefix = `<at>@${name}</at> `;
78
+ target.autoMention = name;
79
+ replaceEditorRange(input, 0, 0, prefix);
80
+ input.setCaret(prefix.length);
81
+ input.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertText" }));
82
+ }
83
+ app.setReplyTarget(roomId, target);
84
+ input.focus({ preventScroll: true });
78
85
  }
79
-
80
86
  function cancelReply(app) {
81
- const roomId = app.state.room?.id, target = roomId && app.replyTargetFor(roomId);
82
- if (!roomId || !target) return;
83
- removeAutoMention(target, app.$("#msgInput"));
84
- app.clearReplyTarget(roomId);
87
+ const roomId = app.state.room?.id, target = roomId && app.replyTargetFor(roomId);
88
+ if (!roomId || !target)
89
+ return;
90
+ removeAutoMention(target, app.$("#msgInput"));
91
+ app.clearReplyTarget(roomId);
85
92
  }
86
-
87
93
  function removeAutoMention(target, input) {
88
- const prefix = target?.autoMention && `<at>@${target.autoMention}</at> `;
89
- if (prefix && input.value.startsWith(prefix)) {
90
- setEditorSelection(input, 0, prefix.length); getSelection().deleteFromDocument(); setCaret(input, 0);
91
- input.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "deleteContentBackward" }));
92
- }
94
+ const prefix = target?.autoMention && `<at>@${target.autoMention}</at> `;
95
+ if (prefix && input.value.startsWith(prefix)) {
96
+ setEditorSelection(input, 0, prefix.length);
97
+ getSelection().deleteFromDocument();
98
+ setCaret(input, 0);
99
+ input.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "deleteContentBackward" }));
100
+ }
93
101
  }
94
-
95
102
  function uniqueAuthor(message, app) {
96
- const members = app.state.memberSessions.get(app.state.room?.id) || [];
97
- const matches = message.senderSessionID ? members.filter((item) => item.sessionID === message.senderSessionID)
98
- : members.filter((item) => item.name === message.senderId);
99
- const name = matches[0]?.name;
100
- return matches.length === 1 && members.filter((item) => item.name === name).length === 1 && matches[0].sessionID !== LS.sessionID && name !== "all" ? name : "";
103
+ const members = app.state.memberSessions.get(app.state.room?.id) || [];
104
+ const matches = message.senderSessionID ? members.filter((item) => item.sessionID === message.senderSessionID)
105
+ : members.filter((item) => item.name === message.senderId);
106
+ const name = matches[0]?.name;
107
+ return matches.length === 1 && members.filter((item) => item.name === name).length === 1 && matches[0].sessionID !== LS.sessionID && name !== "all" ? name : "";
101
108
  }
102
-
103
109
  function senderName(message, app) {
104
- if (message.senderSessionID === LS.sessionID) return app.t("you");
105
- const members = app.state.memberSessions.get(app.state.room?.id) || [];
106
- const match = message.senderSessionID && members.find((item) => item.sessionID === message.senderSessionID);
107
- if (match) return match.name;
108
- return message.senderId || app.t("guest");
110
+ if (message.senderSessionID === LS.sessionID)
111
+ return app.t("you");
112
+ const members = app.state.memberSessions.get(app.state.room?.id) || [];
113
+ const match = message.senderSessionID && members.find((item) => item.sessionID === message.senderSessionID);
114
+ if (match)
115
+ return match.name;
116
+ return message.senderId || app.t("guest");
109
117
  }
110
-
111
118
  function quoteButton(message, app) {
112
- const button = document.createElement("button"), targetId = message.answerToMessageID;
113
- const original = app.state.room.messages.find((item) => item.id === targetId);
114
- button.type = "button"; button.className = "reply-quote"; button.dataset.replyTargetId = targetId;
115
- button.setAttribute("aria-label", app.t("replyOpenOriginal")); button.dataset.i18nAriaLabel = "replyOpenOriginal";
116
- button.textContent = original ? (original.recalledAt ? app.t("replyOriginalRecalled") : `${senderName(original, app)} · ${excerpt(original.text)}`) : app.t("replyOpenOriginal");
117
- return button;
119
+ const button = document.createElement("button"), targetId = message.answerToMessageID;
120
+ const original = app.state.room.messages.find((item) => item.id === targetId);
121
+ button.type = "button";
122
+ button.className = "reply-quote";
123
+ button.dataset.replyTargetId = targetId;
124
+ button.setAttribute("aria-label", app.t("replyOpenOriginal"));
125
+ button.dataset.i18nAriaLabel = "replyOpenOriginal";
126
+ button.textContent = original ? (original.recalledAt ? app.t("replyOriginalRecalled") : `${senderName(original, app)} · ${excerpt(original.text)}`) : app.t("replyOpenOriginal");
127
+ return button;
118
128
  }
119
-
120
129
  async function jumpToOriginal(roomId, messageId, app) {
121
- const generation = app.state.navigationGeneration;
122
- let entry = app.state.rooms.get(roomId), room = entry?.room;
123
- if (!entry || !room) return;
124
- let original = room.messages.find((item) => item.id === messageId), beforeSeq;
125
- try {
126
- while (!original) {
127
- const query = new URLSearchParams({ limit: "100" });
128
- if (beforeSeq) query.set("beforeSeq", String(beforeSeq));
129
- const page = await app.api(`/rooms/${encodeURIComponent(roomId)}/history?${query}`);
130
- entry = app.state.rooms.get(roomId); if (!entry) return;
131
- room = entry.room;
132
- original = (page.messages || []).find((item) => item.id === messageId);
133
- const merged = new Map([...room.messages, ...(page.messages || []).map((item) => ({ ...item, roomId }))].map((item) => [item.id, item]));
134
- room.messages = [...merged.values()].sort((left, right) => left.createdAt - right.createdAt);
135
- // Keep the upward-pagination cursor aligned with what the jump loaded.
136
- if (typeof room.messages[0]?.seq === "number") entry.historyBeforeSeq = room.messages[0].seq;
137
- if (!page.hasMore) entry.historyComplete = true;
138
- if (original || !page.hasMore || !page.nextBeforeSeq || page.nextBeforeSeq === beforeSeq) break;
139
- beforeSeq = page.nextBeforeSeq;
130
+ const generation = app.state.navigationGeneration;
131
+ let entry = app.state.rooms.get(roomId), room = entry?.room;
132
+ if (!entry || !room)
133
+ return;
134
+ let original = room.messages.find((item) => item.id === messageId), beforeSeq;
135
+ try {
136
+ while (!original) {
137
+ const query = new URLSearchParams({ limit: "100" });
138
+ if (beforeSeq)
139
+ query.set("beforeSeq", String(beforeSeq));
140
+ const page = await app.api(`/rooms/${encodeURIComponent(roomId)}/history?${query}`);
141
+ entry = app.state.rooms.get(roomId);
142
+ if (!entry)
143
+ return;
144
+ room = entry.room;
145
+ original = (page.messages || []).find((item) => item.id === messageId);
146
+ const merged = new Map([...room.messages, ...(page.messages || []).map((item) => ({ ...item, roomId }))].map((item) => [item.id, item]));
147
+ room.messages = [...merged.values()].sort((left, right) => left.createdAt - right.createdAt);
148
+ // Keep the upward-pagination cursor aligned with what the jump loaded.
149
+ if (typeof room.messages[0]?.seq === "number")
150
+ entry.historyBeforeSeq = room.messages[0].seq;
151
+ if (!page.hasMore)
152
+ entry.historyComplete = true;
153
+ if (original || !page.hasMore || !page.nextBeforeSeq || page.nextBeforeSeq === beforeSeq)
154
+ break;
155
+ beforeSeq = page.nextBeforeSeq;
156
+ }
140
157
  }
141
- } catch { return; }
142
- if (!original) return markUnavailable(messageId, roomId, app);
143
- app.state.positions.set(roomId, { messageId, offset: 0, atBottom: false }); app.savePosition(roomId, { messageId, offset: 0, atBottom: false });
144
- // Jumping to an older message is the reader choosing history.
145
- app.state.followBottom = false;
146
- if (app.state.room?.id === roomId && app.state.navigationGeneration === generation) {
147
- app.state.room = app.state.rooms.get(roomId)?.room || room; app.rerenderMessages();
148
- const row = document.querySelector(`[data-msg-id="${CSS.escape(messageId)}"]`), thread = app.$("#thread");
149
- if (row && thread) {
150
- // Land the message's top on the thread's top edge so the most context shows.
151
- thread.scrollTop += row.getBoundingClientRect().top - (thread.getBoundingClientRect().top + thread.clientTop);
152
- clearTimeout(row._jumpFlashTimer); row.classList.remove("jump-flash"); void row.offsetWidth; row.classList.add("jump-flash");
153
- row._jumpFlashTimer = setTimeout(() => row.classList.remove("jump-flash"), 900);
158
+ catch {
159
+ return;
154
160
  }
155
- }
156
- const quote = document.querySelector(`[data-reply-target-id="${CSS.escape(messageId)}"]`);
157
- if (quote) quote.textContent = `${senderName(original, app)} · ${excerpt(original.text)}`;
161
+ if (!original)
162
+ return markUnavailable(messageId, roomId, app);
163
+ app.state.positions.set(roomId, { messageId, offset: 0, atBottom: false });
164
+ app.savePosition(roomId, { messageId, offset: 0, atBottom: false });
165
+ // Jumping to an older message is the reader choosing history.
166
+ app.state.followBottom = false;
167
+ if (app.state.room?.id === roomId && app.state.navigationGeneration === generation) {
168
+ app.state.room = app.state.rooms.get(roomId)?.room || room;
169
+ app.rerenderMessages();
170
+ const row = document.querySelector(`[data-msg-id="${CSS.escape(messageId)}"]`), thread = app.$("#thread");
171
+ if (row && thread) {
172
+ // Land the message's top on the thread's top edge so the most context shows.
173
+ thread.scrollTop += row.getBoundingClientRect().top - (thread.getBoundingClientRect().top + thread.clientTop);
174
+ clearTimeout(row._jumpFlashTimer);
175
+ row.classList.remove("jump-flash");
176
+ void row.offsetWidth;
177
+ row.classList.add("jump-flash");
178
+ row._jumpFlashTimer = setTimeout(() => row.classList.remove("jump-flash"), 900);
179
+ }
180
+ }
181
+ const quote = document.querySelector(`[data-reply-target-id="${CSS.escape(messageId)}"]`);
182
+ if (quote)
183
+ quote.textContent = `${senderName(original, app)} · ${excerpt(original.text)}`;
158
184
  }
159
-
160
185
  function markUnavailable(messageId, roomId, app) {
161
- if (app.state.room?.id !== roomId) return;
162
- const quote = document.querySelector(`[data-reply-target-id="${CSS.escape(messageId)}"]`);
163
- if (quote) { quote.textContent = app.t("replyOriginalUnavailable"); quote.disabled = true; }
186
+ if (app.state.room?.id !== roomId)
187
+ return;
188
+ const quote = document.querySelector(`[data-reply-target-id="${CSS.escape(messageId)}"]`);
189
+ if (quote) {
190
+ quote.textContent = app.t("replyOriginalUnavailable");
191
+ quote.disabled = true;
192
+ }
164
193
  }
@@ -6,80 +6,77 @@ export const TEXT_PREVIEW_LIMIT = 2 * 1024 * 1024;
6
6
  export const OFFICE_PREVIEW_LIMIT = 20 * 1024 * 1024;
7
7
  export const OFFICE_KINDS = new Set(["docx", "xlsx", "pptx"]);
8
8
  const OFFICE_MIMES = {
9
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
10
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
11
- "application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
9
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
10
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
11
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
12
12
  };
13
-
14
13
  const MIME_LANGUAGES = {
15
- "application/json": "json", "application/ld+json": "json",
16
- "application/xml": "xml", "text/xml": "xml",
17
- "application/javascript": "javascript", "application/x-javascript": "javascript",
18
- "application/typescript": "typescript",
19
- "application/x-yaml": "yaml", "application/yaml": "yaml",
20
- "application/toml": "ini",
21
- "text/html": "xml", "text/css": "css",
14
+ "application/json": "json", "application/ld+json": "json",
15
+ "application/xml": "xml", "text/xml": "xml",
16
+ "application/javascript": "javascript", "application/x-javascript": "javascript",
17
+ "application/typescript": "typescript",
18
+ "application/x-yaml": "yaml", "application/yaml": "yaml",
19
+ "application/toml": "ini",
20
+ "text/html": "xml", "text/css": "css",
22
21
  };
23
-
24
22
  const EXTENSION_LANGUAGES = {
25
- txt: "", log: "", csv: "", tsv: "",
26
- json: "json", jsonc: "json", yaml: "yaml", yml: "yaml",
27
- toml: "ini", ini: "ini", conf: "ini", env: "ini", properties: "properties",
28
- sh: "bash", bash: "bash", zsh: "bash", fish: "bash",
29
- ps1: "powershell", bat: "dos", cmd: "dos",
30
- js: "javascript", mjs: "javascript", cjs: "javascript", jsx: "javascript",
31
- ts: "typescript", tsx: "typescript",
32
- py: "python", rb: "ruby", go: "go", rs: "rust", java: "java",
33
- kt: "kotlin", kts: "kotlin", c: "c", h: "c", cpp: "cpp", hpp: "cpp", cc: "cpp",
34
- cs: "csharp", php: "php", swift: "swift", sql: "sql",
35
- html: "xml", htm: "xml", css: "css", scss: "scss", less: "less",
36
- xml: "xml", svg: "xml", vue: "xml", svelte: "xml",
37
- lua: "lua", r: "r", pl: "perl", pm: "perl", dart: "dart",
38
- gradle: "groovy", dockerfile: "dockerfile", makefile: "makefile", mk: "makefile",
23
+ txt: "", log: "", csv: "", tsv: "",
24
+ json: "json", jsonc: "json", yaml: "yaml", yml: "yaml",
25
+ toml: "ini", ini: "ini", conf: "ini", env: "ini", properties: "properties",
26
+ sh: "bash", bash: "bash", zsh: "bash", fish: "bash",
27
+ ps1: "powershell", bat: "dos", cmd: "dos",
28
+ js: "javascript", mjs: "javascript", cjs: "javascript", jsx: "javascript",
29
+ ts: "typescript", tsx: "typescript",
30
+ py: "python", rb: "ruby", go: "go", rs: "rust", java: "java",
31
+ kt: "kotlin", kts: "kotlin", c: "c", h: "c", cpp: "cpp", hpp: "cpp", cc: "cpp",
32
+ cs: "csharp", php: "php", swift: "swift", sql: "sql",
33
+ html: "xml", htm: "xml", css: "css", scss: "scss", less: "less",
34
+ xml: "xml", svg: "xml", vue: "xml", svelte: "xml",
35
+ lua: "lua", r: "r", pl: "perl", pm: "perl", dart: "dart",
36
+ gradle: "groovy", dockerfile: "dockerfile", makefile: "makefile", mk: "makefile",
39
37
  };
40
-
41
38
  const LANGUAGE_NAMES = {
42
- typescript: "TypeScript", javascript: "JavaScript", python: "Python", ruby: "Ruby",
43
- bash: "Shell", yaml: "YAML", json: "JSON", xml: "XML", c: "C", cpp: "C++",
44
- csharp: "C#", kotlin: "Kotlin", rust: "Rust", go: "Go", java: "Java",
45
- php: "PHP", swift: "Swift", sql: "SQL", css: "CSS", scss: "SCSS", less: "Less",
46
- ini: "Config", properties: "Properties", powershell: "PowerShell", dos: "Batch",
47
- dockerfile: "Dockerfile", makefile: "Makefile", lua: "Lua", r: "R", perl: "Perl",
48
- dart: "Dart", groovy: "Gradle",
39
+ typescript: "TypeScript", javascript: "JavaScript", python: "Python", ruby: "Ruby",
40
+ bash: "Shell", yaml: "YAML", json: "JSON", xml: "XML", c: "C", cpp: "C++",
41
+ csharp: "C#", kotlin: "Kotlin", rust: "Rust", go: "Go", java: "Java",
42
+ php: "PHP", swift: "Swift", sql: "SQL", css: "CSS", scss: "SCSS", less: "Less",
43
+ ini: "Config", properties: "Properties", powershell: "PowerShell", dos: "Batch",
44
+ dockerfile: "Dockerfile", makefile: "Makefile", lua: "Lua", r: "R", perl: "Perl",
45
+ dart: "Dart", groovy: "Gradle",
49
46
  };
50
-
51
47
  const TEXT_MIMES = new Set([
52
- "application/json", "application/ld+json", "application/xml", "application/x-yaml",
53
- "application/yaml", "application/toml", "application/javascript",
54
- "application/x-javascript", "application/typescript",
48
+ "application/json", "application/ld+json", "application/xml", "application/x-yaml",
49
+ "application/yaml", "application/toml", "application/javascript",
50
+ "application/x-javascript", "application/typescript",
55
51
  ]);
56
-
57
52
  function fileExtension(name) {
58
- const base = String(name || "").toLowerCase().split(/[\\/]/).pop() || "";
59
- if (base === "dockerfile" || base === "makefile") return base;
60
- return /\.([a-z0-9]+)$/.exec(base)?.[1] || "";
53
+ const base = String(name || "").toLowerCase().split(/[\\/]/).pop() || "";
54
+ if (base === "dockerfile" || base === "makefile")
55
+ return base;
56
+ return /\.([a-z0-9]+)$/.exec(base)?.[1] || "";
61
57
  }
62
-
63
58
  function isTextMime(mime) {
64
- if (mime === "text/markdown" || mime === "text/x-markdown") return false;
65
- return mime.startsWith("text/") || TEXT_MIMES.has(mime);
59
+ if (mime === "text/markdown" || mime === "text/x-markdown")
60
+ return false;
61
+ return mime.startsWith("text/") || TEXT_MIMES.has(mime);
66
62
  }
67
-
68
63
  export function docPreviewFormat(resource) {
69
- const mime = String(resource?.mimeType || "").split(";")[0].trim().toLowerCase();
70
- const name = String(resource?.name || "");
71
- const ext = fileExtension(name);
72
- if (mime === "application/pdf" || ext === "pdf") return { kind: "pdf", language: "", label: "PDF" };
73
- if (mime === "text/markdown" || mime === "text/x-markdown" || ext === "md" || ext === "markdown") {
74
- return { kind: "markdown", language: "", label: "" };
75
- }
76
- // Server sniffing reports Office packages as octet-stream, so the extension counts.
77
- const office = OFFICE_MIMES[mime] || (OFFICE_KINDS.has(ext) ? ext : "");
78
- if (office) return { kind: office, language: "", label: office.toUpperCase() };
79
- const knownExtension = Object.hasOwn(EXTENSION_LANGUAGES, ext);
80
- if (!knownExtension && !isTextMime(mime)) return null;
81
- const language = knownExtension ? EXTENSION_LANGUAGES[ext] : MIME_LANGUAGES[mime] || "";
82
- return { kind: "text", language, label: LANGUAGE_NAMES[language] || (ext ? ext.toUpperCase() : "Text") };
64
+ const mime = String(resource?.mimeType || "").split(";")[0].trim().toLowerCase();
65
+ const name = String(resource?.name || "");
66
+ const ext = fileExtension(name);
67
+ if (mime === "application/pdf" || ext === "pdf")
68
+ return { kind: "pdf", language: "", label: "PDF" };
69
+ if (mime === "text/markdown" || mime === "text/x-markdown" || ext === "md" || ext === "markdown") {
70
+ return { kind: "markdown", language: "", label: "" };
71
+ }
72
+ // Server sniffing reports Office packages as octet-stream, so the extension counts.
73
+ const office = OFFICE_MIMES[mime] || (OFFICE_KINDS.has(ext) ? ext : "");
74
+ if (office)
75
+ return { kind: office, language: "", label: office.toUpperCase() };
76
+ const knownExtension = Object.hasOwn(EXTENSION_LANGUAGES, ext);
77
+ if (!knownExtension && !isTextMime(mime))
78
+ return null;
79
+ const language = knownExtension ? EXTENSION_LANGUAGES[ext] : MIME_LANGUAGES[mime] || "";
80
+ return { kind: "text", language, label: LANGUAGE_NAMES[language] || (ext ? ext.toUpperCase() : "Text") };
83
81
  }
84
-
85
- export const isDocPreviewResource = (resource) => docPreviewFormat(resource) !== null;
82
+ export const isDocPreviewResource = (resource) => docPreviewFormat(resource) !== null;
@@ -1,68 +1,71 @@
1
1
  import { formatRoomPreview } from "./system-messages.js";
2
-
3
2
  // The room rows in the rail and the mobile drawer share one renderer.
4
3
  export function renderRoomOptions(app, list, rooms) {
5
- if (!list) return;
4
+ if (!list)
5
+ return;
6
6
  list.textContent = "";
7
7
  const ordered = [...rooms].sort((left, right) => Number(app.state.rooms.has(right.id) || right.joined) - Number(app.state.rooms.has(left.id) || left.joined));
8
8
  for (const room of ordered) {
9
- const row = document.createElement("li"), button = document.createElement("button");
10
- button.type = "button";
11
- button.dataset.roomId = room.id;
12
- const entry = app.state.rooms.get(room.id);
13
- const joined = Boolean(entry || room.joined);
14
- const pending = !joined && Boolean(app.state.pendingJoinIds?.has(room.id));
15
- const approval = !joined && room.joinPolicy === "approval";
16
- button.className = `room-row${app.state.room?.id === room.id ? " selected" : ""}${joined ? " joined" : ""}`;
17
- if (app.state.room?.id === room.id) button.setAttribute("aria-current", "page");
18
- button.title = app.t(joined ? "joined" : pending ? "joinPendingStatus" : approval ? "joinRequired" : "joinAction");
19
- const name = document.createElement("span");
20
- name.className = "r-name";
21
- name.textContent = room.name;
22
- const kind = document.createElement("span");
23
- kind.className = "r-kind";
24
- if (room.kind === "direct") app.setText(kind, "direct");
25
- const meta = document.createElement("span");
26
- meta.className = "r-meta";
27
- const shownRoom = entry?.room || room;
28
- meta.textContent = app.t("roomMeta", { members: shownRoom.participants.length, count: shownRoom.messages.length });
29
- const preview = document.createElement("span");
30
- preview.className = "r-preview";
31
- preview.textContent = entry ? formatRoomPreview(entry, shownRoom.messages.at(-1), app) : "";
32
- const status = document.createElement("span");
33
- status.className = "r-status";
34
- app.setText(status, joined ? "joined" : pending ? "joinPendingStatus" : approval ? "joinRequired" : "joinAction");
35
- button.append(name, kind, meta, preview, status);
36
- const unread = entry && app.state.room?.id !== room.id ? (entry.unreadOverflow ? 100 : entry.unreadIds.size) : 0;
37
- const openQuestions = Number(shownRoom.openQuestions) || 0;
38
- // Same badge slot as unread: a pending question shows "?" instead of a count.
39
- if (unread || openQuestions) {
40
- const badge = document.createElement("span");
41
- badge.className = openQuestions ? "r-badge r-badge-question" : "r-badge";
42
- badge.textContent = openQuestions ? "?" : (unread > 99 ? "99+" : String(unread));
43
- const label = openQuestions ? app.t("openQuestions", { count: openQuestions }) : app.t("unreadMessages", { count: unread });
44
- badge.title = label;
45
- badge.setAttribute("aria-label", label);
46
- button.append(badge);
47
- }
48
- button.addEventListener("click", () => {
49
- const name = app.state.myName || app.$("#inName").value.trim() || app.t("guest");
50
- // A protected room must ask before turning a click into a join request.
51
- if (!joined && approval && !pending && app.confirmAction) {
52
- void app.confirmAction(app.t("joinApprovalPrompt", { name: room.name })).then((ok) => { if (ok) void app.joinRoom(room.id, name); });
53
- return;
9
+ const row = document.createElement("li"), button = document.createElement("button");
10
+ button.type = "button";
11
+ button.dataset.roomId = room.id;
12
+ const entry = app.state.rooms.get(room.id);
13
+ const joined = Boolean(entry || room.joined);
14
+ const pending = !joined && Boolean(app.state.pendingJoinIds?.has(room.id));
15
+ const approval = !joined && room.joinPolicy === "approval";
16
+ button.className = `room-row${app.state.room?.id === room.id ? " selected" : ""}${joined ? " joined" : ""}`;
17
+ if (app.state.room?.id === room.id)
18
+ button.setAttribute("aria-current", "page");
19
+ button.title = app.t(joined ? "joined" : pending ? "joinPendingStatus" : approval ? "joinRequired" : "joinAction");
20
+ const name = document.createElement("span");
21
+ name.className = "r-name";
22
+ name.textContent = room.name;
23
+ const kind = document.createElement("span");
24
+ kind.className = "r-kind";
25
+ if (room.kind === "direct")
26
+ app.setText(kind, "direct");
27
+ const meta = document.createElement("span");
28
+ meta.className = "r-meta";
29
+ const shownRoom = entry?.room || room;
30
+ meta.textContent = app.t("roomMeta", { members: shownRoom.participants.length, count: shownRoom.messages.length });
31
+ const preview = document.createElement("span");
32
+ preview.className = "r-preview";
33
+ preview.textContent = entry ? formatRoomPreview(entry, shownRoom.messages.at(-1), app) : "";
34
+ const status = document.createElement("span");
35
+ status.className = "r-status";
36
+ app.setText(status, joined ? "joined" : pending ? "joinPendingStatus" : approval ? "joinRequired" : "joinAction");
37
+ button.append(name, kind, meta, preview, status);
38
+ const unread = entry && app.state.room?.id !== room.id ? (entry.unreadOverflow ? 100 : entry.unreadIds.size) : 0;
39
+ const openQuestions = Number(shownRoom.openQuestions) || 0;
40
+ // Same badge slot as unread: a pending question shows "?" instead of a count.
41
+ if (unread || openQuestions) {
42
+ const badge = document.createElement("span");
43
+ badge.className = openQuestions ? "r-badge r-badge-question" : "r-badge";
44
+ badge.textContent = openQuestions ? "?" : (unread > 99 ? "99+" : String(unread));
45
+ const label = openQuestions ? app.t("openQuestions", { count: openQuestions }) : app.t("unreadMessages", { count: unread });
46
+ badge.title = label;
47
+ badge.setAttribute("aria-label", label);
48
+ button.append(badge);
54
49
  }
55
- void app.joinRoom(room.id, name);
56
- });
57
- row.append(button);
58
- list.append(row);
50
+ button.addEventListener("click", () => {
51
+ const name = app.state.myName || app.$("#inName").value.trim() || app.t("guest");
52
+ // A protected room must ask before turning a click into a join request.
53
+ if (!joined && approval && !pending && app.confirmAction) {
54
+ void app.confirmAction(app.t("joinApprovalPrompt", { name: room.name })).then((ok) => { if (ok)
55
+ void app.joinRoom(room.id, name); });
56
+ return;
57
+ }
58
+ void app.joinRoom(room.id, name);
59
+ });
60
+ row.append(button);
61
+ list.append(row);
59
62
  }
60
63
  // Other rooms' unread changes only reach the title through this rerender.
61
64
  app.updateTitle();
62
65
  const keyHint = document.getElementById("railKeyHint");
63
66
  if (keyHint && list.id === "roomListChat") {
64
- // Alt+Arrow only cycles joined rooms, so the hint appears once there is a choice.
65
- const joined = rooms.filter((room) => app.state.rooms.has(room.id) || room.joined).length;
66
- keyHint.hidden = joined < 2;
67
+ // Alt+Arrow only cycles joined rooms, so the hint appears once there is a choice.
68
+ const joined = rooms.filter((room) => app.state.rooms.has(room.id) || room.joined).length;
69
+ keyHint.hidden = joined < 2;
67
70
  }
68
- }
71
+ }