@wtfalch/chat 0.5.1 → 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 +101 -17
- 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
|
@@ -6,6 +6,9 @@ export type FakeRoomSeed = {
|
|
|
6
6
|
isDirect?: boolean;
|
|
7
7
|
/** Seeds `unread_notifications.notification_count`. Defaults to `0`. */
|
|
8
8
|
notificationCount?: number;
|
|
9
|
+
/** Seeds `unread_notifications.highlight_count` -- the subset of
|
|
10
|
+
* `notificationCount` that mentions this account. Defaults to `0`. */
|
|
11
|
+
highlightCount?: number;
|
|
9
12
|
/** An `m.space` rather than a room -- the company space. Its `members`
|
|
10
13
|
* are what `client.people()` reads. Defaults to `false`. */
|
|
11
14
|
isSpace?: boolean;
|
|
@@ -23,6 +26,13 @@ export type FakeRoomSeed = {
|
|
|
23
26
|
* reads to report a room unsearchable (agora#252). Defaults to
|
|
24
27
|
* `false`. */
|
|
25
28
|
encrypted?: boolean;
|
|
29
|
+
/** Seeds an `m.room.power_levels` state event with `events_default: 100`
|
|
30
|
+
* -- the one thing `ChatRoomSummary.archived` and `AdminChannel.archived`
|
|
31
|
+
* both read to report a room's member writes locked. Defaults to
|
|
32
|
+
* `false`, which seeds no such event (an unset `events_default`
|
|
33
|
+
* defaults to `0` in real Matrix, same as the client and admin reads
|
|
34
|
+
* treat it). */
|
|
35
|
+
archived?: boolean;
|
|
26
36
|
/** Seeds this room as an unanswered invitation to the fake account
|
|
27
37
|
* itself, rather than a room it has joined -- a `rooms.invite` entry
|
|
28
38
|
* with the stripped state real Matrix delivers one in, the one shape
|
|
@@ -58,6 +68,11 @@ export type FakeMember = {
|
|
|
58
68
|
userId: string;
|
|
59
69
|
/** Their `m.room.member` display name. Defaults to the user id. */
|
|
60
70
|
name?: string;
|
|
71
|
+
/** Marks this member a guest, carrying `GUEST_MARKER_KEY` on their
|
|
72
|
+
* `m.room.member` content with `{ until: guestUntil }` -- what
|
|
73
|
+
* `client.ts`'s `readGuest` reads into `ChatPerson.guest`. Omitted for
|
|
74
|
+
* an ordinary member. */
|
|
75
|
+
guestUntil?: string;
|
|
61
76
|
};
|
|
62
77
|
export type FakeChatServerOptions = {
|
|
63
78
|
/** Defaults to a distinct `https://chat.<random>.example.test`, so two
|
|
@@ -70,6 +85,11 @@ export type FakeChatServerOptions = {
|
|
|
70
85
|
* which does not care about refresh timing never trips it by accident. */
|
|
71
86
|
tokenLifetimeMs?: number;
|
|
72
87
|
now?: () => number;
|
|
88
|
+
/** Whether `/versions` advertises MSC4133 extended profiles. Defaults to
|
|
89
|
+
* `true`; a test simulating production before
|
|
90
|
+
* wtfalch/foundry#41 turns it on passes `false`, the same "off" every
|
|
91
|
+
* company's Synapse ships with today (`docs/status.md`). */
|
|
92
|
+
extendedProfilesEnabled?: boolean;
|
|
73
93
|
};
|
|
74
94
|
/**
|
|
75
95
|
* A fake exchange endpoint and a fake homeserver, both answered by
|
|
@@ -98,6 +118,20 @@ export declare class FakeChatServer {
|
|
|
98
118
|
* gives a member, which `pinMessage`/`unpinMessage` must reject on
|
|
99
119
|
* rather than resolve quietly. */
|
|
100
120
|
pinStatus: number;
|
|
121
|
+
/** What `PUT .../send/...` answers with -- anything but 200 fails the
|
|
122
|
+
* send, with nothing stored. */
|
|
123
|
+
sendStatus: number;
|
|
124
|
+
/** Holds every thread follow `GET` until it resolves -- for a test of a
|
|
125
|
+
* read that is still in flight when the person clicks. */
|
|
126
|
+
threadFollowReadBarrier: Promise<void> | null;
|
|
127
|
+
/** What a thread follow `GET` answers with. */
|
|
128
|
+
threadFollowReadStatus: number;
|
|
129
|
+
/** Every call to the thread follow route, in arrival order. */
|
|
130
|
+
readonly threadFollowRequests: Array<{
|
|
131
|
+
method: string;
|
|
132
|
+
roomId: string;
|
|
133
|
+
rootId: string;
|
|
134
|
+
}>;
|
|
101
135
|
readonly userId: string;
|
|
102
136
|
/** The Matrix server name, as `userId` gives it -- what an `mxc://`
|
|
103
137
|
* reference from this homeserver names. */
|
|
@@ -149,6 +183,12 @@ export declare class FakeChatServer {
|
|
|
149
183
|
path: string;
|
|
150
184
|
authorised: boolean;
|
|
151
185
|
}>;
|
|
186
|
+
/** Who follows which thread, as `apps/chat-service`'s thread follow
|
|
187
|
+
* route keeps it: `roomId rootId` -> whether the person unfollowed. A
|
|
188
|
+
* thread with no entry is not followed. */
|
|
189
|
+
readonly threadFollows: Map<string, {
|
|
190
|
+
muted: boolean;
|
|
191
|
+
}>;
|
|
152
192
|
/** Every `PUT .../typing/...` this server has answered, in order -- for a
|
|
153
193
|
* test that asserts `sendTyping` actually reached the wire, with what
|
|
154
194
|
* it sent. */
|
|
@@ -174,15 +214,40 @@ export declare class FakeChatServer {
|
|
|
174
214
|
* `sentPresence` would pass against a client that cannot hold anybody
|
|
175
215
|
* away for longer than one poll. */
|
|
176
216
|
readonly syncPresence: Array<string | undefined>;
|
|
217
|
+
/** Every `PUT`/`DELETE` on an MSC4133 extended-profile property this
|
|
218
|
+
* server has answered, in order -- what `ChatClient.setOwnStatus`
|
|
219
|
+
* writes. `value: undefined` records a delete. */
|
|
220
|
+
readonly extendedProfileWrites: Array<{
|
|
221
|
+
userId: string;
|
|
222
|
+
key: string;
|
|
223
|
+
value: unknown;
|
|
224
|
+
}>;
|
|
177
225
|
/** Rooms currently carrying the room-scoped `dont_notify` push rule, for
|
|
178
226
|
* a test that wants to assert on the server's own state rather than
|
|
179
227
|
* only through the client's `rooms()`. */
|
|
180
228
|
get mutedRoomIds(): string[];
|
|
229
|
+
/** Rooms currently carrying MSC2867's marked-unread flag, for a test that
|
|
230
|
+
* wants to assert on the server's own state rather than only through the
|
|
231
|
+
* client's `rooms()`. */
|
|
232
|
+
get markedUnreadRoomIds(): string[];
|
|
181
233
|
constructor(options?: FakeChatServerOptions);
|
|
234
|
+
/** Sets `userId`'s MSC4133 extended-profile `key` directly, for a test
|
|
235
|
+
* simulating "somebody else already has this set on the server" --
|
|
236
|
+
* `ChatClient.status`'s background fetch then reads it exactly as it
|
|
237
|
+
* would a real peer's. Real Matrix never lets a client PUT anyone's
|
|
238
|
+
* profile but its own, which is why this exists as a server-side seed
|
|
239
|
+
* rather than something `setOwnStatus` could reach. */
|
|
240
|
+
seedExtendedProfile(userId: string, key: string, value: unknown): void;
|
|
182
241
|
dispose(): void;
|
|
183
242
|
/** Resolves once a `/sync` request is parked waiting for a test to drive
|
|
184
243
|
* it -- immediately if one already is. */
|
|
185
244
|
waitForParkedPoll(): Promise<void>;
|
|
245
|
+
/** Delivers a parked poll as if another of this account's own devices
|
|
246
|
+
* had just written `type` room account data for `roomId` -- a draft,
|
|
247
|
+
* most likely -- the way a real incremental `/sync` carries a change
|
|
248
|
+
* made from elsewhere. Throws if nothing is parked -- await
|
|
249
|
+
* `waitForParkedPoll()` first. */
|
|
250
|
+
receiveRoomAccountData(roomId: string, type: string, content: Record<string, unknown>): void;
|
|
186
251
|
/** Adds a room and, if a poll is parked, delivers it now. Throws if
|
|
187
252
|
* nothing is parked -- await `waitForParkedPoll()` first. */
|
|
188
253
|
addRoom(seed: FakeRoomSeed): void;
|
|
@@ -202,9 +267,12 @@ export declare class FakeChatServer {
|
|
|
202
267
|
/** Delivers a parked poll as an existing, already-known room receiving
|
|
203
268
|
* one new message from the fake peer -- a timeline event and a bumped
|
|
204
269
|
* notification count together, the way a real incremental `/sync`
|
|
205
|
-
* carries both at once.
|
|
206
|
-
*
|
|
207
|
-
|
|
270
|
+
* carries both at once. `highlightCount` defaults to `0`: an ordinary
|
|
271
|
+
* message that does not mention this account, same as Matrix would
|
|
272
|
+
* report. Pass it to simulate a mention arriving. Returns the minted
|
|
273
|
+
* event id, for a test that then calls `markRoomRead` against it.
|
|
274
|
+
* Throws if nothing is parked. */
|
|
275
|
+
receiveMessage(roomId: string, notificationCount?: number, highlightCount?: number): string;
|
|
208
276
|
/** Delivers a parked poll renaming an already-known room -- an
|
|
209
277
|
* `m.room.name` state event, the way a real incremental `/sync` carries
|
|
210
278
|
* a rename. Throws if nothing is parked. */
|
package/dist/chat/fake/server.js
CHANGED
|
@@ -36,6 +36,16 @@ export class FakeChatServer {
|
|
|
36
36
|
* gives a member, which `pinMessage`/`unpinMessage` must reject on
|
|
37
37
|
* rather than resolve quietly. */
|
|
38
38
|
pinStatus = 200;
|
|
39
|
+
/** What `PUT .../send/...` answers with -- anything but 200 fails the
|
|
40
|
+
* send, with nothing stored. */
|
|
41
|
+
sendStatus = 200;
|
|
42
|
+
/** Holds every thread follow `GET` until it resolves -- for a test of a
|
|
43
|
+
* read that is still in flight when the person clicks. */
|
|
44
|
+
threadFollowReadBarrier = null;
|
|
45
|
+
/** What a thread follow `GET` answers with. */
|
|
46
|
+
threadFollowReadStatus = 200;
|
|
47
|
+
/** Every call to the thread follow route, in arrival order. */
|
|
48
|
+
threadFollowRequests = [];
|
|
39
49
|
userId;
|
|
40
50
|
/** The Matrix server name, as `userId` gives it -- what an `mxc://`
|
|
41
51
|
* reference from this homeserver names. */
|
|
@@ -65,6 +75,10 @@ export class FakeChatServer {
|
|
|
65
75
|
* request carried -- for a test that asserts nothing reaches the
|
|
66
76
|
* legacy unauthenticated endpoints, and that the token was sent. */
|
|
67
77
|
mediaRequests = [];
|
|
78
|
+
/** Who follows which thread, as `apps/chat-service`'s thread follow
|
|
79
|
+
* route keeps it: `roomId rootId` -> whether the person unfollowed. A
|
|
80
|
+
* thread with no entry is not followed. */
|
|
81
|
+
threadFollows = new Map();
|
|
68
82
|
/** Every `PUT .../typing/...` this server has answered, in order -- for a
|
|
69
83
|
* test that asserts `sendTyping` actually reached the wire, with what
|
|
70
84
|
* it sent. */
|
|
@@ -82,12 +96,22 @@ export class FakeChatServer {
|
|
|
82
96
|
* `sentPresence` would pass against a client that cannot hold anybody
|
|
83
97
|
* away for longer than one poll. */
|
|
84
98
|
syncPresence = [];
|
|
99
|
+
/** Every `PUT`/`DELETE` on an MSC4133 extended-profile property this
|
|
100
|
+
* server has answered, in order -- what `ChatClient.setOwnStatus`
|
|
101
|
+
* writes. `value: undefined` records a delete. */
|
|
102
|
+
extendedProfileWrites = [];
|
|
85
103
|
/** Rooms currently carrying the room-scoped `dont_notify` push rule, for
|
|
86
104
|
* a test that wants to assert on the server's own state rather than
|
|
87
105
|
* only through the client's `rooms()`. */
|
|
88
106
|
get mutedRoomIds() {
|
|
89
107
|
return [...this.#mutedRooms];
|
|
90
108
|
}
|
|
109
|
+
/** Rooms currently carrying MSC2867's marked-unread flag, for a test that
|
|
110
|
+
* wants to assert on the server's own state rather than only through the
|
|
111
|
+
* client's `rooms()`. */
|
|
112
|
+
get markedUnreadRoomIds() {
|
|
113
|
+
return [...this.#markedUnread.entries()].filter(([, unread]) => unread).map(([id]) => id);
|
|
114
|
+
}
|
|
91
115
|
#dispose;
|
|
92
116
|
#rooms;
|
|
93
117
|
#tokenLifetimeMs;
|
|
@@ -111,12 +135,31 @@ export class FakeChatServer {
|
|
|
111
135
|
* of it -- matrix-js-sdk asks for both while it builds a thread. */
|
|
112
136
|
#events = new Map();
|
|
113
137
|
#tags = new Map();
|
|
138
|
+
/** Room-scoped account data a test or the client has set on a room,
|
|
139
|
+
* keyed by room id then event type -- what `client.setDraft` and
|
|
140
|
+
* `client.setRoomAccountData` more generally write, distinct from
|
|
141
|
+
* `#tags`'s own `m.tag` shape. */
|
|
142
|
+
#roomAccountData = new Map();
|
|
114
143
|
/** Rooms carrying the account's room-scoped `dont_notify` push rule --
|
|
115
144
|
* what `muteRoom` writes and takes away, and the only rule kind this
|
|
116
145
|
* fake bothers to model. Read back through `/pushrules/`, exactly as
|
|
117
146
|
* Synapse would answer it, so a test never has to reach past the
|
|
118
147
|
* client's own `rooms()` to know a mute landed. */
|
|
119
148
|
#mutedRooms = new Set();
|
|
149
|
+
/** Rooms carrying MSC2867's marked-unread flag -- what `markRoomUnread`
|
|
150
|
+
* writes as room-scoped account data under both `m.marked_unread` and
|
|
151
|
+
* `com.famedly.marked_unread`. One value stands for both keys: a real
|
|
152
|
+
* client never has a reason to disagree with itself about which key
|
|
153
|
+
* means what it wrote. */
|
|
154
|
+
#markedUnread = new Map();
|
|
155
|
+
/** MSC4133 extended-profile properties, keyed by user id then property
|
|
156
|
+
* key -- what `setOwnStatus` PUTs and DELETEs on the signed-in
|
|
157
|
+
* account's own entry, and `status`'s background fetch GETs for
|
|
158
|
+
* anyone. `seedExtendedProfile` writes another (peer) user's entry
|
|
159
|
+
* directly, since real Matrix never lets a client set anyone's profile
|
|
160
|
+
* but its own. */
|
|
161
|
+
#extendedProfiles = new Map();
|
|
162
|
+
#extendedProfilesEnabled;
|
|
120
163
|
#roomSeq = 0;
|
|
121
164
|
#mediaSeq = 0;
|
|
122
165
|
/** Deliveries made while no poll was parked, waiting for the next one --
|
|
@@ -132,6 +175,7 @@ export class FakeChatServer {
|
|
|
132
175
|
this.#rooms = [...(options.rooms ?? [])];
|
|
133
176
|
this.#tokenLifetimeMs = options.tokenLifetimeMs ?? 10 * 60_000;
|
|
134
177
|
this.#now = options.now ?? Date.now;
|
|
178
|
+
this.#extendedProfilesEnabled = options.extendedProfilesEnabled ?? true;
|
|
135
179
|
for (const room of this.#rooms)
|
|
136
180
|
this.#materialise(room);
|
|
137
181
|
for (const room of this.#rooms) {
|
|
@@ -143,6 +187,20 @@ export class FakeChatServer {
|
|
|
143
187
|
}
|
|
144
188
|
this.#dispose = installFetchRoute((input, init) => this.#route(input, init));
|
|
145
189
|
}
|
|
190
|
+
/** Sets `userId`'s MSC4133 extended-profile `key` directly, for a test
|
|
191
|
+
* simulating "somebody else already has this set on the server" --
|
|
192
|
+
* `ChatClient.status`'s background fetch then reads it exactly as it
|
|
193
|
+
* would a real peer's. Real Matrix never lets a client PUT anyone's
|
|
194
|
+
* profile but its own, which is why this exists as a server-side seed
|
|
195
|
+
* rather than something `setOwnStatus` could reach. */
|
|
196
|
+
seedExtendedProfile(userId, key, value) {
|
|
197
|
+
let profile = this.#extendedProfiles.get(userId);
|
|
198
|
+
if (!profile) {
|
|
199
|
+
profile = new Map();
|
|
200
|
+
this.#extendedProfiles.set(userId, profile);
|
|
201
|
+
}
|
|
202
|
+
profile.set(key, value);
|
|
203
|
+
}
|
|
146
204
|
dispose() {
|
|
147
205
|
if (this.#disposed)
|
|
148
206
|
return;
|
|
@@ -162,6 +220,18 @@ export class FakeChatServer {
|
|
|
162
220
|
return;
|
|
163
221
|
await new Promise((resolve) => this.#parkedWaiters.push(resolve));
|
|
164
222
|
}
|
|
223
|
+
/** Delivers a parked poll as if another of this account's own devices
|
|
224
|
+
* had just written `type` room account data for `roomId` -- a draft,
|
|
225
|
+
* most likely -- the way a real incremental `/sync` carries a change
|
|
226
|
+
* made from elsewhere. Throws if nothing is parked -- await
|
|
227
|
+
* `waitForParkedPoll()` first. */
|
|
228
|
+
receiveRoomAccountData(roomId, type, content) {
|
|
229
|
+
this.#storeRoomAccountData(roomId, type, content);
|
|
230
|
+
const seed = this.#rooms.find((room) => room.id === roomId);
|
|
231
|
+
if (!seed)
|
|
232
|
+
return;
|
|
233
|
+
this.#deliverParked({ [roomId]: this.#joinEntry(seed) });
|
|
234
|
+
}
|
|
165
235
|
/** Adds a room and, if a poll is parked, delivers it now. Throws if
|
|
166
236
|
* nothing is parked -- await `waitForParkedPoll()` first. */
|
|
167
237
|
addRoom(seed) {
|
|
@@ -203,9 +273,12 @@ export class FakeChatServer {
|
|
|
203
273
|
/** Delivers a parked poll as an existing, already-known room receiving
|
|
204
274
|
* one new message from the fake peer -- a timeline event and a bumped
|
|
205
275
|
* notification count together, the way a real incremental `/sync`
|
|
206
|
-
* carries both at once.
|
|
207
|
-
*
|
|
208
|
-
|
|
276
|
+
* carries both at once. `highlightCount` defaults to `0`: an ordinary
|
|
277
|
+
* message that does not mention this account, same as Matrix would
|
|
278
|
+
* report. Pass it to simulate a mention arriving. Returns the minted
|
|
279
|
+
* event id, for a test that then calls `markRoomRead` against it.
|
|
280
|
+
* Throws if nothing is parked. */
|
|
281
|
+
receiveMessage(roomId, notificationCount = 1, highlightCount = 0) {
|
|
209
282
|
this.#eventSeq += 1;
|
|
210
283
|
const eventId = `$msg-${this.#eventSeq}`;
|
|
211
284
|
this.#deliverParked({
|
|
@@ -227,7 +300,10 @@ export class FakeChatServer {
|
|
|
227
300
|
},
|
|
228
301
|
ephemeral: { events: [] },
|
|
229
302
|
account_data: { events: [] },
|
|
230
|
-
unread_notifications: {
|
|
303
|
+
unread_notifications: {
|
|
304
|
+
highlight_count: highlightCount,
|
|
305
|
+
notification_count: notificationCount,
|
|
306
|
+
},
|
|
231
307
|
},
|
|
232
308
|
});
|
|
233
309
|
return eventId;
|
|
@@ -299,15 +375,27 @@ export class FakeChatServer {
|
|
|
299
375
|
: [];
|
|
300
376
|
}
|
|
301
377
|
/** A room's own account data: the tags a test or the client has set on
|
|
302
|
-
* it
|
|
378
|
+
* it (`m.tag`, how `hideDirectMessage` reaches `room.tags`), MSC2867's
|
|
379
|
+
* marked-unread flag under both keys `markRoomUnread` writes, plus
|
|
380
|
+
* whatever else `#roomAccountData` holds -- a draft, most likely. */
|
|
303
381
|
#roomAccountDataEvents(roomId) {
|
|
382
|
+
const events = [];
|
|
304
383
|
const tags = this.#tags.get(roomId);
|
|
305
|
-
if (
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
384
|
+
if (tags) {
|
|
385
|
+
const content = {};
|
|
386
|
+
for (const tag of tags)
|
|
387
|
+
content[tag] = {};
|
|
388
|
+
events.push({ type: 'm.tag', content: { tags: content } });
|
|
389
|
+
}
|
|
390
|
+
const unread = this.#markedUnread.get(roomId);
|
|
391
|
+
if (unread !== undefined) {
|
|
392
|
+
events.push({ type: 'm.marked_unread', content: { unread } });
|
|
393
|
+
events.push({ type: 'com.famedly.marked_unread', content: { unread } });
|
|
394
|
+
}
|
|
395
|
+
for (const [type, content] of this.#roomAccountData.get(roomId) ?? []) {
|
|
396
|
+
events.push({ type, content });
|
|
397
|
+
}
|
|
398
|
+
return events;
|
|
311
399
|
}
|
|
312
400
|
#memberEvent(seed, member, membership) {
|
|
313
401
|
return {
|
|
@@ -316,7 +404,14 @@ export class FakeChatServer {
|
|
|
316
404
|
event_id: `$member-${seed.id}-${member.userId}-${membership}`,
|
|
317
405
|
sender: this.userId,
|
|
318
406
|
origin_server_ts: this.#now(),
|
|
319
|
-
content: {
|
|
407
|
+
content: {
|
|
408
|
+
membership,
|
|
409
|
+
displayname: member.name ?? member.userId,
|
|
410
|
+
// 'dev.wtfalch.chat.guest' -- see `client.ts`'s `GUEST_MARKER_KEY`.
|
|
411
|
+
...(member.guestUntil !== undefined
|
|
412
|
+
? { 'dev.wtfalch.chat.guest': { until: member.guestUntil } }
|
|
413
|
+
: {}),
|
|
414
|
+
},
|
|
320
415
|
};
|
|
321
416
|
}
|
|
322
417
|
#joinEntry(seed) {
|
|
@@ -373,6 +468,16 @@ export class FakeChatServer {
|
|
|
373
468
|
content: { algorithm: 'm.megolm.v1.aes-sha2' },
|
|
374
469
|
});
|
|
375
470
|
}
|
|
471
|
+
if (seed.archived) {
|
|
472
|
+
events.push({
|
|
473
|
+
type: 'm.room.power_levels',
|
|
474
|
+
state_key: '',
|
|
475
|
+
event_id: `$power-levels-${seed.id}`,
|
|
476
|
+
sender: this.userId,
|
|
477
|
+
origin_server_ts: now,
|
|
478
|
+
content: { events_default: 100 },
|
|
479
|
+
});
|
|
480
|
+
}
|
|
376
481
|
return {
|
|
377
482
|
summary: {},
|
|
378
483
|
state: { events },
|
|
@@ -383,7 +488,10 @@ export class FakeChatServer {
|
|
|
383
488
|
},
|
|
384
489
|
ephemeral: { events: [] },
|
|
385
490
|
account_data: { events: this.#roomAccountDataEvents(seed.id) },
|
|
386
|
-
unread_notifications: {
|
|
491
|
+
unread_notifications: {
|
|
492
|
+
highlight_count: seed.highlightCount ?? 0,
|
|
493
|
+
notification_count: seed.notificationCount ?? 0,
|
|
494
|
+
},
|
|
387
495
|
};
|
|
388
496
|
}
|
|
389
497
|
/** A room's invite-state entry: the stripped state real Matrix delivers
|
|
@@ -686,6 +794,32 @@ export class FakeChatServer {
|
|
|
686
794
|
if (seed)
|
|
687
795
|
this.#deliverOrQueue({ [roomId]: this.#joinEntry(seed) });
|
|
688
796
|
}
|
|
797
|
+
/** What `markRoomUnread` PUTs, under either key it writes -- see
|
|
798
|
+
* `ChatClient.markRoomUnread`. Echoed back the same way `#setTag` echoes
|
|
799
|
+
* a tag: as part of the room's own next join entry, so a client that
|
|
800
|
+
* actually reads its account data off `/sync` (rather than trusting its
|
|
801
|
+
* own local echo) sees the same answer. */
|
|
802
|
+
#setMarkedUnread(roomId, unread) {
|
|
803
|
+
this.#markedUnread.set(roomId, unread);
|
|
804
|
+
const seed = this.#rooms.find((room) => room.id === roomId);
|
|
805
|
+
if (seed)
|
|
806
|
+
this.#deliverOrQueue({ [roomId]: this.#joinEntry(seed) });
|
|
807
|
+
}
|
|
808
|
+
#storeRoomAccountData(roomId, type, content) {
|
|
809
|
+
const forRoom = this.#roomAccountData.get(roomId) ?? new Map();
|
|
810
|
+
forRoom.set(type, content);
|
|
811
|
+
this.#roomAccountData.set(roomId, forRoom);
|
|
812
|
+
}
|
|
813
|
+
/** What `PUT .../rooms/{roomId}/account_data/{type}` writes -- a draft,
|
|
814
|
+
* most likely. Delivered back through the room's `join` entry exactly
|
|
815
|
+
* like `#setTag`, so the writing client's own next poll sees it the
|
|
816
|
+
* same way real Matrix account data comes back through `/sync`. */
|
|
817
|
+
#setRoomAccountData(roomId, type, content) {
|
|
818
|
+
this.#storeRoomAccountData(roomId, type, content);
|
|
819
|
+
const seed = this.#rooms.find((room) => room.id === roomId);
|
|
820
|
+
if (seed)
|
|
821
|
+
this.#deliverOrQueue({ [roomId]: this.#joinEntry(seed) });
|
|
822
|
+
}
|
|
689
823
|
#handleExchange(init) {
|
|
690
824
|
this.exchangeCount += 1;
|
|
691
825
|
const zitadelToken = bearerToken(init);
|
|
@@ -766,7 +900,17 @@ export class FakeChatServer {
|
|
|
766
900
|
return null;
|
|
767
901
|
const url = new URL(rawUrl);
|
|
768
902
|
if (url.pathname === '/_matrix/client/versions') {
|
|
769
|
-
return Promise.resolve(jsonResponse(200, {
|
|
903
|
+
return Promise.resolve(jsonResponse(200, {
|
|
904
|
+
versions: ['v1.4'],
|
|
905
|
+
// Only the unstable flag, never `.stable` -- `doesServerSupport
|
|
906
|
+
// ExtendedProfiles` reads either, but `getExtendedProfileRequest
|
|
907
|
+
// Prefix` only takes the `/_matrix/client/v3` path for `.stable`
|
|
908
|
+
// or a real v1.16, so this keeps every extended-profile request
|
|
909
|
+
// on the `/_matrix/client/unstable/uk.tcpip.msc4133` prefix the
|
|
910
|
+
// route below answers -- the same "off by default" MSC4133 gate
|
|
911
|
+
// `docs/status.md` describes for real Synapse.
|
|
912
|
+
unstable_features: { 'uk.tcpip.msc4133': this.#extendedProfilesEnabled },
|
|
913
|
+
}));
|
|
770
914
|
}
|
|
771
915
|
if (url.pathname === '/_matrix/client/v3/pushrules/') {
|
|
772
916
|
return Promise.resolve(jsonResponse(200, {
|
|
@@ -972,6 +1116,9 @@ export class FakeChatServer {
|
|
|
972
1116
|
}
|
|
973
1117
|
const send = url.pathname.match(/^\/_matrix\/client\/v3\/rooms\/([^/]+)\/send\/([^/]+)\/([^/]+)$/);
|
|
974
1118
|
if (send && this.#authorised(init)) {
|
|
1119
|
+
if (this.sendStatus !== 200) {
|
|
1120
|
+
return Promise.resolve(jsonResponse(this.sendStatus, { errcode: 'M_FORBIDDEN' }));
|
|
1121
|
+
}
|
|
975
1122
|
let content = {};
|
|
976
1123
|
try {
|
|
977
1124
|
content = JSON.parse(String(init?.body ?? '{}'));
|
|
@@ -1082,6 +1229,44 @@ export class FakeChatServer {
|
|
|
1082
1229
|
return jsonResponse(200, { content_uri: `mxc://${this.serverName}/${mediaId}` });
|
|
1083
1230
|
})();
|
|
1084
1231
|
}
|
|
1232
|
+
// `apps/chat-service`'s thread follow route: the same rule the real one
|
|
1233
|
+
// has -- an automatic follow never undoes an unfollow.
|
|
1234
|
+
const chatThread = url.pathname.match(/^\/_chat\/threads\/([^/]+)\/([^/]+)\/follow$/);
|
|
1235
|
+
if (chatThread) {
|
|
1236
|
+
if (!this.#authorised(init)) {
|
|
1237
|
+
return Promise.resolve(jsonResponse(401, { error: 'token_invalid' }));
|
|
1238
|
+
}
|
|
1239
|
+
const roomId = decodeURIComponent(chatThread[1]);
|
|
1240
|
+
if (!this.#rooms.some((room) => room.id === roomId)) {
|
|
1241
|
+
return Promise.resolve(jsonResponse(403, { error: 'not_a_member' }));
|
|
1242
|
+
}
|
|
1243
|
+
const rootId = decodeURIComponent(chatThread[2]);
|
|
1244
|
+
const key = `${roomId} ${rootId}`;
|
|
1245
|
+
const method = init?.method ?? 'GET';
|
|
1246
|
+
this.threadFollowRequests.push({ method, roomId, rootId });
|
|
1247
|
+
if (method === 'GET') {
|
|
1248
|
+
// The answer is what was true when the request arrived, however
|
|
1249
|
+
// long the barrier holds it.
|
|
1250
|
+
const barrier = this.threadFollowReadBarrier;
|
|
1251
|
+
const status = this.threadFollowReadStatus;
|
|
1252
|
+
const found = this.threadFollows.get(key);
|
|
1253
|
+
return (async () => {
|
|
1254
|
+
await barrier;
|
|
1255
|
+
if (status !== 200)
|
|
1256
|
+
return jsonResponse(status, { error: 'internal_error' });
|
|
1257
|
+
return jsonResponse(200, { following: found !== undefined && !found.muted });
|
|
1258
|
+
})();
|
|
1259
|
+
}
|
|
1260
|
+
if (method === 'DELETE')
|
|
1261
|
+
this.threadFollows.set(key, { muted: true });
|
|
1262
|
+
if (method === 'PUT') {
|
|
1263
|
+
const auto = JSON.parse(String(init?.body ?? '{}')).auto === true;
|
|
1264
|
+
if (!auto || !this.threadFollows.has(key))
|
|
1265
|
+
this.threadFollows.set(key, { muted: false });
|
|
1266
|
+
}
|
|
1267
|
+
const found = this.threadFollows.get(key);
|
|
1268
|
+
return Promise.resolve(jsonResponse(200, { following: found !== undefined && !found.muted }));
|
|
1269
|
+
}
|
|
1085
1270
|
// `apps/chat-service`'s media proxy (wtfalch/chat#32). The same two
|
|
1086
1271
|
// checks the real one makes: the account is still in `roomId`, and
|
|
1087
1272
|
// `eventId` is a message sent there that references this media.
|
|
@@ -1150,6 +1335,31 @@ export class FakeChatServer {
|
|
|
1150
1335
|
}
|
|
1151
1336
|
return Promise.resolve(jsonResponse(200, {}));
|
|
1152
1337
|
}
|
|
1338
|
+
// What `client.setRoomAccountData` PUTs -- both keys `markRoomUnread`
|
|
1339
|
+
// writes (see `ChatClient.markRoomUnread`) get the marked-unread
|
|
1340
|
+
// treatment; any other room-scoped account data type -- a draft, most
|
|
1341
|
+
// likely -- is stored generically through `#setRoomAccountData`.
|
|
1342
|
+
const roomAccountData = url.pathname.match(/^\/_matrix\/client\/v3\/user\/([^/]+)\/rooms\/([^/]+)\/account_data\/([^/]+)$/);
|
|
1343
|
+
if (roomAccountData && this.#authorised(init)) {
|
|
1344
|
+
const roomId = decodeURIComponent(roomAccountData[2]);
|
|
1345
|
+
const type = decodeURIComponent(roomAccountData[3]);
|
|
1346
|
+
let content = {};
|
|
1347
|
+
try {
|
|
1348
|
+
content = JSON.parse(String(init?.body ?? '{}'));
|
|
1349
|
+
}
|
|
1350
|
+
catch {
|
|
1351
|
+
// Same tolerance as every other write here: a malformed body is
|
|
1352
|
+
// recorded as sent rather than failing the test for a reason it
|
|
1353
|
+
// did not choose.
|
|
1354
|
+
}
|
|
1355
|
+
if (type === 'm.marked_unread' || type === 'com.famedly.marked_unread') {
|
|
1356
|
+
this.#setMarkedUnread(roomId, Boolean(content.unread));
|
|
1357
|
+
}
|
|
1358
|
+
else {
|
|
1359
|
+
this.#setRoomAccountData(roomId, type, content);
|
|
1360
|
+
}
|
|
1361
|
+
return Promise.resolve(jsonResponse(200, {}));
|
|
1362
|
+
}
|
|
1153
1363
|
const tag = url.pathname.match(/^\/_matrix\/client\/v3\/user\/([^/]+)\/rooms\/([^/]+)\/tags\/([^/]+)$/);
|
|
1154
1364
|
if (tag && this.#authorised(init)) {
|
|
1155
1365
|
this.#setTag(decodeURIComponent(tag[2]), decodeURIComponent(tag[3]), init?.method !== 'DELETE');
|
|
@@ -1207,6 +1417,39 @@ export class FakeChatServer {
|
|
|
1207
1417
|
});
|
|
1208
1418
|
return Promise.resolve(jsonResponse(200, {}));
|
|
1209
1419
|
}
|
|
1420
|
+
// What `getExtendedProfileProperty`/`setExtendedProfileProperty`/
|
|
1421
|
+
// `deleteExtendedProfileProperty` read and write -- MSC4133 extended
|
|
1422
|
+
// profiles, `ChatClient.status`'s own storage (`docs/status.md`). This
|
|
1423
|
+
// fake only ever advertises the unstable feature flag (see `/versions`
|
|
1424
|
+
// above), so matrix-js-sdk always asks this prefix, never `/_matrix/
|
|
1425
|
+
// client/v3/profile/...`.
|
|
1426
|
+
const extendedProfileProperty = url.pathname.match(/^\/_matrix\/client\/unstable\/uk\.tcpip\.msc4133\/profile\/([^/]+)\/([^/]+)$/);
|
|
1427
|
+
if (extendedProfileProperty && this.#authorised(init)) {
|
|
1428
|
+
const profileUserId = decodeURIComponent(extendedProfileProperty[1]);
|
|
1429
|
+
const key = decodeURIComponent(extendedProfileProperty[2]);
|
|
1430
|
+
if (init?.method === 'PUT') {
|
|
1431
|
+
let body = {};
|
|
1432
|
+
try {
|
|
1433
|
+
body = JSON.parse(String(init?.body ?? '{}'));
|
|
1434
|
+
}
|
|
1435
|
+
catch {
|
|
1436
|
+
// Same tolerance as every other write here.
|
|
1437
|
+
}
|
|
1438
|
+
this.seedExtendedProfile(profileUserId, key, body[key]);
|
|
1439
|
+
this.extendedProfileWrites.push({ userId: profileUserId, key, value: body[key] });
|
|
1440
|
+
return Promise.resolve(jsonResponse(200, {}));
|
|
1441
|
+
}
|
|
1442
|
+
if (init?.method === 'DELETE') {
|
|
1443
|
+
this.#extendedProfiles.get(profileUserId)?.delete(key);
|
|
1444
|
+
this.extendedProfileWrites.push({ userId: profileUserId, key, value: undefined });
|
|
1445
|
+
return Promise.resolve(jsonResponse(200, {}));
|
|
1446
|
+
}
|
|
1447
|
+
const value = this.#extendedProfiles.get(profileUserId)?.get(key);
|
|
1448
|
+
if (value === undefined) {
|
|
1449
|
+
return Promise.resolve(jsonResponse(404, { errcode: 'M_NOT_FOUND', error: 'Not found' }));
|
|
1450
|
+
}
|
|
1451
|
+
return Promise.resolve(jsonResponse(200, { [key]: value }));
|
|
1452
|
+
}
|
|
1210
1453
|
const receipt = url.pathname.match(/^\/_matrix\/client\/v3\/rooms\/([^/]+)\/receipt\/m\.read\/([^/]+)$/);
|
|
1211
1454
|
if (receipt) {
|
|
1212
1455
|
const token = bearerToken(init);
|
|
@@ -14,10 +14,10 @@ export type NewDirectMessageProps = {
|
|
|
14
14
|
* (`apps/agora/DESIGN.md`'s `Board`): an enamel card under an ink name-plate.
|
|
15
15
|
* Nothing floats, so the Flat Map Rule holds.
|
|
16
16
|
*
|
|
17
|
-
* Who is offered comes from `client.people()
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* (chat plan section 5),
|
|
21
|
-
* offer.
|
|
17
|
+
* Who is offered comes from `client.people()`: the company space's own
|
|
18
|
+
* membership, plus any guest sharing a room with the signed-in person
|
|
19
|
+
* (docs/guests.md). A guest outside a shared room is never offered -- the
|
|
20
|
+
* Synapse gate would refuse the invitation anyway (chat plan section 5),
|
|
21
|
+
* and an offer that ends in a refusal is not an offer.
|
|
22
22
|
*/
|
|
23
23
|
export declare function NewDirectMessage({ client, onStarted, onCancel }: NewDirectMessageProps): import("react").JSX.Element;
|
|
@@ -9,11 +9,11 @@ import { useCallback, useEffect, useState } from 'react';
|
|
|
9
9
|
* (`apps/agora/DESIGN.md`'s `Board`): an enamel card under an ink name-plate.
|
|
10
10
|
* Nothing floats, so the Flat Map Rule holds.
|
|
11
11
|
*
|
|
12
|
-
* Who is offered comes from `client.people()
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* (chat plan section 5),
|
|
16
|
-
* offer.
|
|
12
|
+
* Who is offered comes from `client.people()`: the company space's own
|
|
13
|
+
* membership, plus any guest sharing a room with the signed-in person
|
|
14
|
+
* (docs/guests.md). A guest outside a shared room is never offered -- the
|
|
15
|
+
* Synapse gate would refuse the invitation anyway (chat plan section 5),
|
|
16
|
+
* and an offer that ends in a refusal is not an offer.
|
|
17
17
|
*/
|
|
18
18
|
export function NewDirectMessage({ client, onStarted, onCancel }) {
|
|
19
19
|
const [people, setPeople] = useState(() => client.people());
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Button, Icon } from '@wtfalch/design';
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
4
|
import { Composer } from "./Composer.js";
|
|
4
5
|
import { Timeline } from "./Timeline.js";
|
|
5
6
|
/**
|
|
@@ -13,5 +14,47 @@ import { Timeline } from "./Timeline.js";
|
|
|
13
14
|
* panel. One word, one action, no second control that does the same thing.
|
|
14
15
|
*/
|
|
15
16
|
export function ThreadPanel({ client, roomId, threadId, onClose, onGoToRoot, now, sendOnEnter, }) {
|
|
16
|
-
|
|
17
|
+
// `null` until the first read answers, and again after a read fails.
|
|
18
|
+
const [following, setFollowing] = useState(null);
|
|
19
|
+
// Bumped by every click and every follow the person's own reply makes:
|
|
20
|
+
// a read that started before one of them answers stale, and is dropped.
|
|
21
|
+
const version = useRef(0);
|
|
22
|
+
const read = () => {
|
|
23
|
+
const started = version.current;
|
|
24
|
+
client
|
|
25
|
+
.threadFollowing(roomId, threadId)
|
|
26
|
+
.then((value) => {
|
|
27
|
+
if (version.current === started)
|
|
28
|
+
setFollowing(value);
|
|
29
|
+
})
|
|
30
|
+
.catch(() => { });
|
|
31
|
+
};
|
|
32
|
+
// Read on open, and listen for the follow the person's own reply makes.
|
|
33
|
+
// Nothing else re-reads: someone else's reply never changes it.
|
|
34
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: `client` is stable for a session.
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
version.current += 1;
|
|
37
|
+
setFollowing(null);
|
|
38
|
+
read();
|
|
39
|
+
const stop = client.onThreadFollowChanged(roomId, threadId, (value) => {
|
|
40
|
+
version.current += 1;
|
|
41
|
+
setFollowing(value);
|
|
42
|
+
});
|
|
43
|
+
return () => {
|
|
44
|
+
version.current += 1;
|
|
45
|
+
stop();
|
|
46
|
+
};
|
|
47
|
+
}, [roomId, threadId]);
|
|
48
|
+
const toggleFollow = () => {
|
|
49
|
+
// The state is not known yet, or the read failed: read it again.
|
|
50
|
+
if (following === null) {
|
|
51
|
+
read();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
version.current += 1;
|
|
55
|
+
const next = !following;
|
|
56
|
+
setFollowing(next);
|
|
57
|
+
(next ? client.followThread(roomId, threadId) : client.unfollowThread(roomId, threadId)).catch(() => setFollowing(!next));
|
|
58
|
+
};
|
|
59
|
+
return (_jsxs("aside", { className: "chat-thread", "aria-label": "Thread", children: [_jsxs("header", { className: "chat-thread-bar", children: [_jsxs(Button, { kind: "ghost", size: "sm", onPress: onClose, children: [_jsx(Icon, { name: "back", size: 16 }), "Back"] }), _jsx("span", { className: "chat-thread-heading", children: "Thread" }), _jsx(Button, { kind: "ghost", size: "sm", onPress: toggleFollow, children: following ? 'Unfollow' : 'Follow' }), _jsx(Button, { kind: "ghost", size: "sm", onPress: onGoToRoot, children: "Go to message" })] }), _jsx(Timeline, { client: client, roomId: roomId, threadId: threadId, now: now }, threadId), _jsx(Composer, { client: client, roomId: roomId, threadId: threadId, sendOnEnter: sendOnEnter }, `composer-${threadId}`)] }));
|
|
17
60
|
}
|