@alexsun-top/opencode-chat-room 0.3.2 → 0.4.0

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 CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0 — 2026-11-06
4
+
5
+ - Rename the web application to OC Chat and improve text contrast, typography, message widths, and control alignment. Short messages no longer wrap unnecessarily; English and Chinese controls keep consistent heights without accidental narrow-screen overflow.
6
+ - Replace in-message reader dropdowns with a separate reader-details panel. Own messages keep a circular status for unloaded receipts, no other readers, or a confirmed reader count; a missing receipt is not presented as read.
7
+ - Require an explicit, non-empty participant name for the room tool's `join` action. Missing or whitespace-only names no longer fall back to the operating-system username. Existing memberships and other tool actions are unchanged.
8
+ - Add persistent question messages through optional `isQuestion: true` on `send`. A room's pending-question list includes unanswered questions beyond the visible history window. Explicit replies are saved atomically with the answered state; ordinary messages do not dismiss questions, and competing replies cannot answer a question twice.
9
+ - Add a room-scoped question panel and reply workflow in the web chat. Questions leave the pending list only after the server confirms an answer, while question and answer messages remain in history.
10
+ - Preserve the active reply's focus, caret, and draft through polling. Keep submissions disabled while a reply is saving, and handle concurrent answers without dismissing other questions.
11
+ - Apply the SQLite startup lock timeout before enabling WAL, allowing concurrent legacy upgrades to wait for the schema lock. Normal operations retain their shorter busy timeout.
12
+ - Upgrade the central server for the new interface, question APIs, and additive SQLite migration. Reload client plugins to send `isQuestion` and enforce named joins. Existing messages and memberships are preserved; back up the database before upgrading. The shared token does not establish a separate human identity.
13
+ - Verified all 144 tests with Edge browser coverage, TypeScript, desktop/mobile screenshots, and English/Chinese layout checks. Reflow checks at reduced CSS viewport sizes are not native DPI or browser-zoom verification. Image messages remain unimplemented.
14
+
15
+ ## 0.3.3 — 2026-11-04
16
+
17
+ - Added an always-visible copy button below every message, including system messages. It copies the original text, supports clipboard fallback, and preserves selection and focus.
18
+ - Moved per-message reader counts into circular badges beside message bubbles. Reader details remain available on desktop and mobile, with localized accessible labels.
19
+ - Fixed capped V2 notifications discarding receipts for complete short messages in the same batch. Only uniquely matched, fully rendered messages qualify; truncated, omitted, multiline capped, and ambiguous duplicate messages remain unreceipted.
20
+ - Flush up to eight ready receipt candidates per round with ordered rotation, so transient upload failures do not repeatedly block later candidates. Failed candidates remain queued for retry.
21
+ - Verified all 143 tests, including Edge browser coverage, and TypeScript checks. An isolated OpenCode 2.2.5 host using the modified engine recorded the complete message but not the truncated message in a mixed batch. The reported production incident has not been independently attributed to either fixed case.
22
+ - Upgrade the central server for the web changes and reload each V2 client plugin for receipt fixes. This release does not deploy servers, change OpenCode permissions, or implement image messages.
23
+
3
24
  ## 0.3.2 — 2026-11-02
4
25
 
5
26
  - Fixed V2 context-receipt attribution when the verified host owner is discovered after plugin setup, and propagate that owner across project attachments. A full short message can now record `context` evidence without `room.poll`; capped previews remain unreceipted. A previously unready candidate becomes eligible only if its complete original message appears in agent context again—there is no read-all backfill or synthetic empty-context replay.
package/README.md CHANGED
@@ -79,17 +79,17 @@ On the server machine, install Bun first. `npx`, `pnpx`, and `bunx` only execute
79
79
 
