@wtfalch/chat 0.5.1 → 0.7.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 +755 -81
- package/dist/chat/fake/server.d.ts +94 -3
- package/dist/chat/fake/server.js +505 -26
- 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 +296 -12
- package/package.json +2 -2
package/dist/chat/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BackupTrustInfo, BootstrapCrossSigningOpts, CreateSecretStorageOpts, CryptoApi, DeviceVerificationStatus, GeneratedSecretStorageKey, KeyBackupCheck, KeyBackupInfo, SecretStorageStatus, UserVerificationStatus, VerificationRequest } from 'matrix-js-sdk/lib/crypto-api';
|
|
1
2
|
/**
|
|
2
3
|
* The exchange contract, as `apps/chat-service`'s README and
|
|
3
4
|
* `src/exchange.ts` define it: `POST <exchangeUrl>` with a ZITADEL bearer
|
|
@@ -61,21 +62,72 @@ export type ChatRoomSummary = {
|
|
|
61
62
|
* which is what keeps this field climbing while `muted` stops the
|
|
62
63
|
* bell. */
|
|
63
64
|
readonly unreadCount: number;
|
|
65
|
+
/** The subset of `unreadCount` that mentions this person by name, by
|
|
66
|
+
* display name, or through a room-wide `@room` -- Matrix's own
|
|
67
|
+
* `unread_notifications.highlight_count` from `/sync`, read the same
|
|
68
|
+
* way `unreadCount` reads `notification_count`. `unreadCount >=
|
|
69
|
+
* mentionCount` always holds, so a list needs no third field: weight
|
|
70
|
+
* (bold) on `unreadCount > 0`, a badge on `mentionCount > 0` -- the
|
|
71
|
+
* distinction every other chat client draws and this one could not
|
|
72
|
+
* (wtfalch/chat#45).
|
|
73
|
+
*
|
|
74
|
+
* Ships as the server figure alone, with the same gap `unreadCount`'s
|
|
75
|
+
* own docs would have if it only read Synapse: a muted room's
|
|
76
|
+
* `highlight_count` is gated by the same room-scoped `dont_notify` rule
|
|
77
|
+
* `muteRoom` writes, so it reads `0` there regardless of whether a
|
|
78
|
+
* message actually named this person. `unreadCount` solves this for
|
|
79
|
+
* itself with a local timeline walk (`unreadTimelineCount`); the same
|
|
80
|
+
* walk for highlights needs push-rule evaluation (display name,
|
|
81
|
+
* `@room`, `.m.rule.contains_user_name`) that is not built yet. A
|
|
82
|
+
* muted room is exactly the case this field exists for -- muting a
|
|
83
|
+
* channel and staying reachable by name is most of why people are
|
|
84
|
+
* willing to mute it at all -- so treat `mentionCount === 0` in a muted
|
|
85
|
+
* room as unproven, not as "nobody mentioned you", until that walk
|
|
86
|
+
* exists. */
|
|
87
|
+
readonly mentionCount: number;
|
|
64
88
|
/** Whether `muteRoom` has muted this room: a room-scoped push rule with
|
|
65
89
|
* the `dont_notify` action, which is what a list dims. Independent of
|
|
66
90
|
* `unreadCount` -- muting stops a room from notifying, never from
|
|
67
91
|
* counting, so a muted room keeps climbing exactly as an unmuted one
|
|
68
92
|
* would. */
|
|
69
93
|
readonly muted: boolean;
|
|
94
|
+
/** Whether this room carries MSC2867's marked-unread flag: room-scoped
|
|
95
|
+
* account data under `m.marked_unread`, or the pre-merge
|
|
96
|
+
* `com.famedly.marked_unread` key some clients still write -- both are
|
|
97
|
+
* what `markRoomUnread` writes, and what `markRoomRead` clears. Not
|
|
98
|
+
* derived from `unreadCount`: unlike `muted`, which only ever changes
|
|
99
|
+
* whether a room notifies, marking a room unread is a person's own
|
|
100
|
+
* signal on top of whatever `unreadCount` already says, the same way a
|
|
101
|
+
* read room can still be flagged unread by hand in any Matrix client. */
|
|
102
|
+
readonly markedUnread: boolean;
|
|
103
|
+
/** Whether this room's `m.room.power_levels` has locked member writes
|
|
104
|
+
* (`events_default >= 100`) -- the same test `admin/index.ts`'s
|
|
105
|
+
* `AdminChannel.archived` reads, mirrored here so a member's client has
|
|
106
|
+
* something to show a refused write against (agora#32). */
|
|
107
|
+
readonly archived: boolean;
|
|
108
|
+
/** Whether `starRoom` has starred this room: the Matrix spec's own
|
|
109
|
+
* `m.favourite` room tag, synced across every device on the account
|
|
110
|
+
* the same way `hideDirectMessage`'s tag is (agora#27). */
|
|
111
|
+
readonly starred: boolean;
|
|
70
112
|
};
|
|
71
113
|
/** Someone this person can start a direct message with: a member of the
|
|
72
|
-
* company space
|
|
73
|
-
*
|
|
74
|
-
* is
|
|
114
|
+
* company space, or a guest sharing a room with them (docs/guests.md,
|
|
115
|
+
* "What the SDK shows"). Guests are never in the space (chat plan section
|
|
116
|
+
* 5), so `guest` is what keeps "the UI does not offer it" true for anyone
|
|
117
|
+
* outside a shared room -- without this package knowing what a guest *is*.
|
|
118
|
+
* It displays what the service marks on a room member and enforces
|
|
119
|
+
* nothing of its own. */
|
|
75
120
|
export type ChatPerson = {
|
|
76
121
|
readonly userId: string;
|
|
77
|
-
/** Their display name
|
|
122
|
+
/** Their display name, falling back to `userId`. */
|
|
78
123
|
readonly name: string;
|
|
124
|
+
/** Set when the service has marked this room member a guest, with when
|
|
125
|
+
* their access ends. A safety line on their messages, not decoration --
|
|
126
|
+
* it is how somebody knows not to paste the numbers in front of them.
|
|
127
|
+
* `undefined` for an ordinary member. */
|
|
128
|
+
readonly guest?: {
|
|
129
|
+
readonly until: string;
|
|
130
|
+
};
|
|
79
131
|
};
|
|
80
132
|
/** Where a `m.room.message` event stands with the homeserver, for the
|
|
81
133
|
* composer's optimistic send (chat plan section 9, ticket #15). `'sent'`
|
|
@@ -240,6 +292,21 @@ export type ChatConnectionStatus = 'connected' | 'catching-up' | 'offline';
|
|
|
240
292
|
* genuinely offline has, which is the honest answer when the only
|
|
241
293
|
* difference is that nobody has said otherwise (see `ChatClient.presence`). */
|
|
242
294
|
export type Presence = 'online' | 'busy' | 'away' | 'offline';
|
|
295
|
+
/** What a person has told us, durably -- distinct from `Presence`, which is
|
|
296
|
+
* ephemeral and dies with the sync loop (`docs/status.md`). Presence
|
|
297
|
+
* answers "is this person's app open right now"; status answers "should I
|
|
298
|
+
* expect a reply". They compose rather than one replacing the other:
|
|
299
|
+
* somebody can be `offline` and `vacation` until Monday, or `online` and
|
|
300
|
+
* `meeting`. See `ChatClient.status`. */
|
|
301
|
+
export type ChatStatus = {
|
|
302
|
+
readonly kind: 'here' | 'busy' | 'meeting' | 'vacation' | 'sick';
|
|
303
|
+
/** ISO 8601. When this status ends, if the person said. */
|
|
304
|
+
readonly until?: string;
|
|
305
|
+
/** What actually redirects the person who was about to write --
|
|
306
|
+
* `docs/status.md`'s own point: "on vacation" helps a little, "back on
|
|
307
|
+
* the 6th, ask Marcus for anything urgent" is the thing that works. */
|
|
308
|
+
readonly message?: string;
|
|
309
|
+
};
|
|
243
310
|
export type CreateChatClientOptions = {
|
|
244
311
|
/** `POST` here exchanges the agora's current ZITADEL token for a Matrix
|
|
245
312
|
* one. See `apps/chat-service/README.md`. */
|
|
@@ -252,9 +319,15 @@ export type CreateChatClientOptions = {
|
|
|
252
319
|
* chat plan section 4. Stable across sign-ins so MAS keeps one Matrix
|
|
253
320
|
* device for its whole life. */
|
|
254
321
|
deviceId: string;
|
|
255
|
-
/**
|
|
256
|
-
*
|
|
322
|
+
/** Workspace namespace for this client's local store, typically the company/project id.
|
|
323
|
+
* The SDK also binds the cache to the exchanged homeserver and Matrix user id. */
|
|
257
324
|
storeName: string;
|
|
325
|
+
/** Turns on matrix-js-sdk's Rust crypto layer (`initRustCrypto()`) before
|
|
326
|
+
* the first sync -- see `createChatClient`'s own comment for what that
|
|
327
|
+
* gates. `false`/omitted keeps crypto off exactly as this package always
|
|
328
|
+
* has: the WASM module is never even loaded. Key backup, recovery key
|
|
329
|
+
* and device verification (chat#67-69) all need this on first. */
|
|
330
|
+
encryptionEnabled?: boolean;
|
|
258
331
|
};
|
|
259
332
|
/**
|
|
260
333
|
* What a UI needs from a signed-in chat session: whether it is running, the
|
|
@@ -276,6 +349,113 @@ export type ChatClient = {
|
|
|
276
349
|
onRoomsChanged: (listener: (rooms: ChatRoomSummary[]) => void) => () => void;
|
|
277
350
|
/** The signed-in Matrix user id, or `null` before `start()` resolves. */
|
|
278
351
|
userId: () => string | null;
|
|
352
|
+
/** matrix-js-sdk's own crypto surface -- key backup, secret storage,
|
|
353
|
+
* device verification -- once `encryptionEnabled: true` has turned it on
|
|
354
|
+
* and `start()` has created the underlying `MatrixClient`. `undefined`
|
|
355
|
+
* otherwise, for the whole life of a client started with crypto off,
|
|
356
|
+
* the same as `MatrixClient.getCrypto()` itself. The one door
|
|
357
|
+
* chat#67-69's key-backup, recovery-key and device-verification methods
|
|
358
|
+
* reach matrix-js-sdk's `CryptoApi` through, rather than each holding
|
|
359
|
+
* its own closed-over `MatrixClient`. */
|
|
360
|
+
getCrypto: () => CryptoApi | undefined;
|
|
361
|
+
/** The `version` of the server-side key backup currently being uploaded
|
|
362
|
+
* to, or `null` if automatic backup is off -- `CryptoApi.
|
|
363
|
+
* getActiveSessionBackupVersion` (chat#67). Throws if called before
|
|
364
|
+
* `start()` or without `encryptionEnabled: true`, the same as every
|
|
365
|
+
* method below it. */
|
|
366
|
+
getActiveSessionBackupVersion: () => Promise<string | null>;
|
|
367
|
+
/** The latest backup on the server, as matrix-js-sdk last checked it, or
|
|
368
|
+
* `null` if there is none -- `CryptoApi.getKeyBackupInfo`. Normally a
|
|
369
|
+
* cached answer; fires one request if nothing has checked yet. */
|
|
370
|
+
getKeyBackupInfo: () => Promise<KeyBackupInfo | null>;
|
|
371
|
+
/** Whether `info` -- a `getKeyBackupInfo()` result -- is signed by a
|
|
372
|
+
* trusted device, or matches the decryption key already held --
|
|
373
|
+
* `CryptoApi.isKeyBackupTrusted`. */
|
|
374
|
+
isKeyBackupTrusted: (info: KeyBackupInfo) => Promise<BackupTrustInfo>;
|
|
375
|
+
/** Re-checks the server's backup and starts or stops uploading to it as
|
|
376
|
+
* trust dictates -- `CryptoApi.checkKeyBackupAndEnable`. `null` if the
|
|
377
|
+
* server has no backup at all; otherwise the backup and whether it is
|
|
378
|
+
* trusted. */
|
|
379
|
+
checkKeyBackupAndEnable: () => Promise<KeyBackupCheck | null>;
|
|
380
|
+
/** Creates a new backup version, replacing any existing one, and starts
|
|
381
|
+
* uploading to it -- `CryptoApi.resetKeyBackup`. The generated
|
|
382
|
+
* decryption key is saved to secret storage when one is set up
|
|
383
|
+
* (chat#68's `bootstrapSecretStorage`); otherwise it exists only on
|
|
384
|
+
* this device until a caller does something with it. */
|
|
385
|
+
resetKeyBackup: () => Promise<void>;
|
|
386
|
+
/** Whether secret storage is fully set up: cross-signing's private keys
|
|
387
|
+
* and (if backup is on) the backup decryption key are all stored,
|
|
388
|
+
* encrypted, in account data -- `CryptoApi.isSecretStorageReady`.
|
|
389
|
+
* `false` means `bootstrapSecretStorage` can fix it. */
|
|
390
|
+
isSecretStorageReady: () => Promise<boolean>;
|
|
391
|
+
/** The same answer as `isSecretStorageReady`, broken down by which of
|
|
392
|
+
* the secrets it checked are actually present -- `CryptoApi.
|
|
393
|
+
* getSecretStorageStatus`. */
|
|
394
|
+
getSecretStorageStatus: () => Promise<SecretStorageStatus>;
|
|
395
|
+
/** Sets up secret storage -- `CryptoApi.bootstrapSecretStorage`. `opts.
|
|
396
|
+
* createSecretStorageKey` is how a caller gets the generated recovery
|
|
397
|
+
* key back to show the person; omitted, matrix-js-sdk still creates and
|
|
398
|
+
* stores one, just without handing it to anything that can display it.
|
|
399
|
+
* `opts.setupNewKeyBackup` also resets key backup (see `resetKeyBackup`)
|
|
400
|
+
* as part of the same bootstrap. Secret storage's own readiness check
|
|
401
|
+
* always covers the cross-signing secrets too, so a caller needing
|
|
402
|
+
* `isSecretStorageReady()` to ever answer `true` bootstraps
|
|
403
|
+
* cross-signing first, through `bootstrapCrossSigning` below. */
|
|
404
|
+
bootstrapSecretStorage: (opts: CreateSecretStorageOpts) => Promise<void>;
|
|
405
|
+
/** Unlocks existing secret storage with a recovery key a person typed
|
|
406
|
+
* in on a new device: decodes it, checks it against the account's
|
|
407
|
+
* default secret-storage key, and only then caches it for this session
|
|
408
|
+
* so secret storage can be read, then loads and restores the key backup
|
|
409
|
+
* (if one exists). Rejects without touching storage when the key is
|
|
410
|
+
* malformed or wrong, or when no secret storage exists. Unlike
|
|
411
|
+
* `bootstrapSecretStorage`, never replaces anything. */
|
|
412
|
+
enterRecoveryKey: (encodedRecoveryKey: string) => Promise<void>;
|
|
413
|
+
/** Sets up cross-signing -- `CryptoApi.bootstrapCrossSigning`. Real
|
|
414
|
+
* Synapse protects the device-signing key upload with user-interactive
|
|
415
|
+
* auth, so the app must supply `opts.authUploadDeviceSigningKeys` (it
|
|
416
|
+
* runs the UIA dance with the person's credentials); without it, the
|
|
417
|
+
* upload is refused. The fake server does not model that dance. */
|
|
418
|
+
bootstrapCrossSigning: (opts: BootstrapCrossSigningOpts) => Promise<void>;
|
|
419
|
+
/** Derives a new recovery key from `password`, or generates one at
|
|
420
|
+
* random if omitted -- `CryptoApi.createRecoveryKeyFromPassphrase`. The
|
|
421
|
+
* result's `encodedPrivateKey` is what a person types back in on
|
|
422
|
+
* another device; this does not itself store anything in secret
|
|
423
|
+
* storage -- pass it to `bootstrapSecretStorage` for that. */
|
|
424
|
+
createRecoveryKeyFromPassphrase: (password?: string) => Promise<GeneratedSecretStorageKey>;
|
|
425
|
+
/** The verification status of `userId` -- whether their identity is
|
|
426
|
+
* cross-signing verified, and whether it changed since it was last
|
|
427
|
+
* verified -- `CryptoApi.getUserVerificationStatus`. */
|
|
428
|
+
getUserVerificationStatus: (userId: string) => Promise<UserVerificationStatus>;
|
|
429
|
+
/** The verification status of one of `userId`'s devices, or `null` if
|
|
430
|
+
* the device is unknown or has published no encryption keys --
|
|
431
|
+
* `CryptoApi.getDeviceVerificationStatus`. */
|
|
432
|
+
getDeviceVerificationStatus: (userId: string, deviceId: string) => Promise<DeviceVerificationStatus | null>;
|
|
433
|
+
/** Verification requests sent to specific devices (not through a DM) that
|
|
434
|
+
* are still in progress for `userId` -- `CryptoApi.
|
|
435
|
+
* getVerificationRequestsToDeviceInProgress`. Includes both a request
|
|
436
|
+
* this session started and one it received but has not resolved yet. */
|
|
437
|
+
getVerificationRequestsToDeviceInProgress: (userId: string) => VerificationRequest[];
|
|
438
|
+
/** Asks this account's own other devices to verify the current one --
|
|
439
|
+
* `CryptoApi.requestOwnUserVerification`. Throws if this device has no
|
|
440
|
+
* cross-signing identity yet (`bootstrapSecretStorage`, or
|
|
441
|
+
* `getUserVerificationStatus` on this account's own id, come first). */
|
|
442
|
+
requestOwnUserVerification: () => Promise<VerificationRequest>;
|
|
443
|
+
/** Requests verification of one specific device of `userId`'s --
|
|
444
|
+
* `CryptoApi.requestDeviceVerification`. The device must already be
|
|
445
|
+
* known to this client (a prior `getCrypto()?.getUserDeviceInfo(...)`,
|
|
446
|
+
* or sync having already delivered its keys); throws otherwise. */
|
|
447
|
+
requestDeviceVerification: (userId: string, deviceId: string) => Promise<VerificationRequest>;
|
|
448
|
+
/** Requests verification of `userId` over a DM in `roomId` --
|
|
449
|
+
* `CryptoApi.requestVerificationDM`. Unlike `requestDeviceVerification`,
|
|
450
|
+
* this targets the user's whole identity, not one device, and is how
|
|
451
|
+
* two people verify each other rather than one person's own devices. */
|
|
452
|
+
requestVerificationDM: (userId: string, roomId: string) => Promise<VerificationRequest>;
|
|
453
|
+
/** Called with each verification request this session receives from
|
|
454
|
+
* somebody else -- a UI's cue to prompt the person to accept or decline
|
|
455
|
+
* it. Returns a function that stops listening. Nothing here accepts,
|
|
456
|
+
* declines, or times a request out on its own; the `VerificationRequest`
|
|
457
|
+
* itself carries those methods. */
|
|
458
|
+
onVerificationRequestReceived: (listener: (request: VerificationRequest) => void) => () => void;
|
|
279
459
|
/** A room's currently-known timeline, or -- given `threadId`, the id of
|
|
280
460
|
* the message that started one -- that thread's own, root first. Empty,
|
|
281
461
|
* with `hasMore: true`, for a room `start()` has not caught up to yet.
|
|
@@ -338,9 +518,12 @@ export type ChatClient = {
|
|
|
338
518
|
* top-level `url` for `contains_url` to match, so this returns `[]` for
|
|
339
519
|
* a room full of files exactly as it would for one with none -- an
|
|
340
520
|
* empty list from such a room means "cannot see", not "none". Not a bug
|
|
341
|
-
* to fix here:
|
|
342
|
-
*
|
|
343
|
-
*
|
|
521
|
+
* to fix here: crypto stays off by default (see `createChatClient`'s own
|
|
522
|
+
* comment), so an encrypted room's whole timeline is already unusable in
|
|
523
|
+
* that case, not just this method -- and turning `encryptionEnabled` on
|
|
524
|
+
* is only the crypto bootstrap (chat#66), not the key backup, recovery
|
|
525
|
+
* or device verification (chat#67-69) an encrypted room's history
|
|
526
|
+
* actually needs to decrypt.
|
|
344
527
|
*
|
|
345
528
|
* No files and a `null` cursor before `start()` resolves, or for a room
|
|
346
529
|
* this client does not know. */
|
|
@@ -430,6 +613,44 @@ export type ChatClient = {
|
|
|
430
613
|
* separator -- read once when a room is opened, not tracked live, so the
|
|
431
614
|
* marker does not move while someone is reading past it. */
|
|
432
615
|
readUpToEventId: (roomId: string) => string | null;
|
|
616
|
+
/** This session's own current draft for `roomId` -- unsent composer text
|
|
617
|
+
* that would otherwise not survive navigating away, a reconnect, or
|
|
618
|
+
* opening the room on a second device (agora#25). `''` for a room with
|
|
619
|
+
* no draft, or one this client does not know.
|
|
620
|
+
*
|
|
621
|
+
* Reads this client's own running knowledge of the draft, not
|
|
622
|
+
* matrix-js-sdk's account data directly: a write's promise resolves on
|
|
623
|
+
* the server's HTTP response, before its echo has come back through
|
|
624
|
+
* `/sync` and landed in the room's account data (the same gap
|
|
625
|
+
* `ChatClient.pinMessage`'s own comment documents for state events), so
|
|
626
|
+
* a caller reading right after an awaited `setDraft` would otherwise
|
|
627
|
+
* see the old value. */
|
|
628
|
+
getDraft: (roomId: string) => string;
|
|
629
|
+
/** Saves `text` as `roomId`'s draft, replacing whatever was there.
|
|
630
|
+
* Visible to this client at once; another device sees it once its own
|
|
631
|
+
* `/sync` next delivers the account data. A no-op for a room this
|
|
632
|
+
* client does not know, or before `start()`. */
|
|
633
|
+
setDraft: (roomId: string, text: string) => Promise<void>;
|
|
634
|
+
/** Empties `roomId`'s draft -- call this once a message actually sends,
|
|
635
|
+
* so the composer does not reoffer text already delivered. Same
|
|
636
|
+
* visibility and no-op rules as `setDraft`. */
|
|
637
|
+
clearDraft: (roomId: string) => Promise<void>;
|
|
638
|
+
/** Whether the signed-in person follows the thread `threadId` (the
|
|
639
|
+
* message that started it) in `roomId`. A person follows a thread by
|
|
640
|
+
* posting in it or being mentioned in it, until they unfollow; then only
|
|
641
|
+
* `followThread` follows it again. Activity tells them about replies in
|
|
642
|
+
* the threads they follow. Rejects when the chat service refuses or
|
|
643
|
+
* cannot be reached. */
|
|
644
|
+
threadFollowing: (roomId: string, threadId: string) => Promise<boolean>;
|
|
645
|
+
/** Follows the thread, including after an earlier unfollow. */
|
|
646
|
+
followThread: (roomId: string, threadId: string) => Promise<void>;
|
|
647
|
+
/** Unfollows the thread. It stays unfollowed: a later post or mention of
|
|
648
|
+
* the person in it does not follow it again. */
|
|
649
|
+
unfollowThread: (roomId: string, threadId: string) => Promise<void>;
|
|
650
|
+
/** Calls `listener` with whether the person follows the thread each time
|
|
651
|
+
* this session's own post in it has followed it (or found it
|
|
652
|
+
* unfollowed). Returns the unsubscribe. */
|
|
653
|
+
onThreadFollowChanged: (roomId: string, threadId: string, listener: (following: boolean) => void) => () => void;
|
|
433
654
|
/** Whether this session may load `mxcUri` at all: a well-formed
|
|
434
655
|
* `mxc://` on *this* homeserver. `false` for anything else, a reference
|
|
435
656
|
* to another server included.
|
|
@@ -485,9 +706,37 @@ export type ChatClient = {
|
|
|
485
706
|
*
|
|
486
707
|
* A no-op for a room this client does not know. */
|
|
487
708
|
muteRoom: (roomId: string, muted: boolean) => Promise<void>;
|
|
488
|
-
/**
|
|
489
|
-
*
|
|
490
|
-
*
|
|
709
|
+
/** Sets or clears MSC2867's marked-unread flag on `roomId`: room-scoped
|
|
710
|
+
* account data under `m.marked_unread`, and, for clients that still read
|
|
711
|
+
* the pre-merge key, `com.famedly.marked_unread` alongside it -- both
|
|
712
|
+
* with the same content. Independent of `unreadCount` and `muted`, the
|
|
713
|
+
* same way `muted` is independent of `unreadCount`: this is a person's
|
|
714
|
+
* own flag, not a count.
|
|
715
|
+
*
|
|
716
|
+
* Account data lands through the next `/sync`, the same way a room tag
|
|
717
|
+
* does (`hideDirectMessage`) -- there is no local echo, and no separate
|
|
718
|
+
* push-rule refetch to piggyback on the way `muteRoom` does.
|
|
719
|
+
*
|
|
720
|
+
* `markRoomRead` clears this flag itself when it is set, so opening a
|
|
721
|
+
* room a person had marked unread also un-marks it -- a marked-unread
|
|
722
|
+
* room a real read left flagged would be a room no read ever un-reads.
|
|
723
|
+
*
|
|
724
|
+
* A no-op for a room this client does not know. */
|
|
725
|
+
markRoomUnread: (roomId: string, unread: boolean) => Promise<void>;
|
|
726
|
+
/** Stars or unstars `roomId`: the Matrix spec's own `m.favourite` room
|
|
727
|
+
* tag, the same `setRoomTag`/`deleteRoomTag` pair `hideDirectMessage`
|
|
728
|
+
* uses for its own tag. Room tags are account data, so starring here
|
|
729
|
+
* is visible on every device signed into this person's account, not
|
|
730
|
+
* just this session (agora#27).
|
|
731
|
+
*
|
|
732
|
+
* A no-op for a room this client does not know. */
|
|
733
|
+
starRoom: (roomId: string, starred: boolean) => Promise<void>;
|
|
734
|
+
/** Everyone in the company space except the signed-in person, plus every
|
|
735
|
+
* guest sharing a joined room with them (see `ChatPerson.guest`) --
|
|
736
|
+
* someone invited for a purpose has to be reachable by the people they
|
|
737
|
+
* were invited to work with. Empty before `start()` resolves, and empty
|
|
738
|
+
* for a session whose account is in no space and shares no room with a
|
|
739
|
+
* guest. */
|
|
491
740
|
people: () => ChatPerson[];
|
|
492
741
|
/** Opens the direct room with exactly `userIds` and resolves with its id.
|
|
493
742
|
*
|
|
@@ -625,6 +874,41 @@ export type ChatClient = {
|
|
|
625
874
|
* current presence has to read `presence(userId)` for each member first
|
|
626
875
|
* and use this only to hear about what changes after. */
|
|
627
876
|
onPresenceChanged: (listener: (changed: ReadonlyMap<string, Presence>) => void) => () => void;
|
|
877
|
+
/** Somebody's durable status -- see `ChatStatus` and `docs/status.md`.
|
|
878
|
+
* Stored as a Matrix custom profile field (MSC4133 extended profiles),
|
|
879
|
+
* so it survives the person closing their laptop entirely, unlike
|
|
880
|
+
* `presence`. `null` for a person with nothing set, or whose
|
|
881
|
+
* homeserver does not support extended profiles yet
|
|
882
|
+
* (`experimental_features.msc4133_enabled`, off until
|
|
883
|
+
* wtfalch/foundry#41 turns it on).
|
|
884
|
+
*
|
|
885
|
+
* Reads a local cache and never blocks: the first call for a given
|
|
886
|
+
* `userId` starts a fetch in the background and returns `null` until it
|
|
887
|
+
* resolves, the same lazy-then-cached shape most of this package uses
|
|
888
|
+
* for anything that has to reach the network. Call `onStatusChanged` to
|
|
889
|
+
* hear the fetch land, rather than polling this. */
|
|
890
|
+
status: (userId: string) => ChatStatus | null;
|
|
891
|
+
/** Sets, or (`null`) clears, the signed-in person's own status
|
|
892
|
+
* (`docs/status.md`). Writes through to the local cache and notifies
|
|
893
|
+
* `onStatusChanged` immediately, before the request resolves -- but
|
|
894
|
+
* unlike `starRoom`/`muteRoom`'s optimism, a rejection rolls the cache
|
|
895
|
+
* back to what it held before: this write fails for an ordinary reason
|
|
896
|
+
* in production today (MSC4133 off until wtfalch/foundry#41 turns it
|
|
897
|
+
* on), so `status(myOwnId)` reporting a status that was never actually
|
|
898
|
+
* saved would be a common bug here, not a rare one. Rejects rather
|
|
899
|
+
* than silently doing nothing when it fails.
|
|
900
|
+
*
|
|
901
|
+
* Durable by construction once it succeeds: this is what makes
|
|
902
|
+
* wtfalch/chat#24's own done-check true -- a colleague who reads
|
|
903
|
+
* `status` after this session has gone offline entirely still gets it,
|
|
904
|
+
* because it lives on the Matrix profile, not in this client's
|
|
905
|
+
* memory. */
|
|
906
|
+
setOwnStatus: (status: ChatStatus | null) => Promise<void>;
|
|
907
|
+
/** Called whenever a status fetch or `setOwnStatus` lands, with just the
|
|
908
|
+
* people who changed. Nothing is replayed on subscribing, the same as
|
|
909
|
+
* `onPresenceChanged`: read `status(userId)` for anyone already of
|
|
910
|
+
* interest before relying on this for what changes next. */
|
|
911
|
+
onStatusChanged: (listener: (changed: ReadonlyMap<string, ChatStatus | null>) => void) => () => void;
|
|
628
912
|
/** Tells `roomId` the signed-in person has started, or stopped, typing --
|
|
629
913
|
* `m.typing`, which is not an event: nothing lands in `timeline()`, and
|
|
630
914
|
* nothing is retried if this fails, the same as any other presence-like
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wtfalch/chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "A Matrix chat client behind the agora's token exchange.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"@types/node": "22.20.2",
|
|
70
70
|
"@types/react": "19.3.0",
|
|
71
71
|
"@types/react-dom": "19.3.0",
|
|
72
|
-
"@wtfalch/design": "0.
|
|
72
|
+
"@wtfalch/design": "0.30.0",
|
|
73
73
|
"fake-indexeddb": "6.2.5",
|
|
74
74
|
"jsdom": "30.0.1",
|
|
75
75
|
"react": "19.2.4",
|