@alexsun-top/opencode-chat-room 0.8.2 → 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 (92) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +18 -62
  3. package/README.zh-CN.md +25 -69
  4. package/dist/cli.js +466 -188
  5. package/package.json +8 -5
  6. package/packages/chat-room-channeld/README.md +25 -3
  7. package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
  8. package/packages/chat-room-channeld/src/adapter.ts +5 -0
  9. package/packages/chat-room-channeld/src/cli.ts +72 -5
  10. package/packages/chat-room-channeld/src/host.ts +17 -2
  11. package/packages/chat-room-channeld/src/pg/database.ts +187 -0
  12. package/packages/chat-room-channeld/src/pg/migrate.ts +150 -0
  13. package/packages/chat-room-channeld/src/pg/schema.ts +60 -0
  14. package/packages/chat-room-channeld/src/pg/sql.mjs +175 -0
  15. package/packages/chat-room-channeld/src/pg/sqlite.ts +100 -0
  16. package/packages/chat-room-channeld/src/pg/worker.mjs +133 -0
  17. package/packages/chat-room-channeld/src/protocol.ts +1 -0
  18. package/packages/chat-room-channeld/src/state.ts +73 -97
  19. package/packages/chat-room-channeld/src/stats.ts +140 -109
  20. package/server/assets/base.css +3 -1
  21. package/server/assets/chat/admin-badge.js +32 -30
  22. package/server/assets/chat/admin.js +198 -161
  23. package/server/assets/chat/announcements.js +295 -208
  24. package/server/assets/chat/attachment-store.js +106 -75
  25. package/server/assets/chat/attachments.js +686 -441
  26. package/server/assets/chat/chat-background.js +185 -156
  27. package/server/assets/chat/clipboard.js +44 -25
  28. package/server/assets/chat/confirm-dialog.js +36 -33
  29. package/server/assets/chat/copy-action.js +40 -40
  30. package/server/assets/chat/create-room-dialog.js +50 -47
  31. package/server/assets/chat/diagram-viewer.js +293 -234
  32. package/server/assets/chat/doc-preview.js +507 -441
  33. package/server/assets/chat/editor.js +423 -335
  34. package/server/assets/chat/events.js +637 -510
  35. package/server/assets/chat/files.js +476 -430
  36. package/server/assets/chat/history-loader.js +79 -73
  37. package/server/assets/chat/icons.js +9 -11
  38. package/server/assets/chat/image-zoom.js +239 -176
  39. package/server/assets/chat/index.js +2 -3
  40. package/server/assets/chat/install-prompt.js +86 -66
  41. package/server/assets/chat/integration-account-schema.js +88 -86
  42. package/server/assets/chat/integration-editor.js +162 -153
  43. package/server/assets/chat/integration-values.js +109 -100
  44. package/server/assets/chat/integrations.js +689 -622
  45. package/server/assets/chat/join-requests.js +408 -358
  46. package/server/assets/chat/locales/de.js +193 -194
  47. package/server/assets/chat/locales/es.js +193 -194
  48. package/server/assets/chat/locales/fr.js +193 -194
  49. package/server/assets/chat/locales/index.js +1 -2
  50. package/server/assets/chat/locales/it.js +193 -194
  51. package/server/assets/chat/locales/ja.js +193 -193
  52. package/server/assets/chat/locales/ko.js +193 -193
  53. package/server/assets/chat/markdown-footnotes.js +134 -102
  54. package/server/assets/chat/markdown.js +547 -403
  55. package/server/assets/chat/members.js +236 -197
  56. package/server/assets/chat/mentions.js +157 -133
  57. package/server/assets/chat/message-cache.js +40 -33
  58. package/server/assets/chat/message-polling.js +280 -227
  59. package/server/assets/chat/message-window.js +74 -55
  60. package/server/assets/chat/messages.js +552 -480
  61. package/server/assets/chat/office-preview.js +46 -45
  62. package/server/assets/chat/palette.js +450 -417
  63. package/server/assets/chat/panels.js +94 -78
  64. package/server/assets/chat/pwa.js +144 -73
  65. package/server/assets/chat/questions.js +372 -302
  66. package/server/assets/chat/recall.js +320 -273
  67. package/server/assets/chat/receipts.js +149 -121
  68. package/server/assets/chat/reminders.js +331 -214
  69. package/server/assets/chat/replies.js +165 -130
  70. package/server/assets/chat/resource-format.js +59 -62
  71. package/server/assets/chat/room-list.js +58 -55
  72. package/server/assets/chat/room-watcher.js +72 -50
  73. package/server/assets/chat/rooms.js +623 -500
  74. package/server/assets/chat/search.js +136 -114
  75. package/server/assets/chat/settings.js +223 -200
  76. package/server/assets/chat/shiki.js +61 -62
  77. package/server/assets/chat/shortcuts.js +212 -187
  78. package/server/assets/chat/side-pane.js +160 -150
  79. package/server/assets/chat/state.js +849 -735
  80. package/server/assets/chat/system-events.js +45 -43
  81. package/server/assets/chat/system-messages.js +57 -56
  82. package/server/assets/chat/task-form.js +178 -182
  83. package/server/assets/chat/task-row.js +158 -155
  84. package/server/assets/chat/tasks.js +653 -587
  85. package/server/assets/chat/viewport.js +32 -29
  86. package/server/assets/chat/window-controls.js +32 -32
  87. package/server/assets/conversation.css +10 -4
  88. package/server/chat-server.ts +9 -1
  89. package/server/chat.html +2 -1
  90. package/server/routes/pages.ts +7 -5
  91. package/server/sw.js +346 -268
  92. package/src/web/integration-rules-editor.ts +2 -0