80
80
  ```bash
81
81
  # Show CLI options:
82
- npx --yes --package=@alexsun-top/opencode-chat-room@0.3.2 -- opencode-chat-room --help
82
+ npx --yes --package=@alexsun-top/opencode-chat-room@0.4.0 -- opencode-chat-room --help
83
83
 
84
84
  # Start the local central server (choose any one runner):
85
- npx --yes --package=@alexsun-top/opencode-chat-room@0.3.2 -- opencode-chat-room --host 0.0.0.0 --port 4399
86
- pnpx --package=@alexsun-top/opencode-chat-room@0.3.2 opencode-chat-room --host 0.0.0.0 --port 4399
87
- bunx @alexsun-top/opencode-chat-room@0.3.2 --host 0.0.0.0 --port 4399 --token secret
85
+ npx --yes --package=@alexsun-top/opencode-chat-room@0.4.0 -- opencode-chat-room --host 0.0.0.0 --port 4399
86
+ pnpx --package=@alexsun-top/opencode-chat-room@0.4.0 opencode-chat-room --host 0.0.0.0 --port 4399
87
+ bunx @alexsun-top/opencode-chat-room@0.4.0 --host 0.0.0.0 --port 4399 --token secret
88
88
 
89
89
  # Environment variables also work; CLI options take precedence:
90
90
  CHAT_ROOM_SERVER_HOST=127.0.0.1 CHAT_ROOM_SERVER_PORT=4399 \
91
91
  CHAT_ROOM_SERVER_TOKEN=secret \
92
- bunx @alexsun-top/opencode-chat-room@0.3.2
92
+ bunx @alexsun-top/opencode-chat-room@0.4.0
93
93
 
94
94
  # Local checkout:
95
95
  bun install
@@ -110,6 +110,14 @@ The chat renders GitHub Flavored Markdown using locally bundled Marked and DOMPu
110
110
 
111
111
  The central server uses a trusted shared-token model, not per-user authorization or private DMs: anyone holding the token can read messages, manage rooms, remove members, and delete rooms. The server and its SQLite database can read direct-message content. Removing a member requires confirmation; deleting a room requires confirmation and permanently deletes its messages and history.
112
112
 
113
+ ### Question messages (0.4.0)
114
+
115
+ Use `room` with `action: "send"`, `roomId`, `text`, and `isQuestion: true` to send a question. In web chat, enable **Question** before sending. Open the room's **Questions** panel to answer pending questions one at a time. Ordinary chat replies do not dismiss questions. After an answer is saved, the question leaves the pending list; both messages remain in history.
116
+
117
+ `GET /rooms/:roomId/questions` returns `{ questions }`, oldest first, including pending questions outside the visible history window. `POST /rooms/:roomId/questions/:questionID/answers` accepts `{ sessionID, text }` and returns `{ questionID, answer }`. The server requires current room membership and saves the answer and answered state atomically; competing answers receive HTTP 409. Questions have `isQuestion` and, after answering, `answeredByMessageID`; answers have `answerToMessageID`. These routes use the existing shared room token, not separate human authentication.
118
+
119
+ Version 0.4.0 requires an explicit non-empty `name` for `room`'s `join` action. Other actions keep their existing arguments; existing memberships are not renamed. Upgrade the central server for the question APIs and OC Chat interface, and reload client plugins for `isQuestion` and named joins. Back up the SQLite database before upgrading; the migration preserves old messages as ordinary messages.
120
+
113
121
  ### Agent presence and message receipts
114
122
 
115
123
  `GET /rooms/<roomId>/members` returns each member's `membershipID`, `type`, and `activity: { state, observedAt }`; `observedAt` is the server timestamp in milliseconds. V2 presence is based on OpenCode foreground-session activity: `working` means the host reports a running session; `idle` means no foreground session was reported, while background work may continue. `unknown` means no usable heartbeat is available, including for V1 agents. `waiting` is an accepted state but is not automatically detected. Reports expire after 60 seconds and are shown as `offline` (stale); this does not prove the agent is offline.
@@ -132,7 +140,9 @@ Browser tabs fetch messages with `GET /inbox?sessionID=…&roomId=…&excludeSel
132
140
 
