@alexsun-top/opencode-chat-room 0.6.7 → 0.6.8
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 +6 -3
- package/README.zh-CN.md +7 -3
- package/docs/administrator-rooms.md +7 -2
- package/package.json +4 -1
- package/plugin.ts +38 -8
- package/server/assets/base.css +228 -28
- package/server/assets/chat/admin-badge.js +28 -6
- package/server/assets/chat/admin.js +7 -1
- package/server/assets/chat/attachment-store.js +106 -0
- package/server/assets/chat/attachments.js +201 -21
- package/server/assets/chat/events.js +28 -8
- package/server/assets/chat/image-zoom.js +86 -2
- package/server/assets/chat/index.js +8 -0
- package/server/assets/chat/install-prompt.js +82 -0
- package/server/assets/chat/join-requests.js +355 -0
- package/server/assets/chat/markdown.js +54 -6
- package/server/assets/chat/members.js +4 -2
- package/server/assets/chat/message-polling.js +24 -3
- package/server/assets/chat/messages.js +6 -4
- package/server/assets/chat/questions.js +10 -6
- package/server/assets/chat/recall.js +279 -0
- package/server/assets/chat/reminders.js +52 -8
- package/server/assets/chat/replies.js +1 -1
- package/server/assets/chat/room-list.js +14 -5
- package/server/assets/chat/room-watcher.js +5 -1
- package/server/assets/chat/rooms.js +16 -4
- package/server/assets/chat/shortcuts.js +254 -0
- package/server/assets/chat/state.js +73 -14
- package/server/assets/chat/system-messages.js +3 -0
- package/server/assets/conversation.css +2 -2
- package/server/assets/keyboard-hints.css +51 -0
- package/server/assets/recall.css +29 -0
- package/server/assets/responsive.css +38 -13
- package/server/chat-server.ts +55 -66
- package/server/chat.html +146 -16
- package/server/inbox.ts +1 -1
- package/server/join-requests.ts +106 -0
- package/server/message-recall-routes.ts +37 -0
- package/server/newrooms.ts +9 -0
- package/server/room-join.ts +59 -0
- package/server/room-owner.ts +3 -20
- package/server/room-payload.ts +2 -0
- package/server/sw.js +1 -0
- package/server/wake.ts +45 -16
- package/skills/chatroom/SKILL.md +32 -0
- package/src/README.md +5 -3
- package/src/agent/admin-client.ts +28 -4
- package/src/center/center-client.ts +81 -4
- package/src/center/center-inbox.ts +35 -10
- package/src/center/center-wake.ts +25 -12
- package/src/center/message-ids.ts +7 -0
- package/src/center/notification-budget.ts +16 -0
- package/src/center/queue.ts +14 -4
- package/src/rooms/room-service.ts +10 -1
- package/src/runtime/plugin-notifications.ts +37 -11
- package/src/runtime/v2-plugin.ts +1 -1
- package/src/state/roles.ts +34 -0
- package/src/state/sqlite-state.ts +196 -27
- package/src/state/store.ts +22 -3
- package/src/tests/announcement-board.ts +9 -0
|
@@ -2,14 +2,47 @@
|
|
|
2
2
|
// message list moves: the overlay is a top-layer dialog, not a row change.
|
|
3
3
|
export function initImageZoom(app) {
|
|
4
4
|
const dialog = app.$("#imageDialog"), preview = app.$("#imageDialogImage");
|
|
5
|
-
|
|
5
|
+
const zoomLevel = app.$("#zoomLevel"), zoomOut = app.$("#btnZoomOut"), zoomIn = app.$("#btnZoomIn"), zoomReset = app.$("#btnZoomReset");
|
|
6
|
+
const MIN = 1, MAX = 4, STEP = 1.25;
|
|
7
|
+
let trigger = null, scale = 1, panX = 0, panY = 0, drag = null;
|
|
8
|
+
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
6
9
|
const imageOf = (node) => node?.closest?.("#msgList img, #attachmentList img");
|
|
10
|
+
function limits() {
|
|
11
|
+
const style = getComputedStyle(dialog);
|
|
12
|
+
const width = dialog.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
|
|
13
|
+
const height = dialog.clientHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom);
|
|
14
|
+
return { x: Math.max(0, (preview.offsetWidth * scale - width) / 2), y: Math.max(0, (preview.offsetHeight * scale - height) / 2) };
|
|
15
|
+
}
|
|
16
|
+
function apply() {
|
|
17
|
+
const limit = limits();
|
|
18
|
+
panX = clamp(panX, -limit.x, limit.x); panY = clamp(panY, -limit.y, limit.y);
|
|
19
|
+
preview.style.transform = scale > 1 ? `translate3d(${panX}px, ${panY}px, 0) scale(${scale})` : "";
|
|
20
|
+
preview.classList.toggle("is-zoomed", scale > 1);
|
|
21
|
+
if (zoomLevel) zoomLevel.textContent = `${Math.round(scale * 100)}%`;
|
|
22
|
+
if (zoomOut) zoomOut.disabled = scale <= MIN + .001;
|
|
23
|
+
if (zoomIn) zoomIn.disabled = scale >= MAX - .001;
|
|
24
|
+
}
|
|
25
|
+
function zoomTo(next, x = innerWidth / 2, y = innerHeight / 2) {
|
|
26
|
+
const target = clamp(next, MIN, MAX);
|
|
27
|
+
if (Math.abs(target - scale) < .001) return apply();
|
|
28
|
+
// Keep the point under the pointer fixed while scaling.
|
|
29
|
+
const dx = x - innerWidth / 2, dy = y - innerHeight / 2, ratio = target / scale;
|
|
30
|
+
panX = dx - ratio * (dx - panX); panY = dy - ratio * (dy - panY);
|
|
31
|
+
scale = target;
|
|
32
|
+
if (scale <= 1) { scale = 1; panX = 0; panY = 0; }
|
|
33
|
+
preview.style.animation = "none";
|
|
34
|
+
apply();
|
|
35
|
+
}
|
|
36
|
+
const zoomBy = (factor) => zoomTo(scale * factor);
|
|
37
|
+
const resetZoom = () => { scale = 1; panX = 0; panY = 0; apply(); };
|
|
7
38
|
function open(image) {
|
|
8
39
|
if (!image || !dialog) return;
|
|
9
40
|
trigger = image;
|
|
10
41
|
// Reuse the URL the list already loaded, so the overlay costs no second download.
|
|
11
42
|
preview.src = image.currentSrc || image.src;
|
|
12
43
|
preview.alt = image.alt || "";
|
|
44
|
+
preview.style.animation = "";
|
|
45
|
+
resetZoom();
|
|
13
46
|
dialog.showModal();
|
|
14
47
|
}
|
|
15
48
|
const close = () => { if (dialog.open) dialog.close(); };
|
|
@@ -34,8 +67,59 @@ export function initImageZoom(app) {
|
|
|
34
67
|
});
|
|
35
68
|
app.$("#btnCloseImage")?.addEventListener("click", close);
|
|
36
69
|
dialog.addEventListener("click", (event) => { if (event.target === dialog) close(); });
|
|
70
|
+
// The viewer owns the wheel while it is open so the thread behind it cannot scroll.
|
|
71
|
+
dialog.addEventListener("wheel", (event) => {
|
|
72
|
+
if (!dialog.open) return;
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
if (event.target.closest?.(".image-dialog-tools, .image-dialog-close")) return;
|
|
75
|
+
const delta = event.deltaMode === 1 ? event.deltaY * 16 : event.deltaY;
|
|
76
|
+
zoomTo(scale * Math.exp(-delta * .0015), event.clientX, event.clientY);
|
|
77
|
+
}, { passive: false });
|
|
78
|
+
dialog.addEventListener("keydown", (event) => {
|
|
79
|
+
if (!dialog.open) return;
|
|
80
|
+
if (event.key === "+" || event.key === "=") { event.preventDefault(); zoomBy(STEP); }
|
|
81
|
+
else if (event.key === "-" || event.key === "_") { event.preventDefault(); zoomBy(1 / STEP); }
|
|
82
|
+
else if (event.key === "0") { event.preventDefault(); resetZoom(); }
|
|
83
|
+
else if (scale > 1 && event.key.startsWith("Arrow")) {
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
const step = event.shiftKey ? 120 : 40;
|
|
86
|
+
if (event.key === "ArrowLeft") panX += step;
|
|
87
|
+
else if (event.key === "ArrowRight") panX -= step;
|
|
88
|
+
else if (event.key === "ArrowUp") panY += step;
|
|
89
|
+
else panY -= step;
|
|
90
|
+
apply();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
zoomIn?.addEventListener("click", () => zoomBy(STEP));
|
|
94
|
+
zoomOut?.addEventListener("click", () => zoomBy(1 / STEP));
|
|
95
|
+
zoomReset?.addEventListener("click", resetZoom);
|
|
96
|
+
window.addEventListener("resize", () => { if (dialog.open) apply(); });
|
|
97
|
+
// Pointer dragging pans the zoomed image; the tool buttons are the touch and
|
|
98
|
+
// keyboard alternative for changing the scale, and arrow keys pan to the edges.
|
|
99
|
+
preview.draggable = false;
|
|
100
|
+
preview.addEventListener("pointerdown", (event) => {
|
|
101
|
+
if (scale <= 1 || event.button !== 0) return;
|
|
102
|
+
drag = { id: event.pointerId, x: event.clientX, y: event.clientY, panX, panY };
|
|
103
|
+
preview.setPointerCapture(event.pointerId);
|
|
104
|
+
preview.classList.add("is-dragging");
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
});
|
|
107
|
+
preview.addEventListener("pointermove", (event) => {
|
|
108
|
+
if (!drag || event.pointerId !== drag.id) return;
|
|
109
|
+
panX = drag.panX + event.clientX - drag.x; panY = drag.panY + event.clientY - drag.y;
|
|
110
|
+
apply();
|
|
111
|
+
});
|
|
112
|
+
const endDrag = (event) => {
|
|
113
|
+
if (!drag || event.pointerId !== drag.id) return;
|
|
114
|
+
drag = null; preview.classList.remove("is-dragging");
|
|
115
|
+
if (preview.hasPointerCapture(event.pointerId)) preview.releasePointerCapture(event.pointerId);
|
|
116
|
+
};
|
|
117
|
+
preview.addEventListener("pointerup", endDrag);
|
|
118
|
+
preview.addEventListener("pointercancel", endDrag);
|
|
37
119
|
dialog.addEventListener("close", () => {
|
|
38
120
|
preview.removeAttribute("src");
|
|
121
|
+
preview.style.animation = "";
|
|
122
|
+
resetZoom();
|
|
39
123
|
if (trigger?.isConnected) trigger.focus({ preventScroll: true });
|
|
40
124
|
trigger = null;
|
|
41
125
|
});
|
|
@@ -54,4 +138,4 @@ export function initImageZoom(app) {
|
|
|
54
138
|
if (list) new MutationObserver(enhance).observe(list, { childList: true, subtree: true });
|
|
55
139
|
}
|
|
56
140
|
enhance();
|
|
57
|
-
}
|
|
141
|
+
}
|
|
@@ -3,6 +3,7 @@ import { initMentions } from "./mentions.js";
|
|
|
3
3
|
import { initMessages } from "./messages.js";
|
|
4
4
|
import { initMembers } from "./members.js";
|
|
5
5
|
import { initRooms } from "./rooms.js";
|
|
6
|
+
import { initJoinRequests } from "./join-requests.js";
|
|
6
7
|
import { initEvents } from "./events.js";
|
|
7
8
|
import { initQuestions } from "./questions.js";
|
|
8
9
|
import { initReceipts } from "./receipts.js";
|
|
@@ -10,10 +11,13 @@ import { initAnnouncements } from "./announcements.js";
|
|
|
10
11
|
import { initAdmin } from "./admin.js";
|
|
11
12
|
import { initAttachments } from "./attachments.js";
|
|
12
13
|
import { initReplies } from "./replies.js";
|
|
14
|
+
import { initRecall } from "./recall.js";
|
|
13
15
|
import { initHistoryLoader } from "./history-loader.js";
|
|
14
16
|
import { initImageZoom } from "./image-zoom.js";
|
|
15
17
|
import { initReminders } from "./reminders.js";
|
|
16
18
|
import { initPwa } from "./pwa.js";
|
|
19
|
+
import { initInstallPrompt } from "./install-prompt.js";
|
|
20
|
+
import { initShortcuts } from "./shortcuts.js";
|
|
17
21
|
|
|
18
22
|
initMentions(app);
|
|
19
23
|
initMessages(app);
|
|
@@ -21,12 +25,16 @@ initAttachments(app);
|
|
|
21
25
|
initReceipts(app);
|
|
22
26
|
initMembers(app);
|
|
23
27
|
initRooms(app);
|
|
28
|
+
initJoinRequests(app);
|
|
24
29
|
initHistoryLoader(app);
|
|
25
30
|
initQuestions(app);
|
|
26
31
|
initReplies(app);
|
|
32
|
+
initRecall(app);
|
|
27
33
|
initEvents(app);
|
|
34
|
+
initShortcuts(app);
|
|
28
35
|
initAnnouncements(app);
|
|
29
36
|
initReminders(app);
|
|
30
37
|
initAdmin(app);
|
|
31
38
|
initImageZoom(app);
|
|
32
39
|
initPwa();
|
|
40
|
+
initInstallPrompt(app);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// A one-time install recommendation for phones. The browser prompt itself is deferred
|
|
2
|
+
// until the Install button gesture; desktop, standalone, installed, and recent dissent
|
|
3
|
+
// all stay silent. Local storage is optional: blocked storage falls back to this tab.
|
|
4
|
+
const DISMISS_MS = 30 * 24 * 60 * 60 * 1000;
|
|
5
|
+
const DISMISS_KEY = "chat.installDismissedAt";
|
|
6
|
+
const INSTALLED_KEY = "chat.installedApp";
|
|
7
|
+
const memory = new Map();
|
|
8
|
+
|
|
9
|
+
function read(key) {
|
|
10
|
+
try { return localStorage.getItem(key); } catch { /* Try the tab next. */ }
|
|
11
|
+
try { return sessionStorage.getItem(key); } catch { /* Use memory. */ }
|
|
12
|
+
return memory.get(key) ?? null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function write(key, value) {
|
|
16
|
+
try { localStorage.setItem(key, value); return; } catch { /* Try the tab next. */ }
|
|
17
|
+
try { sessionStorage.setItem(key, value); } catch { memory.set(key, value); }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function isIos() {
|
|
21
|
+
return /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isStandalone() {
|
|
25
|
+
return matchMedia("(display-mode: standalone)").matches || navigator.standalone === true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function initInstallPrompt(app) {
|
|
29
|
+
const card = app.$("#installPrompt"), installButton = app.$("#btnInstallApp"), guideButton = app.$("#btnInstallGuide"), guide = app.$("#installGuide"), dismissButton = app.$("#btnDismissInstall");
|
|
30
|
+
const rail = app.$("#railInstall"), railInstall = app.$("#btnRailInstall"), railGuide = app.$("#railInstallGuide");
|
|
31
|
+
if (!card || !installButton || !guideButton || !guide || !dismissButton || !rail || !railInstall || !railGuide) return;
|
|
32
|
+
const eligible = () => matchMedia("(max-width: 760px)").matches && window.isSecureContext;
|
|
33
|
+
const suppressed = () => read(INSTALLED_KEY) === "1" || Number(read(DISMISS_KEY) || 0) > Date.now() - DISMISS_MS;
|
|
34
|
+
let deferred = null;
|
|
35
|
+
|
|
36
|
+
function hide() {
|
|
37
|
+
const fromCard = card.contains(document.activeElement), fromRail = rail.contains(document.activeElement);
|
|
38
|
+
card.hidden = true;
|
|
39
|
+
rail.hidden = true;
|
|
40
|
+
if (fromCard) app.$("#inName")?.focus({ preventScroll: true });
|
|
41
|
+
else if (fromRail) app.$("#btnSettings")?.focus({ preventScroll: true });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// The join card explains itself; the room drawer carries the same offer for people
|
|
45
|
+
// who restore straight into a room and never see the join page.
|
|
46
|
+
function render(mode) {
|
|
47
|
+
const visible = Boolean(mode) && eligible() && !isStandalone() && !suppressed();
|
|
48
|
+
card.hidden = rail.hidden = !visible;
|
|
49
|
+
if (!visible) return;
|
|
50
|
+
installButton.hidden = mode !== "prompt";
|
|
51
|
+
guideButton.hidden = mode !== "ios";
|
|
52
|
+
railInstall.hidden = mode !== "prompt";
|
|
53
|
+
railGuide.hidden = mode !== "ios";
|
|
54
|
+
if (mode !== "ios") { guide.hidden = true; guideButton.setAttribute("aria-expanded", "false"); }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
window.addEventListener("beforeinstallprompt", (event) => {
|
|
58
|
+
if (!eligible() || isStandalone() || suppressed()) return;
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
deferred = event;
|
|
61
|
+
render("prompt");
|
|
62
|
+
});
|
|
63
|
+
window.addEventListener("appinstalled", () => { write(INSTALLED_KEY, "1"); hide(); });
|
|
64
|
+
const promptInstall = async () => {
|
|
65
|
+
const prompt = deferred;
|
|
66
|
+
if (!prompt) return;
|
|
67
|
+
deferred = null;
|
|
68
|
+
let accepted = false;
|
|
69
|
+
try { accepted = (await prompt.prompt())?.outcome === "accepted"; } catch { /* Count it as declined. */ }
|
|
70
|
+
write(accepted ? INSTALLED_KEY : DISMISS_KEY, accepted ? "1" : String(Date.now()));
|
|
71
|
+
hide();
|
|
72
|
+
};
|
|
73
|
+
installButton.addEventListener("click", promptInstall);
|
|
74
|
+
railInstall.addEventListener("click", promptInstall);
|
|
75
|
+
guideButton.addEventListener("click", () => {
|
|
76
|
+
const open = guide.hidden;
|
|
77
|
+
guide.hidden = !open;
|
|
78
|
+
guideButton.setAttribute("aria-expanded", String(open));
|
|
79
|
+
});
|
|
80
|
+
dismissButton.addEventListener("click", () => { write(DISMISS_KEY, String(Date.now())); hide(); });
|
|
81
|
+
if (isIos()) render("ios");
|
|
82
|
+
}
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { LS } from "./state.js";
|
|
2
|
+
import { isRoomAdmin } from "./admin-badge.js";
|
|
3
|
+
|
|
4
|
+
// Pending join state is browser-local; the server remains authoritative.
|
|
5
|
+
export function initJoinRequests(app) {
|
|
6
|
+
const $ = app.$;
|
|
7
|
+
const pendingIds = (app.state.pendingJoinIds ??= new Set());
|
|
8
|
+
let pending = { roomId: "", name: "", status: "", timer: 0, generation: 0, checking: false };
|
|
9
|
+
let requests = [], requestsRoomId = "", requestsGeneration = 0, requestsLoading = false, deniedRoomId = "";
|
|
10
|
+
let requestSignature = "";
|
|
11
|
+
|
|
12
|
+
const panel = $("#memberPanel"), section = $("#joinRequests"), list = $("#joinRequestList");
|
|
13
|
+
const card = $("#joinPending"), title = $("#joinPendingTitle"), body = $("#joinPendingBody"), hint = $("#joinPendingHint");
|
|
14
|
+
const notice = $("#joinNotice"), noticeText = $("#joinNoticeText");
|
|
15
|
+
const roomNameFor = (roomId) => app.state.availableRooms?.find((item) => item.id === roomId)?.name
|
|
16
|
+
|| app.state.rooms.get(roomId)?.room.name || roomId;
|
|
17
|
+
const approveText = (request) => app.t("joinRequestApproveLabel", { name: request.name });
|
|
18
|
+
const denyText = (request) => app.t("joinRequestDenyLabel", { name: request.name });
|
|
19
|
+
|
|
20
|
+
app.showJoinPending = (roomId, name) => {
|
|
21
|
+
clearTimeout(pending.timer);
|
|
22
|
+
pending = { roomId, name, status: "pending", timer: 0, generation: pending.generation + 1, checking: false };
|
|
23
|
+
pendingIds.add(roomId);
|
|
24
|
+
const roomName = roomNameFor(roomId);
|
|
25
|
+
app.setText(title, "joinPendingTitle");
|
|
26
|
+
app.setText(body, "joinPendingBody", { name: roomName });
|
|
27
|
+
app.setText(hint, "joinPendingHint");
|
|
28
|
+
app.setText(noticeText, "joinPendingNotice", { name: roomName });
|
|
29
|
+
notice.hidden = $("#chatView").hidden;
|
|
30
|
+
hint.hidden = false;
|
|
31
|
+
card.hidden = false;
|
|
32
|
+
$("#joinError").hidden = true;
|
|
33
|
+
renderPendingActions();
|
|
34
|
+
app.renderRoomOptions($("#roomList"), app.state.availableRooms || []);
|
|
35
|
+
app.renderRoomOptions($("#roomListChat"), app.state.availableRooms || []);
|
|
36
|
+
scheduleCheck();
|
|
37
|
+
if ($("#joinView").hidden) return;
|
|
38
|
+
title.focus({ preventScroll: true });
|
|
39
|
+
card.scrollIntoView({ block: "nearest" });
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function renderPendingActions() {
|
|
43
|
+
const waiting = pending.status === "pending";
|
|
44
|
+
const gone = pending.status === "gone";
|
|
45
|
+
$("#btnJoinPendingCheck").hidden = !waiting;
|
|
46
|
+
$("#btnJoinPendingStop").hidden = !waiting;
|
|
47
|
+
$("#btnJoinPendingAgain").hidden = waiting || gone;
|
|
48
|
+
$("#btnJoinNoticeCheck").hidden = !waiting;
|
|
49
|
+
$("#btnJoinNoticeStop").hidden = !waiting;
|
|
50
|
+
$("#btnJoinNoticeAgain").hidden = waiting || gone;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function closePending(keepWaiting = false) {
|
|
54
|
+
clearTimeout(pending.timer);
|
|
55
|
+
pending.timer = 0;
|
|
56
|
+
pending.generation++;
|
|
57
|
+
card.hidden = true;
|
|
58
|
+
notice.hidden = true;
|
|
59
|
+
if (!keepWaiting) {
|
|
60
|
+
pending.roomId = "";
|
|
61
|
+
pending.name = "";
|
|
62
|
+
pending.status = "";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function scheduleCheck(delay = 4000) {
|
|
67
|
+
clearTimeout(pending.timer);
|
|
68
|
+
if (!pending.roomId || pending.status !== "pending") return;
|
|
69
|
+
pending.timer = setTimeout(() => void checkPending(), delay);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function checkPending(manual = false) {
|
|
73
|
+
if (pending.checking || !pending.roomId || pending.status !== "pending") return;
|
|
74
|
+
if (document.hidden) { scheduleCheck(); return; }
|
|
75
|
+
const generation = pending.generation, roomId = pending.roomId;
|
|
76
|
+
pending.checking = true;
|
|
77
|
+
if (manual) { $("#btnJoinPendingCheck").disabled = true; $("#btnJoinNoticeCheck").disabled = true; }
|
|
78
|
+
try {
|
|
79
|
+
const result = await app.api(`/rooms/${encodeURIComponent(roomId)}/join-requests/status?sessionID=${encodeURIComponent(LS.sessionID)}`);
|
|
80
|
+
if (generation !== pending.generation) return;
|
|
81
|
+
if (result.status === "joined") {
|
|
82
|
+
const name = pending.name || LS.name;
|
|
83
|
+
pendingIds.delete(roomId);
|
|
84
|
+
closePending();
|
|
85
|
+
void app.joinRoom(roomId, name);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (result.status === "pending") {
|
|
89
|
+
app.setText(hint, "joinPendingHint");
|
|
90
|
+
hint.hidden = false;
|
|
91
|
+
scheduleCheck();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
pendingIds.delete(roomId);
|
|
95
|
+
pending.status = "none";
|
|
96
|
+
app.setText(title, "joinPendingGoneTitle");
|
|
97
|
+
app.setText(body, "joinPendingGoneBody");
|
|
98
|
+
app.setText(noticeText, "joinPendingGoneBody");
|
|
99
|
+
notice.hidden = $("#chatView").hidden;
|
|
100
|
+
hint.hidden = true;
|
|
101
|
+
renderPendingActions();
|
|
102
|
+
renderRoomLists();
|
|
103
|
+
rethrowFocus($("#joinView").hidden ? $("#btnJoinNoticeAgain") : $("#btnJoinPendingAgain"));
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (generation !== pending.generation) return;
|
|
106
|
+
if (error.status === 404) {
|
|
107
|
+
pendingIds.delete(roomId);
|
|
108
|
+
pending.status = "gone";
|
|
109
|
+
app.setText(title, "joinPendingGoneTitle");
|
|
110
|
+
app.setText(body, "joinPendingRoomGone");
|
|
111
|
+
app.setText(noticeText, "joinPendingRoomGone");
|
|
112
|
+
notice.hidden = $("#chatView").hidden;
|
|
113
|
+
hint.hidden = true;
|
|
114
|
+
renderPendingActions();
|
|
115
|
+
renderRoomLists();
|
|
116
|
+
} else {
|
|
117
|
+
app.setText(hint, "joinPendingError");
|
|
118
|
+
hint.hidden = false;
|
|
119
|
+
scheduleCheck(8000);
|
|
120
|
+
}
|
|
121
|
+
} finally {
|
|
122
|
+
pending.checking = false;
|
|
123
|
+
$("#btnJoinPendingCheck").disabled = false;
|
|
124
|
+
$("#btnJoinNoticeCheck").disabled = false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function rethrowFocus(element) {
|
|
129
|
+
if (!element || element.hidden) return;
|
|
130
|
+
element.focus({ preventScroll: true });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function renderPendingCopy() {
|
|
134
|
+
if (!pending.roomId) return;
|
|
135
|
+
const roomName = roomNameFor(pending.roomId);
|
|
136
|
+
if (pending.status === "pending") {
|
|
137
|
+
app.setText(title, "joinPendingTitle");
|
|
138
|
+
app.setText(body, "joinPendingBody", { name: roomName });
|
|
139
|
+
app.setText(hint, "joinPendingHint");
|
|
140
|
+
app.setText(noticeText, "joinPendingNotice", { name: roomName });
|
|
141
|
+
notice.hidden = $("#chatView").hidden;
|
|
142
|
+
hint.hidden = false;
|
|
143
|
+
} else if (pending.status === "none") {
|
|
144
|
+
app.setText(title, "joinPendingGoneTitle");
|
|
145
|
+
app.setText(body, "joinPendingGoneBody");
|
|
146
|
+
app.setText(noticeText, "joinPendingGoneBody");
|
|
147
|
+
notice.hidden = $("#chatView").hidden;
|
|
148
|
+
hint.hidden = true;
|
|
149
|
+
} else if (pending.status === "gone") {
|
|
150
|
+
app.setText(title, "joinPendingGoneTitle");
|
|
151
|
+
app.setText(body, "joinPendingRoomGone");
|
|
152
|
+
app.setText(noticeText, "joinPendingRoomGone");
|
|
153
|
+
notice.hidden = $("#chatView").hidden;
|
|
154
|
+
hint.hidden = true;
|
|
155
|
+
}
|
|
156
|
+
renderPendingActions();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
app.refreshJoinRequests = () => void refreshRequests();
|
|
160
|
+
app.clearJoinRequests = () => {
|
|
161
|
+
deniedRoomId = ""; requestsGeneration++; requests = []; requestsRoomId = ""; requestSignature = "";
|
|
162
|
+
renderRequests();
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
async function refreshRequests() {
|
|
166
|
+
const room = app.state.room;
|
|
167
|
+
if (deniedRoomId && deniedRoomId !== room?.id) deniedRoomId = "";
|
|
168
|
+
if (!room || room.kind === "direct" || room.joinPolicy !== "approval" || !isRoomAdmin(app) || deniedRoomId === room.id) {
|
|
169
|
+
requestsGeneration++;
|
|
170
|
+
requests = []; requestsRoomId = ""; requestSignature = "";
|
|
171
|
+
renderRequests();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (requestsLoading) return;
|
|
175
|
+
const generation = ++requestsGeneration, roomId = room.id;
|
|
176
|
+
requestsLoading = true;
|
|
177
|
+
try {
|
|
178
|
+
const data = await app.api(`/rooms/${encodeURIComponent(roomId)}/join-requests?sessionID=${encodeURIComponent(LS.sessionID)}`);
|
|
179
|
+
if (generation !== requestsGeneration || app.state.room?.id !== roomId) return;
|
|
180
|
+
requestsRoomId = roomId;
|
|
181
|
+
requests = Array.isArray(data.requests)
|
|
182
|
+
? data.requests.filter((request) => request && typeof request.sessionID === "string" && request.sessionID && typeof request.name === "string")
|
|
183
|
+
: [];
|
|
184
|
+
renderRequests();
|
|
185
|
+
} catch (error) {
|
|
186
|
+
if (generation !== requestsGeneration || app.state.room?.id !== roomId) return;
|
|
187
|
+
if (error.status === 403) { deniedRoomId = roomId; requests = []; renderRequests(); }
|
|
188
|
+
else $("#joinRequestsStatus").textContent = app.t("joinRequestsLoadFailed");
|
|
189
|
+
} finally {
|
|
190
|
+
requestsLoading = false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function renderRequests() {
|
|
195
|
+
const room = app.state.room;
|
|
196
|
+
const visible = Boolean(room && room.kind !== "direct" && room.joinPolicy === "approval" && isRoomAdmin(app) && deniedRoomId !== room.id);
|
|
197
|
+
section.hidden = !visible;
|
|
198
|
+
if (!visible) {
|
|
199
|
+
list.textContent = ""; requestSignature = "";
|
|
200
|
+
updateBadge(0);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (requestsRoomId && requestsRoomId !== room.id) {
|
|
204
|
+
requests = []; requestsRoomId = room.id; requestSignature = "";
|
|
205
|
+
}
|
|
206
|
+
const count = requests.length;
|
|
207
|
+
$("#joinRequestsHint").hidden = !room.adminSessionID;
|
|
208
|
+
$("#joinRequestsEmpty").hidden = count > 0;
|
|
209
|
+
const countNode = $("#joinRequestsCount");
|
|
210
|
+
countNode.textContent = count > 99 ? "99+" : String(count);
|
|
211
|
+
countNode.hidden = !count;
|
|
212
|
+
const signature = `${room.id}\0${app.locale}\0${requests.map((item) => `${item.sessionID}\0${item.name}\0${item.isAgent}\0${item.createdAt}`).join("\u0001")}`;
|
|
213
|
+
if (signature === requestSignature) { updateBadge(count); return; }
|
|
214
|
+
const active = list.contains(document.activeElement)
|
|
215
|
+
? { id: document.activeElement.closest("[data-request-session]")?.dataset.requestSession, action: document.activeElement.dataset.requestAction }
|
|
216
|
+
: undefined;
|
|
217
|
+
requestSignature = signature;
|
|
218
|
+
list.textContent = "";
|
|
219
|
+
for (const request of requests) list.append(requestRow(request));
|
|
220
|
+
if (active) {
|
|
221
|
+
const row = list.querySelector(`[data-request-session="${CSS.escape(active.id || "")}"]`);
|
|
222
|
+
const target = row?.querySelector(`[data-request-action="${active.action || ""}"]`);
|
|
223
|
+
target?.focus({ preventScroll: true });
|
|
224
|
+
}
|
|
225
|
+
updateBadge(count);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function requestRow(request) {
|
|
229
|
+
const item = document.createElement("li"), info = document.createElement("div"), name = document.createElement("span");
|
|
230
|
+
const meta = document.createElement("span"), kind = document.createElement("span"), actions = document.createElement("div");
|
|
231
|
+
item.className = "join-request-item"; item.dataset.requestSession = request.sessionID;
|
|
232
|
+
info.className = "join-request-info";
|
|
233
|
+
name.className = "join-request-name"; name.textContent = request.name;
|
|
234
|
+
meta.className = "join-request-meta";
|
|
235
|
+
const time = Number(request.createdAt);
|
|
236
|
+
meta.textContent = app.t("joinRequestTime", { time: app.fmtTime(Number.isFinite(time) && time > 0 ? time : Date.now()) });
|
|
237
|
+
kind.className = `join-request-kind${request.isAgent ? " agent" : ""}`;
|
|
238
|
+
kind.textContent = request.isAgent ? app.t("joinRequestAgent") : app.t("joinRequestHuman");
|
|
239
|
+
info.append(name, kind, meta);
|
|
240
|
+
actions.className = "join-request-actions";
|
|
241
|
+
const approve = actionButton("approve", app.t("joinRequestApprove"), approveText(request));
|
|
242
|
+
const deny = actionButton("deny", app.t("joinRequestDeny"), denyText(request));
|
|
243
|
+
approve.className = "btn primary small"; deny.className = "btn ghost small danger-text";
|
|
244
|
+
approve.addEventListener("click", () => void decide(request, "approve", item, approve, deny));
|
|
245
|
+
deny.addEventListener("click", () => void decide(request, "deny", item, approve, deny));
|
|
246
|
+
actions.append(approve, deny); item.append(info, actions);
|
|
247
|
+
return item;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function actionButton(action, label, ariaLabel) {
|
|
251
|
+
const button = document.createElement("button");
|
|
252
|
+
button.type = "button"; button.dataset.requestAction = action;
|
|
253
|
+
button.textContent = label; button.setAttribute("aria-label", ariaLabel);
|
|
254
|
+
return button;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async function decide(request, action, item, approve, deny) {
|
|
258
|
+
const room = app.state.room;
|
|
259
|
+
if (!room) return;
|
|
260
|
+
const index = requests.findIndex((entry) => entry.sessionID === request.sessionID);
|
|
261
|
+
item.setAttribute("aria-busy", "true"); approve.disabled = true; deny.disabled = true;
|
|
262
|
+
try {
|
|
263
|
+
await app.api(`/rooms/${encodeURIComponent(room.id)}/join-requests/${encodeURIComponent(request.sessionID)}/${action}`, {
|
|
264
|
+
method: "POST", body: JSON.stringify({ sessionID: LS.sessionID }),
|
|
265
|
+
});
|
|
266
|
+
requests = requests.filter((entry) => entry.sessionID !== request.sessionID);
|
|
267
|
+
requestSignature = "";
|
|
268
|
+
app.setText($("#joinRequestsStatus"), action === "approve" ? "joinRequestApproved" : "joinRequestDenied", { name: request.name });
|
|
269
|
+
renderRequests();
|
|
270
|
+
focusAfterRequest(index);
|
|
271
|
+
if (action === "approve") void app.refreshRoomMeta?.();
|
|
272
|
+
} catch (error) {
|
|
273
|
+
if (error.status === 404) {
|
|
274
|
+
requests = requests.filter((entry) => entry.sessionID !== request.sessionID);
|
|
275
|
+
requestSignature = "";
|
|
276
|
+
app.setText($("#joinRequestsStatus"), "joinRequestAlreadyHandled");
|
|
277
|
+
renderRequests();
|
|
278
|
+
focusAfterRequest(index);
|
|
279
|
+
} else if (error.status === 403) {
|
|
280
|
+
deniedRoomId = room.id; requests = []; renderRequests();
|
|
281
|
+
} else {
|
|
282
|
+
item.removeAttribute("aria-busy"); approve.disabled = false; deny.disabled = false;
|
|
283
|
+
app.setText($("#joinRequestsStatus"), "joinRequestActionFailed", { message: error.message });
|
|
284
|
+
if (error.status === 409) void refreshRequests();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function focusAfterRequest(index) {
|
|
290
|
+
const rows = [...list.querySelectorAll(".join-request-item")];
|
|
291
|
+
const row = rows[Math.min(index, rows.length - 1)];
|
|
292
|
+
const target = row?.querySelector('[data-request-action="approve"]') || $("#joinRequestsTitle");
|
|
293
|
+
target?.focus({ preventScroll: true });
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function updateBadge(count) {
|
|
297
|
+
const badge = $("#joinRequestBadge"), button = $("#btnMembers");
|
|
298
|
+
$("#joinRequestBadgeCount").textContent = count > 99 ? "99+" : String(count);
|
|
299
|
+
$("#joinRequestBadgeWord").textContent = count === 1 ? app.t("joinRequestBadgeOne") : app.t("joinRequestBadgeMany");
|
|
300
|
+
badge.title = count ? app.t("membersWithRequests", { count }) : "";
|
|
301
|
+
badge.hidden = !count;
|
|
302
|
+
button.setAttribute("aria-label", count ? app.t("membersWithRequests", { count }) : app.t("members"));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function renderRoomLists() {
|
|
306
|
+
app.renderRoomOptions($("#roomList"), app.state.availableRooms || []);
|
|
307
|
+
app.renderRoomOptions($("#roomListChat"), app.state.availableRooms || []);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function stopWaiting() {
|
|
311
|
+
closePending(true);
|
|
312
|
+
pending.status = "dismissed";
|
|
313
|
+
($("#joinView").hidden ? $("#msgInput") : $("#inRoomId"))?.focus();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function requestAgain() {
|
|
317
|
+
if (pending.roomId) void app.joinRoom(pending.roomId, pending.name || LS.name);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
$("#btnJoinPendingCheck").addEventListener("click", () => void checkPending(true));
|
|
321
|
+
$("#btnJoinNoticeCheck").addEventListener("click", () => void checkPending(true));
|
|
322
|
+
$("#btnJoinPendingStop").addEventListener("click", stopWaiting);
|
|
323
|
+
$("#btnJoinNoticeStop").addEventListener("click", stopWaiting);
|
|
324
|
+
$("#btnJoinPendingAgain").addEventListener("click", requestAgain);
|
|
325
|
+
$("#btnJoinNoticeAgain").addEventListener("click", requestAgain);
|
|
326
|
+
$("#btnMembers").addEventListener("click", () => {
|
|
327
|
+
setTimeout(() => { if (!$("#memberPanel").hidden) void refreshRequests(); }, 0);
|
|
328
|
+
});
|
|
329
|
+
document.addEventListener("chat-room-activated", (event) => {
|
|
330
|
+
const roomId = event.detail;
|
|
331
|
+
if (pending.roomId === roomId) {
|
|
332
|
+
pendingIds.delete(roomId);
|
|
333
|
+
closePending();
|
|
334
|
+
}
|
|
335
|
+
deniedRoomId = ""; requests = []; requestsRoomId = roomId || ""; requestSignature = "";
|
|
336
|
+
renderRequests();
|
|
337
|
+
void refreshRequests();
|
|
338
|
+
renderRoomLists();
|
|
339
|
+
});
|
|
340
|
+
document.addEventListener("visibilitychange", () => {
|
|
341
|
+
if (document.hidden) return;
|
|
342
|
+
if (pending.roomId && pending.status === "pending" && !pending.timer) scheduleCheck(0);
|
|
343
|
+
if (!panel.hidden) void refreshRequests();
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
// Locale changes must relabel rows and the open request card without another round trip.
|
|
347
|
+
const applyLocale = app.applyLocale;
|
|
348
|
+
app.applyLocale = () => {
|
|
349
|
+
applyLocale();
|
|
350
|
+
renderPendingCopy();
|
|
351
|
+
renderRequests();
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
renderRequests();
|
|
355
|
+
}
|
|
@@ -129,18 +129,18 @@ async function loadResourceCard(card, roomId, app) {
|
|
|
129
129
|
actions.className = "resource-actions"; status.className = "resource-status"; status.setAttribute("role", "status");
|
|
130
130
|
card.replaceChildren(info, actions, status);
|
|
131
131
|
const download = resourceButton("resourceDownload", resource.name, () => downloadResource(card, roomId, id, resource, app, status, download), app);
|
|
132
|
-
|
|
132
|
+
download.classList.add("resource-download");
|
|
133
|
+
if (isRoomAdmin(app)) {
|
|
134
|
+
let remove;
|
|
135
|
+
remove = resourceMenuItem("resourceDelete", () => deleteResource(card, roomId, id, resource, app, status, remove), app);
|
|
136
|
+
actions.append(resourceSplit(app, resource, download, remove));
|
|
137
|
+
} else actions.append(download);
|
|
133
138
|
if (previewKind(type)) {
|
|
134
139
|
const preview = resourceButton("resourcePreview", resource.name, () => previewResource(card, roomId, id, resource, type, preview, app, status), app);
|
|
135
140
|
actions.append(preview);
|
|
136
141
|
// Media you sent yourself is shown inline; other people's media stays collapsed.
|
|
137
142
|
if (card.closest(".msg.own")) void previewResource(card, roomId, id, resource, type, preview, app, status);
|
|
138
143
|
}
|
|
139
|
-
if (isRoomAdmin(app)) {
|
|
140
|
-
const remove = resourceButton("resourceDelete", resource.name, () => deleteResource(card, roomId, id, resource, app, status, remove), app);
|
|
141
|
-
remove.classList.add("danger-text");
|
|
142
|
-
actions.append(remove);
|
|
143
|
-
}
|
|
144
144
|
} catch (error) { if (card.isConnected) setResourceError(card, app, error?.status === 404 ? "resourceDeleted" : "resourceFailed"); }
|
|
145
145
|
}
|
|
146
146
|
function setResourceButton(button, key, name, app) {
|
|
@@ -153,6 +153,54 @@ function resourceButton(key, name, action, app) {
|
|
|
153
153
|
setResourceButton(button, key, name, app);
|
|
154
154
|
button.addEventListener("click", action); return button;
|
|
155
155
|
}
|
|
156
|
+
function resourceMenuItem(key, action, app) {
|
|
157
|
+
const button = document.createElement("button");
|
|
158
|
+
button.type = "button"; button.className = "menu-action danger-text"; button.setAttribute("role", "menuitem");
|
|
159
|
+
button.dataset.i18n = key; button.textContent = app.t(key);
|
|
160
|
+
button.addEventListener("click", action); return button;
|
|
161
|
+
}
|
|
162
|
+
function resourceSplit(app, resource, download, item) {
|
|
163
|
+
const group = document.createElement("span"), toggle = document.createElement("button"), menu = document.createElement("span");
|
|
164
|
+
group.className = "resource-split";
|
|
165
|
+
toggle.type = "button"; toggle.className = "btn ghost small resource-button resource-split-toggle";
|
|
166
|
+
toggle.setAttribute("aria-haspopup", "menu"); toggle.setAttribute("aria-expanded", "false");
|
|
167
|
+
toggle.setAttribute("data-i18n-aria-label", "resourceMoreActions");
|
|
168
|
+
toggle._i18nValues = { name: resource.name };
|
|
169
|
+
toggle.setAttribute("aria-label", app.t("resourceMoreActions", { name: resource.name }));
|
|
170
|
+
const icon = document.createElementNS("http://www.w3.org/2000/svg", "svg"), path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
171
|
+
icon.setAttribute("aria-hidden", "true"); icon.setAttribute("viewBox", "0 0 24 24"); path.setAttribute("d", "M6 9l6 6 6-6"); icon.append(path); toggle.append(icon);
|
|
172
|
+
menu.className = "resource-split-menu"; menu.hidden = true; menu.setAttribute("role", "menu"); menu.append(item);
|
|
173
|
+
group.append(download, toggle, menu);
|
|
174
|
+
function close(focusToggle = false) {
|
|
175
|
+
if (menu.hidden) return;
|
|
176
|
+
menu.hidden = true; toggle.setAttribute("aria-expanded", "false");
|
|
177
|
+
document.removeEventListener("click", outside);
|
|
178
|
+
if (focusToggle) toggle.focus();
|
|
179
|
+
}
|
|
180
|
+
function open() {
|
|
181
|
+
if (!menu.hidden) return;
|
|
182
|
+
menu.hidden = false; toggle.setAttribute("aria-expanded", "true");
|
|
183
|
+
document.addEventListener("click", outside); item.focus();
|
|
184
|
+
}
|
|
185
|
+
function outside(event) { if (!group.isConnected || !group.contains(event.target)) close(); }
|
|
186
|
+
item.addEventListener("click", () => close(), { capture: true });
|
|
187
|
+
toggle.addEventListener("click", () => { if (menu.hidden) open(); else close(true); });
|
|
188
|
+
toggle.addEventListener("keydown", (event) => {
|
|
189
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") { event.preventDefault(); open(); }
|
|
190
|
+
});
|
|
191
|
+
menu.addEventListener("keydown", (event) => {
|
|
192
|
+
const items = [...menu.querySelectorAll('[role="menuitem"]:not(:disabled)')], index = items.indexOf(document.activeElement);
|
|
193
|
+
if (event.key === "Escape") { event.preventDefault(); close(true); }
|
|
194
|
+
else if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
195
|
+
event.preventDefault(); items[(index + (event.key === "ArrowDown" ? 1 : -1) + items.length) % items.length]?.focus();
|
|
196
|
+
} else if (event.key === "Home" || event.key === "End") { event.preventDefault(); (event.key === "Home" ? items[0] : items.at(-1))?.focus(); }
|
|
197
|
+
});
|
|
198
|
+
group.addEventListener("keydown", (event) => {
|
|
199
|
+
if (event.key === "Escape" && !menu.hidden) { event.preventDefault(); close(true); }
|
|
200
|
+
});
|
|
201
|
+
group.addEventListener("focusout", (event) => { if (!menu.hidden && !group.contains(event.relatedTarget)) close(); });
|
|
202
|
+
return group;
|
|
203
|
+
}
|
|
156
204
|
async function deleteResource(card, roomId, id, resource, app, status, button) {
|
|
157
205
|
if (!confirm(app.t("resourceDeleteConfirm", { name: resource.name }))) return;
|
|
158
206
|
button.disabled = true;
|