@@ -1,158 +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
- }
46
- return row;
47
- };
48
- $("#msgList").addEventListener("click", (event) => {
49
- const button = event.target.closest?.("[data-reply-message], [data-reply-target-id]");
50
- if (!button || !app.state.room) return;
51
- const room = app.state.room, id = button.dataset.replyMessage || button.dataset.replyTargetId;
52
- if (button.dataset.replyMessage) selectReply(app.state.room.messages.find((item) => item.id === id), app);
53
- else void jumpToOriginal(room.id, id, app);
54
- });
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
+ });
55
67
  }
56
-
57
68
  function selectReply(message, app) {
58
- if (!message || !app.state.room) return;
59
- const roomId = app.state.room.id;
60
- removeAutoMention(app.replyTargetFor(roomId), app.$("#msgInput"));
61
- const target = { id: message.id, text: message.text, senderId: message.senderId, senderSessionID: message.senderSessionID, isQuestion: Boolean(message.isQuestion) };
62
- const name = uniqueAuthor(message, app);
63
- const input = app.$("#msgInput");
64
- if (name && !input.value.includes(`<at>@${name}</at>`)) {
65
- const prefix = `<at>@${name}</at> `;
66
- target.autoMention = name;
67
- replaceEditorRange(input, 0, 0, prefix); input.setCaret(prefix.length);
68
- input.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertText" }));
69
- }
70
- app.setReplyTarget(roomId, target);
71
- 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 });
72
85
  }
73
-
74
86
  function cancelReply(app) {
75
- const roomId = app.state.room?.id, target = roomId && app.replyTargetFor(roomId);
76
- if (!roomId || !target) return;
77
- removeAutoMention(target, app.$("#msgInput"));
78
- 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);
79
92
  }
80
-
81
93
  function removeAutoMention(target, input) {
82
- const prefix = target?.autoMention && `<at>@${target.autoMention}</at> `;
83
- if (prefix && input.value.startsWith(prefix)) {
84
- setEditorSelection(input, 0, prefix.length); getSelection().deleteFromDocument(); setCaret(input, 0);
85
- input.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "deleteContentBackward" }));
86
- }
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
+ }
87
101
  }
88
-
89
102
  function uniqueAuthor(message, app) {
90
- const members = app.state.memberSessions.get(app.state.room?.id) || [];
91
- const matches = message.senderSessionID ? members.filter((item) => item.sessionID === message.senderSessionID)
92
- : members.filter((item) => item.name === message.senderId);
93
- const name = matches[0]?.name;
94
- 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 : "";
95
108
  }
