@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.
- package/CHANGELOG.md +10 -0
- package/README.md +18 -62
- package/README.zh-CN.md +25 -69
- package/dist/cli.js +466 -188
- package/package.json +8 -5
- package/packages/chat-room-channeld/README.md +25 -3
- package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
- package/packages/chat-room-channeld/src/adapter.ts +5 -0
- package/packages/chat-room-channeld/src/cli.ts +72 -5
- package/packages/chat-room-channeld/src/host.ts +17 -2
- package/packages/chat-room-channeld/src/pg/database.ts +187 -0
- package/packages/chat-room-channeld/src/pg/migrate.ts +150 -0
- package/packages/chat-room-channeld/src/pg/schema.ts +60 -0
- package/packages/chat-room-channeld/src/pg/sql.mjs +175 -0
- package/packages/chat-room-channeld/src/pg/sqlite.ts +100 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +133 -0
- package/packages/chat-room-channeld/src/protocol.ts +1 -0
- package/packages/chat-room-channeld/src/state.ts +73 -97
- package/packages/chat-room-channeld/src/stats.ts +140 -109
- package/server/assets/base.css +3 -1
- package/server/assets/chat/admin-badge.js +32 -30
- package/server/assets/chat/admin.js +198 -161
- package/server/assets/chat/announcements.js +295 -208
- package/server/assets/chat/attachment-store.js +106 -75
- package/server/assets/chat/attachments.js +686 -441
- package/server/assets/chat/chat-background.js +185 -156
- package/server/assets/chat/clipboard.js +44 -25
- package/server/assets/chat/confirm-dialog.js +36 -33
- package/server/assets/chat/copy-action.js +40 -40
- package/server/assets/chat/create-room-dialog.js +50 -47
- package/server/assets/chat/diagram-viewer.js +293 -234
- package/server/assets/chat/doc-preview.js +507 -441
- package/server/assets/chat/editor.js +423 -335
- package/server/assets/chat/events.js +637 -510
- package/server/assets/chat/files.js +476 -430
- package/server/assets/chat/history-loader.js +79 -73
- package/server/assets/chat/icons.js +9 -11
- package/server/assets/chat/image-zoom.js +239 -176
- package/server/assets/chat/index.js +2 -3
- package/server/assets/chat/install-prompt.js +86 -66
- package/server/assets/chat/integration-account-schema.js +88 -86
- package/server/assets/chat/integration-editor.js +162 -153
- package/server/assets/chat/integration-values.js +109 -100
- package/server/assets/chat/integrations.js +689 -622
- package/server/assets/chat/join-requests.js +408 -358
- package/server/assets/chat/locales/de.js +193 -194
- package/server/assets/chat/locales/es.js +193 -194
- package/server/assets/chat/locales/fr.js +193 -194
- package/server/assets/chat/locales/index.js +1 -2
- package/server/assets/chat/locales/it.js +193 -194
- package/server/assets/chat/locales/ja.js +193 -193
- package/server/assets/chat/locales/ko.js +193 -193
- package/server/assets/chat/markdown-footnotes.js +134 -102
- package/server/assets/chat/markdown.js +547 -403
- package/server/assets/chat/members.js +236 -197
- package/server/assets/chat/mentions.js +157 -133
- package/server/assets/chat/message-cache.js +40 -33
- package/server/assets/chat/message-polling.js +280 -227
- package/server/assets/chat/message-window.js +74 -55
- package/server/assets/chat/messages.js +552 -480
- package/server/assets/chat/office-preview.js +46 -45
- package/server/assets/chat/palette.js +450 -417
- package/server/assets/chat/panels.js +94 -78
- package/server/assets/chat/pwa.js +144 -73
- package/server/assets/chat/questions.js +372 -302
- package/server/assets/chat/recall.js +320 -273
- package/server/assets/chat/receipts.js +149 -121
- package/server/assets/chat/reminders.js +331 -214
- package/server/assets/chat/replies.js +165 -130
- package/server/assets/chat/resource-format.js +59 -62
- package/server/assets/chat/room-list.js +58 -55
- package/server/assets/chat/room-watcher.js +72 -50
- package/server/assets/chat/rooms.js +623 -500
- package/server/assets/chat/search.js +136 -114
- package/server/assets/chat/settings.js +223 -200
- package/server/assets/chat/shiki.js +61 -62
- package/server/assets/chat/shortcuts.js +212 -187
- package/server/assets/chat/side-pane.js +160 -150
- package/server/assets/chat/state.js +849 -735
- package/server/assets/chat/system-events.js +45 -43
- package/server/assets/chat/system-messages.js +57 -56
- package/server/assets/chat/task-form.js +178 -182
- package/server/assets/chat/task-row.js +158 -155
- package/server/assets/chat/tasks.js +653 -587
- package/server/assets/chat/viewport.js +32 -29
- package/server/assets/chat/window-controls.js +32 -32
- package/server/assets/conversation.css +10 -4
- package/server/chat-server.ts +9 -1
- package/server/chat.html +2 -1
- package/server/routes/pages.ts +7 -5
- package/server/sw.js +346 -268
- 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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
136
|
-
|
|
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
|
-
|
|
151
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
65
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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)
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
+
}
|