@alexsun-top/opencode-chat-room 0.7.4 → 0.7.6
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 +23 -0
- package/README.md +6 -6
- package/README.zh-CN.md +6 -6
- package/cli.ts +20 -0
- package/dist/cli.js +18 -0
- package/package.json +1 -1
- package/server/assets/FLUENT-ICONS-LICENSE +25 -0
- package/server/assets/NOTICE.txt +2 -1
- package/server/assets/attachments.css +1 -1
- package/server/assets/base.css +29 -7
- package/server/assets/chat/doc-preview.js +113 -0
- package/server/assets/chat/events.js +6 -0
- package/server/assets/chat/files.js +25 -16
- package/server/assets/chat/history-loader.js +36 -26
- package/server/assets/chat/icons.js +15 -0
- package/server/assets/chat/index.js +3 -1
- package/server/assets/chat/locales/de.js +6 -5
- package/server/assets/chat/locales/es.js +6 -5
- package/server/assets/chat/locales/fr.js +6 -5
- package/server/assets/chat/locales/it.js +6 -5
- package/server/assets/chat/locales/ja.js +6 -5
- package/server/assets/chat/locales/ko.js +6 -5
- package/server/assets/chat/markdown.js +17 -37
- package/server/assets/chat/messages.js +4 -9
- package/server/assets/chat/palette.js +50 -34
- package/server/assets/chat/pwa.js +67 -9
- package/server/assets/chat/recall.js +3 -2
- package/server/assets/chat/replies.js +2 -1
- package/server/assets/chat/rooms.js +12 -4
- package/server/assets/chat/shortcuts.js +1 -1
- package/server/assets/chat/state.js +12 -10
- package/server/assets/chat/system-messages.js +7 -1
- package/server/assets/code-highlight.css +0 -5
- package/server/assets/conversation.css +5 -4
- package/server/assets/doc-preview.css +158 -0
- package/server/assets/edit-room.css +8 -0
- package/server/assets/files.css +0 -15
- package/server/assets/fluent-icons.svg +42 -0
- package/server/assets/icons.css +9 -0
- package/server/assets/palette.css +1 -15
- package/server/assets/recall.css +2 -2
- package/server/assets/responsive.css +4 -4
- package/server/assets/room-create.css +1 -1
- package/server/assets/settings.css +13 -6
- package/server/chat.html +93 -57
- package/server/sw.js +10 -1
- package/src/tui/app.mjs +16 -1
- package/src/tui/http.mjs +109 -10
- package/src/tui/info-app.mjs +435 -0
- package/src/tui/info-content.mjs +198 -0
- package/src/tui/join-app.mjs +71 -0
- package/src/tui/main.mjs +23 -4
- package/src/tui/markdown.mjs +269 -0
- package/src/tui/message-app.mjs +177 -0
- package/src/tui/message-view.mjs +128 -0
- package/src/tui/palette-app.mjs +85 -9
- package/src/tui/palette.mjs +17 -2
- package/src/tui/reminder-app.mjs +189 -0
- package/src/tui/room-settings-app.mjs +249 -0
- package/src/tui/ui-content.mjs +136 -93
- package/src/tui/ui-overlay-view.mjs +255 -0
- package/src/tui/ui-view.mjs +2 -190
- package/src/tui/ui.mjs +103 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.6 — 2026-11-22
|
|
4
|
+
|
|
5
|
+
- Restore a usable caret when the search palette closes: the composer keeps keyboard focus and typing works immediately after Escape.
|
|
6
|
+
- Keep internal resource IDs out of user-facing text: the room rail previews attachment-only messages as Attachments, and terminal message bodies replace `[[resource:…]]` markers with Attachments instead of showing UUIDs.
|
|
7
|
+
- Use `/` as the command prefix in the web search palette, so `/` alone lists every command and `/leave` filters to Leave room; plain text still searches messages. Placeholders and translations follow.
|
|
8
|
+
- Start the terminal client automatically with Bun when `bunx` launches the package under Node but a supported Bun is installed, so the plain `bunx @alexsun-top/opencode-chat-room cli` form works.
|
|
9
|
+
- Render terminal message bodies as Markdown with theme-aware syntax highlighting, and show `<at>@name</at>` as a highlighted mention instead of literal tags. Keep recall, question, search-highlight, and sticky-scroll behavior.
|
|
10
|
+
- Add `/` command mode to the terminal client with Quit, members, announcements, questions and ask, files (download/upload/delete), join approvals, reminders, a redacted settings summary, room settings, and recall/reveal/reply by message ID, alongside the existing room, message, and search commands.
|
|
11
|
+
- Fix the terminal client's false disconnects: a 20-second inbox long poll now uses a matching request timeout instead of being cut off by the generic 10-second timeout.
|
|
12
|
+
- Preview Markdown resources in a rendered document view: a fixed right reading pane on wide, tall windows and a modal overlay on narrow or short ones, with Download retained and focus restored on close.
|
|
13
|
+
- Give every Settings row and Edit room field a matching Fluent icon, without adding another icon style or external requests.
|
|
14
|
+
- Manage room reminders from the terminal client: list, create one-time or cron reminders, edit text, pause/resume, and delete.
|
|
15
|
+
- Reject terminal file uploads over 100 MiB before reading them, so a large file cannot exhaust memory.
|
|
16
|
+
|
|
17
|
+
## 0.7.5 — 2026-11-21
|
|
18
|
+
|
|
19
|
+
- Ask before applying a web app update: when a new service worker is ready, a bottom-left prompt offers **Update now** or **Later**. Nothing reloads until **Update now** is chosen; **Later** keeps the current page intact and lets the update apply on the next open.
|
|
20
|
+
- Debounce web search by 220 ms and keep the previous results visible while a new query runs, so typing no longer flashes an empty palette.
|
|
21
|
+
- Show the Enter hint only on the selected palette row, and let Alt+1–9 move the selection directly.
|
|
22
|
+
- Switch rooms from the local message cache: render the newest 300 rows first and prepend older cached rows on scroll, instead of issuing room-list or history requests when entering a room.
|
|
23
|
+
- Use one local MIT-licensed Fluent System Icons sprite for every web icon, including room menus, dialogs, the palette, message actions, and code tools. No icon requests leave the page.
|
|
24
|
+
- Move the selected room in the rail with a short Fluent decelerate glide and fade instead of a springy row motion.
|
|
25
|
+
|
|
3
26
|
## 0.7.4 — 2026-11-21
|
|
4
27
|
|
|
5
28
|
- Run the central server on Node.js 24.2+, Deno 2, or Bun. The server uses Node's HTTP and SQLite modules, the container runtime is Node instead of Bun, and the npm CLI ships as bundled JavaScript so `npx` works under Node.
|
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ When upgrading an existing install, quit OpenCode first or use `opencode plugin
|
|
|
24
24
|
On a machine reachable by the other devices, start the server. Replace `your-password` with a shared password:
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
|
-
npx --yes --package=@alexsun-top/opencode-chat-room@0.7.
|
|
27
|
+
npx --yes --package=@alexsun-top/opencode-chat-room@0.7.6 -- opencode-chat-room --host 0.0.0.0 --port 4399 --token 'your-password'
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
The server runs on Node.js 24.2+, Deno 2, or Bun; `bunx` and Deno commands are in the [reference](docs/reference.en.md#central-mode-multi-host). OpenCode itself still runs on Bun.
|
|
@@ -53,7 +53,7 @@ docker run --rm -p 4399:4399 -v chat-room-data:/data \
|
|
|
53
53
|
ghcr.io/agentsyaml/opencode-chat-room:latest
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
Pin a release with `ghcr.io/agentsyaml/opencode-chat-room:v0.7.
|
|
56
|
+
Pin a release with `ghcr.io/agentsyaml/opencode-chat-room:v0.7.6`. Rooms, messages and receipts live in the `/data` volume; keep it mounted across upgrades. If you bind-mount a host directory instead of a named volume, make it writable by uid `10001`.
|
|
57
57
|
|
|
58
58
|
## 3. Start chatting
|
|
59
59
|
|
|
@@ -64,16 +64,16 @@ Pin a release with `ghcr.io/agentsyaml/opencode-chat-room:v0.7.4`. Rooms, messag
|
|
|
64
64
|
- Use the room's reminder button for one-time or recurring reminders. Times default to the server's time zone.
|
|
65
65
|
- Reminder text supports `{{time}}`, `{{initiator}}`, and `{{room}}`.
|
|
66
66
|
- A compact shortcut chip under the composer shows Alt+/ (Option+/ on Mac); click it or press the keys to open the sheet. Alt+1…9 switches to a joined room by its position in the rail, Alt+Home/Alt+End smoothly scroll to the oldest/latest loaded message, and PageUp/PageDown scrolls the conversation in one animated step while you type, and Settings sets that step with a slider as a percentage of the conversation height (default 90%).
|
|
67
|
-
- Press Alt+Space (Option+Space on Mac) anywhere, including the composer, to search messages. Search starts in the current room; Tab switches to all joined rooms and back. Type
|
|
68
|
-
- Attach files, drag them in, or paste images. The default limit is 500 MiB per file. Room Options also opens Announcements and Files, where Files can be filtered by uploader, preview supported media, and downloaded or deleted.
|
|
69
|
-
- In a terminal, run `bunx --
|
|
67
|
+
- Press Alt+Space (Option+Space on Mac) anywhere, including the composer, to search messages. Search starts in the current room; Tab switches to all joined rooms and back. Type `/` to filter common commands instead. ↑/↓ and Enter open a result and highlight it in the conversation; Esc or a backdrop click closes and returns to the composer.
|
|
68
|
+
- Attach files, drag them in, or paste images. The default limit is 500 MiB per file. Room Options also opens Announcements and Files, where Files can be filtered by uploader, preview supported media and Markdown documents, and downloaded or deleted.
|
|
69
|
+
- In a terminal, run `bunx --package @alexsun-top/opencode-chat-room@0.7.6 opencode-chat-room cli` against the same server. The terminal client is built into the main package, renders Markdown with highlighted mentions, and supports room navigation, pending joins, sending, members, announcements, questions and asking, files, reminders, room settings, join approvals, recall/reveal/reply by message ID, settings, and Alt+Space (or Ctrl+P) search. Typing `/` in an empty composer opens commands, including quit. It uses OpenTUI: Bun 1.3.14+ is recommended, Node.js 26.4+ needs `--experimental-ffi`, and Deno is not supported for this client. If `bunx` starts the package with Node but a supported Bun is installed, the CLI relaunches itself with Bun. Only `cli` loads OpenTUI; the server and `watch` stay on Node.js 24.2+, Deno 2, and Bun.
|
|
70
70
|
- Fenced code blocks are syntax-highlighted locally. Hover or focus a block for icon-only wrap and copy controls.
|
|
71
71
|
- Agents can recall a message by ID; the original stays available to current members.
|
|
72
72
|
- Agents can use the `room` tool's `read_resource` action to save an attachment to a temporary file before opening it.
|
|
73
73
|
|
|
74
74
|
### Install as an app
|
|
75
75
|
|
|
76
|
-
The web interface ships a web app manifest and a service worker, so a phone can add it to the home screen and open it without browser chrome. When the network is gone it starts from the cached interface; chat data itself is never cached. Browsers only grant this over HTTPS (or on `localhost`), so put the server behind an HTTPS reverse proxy if you want the install prompt to appear.
|
|
76
|
+
The web interface ships a web app manifest and a service worker, so a phone can add it to the home screen and open it without browser chrome. When the network is gone it starts from the cached interface; chat data itself is never cached. When a new version is ready, a bottom-left prompt lets you update now or later; choosing later keeps the current page and applies it on the next open. Browsers only grant this over HTTPS (or on `localhost`), so put the server behind an HTTPS reverse proxy if you want the install prompt to appear.
|
|
77
77
|
|
|
78
78
|
For OpenCode sessions on one machine, no server or environment variables are needed. The web interface and multi-machine chat require the central server.
|
|
79
79
|
|
package/README.zh-CN.md
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
在一台可被其他设备访问的机器上启动服务器,把 `换成自己的密码` 换成共享密码:
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
|
-
npx --yes --package=@alexsun-top/opencode-chat-room@0.7.
|
|
27
|
+
npx --yes --package=@alexsun-top/opencode-chat-room@0.7.6 -- opencode-chat-room --host 0.0.0.0 --port 4399 --token '换成自己的密码'
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
服务端可在 Node.js 24.2+、Deno 2 或 Bun 上运行;`bunx` 与 Deno 命令见[参考文档](docs/reference.zh-CN.md)。OpenCode 本身仍运行在 Bun 上。
|
|
@@ -53,7 +53,7 @@ docker run --rm -p 4399:4399 -v chat-room-data:/data \
|
|
|
53
53
|
ghcr.io/agentsyaml/opencode-chat-room:latest
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
用 `ghcr.io/agentsyaml/opencode-chat-room:v0.7.
|
|
56
|
+
用 `ghcr.io/agentsyaml/opencode-chat-room:v0.7.6` 可以固定到具体版本。房间、消息和回执都保存在 `/data` 卷里,升级时保留该卷即可。如果改用宿主目录做挂载,需要让该目录对 uid `10001` 可写。
|
|
57
57
|
|
|
58
58
|
## 3. 开始聊天
|
|
59
59
|
|
|
@@ -64,16 +64,16 @@ docker run --rm -p 4399:4399 -v chat-room-data:/data \
|
|
|
64
64
|
- 点击房间里的提醒按钮,可创建一次性或周期提醒。默认使用服务器时区。
|
|
65
65
|
- 提醒正文支持 `{{time}}`、`{{initiator}}`、`{{room}}` 模板变量。
|
|
66
66
|
- 输入框下方保留唯一快捷键入口,以紧凑标签显示 Alt+/(Mac 为 Option+/);点击或按快捷键都能打开面板。Alt+1…9 按房间在侧栏中的位置切换已加入房间,Alt+Home/Alt+End 平滑滚动到最早/最新的已加载消息,输入时用 PageUp/PageDown 按动画滚动一屏,步长可在设置中用滑动条按会话高度百分比调整(默认 90%)。
|
|
67
|
-
- 在任意位置(包括输入框)按 Alt+Space(Mac 为 Option+Space)打开搜索:默认搜索当前房间,按 Tab 切换到全部已加入房间;输入
|
|
68
|
-
- 点击附件按钮、拖入文件或粘贴图片即可分享;默认单文件上限为 500 MiB
|
|
69
|
-
- 终端里可以运行 `bunx --
|
|
67
|
+
- 在任意位置(包括输入框)按 Alt+Space(Mac 为 Option+Space)打开搜索:默认搜索当前房间,按 Tab 切换到全部已加入房间;输入 `/` 可改为过滤常用命令。↑/↓ 加 Enter 打开结果并在会话中高亮;Esc 或点击遮罩关闭并回到输入框。
|
|
68
|
+
- 点击附件按钮、拖入文件或粘贴图片即可分享;默认单文件上限为 500 MiB。房间选项里还有“公告”和“文件”;文件可以按上传者筛选、预览支持的媒体和 Markdown 文档,并下载或删除。
|
|
69
|
+
- 终端里可以运行 `bunx --package @alexsun-top/opencode-chat-room@0.7.6 opencode-chat-room cli` 连接同一个服务器。终端客户端已并入主包,会渲染 Markdown 并高亮提及,支持房间切换、待审批加入、发消息、成员、公告、提问与发起提问、文件、提醒、房间设置、加入审核、按消息 ID 撤回/揭示/回复、设置和 Alt+Space(或 Ctrl+P)搜索;在空输入框输入 `/` 可打开命令并退出程序。它使用 OpenTUI:推荐 Bun 1.3.14+,Node.js 26.4+ 需要 `--experimental-ffi`,Deno 不支持该客户端。如果 `bunx` 使用 Node 启动但本机安装了受支持的 Bun,CLI 会自动改用 Bun 重新启动。只有 `cli` 会加载 OpenTUI;服务端和 `watch` 仍支持 Node.js 24.2+、Deno 2 和 Bun。
|
|
70
70
|
- 围栏代码块会在本地做语法高亮;鼠标悬停或键盘聚焦时显示纯图标的自动换行和复制按钮。
|
|
71
71
|
- Agent 可按消息 ID 撤回;当前成员仍可查看原文。
|
|
72
72
|
- Agent 收到附件后可通过 `room` 的 `read_resource` 操作保存到临时文件,再打开查看。
|
|
73
73
|
|
|
74
74
|
### 安装为应用
|
|
75
75
|
|
|
76
|
-
网页端带 Web App Manifest 与 Service Worker
|
|
76
|
+
网页端带 Web App Manifest 与 Service Worker:手机可以「添加到主屏幕」,以独立窗口打开,断网时从本地缓存的界面启动。聊天数据本身不进缓存,所以不会看到过期消息。新版本准备好后,左下角会提示立即升级或稍后;选择稍后不会打断当前页面,下次打开时应用更新。浏览器只在 HTTPS(或 `localhost`)下允许这项能力,想让安装入口出现,需要给服务端套一层 HTTPS 反向代理。
|
|
77
77
|
|
|
78
78
|
只在同一台机器的 OpenCode 会话之间聊天时,无需启动服务器或设置环境变量。网页聊天和跨机器聊天需要中心服务器。
|
|
79
79
|
|
package/cli.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
2
3
|
import { existsSync } from "node:fs";
|
|
3
4
|
import { readFile } from "node:fs/promises";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
@@ -41,7 +42,26 @@ function validatePort(value: string): void {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
const args = process.argv.slice(2);
|
|
45
|
+
|
|
46
|
+
// `bunx package` runs the bin with Node by default, even when Bun is installed.
|
|
47
|
+
// The terminal client needs Bun here, so hand off to a supported Bun when one is
|
|
48
|
+
// available instead of making every user remember the --bun flag.
|
|
49
|
+
function relaunchTuiWithBun(): void {
|
|
50
|
+
if (process.versions.bun) return;
|
|
51
|
+
const probe = spawnSync("bun", ["--version"], { encoding: "utf8" });
|
|
52
|
+
if (probe.error || probe.status !== 0) return;
|
|
53
|
+
const [major = 0, minor = 0, patch = 0] = String(probe.stdout).trim().split(".").map(Number);
|
|
54
|
+
const supported = major > 1 || (major === 1 && (minor > 3 || (minor === 3 && patch >= 14)));
|
|
55
|
+
if (!supported) return;
|
|
56
|
+
const child = spawnSync("bun", [fileURLToPath(import.meta.url), ...process.argv.slice(2)], {
|
|
57
|
+
stdio: "inherit",
|
|
58
|
+
env: process.env,
|
|
59
|
+
});
|
|
60
|
+
process.exit(child.status ?? 1);
|
|
61
|
+
}
|
|
62
|
+
|
|
44
63
|
if (args[0] === "cli") {
|
|
64
|
+
relaunchTuiWithBun();
|
|
45
65
|
// Keep the plain-JS TUI outside dist so bundling cannot hoist OpenTUI into
|
|
46
66
|
// every CLI command. The packaged layout has dist/cli.js beside src/tui.
|
|
47
67
|
const packaged = new URL("../src/tui/main.mjs", import.meta.url);
|
package/dist/cli.js
CHANGED
|
@@ -7678,6 +7678,7 @@ var init_chat_server = __esm(async () => {
|
|
|
7678
7678
|
});
|
|
7679
7679
|
|
|
7680
7680
|
// cli.ts
|
|
7681
|
+
import { spawnSync } from "node:child_process";
|
|
7681
7682
|
import { existsSync as existsSync3 } from "node:fs";
|
|
7682
7683
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
7683
7684
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
@@ -7715,7 +7716,24 @@ function validatePort(value) {
|
|
|
7715
7716
|
}
|
|
7716
7717
|
}
|
|
7717
7718
|
var args = process.argv.slice(2);
|
|
7719
|
+
function relaunchTuiWithBun() {
|
|
7720
|
+
if (process.versions.bun)
|
|
7721
|
+
return;
|
|
7722
|
+
const probe = spawnSync("bun", ["--version"], { encoding: "utf8" });
|
|
7723
|
+
if (probe.error || probe.status !== 0)
|
|
7724
|
+
return;
|
|
7725
|
+
const [major = 0, minor = 0, patch = 0] = String(probe.stdout).trim().split(".").map(Number);
|
|
7726
|
+
const supported = major > 1 || major === 1 && (minor > 3 || minor === 3 && patch >= 14);
|
|
7727
|
+
if (!supported)
|
|
7728
|
+
return;
|
|
7729
|
+
const child = spawnSync("bun", [fileURLToPath5(import.meta.url), ...process.argv.slice(2)], {
|
|
7730
|
+
stdio: "inherit",
|
|
7731
|
+
env: process.env
|
|
7732
|
+
});
|
|
7733
|
+
process.exit(child.status ?? 1);
|
|
7734
|
+
}
|
|
7718
7735
|
if (args[0] === "cli") {
|
|
7736
|
+
relaunchTuiWithBun();
|
|
7719
7737
|
const packaged = new URL("../src/tui/main.mjs", import.meta.url);
|
|
7720
7738
|
const source = new URL("./src/tui/main.mjs", import.meta.url);
|
|
7721
7739
|
const entry = existsSync3(fileURLToPath5(packaged)) ? packaged : source;
|
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Fluent System Icons
|
|
2
|
+
@fluentui/svg-icons 1.1.347, 24px regular variants
|
|
3
|
+
https://github.com/microsoft/fluentui-system-icons
|
|
4
|
+
|
|
5
|
+
MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2020 Microsoft Corporation
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
package/server/assets/NOTICE.txt
CHANGED
|
@@ -4,5 +4,6 @@ marked 18.0.4 — MIT License, see MARKED-LICENSE.
|
|
|
4
4
|
DOMPurify 3.4.7 — MPL 2.0 or Apache License 2.0, see DOMPURIFY-LICENSE.
|
|
5
5
|
Mermaid 11.12.2 — MIT License, see MERMAID-LICENSE.
|
|
6
6
|
highlight.js 10.7.3 — BSD 3-Clause License, see HIGHLIGHT-LICENSE.
|
|
7
|
+
Fluent System Icons (@fluentui/svg-icons 1.1.347) — MIT License, see FLUENT-ICONS-LICENSE.
|
|
7
8
|
|
|
8
|
-
Sources: https://www.npmjs.com/package/marked, https://www.npmjs.com/package/dompurify, https://www.npmjs.com/package/mermaid
|
|
9
|
+
Sources: https://www.npmjs.com/package/marked, https://www.npmjs.com/package/dompurify, https://www.npmjs.com/package/mermaid, https://www.npmjs.com/package/highlight.js and https://github.com/microsoft/fluentui-system-icons
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* Composer attachment tray: kept apart from the conversation layout. */
|
|
2
2
|
.attachment-button { flex: none; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 12px; color: var(--ink-2); background: var(--surface); font: inherit; font-size: 24px; cursor: pointer; }
|
|
3
|
-
.attachment-button svg { width: 20px; height: 20px;
|
|
3
|
+
.attachment-button svg { width: 20px; height: 20px; }
|
|
4
4
|
.attachment-button:hover { color: var(--accent); border-color: var(--accent); }
|
|
5
5
|
.attachment-button:disabled { opacity: .5; cursor: default; }
|
|
6
6
|
.attachment-tray { width: min(940px, 100%); margin: 0 auto; }
|
package/server/assets/base.css
CHANGED
|
@@ -90,6 +90,27 @@
|
|
|
90
90
|
.install-prompt { grid-template-columns: minmax(0, 1fr); }
|
|
91
91
|
.install-prompt-actions { justify-content: flex-start; }
|
|
92
92
|
}
|
|
93
|
+
.pwa-update {
|
|
94
|
+
position: fixed;
|
|
95
|
+
z-index: 60;
|
|
96
|
+
left: 18px;
|
|
97
|
+
bottom: max(18px, env(safe-area-inset-bottom));
|
|
98
|
+
display: grid;
|
|
99
|
+
gap: 10px;
|
|
100
|
+
width: min(392px, calc(100vw - 36px));
|
|
101
|
+
padding: 14px 16px;
|
|
102
|
+
border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
|
|
103
|
+
border-radius: 16px;
|
|
104
|
+
background: var(--surface);
|
|
105
|
+
box-shadow: 0 8px 30px rgb(34 53 47 / .16);
|
|
106
|
+
}
|
|
107
|
+
.pwa-update-copy strong { display: block; font-size: 13.5px; font-weight: 650; }
|
|
108
|
+
.pwa-update-copy p { margin: 3px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--ink-2); }
|
|
109
|
+
.pwa-update-actions { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
110
|
+
.pwa-update-actions .btn { min-height: 36px; padding: 7px 12px; font-size: 12.5px; }
|
|
111
|
+
@media (max-width: 560px) {
|
|
112
|
+
.pwa-update { right: 10px; bottom: max(10px, env(safe-area-inset-bottom)); left: 10px; width: auto; }
|
|
113
|
+
}
|
|
93
114
|
.entry-card {
|
|
94
115
|
display: grid;
|
|
95
116
|
gap: 10px;
|
|
@@ -112,10 +133,10 @@
|
|
|
112
133
|
appearance: none;
|
|
113
134
|
padding-left: var(--select-pad);
|
|
114
135
|
padding-right: calc(var(--select-pad) + 22px);
|
|
115
|
-
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='
|
|
136
|
+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24'%3E%3Cpath fill='%2363716b' d='M4.22 8.47c.3-.3.77-.3 1.06 0L12 15.19l6.72-6.72a.75.75 0 1 1 1.06 1.06l-7.25 7.25c-.3.3-.77.3-1.06 0L4.22 9.53a.75.75 0 0 1 0-1.06'/%3E%3C/svg%3E");
|
|
116
137
|
background-position: right var(--select-pad) center;
|
|
117
138
|
background-repeat: no-repeat;
|
|
118
|
-
background-size:
|
|
139
|
+
background-size: 16px 16px;
|
|
119
140
|
}
|
|
120
141
|
@media (forced-colors: active) {
|
|
121
142
|
select { appearance: auto; padding-right: var(--select-pad); background-image: none; }
|
|
@@ -146,7 +167,7 @@
|
|
|
146
167
|
color: var(--ink-2);
|
|
147
168
|
}
|
|
148
169
|
.locale-label { display: flex; align-items: center; gap: 6px; }
|
|
149
|
-
.locale-icon { width: 16px; height: 16px; flex: none;
|
|
170
|
+
.locale-icon { width: 16px; height: 16px; flex: none; }
|
|
150
171
|
|
|
151
172
|
.input {
|
|
152
173
|
width: 100%;
|
|
@@ -326,8 +347,8 @@
|
|
|
326
347
|
transition: background .12s, border-color .12s;
|
|
327
348
|
}
|
|
328
349
|
.room-row:hover { background: var(--surface-2); border-color: var(--line); }
|
|
329
|
-
.room-row.room-switch-enter { animation: room-switch-row .
|
|
330
|
-
@keyframes room-switch-row { from { transform: translateY(var(--room-switch-shift,
|
|
350
|
+
.room-row.room-switch-enter { animation: room-switch-row .15s cubic-bezier(.1, .9, .2, 1); }
|
|
351
|
+
@keyframes room-switch-row { from { opacity: .55; transform: translateY(var(--room-switch-shift, 3px)); } }
|
|
331
352
|
.r-name { font-weight: 600; font-size: 14px; }
|
|
332
353
|
.r-meta { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
|
|
333
354
|
.r-go {
|
|
@@ -346,6 +367,7 @@
|
|
|
346
367
|
/* Full-screen image viewer zoom controls and split file actions. */
|
|
347
368
|
.image-dialog-tools { position: fixed; z-index: 2; top: 14px; left: 14px; display: flex; align-items: center; gap: 2px; padding: 3px; border: 1px solid rgb(255 255 255 / .18); border-radius: 999px; background: rgb(9 16 22 / .58); backdrop-filter: blur(6px); }
|
|
348
369
|
.image-dialog-tool { display: grid; place-items: center; min-width: 40px; height: 40px; padding: 0 8px; border: 1px solid transparent; border-radius: 999px; color: #fff; background: transparent; font: inherit; font-size: 18px; font-weight: 600; line-height: 1; cursor: pointer; }
|
|
370
|
+
.image-dialog-tool .fluent-icon { width: 16px; height: 16px; }
|
|
349
371
|
.image-dialog-tool:hover { background: rgb(255 255 255 / .14); }
|
|
350
372
|
.image-dialog-tool:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
|
|
351
373
|
.image-dialog-tool:disabled { opacity: .38; cursor: default; }
|
|
@@ -355,7 +377,7 @@
|
|
|
355
377
|
.resource-split { position: relative; display: inline-flex; align-items: stretch; }
|
|
356
378
|
.resource-split .resource-download { border-right: 0; border-radius: 10px 0 0 10px; }
|
|
357
379
|
.resource-split .resource-split-toggle { display: grid; place-items: center; width: 34px; min-height: 34px; padding: 0; border-radius: 0 10px 10px 0; color: var(--ink-2); }
|
|
358
|
-
.resource-split .resource-split-toggle svg { width: 15px; height: 15px;
|
|
380
|
+
.resource-split .resource-split-toggle svg { width: 15px; height: 15px; }
|
|
359
381
|
.resource-split .resource-split-toggle[aria-expanded="true"] { color: var(--accent); background: var(--accent-soft); }
|
|
360
382
|
.resource-split-menu { position: absolute; z-index: 30; top: calc(100% + 5px); right: 0; min-width: 160px; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
|
|
361
383
|
|
|
@@ -377,7 +399,7 @@
|
|
|
377
399
|
.admin-join-policy + .join-policy-hint { margin-bottom: 12px; }
|
|
378
400
|
.join-pending { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: 12px 14px; padding: 18px 20px; border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--line)); border-radius: 18px; background: linear-gradient(135deg, color-mix(in srgb, var(--accent-soft) 65%, var(--surface)), var(--surface)); box-shadow: 0 2px 5px rgb(34 53 47 / .04), 0 14px 34px rgb(34 53 47 / .07); }
|
|
379
401
|
.join-pending-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; color: var(--accent-ink); background: var(--accent); }
|
|
380
|
-
.join-pending-mark svg { width: 19px; height: 19px;
|
|
402
|
+
.join-pending-mark svg { width: 19px; height: 19px; }
|
|
381
403
|
.join-pending h2 { margin: 0; font-family: var(--font-display); font-size: 21px; font-weight: 600; letter-spacing: -.02em; }
|
|
382
404
|
.join-pending p { margin: 5px 0 0; font-size: 13px; line-height: 1.55; color: var(--ink-2); }
|
|
383
405
|
.join-pending .hint { color: var(--ink-3); font-size: 12px; }
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Markdown resources open in a reading pane on wide screens, or in a modal overlay
|
|
2
|
+
// when the window is too narrow or too short to give the chat a usable column.
|
|
3
|
+
import { formatBytes, renderMarkdown } from "./markdown.js";
|
|
4
|
+
|
|
5
|
+
const PANE_QUERY = "(min-width: 1100px) and (min-height: 560px)";
|
|
6
|
+
|
|
7
|
+
export function initDocPreview(app) {
|
|
8
|
+
const dialog = app.$("#docPreview");
|
|
9
|
+
if (!dialog) return;
|
|
10
|
+
const title = app.$("#docPreviewTitle"), size = app.$("#docPreviewSize");
|
|
11
|
+
const status = app.$("#docPreviewStatus"), body = app.$("#docPreviewBody");
|
|
12
|
+
const empty = app.$("#docPreviewEmpty"), download = app.$("#btnDocPreviewDownload");
|
|
13
|
+
const chatView = app.$("#chatView"), pane = matchMedia(PANE_QUERY);
|
|
14
|
+
let current = null, blob = null, token = 0, opener = null, pendingReopen = false;
|
|
15
|
+
|
|
16
|
+
const show = () => {
|
|
17
|
+
if (pane.matches) {
|
|
18
|
+
dialog.classList.add("is-pane");
|
|
19
|
+
chatView.classList.add("has-doc");
|
|
20
|
+
if (!dialog.open) dialog.show();
|
|
21
|
+
} else {
|
|
22
|
+
dialog.classList.remove("is-pane");
|
|
23
|
+
chatView.classList.remove("has-doc");
|
|
24
|
+
if (!dialog.open) dialog.showModal();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Crossing the breakpoint keeps the document: the pane becomes an overlay, or back.
|
|
29
|
+
const syncMode = () => {
|
|
30
|
+
if (!dialog.open || pane.matches === dialog.classList.contains("is-pane")) return;
|
|
31
|
+
pendingReopen = true;
|
|
32
|
+
dialog.close();
|
|
33
|
+
show();
|
|
34
|
+
title.focus({ preventScroll: true });
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const open = async (roomId, resource, source) => {
|
|
38
|
+
opener = source instanceof HTMLElement ? source : null;
|
|
39
|
+
current = { roomId, resource };
|
|
40
|
+
const request = ++token;
|
|
41
|
+
blob = null;
|
|
42
|
+
title.textContent = resource.name;
|
|
43
|
+
size.textContent = formatBytes(resource.size);
|
|
44
|
+
status.textContent = app.t("resourceLoading");
|
|
45
|
+
body.textContent = "";
|
|
46
|
+
empty.hidden = true;
|
|
47
|
+
download.disabled = true;
|
|
48
|
+
if (app.preserveReadingLayout) await app.preserveReadingLayout(show);
|
|
49
|
+
else show();
|
|
50
|
+
if (request !== token) return;
|
|
51
|
+
title.focus({ preventScroll: true });
|
|
52
|
+
try {
|
|
53
|
+
const data = await app.apiBlob(`/rooms/${encodeURIComponent(roomId)}/resources/${encodeURIComponent(resource.id)}/content`);
|
|
54
|
+
if (request !== token) return;
|
|
55
|
+
const text = await data.text();
|
|
56
|
+
if (request !== token) return;
|
|
57
|
+
blob = data;
|
|
58
|
+
renderMarkdown(body, text, app);
|
|
59
|
+
empty.hidden = body.children.length > 0;
|
|
60
|
+
status.textContent = "";
|
|
61
|
+
download.disabled = false;
|
|
62
|
+
} catch {
|
|
63
|
+
if (request === token) status.textContent = app.t("docPreviewFailed");
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const close = (restoreFocus = true) => {
|
|
68
|
+
if (!restoreFocus) opener = null;
|
|
69
|
+
if (dialog.open) dialog.close();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const downloadDocument = () => {
|
|
73
|
+
if (!blob || !current) return;
|
|
74
|
+
const url = URL.createObjectURL(blob), link = document.createElement("a");
|
|
75
|
+
link.href = url;
|
|
76
|
+
link.download = String(current.resource.name).replace(/[\\/\u0000-\u001f\u007f]/g, "_") || "download";
|
|
77
|
+
document.body.append(link); link.click(); link.remove();
|
|
78
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
app.openDocPreview = (roomId, resource, source) => { void open(roomId, resource, source); };
|
|
82
|
+
app.closeDocPreview = () => close();
|
|
83
|
+
|
|
84
|
+
app.$("#btnCloseDocPreview")?.addEventListener("click", () => close());
|
|
85
|
+
download.addEventListener("click", downloadDocument);
|
|
86
|
+
dialog.addEventListener("click", (event) => {
|
|
87
|
+
if (event.target === dialog && !dialog.classList.contains("is-pane")) close();
|
|
88
|
+
});
|
|
89
|
+
dialog.addEventListener("cancel", (event) => { event.preventDefault(); close(); });
|
|
90
|
+
document.addEventListener("keydown", (event) => {
|
|
91
|
+
if (event.key !== "Escape" || !dialog.open || !dialog.classList.contains("is-pane")) return;
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
close();
|
|
94
|
+
});
|
|
95
|
+
dialog.addEventListener("close", () => {
|
|
96
|
+
// A breakpoint switch closes and reopens the same dialog; its queued close event
|
|
97
|
+
// must not wipe the document that is already back on screen.
|
|
98
|
+
if (pendingReopen) { pendingReopen = false; return; }
|
|
99
|
+
token++;
|
|
100
|
+
current = null; blob = null;
|
|
101
|
+
chatView.classList.remove("has-doc");
|
|
102
|
+
dialog.classList.remove("is-pane");
|
|
103
|
+
title.textContent = ""; size.textContent = ""; status.textContent = "";
|
|
104
|
+
body.textContent = ""; empty.hidden = true; download.disabled = true;
|
|
105
|
+
const target = opener; opener = null;
|
|
106
|
+
if (target?.isConnected && target.getClientRects().length) target.focus({ preventScroll: true });
|
|
107
|
+
else app.focusChatComposer?.({ force: true });
|
|
108
|
+
});
|
|
109
|
+
const onChange = () => syncMode();
|
|
110
|
+
if (pane.addEventListener) pane.addEventListener("change", onChange);
|
|
111
|
+
else pane.addListener(onChange);
|
|
112
|
+
document.addEventListener("chat-room-activated", () => close(false));
|
|
113
|
+
}
|
|
@@ -12,7 +12,13 @@ export function initEvents(app) {
|
|
|
12
12
|
if ($("#chatView").hidden || editor.contentEditable !== "true" || !editor.getClientRects().length) return false;
|
|
13
13
|
if (roomRail.classList.contains("drawer-open")) return false;
|
|
14
14
|
if (!force && (document.activeElement !== document.body || window.getSelection()?.toString())) return false;
|
|
15
|
+
const selection = window.getSelection();
|
|
16
|
+
const selectionInside = Boolean(selection?.anchorNode && editor.contains(selection.anchorNode));
|
|
15
17
|
editor.focus({ preventScroll: true });
|
|
18
|
+
// A closed modal can leave the DOM selection inside its removed input even
|
|
19
|
+
// after the composer looks focused. Re-seat the caret so the next keystroke
|
|
20
|
+
// lands in the editor instead of disappearing.
|
|
21
|
+
if (force && !selectionInside) editor.setCaret?.(editor.value.length);
|
|
16
22
|
return true;
|
|
17
23
|
};
|
|
18
24
|
app.focusComposer = () => {
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
// Room files: a file-browser dialog over the room's uploaded resources.
|
|
2
2
|
import { LS } from "./state.js";
|
|
3
3
|
import { isRoomAdmin } from "./admin-badge.js";
|
|
4
|
+
import { icon } from "./icons.js";
|
|
5
|
+
import { isMarkdownResource } from "./markdown.js";
|
|
4
6
|
|
|
5
7
|
const PAGE_SIZE = 500;
|
|
6
8
|
const UNKNOWN_UPLOADER = "__unknown_uploader__";
|
|
7
9
|
const ICONS = {
|
|
8
|
-
image:
|
|
9
|
-
audio:
|
|
10
|
-
video:
|
|
11
|
-
file:
|
|
12
|
-
preview:
|
|
13
|
-
download:
|
|
14
|
-
trash:
|
|
10
|
+
image: "image",
|
|
11
|
+
audio: "music_note_2",
|
|
12
|
+
video: "video",
|
|
13
|
+
file: "document",
|
|
14
|
+
preview: "eye",
|
|
15
|
+
download: "arrow_download",
|
|
16
|
+
trash: "delete",
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
export function initFiles(app) {
|
|
@@ -123,14 +125,14 @@ export function initFiles(app) {
|
|
|
123
125
|
} catch { showError("resourceDeleteFailed"); }
|
|
124
126
|
};
|
|
125
127
|
|
|
126
|
-
const actionButton = (action, label,
|
|
128
|
+
const actionButton = (action, label, iconName, extra = {}) => {
|
|
127
129
|
const button = document.createElement("button");
|
|
128
130
|
button.type = "button";
|
|
129
131
|
button.className = `file-action file-action-${action}`;
|
|
130
132
|
button.dataset.fileAction = action;
|
|
131
133
|
button.setAttribute("aria-label", label);
|
|
132
134
|
button.title = label;
|
|
133
|
-
button.innerHTML = icon;
|
|
135
|
+
button.innerHTML = icon(iconName);
|
|
134
136
|
for (const [name, value] of Object.entries(extra)) button.setAttribute(name, value);
|
|
135
137
|
return button;
|
|
136
138
|
};
|
|
@@ -144,7 +146,7 @@ export function initFiles(app) {
|
|
|
144
146
|
badge.className = "file-kind";
|
|
145
147
|
badge.dataset.kind = kind;
|
|
146
148
|
badge.setAttribute("aria-hidden", "true");
|
|
147
|
-
badge.innerHTML = ICONS[kind] || ICONS.file;
|
|
149
|
+
badge.innerHTML = icon(ICONS[kind] || ICONS.file);
|
|
148
150
|
|
|
149
151
|
const main = document.createElement("div");
|
|
150
152
|
main.className = "file-main";
|
|
@@ -177,10 +179,11 @@ export function initFiles(app) {
|
|
|
177
179
|
const actions = document.createElement("div");
|
|
178
180
|
actions.className = "file-actions";
|
|
179
181
|
const previewID = `file-preview-${resource.id}`;
|
|
180
|
-
if (mediaKind(resource.mimeType)) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
if (mediaKind(resource.mimeType) || isMarkdownResource(resource)) {
|
|
183
|
+
const inline = mediaKind(resource.mimeType);
|
|
184
|
+
actions.append(actionButton("preview", app.t("filesPreviewLabel", { name: resource.name }), ICONS.preview, inline
|
|
185
|
+
? { "aria-expanded": "false", "aria-controls": previewID }
|
|
186
|
+
: {}));
|
|
184
187
|
}
|
|
185
188
|
actions.append(actionButton("download", app.t("filesDownloadLabel", { name: resource.name }), ICONS.download));
|
|
186
189
|
if (canDelete(resource)) actions.append(actionButton("delete", app.t("filesDeleteLabel", { name: resource.name }), ICONS.trash));
|
|
@@ -337,7 +340,8 @@ export function initFiles(app) {
|
|
|
337
340
|
hideError();
|
|
338
341
|
const target = opener;
|
|
339
342
|
opener = null;
|
|
340
|
-
|
|
343
|
+
// A document preview opens right after the file list closes; keep focus there.
|
|
344
|
+
if (target?.isConnected && !document.querySelector("dialog[open]")) target.focus({ preventScroll: true });
|
|
341
345
|
});
|
|
342
346
|
list.addEventListener("click", (event) => {
|
|
343
347
|
const button = event.target.closest?.("[data-file-action]");
|
|
@@ -346,7 +350,12 @@ export function initFiles(app) {
|
|
|
346
350
|
const resource = items.find((item) => item.id === row?.dataset.resourceId);
|
|
347
351
|
if (!resource) return;
|
|
348
352
|
const action = button.dataset.fileAction;
|
|
349
|
-
if (action === "preview"
|
|
353
|
+
if (action === "preview" && isMarkdownResource(resource)) {
|
|
354
|
+
// The document pane lives in the chat view; the modal file list would hide it.
|
|
355
|
+
close();
|
|
356
|
+
app.openDocPreview(resource.roomID, resource, null);
|
|
357
|
+
}
|
|
358
|
+
else if (action === "preview") void togglePreview(resource, row, button);
|
|
350
359
|
else if (action === "download") void download(resource);
|
|
351
360
|
else if (action === "delete") void removeResource(resource);
|
|
352
361
|
});
|
|
@@ -16,14 +16,47 @@ export function initHistoryLoader(app) {
|
|
|
16
16
|
label.textContent = app.t("loadingHistory");
|
|
17
17
|
spinner.append(wheel, label);
|
|
18
18
|
|
|
19
|
+
const prependOlder = (older, thread, list) => {
|
|
20
|
+
const tailSep = list.firstElementChild;
|
|
21
|
+
const fragment = document.createDocumentFragment();
|
|
22
|
+
let day = null;
|
|
23
|
+
for (const message of older) {
|
|
24
|
+
const messageDay = new Date(message.createdAt).toDateString();
|
|
25
|
+
if (messageDay !== day) {
|
|
26
|
+
const separator = document.createElement("li");
|
|
27
|
+
separator.className = "day-sep";
|
|
28
|
+
separator.dataset.day = messageDay;
|
|
29
|
+
separator.textContent = app.dayText(message.createdAt);
|
|
30
|
+
fragment.append(separator);
|
|
31
|
+
day = messageDay;
|
|
32
|
+
}
|
|
33
|
+
const row = app.renderMessage(message, false);
|
|
34
|
+
row.dataset.day = messageDay;
|
|
35
|
+
fragment.append(row);
|
|
36
|
+
}
|
|
37
|
+
const beforeHeight = thread.scrollHeight, beforeTop = thread.scrollTop;
|
|
38
|
+
list.prepend(fragment);
|
|
39
|
+
if (tailSep?.classList.contains("day-sep") && new Date(older.at(-1).createdAt).toDateString() === tailSep.dataset.day) tailSep.remove();
|
|
40
|
+
app.cancelThreadScrollAnimation?.();
|
|
41
|
+
thread.scrollTop = beforeTop + (thread.scrollHeight - beforeHeight);
|
|
42
|
+
app.queueReceiptRefresh?.();
|
|
43
|
+
};
|
|
44
|
+
|
|
19
45
|
app.loadOlderHistory = async () => {
|
|
20
46
|
const room = app.state.room, entry = room && app.state.rooms.get(room.id);
|
|
21
47
|
const thread = $("#thread"), list = $("#msgList");
|
|
22
|
-
if (!room || !entry || loading
|
|
48
|
+
if (!room || !entry || loading) return;
|
|
23
49
|
loading = true;
|
|
24
50
|
const generation = app.state.pollGeneration;
|
|
25
|
-
list.prepend(spinner);
|
|
26
51
|
try {
|
|
52
|
+
const firstRow = list.querySelector("[data-msg-id]");
|
|
53
|
+
const cachedIndex = firstRow ? entry.room.messages.findIndex((message) => message.id === firstRow.dataset.msgId) : -1;
|
|
54
|
+
if (cachedIndex > 0) {
|
|
55
|
+
prependOlder(entry.room.messages.slice(Math.max(0, cachedIndex - 100), cachedIndex), thread, list);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (entry.historyComplete || entry.historyBeforeSeq == null) return;
|
|
59
|
+
list.prepend(spinner);
|
|
27
60
|
const page = await app.api(`/rooms/${encodeURIComponent(room.id)}/history?beforeSeq=${entry.historyBeforeSeq}&limit=100`);
|
|
28
61
|
if (app.state.room?.id !== room.id || app.state.pollGeneration !== generation) return;
|
|
29
62
|
const known = new Set(entry.room.messages.map((message) => message.id));
|
|
@@ -31,33 +64,10 @@ export function initHistoryLoader(app) {
|
|
|
31
64
|
entry.historyComplete = !page.hasMore;
|
|
32
65
|
spinner.remove();
|
|
33
66
|
if (older.length) {
|
|
34
|
-
|
|
35
|
-
const fragment = document.createDocumentFragment();
|
|
36
|
-
let day = null;
|
|
37
|
-
for (const message of older) {
|
|
38
|
-
const messageDay = new Date(message.createdAt).toDateString();
|
|
39
|
-
if (messageDay !== day) {
|
|
40
|
-
const separator = document.createElement("li");
|
|
41
|
-
separator.className = "day-sep";
|
|
42
|
-
separator.dataset.day = messageDay;
|
|
43
|
-
separator.textContent = app.dayText(message.createdAt);
|
|
44
|
-
fragment.append(separator);
|
|
45
|
-
day = messageDay;
|
|
46
|
-
}
|
|
47
|
-
const row = app.renderMessage(message, false);
|
|
48
|
-
row.dataset.day = messageDay;
|
|
49
|
-
fragment.append(row);
|
|
50
|
-
}
|
|
51
|
-
// Baseline after the fetch: polls may have grown the tail meanwhile.
|
|
52
|
-
const beforeHeight = thread.scrollHeight, beforeTop = thread.scrollTop;
|
|
53
|
-
list.prepend(fragment);
|
|
54
|
-
if (tailSep?.classList.contains("day-sep") && new Date(older.at(-1).createdAt).toDateString() === tailSep.dataset.day) tailSep.remove();
|
|
67
|
+
prependOlder(older, thread, list);
|
|
55
68
|
entry.room.messages = [...older, ...entry.room.messages].sort((left, right) => left.createdAt - right.createdAt);
|
|
56
69
|
if (entry.room.messages.length > LOADED_MESSAGE_LIMIT) entry.room.messages.splice(0, entry.room.messages.length - LOADED_MESSAGE_LIMIT);
|
|
57
|
-
app.cancelThreadScrollAnimation?.();
|
|
58
|
-
thread.scrollTop = beforeTop + (thread.scrollHeight - beforeHeight);
|
|
59
70
|
app.cacheRoomSoon?.(room.id);
|
|
60
|
-
app.queueReceiptRefresh?.();
|
|
61
71
|
}
|
|
62
72
|
entry.historyBeforeSeq = page.hasMore ? (page.nextBeforeSeq ?? entry.room.messages[0]?.seq ?? null) : null;
|
|
63
73
|
} catch { /* the next scroll toward the top retries */ }
|