@zextras/carbonio-ws-collaboration-ui-sdk 0.5.0 → 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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { H as HttpMethod, a as HttpPorts, c as components, W as WireMessage, b as WireInboxEntry, d as WireSystemEvent, e as WireReadMarker, f as WireTimelineMessage, g as WirePresenceStatus, h as WireTimeline } from './asyncapi-DB0usrAf.js';
2
- export { F as FetchLike, i as HeadersLike, L as Logger, R as RequestInitLike, j as ResponseLike, V as VersionStore, k as WireInboxMember, l as WireInboxResponse, m as WireInboxRoom, n as WireMessageSearchResult, o as WirePinnedMessage, p as WireTimelineItem } from './asyncapi-DB0usrAf.js';
1
+ import { H as HttpMethod, a as HttpPorts, c as components, W as WireMessage, A as AbortSignalLike, b as WireInboxEntry, d as WireSystemEvent, e as WireReadMarker, f as WireTimelineMessage, g as WirePresenceStatus, h as WireTimeline } from './asyncapi-B8fJWyes.js';
2
+ export { F as FetchLike, i as HeadersLike, L as Logger, R as RequestInitLike, j as ResponseLike, V as VersionStore, k as WireInboxMember, l as WireInboxResponse, m as WireInboxRoom, n as WireMessageSearchResult, o as WirePinnedMessage, p as WireTimelineItem } from './asyncapi-B8fJWyes.js';
3
3
 
4
4
  /**
5
5
  * Per-room FIFO queue for REST writes (send/edit/delete/forward). XMPP
@@ -11,8 +11,12 @@ type WriteQueue = Map<string, Promise<unknown>>;
11
11
 
12
12
  declare const WSC_API_VERSION_HEADER = "X-WSC-API-VERSION";
13
13
  type JsonBody = Record<string, unknown> | Array<unknown>;
14
+ type RequestOptions = {
15
+ /** Aborts the request and rejects with a `TimeoutError` when no response came in time. */
16
+ timeoutMs?: number;
17
+ };
14
18
  type HttpClient = {
15
- request: <T>(endpoint: string, method: HttpMethod, body?: JsonBody) => Promise<T>;
19
+ request: <T>(endpoint: string, method: HttpMethod, body?: JsonBody, options?: RequestOptions) => Promise<T>;
16
20
  };
17
21
  /**
18
22
  * REST core shared by web and mobile. Reproduces the semantics of the two
@@ -20,8 +24,9 @@ type HttpClient = {
20
24
  * 422 retry counter) on top of injected ports:
21
25
  *
22
26
  * - stamps `X-WSC-API-VERSION` with the client's negotiated version;
23
- * - on 422, adopts the server version when it is supported and retries
24
- * (bounded), mirroring the in-production renegotiation;
27
+ * - on 422, adopts the highest supported version not above the server's and
28
+ * retries (bounded), mirroring the in-production renegotiation;
29
+ * - times out a request on demand (`timeoutMs`), aborting its fetch;
25
30
  * - decodes JSON / image blobs, returns the raw response otherwise.
26
31
  */
27
32
  declare function createHttpClient(ports: HttpPorts): HttpClient;
@@ -51,6 +56,7 @@ type StoreAttachment = {
51
56
  };
