@alexsun-top/opencode-chat-room 0.2.2 → 0.3.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 +21 -0
- package/README.md +31 -13
- package/README.zh-CN.md +31 -14
- package/package.json +5 -2
- package/plugin.ts +6 -5
- package/server/assets/DOMPURIFY-LICENSE +202 -0
- package/server/assets/MARKED-LICENSE +44 -0
- package/server/assets/NOTICE.txt +6 -0
- package/server/assets/base.css +225 -0
- package/server/assets/chat/events.js +146 -0
- package/server/assets/chat/index.js +12 -0
- package/server/assets/chat/markdown.js +65 -0
- package/server/assets/chat/members.js +95 -0
- package/server/assets/chat/mentions.js +131 -0
- package/server/assets/chat/messages.js +417 -0
- package/server/assets/chat/rooms.js +443 -0
- package/server/assets/chat/state.js +316 -0
- package/server/assets/conversation.css +350 -0
- package/server/assets/dompurify-3.4.7.js +3 -0
- package/server/assets/marked-18.0.4.js +79 -0
- package/server/assets/responsive.css +119 -0
- package/server/chat-server.ts +34 -10
- package/server/chat.html +27 -1984
- package/server/history-route.ts +2 -1
- package/server/inbox.ts +1 -1
- package/server/newrooms.ts +90 -0
- package/server/wake.ts +14 -15
- package/src/background.ts +70 -25
- package/src/center-client.ts +3 -1
- package/src/center-inbox.ts +71 -37
- package/src/center-wake.ts +45 -11
- package/src/mentions.ts +7 -0
- package/src/plugin-notifications.ts +71 -24
- package/src/queue-transport.ts +18 -2
- package/src/queue.ts +36 -2
- package/src/receiver-state.ts +58 -1
- package/src/room-service.ts +19 -1
- package/src/sqlite-state.ts +24 -9
- package/src/store.ts +4 -3
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
export const app = {
|
|
2
|
+
$: (selector) => document.querySelector(selector),
|
|
3
|
+
state: {
|
|
4
|
+
room: null, myName: "", unread: 0, drafts: new Map(), rooms: new Map(),
|
|
5
|
+
pollGeneration: 0, navigationGeneration: 0, draftRevision: new Map(), memberSessions: new Map(),
|
|
6
|
+
retryingFailedIds: new Set(), pollController: null,
|
|
7
|
+
pendingAction: null, watcherTimer: 0, restored: false,
|
|
8
|
+
},
|
|
9
|
+
rendered: 0,
|
|
10
|
+
firstMessageId: null,
|
|
11
|
+
pollDelay: 2000,
|
|
12
|
+
copyTimer: 0,
|
|
13
|
+
failedRenderIds: new Set(),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function createRandomId() {
|
|
17
|
+
const crypto = globalThis.crypto;
|
|
18
|
+
if (crypto?.randomUUID) return crypto.randomUUID();
|
|
19
|
+
if (!crypto?.getRandomValues) throw new Error("Secure session ID generation is unavailable");
|
|
20
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
21
|
+
bytes[6] = (bytes[6] & 15) | 64;
|
|
22
|
+
bytes[8] = (bytes[8] & 63) | 128;
|
|
23
|
+
const hex = [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
24
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function createAuth(storage, fetcher, translate = (key) => key, sessionStore) {
|
|
28
|
+
const memory = Object.create(null);
|
|
29
|
+
let memorySessionID = "";
|
|
30
|
+
const read = (key) => {
|
|
31
|
+
if (Object.hasOwn(memory, key)) return memory[key];
|
|
32
|
+
try { return (storage ?? globalThis.localStorage).getItem(key); } catch { return null; }
|
|
33
|
+
};
|
|
34
|
+
const write = (key, value) => {
|
|
35
|
+
const stored = value == null ? null : String(value);
|
|
36
|
+
try {
|
|
37
|
+
const store = storage ?? globalThis.localStorage;
|
|
38
|
+
if (stored == null) store.removeItem(key);
|
|
39
|
+
else store.setItem(key, stored);
|
|
40
|
+
delete memory[key];
|
|
41
|
+
} catch { memory[key] = stored; }
|
|
42
|
+
};
|
|
43
|
+
const readSession = (key) => {
|
|
44
|
+
try { return (sessionStore ?? globalThis.sessionStorage).getItem(key); } catch { return null; }
|
|
45
|
+
};
|
|
46
|
+
const writeSession = (key, value) => {
|
|
47
|
+
try {
|
|
48
|
+
const store = sessionStore ?? globalThis.sessionStorage;
|
|
49
|
+
if (value == null) store.removeItem(key);
|
|
50
|
+
else store.setItem(key, value);
|
|
51
|
+
} catch { /* Tab-scoped state is best effort. */ }
|
|
52
|
+
};
|
|
53
|
+
const auth = {
|
|
54
|
+
get sessionID() {
|
|
55
|
+
if (memorySessionID) return memorySessionID;
|
|
56
|
+
try {
|
|
57
|
+
const store = sessionStore ?? globalThis.sessionStorage;
|
|
58
|
+
memorySessionID = store.getItem("chat.sessionID") || "";
|
|
59
|
+
} catch { /* Keep one identity in memory when tab storage is blocked. */ }
|
|
60
|
+
if (!memorySessionID) {
|
|
61
|
+
memorySessionID = createRandomId();
|
|
62
|
+
try { (sessionStore ?? globalThis.sessionStorage).setItem("chat.sessionID", memorySessionID); }
|
|
63
|
+
catch { /* In-memory identity remains stable. */ }
|
|
64
|
+
}
|
|
65
|
+
return memorySessionID;
|
|
66
|
+
},
|
|
67
|
+
get roomId() {
|
|
68
|
+
const active = readSession("chat.roomId");
|
|
69
|
+
if (active) return active;
|
|
70
|
+
const legacy = read("chat.roomId");
|
|
71
|
+
if (legacy) writeSession("chat.roomId", legacy);
|
|
72
|
+
return legacy || "";
|
|
73
|
+
},
|
|
74
|
+
set roomId(value) { writeSession("chat.roomId", value || null); write("chat.roomId", null); },
|
|
75
|
+
get name() { return readSession("chat.name") || read("chat.name") || ""; },
|
|
76
|
+
set name(value) { writeSession("chat.name", value || null); write("chat.name", null); },
|
|
77
|
+
get token() { return read("chat.token") || ""; }, set token(value) { write("chat.token", value || null); },
|
|
78
|
+
get locale() { return read("chat.locale") || "en"; }, set locale(value) { write("chat.locale", value || null); },
|
|
79
|
+
get joinedRoomIds() {
|
|
80
|
+
try {
|
|
81
|
+
const ids = JSON.parse(readSession("chat.joinedRoomIds") || "[]");
|
|
82
|
+
return Array.isArray(ids) ? [...new Set(ids.filter((id) => typeof id === "string"))] : [];
|
|
83
|
+
} catch { return []; }
|
|
84
|
+
},
|
|
85
|
+
set joinedRoomIds(ids) { writeSession("chat.joinedRoomIds", JSON.stringify([...new Set(ids)])); },
|
|
86
|
+
get roomNames() { try { return JSON.parse(readSession("chat.roomNames") || "{}"); } catch { return {}; } },
|
|
87
|
+
set roomNames(value) { writeSession("chat.roomNames", JSON.stringify(value)); },
|
|
88
|
+
get drafts() { try { return JSON.parse(readSession("chat.drafts") || "{}"); } catch { return {}; } },
|
|
89
|
+
set drafts(value) { writeSession("chat.drafts", JSON.stringify(value)); },
|
|
90
|
+
get positions() { try { return JSON.parse(readSession("chat.positions") || "{}"); } catch { return {}; } },
|
|
91
|
+
set positions(value) { writeSession("chat.positions", JSON.stringify(value)); },
|
|
92
|
+
get failedMessages() {
|
|
93
|
+
try {
|
|
94
|
+
const value = JSON.parse(readSession("chat.failedMessages") || "{}");
|
|
95
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
96
|
+
} catch { return {}; }
|
|
97
|
+
},
|
|
98
|
+
set failedMessages(value) { writeSession("chat.failedMessages", JSON.stringify(value)); },
|
|
99
|
+
};
|
|
100
|
+
const saveToken = (value) => { auth.token = String(value ?? "").trim(); return auth.token; };
|
|
101
|
+
const api = async (url, options = {}) => {
|
|
102
|
+
const headers = { ...options.headers };
|
|
103
|
+
if (options.body) headers["Content-Type"] = "application/json";
|
|
104
|
+
if (auth.token) headers.Authorization = `Bearer ${auth.token}`;
|
|
105
|
+
let response;
|
|
106
|
+
try { response = await (fetcher ?? globalThis.fetch)(url, { ...options, headers }); }
|
|
107
|
+
catch {
|
|
108
|
+
const error = new Error(translate("networkError"));
|
|
109
|
+
error.network = true;
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
const data = await response.json().catch(() => ({}));
|
|
113
|
+
if (!response.ok) {
|
|
114
|
+
const error = new Error(data.error || translate("requestFailed", { status: response.status }));
|
|
115
|
+
error.status = response.status;
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
return data;
|
|
119
|
+
};
|
|
120
|
+
return { LS: auth, saveToken, api };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const messages = {
|
|
124
|
+
en: {
|
|
125
|
+
brand: "Casual Chat", documentTitle: "Casual Chat · Lightweight Chatroom",
|
|
126
|
+
roomTitle: ({ name }) => `${name} · Casual Chat`,
|
|
127
|
+
tagline: "A lightweight chat room. Enter a room ID to join, or create a new one.",
|
|
128
|
+
languageLabel: "Language", roomIdLabel: "Room ID", roomIdPlaceholder: "Paste or enter a room ID",
|
|
129
|
+
nameLabel: "Your name", namePlaceholder: "What should we call you?", joinRoom: "Join room",
|
|
130
|
+
or: "or", newRoomNameLabel: "New room name", newRoomNamePlaceholder: "e.g. Weekend movie night",
|
|
131
|
+
createRoom: "Create room", tokenOptional: "Access token (optional)", bearerToken: "Bearer token",
|
|
132
|
+
tokenPlaceholder: "Enter if the server requires it", save: "Save",
|
|
133
|
+
tokenHint: "If the server requires an access token (401), all requests will include it.",
|
|
134
|
+
existingRooms: "Rooms", noRooms: "No rooms yet. Create one.", copyRoomId: "Copy room ID",
|
|
135
|
+
newRoom: "Create a room",
|
|
136
|
+
copyRoomIdTitle: ({ id }) => `Click to copy the full room ID: ${id}`, copied: "Copied",
|
|
137
|
+
members: "Members", membersCount: ({ count }) => `Members (${count})`, noMembers: "No members yet.",
|
|
138
|
+
settings: "Settings", tokenRequired: "The server requires an access token (401).",
|
|
139
|
+
leave: "Leave", reconnecting: "Connection lost. Retrying…", messageList: "Message list",
|
|
140
|
+
noMessages: "No messages yet. Say something.", latestMessages: "Back to latest messages",
|
|
141
|
+
mentionMembers: "Choose a member to mention", messagePlaceholder: "Message · Enter sends · Shift+Enter adds a line",
|
|
142
|
+
send: "Send", roomMeta: ({ members, count }) => `${members} ${members === 1 ? "member" : "members"} · ${count} ${count === 1 ? "message" : "messages"}`,
|
|
143
|
+
joinArrow: "Join →", joinDirectTitle: "Click to join directly", mentionEmpty: "No matching members",
|
|
144
|
+
joined: "Joined", joinAction: "Join room", unreadMessages: ({ count }) => `${count} unread`,
|
|
145
|
+
mentionHint: "↑↓ Select · Enter to confirm · Esc to close", today: "Today", yesterday: "Yesterday",
|
|
146
|
+
earlierMessages: "Earlier messages omitted", you: "You", saved: "Saved",
|
|
147
|
+
savedMemory: "Saved for this tab only", copyFailed: ({ id }) => `Copy failed. Copy manually: ${id}`,
|
|
148
|
+
copyCode: "Copy code", copiedCode: "Copied", copyCodeFailed: "Could not copy code. Select and copy it manually.",
|
|
149
|
+
networkError: "Network connection failed", requestFailed: ({ status }) => `Request failed (HTTP ${status})`,
|
|
150
|
+
roomIdRequired: "Enter a room ID", nameRequired: "Enter your name", authRetry: "The server requires an access token. Enter it and try again.",
|
|
151
|
+
networkRetry: "Unable to connect to the server. Check your network and try again.",
|
|
152
|
+
joinFailed: ({ message }) => `Could not join: ${message}`, roomNameRequired: "Enter a room name",
|
|
153
|
+
createFailed: ({ message }) => `Could not create the room: ${message}`,
|
|
154
|
+
roomNotFound: "This room is gone, or you no longer have access.",
|
|
155
|
+
sendAuth: "Send failed: an access token is required", sendNetwork: "Send failed. Your message is saved below.",
|
|
156
|
+
sendFailed: ({ message }) => `Send failed: ${message}`,
|
|
157
|
+
failedMessages: "Messages not sent", retryFailed: "Retry", discardFailed: "Discard",
|
|
158
|
+
roomListError: "Unable to load rooms. You can enter a room ID directly.", guest: "Guest",
|
|
159
|
+
roomsLabel: "Rooms", refreshRooms: "Refresh rooms", identityLabel: ({ name }) => `Chatting as ${name}`,
|
|
160
|
+
direct: "Direct", messagePrivately: "Message privately", removeMember: "Remove",
|
|
161
|
+
kickConfirm: ({ name, id }) => `Remove ${name} (session ${id}) from this room?`,
|
|
162
|
+
deleteRoom: "Delete room", deleteConfirm: ({ name }) => `Delete “${name}” and all its messages? This cannot be undone.`,
|
|
163
|
+
allMembers: "Everyone", messageCount: ({ count }) => `${count} / 2000`,
|
|
164
|
+
privacyNote: "Anyone with the shared token can read direct messages and manage rooms; the server can read them too.",
|
|
165
|
+
systemJoined: ({ name }) => `${name} joined the room`, systemLeft: ({ name }) => `${name} left the room`,
|
|
166
|
+
},
|
|
167
|
+
"zh-CN": {
|
|
168
|
+
brand: "闲叙", documentTitle: "闲叙 · 轻量聊天室", roomTitle: ({ name }) => `${name} · 闲叙`,
|
|
169
|
+
tagline: "一个轻量的聊天房间。输入房间 ID 加入,或直接新建一个。", languageLabel: "语言",
|
|
170
|
+
roomIdLabel: "房间 ID", roomIdPlaceholder: "粘贴或输入房间 ID", nameLabel: "你的昵称",
|
|
171
|
+
namePlaceholder: "怎么称呼你", joinRoom: "加入房间", or: "或", newRoomNameLabel: "新房间名称",
|
|
172
|
+
newRoomNamePlaceholder: "例如:周末电影夜", createRoom: "创建新房间", tokenOptional: "访问令牌(可选)",
|
|
173
|
+
bearerToken: "Bearer Token", tokenPlaceholder: "服务器要求时填写", save: "保存",
|
|
174
|
+
tokenHint: "若服务器设置了访问令牌(401),所有请求都会带上它。", existingRooms: "房间",
|
|
175
|
+
noRooms: "还没有房间,创建一个吧。", copyRoomId: "复制房间 ID",
|
|
176
|
+
newRoom: "创建房间",
|
|
177
|
+
copyRoomIdTitle: ({ id }) => `点击复制完整房间 ID:${id}`, copied: "已复制", members: "成员",
|
|
178
|
+
membersCount: ({ count }) => `成员 ${count}`, noMembers: "暂无成员", settings: "设置",
|
|
179
|
+
tokenRequired: "服务器要求访问令牌(401)。", leave: "离开", reconnecting: "连接中断,正在重试…",
|
|
180
|
+
messageList: "消息列表", noMessages: "还没有消息,说点什么吧。", latestMessages: "回到最新消息",
|
|
181
|
+
mentionMembers: "选择要提及的成员", messagePlaceholder: "输入消息,Enter 发送,Shift+Enter 换行",
|
|
182
|
+
send: "发送", roomMeta: ({ members, count }) => `${members} 人 · ${count} 条消息`, joinArrow: "加入 →",
|
|
183
|
+
joinDirectTitle: "点击直接加入", mentionEmpty: "没有匹配的成员", mentionHint: "↑↓ 选择 · Enter 确认 · Esc 关闭",
|
|
184
|
+
joined: "已加入", joinAction: "加入房间", unreadMessages: ({ count }) => `${count} 条未读`,
|
|
185
|
+
today: "今天", yesterday: "昨天", earlierMessages: "更早的消息已省略", you: "我", saved: "已保存",
|
|
186
|
+
savedMemory: "仅保存于当前标签页", copyFailed: ({ id }) => `复制失败,请手动复制:${id}`,
|
|
187
|
+
copyCode: "复制代码", copiedCode: "已复制", copyCodeFailed: "复制失败,请手动选择并复制代码。",
|
|
188
|
+
networkError: "网络连接失败", requestFailed: ({ status }) => `请求失败(HTTP ${status})`,
|
|
189
|
+
roomIdRequired: "请输入房间 ID", nameRequired: "请输入你的昵称", authRetry: "服务器要求访问令牌,请填写后重试",
|
|
190
|
+
networkRetry: "无法连接服务器,请检查网络后重试", joinFailed: ({ message }) => `加入失败:${message}`,
|
|
191
|
+
roomNameRequired: "请输入房间名称", createFailed: ({ message }) => `创建失败:${message}`,
|
|
192
|
+
roomNotFound: "房间不存在,或你已被移出房间", sendAuth: "发送失败:需要访问令牌",
|
|
193
|
+
sendNetwork: "发送失败,消息已保存在下方", sendFailed: ({ message }) => `发送失败:${message}`,
|
|
194
|
+
failedMessages: "未发送的消息", retryFailed: "重试", discardFailed: "删除",
|
|
195
|
+
roomListError: "无法加载房间列表,可直接输入房间 ID 加入。", guest: "访客", roomsLabel: "房间列表",
|
|
196
|
+
refreshRooms: "刷新房间", identityLabel: ({ name }) => `当前昵称:${name}`, direct: "私聊",
|
|
197
|
+
messagePrivately: "私聊", removeMember: "移除", kickConfirm: ({ name, id }) => `确定将 ${name}(会话 ${id})移出此房间?`,
|
|
198
|
+
deleteRoom: "删除房间", deleteConfirm: ({ name }) => `删除“${name}”及全部聊天记录?此操作无法撤销。`,
|
|
199
|
+
allMembers: "所有人", messageCount: ({ count }) => `${count} / 2000`,
|
|
200
|
+
privacyNote: "持有共享令牌的人都可以读取私聊内容和管理房间;服务器也可以读取私聊内容。",
|
|
201
|
+
systemJoined: ({ name }) => `${name} 加入了房间`, systemLeft: ({ name }) => `${name} 离开了房间`,
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
app.t = (key, values = {}) => {
|
|
206
|
+
const entry = messages[app.locale][key] ?? messages.en[key] ?? key;
|
|
207
|
+
const text = typeof entry === "function" ? entry(values) : entry;
|
|
208
|
+
return String(text).replace(/\{(\w+)\}/g, (_, name) => values[name] ?? "");
|
|
209
|
+
};
|
|
210
|
+
export const { LS, saveToken, api } = createAuth(undefined, undefined, (key, values) => app.t(key, values));
|
|
211
|
+
app.LS = LS;
|
|
212
|
+
app.api = api;
|
|
213
|
+
app.setToken = saveToken;
|
|
214
|
+
app.locale = LS.locale === "zh-CN" ? "zh-CN" : "en";
|
|
215
|
+
app.state.joinedIds = new Set(LS.joinedRoomIds);
|
|
216
|
+
app.state.drafts = new Map(Object.entries(LS.drafts));
|
|
217
|
+
app.state.positions = new Map(Object.entries(LS.positions).map(([id, value]) => [id, Number(value) || 0]));
|
|
218
|
+
app.state.roomNames = new Map(Object.entries(LS.roomNames));
|
|
219
|
+
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") : []]));
|
|
220
|
+
app.saveDraft = (roomId, text) => {
|
|
221
|
+
app.state.drafts.set(roomId, text);
|
|
222
|
+
LS.drafts = Object.fromEntries(app.state.drafts);
|
|
223
|
+
};
|
|
224
|
+
app.clearDraft = (roomId) => {
|
|
225
|
+
app.state.drafts.delete(roomId);
|
|
226
|
+
LS.drafts = Object.fromEntries(app.state.drafts);
|
|
227
|
+
};
|
|
228
|
+
app.saveFailedMessages = (roomId, items) => {
|
|
229
|
+
if (items.length) app.state.failedMessages.set(roomId, items);
|
|
230
|
+
else app.state.failedMessages.delete(roomId);
|
|
231
|
+
LS.failedMessages = Object.fromEntries(app.state.failedMessages);
|
|
232
|
+
};
|
|
233
|
+
app.savePosition = (roomId, position) => {
|
|
234
|
+
app.state.positions.set(roomId, position);
|
|
235
|
+
LS.positions = Object.fromEntries(app.state.positions);
|
|
236
|
+
};
|
|
237
|
+
app.clearPosition = (roomId) => {
|
|
238
|
+
app.state.positions.delete(roomId);
|
|
239
|
+
LS.positions = Object.fromEntries(app.state.positions);
|
|
240
|
+
};
|
|
241
|
+
app.saveJoinedIds = () => { LS.joinedRoomIds = [...app.state.joinedIds]; };
|
|
242
|
+
app.saveRoomNames = () => { LS.roomNames = Object.fromEntries(app.state.roomNames); };
|
|
243
|
+
app.setText = (element, key, values = {}) => {
|
|
244
|
+
element.dataset.i18n = key;
|
|
245
|
+
element._i18nValues = values;
|
|
246
|
+
element.textContent = app.t(key, values);
|
|
247
|
+
};
|
|
248
|
+
app.applyLocale = () => {
|
|
249
|
+
document.documentElement.lang = app.locale;
|
|
250
|
+
document.querySelectorAll("[data-i18n]").forEach((element) => {
|
|
251
|
+
element.textContent = element._flashKey
|
|
252
|
+
? app.t(element._flashKey)
|
|
253
|
+
: app.t(element.dataset.i18n, element._i18nValues || {});
|
|
254
|
+
});
|
|
255
|
+
for (const attribute of ["aria-label", "title", "placeholder"]) {
|
|
256
|
+
document.querySelectorAll(`[data-i18n-${attribute}]`).forEach((element) => {
|
|
257
|
+
element.setAttribute(attribute, app.t(element.getAttribute(`data-i18n-${attribute}`), element._i18nValues || {}));
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
document.querySelectorAll(".locale-select").forEach((select) => { select.value = app.locale; });
|
|
261
|
+
app.updateDraftCount?.();
|
|
262
|
+
app.updateMentionList?.();
|
|
263
|
+
app.renderFailedMessages?.();
|
|
264
|
+
if (app.state.room) {
|
|
265
|
+
app.renderHead();
|
|
266
|
+
app.renderMembers();
|
|
267
|
+
app.rerenderMessages();
|
|
268
|
+
} else app.updateTitle();
|
|
269
|
+
};
|
|
270
|
+
app.setLocale = (locale) => {
|
|
271
|
+
app.locale = locale === "zh-CN" ? "zh-CN" : "en";
|
|
272
|
+
LS.locale = app.locale;
|
|
273
|
+
app.applyLocale();
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
app.intlLocale = () => app.locale === "zh-CN" ? "zh-CN" : "en-US";
|
|
277
|
+
app.fmtTime = (timestamp) => {
|
|
278
|
+
const date = new Date(timestamp);
|
|
279
|
+
return date.toDateString() === new Date().toDateString()
|
|
280
|
+
? `${app.t("today")} ${app.timeHM(timestamp)}`
|
|
281
|
+
: new Intl.DateTimeFormat(app.intlLocale(), { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" }).format(date);
|
|
282
|
+
};
|
|
283
|
+
app.timeHM = (timestamp) => new Date(timestamp).toLocaleTimeString(app.intlLocale(), { hour: "2-digit", minute: "2-digit" });
|
|
284
|
+
app.dayText = (timestamp) => {
|
|
285
|
+
const date = new Date(timestamp), now = new Date();
|
|
286
|
+
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
287
|
+
const thatDay = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
288
|
+
const difference = Math.round((today - thatDay) / 86400000);
|
|
289
|
+
if (difference === 0) return app.t("today");
|
|
290
|
+
if (difference === 1) return app.t("yesterday");
|
|
291
|
+
return new Intl.DateTimeFormat(app.intlLocale(), { month: "short", day: "numeric" }).format(date);
|
|
292
|
+
};
|
|
293
|
+
app.flash = (button, key) => {
|
|
294
|
+
button._flashKey = key;
|
|
295
|
+
button.textContent = app.t(key);
|
|
296
|
+
setTimeout(() => {
|
|
297
|
+
if (button._flashKey !== key) return;
|
|
298
|
+
delete button._flashKey;
|
|
299
|
+
button.textContent = app.t(button.dataset.i18n, button._i18nValues || {});
|
|
300
|
+
}, 1200);
|
|
301
|
+
};
|
|
302
|
+
app.updateTitle = () => {
|
|
303
|
+
const title = app.state.room ? app.t("roomTitle", { name: app.state.room.name }) : app.t("documentTitle");
|
|
304
|
+
document.title = app.state.unread ? `(${app.state.unread}) ${title}` : title;
|
|
305
|
+
};
|
|
306
|
+
app.setOnline = (online) => { app.$("#connBar").hidden = online; };
|
|
307
|
+
app.showSendError = (key, values = {}) => {
|
|
308
|
+
app.setText(app.$("#sendError"), key, values);
|
|
309
|
+
app.$("#sendError").hidden = false;
|
|
310
|
+
};
|
|
311
|
+
app.hideSendError = () => { app.$("#sendError").hidden = true; };
|
|
312
|
+
app.showJoinError = (key, values = {}) => {
|
|
313
|
+
app.setText(app.$("#joinError"), key, values);
|
|
314
|
+
app.$("#joinError").hidden = false;
|
|
315
|
+
};
|
|
316
|
+
app.hideJoinError = () => { app.$("#joinError").hidden = true; };
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
.chat-head {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-wrap: wrap;
|
|
4
|
+
align-items: center;
|
|
5
|
+
justify-content: space-between;
|
|
6
|
+
gap: 8px 14px;
|
|
7
|
+
padding: 14px 20px;
|
|
8
|
+
border-bottom: 1px solid var(--line);
|
|
9
|
+
background: var(--surface);
|
|
10
|
+
}
|
|
11
|
+
.chat-head-main h1 { margin: 0; font-family: var(--font-serif); font-size: 19px; letter-spacing: .02em; }
|
|
12
|
+
.room-meta { margin: 2px 0 0; font-size: 12px; color: var(--ink-3); }
|
|
13
|
+
.mono { font-family: var(--font-mono); }
|
|
14
|
+
.copy-id {
|
|
15
|
+
appearance: none;
|
|
16
|
+
font: inherit;
|
|
17
|
+
font-size: 12px;
|
|
18
|
+
color: var(--ink-3);
|
|
19
|
+
background: none;
|
|
20
|
+
border: none;
|
|
21
|
+
border-bottom: 1px dashed var(--ink-3);
|
|
22
|
+
padding: 0 0 1px;
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
transition: color .12s, border-color .12s;
|
|
25
|
+
}
|
|
26
|
+
.copy-id:hover { color: var(--accent); border-color: var(--accent); }
|
|
27
|
+
.copy-id .copy-ok { display: none; }
|
|
28
|
+
.copy-id.copied .mono { display: none; }
|
|
29
|
+
.copy-id.copied .copy-ok { display: inline; color: var(--accent); }
|
|
30
|
+
|
|
31
|
+
.chat-head-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
|
|
32
|
+
.chip {
|
|
33
|
+
appearance: none;
|
|
34
|
+
font: inherit;
|
|
35
|
+
font-size: 13px;
|
|
36
|
+
font-weight: 600;
|
|
37
|
+
color: var(--ink-2);
|
|
38
|
+
background: var(--surface);
|
|
39
|
+
border: 1px solid var(--line);
|
|
40
|
+
border-radius: 999px;
|
|
41
|
+
padding: 7px 13px;
|
|
42
|
+
cursor: pointer;
|
|
43
|
+
transition: color .12s, border-color .12s, background .12s;
|
|
44
|
+
}
|
|
45
|
+
.chip:hover { color: var(--ink); border-color: var(--ink-3); }
|
|
46
|
+
.chip.danger { color: var(--danger); }
|
|
47
|
+
.chip.danger:hover { border-color: var(--danger); background: var(--danger-soft); }
|
|
48
|
+
|
|
49
|
+
.anchor { position: relative; }
|
|
50
|
+
.panel {
|
|
51
|
+
position: absolute;
|
|
52
|
+
top: calc(100% + 8px);
|
|
53
|
+
right: 0;
|
|
54
|
+
z-index: 20;
|
|
55
|
+
width: min(320px, calc(100vw - 32px));
|
|
56
|
+
padding: 16px;
|
|
57
|
+
background: var(--surface);
|
|
58
|
+
border: 1px solid var(--line);
|
|
59
|
+
border-radius: 14px;
|
|
60
|
+
box-shadow: var(--shadow);
|
|
61
|
+
animation: rise .18s ease both;
|
|
62
|
+
}
|
|
63
|
+
.panel h3 { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
|
|
64
|
+
.panel .btn { margin-top: 10px; }
|
|
65
|
+
#memberList { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
|
|
66
|
+
#memberList li {
|
|
67
|
+
display: flex;
|
|
68
|
+
justify-content: space-between;
|
|
69
|
+
align-items: baseline;
|
|
70
|
+
gap: 10px;
|
|
71
|
+
padding: 7px 0;
|
|
72
|
+
border-bottom: 1px solid var(--line);
|
|
73
|
+
font-size: 14px;
|
|
74
|
+
}
|
|
75
|
+
#memberList li:last-child { border-bottom: none; }
|
|
76
|
+
.m-time { font-size: 11.5px; color: var(--ink-3); }
|
|
77
|
+
|
|
78
|
+
.conn-bar {
|
|
79
|
+
display: flex;
|
|
80
|
+
align-items: center;
|
|
81
|
+
justify-content: center;
|
|
82
|
+
gap: 8px;
|
|
83
|
+
padding: 6px;
|
|
84
|
+
font-size: 12.5px;
|
|
85
|
+
color: var(--ink-2);
|
|
86
|
+
background: var(--surface-2);
|
|
87
|
+
border-bottom: 1px solid var(--line);
|
|
88
|
+
}
|
|
89
|
+
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
|
|
90
|
+
|
|
91
|
+
.msg-scroll {
|
|
92
|
+
flex: 1;
|
|
93
|
+
min-height: 0;
|
|
94
|
+
position: relative;
|
|
95
|
+
display: flex;
|
|
96
|
+
flex-direction: column;
|
|
97
|
+
}
|
|
98
|
+
.thread {
|
|
99
|
+
flex: 1;
|
|
100
|
+
min-height: 0;
|
|
101
|
+
overflow-y: auto;
|
|
102
|
+
overscroll-behavior: contain;
|
|
103
|
+
padding: 22px 22px 6px;
|
|
104
|
+
}
|
|
105
|
+
#msgList { list-style: none; margin: 0; padding: 0; }
|
|
106
|
+
|
|
107
|
+
.thread, #roomList, #memberList {
|
|
108
|
+
scrollbar-width: thin;
|
|
109
|
+
scrollbar-color: color-mix(in srgb, var(--ink-3) 40%, transparent) transparent;
|
|
110
|
+
}
|
|
111
|
+
.thread::-webkit-scrollbar, #roomList::-webkit-scrollbar, #memberList::-webkit-scrollbar { width: 8px; }
|
|
112
|
+
.thread::-webkit-scrollbar-thumb, #roomList::-webkit-scrollbar-thumb, #memberList::-webkit-scrollbar-thumb {
|
|
113
|
+
background: color-mix(in srgb, var(--ink-3) 40%, transparent);
|
|
114
|
+
border-radius: 4px;
|
|
115
|
+
}
|
|
116
|
+
.thread::-webkit-scrollbar-track { background: transparent; }
|
|
117
|
+
|
|
118
|
+
.jump {
|
|
119
|
+
position: absolute;
|
|
120
|
+
right: 20px;
|
|
121
|
+
bottom: 16px;
|
|
122
|
+
z-index: 5;
|
|
123
|
+
display: flex;
|
|
124
|
+
align-items: center;
|
|
125
|
+
gap: 6px;
|
|
126
|
+
padding: 9px 14px;
|
|
127
|
+
font: inherit;
|
|
128
|
+
font-size: 13px;
|
|
129
|
+
font-weight: 600;
|
|
130
|
+
color: var(--accent-ink);
|
|
131
|
+
background: var(--accent);
|
|
132
|
+
border: none;
|
|
133
|
+
border-radius: 999px;
|
|
134
|
+
cursor: pointer;
|
|
135
|
+
box-shadow: var(--shadow);
|
|
136
|
+
transition: filter .12s, transform .1s;
|
|
137
|
+
}
|
|
138
|
+
.jump:hover { filter: brightness(1.07); }
|
|
139
|
+
.jump:active { transform: translateY(1px); }
|
|
140
|
+
.jump .badge {
|
|
141
|
+
display: inline-flex;
|
|
142
|
+
align-items: center;
|
|
143
|
+
justify-content: center;
|
|
144
|
+
min-width: 18px;
|
|
145
|
+
height: 18px;
|
|
146
|
+
padding: 0 5px;
|
|
147
|
+
font-size: 11px;
|
|
148
|
+
font-weight: 700;
|
|
149
|
+
color: var(--accent);
|
|
150
|
+
background: var(--accent-ink);
|
|
151
|
+
border-radius: 999px;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.msg { display: flex; flex-direction: column; margin-bottom: 14px; }
|
|
155
|
+
.msg.in, .sys.in, .day-sep.in { animation: msg-in .25s ease both; }
|
|
156
|
+
.msg.own { align-items: flex-end; }
|
|
157
|
+
.msg.repeat { margin-bottom: 8px; }
|
|
158
|
+
.msg-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
|
|
159
|
+
.msg-name { font-size: 13px; font-weight: 600; color: var(--ink); }
|
|
160
|
+
.msg.own .msg-name { color: var(--accent); }
|
|
161
|
+
.msg.repeat .msg-name { display: none; }
|
|
162
|
+
.msg-time { font-size: 11.5px; color: var(--ink-3); }
|
|
163
|
+
.msg-text {
|
|
164
|
+
display: inline-block;
|
|
165
|
+
max-width: min(86%, 540px);
|
|
166
|
+
padding: 8px 12px;
|
|
167
|
+
border-radius: 14px;
|
|
168
|
+
background: var(--surface-2);
|
|
169
|
+
border-bottom-left-radius: 4px;
|
|
170
|
+
font-size: 15px;
|
|
171
|
+
line-height: 1.65;
|
|
172
|
+
white-space: normal;
|
|
173
|
+
overflow-wrap: anywhere;
|
|
174
|
+
}
|
|
175
|
+
.msg.own .msg-text { background: var(--accent-soft); border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
|
|
176
|
+
|
|
177
|
+
/* Markdown content */
|
|
178
|
+
.msg-text p, .msg-text pre, .msg-text blockquote, .msg-text ul, .msg-text ol { margin: 0; }
|
|
179
|
+
.msg-text > :not(:first-child) { margin-top: 8px; }
|
|
180
|
+
.msg-text ul, .msg-text ol { padding-left: 22px; }
|
|
181
|
+
.msg-text li { margin: 2px 0; }
|
|
182
|
+
.msg-text blockquote {
|
|
183
|
+
padding: 1px 0 1px 12px;
|
|
184
|
+
border-left: 3px solid var(--ink-3);
|
|
185
|
+
color: var(--ink-2);
|
|
186
|
+
}
|
|
187
|
+
.msg-text code {
|
|
188
|
+
font-family: var(--font-mono);
|
|
189
|
+
font-size: .9em;
|
|
190
|
+
background: color-mix(in srgb, var(--ink) 8%, transparent);
|
|
191
|
+
border: 1px solid color-mix(in srgb, var(--ink) 14%, transparent);
|
|
192
|
+
border-radius: 5px;
|
|
193
|
+
padding: 0 4px;
|
|
194
|
+
}
|
|
195
|
+
.msg-text pre {
|
|
196
|
+
overflow-x: auto; /* Keep long code lines scrollable without wrapping. */
|
|
197
|
+
padding: 10px 12px;
|
|
198
|
+
border: 1px solid var(--line);
|
|
199
|
+
border-radius: 8px;
|
|
200
|
+
background: color-mix(in srgb, var(--ink) 5%, transparent);
|
|
201
|
+
font-size: 13.5px;
|
|
202
|
+
line-height: 1.55;
|
|
203
|
+
}
|
|
204
|
+
.msg-text pre code {
|
|
205
|
+
display: block;
|
|
206
|
+
background: none;
|
|
207
|
+
border: none;
|
|
208
|
+
padding: 0;
|
|
209
|
+
font-size: inherit;
|
|
210
|
+
white-space: pre;
|
|
211
|
+
}
|
|
212
|
+
.msg-text a {
|
|
213
|
+
color: var(--mention-blue);
|
|
214
|
+
text-decoration: underline;
|
|
215
|
+
text-underline-offset: 2px;
|
|
216
|
+
}
|
|
217
|
+
.msg-text a:hover { text-decoration: none; }
|
|
218
|
+
|
|
219
|
+
/* Mention picker */
|
|
220
|
+
/* Inactive names stay quiet; current members use the accent color. */
|
|
221
|
+
.mention-chip {
|
|
222
|
+
display: inline-block;
|
|
223
|
+
margin: 0 1px;
|
|
224
|
+
padding: 2px 7px;
|
|
225
|
+
max-width: 100%;
|
|
226
|
+
overflow: hidden;
|
|
227
|
+
text-overflow: ellipsis;
|
|
228
|
+
white-space: nowrap;
|
|
229
|
+
/* Align pills to mixed Latin and CJK text without growing the line box. */
|
|
230
|
+
vertical-align: middle;
|
|
231
|
+
line-height: 1;
|
|
232
|
+
font-size: .92em;
|
|
233
|
+
font-weight: 600;
|
|
234
|
+
color: var(--ink-2);
|
|
235
|
+
background: color-mix(in srgb, var(--ink-2) 12%, transparent);
|
|
236
|
+
border: 1px solid color-mix(in srgb, var(--ink-2) 26%, transparent);
|
|
237
|
+
border-radius: 999px;
|
|
238
|
+
}
|
|
239
|
+
.mention-chip.member {
|
|
240
|
+
color: var(--mention-blue);
|
|
241
|
+
background: color-mix(in srgb, var(--mention-blue) 14%, transparent);
|
|
242
|
+
border: 1px solid color-mix(in srgb, var(--mention-blue) 32%, transparent);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.mention-picker {
|
|
246
|
+
position: absolute;
|
|
247
|
+
left: 16px;
|
|
248
|
+
right: 16px;
|
|
249
|
+
bottom: calc(100% + 8px);
|
|
250
|
+
z-index: 30;
|
|
251
|
+
max-height: 224px;
|
|
252
|
+
overflow-y: auto;
|
|
253
|
+
padding: 6px;
|
|
254
|
+
background: var(--surface);
|
|
255
|
+
border: 1px solid var(--line);
|
|
256
|
+
border-radius: 12px;
|
|
257
|
+
box-shadow: var(--shadow);
|
|
258
|
+
animation: rise .15s ease both;
|
|
259
|
+
}
|
|
260
|
+
.mention-picker ul { list-style: none; margin: 0; padding: 0; position: relative; }
|
|
261
|
+
.mention-opt {
|
|
262
|
+
padding: 7px 10px;
|
|
263
|
+
border-radius: 8px;
|
|
264
|
+
font-size: 14px;
|
|
265
|
+
color: var(--ink);
|
|
266
|
+
cursor: pointer;
|
|
267
|
+
white-space: nowrap;
|
|
268
|
+
overflow: hidden;
|
|
269
|
+
text-overflow: ellipsis;
|
|
270
|
+
}
|
|
271
|
+
.mention-opt:hover { background: var(--surface-2); }
|
|
272
|
+
.mention-opt.active { background: var(--accent-soft); color: var(--accent); }
|
|
273
|
+
.mention-at { font-weight: 600; color: var(--accent); margin-right: 4px; }
|
|
274
|
+
.mention-hit { background: color-mix(in srgb, var(--accent) 25%, transparent); border-radius: 3px; }
|
|
275
|
+
.mention-empty { margin: 0; padding: 12px 8px; font-size: 13px; color: var(--ink-3); text-align: center; }
|
|
276
|
+
.mention-hint {
|
|
277
|
+
margin: 6px 0 2px;
|
|
278
|
+
padding: 7px 8px 0;
|
|
279
|
+
border-top: 1px solid var(--line);
|
|
280
|
+
font-size: 11.5px;
|
|
281
|
+
color: var(--ink-3);
|
|
282
|
+
text-align: center;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
.sys {
|
|
286
|
+
display: flex;
|
|
287
|
+
align-items: center;
|
|
288
|
+
gap: 12px;
|
|
289
|
+
margin: 20px 0;
|
|
290
|
+
font-size: 12.5px;
|
|
291
|
+
color: var(--ink-2);
|
|
292
|
+
}
|
|
293
|
+
.sys::before, .sys::after { content: ""; flex: 1; height: 1px; background: var(--line); }
|
|
294
|
+
.sys span { flex-shrink: 0; }
|
|
295
|
+
|
|
296
|
+
.day-sep {
|
|
297
|
+
display: flex;
|
|
298
|
+
align-items: center;
|
|
299
|
+
gap: 12px;
|
|
300
|
+
margin: 26px 0 16px;
|
|
301
|
+
font-size: 12px;
|
|
302
|
+
font-weight: 600;
|
|
303
|
+
letter-spacing: .08em;
|
|
304
|
+
color: var(--ink-2);
|
|
305
|
+
}
|
|
306
|
+
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
|
|
307
|
+
|
|
308
|
+
.gap { padding: 6px 0 2px; text-align: center; font-size: 12px; color: var(--ink-3); }
|
|
309
|
+
|
|
310
|
+
.chat-empty { padding: 56px 0 40px; text-align: center; font-size: 13px; color: var(--ink-3); }
|
|
311
|
+
.chat-empty::before {
|
|
312
|
+
content: "";
|
|
313
|
+
display: block;
|
|
314
|
+
width: 56px;
|
|
315
|
+
height: 56px;
|
|
316
|
+
margin: 0 auto 14px;
|
|
317
|
+
border: 1.5px dashed var(--line);
|
|
318
|
+
border-radius: 50%;
|
|
319
|
+
background: radial-gradient(circle at 50% 50%, var(--ink-3) 0 3px, transparent 4px);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
.composer {
|
|
323
|
+
position: relative;
|
|
324
|
+
display: flex;
|
|
325
|
+
flex-direction: column;
|
|
326
|
+
gap: 8px;
|
|
327
|
+
padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
|
|
328
|
+
border-top: 1px solid var(--line);
|
|
329
|
+
background: var(--surface);
|
|
330
|
+
}
|
|
331
|
+
.composer-row { display: flex; gap: 10px; align-items: flex-end; }
|
|
332
|
+
.composer .input { flex: 1; }
|
|
333
|
+
.composer .input:disabled { opacity: .5; }
|
|
334
|
+
#msgInput {
|
|
335
|
+
min-height: 46px;
|
|
336
|
+
max-height: 132px;
|
|
337
|
+
padding: 12px 13px;
|
|
338
|
+
line-height: 1.5;
|
|
339
|
+
resize: none;
|
|
340
|
+
overflow-y: auto;
|
|
341
|
+
}
|
|
342
|
+
#btnSend { padding: 12px 22px; }
|
|
343
|
+
.send-error { margin: 0; font-size: 12.5px; color: var(--danger); }
|
|
344
|
+
.draft-count { width: min(940px, 100%); margin: -3px auto 0; color: var(--ink-3); text-align: right; font-size: 11px; font-variant-numeric: tabular-nums; }
|
|
345
|
+
.failed-messages { max-height: 150px; overflow-y: auto; padding: 8px 10px; border: 1px solid var(--danger-soft); border-radius: 10px; background: var(--danger-soft); }
|
|
346
|
+
.failed-messages h3 { margin: 0 0 5px; color: var(--danger); font-size: 12px; }
|
|
347
|
+
.failed-message { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-top: 1px solid var(--line); }
|
|
348
|
+
.failed-message p { flex: 1; min-width: 0; max-height: 48px; overflow: auto; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }
|
|
349
|
+
.failed-message button { flex: none; border: 1px solid var(--line); border-radius: 7px; padding: 4px 8px; background: var(--surface); color: var(--ink-2); font: inherit; font-size: 12px; cursor: pointer; }
|
|
350
|
+
.failed-message button:disabled { opacity: .5; cursor: default; }
|