@alexsun-top/opencode-chat-room 0.3.3 → 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 +27 -0
- package/README.md +44 -11
- package/README.zh-CN.md +40 -10
- package/package.json +4 -1
- package/plugin.ts +26 -10
- 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 +43 -27
- package/server/assets/chat/announcements.js +119 -0
- package/server/assets/chat/events.js +180 -6
- package/server/assets/chat/index.js +6 -0
- package/server/assets/chat/markdown.js +214 -11
- package/server/assets/chat/members.js +4 -1
- package/server/assets/chat/messages.js +57 -77
- package/server/assets/chat/questions.js +204 -0
- package/server/assets/chat/receipts.js +117 -0
- package/server/assets/chat/rooms.js +11 -6
- package/server/assets/chat/state.js +64 -18
- package/server/assets/conversation.css +58 -17
- package/server/assets/mermaid-11.12.2.min.js +2811 -0
- package/server/assets/responsive.css +47 -23
- package/server/chat-server.ts +41 -12
- package/server/chat.html +51 -10
- 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 +32 -2
- 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/room-service.ts +5 -0
- package/src/sqlite-state.ts +83 -13
- package/src/store.ts +4 -11
- package/src/v1-plugin.ts +6 -1
- package/src/v2-plugin.ts +39 -8
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { LS } from "./state.js";
|
|
2
|
+
|
|
3
|
+
export function initAnnouncements(app) {
|
|
4
|
+
const $ = app.$, drafts = new Map();
|
|
5
|
+
const panel = $("#announcementPanel"), trigger = $("#btnAnnouncements"), list = $("#announcementList");
|
|
6
|
+
let items = [], selected = "", generation = 0, roomGeneration = 0, editorRevision = 0, saveToken = 0;
|
|
7
|
+
const key = (id, name = selected) => `${id}\0${name ? `item\0${name}` : "new"}`;
|
|
8
|
+
const roomId = () => app.state.room?.id;
|
|
9
|
+
const currentRoom = (id, request) => roomId() === id && roomGeneration === request;
|
|
10
|
+
const draft = (id, name = selected) => drafts.get(key(id, name));
|
|
11
|
+
function storeDraft(id = roomId(), name = selected) {
|
|
12
|
+
if (id) drafts.set(key(id, name), { name: name || $("#announcementName").value, content: $("#announcementContent").value });
|
|
13
|
+
}
|
|
14
|
+
function editorSnapshot() {
|
|
15
|
+
return { selected, revision: editorRevision, name: $("#announcementName").value, content: $("#announcementContent").value };
|
|
16
|
+
}
|
|
17
|
+
const editorMatches = (snapshot) => selected === snapshot.selected && editorRevision === snapshot.revision;
|
|
18
|
+
function clearDraftIfUnchanged(id, name, snapshot) {
|
|
19
|
+
const saved = draft(id, name);
|
|
20
|
+
if (saved?.name === snapshot.name && saved.content === snapshot.content) drafts.delete(key(id, name));
|
|
21
|
+
}
|
|
22
|
+
function status(text) { $("#announcementStatus").textContent = text; }
|
|
23
|
+
function count() { $("#announcementCount").textContent = app.t("announcementCount", { count: Array.from($("#announcementContent").value).length }); }
|
|
24
|
+
function render() {
|
|
25
|
+
list.textContent = "";
|
|
26
|
+
for (const entry of items) {
|
|
27
|
+
const li = document.createElement("li"), button = document.createElement("button");
|
|
28
|
+
button.type = "button"; button.textContent = entry.name;
|
|
29
|
+
if (entry.name === selected) button.setAttribute("aria-current", "true");
|
|
30
|
+
button.addEventListener("click", (event) => { event.stopPropagation(); select(entry); });
|
|
31
|
+
li.append(button); list.append(li);
|
|
32
|
+
}
|
|
33
|
+
if (!items.length) status(app.t("announcementEmpty"));
|
|
34
|
+
}
|
|
35
|
+
function select(entry) {
|
|
36
|
+
const id = roomId(); if (!id) return;
|
|
37
|
+
const next = entry?.name || "";
|
|
38
|
+
if (next !== selected) editorRevision++;
|
|
39
|
+
selected = next;
|
|
40
|
+
const name = $("#announcementName"), content = $("#announcementContent");
|
|
41
|
+
name.value = selected; name.readOnly = Boolean(selected);
|
|
42
|
+
const saved = draft(id);
|
|
43
|
+
name.value = selected || saved?.name || "";
|
|
44
|
+
content.value = saved?.content ?? entry?.content ?? "";
|
|
45
|
+
$("#btnDeleteAnnouncement").hidden = !selected;
|
|
46
|
+
render(); count();
|
|
47
|
+
}
|
|
48
|
+
async function load(id = roomId()) {
|
|
49
|
+
if (!id) return;
|
|
50
|
+
const request = ++generation, context = roomGeneration; status(app.t("announcementLoading"));
|
|
51
|
+
try {
|
|
52
|
+
const result = await app.api(`/rooms/${encodeURIComponent(id)}/announcements`);
|
|
53
|
+
if (roomId() !== id || context !== roomGeneration || generation !== request) return;
|
|
54
|
+
items = Array.isArray(result.announcements) ? result.announcements : [];
|
|
55
|
+
status("");
|
|
56
|
+
const chosen = items.find((item) => item.name === selected);
|
|
57
|
+
if (!chosen) select(null); else select(chosen);
|
|
58
|
+
render();
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (roomId() !== id || context !== roomGeneration || generation !== request) return;
|
|
61
|
+
status(app.t("announcementLoadFailed"));
|
|
62
|
+
if (error.status === 401) app.openChatSettings();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
$("#announcementContent").addEventListener("input", () => {
|
|
66
|
+
editorRevision++; count(); storeDraft();
|
|
67
|
+
});
|
|
68
|
+
$("#announcementName").addEventListener("input", () => {
|
|
69
|
+
editorRevision++; storeDraft();
|
|
70
|
+
});
|
|
71
|
+
$("#announcementForm").addEventListener("submit", async (event) => {
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
const id = roomId(), name = $("#announcementName").value.trim(), content = $("#announcementContent").value;
|
|
74
|
+
if (!id || !name || Array.from(name).length > 64 || Array.from(content).length > 5000) return status(app.t("announcementInvalid"));
|
|
75
|
+
if (!selected && items.some((item) => item.name === name)) return status(app.t("announcementDuplicate"));
|
|
76
|
+
const context = roomGeneration, captured = editorSnapshot(), draftName = selected, button = $("#btnSaveAnnouncement"), token = ++saveToken;
|
|
77
|
+
storeDraft(id, draftName); button.disabled = true;
|
|
78
|
+
try {
|
|
79
|
+
const result = await app.api(`/rooms/${encodeURIComponent(id)}/announcements/${encodeURIComponent(name)}`, {
|
|
80
|
+
method: "PUT", body: JSON.stringify({ sessionID: LS.sessionID, content }),
|
|
81
|
+
});
|
|
82
|
+
if (currentRoom(id, context)) {
|
|
83
|
+
generation++; items = [...items.filter((item) => item.name !== name), result.announcement]; render();
|
|
84
|
+
clearDraftIfUnchanged(id, draftName, captured);
|
|
85
|
+
if (editorMatches(captured)) { select(result.announcement); status(app.t("announcementSaved")); }
|
|
86
|
+
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (currentRoom(id, context) && editorMatches(captured)) status(error.status === 403 ? error.message : app.t("announcementLoadFailed"));
|
|
89
|
+
}
|
|
90
|
+
finally { if (token === saveToken) button.disabled = false; }
|
|
91
|
+
});
|
|
92
|
+
$("#btnNewAnnouncement").addEventListener("click", () => { select(null); $("#announcementName").focus(); });
|
|
93
|
+
$("#btnDeleteAnnouncement").addEventListener("click", async () => {
|
|
94
|
+
const id = roomId(), name = selected;
|
|
95
|
+
if (!id || !name || !confirm(app.t("announcementDeleteConfirm", { name }))) return;
|
|
96
|
+
const context = roomGeneration, captured = editorSnapshot();
|
|
97
|
+
try {
|
|
98
|
+
await app.api(`/rooms/${encodeURIComponent(id)}/announcements/${encodeURIComponent(name)}`, { method: "DELETE", body: JSON.stringify({ sessionID: LS.sessionID }) });
|
|
99
|
+
if (currentRoom(id, context)) {
|
|
100
|
+
generation++; items = items.filter((item) => item.name !== name); render();
|
|
101
|
+
clearDraftIfUnchanged(id, name, captured);
|
|
102
|
+
if (editorMatches(captured)) { select(null); status(app.t("announcementDeleted")); }
|
|
103
|
+
}
|
|
104
|
+
} catch (error) { if (currentRoom(id, context) && editorMatches(captured)) status(error.message); }
|
|
105
|
+
});
|
|
106
|
+
$("#btnRefreshAnnouncements").addEventListener("click", () => void load());
|
|
107
|
+
trigger.addEventListener("click", () => {
|
|
108
|
+
const open = panel.hidden; app.closePanels(); panel.hidden = !open;
|
|
109
|
+
trigger.setAttribute("aria-expanded", String(open)); if (open) { void load(); $("#announcementHeading").focus(); }
|
|
110
|
+
});
|
|
111
|
+
document.addEventListener("keydown", (event) => { if (event.key === "Escape" && !panel.hidden) { app.closePanels(); trigger.focus(); } });
|
|
112
|
+
const close = app.closePanels;
|
|
113
|
+
app.closePanels = () => { close(); panel.hidden = true; trigger.setAttribute("aria-expanded", "false"); };
|
|
114
|
+
document.addEventListener("chat-room-activated", (event) => {
|
|
115
|
+
const id = event.detail;
|
|
116
|
+
roomGeneration++; generation++; saveToken++; $("#btnSaveAnnouncement").disabled = false;
|
|
117
|
+
selected = ""; items = []; select(null); void load(id);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
@@ -3,6 +3,137 @@ import { copyCodeFromButton, copyTextToClipboard } from "./markdown.js";
|
|
|
3
3
|
|
|
4
4
|
export function initEvents(app) {
|
|
5
5
|
const $ = app.$;
|
|
6
|
+
const roomRail = $("#roomRail"), drawerTrigger = $("#btnRoomsDrawer"), backdrop = $("#roomDrawerBackdrop");
|
|
7
|
+
const smallScreen = () => matchMedia("(max-width: 760px)").matches;
|
|
8
|
+
let readingPosition = null, resizeFrame = 0, resizeGeneration = 0, scrollGeneration = 0, resizeResetTimer = 0;
|
|
9
|
+
function captureReadingPosition() {
|
|
10
|
+
const thread = $("#thread"), edge = thread.getBoundingClientRect(), top = edge.top + thread.clientTop;
|
|
11
|
+
const anchor = [...$("#msgList").querySelectorAll("[data-msg-id]")].find((row) => row.getBoundingClientRect().bottom > top);
|
|
12
|
+
readingPosition = { roomId: app.state.room?.id, messageId: anchor?.dataset.msgId, offset: anchor ? anchor.getBoundingClientRect().top - top : 0,
|
|
13
|
+
atBottom: thread.scrollHeight - thread.scrollTop - thread.clientHeight <= 4 };
|
|
14
|
+
const missing = app.state.readAnchorGuard?.roomId === readingPosition.roomId && app.state.readAnchorGuard.missing;
|
|
15
|
+
if (readingPosition.roomId && anchor && (!missing || performance.now() <= app.state.userScrollIntentUntil)) {
|
|
16
|
+
app.savePosition(readingPosition.roomId, { messageId: readingPosition.messageId, offset: readingPosition.offset });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
app.captureReadingPosition = captureReadingPosition;
|
|
20
|
+
let layoutQueue = Promise.resolve();
|
|
21
|
+
app.preserveReadingLayout = (change) => {
|
|
22
|
+
const task = layoutQueue.then(async () => {
|
|
23
|
+
captureReadingPosition();
|
|
24
|
+
const saved = readingPosition, roomId = app.state.room?.id, generation = scrollGeneration;
|
|
25
|
+
app.state.layoutScrollAdjusting = true;
|
|
26
|
+
try {
|
|
27
|
+
await change();
|
|
28
|
+
await new Promise((resolve) => requestAnimationFrame(resolve));
|
|
29
|
+
if (roomId && app.state.room?.id === roomId && generation === scrollGeneration) {
|
|
30
|
+
const thread = $("#thread");
|
|
31
|
+
if (saved.atBottom) thread.scrollTop = thread.scrollHeight;
|
|
32
|
+
else if (saved.messageId) {
|
|
33
|
+
const row = [...$("#msgList").querySelectorAll("[data-msg-id]")].find((item) => item.dataset.msgId === saved.messageId);
|
|
34
|
+
if (row) thread.scrollTop += row.getBoundingClientRect().top - (thread.getBoundingClientRect().top + thread.clientTop + saved.offset);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
captureReadingPosition();
|
|
38
|
+
} finally { requestAnimationFrame(() => { app.state.layoutScrollAdjusting = false; }); }
|
|
39
|
+
});
|
|
40
|
+
layoutQueue = task.catch(() => {});
|
|
41
|
+
return task;
|
|
42
|
+
};
|
|
43
|
+
app.restoreReadingPosition = (roomId) => {
|
|
44
|
+
const thread = $("#thread"), saved = app.state.positions.get(roomId), entry = app.state.rooms.get(roomId);
|
|
45
|
+
const align = (messageId, offset) => {
|
|
46
|
+
const row = [...$("#msgList").querySelectorAll("[data-msg-id]")].find((item) => item.dataset.msgId === messageId);
|
|
47
|
+
if (!row) return false;
|
|
48
|
+
thread.scrollTop += row.getBoundingClientRect().top - (thread.getBoundingClientRect().top + thread.clientTop + offset);
|
|
49
|
+
captureReadingPosition(); return true;
|
|
50
|
+
};
|
|
51
|
+
if (typeof saved === "number") { thread.scrollTop = saved; captureReadingPosition(); return { messageId: readingPosition?.messageId }; }
|
|
52
|
+
if (saved?.messageId && align(saved.messageId, Number(saved.offset) || 0)) return { messageId: saved.messageId };
|
|
53
|
+
const readTs = entry?.readTs || app.state.lastReadTs.get(roomId) || 0;
|
|
54
|
+
const boundary = readTs && entry?.room.messages.find((message) => message.createdAt > readTs);
|
|
55
|
+
if (boundary && align(boundary.id, 0)) return { messageId: boundary.id };
|
|
56
|
+
return saved?.messageId || readTs ? { messageId: saved?.messageId || null, missing: true } : false;
|
|
57
|
+
};
|
|
58
|
+
function closeRoomDrawer(restore = true) {
|
|
59
|
+
roomRail.classList.remove("drawer-open"); roomRail.inert = true; roomRail.setAttribute("aria-hidden", "true");
|
|
60
|
+
backdrop.hidden = true; drawerTrigger.setAttribute("aria-expanded", "false");
|
|
61
|
+
if (restore && smallScreen()) drawerTrigger.focus({ preventScroll: true });
|
|
62
|
+
}
|
|
63
|
+
function syncRoomDrawer() {
|
|
64
|
+
if (!smallScreen()) { roomRail.classList.remove("drawer-open"); roomRail.inert = false; roomRail.removeAttribute("aria-hidden"); backdrop.hidden = true; drawerTrigger.setAttribute("aria-expanded", "false"); }
|
|
65
|
+
else if (!roomRail.classList.contains("drawer-open")) {
|
|
66
|
+
if (roomRail.contains(document.activeElement)) drawerTrigger.focus({ preventScroll: true });
|
|
67
|
+
roomRail.inert = true; roomRail.setAttribute("aria-hidden", "true");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function preserveReadingPosition() {
|
|
71
|
+
syncRoomDrawer();
|
|
72
|
+
if (!app.state.resizeScrollAdjusting) app.state.userScrollIntentUntil = 0;
|
|
73
|
+
app.state.resizeScrollAdjusting = true;
|
|
74
|
+
const generation = ++resizeGeneration;
|
|
75
|
+
if (app.state.receiptObservationFrame) cancelAnimationFrame(app.state.receiptObservationFrame);
|
|
76
|
+
app.state.receiptObservationFrame = 0; app.state.receiptObservation = null;
|
|
77
|
+
clearTimeout(resizeResetTimer);
|
|
78
|
+
resizeResetTimer = setTimeout(() => { if (generation === resizeGeneration) app.state.resizeScrollAdjusting = false; }, 500);
|
|
79
|
+
if (resizeFrame) cancelAnimationFrame(resizeFrame);
|
|
80
|
+
resizeFrame = requestAnimationFrame(() => {
|
|
81
|
+
resizeFrame = 0;
|
|
82
|
+
const position = readingPosition, thread = $("#thread");
|
|
83
|
+
if (!position?.roomId || position.roomId !== app.state.room?.id) return captureReadingPosition();
|
|
84
|
+
if (position.atBottom) thread.scrollTop = thread.scrollHeight;
|
|
85
|
+
else if (position.messageId) {
|
|
86
|
+
const row = [...$("#msgList").querySelectorAll("[data-msg-id]")].find((item) => item.dataset.msgId === position.messageId);
|
|
87
|
+
if (row) thread.scrollTop += row.getBoundingClientRect().top - (thread.getBoundingClientRect().top + thread.clientTop + position.offset);
|
|
88
|
+
}
|
|
89
|
+
captureReadingPosition();
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
syncRoomDrawer();
|
|
93
|
+
window.addEventListener("resize", preserveReadingPosition);
|
|
94
|
+
window.addEventListener("pagehide", captureReadingPosition);
|
|
95
|
+
drawerTrigger.addEventListener("click", () => {
|
|
96
|
+
if (roomRail.classList.contains("drawer-open")) return closeRoomDrawer();
|
|
97
|
+
app.closePanels(); roomRail.inert = false; roomRail.removeAttribute("aria-hidden"); roomRail.classList.add("drawer-open");
|
|
98
|
+
backdrop.hidden = false; drawerTrigger.setAttribute("aria-expanded", "true");
|
|
99
|
+
(roomRail.querySelector('.room-row[aria-current="page"]') || $("#btnRefreshRooms")).focus();
|
|
100
|
+
});
|
|
101
|
+
backdrop.addEventListener("click", () => closeRoomDrawer());
|
|
102
|
+
$("#roomListChat").addEventListener("click", (event) => { if (roomRail.classList.contains("drawer-open") && event.target.closest("[data-room-id]")) closeRoomDrawer(); });
|
|
103
|
+
const activateRoom = app.activateRoom;
|
|
104
|
+
const pendingAnchorLoads = new Map();
|
|
105
|
+
function cancelAnchorLoads() {
|
|
106
|
+
for (const { controller } of pendingAnchorLoads.values()) controller.abort();
|
|
107
|
+
pendingAnchorLoads.clear();
|
|
108
|
+
}
|
|
109
|
+
const showJoin = app.showJoin;
|
|
110
|
+
app.showJoin = (...args) => { cancelAnchorLoads(); return showJoin(...args); };
|
|
111
|
+
const removeJoinedRoom = app.removeJoinedRoom;
|
|
112
|
+
app.removeJoinedRoom = (roomId, options) => {
|
|
113
|
+
if (app.state.room?.id === roomId) cancelAnchorLoads();
|
|
114
|
+
return removeJoinedRoom(roomId, options);
|
|
115
|
+
};
|
|
116
|
+
function activateNow(id) {
|
|
117
|
+
activateRoom(id); captureReadingPosition();
|
|
118
|
+
if (roomRail.classList.contains("drawer-open")) closeRoomDrawer();
|
|
119
|
+
}
|
|
120
|
+
app.activateRoom = (id) => {
|
|
121
|
+
cancelAnchorLoads();
|
|
122
|
+
const entry = app.state.rooms.get(id), saved = app.state.positions.get(id);
|
|
123
|
+
const intent = ++app.state.navigationGeneration;
|
|
124
|
+
if (!entry) return activateNow(id);
|
|
125
|
+
const readTs = entry.readTs || app.state.lastReadTs.get(id) || 0;
|
|
126
|
+
const needAnchor = saved?.messageId && !entry.room.messages.some((message) => message.id === saved.messageId);
|
|
127
|
+
const latest = entry.room.messages.at(-1);
|
|
128
|
+
const needBoundary = !saved?.messageId && readTs && (!latest || latest.createdAt > readTs && !entry.room.messages.some((message) => message.createdAt <= readTs));
|
|
129
|
+
if (!needAnchor && !needBoundary) return activateNow(id);
|
|
130
|
+
const controller = new AbortController();
|
|
131
|
+
const task = loadAnchorHistory(id, entry, saved?.messageId, app, needBoundary ? readTs : 0, controller.signal).catch(() => {}).finally(() => {
|
|
132
|
+
if (pendingAnchorLoads.get(id)?.controller === controller) pendingAnchorLoads.delete(id);
|
|
133
|
+
if (intent === app.state.navigationGeneration) activateNow(id);
|
|
134
|
+
});
|
|
135
|
+
pendingAnchorLoads.set(id, { controller, task });
|
|
136
|
+
};
|
|
6
137
|
document.querySelectorAll(".locale-select").forEach((select) => {
|
|
7
138
|
select.addEventListener("change", () => {
|
|
8
139
|
app.setLocale(select.value);
|
|
@@ -36,6 +167,7 @@ export function initEvents(app) {
|
|
|
36
167
|
$("#inRoomNameChat").addEventListener("input", app.hideSendError);
|
|
37
168
|
|
|
38
169
|
const input = $("#msgInput");
|
|
170
|
+
window.addEventListener("resize", () => app.autoGrow(input));
|
|
39
171
|
$(".composer").addEventListener("click", (event) => {
|
|
40
172
|
const button = event.target.closest?.("[data-failed-action]");
|
|
41
173
|
if (!button) return;
|
|
@@ -66,17 +198,32 @@ export function initEvents(app) {
|
|
|
66
198
|
event.preventDefault();
|
|
67
199
|
app.insertMention(option.dataset.name);
|
|
68
200
|
});
|
|
69
|
-
$("#thread")
|
|
70
|
-
|
|
71
|
-
|
|
201
|
+
const thread = $("#thread");
|
|
202
|
+
const markScrollIntent = () => { scrollGeneration++; app.state.userScrollIntentUntil = performance.now() + 700; };
|
|
203
|
+
thread.addEventListener("wheel", markScrollIntent, { passive: true });
|
|
204
|
+
thread.addEventListener("touchmove", markScrollIntent, { passive: true });
|
|
205
|
+
thread.addEventListener("pointerdown", (event) => {
|
|
206
|
+
if (event.clientX >= thread.getBoundingClientRect().right - 18) markScrollIntent();
|
|
207
|
+
});
|
|
208
|
+
thread.addEventListener("scroll", () => {
|
|
209
|
+
const adjusting = (app.state.resizeScrollAdjusting || app.state.layoutScrollAdjusting)
|
|
210
|
+
&& performance.now() > app.state.userScrollIntentUntil;
|
|
211
|
+
if (!adjusting || performance.now() <= app.state.userScrollIntentUntil) captureReadingPosition();
|
|
212
|
+
if (!adjusting && thread.scrollHeight - thread.scrollTop - thread.clientHeight < 80) void app.markActiveRoomRead();
|
|
72
213
|
app.queueReceiptRefresh();
|
|
73
|
-
app.queueReceiptObservation();
|
|
214
|
+
if (!adjusting) app.queueReceiptObservation();
|
|
74
215
|
app.updateJump();
|
|
75
216
|
});
|
|
76
217
|
document.addEventListener("visibilitychange", () => {
|
|
77
|
-
if (!document.hidden) {
|
|
218
|
+
if (!document.hidden) {
|
|
219
|
+
if (!app.state.resizeScrollAdjusting && !app.state.layoutScrollAdjusting) void app.markActiveRoomRead();
|
|
220
|
+
void app.loadManageableMembers();
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
window.addEventListener("focus", () => {
|
|
224
|
+
if (!app.state.resizeScrollAdjusting && !app.state.layoutScrollAdjusting) { void app.markActiveRoomRead(); app.queueReceiptObservation(); }
|
|
225
|
+
app.queueReceiptRefresh();
|
|
78
226
|
});
|
|
79
|
-
window.addEventListener("focus", () => { void app.markActiveRoomRead(); app.queueReceiptRefresh(); app.queueReceiptObservation(); });
|
|
80
227
|
$("#msgList").addEventListener("click", (event) => {
|
|
81
228
|
const button = event.target.closest("[data-copy-code]");
|
|
82
229
|
if (button) void copyCodeFromButton(button, app);
|
|
@@ -106,6 +253,14 @@ export function initEvents(app) {
|
|
|
106
253
|
if (!event.target.closest("#railRoomForm, #btnNewRoom")) $("#railRoomForm").hidden = true;
|
|
107
254
|
});
|
|
108
255
|
document.addEventListener("keydown", (event) => {
|
|
256
|
+
if (event.key === "Tab" && roomRail.classList.contains("drawer-open")) {
|
|
257
|
+
const stops = [...roomRail.querySelectorAll("button:not(:disabled), input:not(:disabled)")].filter((node) => node.getClientRects().length);
|
|
258
|
+
const first = stops[0], last = stops.at(-1);
|
|
259
|
+
if (!roomRail.contains(document.activeElement)) { event.preventDefault(); first?.focus(); }
|
|
260
|
+
else if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last?.focus(); }
|
|
261
|
+
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first?.focus(); }
|
|
262
|
+
}
|
|
263
|
+
if (event.key === "Escape" && roomRail.classList.contains("drawer-open")) { event.preventDefault(); closeRoomDrawer(); return; }
|
|
109
264
|
if (event.key === "Escape" && app.mentionActive) app.closeMention();
|
|
110
265
|
if (event.key === "Escape" && !$("#railRoomForm").hidden) $("#railRoomForm").hidden = true;
|
|
111
266
|
if (event.key === "Escape" && (!$("#memberPanel").hidden || !$("#chatSettings").hidden)) {
|
|
@@ -121,6 +276,25 @@ export function initEvents(app) {
|
|
|
121
276
|
$("#inRoomId").focus();
|
|
122
277
|
}
|
|
123
278
|
|
|
279
|
+
async function loadAnchorHistory(roomId, entry, messageId, app, readTs = 0, signal) {
|
|
280
|
+
let beforeSeq;
|
|
281
|
+
const messages = [];
|
|
282
|
+
while (!signal?.aborted) {
|
|
283
|
+
const query = new URLSearchParams({ limit: "100" });
|
|
284
|
+
if (beforeSeq) query.set("beforeSeq", String(beforeSeq));
|
|
285
|
+
const result = await app.api(`/rooms/${encodeURIComponent(roomId)}/history?${query}`, { signal });
|
|
286
|
+
if (signal?.aborted) return;
|
|
287
|
+
messages.push(...(result.messages || []));
|
|
288
|
+
const found = messageId ? messages.some((message) => message.id === messageId)
|
|
289
|
+
: messages.some((message) => message.createdAt > readTs) && messages.some((message) => message.createdAt <= readTs);
|
|
290
|
+
if (found || !result.hasMore || !result.nextBeforeSeq || result.nextBeforeSeq === beforeSeq) break;
|
|
291
|
+
beforeSeq = result.nextBeforeSeq;
|
|
292
|
+
}
|
|
293
|
+
if (messageId ? !messages.some((message) => message.id === messageId) : !messages.some((message) => message.createdAt > readTs)) return;
|
|
294
|
+
const merged = new Map([...entry.room.messages, ...messages].map((message) => [message.id, { ...message, roomId }]));
|
|
295
|
+
entry.room.messages = [...merged.values()].sort((left, right) => left.createdAt - right.createdAt);
|
|
296
|
+
}
|
|
297
|
+
|
|
124
298
|
function saveAccessToken(button, app) {
|
|
125
299
|
const input = document.getElementById(button.dataset.tokenSave);
|
|
126
300
|
input.value = app.setToken(input.value);
|
|
@@ -4,9 +4,15 @@ 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";
|
|
9
|
+
import { initAnnouncements } from "./announcements.js";
|
|
7
10
|
|
|
8
11
|
initMentions(app);
|
|
9
12
|
initMessages(app);
|
|
13
|
+
initReceipts(app);
|
|
10
14
|
initMembers(app);
|
|
11
15
|
initRooms(app);
|
|
16
|
+
initQuestions(app);
|
|
12
17
|
initEvents(app);
|
|
18
|
+
initAnnouncements(app);
|
|
@@ -1,33 +1,236 @@
|
|
|
1
1
|
import { createRandomId } from "./state.js";
|
|
2
2
|
|
|
3
3
|
const mentionPattern = /<at>@([^<]+)<\/at>/g;
|
|
4
|
+
const resourcePattern = /\[\[resource:([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})\]\]/gi;
|
|
5
|
+
let mermaidReady = false;
|
|
6
|
+
const previewUrls = new Map();
|
|
7
|
+
let previewObserver;
|
|
4
8
|
|
|
5
9
|
export function renderMarkdown(root, text, app) {
|
|
6
|
-
const mentions = [];
|
|
10
|
+
const mentions = [], diagrams = new Map();
|
|
7
11
|
const nonce = createRandomId();
|
|
8
12
|
const source = String(text).replace(mentionPattern, (_, name) => {
|
|
9
13
|
const token = `CHATMENTION${nonce}${mentions.length}END`;
|
|
10
14
|
mentions.push({ token, name, literal: `<at>@${name}</at>` });
|
|
11
15
|
return token;
|
|
12
16
|
});
|
|
13
|
-
const
|
|
17
|
+
const renderer = new window.marked.Renderer(), renderCode = renderer.code.bind(renderer);
|
|
18
|
+
renderer.code = (token) => {
|
|
19
|
+
if ((token.lang || "").trim().toLowerCase().split(/\s+/)[0] !== "mermaid") return renderCode(token);
|
|
20
|
+
const key = `CHATDIAGRAM${nonce}${diagrams.size}END`;
|
|
21
|
+
const literalToken = new RegExp(`CHATMENTION${nonce}\\d+END`, "g");
|
|
22
|
+
diagrams.set(key, token.text.replace(literalToken, (value) => mentions.find((mention) => mention.token === value)?.literal || value));
|
|
23
|
+
return `<div data-chat-mermaid="${key}"></div>`;
|
|
24
|
+
};
|
|
25
|
+
const parsed = window.marked.parse(source, { gfm: true, breaks: true, async: false, renderer });
|
|
14
26
|
const fragment = window.DOMPurify.sanitize(parsed, { RETURN_DOM_FRAGMENT: true });
|
|
15
27
|
replaceMentionTokens(fragment, mentions, app);
|
|
28
|
+
const resources = replaceResourceMarkers(fragment, app);
|
|
29
|
+
const diagramNodes = [...fragment.querySelectorAll("[data-chat-mermaid]")];
|
|
30
|
+
for (const node of diagramNodes) {
|
|
31
|
+
const source = diagrams.get(node.dataset.chatMermaid);
|
|
32
|
+
node.removeAttribute("data-chat-mermaid"); node.className = "mermaid-diagram";
|
|
33
|
+
if (source !== undefined) showDiagramFallback(node, source, app, !isUnsafeDiagram(source));
|
|
34
|
+
}
|
|
16
35
|
fragment.querySelectorAll("a").forEach((link) => {
|
|
17
36
|
link.target = "_blank";
|
|
18
37
|
link.rel = "noopener noreferrer";
|
|
19
38
|
});
|
|
20
39
|
fragment.querySelectorAll('input[type="checkbox"]').forEach((input) => { input.disabled = true; });
|
|
21
|
-
fragment.querySelectorAll("pre").forEach((pre) =>
|
|
22
|
-
const button = document.createElement("button");
|
|
23
|
-
button.type = "button";
|
|
24
|
-
button.className = "code-copy";
|
|
25
|
-
button.dataset.copyCode = "";
|
|
26
|
-
button.dataset.i18n = "copyCode";
|
|
27
|
-
button.textContent = app.t("copyCode");
|
|
28
|
-
pre.appendChild(button);
|
|
29
|
-
});
|
|
40
|
+
fragment.querySelectorAll("pre").forEach((pre) => addCodeCopy(pre, app));
|
|
30
41
|
root.appendChild(fragment);
|
|
42
|
+
for (let i = 0; i < diagramNodes.length; i++) {
|
|
43
|
+
const source = diagrams.get(`CHATDIAGRAM${nonce}${i}END`);
|
|
44
|
+
if (!isUnsafeDiagram(source)) void renderDiagram(diagramNodes[i], source, app);
|
|
45
|
+
}
|
|
46
|
+
for (const resource of resources) void loadResourceCard(resource.card, resource.roomId, app);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function initializeMermaid() {
|
|
50
|
+
if (mermaidReady) return;
|
|
51
|
+
if (!window.mermaid) await new Promise((resolve, reject) => {
|
|
52
|
+
const script = document.querySelector('script[src$="mermaid-11.12.2.min.js"]');
|
|
53
|
+
if (!script) return reject(new Error("Mermaid bundle is missing"));
|
|
54
|
+
script.addEventListener("load", resolve, { once: true });
|
|
55
|
+
script.addEventListener("error", reject, { once: true });
|
|
56
|
+
window.addEventListener("load", resolve, { once: true });
|
|
57
|
+
});
|
|
58
|
+
if (!window.mermaid) throw new Error("Mermaid bundle failed to load");
|
|
59
|
+
window.mermaid.initialize({
|
|
60
|
+
startOnLoad: false, securityLevel: "strict", htmlLabels: false,
|
|
61
|
+
theme: matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "default",
|
|
62
|
+
flowchart: { htmlLabels: false }, maxTextSize: 20000, maxEdges: 200, suppressErrorRendering: true,
|
|
63
|
+
secure: ["secure", "securityLevel", "startOnLoad", "htmlLabels", "flowchart", "theme", "themeCSS", "themeVariables", "dompurifyConfig", "maxTextSize", "maxEdges", "suppressErrorRendering"],
|
|
64
|
+
});
|
|
65
|
+
mermaidReady = true;
|
|
66
|
+
}
|
|
67
|
+
async function renderDiagram(node, source, app) {
|
|
68
|
+
if (source === undefined || isUnsafeDiagram(source)) return;
|
|
69
|
+
try {
|
|
70
|
+
await initializeMermaid();
|
|
71
|
+
const { svg } = await window.mermaid.render(`oc-chat-${createRandomId()}`, source);
|
|
72
|
+
if (!node.isConnected) return;
|
|
73
|
+
const fragment = window.DOMPurify.sanitize(svg, {
|
|
74
|
+
RETURN_DOM_FRAGMENT: true, USE_PROFILES: { svg: true, svgFilters: true },
|
|
75
|
+
FORBID_TAGS: ["foreignObject", "a", "script"], FORBID_ATTR: ["href", "xlink:href", "onclick", "onload"],
|
|
76
|
+
ALLOW_DATA_ATTR: false,
|
|
77
|
+
});
|
|
78
|
+
if (!fragment.querySelector("svg")) throw new Error("Diagram SVG was rejected");
|
|
79
|
+
const update = () => node.replaceChildren(fragment);
|
|
80
|
+
if (app.preserveReadingLayout) await app.preserveReadingLayout(update); else update();
|
|
81
|
+
} catch {
|
|
82
|
+
if (node.isConnected) showDiagramFallback(node, source, app, false);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function isUnsafeDiagram(source = "") {
|
|
86
|
+
return /%%\s*\{|^\s*---\s*(?:\r?\n)|\burl\s*\(|@import|@\s*\{[^}]*\b(?:img|image)\s*:/i.test(source);
|
|
87
|
+
}
|
|
88
|
+
function showDiagramFallback(node, source, app, loading) {
|
|
89
|
+
node.textContent = "";
|
|
90
|
+
const status = document.createElement("p"); status.className = "diagram-status";
|
|
91
|
+
status.setAttribute("role", "status"); status.textContent = app.t(loading ? "diagramLoading" : "diagramRenderFailed");
|
|
92
|
+
node.append(status);
|
|
93
|
+
if (!loading) {
|
|
94
|
+
const pre = document.createElement("pre"), code = document.createElement("code");
|
|
95
|
+
code.textContent = source; pre.append(code); addCodeCopy(pre, app); node.append(pre);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function addCodeCopy(pre, app) {
|
|
99
|
+
const button = document.createElement("button");
|
|
100
|
+
button.type = "button"; button.className = "code-copy"; button.dataset.copyCode = "";
|
|
101
|
+
button.dataset.i18n = "copyCode"; button.textContent = app.t("copyCode"); pre.append(button);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function replaceResourceMarkers(fragment, app) {
|
|
105
|
+
const walker = document.createTreeWalker(fragment, NodeFilter.SHOW_TEXT), nodes = [], cards = [], roomId = app.state.room?.id;
|
|
106
|
+
while (walker.nextNode()) nodes.push(walker.currentNode);
|
|
107
|
+
for (const node of nodes) {
|
|
108
|
+
if (node.parentElement?.closest("code, pre, a")) continue;
|
|
109
|
+
const value = node.nodeValue || "", replacement = document.createDocumentFragment();
|
|
110
|
+
let last = 0, match;
|
|
111
|
+
resourcePattern.lastIndex = 0;
|
|
112
|
+
while ((match = resourcePattern.exec(value))) {
|
|
113
|
+
replacement.append(document.createTextNode(value.slice(last, match.index)));
|
|
114
|
+
const card = document.createElement("span"), status = document.createElement("span");
|
|
115
|
+
card.className = "chat-resource"; card.dataset.resourceId = match[1]; card.setAttribute("role", "group");
|
|
116
|
+
status.className = "resource-status"; status.setAttribute("role", "status");
|
|
117
|
+
status.textContent = app.t("resourceLoading"); card.append(status); replacement.append(card);
|
|
118
|
+
cards.push({ card, roomId }); last = resourcePattern.lastIndex;
|
|
119
|
+
}
|
|
120
|
+
if (last) { replacement.append(document.createTextNode(value.slice(last))); node.replaceWith(replacement); }
|
|
121
|
+
}
|
|
122
|
+
return cards;
|
|
123
|
+
}
|
|
124
|
+
async function loadResourceCard(card, roomId, app) {
|
|
125
|
+
try {
|
|
126
|
+
const id = card.dataset.resourceId;
|
|
127
|
+
const result = await app.api(`/rooms/${encodeURIComponent(roomId)}/resources/${encodeURIComponent(id)}`);
|
|
128
|
+
if (!card.isConnected) return;
|
|
129
|
+
const resource = result.resource, type = String(resource.mimeType).split(";")[0].toLowerCase();
|
|
130
|
+
card.setAttribute("aria-label", resource.name);
|
|
131
|
+
const info = document.createElement("span"), name = document.createElement("span"), size = document.createElement("span"), actions = document.createElement("span"), status = document.createElement("span");
|
|
132
|
+
info.className = "resource-info"; name.className = "resource-name"; name.textContent = resource.name;
|
|
133
|
+
size.className = "resource-size"; size.textContent = formatBytes(resource.size); info.append(name, size);
|
|
134
|
+
actions.className = "resource-actions"; status.className = "resource-status"; status.setAttribute("role", "status");
|
|
135
|
+
card.replaceChildren(info, actions, status);
|
|
136
|
+
const download = resourceButton("resourceDownload", resource.name, () => downloadResource(card, roomId, id, resource, app, status, download), app);
|
|
137
|
+
actions.append(download);
|
|
138
|
+
if (previewKind(type)) {
|
|
139
|
+
const preview = resourceButton("resourcePreview", resource.name, () => previewResource(card, roomId, id, resource, type, preview, app, status), app);
|
|
140
|
+
actions.append(preview);
|
|
141
|
+
}
|
|
142
|
+
} catch { if (card.isConnected) setResourceError(card, app); }
|
|
143
|
+
}
|
|
144
|
+
function resourceButton(key, name, action, app) {
|
|
145
|
+
const button = document.createElement("button");
|
|
146
|
+
button.type = "button"; button.className = "btn ghost small resource-button";
|
|
147
|
+
button.dataset.i18n = key; button.textContent = app.t(key);
|
|
148
|
+
button.setAttribute("aria-label", `${app.t(key)}: ${name}`);
|
|
149
|
+
button.addEventListener("click", action); return button;
|
|
150
|
+
}
|
|
151
|
+
async function downloadResource(card, roomId, id, resource, app, status, button) {
|
|
152
|
+
if (!card.isConnected || button.disabled) return;
|
|
153
|
+
button.disabled = true;
|
|
154
|
+
status.textContent = app.t("resourceLoading");
|
|
155
|
+
try {
|
|
156
|
+
const blob = await app.apiBlob(`/rooms/${encodeURIComponent(roomId)}/resources/${encodeURIComponent(id)}/content`);
|
|
157
|
+
if (!card.isConnected) return;
|
|
158
|
+
const url = URL.createObjectURL(blob), link = document.createElement("a");
|
|
159
|
+
link.href = url; link.download = String(resource.name).replace(/[\\/\u0000-\u001f\u007f]/g, "_") || "download";
|
|
160
|
+
document.body.append(link); link.click(); link.remove(); setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
161
|
+
status.textContent = "";
|
|
162
|
+
} catch { if (card.isConnected) status.textContent = app.t("resourceFailed"); }
|
|
163
|
+
finally { if (card.isConnected) button.disabled = false; }
|
|
164
|
+
}
|
|
165
|
+
async function previewResource(card, roomId, id, resource, type, button, app, status) {
|
|
166
|
+
if (!card.isConnected || button.disabled) return;
|
|
167
|
+
button.disabled = true;
|
|
168
|
+
if (card._previewElement) {
|
|
169
|
+
try {
|
|
170
|
+
await app.preserveReadingLayout(() => card._previewElement.remove());
|
|
171
|
+
URL.revokeObjectURL(card._resourceUrl); previewUrls.delete(card); delete card._resourceUrl; delete card._previewElement;
|
|
172
|
+
if (card.isConnected) { button.dataset.i18n = "resourcePreview"; button.textContent = app.t("resourcePreview"); }
|
|
173
|
+
} catch {
|
|
174
|
+
if (!card.isConnected) return;
|
|
175
|
+
} finally { if (card.isConnected) button.disabled = false; }
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
status.textContent = app.t("resourceLoading");
|
|
179
|
+
let url;
|
|
180
|
+
try {
|
|
181
|
+
const blob = await app.apiBlob(`/rooms/${encodeURIComponent(roomId)}/resources/${encodeURIComponent(id)}/content`);
|
|
182
|
+
if (!card.isConnected) return;
|
|
183
|
+
url = URL.createObjectURL(blob);
|
|
184
|
+
const kind = previewKind(type), media = document.createElement(kind), ready = waitForMediaSize(media, kind);
|
|
185
|
+
if (kind === "img") media.alt = resource.name;
|
|
186
|
+
else { media.controls = true; media.preload = "metadata"; }
|
|
187
|
+
media.addEventListener("error", () => { if (card.isConnected) status.textContent = app.t("resourceFailed"); });
|
|
188
|
+
media.src = url;
|
|
189
|
+
await app.preserveReadingLayout(async () => { status.textContent = ""; card.append(media); await ready; });
|
|
190
|
+
if (!card.isConnected) { URL.revokeObjectURL(url); return; }
|
|
191
|
+
card._resourceUrl = url; card._previewElement = media; previewUrls.set(card, url); watchPreviewRemoval();
|
|
192
|
+
button.dataset.i18n = "resourceHide"; button.textContent = app.t("resourceHide");
|
|
193
|
+
} catch { if (url) URL.revokeObjectURL(url); if (card.isConnected) status.textContent = app.t("resourceFailed"); }
|
|
194
|
+
finally { if (card.isConnected) button.disabled = false; }
|
|
195
|
+
}
|
|
196
|
+
function waitForMediaSize(media, kind) {
|
|
197
|
+
const event = kind === "img" ? "load" : "loadedmetadata";
|
|
198
|
+
if (kind === "img" && media.complete && media.naturalWidth) return Promise.resolve();
|
|
199
|
+
if (kind !== "img" && media.readyState >= 1) return Promise.resolve();
|
|
200
|
+
return new Promise((resolve, reject) => {
|
|
201
|
+
media.addEventListener(event, resolve, { once: true });
|
|
202
|
+
media.addEventListener("error", reject, { once: true });
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function previewKind(type) {
|
|
206
|
+
if (["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif"].includes(type)) return "img";
|
|
207
|
+
if (["audio/mpeg", "audio/ogg", "audio/wav", "audio/webm", "audio/mp4"].includes(type)) return "audio";
|
|
208
|
+
if (["video/mp4", "video/webm", "video/ogg"].includes(type)) return "video";
|
|
209
|
+
return "";
|
|
210
|
+
}
|
|
211
|
+
function formatBytes(value) {
|
|
212
|
+
const bytes = Math.max(0, Number(value) || 0);
|
|
213
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
214
|
+
return bytes < 1048576 ? `${(bytes / 1024).toFixed(1)} KB` : `${(bytes / 1048576).toFixed(1)} MB`;
|
|
215
|
+
}
|
|
216
|
+
function setResourceError(card, app) {
|
|
217
|
+
card.textContent = "";
|
|
218
|
+
const status = document.createElement("span"); status.className = "resource-status";
|
|
219
|
+
status.setAttribute("role", "status"); status.textContent = app.t("resourceFailed"); card.append(status);
|
|
220
|
+
}
|
|
221
|
+
function watchPreviewRemoval() {
|
|
222
|
+
const list = document.querySelector("#msgList");
|
|
223
|
+
if (previewObserver || !list) return;
|
|
224
|
+
previewObserver = new MutationObserver((records) => {
|
|
225
|
+
for (const node of records.flatMap((record) => [...record.removedNodes])) {
|
|
226
|
+
if (!(node instanceof Element)) continue;
|
|
227
|
+
for (const card of [node, ...node.querySelectorAll(".chat-resource")]) {
|
|
228
|
+
const url = previewUrls.get(card);
|
|
229
|
+
if (url && !card.isConnected) { URL.revokeObjectURL(url); previewUrls.delete(card); }
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
previewObserver.observe(list, { childList: true, subtree: true });
|
|
31
234
|
}
|
|
32
235
|
|
|
33
236
|
function replaceMentionTokens(fragment, mentions, app) {
|
|
@@ -90,13 +90,16 @@ export function initMembers(app) {
|
|
|
90
90
|
app.state.receiptRefreshTimer = setTimeout(() => void app.loadVisibleReceipts(roomId, generation), 180);
|
|
91
91
|
};
|
|
92
92
|
app.queueReceiptObservation = () => {
|
|
93
|
+
if ((app.state.resizeScrollAdjusting || app.state.layoutScrollAdjusting)
|
|
94
|
+
&& performance.now() > app.state.userScrollIntentUntil) return;
|
|
93
95
|
app.state.receiptObservation = { roomId: app.state.room?.id, generation: app.state.pollGeneration };
|
|
94
96
|
if (app.state.receiptObservationFrame) return;
|
|
95
97
|
app.state.receiptObservationFrame = requestAnimationFrame(() => {
|
|
96
98
|
app.state.receiptObservationFrame = 0;
|
|
97
99
|
const target = app.state.receiptObservation;
|
|
98
100
|
app.state.receiptObservation = null;
|
|
99
|
-
if (!target ||
|
|
101
|
+
if (!target || (app.state.resizeScrollAdjusting || app.state.layoutScrollAdjusting)
|
|
102
|
+
&& performance.now() > app.state.userScrollIntentUntil || document.hidden || !document.hasFocus() || !current(app, target.roomId, target.generation)) return;
|
|
100
103
|
void app.loadVisibleReceipts(target.roomId, target.generation);
|
|
101
104
|
void app.ackVisibleMessages(target.roomId, target.generation);
|
|
102
105
|
});
|