52
57
  type StoreForwardedInfo = {
53
58
  id: string;
59
+ /** Epoch milliseconds with the microsecond fraction (backend times are microsecond-precise). */
54
60
  date: number;
55
61
  from: string;
56
62
  count: number;
@@ -58,6 +64,7 @@ type StoreForwardedInfo = {
58
64
  type StoreTextMessage = {
59
65
  id: string;
60
66
  roomId: string;
67
+ /** Epoch milliseconds with the microsecond fraction (backend times are microsecond-precise). */
61
68
  date: number;
62
69
  stanzaId: string;
63
70
  type: 'text';
@@ -75,6 +82,7 @@ type StoreTextMessage = {
75
82
  type StoreConfigurationMessage = {
76
83
  id: string;
77
84
  roomId: string;
85
+ /** Epoch milliseconds with the microsecond fraction (backend times are microsecond-precise). */
78
86
  date: number;
79
87
  type: 'configuration';
80
88
  operation: StoreOperationType;
@@ -173,6 +181,14 @@ type StoreBridge = {
173
181
  * panel reads them; `clearSearchResults` stays app-side with the panel).
174
182
  */
175
183
  setSearchResults: (roomId: string, results: Array<StoreTextMessage>) => void;
184
+ /**
185
+ * Sets a stored room's name and description from `GET /inbox`, already resolved against the
186
+ * newest change seen; no-op for a room not stored.
187
+ */
188
+ setRoomFields: (roomId: string, fields: {
189
+ name: string | undefined;
190
+ description: string | undefined;
191
+ }) => void;
176
192
  };
177
193
 
178
194
  type Schemas = components['schemas'];
@@ -180,8 +196,7 @@ type Schemas = components['schemas'];
180
196
  * A chat push event as the SDK handlers take it: the `asyncapi.yaml` schema
181
197
  * (generated, see specs/SPEC_SOURCE.md) without its `type` discriminant. The
182
198
  * apps own the socket and route on their own event-type enum, then hand the
183
- * SDK the event as it came off the wire. `sentDate`, the `WsEvent` envelope's
184
- * send instant, stays in.
199
+ * SDK the event as it came off the wire.
185
200
  */
186
201
  type WirePushEvent<T> = Omit<T, 'type'>;
187
202
  /**
@@ -223,10 +238,13 @@ type WireMessageDeletedEvent = WirePushEvent<Schemas['MessageDeleted']>;
223
238
  */
224
239
  type WireMessageForwardedEvent = WirePushEvent<Schemas['MessageForwarded']>;
225
240
  /**
226
- * `ReactionChanged` push event: a per-user delta (`added` / `removed`), not
227
- * the aggregated state. A user has one reaction per message: replacing it
228
- * emits `removed` then `added`. Sent to the reactor too, and the only
229
- * confirmation path: both reaction endpoints answer 204.
241
+ * `ReactionChanged` push event: a per-user delta (`added` / `updated` /
242
+ * `removed`), not the aggregated state. A user has one reaction per message:
243
+ * replacing it emits one `updated` event. `added` and `updated` carry the
244
+ * stored `updatedAt`, `removed` the `deletedAt` of the delete (`reaction` is
245
+ * the removed emoji): all on the clock the timeline's `users[].updatedAt`
246
+ * uses. Sent to the reactor too, and the only confirmation path: both
247
+ * reaction endpoints answer 204.
230
248
  */
231
249
  type WireReactionChangedEvent = WirePushEvent<Schemas['ReactionChanged']>;
232
250
  /**
@@ -243,16 +261,38 @@ type WireMessageUnpinnedEvent = WirePushEvent<Schemas['MessageUnpinned']>;
243
261
  * room id: the creation lines written with the room are not announced.
244
262
  */
245
263
  type WireRoomCreatedEvent = WirePushEvent<Schemas['RoomCreated']>;
264
+ /**
265
+ * `RoomNameChanged` push event, with the `ROOM_NAME_CHANGED` system event id
266
+ * and creation time. A change of both name and description sends this event
267
+ * first, then `RoomDescriptionChanged`.
268
+ */
269
+ type WireRoomNameChangedEvent = WirePushEvent<Schemas['RoomNameChanged']>;
270
+ /**
271
+ * `RoomDescriptionChanged` push event, with the `ROOM_DESCRIPTION_CHANGED`
272
+ * system event id and creation time. The description is empty when cleared.
273
+ */
274
+ type WireRoomDescriptionChangedEvent = WirePushEvent<Schemas['RoomDescriptionChanged']>;
275
+ /** `RoomPictureChanged` push event, with the `ROOM_PICTURE_UPDATED` system event id. */
276
+ type WireRoomPictureChangedEvent = WirePushEvent<Schemas['RoomPictureChanged']>;
277
+ /** `RoomPictureDeleted` push event, with the `ROOM_PICTURE_DELETED` system event id. */
278
+ type WireRoomPictureDeletedEvent = WirePushEvent<Schemas['RoomPictureDeleted']>;
279
+ /**
280
+ * `RoomHistoryCleared` push event. `clearedBy` and `systemEventId` only when an
281
+ * owner clears a temporary room for everyone, which writes a
282
+ * `ROOM_HISTORY_CLEARED` system event; the per-user clear writes none.
283
+ */
284
+ type WireRoomHistoryClearedEvent = WirePushEvent<Schemas['RoomHistoryCleared']>;
246
285
  /**
247
286
  * `RoomMemberAdded` push event, one per added member. A bulk add writes one
248
- * `MEMBER_ADDED` system event, so every event of the bulk carries the same
249
- * `systemEventId`.
287
+ * `MEMBER_ADDED` system event per added member: each event carries the
288
+ * `systemEventId` of its own row.
250
289
  */
251
290
  type WireRoomMemberAddedEvent = WirePushEvent<Schemas['RoomMemberAdded']>;
252
291
  /**
253
292
  * `RoomMemberRemoved` push event. `removedBy` is the member itself on a
254
- * leave; it is absent, together with `systemEventId`, on an automatic removal
255
- * (temporary room clean-up), which writes no system event.
293
+ * leave and the first room owner on an automatic removal (temporary room
294
+ * clean-up). Backends before `ec635ad1` omit it, together with
295
+ * `systemEventId`, on an automatic removal, which then writes no system event.
256
296
  */
257
297
  type WireRoomMemberRemovedEvent = WirePushEvent<Schemas['RoomMemberRemoved']>;
258
298
  /**
@@ -270,8 +310,8 @@ type WireMeetingStoppedEvent = WirePushEvent<Schemas['MeetingStopped']>;
270
310
  type WireMeetingDeclinedEvent = WirePushEvent<Schemas['MeetingDeclined']>;
271
311
  /**
272
312
  * `Typing` push event, relayed to every member but the typist. The backend
273
- * normalizes `status` to `started` or `stopped`; its `timestamp` is not
274
- * consumed, the indicator runs on the arrival instant and the expiry timer.
313
+ * normalizes `status` to `started` or `stopped`; the event carries no
314
+ * time, the indicator runs on the arrival instant and the expiry timer.
275
315
  */
276
316
  type WireTypingEvent = WirePushEvent<Schemas['Typing']>;
277
317
  /**
@@ -287,6 +327,48 @@ type MessagesDeps = {
287
327
  bridge: StoreBridge;
288
328
  queue: WriteQueue;
289
329
  };
330
+ type PendingSend = {
331
+ roomId: string;
332
+ tempId: string;
333
+ queued: boolean;
334
+ lane: string;
335
+ backoff: {
336
+ baseMs: number;
337
+ maxMs: number;
338
+ };
339
+ maxConflicts: number;
340
+ attempt: (signal: AbortSignalLike) => Promise<WireMessage>;
341
+ confirm: (response: WireMessage) => StoreMessage | undefined;
342
+ run: () => void;
343
+ resolve: (message: StoreMessage | undefined) => void;
344
+ reject: (error: unknown) => void;
345
+ controller: {
346
+ readonly signal: AbortSignalLike;
347
+ abort: () => void;
348
+ };
349
+ deadline: number;
350
+ state: {
351
+ inFlight: boolean;
352
+ conflicts: number;
353
+ lastError?: unknown;
354
+ deadlineTimer?: unknown;
355
+ detachSignal?: () => void;
356
+ onFirstAttemptSettled?: (outcome: FirstAttemptOutcome) => void;
357
+ };
358
+ placeholder?: StoreMessage;
359
+ };
360
+ type FirstAttemptOutcome = 'confirmed' | 'pending' | 'rejected';
361
+ type SendRetries = {
362
+ sends: Map<string, PendingSend>;
363
+ lanes: Map<string, {
364
+ failures: number;
365
+ timer?: unknown;
366
+ }>;
367
+ };
368
+ declare function createSendRetries(): SendRetries;
369
+ type SendDeps = MessagesDeps & {
370
+ retries: SendRetries;
371
+ };
290
372
  type SendMessageParams = {
291
373
  roomId: string;
292
374
  text: string;
@@ -301,6 +383,30 @@ type SendMessageParams = {
301
383
  */
302
384
  repliedMessage?: StoreTextMessage;
303
385
  };
386
+ type SendAttachmentParams = Omit<ConfirmAttachmentUploadParams, 'response'> & {
387
+ /**
388
+ * One attempt of the app's multipart upload with the placeholder's `tempId`,
389
+ * resolving with its 201; called again with the same `tempId` on every
390
+ * retry. Pass `signal` to the fetch: the SDK aborts it when it gives up.
391
+ * Reject with the HTTP `status`.
392
+ *
393
+ * The SDK sets no timeout on an attempt: bounding it is the app's job (a
394
+ * stall timeout fits files of any size). An attempt that never settles
395
+ * holds back its retries, `retryPendingSends` included, until the upload
396
+ * gives up 50 minutes after the send. Reject a timed-out attempt with an
397
+ * error not named `AbortError` (`AbortSignal.timeout` gives a
398
+ * `TimeoutError`) to have it retried: an `AbortError` is a cancel and gives
399
+ * the upload up.
400
+ */
401
+ upload: (signal: AbortSignalLike) => Promise<WireMessage>;
402
+ /** The caller's cancel: aborting it gives the upload up at once. */
403
+ signal?: AbortSignalLike;
404
+ /**
405
+ * Called once, before the promise handlers, when the first attempt settles:
406
+ * `pending` means retries are scheduled. Never called after `reset()`.
407
+ */
408
+ onFirstAttemptSettled?: (outcome: FirstAttemptOutcome) => void;
409
+ };
304
410
  type ConfirmAttachmentUploadParams = {
305
411
  roomId: string;
306
412
  /** The placeholder's id, sent as the upload's `tempId` form field. */
@@ -312,6 +418,7 @@ type ConfirmAttachmentUploadParams = {
312
418
  /** The quoted message on a reply, resolved from the store like the send's. */
313
419
  repliedMessage?: StoreTextMessage;
314
420
  };
421
+ declare function retryPendingSends(deps: SendDeps): void;
315
422
  /**
316
423
  * `POST /rooms/{roomId}/messages` — one outgoing text message, serialized
317
424
  * through the per-room FIFO write queue (plan §7.4). The optimistic
@@ -320,12 +427,9 @@ type ConfirmAttachmentUploadParams = {
320
427
  * the stanza).
321
428
  *
322
429
  * Confirmation is idempotent from both ways (REST response here, self-echo in
323
- * `handleMessageReceived`). On a definitive send error the placeholder is
324
- * removed — the v1 stanza just vanished leaving an eternal PENDING; the REST
325
- * failure is at least observable (plan §3, minimal proposal) — and the error
326
- * propagates to the façade.
430
+ * `handleMessageReceived`); failures follow the rules of `WscClient.sendMessage`.
327
431
  */
328
- declare function sendMessage({ http, bridge, queue }: MessagesDeps, params: SendMessageParams): Promise<void>;
432
+ declare function sendMessage(deps: SendDeps, params: SendMessageParams): Promise<void>;
329
433
  /**
330
434
  * Confirms an attachment upload from its 201. The apps own the
331
435
  * `POST /rooms/{roomId}/attachments` multipart, whose body is
@@ -342,6 +446,7 @@ declare function sendMessage({ http, bridge, queue }: MessagesDeps, params: Send
342
446
  * the echo like the send's.
343
447
  */
344
448
  declare function confirmAttachmentUpload({ bridge }: MessagesDeps, params: ConfirmAttachmentUploadParams): StoreMessage | undefined;
449
+ declare function sendAttachment(deps: SendDeps, params: SendAttachmentParams): Promise<StoreMessage | undefined>;
345
450
  /**
346
451
  * `MessageReceived` push event — every message of every sender, own echo
347
452
  * included. The SDK performs the store writes shared by all senders; the
@@ -355,9 +460,10 @@ declare function confirmAttachmentUpload({ bridge }: MessagesDeps, params: Confi
355
460
  *
356
461
  * `tempId` promotes the optimistic placeholder. It reaches every member, but
357
462
  * only the sender holds a placeholder under that id: for the others the
358
- * removal is a no-op and the write is a plain append.
463
+ * removal is a no-op and the write is a plain append. For the sender it also
464
+ * confirms the pending send of that tempId and stops its retries.
359
465
  */
360
- declare function handleMessageReceived({ bridge }: MessagesDeps, event: WireMessageReceivedEvent): StoreMessage;
466
+ declare function handleMessageReceived(deps: SendDeps, event: WireMessageReceivedEvent): StoreMessage;
361
467
 
362
468
  type EditMessageParams = {
363
469
  roomId: string;
@@ -432,6 +538,30 @@ declare function forwardMessages({ http, queue }: MessagesDeps, toRoomId: string
432
538
  */
433
539
  declare function handleMessageForwarded({ bridge }: MessagesDeps, event: WireMessageForwardedEvent): StoreMessage;
434
540
 
541
+ type PinOperation = 'messagePinned' | 'messageUnpinned';
542
+
543
+ /**
544
+ * Per room, the time of the last banner write (a pin or unpin event time, or the `pinnedAt` of a
545
+ * `GET /pin` reply) and a count of the banner writes. All times are on the database clock.
546
+ * `fromPage`: the time comes from a pin or unpin line of a timeline page, which writes no banner, so
547
+ * the event or reply of that same change still applies; an empty `GET /pin` reply agrees with an
548
+ * unpin line.
549
+ */
550
+ type PinVersion = {
551
+ time: number;
552
+ writes: number;
553
+ localUnpins?: number;
554
+ fromPage?: PinOperation;
555
+ };
556
+ type PinVersions = Map<string, PinVersion>;
557
+ declare function createPinVersions(): PinVersions;
558
+ type PinDeps = MessagesDeps & {
559
+ pinVersions: PinVersions;
560
+ };
561
+ type PinEventResult = {
562
+ row: StoreConfigurationMessage;
563
+ bannerApplied: boolean;
564
+ };
435
565
  /** Resolves the full pinned message from the caller's store, when loaded. */
436
566
  type FindPinnedMessage = (messageId: string) => StoreTextMessage | undefined;
437
567
  /**
@@ -441,12 +571,6 @@ type FindPinnedMessage = (messageId: string) => StoreTextMessage | undefined;
441
571
  * like the v1 pin IQ that only surfaced through the MUC config broadcast.
442
572
  */
443
573
  declare function pinMessage({ http, queue }: MessagesDeps, roomId: string, messageId: string): Promise<void>;
444
- /**
445
- * `DELETE /rooms/{roomId}/messages/{messageId}/pin` — echo-only like the PUT.
446
- * The v1 façade removed the banner optimistically on unpin (and only on
447
- * unpin): that stays in the app façades, which own the store reads.
448
- */
449
- declare function unpinMessage({ http, queue }: MessagesDeps, roomId: string, messageId: string): Promise<void>;
450
574
  /**
451
575
  * `GET /rooms/{roomId}/pin` — hydrates the room's pinned-message banner (the
452
576
  * v2 replacement for the v1 pin IQ + archive-by-id round-trip). The banner
@@ -459,25 +583,50 @@ declare function unpinMessage({ http, queue }: MessagesDeps, roomId: string, mes
459
583
  * An empty list CLEARS the banner — a deliberate self-healing improvement
460
584
  * over the v1 no-op, which could leave a stale banner after an unpin missed
461
585
  * while offline.
586
+ *
587
+ * The write is skipped when a live pin or unpin touched the banner while the
588
+ * request was in flight and the reply is not newer than it, and always when
589
+ * the user unpinned meanwhile (the reply may predate the unpin, whose echo
590
+ * settles the banner). Known gap: an
591
+ * empty reply followed by a stale late `MessagePinned` cannot be told apart
592
+ * (it would need the unpin time from the backend).
462
593
  */
463
- declare function fetchPinnedMessage({ http, bridge }: MessagesDeps, roomId: string, findMessage?: FindPinnedMessage): Promise<void>;
594
+ declare function fetchPinnedMessage({ http, bridge, pinVersions }: PinDeps, roomId: string, findMessage?: FindPinnedMessage): Promise<void>;
595
+ /**
596
+ * `DELETE /rooms/{roomId}/messages/{messageId}/pin` — echo-only like the PUT.
597
+ * The v1 façade removed the banner optimistically on unpin (and only on
598
+ * unpin): that stays in the app façades, which own the store reads. When the
599
+ * DELETE fails, `GET /pin` runs again: the optimistic removal and a reply
600
+ * dropped while the DELETE was in flight would otherwise leave the banner
601
+ * empty for a pin that still exists. `findMessage` resolves the banner of that
602
+ * `GET /pin`, as in `fetchPinnedMessage`.
603
+ */
604
+ declare function unpinMessage(deps: PinDeps, roomId: string, messageId: string, findMessage?: FindPinnedMessage): Promise<void>;
464
605
  /**
465
606
  * `MessagePinned` push event — every pinner, own echo included (the only
466
607
  * confirmation path). Two v1-parity writes: the configuration row lands in
467
608
  * the timeline, and the banner is set: with the target the caller resolved
468
- * from its store, else with the event's own `message`. Returns the row for
469
- * the router's me/others effects (app events).
609
+ * from its store, else with the event's own `message`. The banner is
610
+ * written only when the event `timestamp` (the system event time, the REST
611
+ * `pinnedAt`) is newer than the room's last banner write: `bannerApplied` is
612
+ * false for a stale event, whose row still lands. Returns the row and that
613
+ * flag for the router's me/others effects (app events).
470
614
  */
471
- declare function handleMessagePinned({ bridge }: MessagesDeps, event: WireMessagePinnedEvent, pinnedMessage?: StoreTextMessage): StoreConfigurationMessage;
615
+ declare function handleMessagePinned({ bridge, pinVersions }: PinDeps, event: WireMessagePinnedEvent, pinnedMessage?: StoreTextMessage): PinEventResult;
472
616
  /**
473
617
  * `MessageUnpinned` push event — configuration row plus banner removal (a
474
618
  * no-op for the unpinner, whose façade already removed it optimistically
475
- * like in v1). The removal is unconditional like the v1 handler. It cannot
476
- * clear a fresh banner: the backend keeps one pin per room and replaces it
477
- * with a lone `MessagePinned`, no `MessageUnpinned` for the old one.
478
- * Returns the row for the router's effects.
619
+ * like in v1). The removal is ordered like the pin by the event `timestamp`:
620
+ * a stale unpin leaves the banner (`bannerApplied` false) and its row still
621
+ * lands. Returns the row and that flag for the router's effects.
622
+ */
623
+ declare function handleMessageUnpinned({ bridge, pinVersions }: PinDeps, event: WireMessageUnpinnedEvent): PinEventResult;
624
+ /**
625
+ * A temporary room's history clear also removes its pin. The clear time becomes the banner version,
626
+ * so a pin event older than the clear, delivered late, does not bring the banner back. Returns
627
+ * whether the banner was removed (false when a newer pin was already applied).
479
628
  */
480
- declare function handleMessageUnpinned({ bridge }: MessagesDeps, event: WireMessageUnpinnedEvent): StoreConfigurationMessage;
629
+ declare function clearPinnedBanner({ bridge, pinVersions }: PinDeps, roomId: string, clearedAt: string): boolean;
481
630
 
482
631
  type SearchDeps = {
483
632
  http: HttpClient;
@@ -490,6 +639,8 @@ type SearchMessagesOptions = {
490
639
  * no load-more), exposed for the future one.
491
640
  */
492
641
  before?: number;
642
+ /** Id of the oldest result of the previous page: with `before` the cursor becomes (createdAt, id). */
643
+ beforeId?: string;
493
644
  /**
494
645
  * Drop results strictly before this instant (ms since epoch) — the v1
495
646
  * MAM `start` bound (`clearedAt ?? createdAt`), inclusive like the
@@ -518,9 +669,129 @@ type SearchMessagesResult = {
518
669
  */
519
670
  declare function searchMessages({ http, bridge }: SearchDeps, roomId: string, query: string, options?: SearchMessagesOptions): Promise<SearchMessagesResult>;
520
671
 
672
+ type SystemLinesDeps = {
673
+ bridge: StoreBridge;
674
+ };
675
+ /**
676
+ * Per room and field (`name`, `description`), the time and value of the newest change seen: a
677
+ * change's `systemEventCreatedAt` or a REST room's `updatedAt`. Two quick changes published by
678
+ * different nodes can arrive inverted: the older one still lands its line, but must not overwrite
679
+ * the newer value.
680
+ */
681
+ type RoomFieldVersions = Map<string, {
682
+ time: number;
683
+ value: string | undefined;
684
+ }>;
685
+ type RoomFieldDeps = SystemLinesDeps & {
686
+ roomFieldVersions: RoomFieldVersions;
687
+ };
688
+ type RoomFieldEventResult = {
689
+ row: StoreConfigurationMessage;
690
+ applied: boolean;
691
+ };
692
+ /**
693
+ * `RoomMemberAdded` push event: lands the `memberAdded` line, whose value is
694
+ * the added member. Returns the row for the router's me/others effects, or
695
+ * undefined when the event announces no line or the line is already in the
696
+ * room. A bulk add writes one line and sends one event for each added member.
697
+ */
698
+ declare function handleRoomMemberAdded({ bridge }: SystemLinesDeps, event: WireRoomMemberAddedEvent): StoreConfigurationMessage | undefined;
699
+ /**
700
+ * `RoomMemberRemoved` push event: lands the `memberRemoved` line, whose value
701
+ * is the removed member. Returns the row, or undefined when the event
702
+ * announces no line (an automatic removal on backends before `ec635ad1`).
703
+ */
704
+ declare function handleRoomMemberRemoved({ bridge }: SystemLinesDeps, event: WireRoomMemberRemovedEvent): StoreConfigurationMessage | undefined;
705
+ /**
706
+ * A room read from REST (`GET /rooms`, `GET /rooms/{id}`) carries `updatedAt`, written by the
707
+ * database clock in the update that changes the name or the description, before that change's line.
708
+ * Returns the name and description to store: the snapshot's when it is newer than the newest change
709
+ * seen (its `updatedAt` becomes the version), otherwise that newer change's value, also when the
710
+ * room was not stored yet.
711
+ */
712
+ declare function resolveRoomSnapshot({ roomFieldVersions }: Pick<RoomFieldDeps, 'roomFieldVersions'>, roomId: string, snapshot: {
713
+ updatedAt: string;
714
+ name?: string;
715
+ description?: string;
716
+ }): {
717
+ name: string | undefined;
718
+ description: string | undefined;
719
+ };
720
+ /**
721
+ * `MeetingStarted` push event: lands the `meetingStarted` line in the
722
+ * meeting's room, which the app resolves from its meetings. Returns the row,
723
+ * or undefined when the room has no line (group meetings).
724
+ */
725
+ declare function handleMeetingStarted({ bridge }: SystemLinesDeps, event: WireMeetingStartedEvent, roomId: string): StoreConfigurationMessage | undefined;
726
+ /**
727
+ * `MeetingStopped` push event: lands the `meetingEnded` line, whose value is
728
+ * the call duration in seconds, `durationSec` (present exactly when
729
+ * `systemEventId` is; an empty value otherwise). Returns the row, or undefined
730
+ * when the room has no line.
731
+ */
732
+ declare function handleMeetingStopped({ bridge }: SystemLinesDeps, event: WireMeetingStoppedEvent, roomId: string): StoreConfigurationMessage | undefined;
733
+ /**
734
+ * `MeetingDeclined` push event: lands the `meetingDeclined` line, authored by
735
+ * the decliner. Returns the row, or undefined when the room has no line.
736
+ */
737
+ declare function handleMeetingDeclined({ bridge }: SystemLinesDeps, event: WireMeetingDeclinedEvent, roomId: string): StoreConfigurationMessage | undefined;
738
+
739
+ /**
740
+ * Latest reaction date applied per `messageId|userId`. Live events and
741
+ * history pages are dated with the same database clock, so anything dated
742
+ * below the stored maximum is a stale state and is never written. Lives as
743
+ * long as the client (it survives a chat registry reset and a reconnection);
744
+ * only `reset()` clears it.
745
+ */
746
+ type ReactionVersions = Map<string, number>;
747
+ type ReactionDeps = {
748
+ http: HttpClient;
749
+ bridge: StoreBridge;
750
+ queue: WriteQueue;
751
+ reactionVersions: ReactionVersions;
752
+ };
753
+ declare function createReactionVersions(): ReactionVersions;
754
+ /**
755
+ * `PUT /rooms/{roomId}/messages/{messageId}/reaction` with `{reaction}` —
756
+ * sets or replaces the user's single reaction on the message. Serialized
757
+ * through the per-room FIFO write queue (plan §7.4). Confirmation is
758
+ * echo-only, like the deletion: the 204 has no body, the store moves on the
759
+ * `ReactionChanged` echo (v1 parity — the reaction stanza confirmed through
760
+ * the MUC echo).
761
+ */
762
+ declare function sendReaction({ http, queue }: ReactionDeps, roomId: string, messageId: string, reaction: string): Promise<void>;
763
+ /**
764
+ * `DELETE /rooms/{roomId}/messages/{messageId}/reaction` — removes the user's
765
+ * reaction on the message, whatever emoji it is. Same queue and echo-only
766
+ * confirmation as `sendReaction`.
767
+ */
768
+ declare function removeReaction({ http, queue }: ReactionDeps, roomId: string, messageId: string): Promise<void>;
769
+ /**
770
+ * `ReactionChanged` push event — every reactor, own echo included (the only
771
+ * confirmation path). One event per write: `added` and `updated` (an emoji
772
+ * replacement, in one event) become a fastening valued with the new
773
+ * `reaction` dated `updatedAt`; `removed` an empty-valued one dated
774
+ * `deletedAt`, which the projection (latest per user by date) reads as "no
775
+ * active reaction" — the v1 semantics verbatim. The id embeds the date:
776
+ * add -> remove -> add again must produce distinct fastenings.
777
+ *
778
+ * Events are ordered per `messageId|userId` by those dates. There is one
779
+ * event per write, so a date equal to the latest applied is the same write
780
+ * delivered twice (or already shown by a history page): it is applied
781
+ * idempotently (same id) but `undefined` is returned, and a date below it is
782
+ * stale and dropped (not written, `undefined`). Only a strictly newer write
783
+ * returns the fastening: the app router owns the me/others effects
784
+ * (animation, browser notification) and must skip them on `undefined`. An
785
+ * event missing the time it needs (`updatedAt` / `deletedAt`) is ignored.
786
+ * No unread bump and no sidebar update: v1 parity.
787
+ */
788
+ declare function handleReactionChanged({ bridge, reactionVersions }: ReactionDeps, event: WireReactionChangedEvent): StoreMessageFastening | undefined;
789
+
521
790
  type TimelineDeps = {
522
791
  http: HttpClient;
523
792
  bridge: StoreBridge;
793
+ reactionVersions: ReactionVersions;
794
+ pinVersions: PinVersions;
524
795
  };
525
796
  type FetchTimelineOptions = {
526
797
  /** Return items strictly older than this instant (ms since epoch) — the v1 MAM `end` bound. */
@@ -626,12 +897,35 @@ type WscClient = {
626
897
  * markers.
627
898
  */
628
899
  handleReadUpdated: (event: WireReadUpdatedEvent) => void;
629
- /** `POST /rooms/{roomId}/messages`: one outgoing text, FIFO-serialized per room. */
900
+ /**
901
+ * `POST /rooms/{roomId}/messages`: one outgoing text, FIFO-serialized per
902
+ * room. Resolves once confirmed (201 or echo). A certain rejection (4xx but
903
+ * 408, 409, 429) removes the placeholder and rejects; any other failure,
904
+ * no answer within 30 s included, keeps it pending and retries the same
905
+ * tempId (2 s to 60 s, at once on `retryPendingSends`) for 50 minutes,
906
+ * then removes it and rejects.
907
+ */
630
908
  sendMessage: (params: SendMessageParams) => Promise<void>;
909
+ /**
910
+ * Attachment upload through the app's multipart (`upload`), confirmed and
911
+ * retried like `sendMessage` but with a 30 s to 10 minutes backoff, and
912
+ * given up at the third 409 in a row (a claim the server left stuck answers
913
+ * 409 for 1 hour: send again with a new tempId); the attempt in flight is
914
+ * aborted when the SDK gives up. Resolves with the confirmed message.
915
+ */
916
+ sendAttachment: (params: SendAttachmentParams) => Promise<StoreMessage | undefined>;
917
+ /**
918
+ * Retries the pending sends and uploads at once, in send order per room,
919
+ * restarting their backoff, after writing back the placeholders missing
920
+ * from the store. Call it on every `WebsocketConnected`, after any store
921
+ * reset of the reconnection.
922
+ */
923
+ retryPendingSends: () => void;
631
924
  /**
632
925
  * `MessageReceived` push event: store writes for every sender, the
633
- * placeholder promoted on `tempId`; returns the mapped message. Quote and
634
- * attachment come from the event's `TimelineMessage`.
926
+ * placeholder promoted on `tempId`, which also confirms the pending send
927
+ * with that tempId; returns the mapped message. Quote and attachment come
928
+ * from the event's `TimelineMessage`.
635
929
  */
636
930
  handleMessageReceived: (event: WireMessageReceivedEvent) => StoreMessage;
637
931
  /**
@@ -659,21 +953,26 @@ type WscClient = {
659
953
  * lastMessage contract as handleMessageEdited.
660
954
  */
661
955
  handleMessageDeleted: (event: WireMessageDeletedEvent, lastMessage?: StoreTextMessage) => void;
662
- /** `POST …/reactions/{reaction}`: FIFO-serialized, echo-confirmed (204 has no body). */
956
+ /**
957
+ * `PUT …/messages/{messageId}/reaction`: sets or replaces the user's single
958
+ * reaction; FIFO-serialized, echo-confirmed (204 has no body).
959
+ */
663
960
  sendReaction: (roomId: string, messageId: string, reaction: string) => Promise<void>;
664
961
  /**
665
- * `DELETE …/reactions/{reaction}` — the caller passes the emoji to remove
666
- * (v1 removed with an empty value; the façade resolves the current one
667
- * from the store).
962
+ * `DELETE …/messages/{messageId}/reaction`: removes the user's reaction,
963
+ * whatever the emoji; FIFO-serialized, echo-confirmed.
668
964
  */
669
- removeReaction: (roomId: string, messageId: string, reaction: string) => Promise<void>;
965
+ removeReaction: (roomId: string, messageId: string) => Promise<void>;
670
966
  /**
671
967
  * `ReactionChanged` push event: synthesizes the per-user reaction
672
968
  * fastening (removals carry an empty value) for every reactor, own echo
673
969
  * included — the only confirmation path. Returns the fastening for the
674
- * app router's me/others effects (animation, browser notification).
970
+ * app router's me/others effects (animation, browser notification), or
971
+ * undefined when the event is not newer than the latest applied for that
972
+ * user and message (a duplicate, applied again idempotently, or stale and
973
+ * dropped): the router must skip its effects.
675
974
  */
676
- handleReactionChanged: (event: WireReactionChangedEvent) => StoreMessageFastening;
975
+ handleReactionChanged: (event: WireReactionChangedEvent) => StoreMessageFastening | undefined;
677
976
  /**
678
977
  * `POST /rooms/{toRoomId}/forward`: one bulk request per destination,
679
978
  * FIFO-serialized on the destination room. Fire-and-forget: the
@@ -688,8 +987,11 @@ type WscClient = {
688
987
  handleMessageForwarded: (event: WireMessageForwardedEvent) => StoreMessage;
689
988
  /** `PUT …/messages/{messageId}/pin`: FIFO-serialized, echo-confirmed (204 has no body). */
690
989
  pinMessage: (roomId: string, messageId: string) => Promise<void>;
691
- /** `DELETE …/messages/{messageId}/pin`: FIFO-serialized, echo-confirmed (204 has no body). */
692
- unpinMessage: (roomId: string, messageId: string) => Promise<void>;
990
+ /**
991
+ * `DELETE …/messages/{messageId}/pin`: FIFO-serialized, echo-confirmed (204 has no body). When
992
+ * it fails, `GET /pin` runs again, with `findMessage` as in `fetchPinnedMessage`.
993
+ */
994
+ unpinMessage: (roomId: string, messageId: string, findMessage?: FindPinnedMessage) => Promise<void>;
693
995
  /**
694
996
  * `GET /rooms/{roomId}/pin`: hydrates the banner with the latest pin —
695
997
  * the full store message when the caller resolves it, the DTO's
@@ -700,14 +1002,22 @@ type WscClient = {
700
1002
  * `MessagePinned` push event: synthesizes the v1 configuration row for
701
1003
  * every pinner (own echo included — the only confirmation path) and sets
702
1004
  * the banner with the target the app resolved from its store, else with the
703
- * event's message. Returns the row for the router's me/others effects.
1005
+ * event's message, both only when the event is newer than the room's last
1006
+ * banner write (`bannerApplied`). Returns the row and that flag for the
1007
+ * router's me/others effects.
704
1008
  */
705
- handleMessagePinned: (event: WireMessagePinnedEvent, pinnedMessage?: StoreTextMessage) => StoreConfigurationMessage;
1009
+ handleMessagePinned: (event: WireMessagePinnedEvent, pinnedMessage?: StoreTextMessage) => PinEventResult;
706
1010
  /**
707
1011
  * `MessageUnpinned` push event: configuration row plus banner removal
708
- * (idempotent over the unpinner's optimistic remove). Returns the row.
1012
+ * (idempotent over the unpinner's optimistic remove), ordered by the event
1013
+ * time like the pin. Returns the row and `bannerApplied`.
709
1014
  */
710
- handleMessageUnpinned: (event: WireMessageUnpinnedEvent) => StoreConfigurationMessage;
1015
+ handleMessageUnpinned: (event: WireMessageUnpinnedEvent) => PinEventResult;
1016
+ /**
1017
+ * A temporary room's history clear removes its pin banner, versioned by `clearedAt`. Returns
1018
+ * false when a newer pin was already applied.
1019
+ */
1020
+ clearPinnedBanner: (roomId: string, clearedAt: string) => boolean;
711
1021
  /**
712
1022
  * `RoomCreated` push event: `GET /rooms/{roomId}/timeline` for the newest
713
1023
  * item, which becomes the new room's last message in the chat list.
@@ -716,14 +1026,53 @@ type WscClient = {
716
1026
  /**
717
1027
  * `RoomMemberAdded` push event: lands the `memberAdded` line in the
718
1028
  * timeline and the chat list. Returns the row, or undefined when the event
719
- * announces no line or a previous event of the same bulk add landed it.
1029
+ * announces no line or the line is already in the room.
720
1030
  */
721
1031
  handleRoomMemberAdded: (event: WireRoomMemberAddedEvent) => StoreConfigurationMessage | undefined;
722
1032
  /**
723
1033
  * `RoomMemberRemoved` push event: lands the `memberRemoved` line. Returns
724
- * the row, or undefined on an automatic removal.
1034
+ * the row, or undefined when the event announces no line.
725
1035
  */
726
1036
  handleRoomMemberRemoved: (event: WireRoomMemberRemovedEvent) => StoreConfigurationMessage | undefined;
1037
+ /**
1038
+ * `RoomNameChanged` push event: lands the `roomNameChanged` line. Returns
1039
+ * the row and `applied`; the app applies the new name to the room only
1040
+ * when `applied` is true.
1041
+ */
1042
+ handleRoomNameChanged: (event: WireRoomNameChangedEvent) => RoomFieldEventResult;
1043
+ /**
1044
+ * A room read from REST: the name and description to store, the snapshot's or a newer change's
1045
+ * already seen (`updatedAt` against the line times).
1046
+ */
1047
+ resolveRoomSnapshot: (roomId: string, snapshot: {
1048
+ updatedAt: string;
1049
+ name?: string;
1050
+ description?: string;
1051
+ }) => {
1052
+ name: string | undefined;
1053
+ description: string | undefined;
1054
+ };
1055
+ /**
1056
+ * `RoomDescriptionChanged` push event: lands the `roomDescriptionChanged`
1057
+ * line. Returns the row and `applied`, as for the name.
1058
+ */
1059
+ handleRoomDescriptionChanged: (event: WireRoomDescriptionChangedEvent) => RoomFieldEventResult;
1060
+ /**
1061
+ * `RoomPictureChanged` push event: lands the `roomPictureUpdated` line.
1062
+ * Returns the row, or undefined when the event announces no line.
1063
+ */
1064
+ handleRoomPictureChanged: (event: WireRoomPictureChangedEvent) => StoreConfigurationMessage | undefined;
1065
+ /**
1066
+ * `RoomPictureDeleted` push event: lands the `roomPictureDeleted` line.
1067
+ * Returns the row, or undefined when the event announces no line.
1068
+ */
1069
+ handleRoomPictureDeleted: (event: WireRoomPictureDeletedEvent) => StoreConfigurationMessage | undefined;
1070
+ /**
1071
+ * `RoomHistoryCleared` push event: lands the `roomHistoryCleared` line of a
1072
+ * temporary room cleared for everyone. Returns the row, or undefined on the
1073
+ * per-user clear. The app still clears the conversation.
1074
+ */
1075
+ handleRoomHistoryCleared: (event: WireRoomHistoryClearedEvent) => StoreConfigurationMessage | undefined;
727
1076
  /**
728
1077
  * `MeetingStarted` push event: lands the `meetingStarted` line in the
729
1078
  * meeting's room, resolved by the app. Returns the row, or undefined when
@@ -731,11 +1080,11 @@ type WscClient = {
731
1080
  */
732
1081
  handleMeetingStarted: (event: WireMeetingStartedEvent, roomId: string) => StoreConfigurationMessage | undefined;
733
1082
  /**
734
- * `MeetingStopped` push event: lands the `meetingEnded` line, with the call
735
- * duration measured from the meeting's `startedAt` the app knows. Returns
736
- * the row, or undefined when the room has no line.
1083
+ * `MeetingStopped` push event: lands the `meetingEnded` line, with the
1084
+ * event's `durationSec` as value. Returns the row, or undefined when the
1085
+ * room has no line.
737
1086
  */
738
- handleMeetingStopped: (event: WireMeetingStoppedEvent, roomId: string, startedAt?: string) => StoreConfigurationMessage | undefined;
1087
+ handleMeetingStopped: (event: WireMeetingStoppedEvent, roomId: string) => StoreConfigurationMessage | undefined;
739
1088
  /**
740
1089
  * `MeetingDeclined` push event: lands the `meetingDeclined` line. Returns
741
1090
  * the row, or undefined when the room has no line.
@@ -747,6 +1096,12 @@ type WscClient = {
747
1096
  * outbound action stays app-side (the apps own the socket until step 18).
748
1097
  */
749
1098
  handleTyping: (event: WireTypingEvent) => void;
1099
+ /**
1100
+ * Drops the session state: pending sends (left unsettled, their retries,
1101
+ * deadlines and uploads cancelled), the write queue, typing timers, the
1102
+ * presence, reaction, pin and room name/description ordering. Call it on logout or session teardown.
1103
+ */
1104
+ reset: () => void;
750
1105
  };
751
1106
  /**
752
1107
  * Aggregates the per-API client modules behind a single injected-deps entry
@@ -776,25 +1131,10 @@ declare function deleteMessage({ http, queue }: MessagesDeps, roomId: string, me
776
1131
  */
777
1132
  declare function handleMessageDeleted({ bridge }: MessagesDeps, event: WireMessageDeletedEvent, lastMessage?: StoreTextMessage): void;
778
1133
 
779
- type InboxDeps = {
780
- http: HttpClient;
781
- bridge: StoreBridge;
782
- };
783
- /**
784
- * `GET /inbox` — one round-trip carrying, per room: the last message, the
785
- * server-side unread count, every member's read marker and presence.
786
- * Replaces the XMPP boot sequence (XEP-0430 inbox + smart markers + roster).
787
- *
788
- * Write order mirrors the v1 flow: last messages first (`setInboxMessages`),
789
- * then markers (the slice recomputes read statuses), then unread counters,
790
- * then presence.
791
- */
792
- declare function fetchInbox({ http, bridge }: InboxDeps): Promise<void>;
793
-
794
1134
  type PresenceUpdate = {
795
1135
  userId: string;
796
1136
  online: boolean;
797
- /** Milliseconds since epoch; only present for offline users with a known last session. */
1137
+ /** Milliseconds since epoch: the last time the user went offline, absent when never offline; also present while online. */
798
1138
  lastActivity?: number;
799
1139
  };
800
1140
  type MappedInboxEntry = {
@@ -838,17 +1178,30 @@ declare function mapWireMarkerToStoreMarker(marker: WireReadMarker, rows: Readon
838
1178
  */
839
1179
  declare function mapInboxEntry(entry: WireInboxEntry, knownRows?: ReadonlyArray<StoreMessage>): MappedInboxEntry;
840
1180
 
1181
+ /**
1182
+ * Per user, the `(lastActivity, online)` pair of the last presence applied. The backend reads
1183
+ * `lastActivity` in the same transaction as the transition, so the pair totally orders a user's
1184
+ * states (offline@T1 < online@T1 < offline@T2 < online@T2; no `lastActivity` is -infinity).
1185
+ */
1186
+ type PresenceGuard = Map<string, {
1187
+ activity: number;
1188
+ online: number;
1189
+ }>;
1190
+ declare function createPresenceGuard(): PresenceGuard;
841
1191
  type PresenceDeps = {
842
1192
  http: HttpClient;
843
1193
  bridge: StoreBridge;
1194
+ presence: PresenceGuard;
844
1195
  };
845
1196
  /**
846
- * The one presence write rule, shared by the inbox and batch hydrations: the
847
- * online flag always lands, and so does the last activity when present. It is
848
- * the last time the user went offline, returned also while online; the UI
849
- * shows "last seen" only for offline users.
1197
+ * The one presence write rule, shared by the inbox and batch hydrations and the push event: an
1198
+ * update lands unless its `(lastActivity, online)` pair is strictly older than the user's last
1199
+ * applied one: an equal pair writes again (idempotent), which re-hydrates a store the app wiped on
1200
+ * a reconnection while the SDK kept its ordering. The online flag always lands with it, and so
1201
+ * does the last activity when present: the last time the user went offline, returned also while
1202
+ * online; the UI shows "last seen" only for offline users.
850
1203
  */
851
- declare function applyPresenceUpdates(bridge: StoreBridge, updates: Array<PresenceUpdate>): void;
1204
+ declare function applyPresenceUpdates({ bridge, presence }: Pick<PresenceDeps, 'bridge' | 'presence'>, updates: Array<PresenceUpdate>): void;
852
1205
  /**
853
1206
  * `POST /presence/batch` — presence + last activity for N users: the v2
854
1207
  * replacement for the v1 per-contact `jabber:iq:last` queries (the roster
@@ -856,45 +1209,28 @@ declare function applyPresenceUpdates(bridge: StoreBridge, updates: Array<Presen
856
1209
  * sent in chunks of 100, the backend limit (400 above). A failed chunk does not
857
1210
  * stop the next ones: the first error is rethrown once every chunk has run.
858
1211
  */
859
- declare function fetchPresence({ http, bridge }: PresenceDeps, userIds: Array<string>): Promise<void>;
1212
+ declare function fetchPresence(deps: PresenceDeps, userIds: Array<string>): Promise<void>;
860
1213
  /**
861
- * `PresenceChanged` push event: the online flag lands immediately, together
862
- * with `lastActivity` (last time the user went offline, sent on both online
863
- * and offline events, same value as the snapshots) when present. No batch
864
- * refresh is needed. The backend never sends a user their own presence; the
865
- * app routers filter it anyway, like in v1 where it never reached the store.
1214
+ * `PresenceChanged` push event: lands through the same `(lastActivity, online)` ordering as the
1215
+ * snapshots, so a late or inverted event never overwrites a newer state. The backend never sends a
1216
+ * user their own presence; the app routers filter it anyway, like in v1 where it never reached the
1217
+ * store.
866
1218
  */
867
- declare function handlePresenceChanged({ bridge }: PresenceDeps, event: WirePresenceChangedEvent): Promise<void>;
1219
+ declare function handlePresenceChanged(deps: PresenceDeps, event: WirePresenceChangedEvent): Promise<void>;
868
1220
 
869
1221
  /**
870
- * `POST /rooms/{roomId}/messages/{messageId}/reactions/{reaction}` —
871
- * serialized through the per-room FIFO write queue (plan §7.4). Confirmation
872
- * is echo-only, like the deletion: the 204 has no body, the store moves on
873
- * the `ReactionChanged` echo (v1 parity — the reaction stanza confirmed
874
- * through the MUC echo).
875
- */
876
- declare function sendReaction({ http, queue }: MessagesDeps, roomId: string, messageId: string, reaction: string): Promise<void>;
877
- /**
878
- * `DELETE /rooms/{roomId}/messages/{messageId}/reactions/{reaction}` — the
879
- * caller passes the emoji to remove: v1 removed with an empty-valued
880
- * reaction stanza, v2 keys the removal on the specific emoji, so the façade
881
- * resolves the user's current one from the store (the same selector the
882
- * reaction pickers already read).
1222
+ * `GET /inbox` — one round-trip carrying, per room: the last message, the
1223
+ * server-side unread count, every member's read marker and presence.
1224
+ * Replaces the XMPP boot sequence (XEP-0430 inbox + smart markers + roster).
1225
+ *
1226
+ * The room names and descriptions land first, resolved against the newest change seen: the inbox
1227
+ * refresh after a reconnection brings the changes whose events were missed meanwhile.
1228
+ *
1229
+ * Write order mirrors the v1 flow: last messages first (`setInboxMessages`),
1230
+ * then markers (the slice recomputes read statuses), then unread counters,
1231
+ * then presence, ordered like `fetchPresence`'s.
883
1232
  */
884
- declare function removeReaction({ http, queue }: MessagesDeps, roomId: string, messageId: string, reaction: string): Promise<void>;
885
- /**
886
- * `ReactionChanged` push event — every reactor, own echo included (the only
887
- * confirmation path). Reactions are repeatable toggles, so unlike edits the
888
- * fastening id embeds the write instant: add -> remove -> add again must
889
- * produce three distinct fastenings (a deduped id would swallow the re-add),
890
- * exactly like the v1 stanzas that each carried their own archive id. A
891
- * removal is a fastening with an empty value: the projection (latest per
892
- * user by date) reads it as "no active reaction" — the v1 semantics
893
- * verbatim. No unread bump and no sidebar update: v1 parity, the app router
894
- * owns the me/others effects (animation, browser notification). Returns the
895
- * fastening for those effects.
896
- */
897
- declare function handleReactionChanged({ bridge }: MessagesDeps, event: WireReactionChangedEvent): StoreMessageFastening;
1233
+ declare function fetchInbox(deps: PresenceDeps & Pick<RoomFieldDeps, 'roomFieldVersions'>): Promise<void>;
898
1234
 
899
1235
  type ReadDeps = {
900
1236
  http: HttpClient;
@@ -933,45 +1269,6 @@ declare function fetchRoomReadMarkers({ http, bridge }: ReadDeps, roomId: string
933
1269
  */
934
1270
  declare function handleReadUpdated({ bridge }: ReadDeps, event: WireReadUpdatedEvent): void;
935
1271
 
936
- type SystemLinesDeps = {
937
- bridge: StoreBridge;
938
- };
939
- /**
940
- * `RoomMemberAdded` push event: lands the `memberAdded` line, whose value is
941
- * the added member. Returns the row for the router's me/others effects, or
942
- * undefined when the event announces no line or the line is already in the
943
- * room: a bulk add sends one event per member for its single line, which
944
- * lands with the first event, like the timeline that shows the first added
945
- * member.
946
- */
947
- declare function handleRoomMemberAdded({ bridge }: SystemLinesDeps, event: WireRoomMemberAddedEvent): StoreConfigurationMessage | undefined;
948
- /**
949
- * `RoomMemberRemoved` push event: lands the `memberRemoved` line, whose value
950
- * is the removed member. Returns the row, or undefined on an automatic
951
- * removal, which has no line.
952
- */
953
- declare function handleRoomMemberRemoved({ bridge }: SystemLinesDeps, event: WireRoomMemberRemovedEvent): StoreConfigurationMessage | undefined;
954
- /**
955
- * `MeetingStarted` push event: lands the `meetingStarted` line in the
956
- * meeting's room, which the app resolves from its meetings. Returns the row,
957
- * or undefined when the room has no line (group meetings).
958
- */
959
- declare function handleMeetingStarted({ bridge }: SystemLinesDeps, event: WireMeetingStartedEvent, roomId: string): StoreConfigurationMessage | undefined;
960
- /**
961
- * `MeetingStopped` push event: lands the `meetingEnded` line, whose value is
962
- * the call duration in seconds, as in the system event. The event carries
963
- * none: it is measured from `startedAt`, the start the app knows, to the
964
- * event's `sentDate`, so it can exceed the backend's by a second until a
965
- * timeline page replaces the row. Without `startedAt` the line has no
966
- * duration. Returns the row, or undefined when the room has no line.
967
- */
968
- declare function handleMeetingStopped({ bridge }: SystemLinesDeps, event: WireMeetingStoppedEvent, roomId: string, startedAt?: string): StoreConfigurationMessage | undefined;
969
- /**
970
- * `MeetingDeclined` push event: lands the `meetingDeclined` line, authored by
971
- * the decliner. Returns the row, or undefined when the room has no line.
972
- */
973
- declare function handleMeetingDeclined({ bridge }: SystemLinesDeps, event: WireMeetingDeclinedEvent, roomId: string): StoreConfigurationMessage | undefined;
974
-
975
1272
  /**
976
1273
  * Safety-net expiry for a typing indicator that never receives its `stopped`
977
1274
  * (lost event, killed app): the v1 handlers used the same 7s window.
@@ -1022,9 +1319,9 @@ type MappedTimelinePage = {
1022
1319
  /**
1023
1320
  * Reaction fastenings synthesized from the messages' `ReactionGroup[]`
1024
1321
  * (current aggregated state, unlike the v1 MAM which carried the stanza
1025
- * history). Deterministic ids (`r_{messageId}_{userId}_{emoji}`) keep
1026
- * refetches idempotent through the slice dedup; dated 1ms after their
1027
- * message so any live fastening (dated now) wins the projection.
1322
+ * history). Ids (`r_{messageId}_{userId}_{emoji}_{date}`, as the live ones) keep
1323
+ * refetches idempotent through the slice dedup; dated with each user's
1324
+ * reaction `updatedAt`.
1028
1325
  */
1029
1326
  fastenings: Array<StoreMessageFastening>;
1030
1327
  markers: Array<StoreMarker>;
@@ -1060,6 +1357,9 @@ type MappedTimelinePage = {
1060
1357
  */
1061
1358
  declare function mapTimelinePage(page: WireTimeline, roomId: string, notBefore?: number, knownRows?: ReadonlyArray<StoreMessage>): MappedTimelinePage;
1062
1359
 
1360
+ declare function parseIsoMicros(iso: string | undefined): number;
1361
+ declare function toIsoMicros(ms: number): string;
1362
+
1063
1363
  declare class WscApiError extends Error {
1064
1364
  readonly status: number;
1065
1365
  readonly endpoint: string;
@@ -1068,4 +1368,4 @@ declare class WscApiError extends Error {
1068
1368
 
1069
1369
  declare function buildQueryString(params: Record<string, string | number | boolean | undefined | null>): string;
1070
1370
 
1071
- export { type ConfirmAttachmentUploadParams, type EditMessageParams, type FetchTimelineGapOptions, type FetchTimelineOptions, type FindPinnedMessage, type ForwardMessageRef, type HttpClient, HttpMethod, HttpPorts, type JsonBody, type MappedInboxEntry, type MappedTimelinePage, type MessagesDeps, type PresenceDeps, type PresenceUpdate, type ReadDeps, type SearchDeps, type SearchMessagesOptions, type SearchMessagesResult, type SendMessageParams, type StoreAttachment, type StoreBridge, type StoreConfigurationMessage, type StoreFasteningAction, type StoreForwardedInfo, type StoreMarker, type StoreMarkerStatus, type StoreMessage, type StoreMessageFastening, type StoreOperationType, type StoreTextMessage, type SystemLinesDeps, TYPING_EXPIRE_MS, type TimelineDeps, type TypingDeps, type TypingTimers, WSC_API_VERSION_HEADER, WireInboxEntry, type WireMeetingDeclinedEvent, type WireMeetingStartedEvent, type WireMeetingStoppedEvent, WireMessage, type WireMessageDeletedEvent, type WireMessageEditedEvent, type WireMessageForwardedEvent, type WireMessagePinnedEvent, type WireMessageReceivedEvent, type WireMessageUnpinnedEvent, type WirePresenceChangedEvent, WirePresenceStatus, type WireReactionChangedEvent, WireReadMarker, type WireReadUpdatedEvent, type WireRoomCreatedEvent, type WireRoomMemberAddedEvent, type WireRoomMemberRemovedEvent, WireSystemEvent, WireTimeline, WireTimelineMessage, type WireTypingEvent, type WireWsErrorEvent, WscApiError, type WscClient, type WscClientDeps, applyPresenceUpdates, buildQueryString, confirmAttachmentUpload, createHttpClient, createTypingTimers, createWscClient, deleteMessage, editMessage, fetchInbox, fetchPinnedMessage, fetchPresence, fetchRoomReadMarkers, fetchTimeline, fetchTimelineGap, forwardMessages, handleMeetingDeclined, handleMeetingStarted, handleMeetingStopped, handleMessageDeleted, handleMessageEdited, handleMessageForwarded, handleMessagePinned, handleMessageReceived, handleMessageUnpinned, handlePresenceChanged, handleReactionChanged, handleReadUpdated, handleRoomMemberAdded, handleRoomMemberRemoved, handleTyping, mapInboxEntry, mapPresenceStatus, mapSearchMessageToStoreMessage, mapSystemEventToStoreMessage, mapTimelinePage, mapWireMarkerToStoreMarker, mapWireMessageToStoreMessage, markAsRead, pinMessage, removeReaction, searchMessages, sendMessage, sendReaction, unpinMessage };
1371
+ export { AbortSignalLike, type ConfirmAttachmentUploadParams, type EditMessageParams, type FetchTimelineGapOptions, type FetchTimelineOptions, type FindPinnedMessage, type FirstAttemptOutcome, type ForwardMessageRef, type HttpClient, HttpMethod, HttpPorts, type JsonBody, type MappedInboxEntry, type MappedTimelinePage, type MessagesDeps, type PinDeps, type PinEventResult, type PinVersions, type PresenceDeps, type PresenceGuard, type PresenceUpdate, type ReactionDeps, type ReactionVersions, type ReadDeps, type RequestOptions, type RoomFieldEventResult, type RoomFieldVersions, type SearchDeps, type SearchMessagesOptions, type SearchMessagesResult, type SendAttachmentParams, type SendDeps, type SendMessageParams, type SendRetries, type StoreAttachment, type StoreBridge, type StoreConfigurationMessage, type StoreFasteningAction, type StoreForwardedInfo, type StoreMarker, type StoreMarkerStatus, type StoreMessage, type StoreMessageFastening, type StoreOperationType, type StoreTextMessage, type SystemLinesDeps, TYPING_EXPIRE_MS, type TimelineDeps, type TypingDeps, type TypingTimers, WSC_API_VERSION_HEADER, WireInboxEntry, type WireMeetingDeclinedEvent, type WireMeetingStartedEvent, type WireMeetingStoppedEvent, WireMessage, type WireMessageDeletedEvent, type WireMessageEditedEvent, type WireMessageForwardedEvent, type WireMessagePinnedEvent, type WireMessageReceivedEvent, type WireMessageUnpinnedEvent, type WirePresenceChangedEvent, WirePresenceStatus, type WireReactionChangedEvent, WireReadMarker, type WireReadUpdatedEvent, type WireRoomCreatedEvent, type WireRoomDescriptionChangedEvent, type WireRoomHistoryClearedEvent, type WireRoomMemberAddedEvent, type WireRoomMemberRemovedEvent, type WireRoomNameChangedEvent, type WireRoomPictureChangedEvent, type WireRoomPictureDeletedEvent, WireSystemEvent, WireTimeline, WireTimelineMessage, type WireTypingEvent, type WireWsErrorEvent, WscApiError, type WscClient, type WscClientDeps, applyPresenceUpdates, buildQueryString, clearPinnedBanner, confirmAttachmentUpload, createHttpClient, createPinVersions, createPresenceGuard, createReactionVersions, createSendRetries, createTypingTimers, createWscClient, deleteMessage, editMessage, fetchInbox, fetchPinnedMessage, fetchPresence, fetchRoomReadMarkers, fetchTimeline, fetchTimelineGap, forwardMessages, handleMeetingDeclined, handleMeetingStarted, handleMeetingStopped, handleMessageDeleted, handleMessageEdited, handleMessageForwarded, handleMessagePinned, handleMessageReceived, handleMessageUnpinned, handlePresenceChanged, handleReactionChanged, handleReadUpdated, handleRoomMemberAdded, handleRoomMemberRemoved, handleTyping, mapInboxEntry, mapPresenceStatus, mapSearchMessageToStoreMessage, mapSystemEventToStoreMessage, mapTimelinePage, mapWireMarkerToStoreMarker, mapWireMessageToStoreMessage, markAsRead, parseIsoMicros, pinMessage, removeReaction, resolveRoomSnapshot, retryPendingSends, searchMessages, sendAttachment, sendMessage, sendReaction, toIsoMicros, unpinMessage };