@alexsun-top/opencode-chat-room 0.4.0 → 0.5.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 +15 -0
- package/README.md +30 -5
- package/README.zh-CN.md +26 -4
- package/package.json +4 -1
- package/plugin.ts +18 -9
- package/server/announcement-routes.ts +34 -0
- package/server/assets/MERMAID-LICENSE +21 -0
- package/server/assets/NOTICE.txt +2 -1
- package/server/assets/base.css +15 -0
- package/server/assets/chat/announcements.js +119 -0
- package/server/assets/chat/events.js +180 -6
- package/server/assets/chat/index.js +2 -0
- package/server/assets/chat/markdown.js +214 -11
- package/server/assets/chat/members.js +4 -1
- package/server/assets/chat/messages.js +54 -18
- package/server/assets/chat/receipts.js +22 -17
- package/server/assets/chat/rooms.js +11 -6
- package/server/assets/chat/state.js +47 -13
- package/server/assets/conversation.css +21 -6
- package/server/assets/mermaid-11.12.2.min.js +2811 -0
- package/server/assets/responsive.css +39 -29
- package/server/chat-server.ts +8 -7
- package/server/chat.html +28 -9
- package/server/member-routes.ts +3 -0
- package/server/newrooms.ts +2 -0
- package/server/resource-routes.ts +65 -0
- package/server/wake.ts +2 -2
- package/skills/chatroom/SKILL.md +92 -0
- package/src/agent-receipts.ts +4 -4
- package/src/announcement-tool.ts +25 -0
- package/src/announcements.ts +16 -0
- package/src/center-client.ts +26 -0
- package/src/center-inbox.ts +9 -9
- package/src/chatroom-skill.ts +15 -0
- package/src/plugin-notifications.ts +7 -9
- package/src/resource-upload.ts +50 -0
- package/src/resources.ts +104 -0
- package/src/sqlite-state.ts +41 -0
- package/src/store.ts +1 -10
- package/src/v1-plugin.ts +6 -1
- package/src/v2-plugin.ts +34 -8
|
@@ -27,7 +27,7 @@ export function initReceipts(app) {
|
|
|
27
27
|
const next = $("#msgList").querySelector(`[data-msg-id="${CSS.escape(anchorId)}"]`);
|
|
28
28
|
if (next) thread.scrollTop += next.getBoundingClientRect().top - thread.getBoundingClientRect().top - anchorTop;
|
|
29
29
|
}
|
|
30
|
-
if (selectedID) renderPanel();
|
|
30
|
+
if (selectedID) { renderPanel(); positionPanel(); }
|
|
31
31
|
};
|
|
32
32
|
$("#msgList").addEventListener("click", (event) => {
|
|
33
33
|
const button = event.target.closest(".message-readers");
|
|
@@ -42,33 +42,38 @@ export function initReceipts(app) {
|
|
|
42
42
|
document.addEventListener("keydown", (event) => {
|
|
43
43
|
if (event.key === "Escape" && selectedID) { event.preventDefault(); close(true); }
|
|
44
44
|
});
|
|
45
|
+
window.addEventListener("resize", positionPanel);
|
|
46
|
+
window.addEventListener("scroll", positionPanel, true);
|
|
45
47
|
|
|
46
48
|
function open(id, button) {
|
|
47
49
|
selectedID = id; trigger = button;
|
|
48
50
|
button.setAttribute("aria-expanded", "true");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}, () => $("#btnCloseReaders").focus());
|
|
51
|
+
panel.hidden = false; renderPanel(); positionPanel();
|
|
52
|
+
requestAnimationFrame(() => $("#readerHeading").focus({ preventScroll: true }));
|
|
52
53
|
}
|
|
53
54
|
function close(restoreFocus) {
|
|
54
55
|
if (!selectedID) return;
|
|
55
56
|
const previous = trigger;
|
|
56
57
|
selectedID = ""; trigger = null;
|
|
57
58
|
previous?.setAttribute("aria-expanded", "false");
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}, () => { if (restoreFocus && previous?.isConnected) previous.focus({ preventScroll: true }); });
|
|
59
|
+
panel.hidden = true;
|
|
60
|
+
if (restoreFocus && previous?.isConnected) previous.focus({ preventScroll: true });
|
|
61
61
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
function positionPanel() {
|
|
63
|
+
if (!selectedID || panel.hidden) return;
|
|
64
|
+
if (!trigger?.isConnected) return close(false);
|
|
65
|
+
const anchor = trigger.getBoundingClientRect(), margin = 12;
|
|
66
|
+
if (anchor.bottom <= 0 || anchor.top >= innerHeight) return close(false);
|
|
67
|
+
const width = Math.min(320, innerWidth - margin * 2);
|
|
68
|
+
panel.style.width = `${width}px`;
|
|
69
|
+
const belowSpace = innerHeight - margin - anchor.bottom - 8;
|
|
70
|
+
const aboveSpace = anchor.top - margin - 8;
|
|
71
|
+
const placeBelow = belowSpace >= aboveSpace;
|
|
72
|
+
panel.style.maxHeight = `${Math.max(0, placeBelow ? belowSpace : aboveSpace)}px`;
|
|
73
|
+
const height = panel.getBoundingClientRect().height;
|
|
74
|
+
const left = Math.max(margin, Math.min(anchor.right - width, innerWidth - width - margin));
|
|
75
|
+
const top = placeBelow ? anchor.bottom + 8 : anchor.top - height - 8;
|
|
76
|
+
panel.style.left = `${left}px`; panel.style.top = `${top}px`;
|
|
72
77
|
}
|
|
73
78
|
function renderPanel() {
|
|
74
79
|
const message = app.state.room?.messages.find((item) => item.id === selectedID);
|
|
@@ -22,6 +22,7 @@ export function initRooms(app) {
|
|
|
22
22
|
$("#btnCopyId").title = app.t("copyRoomIdTitle", { id: app.state.room.id });
|
|
23
23
|
$("#btnCopyId").setAttribute("aria-label", app.t("copyRoomId"));
|
|
24
24
|
app.setText($("#railIdentity"), "identityLabel", { name: app.state.myName });
|
|
25
|
+
$("#profileAvatar").textContent = Array.from(app.state.myName.trim())[0]?.toLocaleUpperCase() || "?";
|
|
25
26
|
app.updateTitle();
|
|
26
27
|
};
|
|
27
28
|
|
|
@@ -40,6 +41,7 @@ export function initRooms(app) {
|
|
|
40
41
|
const entry = existing || { unreadIds: new Map(), unreadOverflow: false, preview: "", previewAt: 0, position: 0, readTs: 0, receivedTs: room.messages.at(-1)?.createdAt ?? 0 };
|
|
41
42
|
entry.unreadIds ||= new Map();
|
|
42
43
|
entry.unreadOverflow ||= false;
|
|
44
|
+
entry.readTs ||= app.state.lastReadTs.get(room.id) || 0;
|
|
43
45
|
entry.room = room;
|
|
44
46
|
entry.name = name;
|
|
45
47
|
const latest = room.messages.at(-1);
|
|
@@ -60,13 +62,12 @@ export function initRooms(app) {
|
|
|
60
62
|
if (app.state.room?.id === roomId) return;
|
|
61
63
|
if (app.state.room) {
|
|
62
64
|
app.saveDraft(app.state.room.id, $("#msgInput").value);
|
|
63
|
-
app.
|
|
65
|
+
app.captureReadingPosition?.();
|
|
64
66
|
}
|
|
65
67
|
app.stopPolling();
|
|
66
68
|
app.state.room = entry.room;
|
|
67
69
|
app.state.myName = entry.name;
|
|
68
|
-
const
|
|
69
|
-
entry.position = app.state.positions.get(roomId) ?? entry.position;
|
|
70
|
+
const savedPosition = app.state.positions.get(roomId);
|
|
70
71
|
app.state.unread = entry.unreadIds.size + (entry.unreadOverflow ? 100 : 0);
|
|
71
72
|
app.rendered = 0;
|
|
72
73
|
app.firstMessageId = null;
|
|
@@ -76,9 +77,11 @@ export function initRooms(app) {
|
|
|
76
77
|
app.renderHead();
|
|
77
78
|
$("#msgList").textContent = "";
|
|
78
79
|
app.renderMessages(false);
|
|
80
|
+
const restoredPosition = app.restoreReadingPosition?.(roomId);
|
|
81
|
+
app.state.readAnchorGuard = restoredPosition ? { roomId, ...restoredPosition } : null;
|
|
79
82
|
app.startPolling();
|
|
80
83
|
app.renderMembers();
|
|
81
|
-
$("#thread").scrollTop =
|
|
84
|
+
if (!restoredPosition) $("#thread").scrollTop = typeof savedPosition === "number" ? savedPosition : entry.position || $("#thread").scrollHeight;
|
|
82
85
|
$("#msgInput").disabled = false;
|
|
83
86
|
$("#msgInput").value = app.state.drafts.get(roomId) || "";
|
|
84
87
|
app.renderFailedMessages();
|
|
@@ -88,10 +91,11 @@ export function initRooms(app) {
|
|
|
88
91
|
app.hideSendError();
|
|
89
92
|
app.updateBadge();
|
|
90
93
|
app.updateJump();
|
|
91
|
-
app.markActiveRoomRead();
|
|
94
|
+
if (!restoredPosition) app.markActiveRoomRead();
|
|
92
95
|
app.renderRoomOptions($("#roomList"), app.state.availableRooms || []);
|
|
93
96
|
app.renderRoomOptions($("#roomListChat"), app.state.availableRooms || []);
|
|
94
97
|
void app.refreshRoomList();
|
|
98
|
+
document.dispatchEvent(new CustomEvent("chat-room-activated", { detail: roomId }));
|
|
95
99
|
};
|
|
96
100
|
|
|
97
101
|
app.joinRoom = async (roomId, name) => {
|
|
@@ -165,7 +169,7 @@ export function initRooms(app) {
|
|
|
165
169
|
if (active) {
|
|
166
170
|
app.state.navigationGeneration++;
|
|
167
171
|
app.saveDraft(roomId, $("#msgInput").value);
|
|
168
|
-
app.
|
|
172
|
+
app.captureReadingPosition?.();
|
|
169
173
|
app.stopPolling();
|
|
170
174
|
app.closeMention();
|
|
171
175
|
app.state.room = null;
|
|
@@ -375,6 +379,7 @@ export function initRooms(app) {
|
|
|
375
379
|
app.openTokenBox = () => { $("#tokenBox").open = true; };
|
|
376
380
|
app.openChatSettings = () => {
|
|
377
381
|
app.closePanels();
|
|
382
|
+
app.lastFocus = $("#btnSettings");
|
|
378
383
|
$("#chatSettings").hidden = false;
|
|
379
384
|
$("#btnSettings").setAttribute("aria-expanded", "true");
|
|
380
385
|
$("#tokenHint").hidden = false;
|
|
@@ -7,7 +7,8 @@ export const app = {
|
|
|
7
7
|
receiptObservation: null,
|
|
8
8
|
memberApiUnavailable: new Set(), receiptApiUnavailable: new Set(),
|
|
9
9
|
receipts: new Map(), acknowledgedMessages: new Map(), pendingAcknowledgements: new Map(),
|
|
10
|
-
pendingAction: null, watcherTimer: 0, restored: false,
|
|
10
|
+
pendingAction: null, watcherTimer: 0, restored: false, resizeScrollAdjusting: false, layoutScrollAdjusting: false,
|
|
11
|
+
readAnchorGuard: null, userScrollIntentUntil: 0,
|
|
11
12
|
},
|
|
12
13
|
rendered: 0,
|
|
13
14
|
firstMessageId: null,
|
|
@@ -145,6 +146,8 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
145
146
|
set drafts(value) { writeSession("chat.drafts", JSON.stringify(value)); },
|
|
146
147
|
get positions() { try { return JSON.parse(readSession("chat.positions") || "{}"); } catch { return {}; } },
|
|
147
148
|
set positions(value) { writeSession("chat.positions", JSON.stringify(value)); },
|
|
149
|
+
get readTs() { try { return JSON.parse(readSession("chat.readTs") || "{}"); } catch { return {}; } },
|
|
150
|
+
set readTs(value) { writeSession("chat.readTs", JSON.stringify(value)); },
|
|
148
151
|
get failedMessages() {
|
|
149
152
|
try {
|
|
150
153
|
const value = JSON.parse(readSession("chat.failedMessages") || "{}");
|
|
@@ -154,10 +157,10 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
154
157
|
set failedMessages(value) { writeSession("chat.failedMessages", JSON.stringify(value)); },
|
|
155
158
|
};
|
|
156
159
|
const saveToken = (value) => { auth.token = String(value ?? "").trim(); return auth.token; };
|
|
157
|
-
const
|
|
160
|
+
const apiResponse = async (url, options = {}) => {
|
|
158
161
|
assertIdentity();
|
|
159
162
|
const headers = { ...options.headers };
|
|
160
|
-
if (options.body) headers["Content-Type"] = "application/json";
|
|
163
|
+
if (typeof options.body === "string" && !headers["Content-Type"]) headers["Content-Type"] = "application/json";
|
|
161
164
|
if (auth.token) headers.Authorization = `Bearer ${auth.token}`;
|
|
162
165
|
let response;
|
|
163
166
|
try { response = await (fetcher ?? globalThis.fetch)(url, { ...options, headers }); }
|
|
@@ -166,16 +169,25 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
166
169
|
error.network = true;
|
|
167
170
|
throw error;
|
|
168
171
|
}
|
|
169
|
-
const data = await response.json().catch(() => ({}));
|
|
170
172
|
assertIdentity();
|
|
171
173
|
if (!response.ok) {
|
|
174
|
+
const data = await response.clone().json().catch(() => ({}));
|
|
175
|
+
assertIdentity();
|
|
172
176
|
const error = new Error(data.error || translate("requestFailed", { status: response.status }));
|
|
173
177
|
error.status = response.status;
|
|
174
178
|
throw error;
|
|
175
179
|
}
|
|
176
|
-
return
|
|
180
|
+
return response;
|
|
177
181
|
};
|
|
178
|
-
|
|
182
|
+
const api = async (url, options) => {
|
|
183
|
+
const response = await apiResponse(url, options), data = await response.json().catch(() => ({}));
|
|
184
|
+
assertIdentity(); return data;
|
|
185
|
+
};
|
|
186
|
+
const apiBlob = async (url, options) => {
|
|
187
|
+
const response = await apiResponse(url, options), blob = await response.blob();
|
|
188
|
+
assertIdentity(); return blob;
|
|
189
|
+
};
|
|
190
|
+
return { LS: auth, saveToken, api, apiBlob };
|
|
179
191
|
}
|
|
180
192
|
|
|
181
193
|
const messages = {
|
|
@@ -192,8 +204,14 @@ const messages = {
|
|
|
192
204
|
existingRooms: "Rooms", noRooms: "No rooms yet. Create one.", copyRoomId: "Copy room ID",
|
|
193
205
|
newRoom: "Create a room",
|
|
194
206
|
copyRoomIdTitle: ({ id }) => `Click to copy the full room ID: ${id}`, copied: "Copied",
|
|
195
|
-
members: "Members", membersCount: ({ count }) => `Members (${count})`, noMembers: "No members yet.",
|
|
207
|
+
members: "Members", membersCount: ({ count }) => `Members (${count})`, noMembers: "No members yet.", profileMenu: "Your profile and settings",
|
|
196
208
|
questions: "Questions", pendingQuestions: "Pending questions", refreshQuestions: "Refresh",
|
|
209
|
+
announcements: "Announcements", announcementName: "Name", announcementContent: "Content",
|
|
210
|
+
diagramLoading: "Rendering diagram…", diagramRenderFailed: "Diagram unavailable; showing its source.", resourceLoading: "Loading file…", resourceFailed: "This file could not be loaded.", resourceDownload: "Download", resourcePreview: "Preview", resourceHide: "Hide preview",
|
|
211
|
+
announcementDelete: "Delete announcement",
|
|
212
|
+
announcementNew: "New announcement", announcementEmpty: "No announcements yet.", announcementLoading: "Loading announcements…",
|
|
213
|
+
announcementLoadFailed: "Could not load announcements. Your draft is still here.", announcementSaved: "Announcement saved.", announcementDeleted: "Announcement deleted.",
|
|
214
|
+
announcementDuplicate: "That name already exists. Select it to edit, or choose another name.", announcementDeleteConfirm: ({ name }) => `Delete “${name}”?`, announcementCount: ({ count }) => `${count} / 5000`, announcementInvalid: "Use a name of 1–64 characters and content up to 5000 characters.",
|
|
197
215
|
questionsLoading: "Loading questions…", questionsEmpty: "No unanswered questions.",
|
|
198
216
|
questionsFailed: "Could not load questions. Try again.", questionLabel: "Question",
|
|
199
217
|
answerQuestion: "Reply", answerPlaceholder: "Write a reply…", sendAnswer: "Send reply",
|
|
@@ -207,7 +225,7 @@ const messages = {
|
|
|
207
225
|
joinArrow: "Join →", joinDirectTitle: "Click to join directly", mentionEmpty: "No matching members",
|
|
208
226
|
joined: "Joined", joinAction: "Join room", unreadMessages: ({ count }) => `${count} unread`,
|
|
209
227
|
mentionHint: "↑↓ Select · Enter to confirm · Esc to close", today: "Today", yesterday: "Yesterday",
|
|
210
|
-
earlierMessages: "Earlier messages omitted", you: "You", saved: "Saved",
|
|
228
|
+
earlierMessages: "Earlier messages omitted", messagesBetweenOmitted: "Messages between this reading point and latest are omitted.", you: "You", saved: "Saved",
|
|
211
229
|
savedMemory: "Saved for this tab only", copyFailed: ({ id }) => `Copy failed. Copy manually: ${id}`,
|
|
212
230
|
copyCode: "Copy code", copiedCode: "Copied", copyCodeFailed: "Could not copy code. Select and copy it manually.",
|
|
213
231
|
copyMessage: "Copy", copiedMessage: "Copied", copyMessageFailed: "Could not copy. Select and copy the message manually.",
|
|
@@ -223,6 +241,7 @@ const messages = {
|
|
|
223
241
|
failedMessages: "Messages not sent", retryFailed: "Retry", discardFailed: "Discard",
|
|
224
242
|
roomListError: "Unable to load rooms. You can enter a room ID directly.", guest: "Guest",
|
|
225
243
|
roomsLabel: "Rooms", refreshRooms: "Refresh rooms", identityLabel: ({ name }) => `Chatting as ${name}`,
|
|
244
|
+
roomsMenu: "Open room list", closeRoomList: "Close room list",
|
|
226
245
|
direct: "Direct", messagePrivately: "Message privately", removeMember: "Remove",
|
|
227
246
|
kickConfirm: ({ name, id }) => `Remove ${name} (session ${id}) from this room?`,
|
|
228
247
|
deleteRoom: "Delete room", deleteConfirm: ({ name }) => `Delete “${name}” and all its messages? This cannot be undone.`,
|
|
@@ -245,8 +264,14 @@ const messages = {
|
|
|
245
264
|
noRooms: "还没有房间,创建一个吧。", copyRoomId: "复制房间 ID",
|
|
246
265
|
newRoom: "创建房间",
|
|
247
266
|
copyRoomIdTitle: ({ id }) => `点击复制完整房间 ID:${id}`, copied: "已复制", members: "成员",
|
|
248
|
-
membersCount: ({ count }) => `成员 ${count}`, noMembers: "暂无成员", settings: "设置",
|
|
267
|
+
membersCount: ({ count }) => `成员 ${count}`, noMembers: "暂无成员", settings: "设置", profileMenu: "个人资料和设置",
|
|
249
268
|
questions: "提问", pendingQuestions: "待回答的问题", refreshQuestions: "刷新",
|
|
269
|
+
announcements: "公告栏", announcementName: "名称", announcementContent: "内容",
|
|
270
|
+
diagramLoading: "正在渲染图表…", diagramRenderFailed: "图表无法显示,以下为源代码。", resourceLoading: "正在加载文件…", resourceFailed: "无法加载此文件。", resourceDownload: "下载", resourcePreview: "预览", resourceHide: "收起预览",
|
|
271
|
+
announcementDelete: "删除公告",
|
|
272
|
+
announcementNew: "新建公告", announcementEmpty: "暂无公告。", announcementLoading: "正在加载公告…",
|
|
273
|
+
announcementLoadFailed: "无法加载公告,草稿仍已保留。", announcementSaved: "公告已保存。", announcementDeleted: "公告已删除。",
|
|
274
|
+
announcementDuplicate: "此名称已存在。请选择该公告进行编辑,或使用其他名称。", announcementDeleteConfirm: ({ name }) => `删除“${name}”?`, announcementCount: ({ count }) => `${count} / 5000`, announcementInvalid: "名称需为 1–64 个字符,内容不能超过 5000 个字符。",
|
|
250
275
|
questionsLoading: "正在加载问题…", questionsEmpty: "没有待回答的问题。",
|
|
251
276
|
questionsFailed: "无法加载问题,请重试。", questionLabel: "问题",
|
|
252
277
|
answerQuestion: "回复", answerPlaceholder: "写下回复…", sendAnswer: "发送回复",
|
|
@@ -258,7 +283,7 @@ const messages = {
|
|
|
258
283
|
send: "发送", roomMeta: ({ members, count }) => `${members} 人 · ${count} 条消息`, joinArrow: "加入 →",
|
|
259
284
|
joinDirectTitle: "点击直接加入", mentionEmpty: "没有匹配的成员", mentionHint: "↑↓ 选择 · Enter 确认 · Esc 关闭",
|
|
260
285
|
joined: "已加入", joinAction: "加入房间", unreadMessages: ({ count }) => `${count} 条未读`,
|
|
261
|
-
today: "今天", yesterday: "昨天", earlierMessages: "更早的消息已省略", you: "我", saved: "已保存",
|
|
286
|
+
today: "今天", yesterday: "昨天", earlierMessages: "更早的消息已省略", messagesBetweenOmitted: "此阅读位置与最新消息之间的部分消息已省略。", you: "我", saved: "已保存",
|
|
262
287
|
savedMemory: "仅保存于当前标签页", copyFailed: ({ id }) => `复制失败,请手动复制:${id}`,
|
|
263
288
|
copyCode: "复制代码", copiedCode: "已复制", copyCodeFailed: "复制失败,请手动选择并复制代码。",
|
|
264
289
|
copyMessage: "复制", copiedMessage: "已复制", copyMessageFailed: "复制失败,请手动选择并复制消息。",
|
|
@@ -271,7 +296,7 @@ const messages = {
|
|
|
271
296
|
sendNetwork: "发送失败,消息已保存在下方", sendFailed: ({ message }) => `发送失败:${message}`,
|
|
272
297
|
failedMessages: "未发送的消息", retryFailed: "重试", discardFailed: "删除",
|
|
273
298
|
roomListError: "无法加载房间列表,可直接输入房间 ID 加入。", guest: "访客", roomsLabel: "房间列表",
|
|
274
|
-
refreshRooms: "刷新房间", identityLabel: ({ name }) => `当前昵称:${name}`, direct: "私聊",
|
|
299
|
+
refreshRooms: "刷新房间", identityLabel: ({ name }) => `当前昵称:${name}`, roomsMenu: "打开房间列表", closeRoomList: "关闭房间列表", direct: "私聊",
|
|
275
300
|
messagePrivately: "私聊", removeMember: "移除", kickConfirm: ({ name, id }) => `确定将 ${name}(会话 ${id})移出此房间?`,
|
|
276
301
|
deleteRoom: "删除房间", deleteConfirm: ({ name }) => `删除“${name}”及全部聊天记录?此操作无法撤销。`,
|
|
277
302
|
allMembers: "所有人", messageCount: ({ count }) => `${count} / 2000`,
|
|
@@ -289,14 +314,16 @@ app.t = (key, values = {}) => {
|
|
|
289
314
|
const text = typeof entry === "function" ? entry(values) : entry;
|
|
290
315
|
return String(text).replace(/\{(\w+)\}/g, (_, name) => values[name] ?? "");
|
|
291
316
|
};
|
|
292
|
-
export const { LS, saveToken, api } = createAuth(undefined, undefined, (key, values) => app.t(key, values));
|
|
317
|
+
export const { LS, saveToken, api, apiBlob } = createAuth(undefined, undefined, (key, values) => app.t(key, values));
|
|
293
318
|
app.LS = LS;
|
|
294
319
|
app.api = api;
|
|
320
|
+
app.apiBlob = apiBlob;
|
|
295
321
|
app.setToken = saveToken;
|
|
296
322
|
app.locale = LS.locale === "zh-CN" ? "zh-CN" : "en";
|
|
297
323
|
app.state.joinedIds = new Set(LS.joinedRoomIds);
|
|
298
324
|
app.state.drafts = new Map(Object.entries(LS.drafts));
|
|
299
|
-
app.state.positions = new Map(Object.entries(LS.positions).map(([id, value]) => [id, Number(value) || 0]));
|
|
325
|
+
app.state.positions = new Map(Object.entries(LS.positions).map(([id, value]) => [id, value && typeof value === "object" ? value : Number(value) || 0]));
|
|
326
|
+
app.state.lastReadTs = new Map(Object.entries(LS.readTs).map(([id, value]) => [id, Number(value) || 0]));
|
|
300
327
|
app.state.roomNames = new Map(Object.entries(LS.roomNames));
|
|
301
328
|
app.state.failedMessages = new Map(Object.entries(LS.failedMessages).map(([id, items]) => [id, Array.isArray(items) ? items.filter((item) => item && typeof item.id === "string" && typeof item.text === "string") : []]));
|
|
302
329
|
app.saveDraft = (roomId, text) => {
|
|
@@ -316,9 +343,15 @@ app.savePosition = (roomId, position) => {
|
|
|
316
343
|
app.state.positions.set(roomId, position);
|
|
317
344
|
LS.positions = Object.fromEntries(app.state.positions);
|
|
318
345
|
};
|
|
346
|
+
app.saveReadTs = (roomId, timestamp) => {
|
|
347
|
+
app.state.lastReadTs.set(roomId, timestamp);
|
|
348
|
+
LS.readTs = Object.fromEntries(app.state.lastReadTs);
|
|
349
|
+
};
|
|
319
350
|
app.clearPosition = (roomId) => {
|
|
320
351
|
app.state.positions.delete(roomId);
|
|
321
352
|
LS.positions = Object.fromEntries(app.state.positions);
|
|
353
|
+
app.state.lastReadTs.delete(roomId);
|
|
354
|
+
LS.readTs = Object.fromEntries(app.state.lastReadTs);
|
|
322
355
|
};
|
|
323
356
|
app.saveJoinedIds = () => { LS.joinedRoomIds = [...app.state.joinedIds]; };
|
|
324
357
|
app.saveRoomNames = () => { LS.roomNames = Object.fromEntries(app.state.roomNames); };
|
|
@@ -340,6 +373,7 @@ app.applyLocale = () => {
|
|
|
340
373
|
});
|
|
341
374
|
}
|
|
342
375
|
document.querySelectorAll(".locale-select").forEach((select) => { select.value = app.locale; });
|
|
376
|
+
app.autoGrow?.(app.$("#msgInput"));
|
|
343
377
|
app.updateDraftCount?.();
|
|
344
378
|
app.updateMentionList?.();
|
|
345
379
|
app.renderFailedMessages?.();
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
background: var(--surface);
|
|
10
10
|
}
|
|
11
11
|
.chat-head-main h1 { margin: 0; font-family: var(--font-sans); font-size: 20px; font-weight: 650; line-height: 1.25; letter-spacing: -.02em; }
|
|
12
|
+
.room-title-row { display: flex; align-items: center; min-width: 0; gap: 8px; }
|
|
13
|
+
.room-title-row h1 { flex: 1; min-width: 0; }
|
|
14
|
+
.rooms-drawer-trigger { display: none; }
|
|
15
|
+
.room-drawer-backdrop { position: fixed; inset: 0; z-index: 49; border: 0; background: rgb(9 16 22 / .38); }
|
|
12
16
|
.room-meta { margin: 2px 0 0; font-size: 13px; color: var(--ink-2); }
|
|
13
17
|
.mono { font-family: var(--font-mono); }
|
|
14
18
|
.copy-id {
|
|
@@ -58,6 +62,8 @@
|
|
|
58
62
|
transition: color .12s, border-color .12s, background .12s;
|
|
59
63
|
}
|
|
60
64
|
.chip:hover { color: var(--ink); border-color: var(--ink-3); }
|
|
65
|
+
.profile-trigger { display: grid; place-items: center; width: 36px; height: 36px; padding: 3px; border-radius: 50%; }
|
|
66
|
+
.profile-trigger .rail-avatar { width: 25px; height: 25px; font-size: 12px; font-weight: 700; }
|
|
61
67
|
.chip.danger { color: var(--danger); }
|
|
62
68
|
.chip.danger:hover { border-color: var(--danger); background: var(--danger-soft); }
|
|
63
69
|
|
|
@@ -199,6 +205,7 @@
|
|
|
199
205
|
overflow-wrap: anywhere;
|
|
200
206
|
}
|
|
201
207
|
.msg.own .msg-text { background: var(--accent-soft); border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
|
|
208
|
+
.msg.own .msg-text ::selection { color: var(--accent-ink); background: var(--accent); }
|
|
202
209
|
.msg-content { position: relative; display: flex; align-items: flex-end; gap: 6px; width: 100%; max-width: 100%; }
|
|
203
210
|
.msg.own .msg-content { flex-direction: row-reverse; }
|
|
204
211
|
.message-copy {
|
|
@@ -224,13 +231,21 @@
|
|
|
224
231
|
.receipt-reader-list li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; }
|
|
225
232
|
.receipt-reader-list li + li { margin-top: 4px; }
|
|
226
233
|
.receipt-reader-list li span:last-child { color: var(--ink-3); }
|
|
227
|
-
.reader-panel {
|
|
234
|
+
.reader-panel { position: fixed; z-index: 40; width: min(320px, calc(100vw - 24px)); min-width: 0; max-height: calc(100dvh - 24px); overflow: auto; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
|
|
228
235
|
.reader-panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
|
|
229
236
|
.reader-panel-head h2 { margin: 0; font-family: var(--font-sans); font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
|
|
230
237
|
.reader-panel-head .hint { margin: 0 0 4px; }
|
|
231
238
|
.reader-close { flex: none; width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 50%; color: var(--ink-2); background: var(--surface); font: inherit; font-size: 21px; cursor: pointer; }
|
|
232
239
|
.reader-excerpt { max-height: 110px; overflow: auto; margin: 16px 0; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--surface-2); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
|
|
233
240
|
.reader-panel .receipt-reader-list li { display: grid; gap: 3px; padding: 10px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
|
|
241
|
+
.chat-resource { display: grid; gap: 8px; min-width: 0; margin: 10px 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
|
|
242
|
+
.resource-info, .resource-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
|
|
243
|
+
.resource-name { min-width: 0; overflow-wrap: anywhere; font-weight: 600; }
|
|
244
|
+
.resource-size, .resource-status { color: var(--ink-3); font-size: 12px; }
|
|
245
|
+
.resource-status { margin: 0; }
|
|
246
|
+
.resource-button { min-height: 34px; }
|
|
247
|
+
.chat-resource img, .chat-resource video { display: block; max-width: 100%; max-height: 420px; border-radius: 7px; }
|
|
248
|
+
.chat-resource audio { width: min(100%, 420px); }
|
|
234
249
|
|
|
235
250
|
/* Markdown content */
|
|
236
251
|
.msg-text p, .msg-text pre, .msg-text blockquote, .msg-text ul, .msg-text ol { margin: 0; }
|
|
@@ -390,21 +405,21 @@
|
|
|
390
405
|
background: var(--surface);
|
|
391
406
|
}
|
|
392
407
|
.composer-row { display: flex; gap: 10px; align-items: flex-end; }
|
|
393
|
-
.
|
|
408
|
+
.composer-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: min(940px, 100%); min-width: 0; margin: -2px auto 0; }
|
|
409
|
+
.question-toggle { min-width: 0; margin: 0; color: var(--ink-2); font-size: 12px; }
|
|
394
410
|
.question-toggle input { accent-color: var(--accent); vertical-align: -1px; }
|
|
395
411
|
.composer .input { flex: 1; }
|
|
396
412
|
.composer .input:disabled { opacity: .5; }
|
|
397
413
|
#msgInput {
|
|
398
|
-
min-height:
|
|
399
|
-
max-height: 132px;
|
|
414
|
+
min-height: 0;
|
|
400
415
|
padding: 12px 13px;
|
|
401
416
|
line-height: 1.5;
|
|
402
417
|
resize: none;
|
|
403
|
-
overflow-y:
|
|
418
|
+
overflow-y: hidden;
|
|
404
419
|
}
|
|
405
420
|
#btnSend { padding: 12px 22px; }
|
|
406
421
|
.send-error { margin: 0; font-size: 12.5px; color: var(--danger); }
|
|
407
|
-
.draft-count {
|
|
422
|
+
.draft-count { flex: none; margin: 0; color: var(--ink-3); text-align: right; font-size: 11px; font-variant-numeric: tabular-nums; }
|
|
408
423
|
.failed-messages { max-height: 150px; overflow-y: auto; padding: 8px 10px; border: 1px solid var(--danger-soft); border-radius: 10px; background: var(--danger-soft); }
|
|
409
424
|
.failed-messages h3 { margin: 0 0 5px; color: var(--danger); font-size: 12px; }
|
|
410
425
|
.failed-message { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-top: 1px solid var(--line); }
|