@wtfalch/chat 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -28
- package/dist/chat/admin/index.d.ts +5 -0
- package/dist/chat/admin/index.js +10 -0
- package/dist/chat/admin/react.d.ts +22 -1
- package/dist/chat/admin/react.js +115 -1
- package/dist/chat/client.d.ts +15 -7
- package/dist/chat/client.js +572 -81
- package/dist/chat/fake/server.d.ts +71 -3
- package/dist/chat/fake/server.js +257 -14
- package/dist/chat/react/NewDirectMessage.d.ts +5 -5
- package/dist/chat/react/NewDirectMessage.js +5 -5
- package/dist/chat/react/ThreadPanel.js +44 -1
- package/dist/chat/store.d.ts +44 -6
- package/dist/chat/store.js +88 -8
- package/dist/chat/types.d.ts +198 -12
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -34,17 +34,24 @@ chat.onRoomsChanged((rooms) => render(rooms));
|
|
|
34
34
|
an Agora type. On `start()`, it `POST`s `exchangeUrl` with that token and a
|
|
35
35
|
device id, and gets back a Matrix homeserver, user id and access token (the
|
|
36
36
|
exact contract is `apps/chat-service/README.md` and
|
|
37
|
-
`apps/chat-service/src/exchange.ts`). `storeName`
|
|
38
|
-
|
|
37
|
+
`apps/chat-service/src/exchange.ts`). `storeName` supplies the workspace namespace
|
|
38
|
+
for its local IndexedDB store. After exchange, the SDK binds that namespace to
|
|
39
|
+
the returned homeserver and Matrix user id, so different accounts and servers
|
|
40
|
+
never replay each other's cached history. The same account keeps its cache
|
|
41
|
+
across restarts. Legacy caches without account identity are left unused; the
|
|
42
|
+
first start after this update fetches fresh history from the server.
|
|
39
43
|
|
|
40
44
|
There is no Matrix refresh token, so this refreshes itself two ways: a timer
|
|
41
45
|
ahead of `expires_at`, and a listener for Synapse's `M_UNKNOWN_TOKEN`. Both
|
|
42
46
|
re-run the exchange and carry on without the caller doing anything.
|
|
43
47
|
|
|
44
|
-
Crypto stays off
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
Crypto stays off unless `createChatClient({ encryptionEnabled: true, ... })`
|
|
49
|
+
turns it on, which calls matrix-js-sdk's `initRustCrypto()` once, before the
|
|
50
|
+
first sync. Omitted or `false`, this never calls it: matrix-js-sdk only
|
|
51
|
+
downloads its Rust crypto WASM when that is called, so skipping it means the
|
|
52
|
+
WASM module is never loaded, in a browser or under vitest -- no shim or
|
|
53
|
+
polyfill needed either way. `chat.getCrypto()` reaches matrix-js-sdk's
|
|
54
|
+
`CryptoApi` once it is on, and is `undefined` otherwise.
|
|
48
55
|
|
|
49
56
|
**Sync, reconnect and unread counts** ([#14](https://github.com/wtfalch/messaging/issues/14)).
|
|
50
57
|
The room list follows matrix-js-sdk's own `/sync` loop: a new room, a rename,
|
|
@@ -53,9 +60,17 @@ never a poll. If Synapse ever refuses the client's stored sync position (seen
|
|
|
53
60
|
after a long enough time offline), this wipes the local store and starts a
|
|
54
61
|
full sync on its own -- no duplicated or missing events either way. Each room
|
|
55
62
|
summary carries `unreadCount`, Matrix's own notification count; `chat.
|
|
56
|
-
totalUnreadCount()` sums it across every room, for the agora's badge.
|
|
63
|
+
totalUnreadCount()` sums it across every room, for the agora's badge. It also
|
|
64
|
+
carries `mentionCount` -- the subset of `unreadCount` that names this person,
|
|
65
|
+
Matrix's own `highlight_count` -- so a list can draw the distinction every
|
|
66
|
+
other chat client does: weight (bold) for "something happened here", a badge
|
|
67
|
+
for "someone tagged you" ([#45](https://github.com/wtfalch/chat/issues/45)).
|
|
68
|
+
`unreadCount >= mentionCount` always holds. `mentionCount` reads `0` in a
|
|
69
|
+
muted room regardless of whether a message actually named this person --
|
|
70
|
+
`ChatRoomSummary.mentionCount`'s own docs carry the reason and the gap it
|
|
71
|
+
leaves.
|
|
57
72
|
`chat.markRoomRead(roomId)` sends `m.read` for the newest event and clears
|
|
58
|
-
|
|
73
|
+
both counts right away -- call it when a room is opened and again when
|
|
59
74
|
the person reaches the newest message. Each summary also carries
|
|
60
75
|
`lastMessage` -- the room's newest real message (sender, text, timestamp),
|
|
61
76
|
reduced the same way `timeline()` reduces one, so an edit's already-folded
|
|
@@ -76,6 +91,16 @@ signed into the account, not just this one. `room.muted` is what a list
|
|
|
76
91
|
dims. Muting only ever changes that: `unreadCount` keeps climbing regardless,
|
|
77
92
|
because a muted room stops notifying and nothing else.
|
|
78
93
|
|
|
94
|
+
**Marked unread** ([#56](https://github.com/wtfalch/chat/issues/56), MSC2867).
|
|
95
|
+
`chat.markRoomUnread(roomId, unread)` writes room-scoped account data under
|
|
96
|
+
`m.marked_unread`, and, for clients that read the pre-merge key, alongside it
|
|
97
|
+
under `com.famedly.marked_unread` too -- both carrying the same `{ unread }`.
|
|
98
|
+
`room.markedUnread` is what a list flags. Independent of `unreadCount`, the
|
|
99
|
+
same way `muted` is: this is a person's own signal on top of whatever is
|
|
100
|
+
already unread, not a recount. `markRoomRead(roomId)` clears the flag itself
|
|
101
|
+
when it is set, so opening a room a person had marked unread also un-marks
|
|
102
|
+
it.
|
|
103
|
+
|
|
79
104
|
**Presence and typing** ([#7](https://github.com/wtfalch/chat/issues/7)).
|
|
80
105
|
Both are ephemeral and both are Matrix-native, which is why they are one
|
|
81
106
|
ticket: `chat.presence(userId)` reads someone's `m.presence` as `'online'`,
|
|
@@ -86,12 +111,14 @@ hears about it changing. `chat.sendTyping(roomId, typing)` sends `m.typing`;
|
|
|
86
111
|
return.
|
|
87
112
|
|
|
88
113
|
**Presence is off in production.** Every company's Synapse is generated by
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
114
|
+
foundry's provisioning (the app-template bootstrap step this once cited is
|
|
115
|
+
archived; foundry owns per-company Synapse config generation now), which
|
|
116
|
+
still hardcodes it off, tracked at
|
|
117
|
+
[wtfalch/foundry#41](https://github.com/wtfalch/foundry/issues/41). Until
|
|
118
|
+
that lands, `presence()` reports `'offline'` for everyone, always -- not
|
|
119
|
+
because nobody is online, but because Synapse never says. The test stack
|
|
120
|
+
turns it on, so the integration suite proves all four states against a real
|
|
121
|
+
server.
|
|
95
122
|
`sendTyping` and `onTypingChanged` are unaffected and work today.
|
|
96
123
|
|
|
97
124
|
**Announcing idleness** ([#20](https://github.com/wtfalch/chat/issues/20)).
|
|
@@ -109,10 +136,34 @@ is a single call and not a heartbeat -- Matrix auto-expires a typing state
|
|
|
109
136
|
after its own timeout, so a composer that wants "typing" to keep showing
|
|
110
137
|
through a long pause has to call this again itself on further keystrokes.
|
|
111
138
|
|
|
139
|
+
**Status** ([#24](https://github.com/wtfalch/chat/issues/24), design:
|
|
140
|
+
[docs/status.md](../../docs/status.md)). Durable, unlike presence: `chat.
|
|
141
|
+
status(userId)` reads a `ChatStatus` (`kind`, an optional `until`, an
|
|
142
|
+
optional `message`) stored as an MSC4133 extended-profile field, so it
|
|
143
|
+
survives the person closing their laptop entirely -- exactly what presence
|
|
144
|
+
cannot do. `chat.setOwnStatus(status | null)` sets or clears the
|
|
145
|
+
signed-in person's own, and `chat.onStatusChanged(listener)` hears a fetch
|
|
146
|
+
or a set land. `status()` never blocks: the first call for a `userId`
|
|
147
|
+
starts a background fetch and reads `null` until it resolves, the same
|
|
148
|
+
lazy-then-cached shape as most of this package's reads that reach the
|
|
149
|
+
network.
|
|
150
|
+
|
|
151
|
+
**Off until Synapse turns it on.** MSC4133 is gated by
|
|
152
|
+
`experimental_features.msc4133_enabled`, off by default, tracked at
|
|
153
|
+
[wtfalch/foundry#41](https://github.com/wtfalch/foundry/issues/41) the
|
|
154
|
+
same way presence is. Until then `status()` reads `null` for everyone in
|
|
155
|
+
production and `setOwnStatus` rejects, honestly, rather than pretending to
|
|
156
|
+
have written something durable. The settings surface for *authoring* a
|
|
157
|
+
status (working hours, an auto-reply message, and the UI around all of
|
|
158
|
+
it) is its own, larger piece of work -- see `docs/status.md`'s
|
|
159
|
+
sequencing table -- and is not this package's to build; this is the read
|
|
160
|
+
and write half through `ChatClient` alone.
|
|
161
|
+
|
|
112
162
|
**Direct messages** ([#16](https://github.com/wtfalch/messaging/issues/16)).
|
|
113
|
-
`chat.people()` is everyone in the company space but the signed-in person
|
|
114
|
-
|
|
115
|
-
|
|
163
|
+
`chat.people()` is everyone in the company space but the signed-in person,
|
|
164
|
+
plus every guest sharing a joined room with them ([docs/guests.md](docs/guests.md),
|
|
165
|
+
"What the SDK shows") -- a guest is never in the space, so the shared room is
|
|
166
|
+
the only way one is ever offered. `chat.startDirectMessage(userIds)` opens the
|
|
116
167
|
direct room with exactly those people and resolves with its id: an existing
|
|
117
168
|
one is found through the account's own `m.direct` data and reopened, and only
|
|
118
169
|
a set of people with no room yet creates one. A different set of people is a
|
|
@@ -122,7 +173,7 @@ message rather than editing the old one.
|
|
|
122
173
|
The room it creates carries `is_direct` and an invite list and nothing else.
|
|
123
174
|
That is not a style choice: Synapse's `wtfalch_chat_gate` module refuses a
|
|
124
175
|
member-created room that also carries a name, a topic, `initial_state` or
|
|
125
|
-
`creation_content`, because a room dressed as a channel is
|
|
176
|
+
`creation_content`, because a room dressed as a channel is Boule's
|
|
126
177
|
to make (chat plan section 5).
|
|
127
178
|
|
|
128
179
|
`chat.hideDirectMessage(roomId)` takes a direct room out of `rooms()` with a
|
|
@@ -140,6 +191,17 @@ thread's own timeline, root first;
|
|
|
140
191
|
reply is never in the room's own timeline: what the room shows is the count
|
|
141
192
|
and the people on the root, through `event.thread`.
|
|
142
193
|
|
|
194
|
+
A person follows a thread by posting in it (and, once the chat service's
|
|
195
|
+
application service is deployed, by being mentioned in it), and Activity tells
|
|
196
|
+
them about replies in the threads they follow. `chat.threadFollowing(roomId,
|
|
197
|
+
threadId)` reads that, `chat.followThread` and `chat.unfollowThread` change it,
|
|
198
|
+
and the thread panel shows the matching Follow or Unfollow button. A post or a
|
|
199
|
+
file follows the thread once it is sent; `chat.onThreadFollowChanged(roomId,
|
|
200
|
+
threadId, listener)` hears the result. An unfollow
|
|
201
|
+
sticks: posting in the thread again does not follow it back, only
|
|
202
|
+
`followThread` does. The state lives in the chat service
|
|
203
|
+
(`/_chat/threads/{roomId}/{threadId}/follow`), not in Matrix.
|
|
204
|
+
|
|
143
205
|
`onTimelineChanged(roomId, listener)` takes no thread id, deliberately. A
|
|
144
206
|
reply changes both the thread it is in and the count on its root, so a caller
|
|
145
207
|
reading either has to hear about it; one subscription per room says that
|
|
@@ -254,11 +316,17 @@ exchange and homeserver answered by intercepting `fetch`. `FakeChatServer`
|
|
|
254
316
|
(`members`, `invited`), adding, renaming or delivering someone leaving a room
|
|
255
317
|
mid-test, sending a message into one, invalidating the current token to
|
|
256
318
|
prove a token recovery, or refusing the next poll's position to prove a
|
|
257
|
-
full-sync recovery. It answers `/createRoom`, `m.direct` account data
|
|
258
|
-
room
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
319
|
+
full-sync recovery. It answers `/createRoom`, `m.direct` account data, room
|
|
320
|
+
tags and other room-scoped account data (a draft, most likely) too, so a
|
|
321
|
+
direct message can be started, reopened and hidden against it -- and it
|
|
322
|
+
refuses a `createRoom` carrying a `name`, the same way the Synapse gate
|
|
323
|
+
does, so a client that started sending one would fail here rather than in
|
|
324
|
+
production. `receiveRoomAccountData` delivers a parked poll as if another
|
|
325
|
+
of this account's own devices had written that room account data, for
|
|
326
|
+
proving a client picks up a change from elsewhere -- there is only ever one
|
|
327
|
+
parked poll at a time (one `#pending` slot), so a "second device" test
|
|
328
|
+
drives this fake through that method rather than starting a second
|
|
329
|
+
`createChatClient` against the same one. It also takes sends (`server.sent` is what went
|
|
262
330
|
out, relation and all), seeds a room with messages, delivers a threaded
|
|
263
331
|
reply, and answers `/event` and `/relations`, which is what matrix-js-sdk
|
|
264
332
|
asks for while it builds a thread. It echoes every accepted send back
|
|
@@ -364,7 +432,7 @@ a person who left a room, or was removed, finds nothing from it on their
|
|
|
364
432
|
next search, with no filter this package wrote itself.
|
|
365
433
|
|
|
366
434
|
**Encrypted rooms say so, rather than returning nothing.** Crypto stays off
|
|
367
|
-
|
|
435
|
+
by default (the module comment says why), so a real encrypted
|
|
368
436
|
room's cleartext was never in Synapse's index to begin with -- an empty
|
|
369
437
|
`results` from one would read as "nothing found" when the honest answer is
|
|
370
438
|
"cannot search here". `search` returns
|
|
@@ -401,7 +469,7 @@ read receipt is on that message or a newer one. It leaves out the signed-in
|
|
|
401
469
|
person and the message's sender. `onTimelineChanged` fires when a receipt
|
|
402
470
|
moves, so a view re-reads it then. Only public read receipts count.
|
|
403
471
|
|
|
404
|
-
## Administration in
|
|
472
|
+
## Administration in Boule
|
|
405
473
|
|
|
406
474
|
`@wtfalch/chat/admin` exports `createChatAdmin`, the typed management
|
|
407
475
|
client, and `hasChatAdminRole` for already-verified identity claims. The admin
|
|
@@ -422,16 +490,34 @@ invitations/removals, moderation (`banPerson`, `unbanPerson`, `redactMessage`,
|
|
|
422
490
|
refused; tokens never appear in URLs or rendered errors. Service authorization
|
|
423
491
|
still verifies the token, organisation and Chat project's admin role on every
|
|
424
492
|
request. Request the Chat project audience and qualified project-role claims
|
|
425
|
-
when
|
|
493
|
+
when Boule signs in; a same-named role from another project is insufficient.
|
|
494
|
+
|
|
495
|
+
`chatJoinUrl(agoraUrl, agoraId, roomId, threadId?)` builds a room (and,
|
|
496
|
+
optionally, thread) join URL Agora can route directly, in the same
|
|
497
|
+
`/h/<agoraId>/chat/<roomId>/<threadId>` shape Agora's own `pathForChat`
|
|
498
|
+
builds and decodes. It shares `createChatAdmin`'s `encodeURIComponent`
|
|
499
|
+
encoding, which leaves `!` unescaped -- `!room:x` becomes `!room%3Ax`, not
|
|
500
|
+
`%21room%3Ax` -- and that round-trips fine through `decodeURIComponent` on
|
|
501
|
+
Agora's side either way.
|
|
426
502
|
|
|
427
503
|
`@wtfalch/chat/admin/react` exports `ChatAdminPanel` plus its action
|
|
428
504
|
contracts. Import `@wtfalch/chat/admin/admin.css` after design styles.
|
|
429
|
-
The SDK owns the controls;
|
|
505
|
+
The SDK owns the controls; Boule supplies an organisation-scoped `load` and
|
|
430
506
|
`run` action, its verified gates, and a roster mapping issuer subjects to names.
|
|
431
507
|
Keep access tokens in server actions. Every action must check both host tenant
|
|
432
508
|
membership and the Chat project role itself; hiding a menu entry is not a gate.
|
|
433
509
|
Mail follows the same separation through `@wtfalch/email/postmaster`.
|
|
434
510
|
|
|
511
|
+
The panel also has a Sessions view and a Reports view
|
|
512
|
+
([#58](https://github.com/wtfalch/chat/issues/58)), alongside `load`/`run`, so
|
|
513
|
+
`ChatAdminActions` grew two more reads: `loadSessions(subject)` for a chosen
|
|
514
|
+
person's Matrix sessions and `loadReports(cursor?)` for what members have
|
|
515
|
+
reported, newest first. `AdminCommand` grew the two mutations that follow from
|
|
516
|
+
each: `revoke` ends one of a person's sessions (their next use of that device
|
|
517
|
+
signs in again), and `ban` bans a report's sender from the channel it happened
|
|
518
|
+
in. Both confirm before running, the same as every other destructive control
|
|
519
|
+
here.
|
|
520
|
+
|
|
435
521
|
The agora is the sole user-facing app and HTTP origin for Mail and Chat. Admin
|
|
436
|
-
panels live in
|
|
522
|
+
panels live in Boule; no separate Chat web host is inferred or provisioned.
|
|
437
523
|
Deployment and real-identity acceptance remain separate from local checks.
|
|
@@ -69,6 +69,11 @@ export declare class ChatAdminError extends Error {
|
|
|
69
69
|
readonly code: string;
|
|
70
70
|
constructor(status: number, code: string);
|
|
71
71
|
}
|
|
72
|
+
/** A join URL Agora can route directly to a room (and, optionally, a
|
|
73
|
+
* thread within it), in the `/h/<agoraId>/chat/<roomId>/<threadId>` shape
|
|
74
|
+
* `pathForChat` in the Agora repo's `apps/agora/src/routes.ts` documents
|
|
75
|
+
* (wtfalch/agora#164). */
|
|
76
|
+
export declare function chatJoinUrl(agoraUrl: string, agoraId: string, roomId: string, threadId?: string | null): string;
|
|
72
77
|
export declare function createChatAdmin(options: ChatAdminOptions): {
|
|
73
78
|
listChannels: (input?: PageInput) => Promise<ChannelPage>;
|
|
74
79
|
getChannel: (roomId: string) => Promise<AdminChannel>;
|
package/dist/chat/admin/index.js
CHANGED
|
@@ -22,6 +22,16 @@ function origin(input) {
|
|
|
22
22
|
}
|
|
23
23
|
return url.origin;
|
|
24
24
|
}
|
|
25
|
+
/** A join URL Agora can route directly to a room (and, optionally, a
|
|
26
|
+
* thread within it), in the `/h/<agoraId>/chat/<roomId>/<threadId>` shape
|
|
27
|
+
* `pathForChat` in the Agora repo's `apps/agora/src/routes.ts` documents
|
|
28
|
+
* (wtfalch/agora#164). */
|
|
29
|
+
export function chatJoinUrl(agoraUrl, agoraId, roomId, threadId) {
|
|
30
|
+
const path = `/h/${encodeURIComponent(agoraId)}/chat/${encodeURIComponent(roomId)}`;
|
|
31
|
+
return threadId
|
|
32
|
+
? `${origin(agoraUrl)}${path}/${encodeURIComponent(threadId)}`
|
|
33
|
+
: `${origin(agoraUrl)}${path}`;
|
|
34
|
+
}
|
|
25
35
|
const record = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
26
36
|
const nullableString = (value) => value === null || typeof value === 'string';
|
|
27
37
|
function channel(value) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChannelInput, ChannelPage } from './index.ts';
|
|
1
|
+
import type { ChannelInput, ChannelPage, ContentReport, PersonSession } from './index.ts';
|
|
2
2
|
export type AdminPerson = {
|
|
3
3
|
subject: string;
|
|
4
4
|
name: string;
|
|
@@ -21,6 +21,19 @@ export type AdminCommand = {
|
|
|
21
21
|
} | {
|
|
22
22
|
operation: 'deactivate';
|
|
23
23
|
subject: string;
|
|
24
|
+
}
|
|
25
|
+
/** Ends one of `subject`'s Matrix sessions (#37, #58). */
|
|
26
|
+
| {
|
|
27
|
+
operation: 'revoke';
|
|
28
|
+
subject: string;
|
|
29
|
+
sessionId: string;
|
|
30
|
+
}
|
|
31
|
+
/** Bans the sender a report named, from the channel it happened in (#38, #58). */
|
|
32
|
+
| {
|
|
33
|
+
operation: 'ban';
|
|
34
|
+
roomId: string;
|
|
35
|
+
subject: string;
|
|
36
|
+
reason?: string;
|
|
24
37
|
};
|
|
25
38
|
export type AdminOutcome = {
|
|
26
39
|
ok: boolean;
|
|
@@ -29,9 +42,17 @@ export type AdminOutcome = {
|
|
|
29
42
|
export type AdminOverview = ChannelPage & {
|
|
30
43
|
people: AdminPerson[];
|
|
31
44
|
};
|
|
45
|
+
export type ReportPage = {
|
|
46
|
+
reports: ContentReport[];
|
|
47
|
+
next_cursor: string | null;
|
|
48
|
+
};
|
|
32
49
|
export type ChatAdminActions = {
|
|
33
50
|
load: (cursor?: string) => Promise<AdminOverview>;
|
|
34
51
|
run: (command: AdminCommand) => Promise<AdminOutcome>;
|
|
52
|
+
/** Every Matrix session signed in as `subject`, for the sessions view. */
|
|
53
|
+
loadSessions: (subject: string) => Promise<PersonSession[]>;
|
|
54
|
+
/** What members reported, newest first, for the reports view. */
|
|
55
|
+
loadReports: (cursor?: string) => Promise<ReportPage>;
|
|
35
56
|
};
|
|
36
57
|
/** The SDK owns the controls. Hosts pass authenticated actions, not tokens;
|
|
37
58
|
* every action must authorize its own caller before reaching the service. */
|
package/dist/chat/admin/react.js
CHANGED
|
@@ -93,7 +93,7 @@ export function ChatAdminPanel({ actions }) {
|
|
|
93
93
|
setSelected(event.target.value);
|
|
94
94
|
}, children: [_jsx("option", { value: "", children: "Choose a channel" }), view.channels.map((item) => (_jsx("option", { value: item.room_id, children: `${item.name}${item.archived ? ' · Archived' : ''}${item.visibility === 'private' ? ' · Private' : ''}` }, item.room_id)))] }) })), _jsxs("div", { className: "chat-admin-toolbar", children: [cursor && _jsx(Button, { onPress: () => void load(), children: "First page" }), view.next_cursor && (_jsx(Button, { onPress: () => void load(view.next_cursor ?? undefined), children: "Next channels" }))] }), channel && (_jsx(ChannelSettings, { channel: channel, people: view.people, run: run, onDirty: (value) => {
|
|
95
95
|
dirty.current = value;
|
|
96
|
-
} }, `${channel.room_id}:${channel.name}:${channel.topic}`)), _jsxs("details", { children: [_jsx("summary", { children: "Remove a person from Chat" }), _jsx("p", { children: "This ends their Chat sessions. Their existing messages remain." }), _jsx(RemovePerson, { people: view.people, run: run })] })] }) }))] }));
|
|
96
|
+
} }, `${channel.room_id}:${channel.name}:${channel.topic}`)), _jsxs("details", { children: [_jsx("summary", { children: "Remove a person from Chat" }), _jsx("p", { children: "This ends their Chat sessions. Their existing messages remain." }), _jsx(RemovePerson, { people: view.people, run: run })] }), _jsxs("details", { children: [_jsx("summary", { children: "Sessions" }), _jsx("p", { children: "End one of a person's signed-in Chat sessions on a single device." }), _jsx(SessionsPanel, { people: view.people, loadSessions: actions.loadSessions, run: run })] }), _jsxs("details", { children: [_jsx("summary", { children: "Reports" }), _jsx("p", { children: "What members have reported. Banning removes the sender from that channel." }), _jsx(ReportsPanel, { loadReports: actions.loadReports, run: run })] })] }) }))] }));
|
|
97
97
|
}
|
|
98
98
|
function ChannelForm({ channel, onSubmit, onDirty, }) {
|
|
99
99
|
const [name, setName] = useState(channel?.name ?? '');
|
|
@@ -142,6 +142,120 @@ function RemovePerson({ people, run, }) {
|
|
|
142
142
|
const name = people.find((person) => person.subject === subject)?.name;
|
|
143
143
|
return (_jsxs("div", { className: "chat-admin-form", children: [_jsx(Field, { label: "Person", children: _jsxs(Select, { value: subject, onChange: (event) => setSubject(event.target.value), children: [_jsx("option", { value: "", children: "Choose a person" }), people.map((person) => (_jsx("option", { value: person.subject, children: person.name }, person.subject)))] }) }), subject && (_jsx(Confirm, { label: "Remove from Chat", consequence: `End ${name}'s Chat sessions and remove their access?`, onConfirm: () => run({ operation: 'deactivate', subject }) }, subject))] }));
|
|
144
144
|
}
|
|
145
|
+
/** Lists one chosen person's Matrix sessions and ends them one at a time
|
|
146
|
+
* (#30, #58). A person keeps every session that is not ended: this is a
|
|
147
|
+
* per-device control, not a "sign this person out everywhere" switch. */
|
|
148
|
+
function SessionsPanel({ people, loadSessions, run, }) {
|
|
149
|
+
const [subject, setSubject] = useState('');
|
|
150
|
+
const [sessions, setSessions] = useState(null);
|
|
151
|
+
const [loading, setLoading] = useState(false);
|
|
152
|
+
const [failed, setFailed] = useState(false);
|
|
153
|
+
const latest = useRef(0);
|
|
154
|
+
const current = useRef('');
|
|
155
|
+
const name = people.find((person) => person.subject === subject)?.name;
|
|
156
|
+
async function refresh(target) {
|
|
157
|
+
// Only the newest request may write: a slower earlier reply must not
|
|
158
|
+
// overwrite the list for the person chosen since.
|
|
159
|
+
const request = ++latest.current;
|
|
160
|
+
setLoading(true);
|
|
161
|
+
setFailed(false);
|
|
162
|
+
try {
|
|
163
|
+
const result = await loadSessions(target);
|
|
164
|
+
if (request === latest.current)
|
|
165
|
+
setSessions(result);
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
if (request === latest.current) {
|
|
169
|
+
setSessions(null);
|
|
170
|
+
setFailed(true);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
if (request === latest.current)
|
|
175
|
+
setLoading(false);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return (_jsxs("div", { className: "chat-admin-form", children: [_jsx(Field, { label: "Person", children: _jsxs(Select, { value: subject, onChange: (event) => {
|
|
179
|
+
const next = event.target.value;
|
|
180
|
+
setSubject(next);
|
|
181
|
+
current.current = next;
|
|
182
|
+
setSessions(null);
|
|
183
|
+
setFailed(false);
|
|
184
|
+
if (next)
|
|
185
|
+
void refresh(next);
|
|
186
|
+
else {
|
|
187
|
+
latest.current++;
|
|
188
|
+
setLoading(false);
|
|
189
|
+
}
|
|
190
|
+
}, children: [_jsx("option", { value: "", children: "Choose a person" }), people.map((person) => (_jsx("option", { value: person.subject, children: person.name }, person.subject)))] }) }), subject && loading && _jsx("p", { children: "Loading sessions\u2026" }), subject && !loading && failed && (_jsxs("p", { role: "alert", children: ["Sessions could not be loaded.", ' ', _jsx(Button, { onPress: () => void refresh(subject), children: "Try again" })] })), subject && !loading && sessions?.length === 0 && _jsx("p", { children: "No active sessions." }), subject && !loading && sessions && sessions.length > 0 && (_jsx("ul", { className: "chat-admin-people", children: sessions.map((session) => (_jsxs("li", { children: [_jsx("span", { children: session.device_id ?? session.session_id }), _jsx(Confirm, { label: "End session", consequence: `End this session for ${name ?? subject}? Their next use of that device signs in again.`, onConfirm: async () => {
|
|
191
|
+
const ok = await run({
|
|
192
|
+
operation: 'revoke',
|
|
193
|
+
subject,
|
|
194
|
+
sessionId: session.session_id,
|
|
195
|
+
});
|
|
196
|
+
// Skip when the admin has switched person meanwhile: this refresh
|
|
197
|
+
// would otherwise become the newest and show the wrong list.
|
|
198
|
+
if (ok && current.current === subject)
|
|
199
|
+
await refresh(subject);
|
|
200
|
+
return ok;
|
|
201
|
+
} })] }, session.session_id))) }))] }));
|
|
202
|
+
}
|
|
203
|
+
/** Lists what members have reported and bans a report's sender from the
|
|
204
|
+
* channel it happened in (#29, #58). Never shows the reported message's
|
|
205
|
+
* text -- `ContentReport` never carries it. */
|
|
206
|
+
function ReportsPanel({ loadReports, run, }) {
|
|
207
|
+
const [page, setPage] = useState(null);
|
|
208
|
+
const [cursor, setCursor] = useState();
|
|
209
|
+
const [loading, setLoading] = useState(false);
|
|
210
|
+
const [failed, setFailed] = useState(false);
|
|
211
|
+
const started = useRef(false);
|
|
212
|
+
const latest = useRef(0);
|
|
213
|
+
const requested = useRef(undefined);
|
|
214
|
+
async function refresh(next) {
|
|
215
|
+
const request = ++latest.current;
|
|
216
|
+
requested.current = next;
|
|
217
|
+
setLoading(true);
|
|
218
|
+
setFailed(false);
|
|
219
|
+
try {
|
|
220
|
+
const result = await loadReports(next);
|
|
221
|
+
if (request === latest.current) {
|
|
222
|
+
setPage(result);
|
|
223
|
+
setCursor(next);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
if (request === latest.current) {
|
|
228
|
+
setPage(null);
|
|
229
|
+
setFailed(true);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
if (request === latest.current)
|
|
234
|
+
setLoading(false);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
useEffect(() => {
|
|
238
|
+
if (started.current)
|
|
239
|
+
return;
|
|
240
|
+
started.current = true;
|
|
241
|
+
void refresh();
|
|
242
|
+
});
|
|
243
|
+
return (_jsxs("div", { className: "chat-admin-form", children: [loading && _jsx("p", { children: "Loading reports\u2026" }), !loading && failed && (_jsxs("p", { role: "alert", children: ["Reports could not be loaded.", ' ', _jsx(Button, { onPress: () => void refresh(requested.current), children: "Try again" })] })), !loading && page && page.reports.length === 0 && _jsx("p", { children: "No open reports." }), !loading && page && page.reports.length > 0 && (_jsx("ul", { className: "chat-admin-people", children: page.reports.map((report) => {
|
|
244
|
+
const roomId = report.room_id;
|
|
245
|
+
const subject = report.sender;
|
|
246
|
+
return (_jsxs("li", { children: [_jsxs("span", { children: [subject ?? 'Unknown sender', report.reason ? ` · ${report.reason}` : ''] }), roomId && subject && (_jsx(Confirm, { label: "Ban", consequence: `Ban ${subject} from this channel?`, onConfirm: async () => {
|
|
247
|
+
const ok = await run({
|
|
248
|
+
operation: 'ban',
|
|
249
|
+
roomId,
|
|
250
|
+
subject,
|
|
251
|
+
reason: report.reason ?? undefined,
|
|
252
|
+
});
|
|
253
|
+
if (ok)
|
|
254
|
+
await refresh(cursor);
|
|
255
|
+
return ok;
|
|
256
|
+
} }))] }, report.id));
|
|
257
|
+
}) })), _jsxs("div", { className: "chat-admin-toolbar", children: [cursor && _jsx(Button, { onPress: () => void refresh(), children: "First page" }), page?.next_cursor && (_jsx(Button, { onPress: () => void refresh(page.next_cursor ?? undefined), children: "Next reports" }))] })] }));
|
|
258
|
+
}
|
|
145
259
|
function Confirm({ label, consequence, onConfirm, }) {
|
|
146
260
|
const [confirming, setConfirming] = useState(false);
|
|
147
261
|
const trigger = useRef(null);
|
package/dist/chat/client.d.ts
CHANGED
|
@@ -8,13 +8,21 @@ export declare const MAX_UPLOAD_BYTES: number;
|
|
|
8
8
|
* A chat session behind the exchange: a matrix-js-sdk `MatrixClient` the
|
|
9
9
|
* caller never sees, refreshed on its own, exposing only what a UI needs.
|
|
10
10
|
*
|
|
11
|
-
* **Crypto stays off
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
11
|
+
* **Crypto stays off unless asked for.** `encryptionEnabled` gates a call
|
|
12
|
+
* to `initRustCrypto()`, made once, right after the `MatrixClient` exists
|
|
13
|
+
* and before anything else touches this closure's own state -- key
|
|
14
|
+
* backup, recovery key and device verification (chat#67-69) all need a
|
|
15
|
+
* running `CryptoApi` (`getCrypto()`) to build against. Omitted or
|
|
16
|
+
* `false`, this behaves exactly as it always has and never calls it at
|
|
17
|
+
* all: matrix-js-sdk only imports its Rust crypto WASM when
|
|
18
|
+
* `initRustCrypto()` is called (`client.js`: "importing rust-crypto will
|
|
19
|
+
* download the webassembly, so we delay it until we know it will be
|
|
20
|
+
* [needed]") -- so skipping it means the WASM module is never loaded, in
|
|
21
|
+
* the browser or under vitest. No shim or polyfill for it is needed
|
|
22
|
+
* either way. Its own store, bound to the exchanged identity the same
|
|
23
|
+
* tuple `createChatStore` binds the sync one to (`cryptoStoreDbPrefix`) --
|
|
24
|
+
* without that, matrix-js-sdk's fixed default name is shared by every
|
|
25
|
+
* client in the browser (chat#71 review).
|
|
18
26
|
*
|
|
19
27
|
* **Refresh, not a Matrix refresh token.** There is no such thing (section
|
|
20
28
|
* 4): a near-expiry timer and a `Session.logged_out` listener (fired by
|