96
-
97
109
  function senderName(message, app) {
98
- if (message.senderSessionID === LS.sessionID) return app.t("you");
99
- const members = app.state.memberSessions.get(app.state.room?.id) || [];
100
- const match = message.senderSessionID && members.find((item) => item.sessionID === message.senderSessionID);
101
- if (match) return match.name;
102
- 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");
103
117
  }
104
-
105
118
  function quoteButton(message, app) {
106
- const button = document.createElement("button"), targetId = message.answerToMessageID;
107
- const original = app.state.room.messages.find((item) => item.id === targetId);
108
- button.type = "button"; button.className = "reply-quote"; button.dataset.replyTargetId = targetId;
109
- button.setAttribute("aria-label", app.t("replyOpenOriginal")); button.dataset.i18nAriaLabel = "replyOpenOriginal";
110
- button.textContent = original ? (original.recalledAt ? app.t("replyOriginalRecalled") : `${senderName(original, app)} · ${excerpt(original.text)}`) : app.t("replyOpenOriginal");
111
- 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;
112
128
  }
113
-
114
129
  async function jumpToOriginal(roomId, messageId, app) {
115
- const generation = app.state.navigationGeneration;
116
- let entry = app.state.rooms.get(roomId), room = entry?.room;
117
- if (!entry || !room) return;
118
- let original = room.messages.find((item) => item.id === messageId), beforeSeq;
119
- try {
120
- while (!original) {
121
- const query = new URLSearchParams({ limit: "100" });
122
- if (beforeSeq) query.set("beforeSeq", String(beforeSeq));
123
- const page = await app.api(`/rooms/${encodeURIComponent(roomId)}/history?${query}`);
124
- entry = app.state.rooms.get(roomId); if (!entry) return;
125
- room = entry.room;
126
- original = (page.messages || []).find((item) => item.id === messageId);
127
- const merged = new Map([...room.messages, ...(page.messages || []).map((item) => ({ ...item, roomId }))].map((item) => [item.id, item]));
128
- room.messages = [...merged.values()].sort((left, right) => left.createdAt - right.createdAt);
129
- // Keep the upward-pagination cursor aligned with what the jump loaded.
130
- if (typeof room.messages[0]?.seq === "number") entry.historyBeforeSeq = room.messages[0].seq;
131
- if (!page.hasMore) entry.historyComplete = true;
132
- if (original || !page.hasMore || !page.nextBeforeSeq || page.nextBeforeSeq === beforeSeq) break;
133
- 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
+ }
134
157
  }
135
- } catch { return; }
136
- if (!original) return markUnavailable(messageId, roomId, app);
137
- app.state.positions.set(roomId, { messageId, offset: 0, atBottom: false }); app.savePosition(roomId, { messageId, offset: 0, atBottom: false });
138
- // Jumping to an older message is the reader choosing history.
139
- app.state.followBottom = false;
140
- if (app.state.room?.id === roomId && app.state.navigationGeneration === generation) {
141
- app.state.room = app.state.rooms.get(roomId)?.room || room; app.rerenderMessages();
142
- const row = document.querySelector(`[data-msg-id="${CSS.escape(messageId)}"]`), thread = app.$("#thread");
143
- if (row && thread) {
144
- // Land the message's top on the thread's top edge so the most context shows.
145
- thread.scrollTop += row.getBoundingClientRect().top - (thread.getBoundingClientRect().top + thread.clientTop);
146
- clearTimeout(row._jumpFlashTimer); row.classList.remove("jump-flash"); void row.offsetWidth; row.classList.add("jump-flash");
147
- row._jumpFlashTimer = setTimeout(() => row.classList.remove("jump-flash"), 900);
158
+ catch {
159
+ return;
148
160
  }
149
- }
150
- const quote = document.querySelector(`[data-reply-target-id="${CSS.escape(messageId)}"]`);
151
- 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)}`;
152
184
  }
153
-
154
185
  function markUnavailable(messageId, roomId, app) {
155
- if (app.state.room?.id !== roomId) return;
156
- const quote = document.querySelector(`[data-reply-target-id="${CSS.escape(messageId)}"]`);
157
- 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
+ }
158
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
+ }