133
141
  Central server 0.3.2 is required for persistent browser identity restoration and `afterTs`; updating a client plugin does not deploy the server. Receipt APIs first appeared in 0.3.1. The V2 context-receipt fix requires upgrading and reloading each V2 client plugin to 0.3.2.
134
142
 
135
- Image messages are not implemented in 0.3.2; see the [image-message proposal](https://github.com/agentsyaml/opencode-chat-room/blob/main/docs/image-messages-plan.md).
143
+ Version 0.3.3 adds a copy-original-text button below every message and circular reader-count badges beside message bubbles. Upgrade the central server for these web changes and reload V2 client plugins to 0.3.3 for batch receipt fixes. Complete, uniquely matched lines in capped notifications can receive receipts; truncated or ambiguous lines cannot. Ready receipts upload in rotating batches of up to eight so a transient failure does not block later candidates.
144
+
145
+ Image messages are not implemented in 0.4.0; see the [image-message proposal](https://github.com/agentsyaml/opencode-chat-room/blob/main/docs/image-messages-plan.md).
136
146
 
137
147
  On every client machine:
138
148
 
package/README.zh-CN.md CHANGED
@@ -77,17 +77,17 @@ OpenCode 2.2.1 会在默认 60 分钟无活动后卸载闲置项目的服务。W
77
77
 
78
78
  ```bash
79
79
  # 查看 CLI 选项:
80
- npx --yes --package=@alexsun-top/opencode-chat-room@0.3.2 -- opencode-chat-room --help
80
+ npx --yes --package=@alexsun-top/opencode-chat-room@0.4.0 -- opencode-chat-room --help
81
81
 
82
82
  # 启动本地中心服务器(三选一):
83
- npx --yes --package=@alexsun-top/opencode-chat-room@0.3.2 -- opencode-chat-room --host 0.0.0.0 --port 4399
84
- pnpx --package=@alexsun-top/opencode-chat-room@0.3.2 opencode-chat-room --host 0.0.0.0 --port 4399
85
- bunx @alexsun-top/opencode-chat-room@0.3.2 --host 0.0.0.0 --port 4399 --token secret
83
+ npx --yes --package=@alexsun-top/opencode-chat-room@0.4.0 -- opencode-chat-room --host 0.0.0.0 --port 4399
84
+ pnpx --package=@alexsun-top/opencode-chat-room@0.4.0 opencode-chat-room --host 0.0.0.0 --port 4399
85
+ bunx @alexsun-top/opencode-chat-room@0.4.0 --host 0.0.0.0 --port 4399 --token secret
86
86
 
87
87
  # 也可以使用环境变量;CLI 参数优先:
88
88
  CHAT_ROOM_SERVER_HOST=127.0.0.1 CHAT_ROOM_SERVER_PORT=4399 \
89
89
  CHAT_ROOM_SERVER_TOKEN=secret \
90
- bunx @alexsun-top/opencode-chat-room@0.3.2
90
+ bunx @alexsun-top/opencode-chat-room@0.4.0
91
91
 
92
92
  # 本地 checkout:
93
93
  bun install
@@ -108,6 +108,14 @@ bun run server
108
108
 
109
109
  中心服务器使用团队共享令牌,不提供逐用户授权或私密私聊:任何持有令牌的人都能读取消息、管理房间、移除成员和删除房间;服务器及其 SQLite 数据库也能读取私聊内容。移除成员前会要求确认;删除房间也会要求确认,并永久删除房间消息和历史记录,无法恢复。
110
110
 
111
+ ### 问题消息(0.4.0)
112
+
113
+ Agent 可调用 `room`,传入 `action: "send"`、`roomId`、`text` 和 `isQuestion: true` 发送问题。网页发送前勾选“问题”,在当前房间的“问题”面板逐条回答。普通聊天回复不会自动消除问题;回答保存成功后,问题移出待回答列表,问题和回答仍保留在历史记录中。
114
+
115
+ `GET /rooms/:roomId/questions` 返回 `{ questions }`,按时间从旧到新排列,包含可视历史窗口以外的未回答问题。`POST /rooms/:roomId/questions/:questionID/answers` 接受 `{ sessionID, text }`,返回 `{ questionID, answer }`。服务端要求当前房间成员身份,并原子保存回答和已回答状态;并发重复回答返回 HTTP 409。问题包含 `isQuestion`,回答后增加 `answeredByMessageID`;回答包含 `answerToMessageID`。接口沿用共享令牌,不提供独立的人类身份认证。
116
+
117
+ 0.4.0 中,`room` 的 `join` 操作必须显式传入非空 `name`;其他操作参数不变,已有成员不会被改名。问题接口和 OC Chat 界面需升级中心服务器,`isQuestion` 和具名加入需重新加载客户端插件。升级前请备份 SQLite 数据库;迁移将旧消息保留为普通消息。
118
+
111
119
  ### Agent 状态与消息回执
112
120
 
113
121
  `GET /rooms/<roomId>/members` 会返回成员的 `membershipID`、`type` 和 `activity: { state, observedAt }`;`observedAt` 是服务端记录的毫秒时间戳。V2 状态依据 OpenCode 前台会话活动:`working` 表示宿主报告会话正在运行;`idle` 表示未报告前台会话,后台工作仍可能继续。没有可用心跳时(包括 V1 agent)状态为 `unknown`。`waiting` 是接口接受的状态,但插件不会自动检测。状态报告 60 秒后过期并显示为 `offline`(已过期);这不能证明 agent 已离线。
@@ -130,7 +138,9 @@ V2 使用 `POST /presence` 上报 owner 范围内递增的序号,每次最多
130
138
 
131
139
  浏览器持久身份恢复和 `afterTs` 需要中心服务器 0.3.2;只更新客户端插件不会部署服务端。回执 API 自 0.3.1 起提供。V2 上下文回执修复需要将每台 V2 客户端插件升级并重新加载到 0.3.2。
132
140
 
133
- 0.3.2 尚未实现图片消息;设计提案见[图片消息方案](https://github.com/agentsyaml/opencode-chat-room/blob/main/docs/image-messages-plan.md)。
141
+ 0.3.3 在每条消息下方增加复制原文按钮,并将已读人数改为消息旁的圆形标记。网页变化需升级中心服务器,批量回执修复需将各 V2 客户端插件升级并重新加载至 0.3.3。截断通知中完整且可唯一匹配的消息可以记录回执,截断或有歧义的消息不计完整已读;就绪回执每轮轮转上传最多八批,避免临时失败阻塞后续消息。
142
+
143
+ 0.4.0 尚未实现图片消息;设计提案见[图片消息方案](https://github.com/agentsyaml/opencode-chat-room/blob/main/docs/image-messages-plan.md)。
134
144
 
135
145
  每台客户端机器上:
136
146
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexsun-top/opencode-chat-room",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "A chat-room plugin and central server for OpenCode.",
5
5
  "repository": {
6
6
  "type": "git",
package/plugin.ts CHANGED
@@ -250,6 +250,11 @@ const roomArgs = z.object({
250
250
  name: z.string().max(64).optional(),
251
251
  roomId: z.string().optional(),
252
252
  text: z.string().max(2000).optional(),
253
+ isQuestion: z.boolean().optional(),
254
+ }).superRefine((args, ctx) => {
255
+ if (args.action === "join" && !args.name?.trim()) {
256
+ ctx.addIssue({ code: "custom", path: ["name"], message: "name is required to join a room" });
257
+ }
253
258
  });
254
259
  type RoomArguments = z.infer<typeof roomArgs>;
255
260
 
@@ -257,6 +262,7 @@ const roomExecute = async (
257
262
  args: RoomArguments,
258
263
  context: Pick<V1ToolContext, "sessionID">,
259
264
  ) => {
265
+ if (args.action === "join" && !args.name?.trim()) return "error: name is required to join a room";
260
266
  try {
261
267
  const runtime = currentRuntime();
262
268
  const explicitV2Join = runtime.protocol === "v2" && (args.action === "create" || args.action === "join");
@@ -317,7 +323,7 @@ const roomExecute = async (
317
323
  if (!args.roomId) {
318
324
  return "error: roomId is required";
319
325
  }
320
- const me = identity(args.name?.trim());
326
+ const me = identity(args.name!.trim());
321
327
  // ponytail: F5 — re-join under a new name retires the old
322
328
  // participant, otherwise every rename leaks a ghost member;
323
329
  // skipped when another session still holds the old name
@@ -391,6 +397,7 @@ const roomExecute = async (
391
397
  selfName,
392
398
  args.text,
393
399
  context.sessionID,
400
+ args.isQuestion,
394
401
  );
395
402
  const room = svc.getRoom(args.roomId);
396
403
  notifications.push({ roomId: args.roomId, roomName: room.name, messages: [...room.messages] });
@@ -3,19 +3,18 @@
3
3
  [hidden] { display: none !important; }
4
4
 
5
5
  :root {
6
- --font-sans: "PingFang SC","Hiragino Sans GB","Noto Sans SC","Noto Sans CJK SC","Source Han Sans SC","Microsoft YaHei",system-ui,-apple-system,sans-serif;
7
- --font-serif: "Songti SC","STSong","Noto Serif SC","Noto Serif CJK SC","Source Han Serif SC","SimSun",serif;
6
+ --font-sans: system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Hiragino Sans GB","Noto Sans SC","Noto Sans CJK SC","Source Han Sans SC","Microsoft YaHei",sans-serif;
8
7
  --font-mono: ui-monospace,"SF Mono","Cascadia Mono","JetBrains Mono",Consolas,monospace;
9
- --bg: #f4f1ea;
10
- --surface: #fdfcf8;
11
- --surface-2: #ece9df;
12
- --ink: #2a2721;
13
- --ink-2: #777162;
14
- --ink-3: #847c69;
15
- --line: #e2ddd0;
16
- --accent: #b85a35;
17
- --accent-ink: #fdf6ef;
18
- --accent-soft: #f6e3d6;
8
+ --bg: #f2f4f6;
9
+ --surface: #ffffff;
10
+ --surface-2: #f3f5f7;
11
+ --ink: #1c2631;
12
+ --ink-2: #465462;
13
+ --ink-3: #566574;
14
+ --line: #d5dce3;
15
+ --accent: #286783;
16
+ --accent-ink: #ffffff;
17
+ --accent-soft: #e2f0f5;
19
18
  --danger: #b23a2e;
20
19
  --danger-soft: #f9e7e2;
21
20
  --mention-blue: #2e6cc4;
@@ -24,16 +23,16 @@
24
23
 
25
24
  @media (prefers-color-scheme: dark) {
26
25
  :root {
27
- --bg: #17150f;
28
- --surface: #211e18;
29
- --surface-2: #2c2820;
30
- --ink: #eae5d8;
31
- --ink-2: #a19a88;
32
- --ink-3: #8a8372;
33
- --line: #322e25;
34
- --accent: #dd8761;
35
- --accent-ink: #241208;
36
- --accent-soft: #3b2418;
26
+ --bg: #151a20;
27
+ --surface: #1e252d;
28
+ --surface-2: #28313a;
29
+ --ink: #edf2f7;
30
+ --ink-2: #cad3dc;
31
+ --ink-3: #b3bfca;
32
+ --line: #3a4652;
33
+ --accent: #75b6cc;
34
+ --accent-ink: #10242c;
35
+ --accent-soft: #263f49;
37
36
  --danger: #e27a6c;
38
37
  --danger-soft: #3a201b;
39
38
  --mention-blue: #86a9ee;
@@ -45,8 +44,8 @@
45
44
  body {
46
45
  margin: 0;
47
46
  font-family: var(--font-sans);
48
- font-size: 15px;
49
- line-height: 1.6;
47
+ font-size: 16px;
48
+ line-height: 1.65;
50
49
  color: var(--ink);
51
50
  background:
52
51
  radial-gradient(1100px 520px at 50% -8%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 65%),
@@ -96,13 +95,14 @@
96
95
  }
97
96
  .locale-control { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-bottom: 20px; color: var(--ink-2); font-size: 12.5px; }
98
97
  .locale-control label { font-weight: 600; }
99
- .locale-select { appearance: auto; font: inherit; font-size: 12.5px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; cursor: pointer; }
98
+ .locale-select { appearance: auto; min-height: 36px; font: inherit; font-size: 12.5px; line-height: 1.25; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; cursor: pointer; }
100
99
  .chat-head-actions .locale-control { margin: 0; }
101
100
  .wordmark {
102
101
  margin: 0;
103
- font-family: var(--font-serif);
102
+ font-family: var(--font-sans);
104
103
  font-size: 30px;
105
- letter-spacing: .14em;
104
+ font-weight: 700;
105
+ letter-spacing: -.03em;
106
106
  color: var(--ink);
107
107
  }
108
108
  .tagline { margin: 8px 0 26px; font-size: 13.5px; color: var(--ink-2); }
@@ -136,6 +136,7 @@
136
136
  border: none;
137
137
  cursor: pointer;
138
138
  font: inherit;
139
+ line-height: 1.25;
139
140
  font-weight: 600;
140
141
  border-radius: 10px;
141
142
  padding: 11px 18px;
@@ -1,5 +1,5 @@
1
1
  import { LS } from "./state.js";
2
- import { copyCodeFromButton } from "./markdown.js";
2
+ import { copyCodeFromButton, copyTextToClipboard } from "./markdown.js";
3
3
 
4
4
  export function initEvents(app) {
5
5
  const $ = app.$;
@@ -80,6 +80,8 @@ export function initEvents(app) {
80
80
  $("#msgList").addEventListener("click", (event) => {
81
81
  const button = event.target.closest("[data-copy-code]");
82
82
  if (button) void copyCodeFromButton(button, app);
83
+ const messageButton = event.target.closest("[data-copy-message]");
84
+ if (messageButton) void copyTextToClipboard(messageButton._copyText).then((copied) => app.flash(messageButton, copied ? "copiedMessage" : "copyMessageFailed"));
83
85
  });
84
86
  ["#inRoomId", "#inName", "#inRoomName"].forEach((selector) => {
85
87
  $(selector).addEventListener("input", app.hideJoinError);
@@ -4,9 +4,13 @@ import { initMessages } from "./messages.js";
4
4
  import { initMembers } from "./members.js";
5
5
  import { initRooms } from "./rooms.js";
6
6
  import { initEvents } from "./events.js";
7
+ import { initQuestions } from "./questions.js";
8
+ import { initReceipts } from "./receipts.js";
7
9
 
8
10
  initMentions(app);
9
11
  initMessages(app);
12
+ initReceipts(app);
10
13
  initMembers(app);
11
14
  initRooms(app);
15
+ initQuestions(app);
12
16
  initEvents(app);
@@ -58,8 +58,27 @@ function replaceMentionTokens(fragment, mentions, app) {
58
58
 
59
59
  export function copyCodeFromButton(button, app) {
60
60
  const code = button.parentElement.querySelector("code")?.textContent || "";
61
- return navigator.clipboard?.writeText(code).then(
62
- () => app.flash(button, "copiedCode"),
63
- () => app.showSendError("copyCodeFailed"),
64
- ) ?? app.showSendError("copyCodeFailed");
61
+ return copyTextToClipboard(code).then((copied) => copied ? app.flash(button, "copiedCode") : app.showSendError("copyCodeFailed"));
62
+ }
63
+
64
+ export async function copyTextToClipboard(text) {
65
+ try {
66
+ if (navigator.clipboard?.writeText) {
67
+ await navigator.clipboard.writeText(text);
68
+ return true;
69
+ }
70
+ } catch { /* Use the legacy clipboard command when permission is unavailable. */ }
71
+ const field = document.createElement("textarea"), selection = getSelection(), active = document.activeElement;
72
+ const ranges = selection ? Array.from({ length: selection.rangeCount }, (_, index) => selection.getRangeAt(index).cloneRange()) : [];
73
+ field.value = text;
74
+ field.setAttribute("readonly", "");
75
+ field.style.cssText = "position:fixed;left:-9999px;top:0";
76
+ document.body.append(field);
77
+ field.select();
78
+ let copied = false;
79
+ try { copied = document.execCommand("copy"); } catch { /* Clipboard access may be disabled. */ }
80
+ field.remove();
81
+ if (selection) { selection.removeAllRanges(); ranges.forEach((range) => selection.addRange(range)); }
82
+ if (active instanceof HTMLElement) active.focus({ preventScroll: true });
83
+ return copied;
65
84
  }
@@ -48,7 +48,7 @@ export function initMessages(app) {
48
48
  app.renderFailedMessages();
49
49
  try {
50
50
  const updated = await app.api(`/rooms/${encodeURIComponent(roomId)}/messages`, {
51
- method: "POST", body: JSON.stringify({ sessionID: LS.sessionID, text: item.text }),
51
+ method: "POST", body: JSON.stringify({ sessionID: LS.sessionID, text: item.text, isQuestion: Boolean(item.isQuestion) }),
52
52
  });
53
53
  const entry = app.state.rooms.get(roomId);
54
54
  if (entry) {
@@ -144,29 +144,23 @@ export function initMessages(app) {
144
144
  const body = document.createElement("div");
145
145
  body.className = "msg-text";
146
146
  renderMarkdown(body, message.text, app);
147
- row.append(meta, body, receiptDetails(message, app));
147
+ const content = document.createElement("div");
148
+ content.className = "msg-content";
149
+ content.append(body, app.createReceiptButton(message, own));
150
+ row.append(meta, content);
148
151
  }
152
+ const copy = document.createElement("button");
153
+ copy.type = "button";
154
+ copy.className = "message-copy";
155
+ copy.dataset.copyMessage = "";
156
+ copy.dataset.i18n = "copyMessage";
157
+ copy.textContent = app.t("copyMessage");
158
+ copy._copyText = String(message.text ?? "");
159
+ row.append(copy);
149
160
  if (live) row.classList.add("in");
150
161
  return row;
151
162
  };
152
163
 
153
- app.renderReceiptData = (roomId, receipts) => {
154
- const thread = $("#thread"), edge = thread.getBoundingClientRect();
155
- const atBottom = thread.scrollHeight - thread.scrollTop - thread.clientHeight <= 2;
156
- const anchor = Array.from($("#msgList").querySelectorAll("[data-msg-id]")).find((node) => node.getBoundingClientRect().bottom > edge.top);
157
- const anchorId = anchor?.dataset.msgId, anchorTop = anchor ? anchor.getBoundingClientRect().top - edge.top : 0;
158
- for (const receipt of receipts) app.state.receipts.set(`${roomId}\0${receipt.messageID}`, receipt.readers);
159
- for (const row of document.querySelectorAll(`#msgList [data-msg-id]`)) {
160
- const message = app.state.room?.messages.find((item) => item.id === row.dataset.msgId);
161
- if (message?.roomId === roomId || app.state.room?.id === roomId && message) updateReceiptDetails(row, message, app);
162
- }
163
- if (atBottom) thread.scrollTop = thread.scrollHeight;
164
- else if (anchorId) {
165
- const next = $("#msgList").querySelector(`[data-msg-id="${CSS.escape(anchorId)}"]`);
166
- if (next) thread.scrollTop += next.getBoundingClientRect().top - thread.getBoundingClientRect().top - anchorTop;
167
- }
168
- };
169
-
170
164
  app.renderMessages = (live = false) => {
171
165
  const thread = $("#thread"), list = $("#msgList"), messages = app.state.room.messages;
172
166
  const nearBottom = thread.scrollHeight - thread.scrollTop - thread.clientHeight <= 2;
@@ -258,7 +252,7 @@ export function initMessages(app) {
258
252
  };
259
253
 
260
254
  app.send = async () => {
261
- const input = $("#msgInput"), text = input.value.trim(), room = app.state.room;
255
+ const input = $("#msgInput"), text = input.value.trim(), room = app.state.room, isQuestion = Boolean(app.isQuestionSending?.());
262
256
  if (!text || !room) return;
263
257
  const revision = app.state.draftRevision.get(room.id) || 0;
264
258
  app.closeMention();
@@ -270,7 +264,7 @@ export function initMessages(app) {
270
264
  app.hideSendError();
271
265
  try {
272
266
  const updated = await app.api(`/rooms/${encodeURIComponent(room.id)}/messages`, {
273
- method: "POST", body: JSON.stringify({ sessionID: LS.sessionID, text }),
267
+ method: "POST", body: JSON.stringify({ sessionID: LS.sessionID, text, isQuestion }),
274
268
  });
275
269
  if (app.state.room?.id !== room.id) return;
276
270
  app.state.room = updated;
@@ -291,7 +285,7 @@ export function initMessages(app) {
291
285
  } catch (error) {
292
286
  const unchanged = (app.state.draftRevision.get(room.id) || 0) === revision;
293
287
  const failures = app.state.failedMessages.get(room.id) || [];
294
- app.saveFailedMessages(room.id, [...failures, { id: createRandomId(), text }]);
288
+ app.saveFailedMessages(room.id, [...failures, { id: createRandomId(), text, isQuestion }]);
295
289
  app.renderFailedMessages();
296
290
  if (app.state.room?.id !== room.id) return;
297
291
  if (unchanged) app.clearDraft(room.id);
@@ -447,40 +441,4 @@ function trimMessages(list, app) {
447
441
  }
448
442
  }
449
443
 
450
- function receiptDetails(message, app) {
451
- const details = document.createElement("details");
452
- details.className = "message-readers";
453
- const summary = document.createElement("summary"), count = document.createElement("span"), list = document.createElement("ul");
454
- count.className = "receipt-count";
455
- list.className = "receipt-reader-list";
456
- summary.append(count);
457
- details.append(summary, list);
458
- updateReceiptDetails(details.closest("li") || details, message, app);
459
- return details;
460
- }
461
-
462
- function updateReceiptDetails(row, message, app) {
463
- const details = row.matches?.("details.message-readers") ? row : row.querySelector("details.message-readers");
464
- if (!details) return;
465
- const detailsKey = `${app.state.room?.id || message.roomId || ""}\0${message.id}`;
466
- const senderID = message.senderSessionID || (app.state.room?.kind === "direct" ? message.senderId : "");
467
- const readers = (app.state.receipts.get(detailsKey) || []).filter((reader) => reader.sessionID !== senderID);
468
- details.hidden = readers.length === 0;
469
- details.querySelector(".receipt-count").textContent = app.t("receiptCount", { count: readers.length });
470
- const list = details.querySelector(".receipt-reader-list");
471
- list.textContent = "";
472
- const members = app.state.memberSessions.get(app.state.room?.id) || [];
473
- for (const reader of readers) {
474
- const row = document.createElement("li"), name = document.createElement("span"), evidence = document.createElement("span");
475
- const duplicates = members.filter((member) => member.name === reader.name).length > 1 || readers.filter((item) => item.name === reader.name).length > 1;
476
- name.textContent = `${reader.name}${duplicates ? ` · ${reader.sessionID.slice(0, 8)}` : ""}${reader.currentMember === false ? ` · ${app.t("departedMember")}` : ""}`;
477
- evidence.textContent = app.t(`receiptEvidence_${reader.evidence}`);
478
- evidence.title = evidence.textContent;
479
- evidence.setAttribute("aria-label", evidence.textContent);
480
- row.dataset.readerSessionId = reader.sessionID;
481
- row.append(name, evidence);
482
- list.append(row);
483
- }
484
- }
485
-
486
444
  }