@alexsun-top/opencode-chat-room 0.8.3 → 0.8.5
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 +7 -1
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/cli.ts +1 -1
- package/dist/cli.js +35 -16
- package/package.json +15 -9
- package/packages/chat-room-channeld/README.md +3 -2
- package/packages/chat-room-channeld/src/inbound.ts +3 -6
- package/packages/chat-room-channeld/src/pg/sql.mjs +157 -142
- package/packages/chat-room-channeld/src/pg/sql.mts +175 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +107 -99
- package/packages/chat-room-channeld/src/pg/worker.mts +166 -0
- package/plugin.ts +1 -1
- package/server/assets/chat/admin-badge.js +1 -1
- package/server/assets/chat/admin.js +16 -10
- package/server/assets/chat/announcements.js +12 -2
- package/server/assets/chat/attachment-store.js +15 -6
- package/server/assets/chat/attachments.js +48 -33
- package/server/assets/chat/chat-background.js +8 -14
- package/server/assets/chat/clipboard.js +2 -1
- package/server/assets/chat/confirm-dialog.js +3 -3
- package/server/assets/chat/copy-action.js +1 -2
- package/server/assets/chat/diagram-viewer.js +7 -9
- package/server/assets/chat/doc-preview.js +19 -12
- package/server/assets/chat/editor.js +87 -61
- package/server/assets/chat/events.js +49 -34
- package/server/assets/chat/files.js +45 -13
- package/server/assets/chat/history-loader.js +5 -3
- package/server/assets/chat/image-zoom.js +21 -17
- package/server/assets/chat/install-prompt.js +10 -9
- package/server/assets/chat/integration-account-schema.js +5 -3
- package/server/assets/chat/integration-editor.js +2 -2
- package/server/assets/chat/integration-values.js +17 -11
- package/server/assets/chat/integrations.js +138 -81
- package/server/assets/chat/join-requests.js +20 -13
- package/server/assets/chat/markdown-footnotes.js +8 -8
- package/server/assets/chat/markdown.js +48 -38
- package/server/assets/chat/members.js +48 -25
- package/server/assets/chat/mentions.js +39 -12
- package/server/assets/chat/message-cache.js +2 -2
- package/server/assets/chat/message-polling.js +40 -21
- package/server/assets/chat/message-window.js +10 -6
- package/server/assets/chat/messages.js +70 -46
- package/server/assets/chat/office-preview.js +3 -3
- package/server/assets/chat/palette.js +45 -29
- package/server/assets/chat/panels.js +19 -1
- package/server/assets/chat/pwa.js +5 -4
- package/server/assets/chat/questions.js +25 -22
- package/server/assets/chat/recall.js +39 -21
- package/server/assets/chat/receipts.js +9 -7
- package/server/assets/chat/reminders.js +25 -8
- package/server/assets/chat/replies.js +34 -15
- package/server/assets/chat/resource-format.js +2 -2
- package/server/assets/chat/room-list.js +2 -2
- package/server/assets/chat/room-watcher.js +8 -4
- package/server/assets/chat/rooms.js +51 -40
- package/server/assets/chat/search.js +8 -6
- package/server/assets/chat/settings.js +16 -14
- package/server/assets/chat/shiki.js +1 -1
- package/server/assets/chat/shortcuts.js +3 -3
- package/server/assets/chat/side-pane.js +4 -3
- package/server/assets/chat/state.js +65 -37
- package/server/assets/chat/system-events.js +6 -5
- package/server/assets/chat/system-messages.js +15 -15
- package/server/assets/chat/task-form.js +5 -5
- package/server/assets/chat/task-row.js +1 -1
- package/server/assets/chat/tasks.js +41 -28
- package/server/assets/chat/window-controls.js +3 -2
- package/server/assets/conversation.css +14 -2
- package/server/assets/doc-preview.css +6 -0
- package/server/assets/office/THIRD-PARTY-NOTICES.txt +23 -1
- package/server/assets/office/licenses/docx-preview-HEADER.txt +6 -0
- package/server/assets/office/licenses/echarts-LICENSE-d3.txt +27 -0
- package/server/assets/office/licenses/echarts-NOTICE.txt +5 -0
- package/server/assets/office/licenses/immediate-LICENSE.txt +20 -0
- package/server/assets/office/licenses/lie-LICENSE.txt +7 -0
- package/server/assets/office/licenses/pako-LICENSE.txt +21 -0
- package/server/assets/office/licenses/pako-ZLIB.txt +18 -0
- package/server/assets/office/licenses/setimmediate-LICENSE.txt +20 -0
- package/server/chat.html +1 -0
- package/server/sw.js +3 -1
- package/skills/chatroom/SKILL.md +9 -0
- package/src/README.md +1 -1
- package/src/agent/agent-receipts.ts +12 -4
- package/src/center/center-client.ts +1 -1
- package/src/state/pg-sql.mjs +157 -142
- package/src/state/pg-sql.mts +175 -0
- package/src/state/pg-worker.mjs +107 -99
- package/src/state/pg-worker.mts +166 -0
- package/src/state/store.ts +21 -7
- package/src/tui/app-types.mjs +1 -0
- package/src/tui/app-types.mts +175 -0
- package/src/tui/app.mjs +426 -423
- package/src/tui/app.mts +500 -0
- package/src/tui/config.mjs +166 -158
- package/src/tui/config.mts +247 -0
- package/src/tui/http.mjs +239 -206
- package/src/tui/http.mts +412 -0
- package/src/tui/i18n.mjs +17 -20
- package/src/tui/i18n.mts +42 -0
- package/src/tui/info-app.mjs +431 -427
- package/src/tui/info-app.mts +500 -0
- package/src/tui/info-content.mjs +205 -199
- package/src/tui/info-content.mts +341 -0
- package/src/tui/join-app.mjs +75 -64
- package/src/tui/join-app.mts +99 -0
- package/src/tui/locales/en.mjs +302 -320
- package/src/tui/locales/en.mts +349 -0
- package/src/tui/locales/zh-CN.mjs +302 -320
- package/src/tui/locales/zh-CN.mts +349 -0
- package/src/tui/main.mjs +219 -213
- package/src/tui/main.mts +255 -0
- package/src/tui/markdown.mjs +128 -272
- package/src/tui/markdown.mts +152 -0
- package/src/tui/mentions.mjs +181 -184
- package/src/tui/mentions.mts +251 -0
- package/src/tui/message-app.mjs +181 -173
- package/src/tui/message-app.mts +213 -0
- package/src/tui/message-view.mjs +90 -111
- package/src/tui/message-view.mts +151 -0
- package/src/tui/messages.mjs +55 -49
- package/src/tui/messages.mts +106 -0
- package/src/tui/palette-app.mjs +364 -344
- package/src/tui/palette-app.mts +388 -0
- package/src/tui/palette.mjs +100 -98
- package/src/tui/palette.mts +176 -0
- package/src/tui/prefs.mjs +56 -63
- package/src/tui/prefs.mts +126 -0
- package/src/tui/reminder-app.mjs +191 -181
- package/src/tui/reminder-app.mts +228 -0
- package/src/tui/room-settings-app.mjs +257 -242
- package/src/tui/room-settings-app.mts +301 -0
- package/src/tui/session.mjs +30 -29
- package/src/tui/session.mts +51 -0
- package/src/tui/settings-app.mjs +151 -138
- package/src/tui/settings-app.mts +179 -0
- package/src/tui/ui-content.mjs +426 -421
- package/src/tui/ui-content.mts +499 -0
- package/src/tui/ui-help.mjs +58 -67
- package/src/tui/ui-help.mts +87 -0
- package/src/tui/ui-mentions.mjs +34 -36
- package/src/tui/ui-mentions.mts +60 -0
- package/src/tui/ui-overlay-view.mjs +259 -267
- package/src/tui/ui-overlay-view.mts +322 -0
- package/src/tui/ui-suggest-view.mjs +54 -57
- package/src/tui/ui-suggest-view.mts +78 -0
- package/src/tui/ui-suggest.mjs +164 -167
- package/src/tui/ui-suggest.mts +248 -0
- package/src/tui/ui-theme.mjs +52 -57
- package/src/tui/ui-theme.mts +98 -0
- package/src/tui/ui-view.mjs +267 -275
- package/src/tui/ui-view.mts +308 -0
- package/src/tui/ui.mjs +372 -359
- package/src/tui/ui.mts +440 -0
- package/src/tui/wire.mjs +215 -0
- package/src/tui/wire.mts +383 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
// Browser settings shared by the join page and the chat: language, theme, window frame, and the optional token.
|
|
2
1
|
export const THEMES = ["system", "light", "dark", "forest", "sand", "custom"];
|
|
3
2
|
const DEFAULT_CUSTOM_THEME = "#22695c";
|
|
4
3
|
const validColor = (value) => /^#[0-9a-f]{6}$/i.test(value) ? value : DEFAULT_CUSTOM_THEME;
|
|
5
4
|
// Relative luminance, so a dark choice gets the dark palette instead of dark text on it.
|
|
6
5
|
const isDarkColor = (color) => {
|
|
7
|
-
const channels = color.slice(1).match(/../g).map((part) => {
|
|
6
|
+
const channels = (color.slice(1).match(/../g) || []).map((part) => {
|
|
8
7
|
const value = parseInt(part, 16) / 255;
|
|
9
8
|
return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
10
9
|
});
|
|
11
|
-
|
|
10
|
+
const [r = 0, g = 0, b = 0] = channels;
|
|
11
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b < 0.4;
|
|
12
12
|
};
|
|
13
13
|
export function initSettings(app) {
|
|
14
14
|
const $ = app.$;
|
|
@@ -16,6 +16,8 @@ export function initSettings(app) {
|
|
|
16
16
|
if (!dialog)
|
|
17
17
|
return;
|
|
18
18
|
const tokenInput = $("#inTokenChat"), tokenHint = $("#tokenHint");
|
|
19
|
+
if (!tokenInput)
|
|
20
|
+
return;
|
|
19
21
|
const contentInput = $("#inContentTransition");
|
|
20
22
|
const pageInput = $("#inPageStep"), pageValue = $("#pageStepValue");
|
|
21
23
|
const frameSelect = $("#inWindowFrame");
|
|
@@ -88,7 +90,7 @@ export function initSettings(app) {
|
|
|
88
90
|
};
|
|
89
91
|
const syncPanelInputs = () => {
|
|
90
92
|
for (const select of panelInputs)
|
|
91
|
-
select.value = app.panelMode(select.dataset.panelMode);
|
|
93
|
+
select.value = app.panelMode(select.dataset.panelMode || "");
|
|
92
94
|
};
|
|
93
95
|
const applyTheme = (value, persist) => {
|
|
94
96
|
clearCustomSchedules();
|
|
@@ -119,7 +121,7 @@ export function initSettings(app) {
|
|
|
119
121
|
const selected = tab.dataset.settingsTab === name;
|
|
120
122
|
tab.setAttribute("aria-selected", String(selected));
|
|
121
123
|
tab.tabIndex = selected ? 0 : -1;
|
|
122
|
-
const panel = document.getElementById(tab.getAttribute("aria-controls"));
|
|
124
|
+
const panel = document.getElementById(tab.getAttribute("aria-controls") || "");
|
|
123
125
|
if (panel)
|
|
124
126
|
panel.hidden = !selected;
|
|
125
127
|
if (selected && focus)
|
|
@@ -129,7 +131,7 @@ export function initSettings(app) {
|
|
|
129
131
|
app.loadIntegrations?.();
|
|
130
132
|
};
|
|
131
133
|
const onTabKey = (event) => {
|
|
132
|
-
const index = tabs.indexOf(event.target);
|
|
134
|
+
const index = event.target instanceof HTMLElement ? tabs.indexOf(event.target) : -1;
|
|
133
135
|
if (index < 0)
|
|
134
136
|
return;
|
|
135
137
|
const step = event.key === "ArrowUp" || event.key === "ArrowLeft" ? -1 : event.key === "ArrowDown" || event.key === "ArrowRight" ? 1 : 0;
|
|
@@ -137,7 +139,7 @@ export function initSettings(app) {
|
|
|
137
139
|
if (target < 0)
|
|
138
140
|
return;
|
|
139
141
|
event.preventDefault();
|
|
140
|
-
activateTab(tabs[target]
|
|
142
|
+
activateTab(tabs[target]?.dataset.settingsTab, { focus: true });
|
|
141
143
|
};
|
|
142
144
|
for (const tab of tabs) {
|
|
143
145
|
tab.addEventListener("click", () => activateTab(tab.dataset.settingsTab));
|
|
@@ -181,7 +183,7 @@ export function initSettings(app) {
|
|
|
181
183
|
$("#btnCloseSettings")?.addEventListener("click", close);
|
|
182
184
|
dialog.addEventListener("cancel", () => opener?.setAttribute("aria-expanded", "false"));
|
|
183
185
|
pageInput?.addEventListener("input", () => {
|
|
184
|
-
app.LS.pageStep = pageInput.value;
|
|
186
|
+
app.LS.pageStep = Number(pageInput.value);
|
|
185
187
|
pageInput.value = String(app.LS.pageStep);
|
|
186
188
|
if (pageValue)
|
|
187
189
|
pageValue.textContent = `${app.LS.pageStep}%`;
|
|
@@ -190,7 +192,7 @@ export function initSettings(app) {
|
|
|
190
192
|
const color = validColor(customColorInput.value);
|
|
191
193
|
scheduleCustomPaint(color);
|
|
192
194
|
clearTimeout(customPersistTimer);
|
|
193
|
-
customPersistTimer = setTimeout(() => {
|
|
195
|
+
customPersistTimer = window.setTimeout(() => {
|
|
194
196
|
customPersistTimer = 0;
|
|
195
197
|
commitCustomColor(validColor(customColorInput.value));
|
|
196
198
|
}, CUSTOM_COLOR_PERSIST_DELAY);
|
|
@@ -202,15 +204,15 @@ export function initSettings(app) {
|
|
|
202
204
|
dialog.addEventListener("change", (event) => {
|
|
203
205
|
if (event.target instanceof HTMLInputElement && event.target.name === "theme")
|
|
204
206
|
app.setTheme(event.target.value);
|
|
205
|
-
if (event.target === frameSelect)
|
|
206
|
-
app.setWindowFrame(frameSelect.value);
|
|
207
|
+
if (frameSelect && event.target === frameSelect)
|
|
208
|
+
app.setWindowFrame(frameSelect.value === "borderless" ? "borderless" : "framed");
|
|
207
209
|
if (event.target instanceof HTMLSelectElement && event.target.dataset.panelMode) {
|
|
208
210
|
app.setPanelMode(event.target.dataset.panelMode, event.target.value);
|
|
209
211
|
}
|
|
210
|
-
if (event.target === contentInput)
|
|
212
|
+
if (contentInput && event.target === contentInput)
|
|
211
213
|
app.LS.contentTransition = contentInput.checked;
|
|
212
|
-
if (event.target === pageInput) {
|
|
213
|
-
app.LS.pageStep = pageInput.value;
|
|
214
|
+
if (pageInput && event.target === pageInput) {
|
|
215
|
+
app.LS.pageStep = Number(pageInput.value);
|
|
214
216
|
pageInput.value = String(app.LS.pageStep);
|
|
215
217
|
if (pageValue)
|
|
216
218
|
pageValue.textContent = `${app.LS.pageStep}%`;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// composer keeps one visible entry and no per-control badges.
|
|
1
|
+
import { closeOnBackdrop } from "./panels.js";
|
|
3
2
|
export function initShortcuts(app) {
|
|
4
3
|
const dialog = app.$("#shortcutsDialog");
|
|
5
4
|
if (!dialog)
|
|
@@ -25,6 +24,7 @@ export function initShortcuts(app) {
|
|
|
25
24
|
app.$("#btnShortcuts")?.addEventListener("mousedown", (event) => event.preventDefault());
|
|
26
25
|
app.$("#btnShortcuts")?.addEventListener("click", openSheet);
|
|
27
26
|
app.$("#btnCloseShortcuts")?.addEventListener("click", () => dialog.close());
|
|
27
|
+
closeOnBackdrop(dialog, () => dialog.close());
|
|
28
28
|
dialog.addEventListener("close", () => requestAnimationFrame(() => app.focusComposer?.()));
|
|
29
29
|
let scrollFrame = 0;
|
|
30
30
|
let scrollGeneration = 0;
|
|
@@ -122,7 +122,7 @@ export function initShortcuts(app) {
|
|
|
122
122
|
if (!bottom) {
|
|
123
123
|
app.state.jumpToLoadedTop = true;
|
|
124
124
|
clearTimeout(app.state.jumpToLoadedTopTimer);
|
|
125
|
-
app.state.jumpToLoadedTopTimer = setTimeout(() => { app.state.jumpToLoadedTop = false; }, reduced ? 150 : 800);
|
|
125
|
+
app.state.jumpToLoadedTopTimer = window.setTimeout(() => { app.state.jumpToLoadedTop = false; }, reduced ? 150 : 800);
|
|
126
126
|
}
|
|
127
127
|
animateScroll(bottom ? thread.scrollHeight : 0);
|
|
128
128
|
};
|
|
@@ -35,7 +35,7 @@ export function initSidePaneSplitter(app) {
|
|
|
35
35
|
paneWasOpen = open;
|
|
36
36
|
view.classList.add("pane-animating");
|
|
37
37
|
clearTimeout(animationTimer);
|
|
38
|
-
animationTimer = setTimeout(() => view.classList.remove("pane-animating"), ANIMATION_MS);
|
|
38
|
+
animationTimer = window.setTimeout(() => view.classList.remove("pane-animating"), ANIMATION_MS);
|
|
39
39
|
};
|
|
40
40
|
// A wide task board must leave the conversation a full working column; the
|
|
41
41
|
// Markdown preview keeps the normal minimum.
|
|
@@ -128,9 +128,10 @@ export function initSidePaneSplitter(app) {
|
|
|
128
128
|
handle.addEventListener("pointerup", endDrag);
|
|
129
129
|
handle.addEventListener("pointercancel", endDrag);
|
|
130
130
|
handle.addEventListener("keydown", (event) => {
|
|
131
|
-
|
|
131
|
+
const pane = activePane();
|
|
132
|
+
if (!pane?.open)
|
|
132
133
|
return;
|
|
133
|
-
const current = applied ||
|
|
134
|
+
const current = applied || pane.getBoundingClientRect().width;
|
|
134
135
|
const step = event.shiftKey ? 64 : 16;
|
|
135
136
|
let next;
|
|
136
137
|
if (event.key === "ArrowRight")
|
|
@@ -20,6 +20,12 @@ export const app = {
|
|
|
20
20
|
copyTimer: 0,
|
|
21
21
|
failedRenderIds: new Set(),
|
|
22
22
|
};
|
|
23
|
+
const $ = (selector) => {
|
|
24
|
+
const element = app.$(selector);
|
|
25
|
+
if (!element)
|
|
26
|
+
throw new Error(`Missing element: ${selector}`);
|
|
27
|
+
return element;
|
|
28
|
+
};
|
|
23
29
|
// Phones and tablets lack the hardware keyboard the shortcut hint assumes.
|
|
24
30
|
// iPadOS reports a desktop Macintosh UA, so touch points identify it there.
|
|
25
31
|
export function isMobileDevice() {
|
|
@@ -53,7 +59,7 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
53
59
|
const validSessionID = (id) => typeof id === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(id);
|
|
54
60
|
const parseIdentity = (value) => {
|
|
55
61
|
try {
|
|
56
|
-
const identity = JSON.parse(value);
|
|
62
|
+
const identity = JSON.parse(value ?? "null");
|
|
57
63
|
return validSessionID(identity?.sessionID) && typeof identity.name === "string" && identity.name.length <= 64
|
|
58
64
|
? { sessionID: identity.sessionID, name: identity.name } : undefined;
|
|
59
65
|
}
|
|
@@ -63,7 +69,7 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
63
69
|
};
|
|
64
70
|
const read = (key) => {
|
|
65
71
|
if (Object.hasOwn(memory, key))
|
|
66
|
-
return memory[key];
|
|
72
|
+
return memory[key] ?? null;
|
|
67
73
|
try {
|
|
68
74
|
return (storage ?? globalThis.localStorage).getItem(key);
|
|
69
75
|
}
|
|
@@ -103,9 +109,9 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
103
109
|
}
|
|
104
110
|
catch { /* Tab-scoped state is best effort. */ }
|
|
105
111
|
};
|
|
106
|
-
const syncTabIdentity = () => {
|
|
107
|
-
writeSession("chat.sessionID",
|
|
108
|
-
writeSession("chat.name",
|
|
112
|
+
const syncTabIdentity = (identity) => {
|
|
113
|
+
writeSession("chat.sessionID", identity.sessionID);
|
|
114
|
+
writeSession("chat.name", identity.name || null);
|
|
109
115
|
};
|
|
110
116
|
const ensureIdentity = () => {
|
|
111
117
|
if (browserIdentity)
|
|
@@ -122,7 +128,7 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
122
128
|
clearMediaCache();
|
|
123
129
|
void postMediaIdentity();
|
|
124
130
|
}
|
|
125
|
-
syncTabIdentity();
|
|
131
|
+
syncTabIdentity(canonical);
|
|
126
132
|
return canonical;
|
|
127
133
|
}
|
|
128
134
|
}
|
|
@@ -132,7 +138,7 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
132
138
|
clearMediaCache();
|
|
133
139
|
void postMediaIdentity();
|
|
134
140
|
}
|
|
135
|
-
syncTabIdentity();
|
|
141
|
+
syncTabIdentity(browserIdentity);
|
|
136
142
|
try {
|
|
137
143
|
store ||= storage ?? globalThis.localStorage;
|
|
138
144
|
store.setItem(identityKey, JSON.stringify(browserIdentity));
|
|
@@ -153,12 +159,12 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
153
159
|
return error;
|
|
154
160
|
};
|
|
155
161
|
const assertIdentity = () => {
|
|
156
|
-
ensureIdentity();
|
|
162
|
+
const identity = ensureIdentity();
|
|
157
163
|
if (identityConflict)
|
|
158
164
|
throw identityError();
|
|
159
165
|
try {
|
|
160
166
|
const current = parseIdentity((storage ?? globalThis.localStorage).getItem(identityKey));
|
|
161
|
-
if (current && current.sessionID !==
|
|
167
|
+
if (current && current.sessionID !== identity.sessionID || identityPersistent && !current) {
|
|
162
168
|
identityConflict = true;
|
|
163
169
|
throw identityError();
|
|
164
170
|
}
|
|
@@ -166,23 +172,24 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
166
172
|
identityPersistent = true;
|
|
167
173
|
}
|
|
168
174
|
catch (error) {
|
|
169
|
-
if (error
|
|
175
|
+
if (error instanceof Error && "identityConflict" in error && error.identityConflict)
|
|
170
176
|
throw error;
|
|
171
177
|
identityPersistent = false;
|
|
172
178
|
}
|
|
173
179
|
};
|
|
174
180
|
const saveIdentity = () => {
|
|
175
|
-
if (!identityPersistent)
|
|
181
|
+
if (!identityPersistent || !browserIdentity)
|
|
176
182
|
return;
|
|
183
|
+
const identity = browserIdentity;
|
|
177
184
|
try {
|
|
178
185
|
const store = storage ?? globalThis.localStorage;
|
|
179
186
|
const current = parseIdentity(store.getItem(identityKey));
|
|
180
|
-
if (current?.sessionID !==
|
|
187
|
+
if (current?.sessionID !== identity.sessionID) {
|
|
181
188
|
identityConflict = true;
|
|
182
189
|
return;
|
|
183
190
|
}
|
|
184
|
-
store.setItem(identityKey, JSON.stringify(
|
|
185
|
-
if (parseIdentity(store.getItem(identityKey))?.sessionID !==
|
|
191
|
+
store.setItem(identityKey, JSON.stringify(identity));
|
|
192
|
+
if (parseIdentity(store.getItem(identityKey))?.sessionID !== identity.sessionID)
|
|
186
193
|
identityConflict = true;
|
|
187
194
|
}
|
|
188
195
|
catch { /* Keep the preferred name in memory when persistence is blocked. */ }
|
|
@@ -202,7 +209,7 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
202
209
|
},
|
|
203
210
|
set roomId(value) { writeSession("chat.roomId", value || null); write("chat.roomId", null); },
|
|
204
211
|
get name() { return ensureIdentity().name; },
|
|
205
|
-
set name(value) { ensureIdentity();
|
|
212
|
+
set name(value) { const identity = ensureIdentity(); identity.name = String(value ?? "").slice(0, 64); writeSession("chat.name", identity.name || null); saveIdentity(); },
|
|
206
213
|
get token() { return read("chat.token") || ""; }, set token(value) { write("chat.token", value || null); },
|
|
207
214
|
get locale() { return read("chat.locale") || "en"; }, set locale(value) { write("chat.locale", value || null); },
|
|
208
215
|
get theme() { return read("chat.theme") || "system"; }, set theme(value) { write("chat.theme", value || null); },
|
|
@@ -291,6 +298,11 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
291
298
|
}
|
|
292
299
|
return auth.token;
|
|
293
300
|
};
|
|
301
|
+
const networkError = () => {
|
|
302
|
+
const error = new Error(translate("networkError"));
|
|
303
|
+
error.network = true;
|
|
304
|
+
return error;
|
|
305
|
+
};
|
|
294
306
|
const apiResponse = async (url, options = {}) => {
|
|
295
307
|
assertIdentity();
|
|
296
308
|
const headers = { ...options.headers };
|
|
@@ -303,9 +315,7 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
303
315
|
response = await (fetcher ?? globalThis.fetch)(url, { ...options, headers });
|
|
304
316
|
}
|
|
305
317
|
catch {
|
|
306
|
-
|
|
307
|
-
error.network = true;
|
|
308
|
-
throw error;
|
|
318
|
+
throw networkError();
|
|
309
319
|
}
|
|
310
320
|
assertIdentity();
|
|
311
321
|
if (!response.ok) {
|
|
@@ -317,10 +327,26 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
317
327
|
}
|
|
318
328
|
return response;
|
|
319
329
|
};
|
|
320
|
-
const api = async (url, options) => {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
330
|
+
const api = async (url, { timeoutMs = 20_000, ...options } = {}) => {
|
|
331
|
+
// Bound restore reads through the end of the body, without timing out writes or downloads.
|
|
332
|
+
const controller = !options.signal && (options.method ?? "GET") === "GET" ? new AbortController() : undefined;
|
|
333
|
+
const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : undefined;
|
|
334
|
+
try {
|
|
335
|
+
const response = await apiResponse(url, controller ? { ...options, signal: controller.signal } : options);
|
|
336
|
+
const data = await response.json().catch(() => ({}));
|
|
337
|
+
controller?.signal.throwIfAborted();
|
|
338
|
+
assertIdentity();
|
|
339
|
+
return data;
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
if (controller?.signal.aborted)
|
|
343
|
+
throw networkError();
|
|
344
|
+
throw error;
|
|
345
|
+
}
|
|
346
|
+
finally {
|
|
347
|
+
if (timer !== undefined)
|
|
348
|
+
clearTimeout(timer);
|
|
349
|
+
}
|
|
324
350
|
};
|
|
325
351
|
const apiBlob = async (url, options) => {
|
|
326
352
|
const response = await apiResponse(url, options), blob = await response.blob();
|
|
@@ -740,15 +766,15 @@ export const messages = {
|
|
|
740
766
|
};
|
|
741
767
|
// Every locale falls back to English for keys it has not translated yet.
|
|
742
768
|
for (const dictionary of Object.values(messages)) {
|
|
743
|
-
for (const key of Object.
|
|
769
|
+
for (const [key, entry] of Object.entries(messages.en)) {
|
|
744
770
|
if (dictionary[key] === undefined)
|
|
745
|
-
dictionary[key] =
|
|
771
|
+
dictionary[key] = entry;
|
|
746
772
|
}
|
|
747
773
|
}
|
|
748
774
|
app.t = (key, values = {}) => {
|
|
749
|
-
const entry = messages[app.locale][key] ?? messages.en[key] ?? key;
|
|
775
|
+
const entry = messages[app.locale]?.[key] ?? messages.en[key] ?? key;
|
|
750
776
|
const text = typeof entry === "function" ? entry(values) : entry;
|
|
751
|
-
return String(text).replace(/\{(\w+)\}/g, (_, name) => values[name] ?? "");
|
|
777
|
+
return String(text).replace(/\{(\w+)\}/g, (_, name) => String(values[name] ?? ""));
|
|
752
778
|
};
|
|
753
779
|
export const { LS, saveToken, api, apiBlob } = createAuth(undefined, undefined, (key, values) => app.t(key, values));
|
|
754
780
|
app.LS = LS;
|
|
@@ -820,7 +846,7 @@ app.applyLocale = () => {
|
|
|
820
846
|
document.querySelectorAll("[data-i18n]").forEach((element) => {
|
|
821
847
|
const text = element._flashKey
|
|
822
848
|
? app.t(element._flashKey)
|
|
823
|
-
: app.t(element.dataset.i18n, element._i18nValues || {});
|
|
849
|
+
: app.t(element.dataset.i18n ?? "", element._i18nValues || {});
|
|
824
850
|
// Controls with icons keep the graphic and swap only the text label.
|
|
825
851
|
const label = element.querySelector(":scope > .i18n-label");
|
|
826
852
|
if (label)
|
|
@@ -830,11 +856,13 @@ app.applyLocale = () => {
|
|
|
830
856
|
});
|
|
831
857
|
for (const attribute of ["aria-label", "aria-placeholder", "title", "placeholder"]) {
|
|
832
858
|
document.querySelectorAll(`[data-i18n-${attribute}]`).forEach((element) => {
|
|
833
|
-
element.setAttribute(attribute, app.t(element.getAttribute(`data-i18n-${attribute}`), element._i18nValues || {}));
|
|
859
|
+
element.setAttribute(attribute, app.t(element.getAttribute(`data-i18n-${attribute}`) ?? "", element._i18nValues || {}));
|
|
834
860
|
});
|
|
835
861
|
}
|
|
836
862
|
document.querySelectorAll(".locale-select").forEach((select) => { select.value = app.locale; });
|
|
837
|
-
app
|
|
863
|
+
const msgInput = app.$("#msgInput");
|
|
864
|
+
if (msgInput)
|
|
865
|
+
app.autoGrow?.(msgInput);
|
|
838
866
|
app.updateDraftCount?.();
|
|
839
867
|
app.updateMentionList?.();
|
|
840
868
|
app.renderFailedMessages?.();
|
|
@@ -890,13 +918,13 @@ app.flash = (button, key) => {
|
|
|
890
918
|
if (output) {
|
|
891
919
|
delete output._flashKey;
|
|
892
920
|
output.hidden = true;
|
|
893
|
-
output.textContent = app.t(output.dataset.i18n, output._i18nValues || {});
|
|
921
|
+
output.textContent = app.t(output.dataset.i18n ?? "", output._i18nValues || {});
|
|
894
922
|
button.classList.remove("is-flashing");
|
|
895
923
|
if (button.dataset.i18nAriaLabel)
|
|
896
924
|
button.setAttribute("aria-label", app.t(button.dataset.i18nAriaLabel));
|
|
897
925
|
}
|
|
898
926
|
else
|
|
899
|
-
button.textContent = app.t(button.dataset.i18n, button._i18nValues || {});
|
|
927
|
+
button.textContent = app.t(button.dataset.i18n ?? "", button._i18nValues || {});
|
|
900
928
|
}, 1200);
|
|
901
929
|
};
|
|
902
930
|
app.updateTitle = () => {
|
|
@@ -908,27 +936,27 @@ app.updateTitle = () => {
|
|
|
908
936
|
document.title = total ? `(${total}) ${title}` : title;
|
|
909
937
|
};
|
|
910
938
|
app.setOnline = (online) => {
|
|
911
|
-
|
|
939
|
+
$("#connBar").hidden = online;
|
|
912
940
|
// A recovered connection makes the network send warning stale, but an auth
|
|
913
941
|
// or validation error still needs the user's attention.
|
|
914
942
|
if (online)
|
|
915
943
|
app.hideSendError("sendNetwork");
|
|
916
944
|
};
|
|
917
945
|
app.showSendError = (key, values = {}) => {
|
|
918
|
-
const node =
|
|
946
|
+
const node = $("#sendError");
|
|
919
947
|
app.setText(node, key, values);
|
|
920
948
|
node.dataset.errorKey = key;
|
|
921
949
|
node.hidden = false;
|
|
922
950
|
};
|
|
923
951
|
app.hideSendError = (key) => {
|
|
924
|
-
const node =
|
|
952
|
+
const node = $("#sendError");
|
|
925
953
|
if (key && node.dataset.errorKey !== key)
|
|
926
954
|
return;
|
|
927
955
|
node.hidden = true;
|
|
928
956
|
delete node.dataset.errorKey;
|
|
929
957
|
};
|
|
930
958
|
app.showJoinError = (key, values = {}) => {
|
|
931
|
-
app.setText(
|
|
932
|
-
|
|
959
|
+
app.setText($("#joinError"), key, values);
|
|
960
|
+
$("#joinError").hidden = false;
|
|
933
961
|
};
|
|
934
|
-
app.hideJoinError = () => {
|
|
962
|
+
app.hideJoinError = () => { $("#joinError").hidden = true; };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// Room notices are inline events: a small icon, a tinted chip, and the time.
|
|
2
1
|
import { iconNode } from "./icons.js";
|
|
3
2
|
import { formatRelayMessage, formatSystemMessage, systemMessageKind } from "./system-messages.js";
|
|
4
3
|
import { renderMarkdown, renderResourceText } from "./markdown.js";
|
|
4
|
+
const noticeIcon = "megaphone";
|
|
5
5
|
const icons = {
|
|
6
6
|
join: "add",
|
|
7
7
|
leave: "arrow_exit",
|
|
@@ -9,7 +9,7 @@ const icons = {
|
|
|
9
9
|
admin: "shield_checkmark",
|
|
10
10
|
forward: "arrow_swap",
|
|
11
11
|
reminder: "alert",
|
|
12
|
-
notice:
|
|
12
|
+
notice: noticeIcon,
|
|
13
13
|
};
|
|
14
14
|
// Notices are Markdown and switch from a pill to a card once they pass three
|
|
15
15
|
// rendered lines; relays always keep the message-card shape because they carry
|
|
@@ -35,15 +35,16 @@ function bindNoticeResize() {
|
|
|
35
35
|
}
|
|
36
36
|
export function renderSystemRow(row, message, app) {
|
|
37
37
|
row.className = "sys";
|
|
38
|
-
|
|
38
|
+
const kind = systemMessageKind(message);
|
|
39
|
+
row.dataset.kind = kind;
|
|
39
40
|
const event = document.createElement("span"), mark = document.createElement("span");
|
|
40
41
|
const text = document.createElement("span"), time = document.createElement("time");
|
|
41
42
|
event.className = "sys-event";
|
|
42
43
|
event.setAttribute("role", "note");
|
|
43
44
|
mark.className = "sys-icon";
|
|
44
|
-
mark.append(iconNode(icons[
|
|
45
|
+
mark.append(iconNode(icons[kind] ?? noticeIcon, "sys-icon-glyph"));
|
|
45
46
|
text.className = "sys-text";
|
|
46
|
-
if (
|
|
47
|
+
if (kind === "relay")
|
|
47
48
|
renderResourceText(text, formatRelayMessage(message, app), app);
|
|
48
49
|
else
|
|
49
50
|
renderMarkdown(text, formatSystemMessage(message, app), app);
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// The fourth column drives the event icon and tint in the web client.
|
|
2
2
|
const patterns = [
|
|
3
|
-
[/^(.*?) joined the room$/, "systemJoined", (m) => ({ name: m[1] }), "join"],
|
|
4
|
-
[/^(.*?) left the room$/, "systemLeft", (m) => ({ name: m[1] }), "leave"],
|
|
5
|
-
[/^(.*?) was removed from the room$/, "systemRemoved", (m) => ({ name: m[1] }), "remove"],
|
|
6
|
-
[/^(.*?) designated (.*?) as administrator$/, "systemDesignated", (m) => ({ actor: m[1], name: m[2] }), "admin"],
|
|
7
|
-
[/^(.*?) updated the room administrators$/, "systemAdminsUpdated", (m) => ({ actor: m[1] }), "admin"],
|
|
8
|
-
[/^(.*?) named (.*?) as the room successor$/, "systemSuccessorNamed", (m) => ({ actor: m[1], name: m[2] }), "admin"],
|
|
9
|
-
[/^(.*?) cleared the room successor$/, "systemSuccessorCleared", (m) => ({ actor: m[1] }), "admin"],
|
|
10
|
-
[/^(.*?) revoked the administrator designation$/, "systemRevoked", (m) => ({ actor: m[1] }), "admin"],
|
|
11
|
-
[/^(.*?) renamed the room from "(.*)" to "(.*)"$/, "systemRenamed", (m) => ({ actor: m[1], from: m[2], to: m[3] }), "admin"],
|
|
12
|
-
[/^(.*?) updated the room description$/, "systemDescribed", (m) => ({ actor: m[1] }), "admin"],
|
|
13
|
-
[/^(.*?) set join approval to (open|approval)$/, "systemJoinPolicy", (m) => ({ actor: m[1], policy: m[2] }), "admin"],
|
|
14
|
-
[/^(.*?) handed the room to (.*)$/, "systemHanded", (m) => ({ actor: m[1], name: m[2] }), "admin"],
|
|
15
|
-
[/^Forwarded to (.*)$/, "systemForwarded", (m) => ({ target: m[1] }), "forward"],
|
|
16
|
-
[/^Forward to (.*?) failed: (.*)$/, "systemForwardFailed", (m) => ({ target: m[1], reason: m[2] }), "forward"],
|
|
3
|
+
[/^(.*?) joined the room$/, "systemJoined", (m) => ({ name: m[1] ?? "" }), "join"],
|
|
4
|
+
[/^(.*?) left the room$/, "systemLeft", (m) => ({ name: m[1] ?? "" }), "leave"],
|
|
5
|
+
[/^(.*?) was removed from the room$/, "systemRemoved", (m) => ({ name: m[1] ?? "" }), "remove"],
|
|
6
|
+
[/^(.*?) designated (.*?) as administrator$/, "systemDesignated", (m) => ({ actor: m[1] ?? "", name: m[2] ?? "" }), "admin"],
|
|
7
|
+
[/^(.*?) updated the room administrators$/, "systemAdminsUpdated", (m) => ({ actor: m[1] ?? "" }), "admin"],
|
|
8
|
+
[/^(.*?) named (.*?) as the room successor$/, "systemSuccessorNamed", (m) => ({ actor: m[1] ?? "", name: m[2] ?? "" }), "admin"],
|
|
9
|
+
[/^(.*?) cleared the room successor$/, "systemSuccessorCleared", (m) => ({ actor: m[1] ?? "" }), "admin"],
|
|
10
|
+
[/^(.*?) revoked the administrator designation$/, "systemRevoked", (m) => ({ actor: m[1] ?? "" }), "admin"],
|
|
11
|
+
[/^(.*?) renamed the room from "(.*)" to "(.*)"$/, "systemRenamed", (m) => ({ actor: m[1] ?? "", from: m[2] ?? "", to: m[3] ?? "" }), "admin"],
|
|
12
|
+
[/^(.*?) updated the room description$/, "systemDescribed", (m) => ({ actor: m[1] ?? "" }), "admin"],
|
|
13
|
+
[/^(.*?) set join approval to (open|approval)$/, "systemJoinPolicy", (m) => ({ actor: m[1] ?? "", policy: m[2] ?? "" }), "admin"],
|
|
14
|
+
[/^(.*?) handed the room to (.*)$/, "systemHanded", (m) => ({ actor: m[1] ?? "", name: m[2] ?? "" }), "admin"],
|
|
15
|
+
[/^Forwarded to (.*)$/, "systemForwarded", (m) => ({ target: m[1] ?? "" }), "forward"],
|
|
16
|
+
[/^Forward to (.*?) failed: (.*)$/, "systemForwardFailed", (m) => ({ target: m[1] ?? "", reason: m[2] ?? "" }), "forward"],
|
|
17
17
|
];
|
|
18
18
|
function formatLine(line, app) {
|
|
19
19
|
for (const [pattern, key, values] of patterns) {
|
|
@@ -49,7 +49,7 @@ export function formatSystemMessage(message, app) {
|
|
|
49
49
|
export function systemMessageKind(message) {
|
|
50
50
|
if (String(message?.id ?? "").startsWith("reminder:"))
|
|
51
51
|
return "reminder";
|
|
52
|
-
const line = String(message?.text ?? "").split("; ")[0];
|
|
52
|
+
const line = String(message?.text ?? "").split("; ")[0] ?? "";
|
|
53
53
|
// Inbound relay lines carry provider ids and read like messages, not notices.
|
|
54
54
|
if (/^\[[A-Za-z][\w .-]*\] message_id=\S+/.test(line))
|
|
55
55
|
return "relay";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
// Task form fields shared by the create and edit forms: people pickers and steps.
|
|
2
1
|
import { icon } from "./icons.js";
|
|
3
2
|
export const TITLE_MAX = 200, TEXT_MAX = 5000, STEP_MAX = 300, STEPS_MAX = 30;
|
|
4
3
|
export const roomPeople = (app) => {
|
|
5
4
|
const room = app.state.room;
|
|
5
|
+
const members = (room ? app.state.memberSessions.get(room.id) : undefined) ?? [];
|
|
6
6
|
return [...new Set([
|
|
7
7
|
...(room?.participants || []).map((person) => person.name),
|
|
8
|
-
...
|
|
9
|
-
].filter(Boolean))]
|
|
8
|
+
...members.map((member) => member.name),
|
|
9
|
+
].filter((name) => Boolean(name)))]
|
|
10
10
|
.sort((left, right) => String(left).localeCompare(String(right), app.intlLocale()));
|
|
11
11
|
};
|
|
12
12
|
export const fillAssignees = (app, select, value) => {
|
|
@@ -90,10 +90,10 @@ export function createStepsEditor(app, container, addButton, initial = []) {
|
|
|
90
90
|
return row;
|
|
91
91
|
};
|
|
92
92
|
const read = () => rows
|
|
93
|
-
.map((row) => ({ text: row.querySelector(".task-step-text")
|
|
93
|
+
.map((row) => ({ text: row.querySelector(".task-step-text")?.value.trim() ?? "", done: row.querySelector(".task-step-done")?.checked === true }))
|
|
94
94
|
.filter((step) => step.text);
|
|
95
95
|
const reset = () => { rows.splice(0).forEach((row) => row.remove()); sync(); };
|
|
96
|
-
addButton.addEventListener("click", () => addRow()?.querySelector(".task-step-text")
|
|
96
|
+
addButton.addEventListener("click", () => addRow()?.querySelector(".task-step-text")?.focus());
|
|
97
97
|
initial.forEach((step) => addRow(step));
|
|
98
98
|
return { addRow, read, reset };
|
|
99
99
|
}
|
|
@@ -86,7 +86,7 @@ export const buildTaskRow = (view, task, index) => {
|
|
|
86
86
|
const toggle = document.createElement("input");
|
|
87
87
|
toggle.type = "checkbox";
|
|
88
88
|
toggle.className = "task-step-toggle";
|
|
89
|
-
toggle.checked = step.done;
|
|
89
|
+
toggle.checked = step.done === true;
|
|
90
90
|
toggle.disabled = !view.canStatus(task) || view.isLocked();
|
|
91
91
|
toggle.dataset.stepIndex = String(position);
|
|
92
92
|
toggle.setAttribute("aria-label", `${app.t("tasksStepDoneLabel")}: ${step.text}`);
|