@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
package/server/chat.html
CHANGED
|
@@ -9,9 +9,12 @@
|
|
|
9
9
|
<link rel="manifest" href="/manifest.webmanifest">
|
|
10
10
|
<link rel="apple-touch-icon" href="/assets/icons/apple-touch-icon.png">
|
|
11
11
|
<meta name="theme-color" content="#22695c">
|
|
12
|
+
<meta name="mobile-web-app-capable" content="yes">
|
|
12
13
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
13
14
|
<link rel="stylesheet" href="/assets/base.css">
|
|
15
|
+
<link rel="stylesheet" href="/assets/keyboard-hints.css">
|
|
14
16
|
<link rel="stylesheet" href="/assets/conversation.css">
|
|
17
|
+
<link rel="stylesheet" href="/assets/recall.css">
|
|
15
18
|
<link rel="stylesheet" href="/assets/attachments.css">
|
|
16
19
|
<link rel="stylesheet" href="/assets/responsive.css">
|
|
17
20
|
</head>
|
|
@@ -27,22 +30,35 @@
|
|
|
27
30
|
<!-- Join or create a room. -->
|
|
28
31
|
<section id="joinView" class="view" hidden>
|
|
29
32
|
<div class="join-shell">
|
|
30
|
-
<
|
|
33
|
+
<header class="join-head">
|
|
34
|
+
<div class="wordmark-row"><span class="brand-mark" aria-hidden="true">OC</span><p class="wordmark" data-i18n="brand">OC Chat</p><span class="version-tag">{{version}}</span></div>
|
|
31
35
|
<div class="locale-control">
|
|
32
|
-
<label for="localeSelectJoin" data-i18n="languageLabel">Language</label>
|
|
36
|
+
<label for="localeSelectJoin" class="locale-label"><svg class="locale-icon" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3c2.5 2.7 3.8 5.7 3.8 9S14.5 18.3 12 21M12 3C9.5 5.7 8.2 8.7 8.2 12s1.3 6.3 3.8 9"/></svg><span data-i18n="languageLabel">Language</span></label>
|
|
33
37
|
<select id="localeSelectJoin" class="locale-select" aria-label="Language" data-i18n-aria-label="languageLabel">
|
|
34
38
|
<option value="en">English</option>
|
|
35
39
|
<option value="zh-CN">中文</option>
|
|
36
40
|
</select>
|
|
41
|
+
<button id="btnKeysJoin" class="keys-hint" type="button" data-shortcuts aria-haspopup="dialog" aria-controls="shortcutsDialog" aria-label="Keyboard hints" data-i18n-aria-label="keyboardHints" title="Keyboard hints" data-i18n-title="keyboardHints" aria-keyshortcuts="?"><kbd class="keys-key" aria-hidden="true">?</kbd><span class="keys-label" data-i18n="shortcutsLabel">Key hints</span></button>
|
|
37
42
|
</div>
|
|
38
|
-
<div class="wordmark-row"><p class="wordmark" data-i18n="brand">OC Chat</p><span class="version-tag">{{version}}</span></div>
|
|
39
43
|
<p class="tagline" data-i18n="tagline">A lightweight chat room. Enter a room ID to join, or create a new one.</p>
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
</header>
|
|
45
|
+
<section id="installPrompt" class="install-prompt" aria-labelledby="installPromptTitle" hidden>
|
|
46
|
+
<div class="install-prompt-copy">
|
|
47
|
+
<strong id="installPromptTitle" data-i18n="installTitle">Install OC Chat</strong>
|
|
48
|
+
<p data-i18n="installBody">Add it to your home screen for a full-screen chat.</p>
|
|
49
|
+
</div>
|
|
50
|
+
<div class="install-prompt-actions">
|
|
51
|
+
<button id="btnInstallApp" class="btn primary small" type="button" data-i18n="installAction">Install</button>
|
|
52
|
+
<button id="btnInstallGuide" class="btn ghost small" type="button" data-i18n="installHow" aria-controls="installGuide" aria-expanded="false" hidden>How to install</button>
|
|
53
|
+
<button id="btnDismissInstall" class="btn ghost small" type="button" data-i18n="installNotNow">Not now</button>
|
|
54
|
+
</div>
|
|
55
|
+
<p id="installGuide" class="install-guide" data-i18n="installIosGuide" hidden>Tap Share, then Add to Home Screen.</p>
|
|
56
|
+
</section>
|
|
57
|
+
<div class="join-entries">
|
|
58
|
+
<label class="entry-card identity-card field join-name">
|
|
59
|
+
<span class="field-label identity-title" data-i18n="nameLabel">Your name</span>
|
|
42
60
|
<input id="inName" class="input" placeholder="What should we call you?" data-i18n-placeholder="namePlaceholder" autocomplete="nickname" maxlength="24">
|
|
43
61
|
</label>
|
|
44
|
-
</div>
|
|
45
|
-
<div class="join-entries">
|
|
46
62
|
<form id="joinForm" class="entry-card" novalidate>
|
|
47
63
|
<h2 data-i18n="joinRoomTitle">Join a room</h2>
|
|
48
64
|
<p class="entry-hint" data-i18n="joinRoomHint">Someone shared a room ID with you? Paste it here.</p>
|
|
@@ -59,10 +75,28 @@
|
|
|
59
75
|
<span class="field-label" data-i18n="newRoomNameLabel">New room name</span>
|
|
60
76
|
<input id="inRoomName" class="input" placeholder="e.g. Weekend movie night" data-i18n-placeholder="newRoomNamePlaceholder" maxlength="40">
|
|
61
77
|
</label>
|
|
78
|
+
<div class="join-policy">
|
|
79
|
+
<input id="inApprovalRequired" type="checkbox" role="switch" aria-describedby="inApprovalRequiredHint">
|
|
80
|
+
<label for="inApprovalRequired" class="join-policy-label" data-i18n="requireApproval">Require approval to join</label>
|
|
81
|
+
</div>
|
|
82
|
+
<p id="inApprovalRequiredHint" class="hint join-policy-hint" data-i18n="requireApprovalHint">New members need a human administrator's approval. Agents may also be approved by the administrator agent.</p>
|
|
62
83
|
<button class="btn ghost" type="submit" id="btnCreate" data-i18n="createRoom">Create room</button>
|
|
63
84
|
</form>
|
|
64
85
|
<div id="joinError" class="alert" role="alert" hidden></div>
|
|
65
86
|
</div>
|
|
87
|
+
<section id="joinPending" class="join-pending" hidden aria-labelledby="joinPendingTitle">
|
|
88
|
+
<span class="join-pending-mark" aria-hidden="true"><svg viewBox="0 0 24 24"><rect x="5" y="10" width="14" height="10" rx="2"/><path d="M8 10V7a4 4 0 0 1 8 0v3"/></svg></span>
|
|
89
|
+
<div class="join-pending-copy">
|
|
90
|
+
<h2 id="joinPendingTitle" tabindex="-1" data-i18n="joinPendingTitle">Waiting for approval</h2>
|
|
91
|
+
<p id="joinPendingBody" role="status" aria-live="polite"></p>
|
|
92
|
+
<p id="joinPendingHint" class="hint"></p>
|
|
93
|
+
</div>
|
|
94
|
+
<div class="join-pending-actions">
|
|
95
|
+
<button id="btnJoinPendingCheck" class="btn ghost small" type="button" data-i18n="joinPendingCheck">Check again</button>
|
|
96
|
+
<button id="btnJoinPendingAgain" class="btn primary small" type="button" data-i18n="joinPendingAgain" hidden>Request again</button>
|
|
97
|
+
<button id="btnJoinPendingStop" class="btn ghost small" type="button" data-i18n="joinPendingStop">Stop waiting</button>
|
|
98
|
+
</div>
|
|
99
|
+
</section>
|
|
66
100
|
<section class="room-list">
|
|
67
101
|
<h2 data-i18n="existingRooms">Existing rooms</h2>
|
|
68
102
|
<ul id="roomList"></ul>
|
|
@@ -94,10 +128,20 @@
|
|
|
94
128
|
<div class="rail-label"><span data-i18n="existingRooms">Rooms</span><span class="rail-tools"><button id="btnNewRoom" class="icon-btn" type="button" aria-label="Create a room" data-i18n-aria-label="newRoom"><svg aria-hidden="true" viewBox="0 0 24 24"><path d="M12 5v14M5 12h14"/></svg></button><button id="btnRefreshRooms" class="icon-btn" type="button" aria-label="Refresh rooms" data-i18n-aria-label="refreshRooms"><svg aria-hidden="true" viewBox="0 0 24 24"><path d="M20 7v5h-5M4 17v-5h5"/><path d="M5.6 9a7 7 0 0 1 11.8-2L20 12M4 12l2.6 5a7 7 0 0 0 11.8-2"/></svg></button></span></div>
|
|
95
129
|
<form id="railRoomForm" class="rail-composer" hidden>
|
|
96
130
|
<label class="field"><span class="field-label" data-i18n="newRoomNameLabel">New room name</span><input id="inRoomNameChat" class="input" maxlength="40" data-i18n-placeholder="newRoomNamePlaceholder" placeholder="e.g. Weekend movie night"></label>
|
|
131
|
+
<div class="join-policy rail-join-policy">
|
|
132
|
+
<input id="inApprovalRequiredChat" type="checkbox" role="switch" aria-describedby="inApprovalRequiredChatHint">
|
|
133
|
+
<label for="inApprovalRequiredChat" class="join-policy-label" data-i18n="requireApproval">Require approval to join</label>
|
|
134
|
+
</div>
|
|
135
|
+
<p id="inApprovalRequiredChatHint" class="hint join-policy-hint rail-join-policy-hint" data-i18n="requireApprovalHint">New members need a human administrator's approval. Agents may also be approved by the administrator agent.</p>
|
|
97
136
|
<button id="btnCreateChatRoom" class="btn primary small" type="submit" data-i18n="createRoom">Create room</button>
|
|
98
137
|
</form>
|
|
99
138
|
<ul id="roomListChat" class="rail-rooms"></ul>
|
|
100
139
|
<p id="roomListChatEmpty" class="hint" data-i18n="noRooms" hidden></p>
|
|
140
|
+
<p id="railKeyHint" class="rail-key-hint" hidden><span class="keys-combo"><kbd class="keys-key">↑</kbd><kbd class="keys-key">↓</kbd></span><span data-i18n="switchRoomsHint">Switch rooms</span></p>
|
|
141
|
+
<div id="railInstall" class="rail-install" hidden>
|
|
142
|
+
<button id="btnRailInstall" class="btn ghost small rail-install-btn" type="button"><svg aria-hidden="true" viewBox="0 0 24 24"><path d="M12 4v10M8 10l4 4 4-4M5 19h14"/></svg><span data-i18n="installAction">Install</span></button>
|
|
143
|
+
<p id="railInstallGuide" class="hint" data-i18n="installIosGuide" hidden>Tap Share, then Add to Home Screen.</p>
|
|
144
|
+
</div>
|
|
101
145
|
<div class="rail-foot">
|
|
102
146
|
<div class="anchor user-menu-anchor">
|
|
103
147
|
<button id="btnSettings" class="user-menu-trigger" type="button" aria-label="Your profile and settings" data-i18n-aria-label="profileMenu" aria-haspopup="dialog" aria-expanded="false" aria-controls="chatSettings">
|
|
@@ -105,7 +149,7 @@
|
|
|
105
149
|
</button>
|
|
106
150
|
<div class="panel user-menu-panel" id="chatSettings" role="dialog" aria-modal="false" aria-labelledby="settingsHeading" hidden>
|
|
107
151
|
<h3 id="settingsHeading" data-i18n="settings">Settings</h3>
|
|
108
|
-
<label class="field"><span class="field-label" data-i18n="languageLabel">Language</span><select id="localeSelectSettings" class="locale-select"><option value="en">English</option><option value="zh-CN">中文</option></select></label>
|
|
152
|
+
<label class="field"><span class="field-label locale-label"><svg class="locale-icon" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3c2.5 2.7 3.8 5.7 3.8 9S14.5 18.3 12 21M12 3C9.5 5.7 8.2 8.7 8.2 12s1.3 6.3 3.8 9"/></svg><span data-i18n="languageLabel">Language</span></span><select id="localeSelectSettings" class="locale-select"><option value="en">English</option><option value="zh-CN">中文</option></select></label>
|
|
109
153
|
<label class="field"><span class="field-label" data-i18n="tokenOptional">Access token (optional)</span><input id="inTokenChat" class="input" type="password" placeholder="Enter if the server requires it" data-i18n-placeholder="tokenPlaceholder" autocomplete="off" spellcheck="false"></label>
|
|
110
154
|
<button class="btn ghost small" type="button" data-token-save="inTokenChat" data-i18n="save">Save</button>
|
|
111
155
|
<p id="tokenHint" class="hint" data-i18n="tokenRequired" hidden>The server requires an access token (401).</p>
|
|
@@ -120,6 +164,11 @@
|
|
|
120
164
|
<form id="editRoomForm" class="admin-guide">
|
|
121
165
|
<label class="field"><span class="field-label" data-i18n="roomNameLabel">Room name</span><input id="editRoomName" class="input" maxlength="64" autocomplete="off" required></label>
|
|
122
166
|
<label class="field"><span class="field-label" data-i18n="roomDescriptionLabel">Description</span><textarea id="editRoomDescription" class="input" rows="3" maxlength="2000"></textarea></label>
|
|
167
|
+
<div class="join-policy admin-join-policy">
|
|
168
|
+
<input id="editRoomJoinPolicy" type="checkbox" role="switch" aria-describedby="editRoomJoinPolicyHint">
|
|
169
|
+
<label for="editRoomJoinPolicy" class="join-policy-label" data-i18n="requireApproval">Require approval to join</label>
|
|
170
|
+
</div>
|
|
171
|
+
<p id="editRoomJoinPolicyHint" class="hint join-policy-hint" data-i18n="joinPolicyEditHint">New members need a human administrator's approval. Turning this off clears all pending requests.</p>
|
|
123
172
|
<fieldset class="admin-fieldset"><legend class="field-label" data-i18n="adminIdsLabel">Human administrators</legend><div id="editRoomAdminIds" class="admin-checklist"></div><p id="editRoomAdminIdsEmpty" class="hint" data-i18n="adminIdsEmpty" hidden>No other members are in this room yet.</p><p class="hint" data-i18n="adminIdsHint">These members can edit room details, manage members, delete files, and choose a successor. The owner always has the same powers.</p></fieldset>
|
|
124
173
|
<label class="field"><span class="field-label" data-i18n="successorLabel">Successor if the owner leaves</span><select id="editRoomSuccessor" class="admin-select"></select></label>
|
|
125
174
|
<p class="hint" data-i18n="successorHint">If the owner leaves, this person becomes owner. If an administrator leaves, this person takes that role. Leave empty to use the longest-present member.</p>
|
|
@@ -141,17 +190,17 @@
|
|
|
141
190
|
<div id="reminderCronFields" hidden><label class="field"><span class="field-label" data-i18n="reminderCron">5-field CRON expression</span><input id="reminderCron" class="input" placeholder="0 9 * * 1-5" autocomplete="off"></label></div>
|
|
142
191
|
<label class="field"><span class="field-label" data-i18n="reminderTimezone">Timezone override (optional)</span><input id="reminderTimezone" class="input" autocomplete="off"></label>
|
|
143
192
|
<p class="hint" data-i18n="reminderTimezoneHint">Leave blank to use the server timezone. Enter an IANA timezone to override it.</p>
|
|
144
|
-
<label class="field"><span class="field-label" data-i18n="reminderText">Reminder text</span><textarea id="reminderText" class="input" rows="3" maxlength="
|
|
193
|
+
<label class="field"><span class="field-label" data-i18n="reminderText">Reminder text</span><textarea id="reminderText" class="input" rows="3" maxlength="2000" required aria-describedby="reminderTemplateHint"></textarea></label>
|
|
145
194
|
<p id="reminderTemplateHint" class="hint" data-i18n="reminderTemplateHint">Use {{time}}, {{initiator}}, and {{room}} in your message.</p>
|
|
146
195
|
<p id="reminderDialogStatus" class="hint" role="status" aria-live="polite"></p>
|
|
147
|
-
<div class="announcement-actions"><button class="btn primary small" type="submit" data-i18n="reminderCreate">Create reminder</button><button id="btnCancelReminder" class="btn ghost small" type="button" data-i18n="close">Close</button></div>
|
|
196
|
+
<div class="announcement-actions"><button id="btnSubmitReminder" class="btn primary small" type="submit" data-i18n="reminderCreate">Create reminder</button><button id="btnCancelReminder" class="btn ghost small" type="button" data-i18n="close">Close</button></div>
|
|
148
197
|
</form>
|
|
149
198
|
</dialog>
|
|
150
199
|
<dialog id="announcementDialog" class="admin-dialog announcement-dialog" aria-labelledby="announcementDialogHeading">
|
|
151
200
|
<header class="admin-dialog-head"><h2 id="announcementDialogHeading" data-i18n="announcementNew">New announcement</h2><div class="admin-dialog-actions"><button id="btnCloseAnnouncement" class="reader-close" type="button" aria-label="Close" data-i18n-aria-label="close"><svg class="close-icon" aria-hidden="true" viewBox="0 0 24 24"><path d="M6 6l12 12M18 6 6 18"/></svg></button></div></header>
|
|
152
201
|
<form id="announcementForm" class="admin-guide announcement-form">
|
|
153
|
-
<label class="field"><span class="field-label" data-i18n="announcementName">Name</span><input id="announcementName" class="input" maxlength="
|
|
154
|
-
<label class="field"><span class="field-label" data-i18n="announcementContent">Content</span><textarea id="announcementContent" class="input" rows="4" maxlength="
|
|
202
|
+
<label class="field"><span class="field-label" data-i18n="announcementName">Name</span><input id="announcementName" class="input" maxlength="64" autocomplete="off" required></label>
|
|
203
|
+
<label class="field"><span class="field-label" data-i18n="announcementContent">Content</span><textarea id="announcementContent" class="input" rows="4" maxlength="5000" aria-describedby="announcementCount"></textarea></label>
|
|
155
204
|
<p id="announcementCount" class="hint">0 / 5000</p>
|
|
156
205
|
<p id="announcementDialogStatus" class="hint" role="status" aria-live="polite"></p>
|
|
157
206
|
<div class="announcement-actions"><button id="btnSaveAnnouncement" class="btn primary small" type="submit" data-i18n="save">Save</button><button id="btnDeleteAnnouncement" class="btn ghost small danger-text" type="button" data-i18n="announcementDelete" hidden>Delete</button><button id="btnCancelAnnouncement" class="btn ghost small" type="button" data-i18n="close">Close</button></div>
|
|
@@ -165,6 +214,7 @@
|
|
|
165
214
|
<button type="button" id="btnCopyId" class="copy-id" aria-label="Copy room ID" data-i18n-aria-label="copyRoomId" title="Click to copy the full room ID" data-i18n-title="copyRoomIdTitle">
|
|
166
215
|
<span class="mono" id="roomIdShort"></span><span class="copy-ok" data-i18n="copied">Copied</span>
|
|
167
216
|
</button>
|
|
217
|
+
<span id="roomPolicy" class="room-policy" data-i18n="approvalRequired" hidden>Approval required</span>
|
|
168
218
|
</p>
|
|
169
219
|
<p id="roomDescription" class="room-description" hidden></p>
|
|
170
220
|
</div>
|
|
@@ -197,9 +247,19 @@
|
|
|
197
247
|
</section>
|
|
198
248
|
</div>
|
|
199
249
|
<div class="anchor">
|
|
200
|
-
<button class="chip" type="button" id="btnMembers" aria-label="Members" data-i18n-aria-label="members" aria-haspopup="true" aria-expanded="false"><svg class="action-icon" aria-hidden="true" viewBox="0 0 24 24"><circle cx="9" cy="8" r="3"/><path d="M3.5 19v-1.5a5.5 5.5 0 0 1 11 0V19zM16 5.5a3 3 0 0 1 0 5.8M17 14a4.5 4.5 0 0 1 3.5 4.4V19h-3"/></svg><span class="action-label" data-i18n="members">Members</span></button>
|
|
250
|
+
<button class="chip" type="button" id="btnMembers" aria-label="Members" data-i18n-aria-label="members" aria-haspopup="true" aria-expanded="false"><svg class="action-icon" aria-hidden="true" viewBox="0 0 24 24"><circle cx="9" cy="8" r="3"/><path d="M3.5 19v-1.5a5.5 5.5 0 0 1 11 0V19zM16 5.5a3 3 0 0 1 0 5.8M17 14a4.5 4.5 0 0 1 3.5 4.4V19h-3"/></svg><span class="action-label" data-i18n="members">Members</span><span id="joinRequestBadge" class="question-badge join-request-badge" aria-hidden="true" hidden><span id="joinRequestBadgeCount"></span><span id="joinRequestBadgeWord" class="join-request-badge-word"></span></span></button>
|
|
201
251
|
<div class="panel" id="memberPanel" hidden>
|
|
202
252
|
<h3 data-i18n="members">Members</h3>
|
|
253
|
+
<section id="joinRequests" class="join-requests" hidden aria-labelledby="joinRequestsTitle">
|
|
254
|
+
<div class="join-requests-head">
|
|
255
|
+
<h4 id="joinRequestsTitle" tabindex="-1" data-i18n="joinRequestsTitle">Join requests</h4>
|
|
256
|
+
<span id="joinRequestsCount" class="join-requests-count" hidden></span>
|
|
257
|
+
</div>
|
|
258
|
+
<p id="joinRequestsHint" class="hint" data-i18n="joinRequestsHint" hidden>Agent requests can also be approved by the administrator agent.</p>
|
|
259
|
+
<p id="joinRequestsStatus" class="hint" role="status" aria-live="polite"></p>
|
|
260
|
+
<ul id="joinRequestList" class="join-request-list" aria-label="Join requests" data-i18n-aria-label="joinRequestsTitle"></ul>
|
|
261
|
+
<p id="joinRequestsEmpty" class="hint" data-i18n="joinRequestsEmpty" hidden>No pending requests.</p>
|
|
262
|
+
</section>
|
|
203
263
|
<ul id="memberList"></ul>
|
|
204
264
|
<p id="memberEmpty" class="hint" data-i18n="noMembers" hidden>No members yet.</p>
|
|
205
265
|
</div>
|
|
@@ -239,22 +299,31 @@
|
|
|
239
299
|
</aside>
|
|
240
300
|
|
|
241
301
|
<footer class="composer">
|
|
302
|
+
<section id="joinNotice" class="join-notice" role="status" aria-live="polite" hidden>
|
|
303
|
+
<span id="joinNoticeText" class="join-notice-text"></span>
|
|
304
|
+
<span class="join-notice-actions">
|
|
305
|
+
<button id="btnJoinNoticeCheck" class="btn ghost small" type="button" data-i18n="joinPendingCheck">Check again</button>
|
|
306
|
+
<button id="btnJoinNoticeAgain" class="btn primary small" type="button" data-i18n="joinPendingAgain" hidden>Request again</button>
|
|
307
|
+
<button id="btnJoinNoticeStop" class="btn ghost small" type="button" data-i18n="joinPendingStop">Stop waiting</button>
|
|
308
|
+
</span>
|
|
309
|
+
</section>
|
|
242
310
|
<p id="sendError" class="send-error" role="alert" hidden></p>
|
|
243
311
|
<section id="replyPreview" class="reply-preview" aria-label="Replying to" data-i18n-aria-label="replyingTo" hidden><div><span data-i18n="replyingTo">Replying to</span> <strong id="replyPreviewName"></strong><p id="replyPreviewText"></p></div><button id="replyCancel" type="button" class="reply-cancel" aria-label="Cancel reply" data-i18n-aria-label="cancelReply">×</button></section>
|
|
244
312
|
<div id="mentionPicker" class="mention-picker" role="listbox" aria-label="Choose a member to mention" data-i18n-aria-label="mentionMembers" hidden></div>
|
|
245
313
|
<section id="attachmentTray" class="attachment-tray" aria-label="Attachments" data-i18n-aria-label="attachments" hidden>
|
|
246
|
-
<p id="attachmentVolatile" class="attachment-volatile" data-i18n="attachmentVolatile" hidden
|
|
314
|
+
<p id="attachmentVolatile" class="attachment-volatile" data-i18n="attachmentVolatile" hidden>Pasted files are recovered after reload; picked files stay in this tab.</p>
|
|
247
315
|
<ul id="attachmentList" class="attachment-list"></ul>
|
|
248
316
|
<p id="attachmentStatus" class="attachment-status" role="status" aria-live="polite"></p>
|
|
249
317
|
</section>
|
|
250
318
|
<div class="composer-row">
|
|
251
319
|
<button class="attachment-button" type="button" id="btnAddAttachments" aria-label="Add files" data-i18n-aria-label="addFiles" aria-controls="attachmentPicker" disabled><svg aria-hidden="true" viewBox="0 0 24 24"><path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.82-2.83l8.49-8.48"/></svg></button>
|
|
252
320
|
<input id="attachmentPicker" type="file" multiple hidden>
|
|
253
|
-
<div id="msgInput" class="input message-editor" role="textbox" aria-multiline="true" aria-label="Message" data-i18n-aria-label="messagePlaceholder" aria-placeholder="Type a message, Enter to send, Shift+Enter for a new line" data-i18n-aria-placeholder="messagePlaceholder" aria-autocomplete="list" aria-controls="mentionPicker" aria-expanded="false" contenteditable="false" aria-disabled="true" tabindex="-1"></div>
|
|
321
|
+
<div id="msgInput" class="input message-editor" role="textbox" aria-multiline="true" aria-label="Message" data-i18n-aria-label="messagePlaceholder" aria-placeholder="Type a message, Enter to send, Shift+Enter for a new line" data-i18n-aria-placeholder="messagePlaceholder" aria-autocomplete="list" aria-controls="mentionPicker" aria-expanded="false" aria-keyshortcuts="Enter Shift+Enter" contenteditable="false" aria-disabled="true" tabindex="-1"></div>
|
|
254
322
|
<button class="btn primary" type="button" id="btnSend" data-i18n="send" disabled>Send</button>
|
|
255
323
|
</div>
|
|
256
324
|
<div class="composer-meta">
|
|
257
|
-
<
|
|
325
|
+
<button id="btnKeysChat" class="keys-hint composer-keys" type="button" data-shortcuts aria-haspopup="dialog" aria-controls="shortcutsDialog" aria-label="Keyboard hints" data-i18n-aria-label="keyboardHints" title="Keyboard hints" data-i18n-title="keyboardHints" aria-keyshortcuts="?"><kbd class="keys-key" aria-hidden="true">?</kbd><span class="keys-label" data-i18n="shortcutsLabel">Key hints</span></button>
|
|
326
|
+
<p id="draftCount" class="draft-count">0 / 5000</p>
|
|
258
327
|
</div>
|
|
259
328
|
</footer>
|
|
260
329
|
<div id="attachmentDropOverlay" class="attachment-drop-overlay" role="status" aria-live="polite" data-i18n="dropFilesHere" hidden></div>
|
|
@@ -263,6 +332,11 @@
|
|
|
263
332
|
<!-- Full-screen view of an image already loaded in the message list. -->
|
|
264
333
|
<dialog id="imageDialog" class="image-dialog" aria-label="Image preview" data-i18n-aria-label="imagePreviewTitle">
|
|
265
334
|
<button id="btnCloseImage" class="image-dialog-close" type="button" aria-label="Close" data-i18n-aria-label="close"><svg class="close-icon" aria-hidden="true" viewBox="0 0 24 24"><path d="M6 6l12 12M18 6 6 18"/></svg></button>
|
|
335
|
+
<div class="image-dialog-tools" role="group" aria-label="Image zoom" data-i18n-aria-label="imageZoomControls">
|
|
336
|
+
<button id="btnZoomOut" class="image-dialog-tool" type="button" aria-label="Zoom out" data-i18n-aria-label="zoomOut">−</button>
|
|
337
|
+
<button id="btnZoomReset" class="image-dialog-tool image-dialog-reset" type="button" aria-label="Reset zoom" data-i18n-aria-label="zoomReset"><span id="zoomLevel">100%</span></button>
|
|
338
|
+
<button id="btnZoomIn" class="image-dialog-tool" type="button" aria-label="Zoom in" data-i18n-aria-label="zoomIn">+</button>
|
|
339
|
+
</div>
|
|
266
340
|
<img id="imageDialogImage" alt="">
|
|
267
341
|
</dialog>
|
|
268
342
|
|
|
@@ -273,6 +347,62 @@
|
|
|
273
347
|
<button id="btnOwnerOnlyOk" class="btn ghost small" type="button" data-i18n="close">Close</button>
|
|
274
348
|
</dialog>
|
|
275
349
|
|
|
350
|
+
<!-- The visible contract that every control works from the keyboard. -->
|
|
351
|
+
<dialog id="shortcutsDialog" class="keys-dialog" aria-labelledby="shortcutsHeading">
|
|
352
|
+
<header class="keys-dialog-head">
|
|
353
|
+
<h2 id="shortcutsHeading" tabindex="-1" data-i18n="shortcutsTitle">Keyboard shortcuts</h2>
|
|
354
|
+
<button id="btnCloseShortcuts" class="reader-close" type="button" aria-label="Close" data-i18n-aria-label="close"><svg class="close-icon" aria-hidden="true" viewBox="0 0 24 24"><path d="M6 6l12 12M18 6 6 18"/></svg></button>
|
|
355
|
+
</header>
|
|
356
|
+
<p class="keys-lead" data-i18n="shortcutsLead">Every control works from the keyboard. Tags show the keys that work.</p>
|
|
357
|
+
<div class="keys-sheet-actions"><button id="btnToggleHints" class="btn ghost small" type="button" data-i18n="hintsHide">Hide tags on controls</button></div>
|
|
358
|
+
<section class="keys-section">
|
|
359
|
+
<h3 data-i18n="shortcutsWriting">Writing</h3>
|
|
360
|
+
<ul class="keys-list">
|
|
361
|
+
<li><span class="keys-combo"><kbd class="keys-key">Enter</kbd></span><span data-i18n="shortcutsSend">Send the message</span></li>
|
|
362
|
+
<li><span class="keys-combo"><kbd class="keys-key">Shift</kbd><span class="keys-sep">+</span><kbd class="keys-key">Enter</kbd></span><span data-i18n="shortcutsNewline">Start a new line</span></li>
|
|
363
|
+
<li><span class="keys-combo"><kbd class="keys-key">↑</kbd><kbd class="keys-key">↓</kbd><span class="keys-sep">·</span><kbd class="keys-key">Enter</kbd></span><span data-i18n="shortcutsMention">Choose a member to mention</span></li>
|
|
364
|
+
</ul>
|
|
365
|
+
</section>
|
|
366
|
+
<section class="keys-section">
|
|
367
|
+
<h3 data-i18n="shortcutsRooms">Rooms</h3>
|
|
368
|
+
<ul class="keys-list">
|
|
369
|
+
<li><span class="keys-combo"><kbd class="keys-key">Alt</kbd><span class="keys-sep">+</span><kbd class="keys-key">↑</kbd><span class="keys-sep">/</span><kbd class="keys-key">↓</kbd></span><span data-i18n="shortcutsSwitchRoom">Switch to the previous or next room</span></li>
|
|
370
|
+
</ul>
|
|
371
|
+
</section>
|
|
372
|
+
<section class="keys-section">
|
|
373
|
+
<h3 data-i18n="shortcutsReading">Reading</h3>
|
|
374
|
+
<ul class="keys-list">
|
|
375
|
+
<li><span class="keys-combo"><kbd class="keys-key">PageUp</kbd><span class="keys-sep">/</span><kbd class="keys-key">PageDown</kbd></span><span data-i18n="shortcutsScroll">Scroll messages while typing</span></li>
|
|
376
|
+
</ul>
|
|
377
|
+
</section>
|
|
378
|
+
<section class="keys-section">
|
|
379
|
+
<h3 data-i18n="shortcutsMenus">Menus and dialogs</h3>
|
|
380
|
+
<ul class="keys-list">
|
|
381
|
+
<li><span class="keys-combo"><kbd class="keys-key">Esc</kbd></span><span data-i18n="shortcutsClose">Close the open menu, panel, or dialog</span></li>
|
|
382
|
+
</ul>
|
|
383
|
+
</section>
|
|
384
|
+
<section class="keys-section">
|
|
385
|
+
<h3 data-i18n="shortcutsEverywhere">Everywhere</h3>
|
|
386
|
+
<ul class="keys-list">
|
|
387
|
+
<li><span class="keys-combo"><kbd class="keys-key">Tab</kbd><span class="keys-sep">/</span><kbd class="keys-key">Shift</kbd><span class="keys-sep">+</span><kbd class="keys-key">Tab</kbd></span><span data-i18n="shortcutsTab">Move between controls</span></li>
|
|
388
|
+
<li><span class="keys-combo"><kbd class="keys-key">Enter</kbd><span class="keys-sep">/</span><kbd class="keys-key">Space</kbd></span><span data-i18n="shortcutsActivate">Use the focused control</span></li>
|
|
389
|
+
<li><span class="keys-combo"><kbd class="keys-key">?</kbd></span><span data-i18n="shortcutsOpen">Open this shortcut list</span></li>
|
|
390
|
+
</ul>
|
|
391
|
+
</section>
|
|
392
|
+
</dialog>
|
|
393
|
+
|
|
394
|
+
<!-- Badges over every visible control; the legend can hide them. -->
|
|
395
|
+
<div id="keyboardHints" class="keys-overlay" hidden>
|
|
396
|
+
<div id="keyboardHintMarks" class="keys-marks" aria-hidden="true"></div>
|
|
397
|
+
<div class="keys-legend">
|
|
398
|
+
<p class="keys-legend-text" data-i18n="hintsLegend">Tab reaches · Enter / Space activates</p>
|
|
399
|
+
<div class="keys-legend-actions">
|
|
400
|
+
<button id="btnAllShortcuts" class="keys-legend-btn" type="button" data-i18n="allShortcuts">All shortcuts</button>
|
|
401
|
+
<button id="btnCloseHints" class="keys-legend-close" type="button" aria-label="Hide tags on controls" data-i18n-aria-label="hintsHide"><svg class="close-icon" aria-hidden="true" viewBox="0 0 24 24"><path d="M6 6l12 12M18 6 6 18"/></svg></button>
|
|
402
|
+
</div>
|
|
403
|
+
</div>
|
|
404
|
+
</div>
|
|
405
|
+
|
|
276
406
|
</main>
|
|
277
407
|
|
|
278
408
|
<script src="/assets/marked-18.0.4.js"></script>
|
package/server/inbox.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type InboxItem = Pick<Message, "id" | "roomId" | "senderId" | "senderSess
|
|
|
6
6
|
roomKind?: "group" | "direct";
|
|
7
7
|
answerQuestionExcerpt?: string;
|
|
8
8
|
};
|
|
9
|
-
export type InboxResult = { member: boolean; items: InboxItem[]; queuedTs: Record<string, number>; hasMore: boolean };
|
|
9
|
+
export type InboxResult = { member: boolean; items: InboxItem[]; queuedTs: Record<string, number>; hasMore: boolean; recallVersion: number };
|
|
10
10
|
|
|
11
11
|
export async function readInbox(sessionID: string, roomFilter: string | null, excludeSelf: boolean, afterTs?: number): Promise<InboxResult> {
|
|
12
12
|
return readInboxMessages(sessionID, roomFilter, excludeSelf, excludeSelf ? 20 : 100, afterTs);
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { databasePath, listJoinRequests, readJoinRequest, readState } from "../src/state/store.ts";
|
|
2
|
+
import { findJoinRequest, removeJoinRequest, writeSqliteStateWithDatabase } from "../src/state/sqlite-state.ts";
|
|
3
|
+
import { binding, tx, validCurrent } from "./admin-state";
|
|
4
|
+
import { hasAdminCapability } from "./admin-auth";
|
|
5
|
+
import { isRoomAdmin } from "./room-owner";
|
|
6
|
+
import { joinRoomMember } from "./room-join";
|
|
7
|
+
|
|
8
|
+
const json = (body: unknown, status = 200) => Response.json(body, { status, headers: { "Cache-Control": "no-store" } });
|
|
9
|
+
|
|
10
|
+
async function agentReviewer(req: Request, roomID: string, actor: string): Promise<boolean> {
|
|
11
|
+
return tx(db => {
|
|
12
|
+
const b = binding(db, roomID);
|
|
13
|
+
return Boolean(b && b.target_room_id === roomID && b.session_id === actor && validCurrent(db, b) && hasAdminCapability(req, b));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function humanReviewer(roomID: string, actor: string): Promise<boolean> {
|
|
18
|
+
return readState((svc, registry) => {
|
|
19
|
+
const entry = registry[roomID]?.[actor];
|
|
20
|
+
return Boolean(entry && isRoomAdmin(svc.getRoom(roomID), entry));
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function bounded(value: unknown): value is string {
|
|
25
|
+
return typeof value === "string" && value.length > 0 && value.length <= 128;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Approval-protected joins: requests stay in SQLite until a reviewer consumes
|
|
29
|
+
// them; denial removes the row so the requester can try again.
|
|
30
|
+
export async function joinRequestRoutes(req: Request, url: URL): Promise<Response | undefined> {
|
|
31
|
+
const status = url.pathname.match(/^\/rooms\/([^/]+)\/join-requests\/status$/);
|
|
32
|
+
const list = url.pathname.match(/^\/rooms\/([^/]+)\/join-requests$/);
|
|
33
|
+
const action = url.pathname.match(/^\/rooms\/([^/]+)\/join-requests\/([^/]+)\/(approve|deny)$/);
|
|
34
|
+
if (!status && !list && !action) return undefined;
|
|
35
|
+
|
|
36
|
+
if (status && req.method === "GET") {
|
|
37
|
+
const roomID = decodeURIComponent(status[1]!);
|
|
38
|
+
const sessionID = url.searchParams.get("sessionID") ?? "";
|
|
39
|
+
if (!bounded(sessionID)) return json({ error: "sessionID is required" }, 400);
|
|
40
|
+
const joined = await readState((svc, registry) => {
|
|
41
|
+
svc.getRoom(roomID);
|
|
42
|
+
return Boolean(registry[roomID]?.[sessionID]);
|
|
43
|
+
});
|
|
44
|
+
if (joined) return json({ status: "joined" });
|
|
45
|
+
return json({ status: await readJoinRequest(roomID, sessionID) ? "pending" : "none" });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (list && req.method === "GET") {
|
|
49
|
+
const roomID = decodeURIComponent(list[1]!);
|
|
50
|
+
const actor = url.searchParams.get("sessionID") ?? "";
|
|
51
|
+
if (!bounded(actor)) return json({ error: "sessionID is required" }, 400);
|
|
52
|
+
const human = await humanReviewer(roomID, actor);
|
|
53
|
+
const agent = !human && await agentReviewer(req, roomID, actor);
|
|
54
|
+
if (!human && !agent) return json({ error: "only room administrators can review join requests" }, 403);
|
|
55
|
+
const requests = await listJoinRequests(roomID, agent);
|
|
56
|
+
return json({ requests: requests.map(({ sessionID, participantId, name, isAgent, createdAt }) =>
|
|
57
|
+
({ sessionID, participantId, name, isAgent, createdAt })) });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (action && req.method === "POST") {
|
|
61
|
+
const roomID = decodeURIComponent(action[1]!);
|
|
62
|
+
const requestSessionID = decodeURIComponent(action[2]!);
|
|
63
|
+
const decision = action[3]!;
|
|
64
|
+
const body: unknown = await req.json();
|
|
65
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) return json({ error: "JSON object body is required" }, 400);
|
|
66
|
+
const actor = typeof (body as Record<string, unknown>).sessionID === "string" ? (body as Record<string, string>).sessionID : "";
|
|
67
|
+
if (!bounded(actor)) return json({ error: "sessionID is required" }, 400);
|
|
68
|
+
const result = await writeSqliteStateWithDatabase(databasePath(), (svc, registry, db) => {
|
|
69
|
+
const room = svc.getRoom(roomID);
|
|
70
|
+
const actorEntry = registry[roomID]?.[actor];
|
|
71
|
+
const human = Boolean(actorEntry && isRoomAdmin(room, actorEntry));
|
|
72
|
+
const b = binding(db, roomID);
|
|
73
|
+
const agent = !human && Boolean(b && b.target_room_id === roomID && b.session_id === actor && validCurrent(db, b) && hasAdminCapability(req, b));
|
|
74
|
+
if (!human && !agent) return { status: 403 as const, error: "only room administrators can review join requests" };
|
|
75
|
+
const request = findJoinRequest(db, roomID, requestSessionID);
|
|
76
|
+
if (!request) return { status: 404 as const, error: "join request not found" };
|
|
77
|
+
if (agent && !request.isAgent) return { status: 403 as const, error: "the management agent can only review agent requests" };
|
|
78
|
+
if (decision === "deny") {
|
|
79
|
+
removeJoinRequest(db, roomID, requestSessionID);
|
|
80
|
+
return { ok: true as const };
|
|
81
|
+
}
|
|
82
|
+
if (registry[roomID]?.[request.sessionID]) {
|
|
83
|
+
removeJoinRequest(db, roomID, requestSessionID);
|
|
84
|
+
return { status: 409 as const, error: "requester already joined the room" };
|
|
85
|
+
}
|
|
86
|
+
if (svc.containsParticipant(roomID, request.participantId)) {
|
|
87
|
+
removeJoinRequest(db, roomID, requestSessionID);
|
|
88
|
+
return { status: 409 as const, error: "participant name is already in use in this room" };
|
|
89
|
+
}
|
|
90
|
+
removeJoinRequest(db, roomID, requestSessionID);
|
|
91
|
+
joinRoomMember(svc, registry, roomID, {
|
|
92
|
+
sessionID: request.sessionID,
|
|
93
|
+
participantId: request.participantId,
|
|
94
|
+
name: request.name,
|
|
95
|
+
...(request.protocol ? { protocol: request.protocol } : {}),
|
|
96
|
+
...(request.receiverOwnerID ? { receiverOwnerID: request.receiverOwnerID } : {}),
|
|
97
|
+
...(request.directory ? { directory: request.directory } : {}),
|
|
98
|
+
...(request.host ? { host: request.host } : {}),
|
|
99
|
+
});
|
|
100
|
+
return { ok: true as const };
|
|
101
|
+
});
|
|
102
|
+
return "ok" in result ? json({ ok: true }) : json({ error: result.error }, result.status);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return json({ error: "method not allowed" }, 405);
|
|
106
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { recallMessage, revealMessageContent } from "../src/state/store.ts";
|
|
2
|
+
import { jsonObject } from "./json-body";
|
|
3
|
+
|
|
4
|
+
const json = (body: unknown, status = 200) => Response.json(body, { status });
|
|
5
|
+
const MAX_SESSION = 128;
|
|
6
|
+
|
|
7
|
+
export async function messageRecallRoutes(req: Request, url: URL): Promise<Response | undefined> {
|
|
8
|
+
const recall = url.pathname.match(/^\/rooms\/([^/]+)\/messages\/([^/]+)\/recall$/);
|
|
9
|
+
if (recall) {
|
|
10
|
+
if (req.method !== "POST") return json({ error: "method not allowed" }, 405);
|
|
11
|
+
const roomID = decodeURIComponent(recall[1]!);
|
|
12
|
+
const messageID = decodeURIComponent(recall[2]!);
|
|
13
|
+
const body = await jsonObject<Record<string, unknown>>(req);
|
|
14
|
+
if (!body) return json({ error: "JSON object body is required" }, 400);
|
|
15
|
+
const sessionID = typeof body.sessionID === "string" ? body.sessionID.trim() : "";
|
|
16
|
+
if (!sessionID || sessionID.length > MAX_SESSION) return json({ error: "sessionID is required" }, 400);
|
|
17
|
+
const result = await recallMessage(roomID, messageID, sessionID);
|
|
18
|
+
if (result.status === "missing") return json({ error: "message not found" }, 404);
|
|
19
|
+
if (result.status === "member") return json({ error: "session is not a room member" }, 409);
|
|
20
|
+
if (result.status === "forbidden") return json({ error: "not allowed to recall this message" }, 403);
|
|
21
|
+
if (result.status !== "ok") return json({ error: "recall failed" }, 409);
|
|
22
|
+
return json({ ok: true, messageID: result.messageID, recalledAt: result.recalledAt, recalledBy: result.recalledBy });
|
|
23
|
+
}
|
|
24
|
+
const content = url.pathname.match(/^\/rooms\/([^/]+)\/messages\/([^/]+)\/content$/);
|
|
25
|
+
if (!content) return undefined;
|
|
26
|
+
if (req.method !== "GET") return json({ error: "method not allowed" }, 405);
|
|
27
|
+
const roomID = decodeURIComponent(content[1]!);
|
|
28
|
+
const messageID = decodeURIComponent(content[2]!);
|
|
29
|
+
const sessionID = url.searchParams.get("sessionID") ?? "";
|
|
30
|
+
if (!sessionID || sessionID.length > MAX_SESSION) return json({ error: "sessionID is required" }, 400);
|
|
31
|
+
const result = await revealMessageContent(roomID, messageID, sessionID);
|
|
32
|
+
if (result.status === "missing") return json({ error: "message not found" }, 404);
|
|
33
|
+
if (result.status === "member") return json({ error: "session is not a room member" }, 409);
|
|
34
|
+
if (result.status === "hidden") return json({ error: "message is not recalled" }, 409);
|
|
35
|
+
if (result.status !== "ok") return json({ error: "message not found" }, 404);
|
|
36
|
+
return json({ messageID: result.messageID, text: result.text, senderId: result.senderId, createdAt: result.createdAt, recalledAt: result.recalledAt });
|
|
37
|
+
}
|
package/server/newrooms.ts
CHANGED
|
@@ -100,6 +100,7 @@ export async function roomManagement(req: Request, url: URL): Promise<Response |
|
|
|
100
100
|
if (!sessionID || sessionID.length > 128) return json({ error: "sessionID is required" }, 400);
|
|
101
101
|
if (body.name !== undefined && (typeof body.name !== "string" || !body.name.trim() || body.name.trim().length > 64)) return json({ error: "name must be 1-64 characters" }, 400);
|
|
102
102
|
if (body.description !== undefined && (typeof body.description !== "string" || body.description.length > 2000)) return json({ error: "description too long (max 2000)" }, 400);
|
|
103
|
+
if (body.joinPolicy !== undefined && body.joinPolicy !== "open" && body.joinPolicy !== "approval") return json({ error: "joinPolicy must be open or approval" }, 400);
|
|
103
104
|
if (body.adminSessionID !== undefined && body.adminSessionID !== null && (typeof body.adminSessionID !== "string" || body.adminSessionID.length > 128)) return json({ error: "invalid adminSessionID" }, 400);
|
|
104
105
|
if (body.adminIds !== undefined && (!Array.isArray(body.adminIds) || body.adminIds.length > 50 || body.adminIds.some((name) => typeof name !== "string" || !name.trim() || name.trim().length > 64))) return json({ error: "adminIds must be up to 50 member names" }, 400);
|
|
105
106
|
if (body.successorId !== undefined && body.successorId !== null && (typeof body.successorId !== "string" || !body.successorId.trim() || body.successorId.trim().length > 64)) return json({ error: "successorId must be a member name or null" }, 400);
|
|
@@ -107,6 +108,7 @@ export async function roomManagement(req: Request, url: URL): Promise<Response |
|
|
|
107
108
|
const adminIds = Array.isArray(body.adminIds) ? [...new Set(body.adminIds.map((name) => (name as string).trim()))] : undefined;
|
|
108
109
|
const name = typeof body.name === "string" ? body.name.trim() : undefined;
|
|
109
110
|
const description = typeof body.description === "string" ? body.description.trim() : undefined;
|
|
111
|
+
const joinPolicy = body.joinPolicy === "open" || body.joinPolicy === "approval" ? body.joinPolicy : undefined;
|
|
110
112
|
const adminSessionID = typeof body.adminSessionID === "string" ? body.adminSessionID : body.adminSessionID === null ? null : undefined;
|
|
111
113
|
if (body.ownerId !== undefined && (typeof body.ownerId !== "string" || !body.ownerId.trim() || body.ownerId.trim().length > 64)) return json({ error: "ownerId must be 1-64 characters" }, 400);
|
|
112
114
|
const nextOwner = typeof body.ownerId === "string" ? body.ownerId.trim() : undefined;
|
|
@@ -122,6 +124,13 @@ export async function roomManagement(req: Request, url: URL): Promise<Response |
|
|
|
122
124
|
const changes: string[] = [];
|
|
123
125
|
if (name !== undefined && name !== room.name) { changes.push(`${actor.name} renamed the room from "${room.name}" to "${name}"`); room.name = name; }
|
|
124
126
|
if (description !== undefined && description !== (room.description ?? "")) { room.description = description || undefined; changes.push(`${actor.name} updated the room description`); }
|
|
127
|
+
if (joinPolicy !== undefined && joinPolicy !== (room.joinPolicy ?? "open")) {
|
|
128
|
+
if (joinPolicy === "approval") room.joinPolicy = "approval"; else delete room.joinPolicy;
|
|
129
|
+
// Opening the room makes waiting requests moot; they would otherwise stay
|
|
130
|
+
// listed forever because anyone can now join directly.
|
|
131
|
+
if (joinPolicy === "open") db.query("DELETE FROM room_join_requests WHERE room_id=?").run(roomId);
|
|
132
|
+
changes.push(`${actor.name} set join approval to ${joinPolicy}`);
|
|
133
|
+
}
|
|
125
134
|
if (adminSessionID !== undefined) {
|
|
126
135
|
if (!adminSessionID) {
|
|
127
136
|
if (binding(db, roomId)) { exec(db, "DELETE FROM admin_rooms WHERE room_id=?", roomId); changes.push(`${actor.name} revoked the administrator designation`); }
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import RoomService, { type Room } from "../src/rooms/room-service.ts";
|
|
3
|
+
import type { Registry, RegistryEntry } from "../src/state/store.ts";
|
|
4
|
+
import { bindOwner, isUser } from "./room-owner";
|
|
5
|
+
|
|
6
|
+
export type JoinMember = {
|
|
7
|
+
sessionID: string;
|
|
8
|
+
participantId: string;
|
|
9
|
+
name: string;
|
|
10
|
+
protocol?: "v2";
|
|
11
|
+
receiverOwnerID?: string;
|
|
12
|
+
directory?: string;
|
|
13
|
+
host?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Shared by the join endpoint and approved join requests so an approved member
|
|
17
|
+
// gets exactly the same membership, rename retirement, and owner binding.
|
|
18
|
+
export function joinRoomMember(svc: RoomService, registry: Registry, roomId: string, member: JoinMember): Room {
|
|
19
|
+
const currentRoom = svc.getRoom(roomId);
|
|
20
|
+
const participantId = currentRoom.kind === "direct" ? member.sessionID : member.participantId;
|
|
21
|
+
const regRoom = (registry[roomId] = registry[roomId] ?? Object.create(null) as Record<string, RegistryEntry>);
|
|
22
|
+
const prevEntry = regRoom[member.sessionID];
|
|
23
|
+
// Retire the participant this session previously held, unless another
|
|
24
|
+
// session still uses the old name.
|
|
25
|
+
if (currentRoom.kind !== "direct" && prevEntry && prevEntry.name !== member.name) {
|
|
26
|
+
const shared = Object.entries(regRoom).some(([sid, entry]) => sid !== member.sessionID && entry.name === prevEntry.name);
|
|
27
|
+
if (!shared && svc.containsParticipant(roomId, prevEntry.name)) svc.leaveRoom(roomId, prevEntry.name);
|
|
28
|
+
}
|
|
29
|
+
const already = svc.containsParticipant(roomId, participantId);
|
|
30
|
+
// Prune a stale registry entry for the same name from another session, but
|
|
31
|
+
// only when the identity is not already present.
|
|
32
|
+
if (!already && currentRoom.kind !== "direct") {
|
|
33
|
+
for (const [sid, entry] of Object.entries(regRoom)) if (sid !== member.sessionID && entry.name === member.name) delete regRoom[sid];
|
|
34
|
+
}
|
|
35
|
+
svc.joinRoom(roomId, { id: participantId, name: member.name });
|
|
36
|
+
if (!already) svc.addEvent(roomId, `${member.name} joined the room`);
|
|
37
|
+
const latestMessageTs = svc.getMessages(roomId).at(-1)?.createdAt ?? 0;
|
|
38
|
+
regRoom[member.sessionID] = {
|
|
39
|
+
serverUrl: "",
|
|
40
|
+
apiPrefix: "/api",
|
|
41
|
+
...(member.protocol === "v2" ? { protocol: "v2" as const } : {}),
|
|
42
|
+
...(member.protocol === "v2" && member.receiverOwnerID ? { receiverOwnerID: member.receiverOwnerID } : {}),
|
|
43
|
+
name: member.name,
|
|
44
|
+
membershipID: prevEntry?.membershipID ?? randomUUID(),
|
|
45
|
+
directory: member.directory || undefined,
|
|
46
|
+
host: member.host ?? "",
|
|
47
|
+
lastQueuedTs: regRoom[member.sessionID]?.lastQueuedTs,
|
|
48
|
+
lastReadTs: regRoom[member.sessionID]?.lastReadTs ?? Math.max(Date.now(), latestMessageTs),
|
|
49
|
+
};
|
|
50
|
+
// An ownerless room is claimed by the first person who arrives; agents never are.
|
|
51
|
+
const joinedRoom = svc.getRoom(roomId);
|
|
52
|
+
if (!joinedRoom.ownerId && isUser(regRoom[member.sessionID])) {
|
|
53
|
+
joinedRoom.ownerId = member.name;
|
|
54
|
+
joinedRoom.ownerMembershipID = regRoom[member.sessionID]!.membershipID;
|
|
55
|
+
} else {
|
|
56
|
+
bindOwner(joinedRoom, regRoom);
|
|
57
|
+
}
|
|
58
|
+
return svc.getRoom(roomId);
|
|
59
|
+
}
|
package/server/room-owner.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import type { Participant, Room } from "../src/rooms/room-service.ts";
|
|
2
|
+
import { isUser } from "../src/state/roles.ts";
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
+
export { isOwnerEntry, isRoomAdmin, isUser } from "../src/state/roles.ts";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
// own a room, so any of those fields marks an entry that must never be promoted.
|
|
7
|
-
export function isUser(entry: OwnerEntry | undefined | null): boolean {
|
|
8
|
-
return Boolean(entry?.name) && !entry!.protocol && !entry!.host && !entry!.receiverOwnerID;
|
|
9
|
-
}
|
|
6
|
+
export type OwnerEntry = { name?: string | null; protocol?: string | null; host?: string | null; receiverOwnerID?: string | null; membershipID?: string | null };
|
|
10
7
|
|
|
11
8
|
function humans(room: Room, registry: Record<string, OwnerEntry>): OwnerEntry[] {
|
|
12
9
|
const joined = new Map([...room.participants.values()].map((member) => [member.name, member]));
|
|
@@ -16,20 +13,6 @@ function humans(room: Room, registry: Record<string, OwnerEntry>): OwnerEntry[]
|
|
|
16
13
|
.sort((left, right) => joined.get(left.name!)!.joinedAt - joined.get(right.name!)!.joinedAt) as OwnerEntry[];
|
|
17
14
|
}
|
|
18
15
|
|
|
19
|
-
// The owner is a person bound to a server-issued membership. The display name is
|
|
20
|
-
// only for presentation: a new session that reuses the name must not inherit the room.
|
|
21
|
-
export function isOwnerEntry(room: Room, entry: OwnerEntry | null | undefined): boolean {
|
|
22
|
-
return isUser(entry) && entry!.name === room.ownerId &&
|
|
23
|
-
(!room.ownerMembershipID || entry!.membershipID === room.ownerMembershipID);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function isRoomAdmin(room: Room, entry: OwnerEntry | null | undefined): boolean {
|
|
27
|
-
if (isOwnerEntry(room, entry)) return true;
|
|
28
|
-
if (!isUser(entry) || !(room.adminIds ?? []).includes(entry!.name!)) return false;
|
|
29
|
-
if (!room.adminMembershipIDs?.length) return true;
|
|
30
|
-
return !entry!.membershipID || room.adminMembershipIDs.includes(entry!.membershipID);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
16
|
// A room whose owner entry vanished follows the explicit successor first, then the
|
|
34
17
|
// first person still present; the last person out leaves the room open to claim.
|
|
35
18
|
export function settleOwner(room: Room, registry: Record<string, OwnerEntry>): string {
|
package/server/room-payload.ts
CHANGED
|
@@ -19,12 +19,14 @@ export async function roomPayload(room: Room, limit = ROOM_WINDOW) {
|
|
|
19
19
|
adminIds: room.adminIds ?? [],
|
|
20
20
|
successorId: room.successorId ?? null,
|
|
21
21
|
createdAt: room.createdAt,
|
|
22
|
+
joinPolicy: room.joinPolicy ?? "open",
|
|
22
23
|
participants: [...room.participants.values()],
|
|
23
24
|
messages: page.messages,
|
|
24
25
|
kind: room.kind ?? "group",
|
|
25
26
|
...(room.directSessionIDs ? { directSessionIDs: room.directSessionIDs } : {}),
|
|
26
27
|
hasMore: page.hasMore,
|
|
27
28
|
nextBeforeSeq: page.nextBeforeSeq,
|
|
29
|
+
recallVersion: page.recallVersion,
|
|
28
30
|
adminSessionID: admin?.session_id ?? null,
|
|
29
31
|
openQuestions,
|
|
30
32
|
};
|