@poolse/react 3.7.0 → 3.8.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.cts CHANGED
@@ -1,9 +1,27 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { PoolseConfig, TrackActivityOptions, Poolse, Me, Uuid, Conversation, ConversationCreateRequest, Membership, MemberRole, Message, MessageCreateRequest, Presence, RealtimeStatus, Attachment, AttachmentUploadInput, PoolseUserProfile, AppEvent, CallRoomStatus, CallParticipant, CameraFacing, CallDeviceKind, CallDevice, LiveKitModule, LiveCall } from '@poolse/sdk';
3
- export { ApiError, ApiErrorCode, AppEvent, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallEndReason, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, CallParticipantStatus, Conversation, ConversationCreateRequest, ConversationReadEvent, DeviceKind, LinkPreview, LinkPreviewType, LiveCall, LiveCallMember, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageEdit, MessageEditList, MessageType, MessageUpdateRequest, NetworkError, NotificationPreferences, NotifyLevel, OwnMembership, OwnMembershipUpdateRequest, PoolseConfig, PoolseError, PoolseUserProfile, Presence, PresenceActivity, PresenceChangedEvent, PresenceState, RateLimitedError, ReadReceiptsState, RealtimeStatus, RoomSession, ThreadParticipant, ThreadUpdatedEvent, TrackActivityOptions, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, isTombstone, mergeMessage, parseCallLog, parseCallLogBody, toTombstone } from '@poolse/sdk';
2
+ import { Poolse, PoolseConfig, TrackActivityOptions, Conversation, Uuid, UnreadTotals, OutboxEntry, Me, ConversationCreateRequest, Membership, MemberRole, Message, MessageCreateRequest, Presence, RealtimeStatus, Attachment, AttachmentUploadInput, PoolseUserProfile, AppEvent, CallRoomStatus, CallParticipant, CameraFacing, CallDeviceKind, CallDevice, LiveKitModule, LiveCall } from '@poolse/sdk';
3
+ export { ApiError, ApiErrorCode, AppEvent, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallEndReason, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, CallParticipantStatus, Conversation, ConversationCreateRequest, ConversationReadEvent, DestroyOptions, DeviceKind, LinkPreview, LinkPreviewType, LiveCall, LiveCallMember, LocalMessageStatus, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageDiscardedError, MessageEdit, MessageEditList, MessageQueuedError, MessageType, MessageUpdateRequest, NetworkError, NotificationPreferences, NotifyLevel, OutboxEntry, OwnMembership, OwnMembershipUpdateRequest, Poolse, PoolseConfig, PoolseError, PoolseStorage, PoolseUserProfile, Presence, PresenceActivity, PresenceChangedEvent, PresenceState, RateLimitedError, ReadReceiptsState, RealtimeStatus, RoomSession, ThreadParticipant, ThreadUpdatedEvent, TimingEvent, TrackActivityOptions, UnreadSummary, UnreadTotals, Uuid, callLogDisplayFor, createIndexedDbStorage, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, isTombstone, memoryStorage, mergeMessage, parseCallLog, parseCallLogBody, toTombstone } from '@poolse/sdk';
4
4
  import { ReactNode } from 'react';
5
5
 
6
6
  interface PoolseProviderProps {
7
+ /**
8
+ * A client you created yourself (`new Poolse(config)`) — for several
9
+ * workspaces, keep one client per workspace outside React and hand
10
+ * each to its own provider. Providers side by side never share
11
+ * state. The provider does NOT destroy a client it was given: it
12
+ * stays connected and warm while its provider is unmounted or hidden,
13
+ * so switching back is a view change. Destroy it yourself on
14
+ * sign-out (`client.destroy({ clearStorage: true })`).
15
+ *
16
+ * Takes precedence over `config`.
17
+ */
18
+ client?: Poolse;
19
+ /**
20
+ * Put the client in the background while `true` (socket closed,
21
+ * reconnects when it turns `false`) — for a workspace that isn't on
22
+ * screen on a phone. See `Poolse.setBackground`.
23
+ */
24
+ background?: boolean;
7
25
  /**
8
26
  * SDK configuration. The provider builds the `Poolse` instance ONCE
9
27
  * per mount and reads `getToken` (and the other function-typed
@@ -16,7 +34,7 @@ interface PoolseProviderProps {
16
34
  * after mount is a no-op (the values are captured at construction
17
35
  * time); dev mode logs a warning when this happens.
18
36
  */
19
- config: PoolseConfig;
37
+ config?: PoolseConfig;
20
38
  /**
21
39
  * Report this device `active` / `idle` for presence from the browser
22
40
  * (`poolse.presence.trackActivity`): idle while the page is hidden,
@@ -39,10 +57,21 @@ interface PoolseProviderProps {
39
57
  * </PoolseProvider>
40
58
  * ```
41
59
  *
42
- * The `Poolse` instance is destroyed on unmount — closes the WebSocket
43
- * and drops every joined channel.
60
+ * A `Poolse` instance the provider built from `config` is destroyed on
61
+ * unmount — closes the WebSocket and drops every joined channel. One
62
+ * passed as `client` is left running.
63
+ *
64
+ * Several workspaces, side by side:
65
+ *
66
+ * ```tsx
67
+ * const acme = new Poolse({ apiUrl: 'https://chat.acme.example', getToken: acmeToken });
68
+ * const beta = new Poolse({ apiUrl: 'https://chat.beta.example', getToken: betaToken });
69
+ *
70
+ * <PoolseProvider client={acme}><Workspace /></PoolseProvider>
71
+ * <PoolseProvider client={beta}><Workspace /></PoolseProvider>
72
+ * ```
44
73
  */
45
- declare function PoolseProvider({ config, trackActivity, children }: PoolseProviderProps): react_jsx_runtime.JSX.Element;
74
+ declare function PoolseProvider({ client, config: configProp, background, trackActivity, children, }: PoolseProviderProps): react_jsx_runtime.JSX.Element;
46
75
  /**
47
76
  * Access the underlying `Poolse` instance. Most app code should prefer
48
77
  * higher-level hooks (`useMessages`, `useTyping`, etc.) but the raw
@@ -51,6 +80,111 @@ declare function PoolseProvider({ config, trackActivity, children }: PoolseProvi
51
80
  */
52
81
  declare function usePoolse(): Poolse;
53
82
 
83
+ interface UseUnreadTotals extends UnreadTotals {
84
+ /** Fetch the totals again. */
85
+ refresh: () => Promise<void>;
86
+ }
87
+ /**
88
+ * Unread and mention totals for one client — every conversation on
89
+ * that server, not just the loaded ones — kept live from realtime.
90
+ *
91
+ * Inside a provider it reads that provider's client; pass a client to
92
+ * read another one (a workspace rail outside every workspace's
93
+ * provider):
94
+ *
95
+ * ```tsx
96
+ * function RailIcon({ client }: { client: Poolse }) {
97
+ * const { unread, mentions } = useUnreadTotals(client);
98
+ * return <Badge count={mentions || unread} strong={mentions > 0} />;
99
+ * }
100
+ * ```
101
+ *
102
+ * Needs the server's `GET /v1/me/unread`; on a server without it the
103
+ * totals are the sum of the loaded conversation list (`source: 'local'`).
104
+ */
105
+ declare function useUnreadTotals(client?: Poolse): UseUnreadTotals;
106
+ interface UseUnreadQueueOptions {
107
+ /** Conversations with unread mentions come first. Default `false`. */
108
+ mentionsFirst?: boolean;
109
+ /** Leave some conversations out (muted ones, say). */
110
+ filter?: (conversation: Conversation) => boolean;
111
+ }
112
+ interface UseUnreadQueue {
113
+ /** Unread conversations in walk-through order (most recent activity first). */
114
+ queue: Conversation[];
115
+ /** The conversation being read now: stays put after it's marked read, until `next()`. */
116
+ current: Conversation | null;
117
+ /** How many unread conversations remain after `current`. */
118
+ remaining: number;
119
+ /** Mark `current` read and move to the next one. Returns it (null when caught up). */
120
+ next: () => Conversation | null;
121
+ /** Move to the next one without marking `current` read; it's not offered again until `reset()`. */
122
+ skip: () => Conversation | null;
123
+ /** Mark one conversation read up to its latest message. */
124
+ markRead: (conversationId: Uuid) => Promise<void>;
125
+ /** Offer skipped conversations again. */
126
+ reset: () => void;
127
+ }
128
+ /**
129
+ * Catch up on unreads: the unread conversations one after another —
130
+ * j/k on desktop, a swipe on phones — marking each read as you go.
131
+ * Built on the shared conversation list, so badges everywhere follow.
132
+ *
133
+ * ```tsx
134
+ * const { current, next, skip, remaining } = useUnreadQueue({ mentionsFirst: true });
135
+ * if (!current) return <p>All caught up.</p>;
136
+ * return <CatchUp conversation={current} onNext={next} onSkip={skip} left={remaining} />;
137
+ * ```
138
+ */
139
+ declare function useUnreadQueue(opts?: UseUnreadQueueOptions): UseUnreadQueue;
140
+ /** Unread conversations, most recent activity first (mentions first if asked). */
141
+ declare function orderUnread(conversations: ReadonlyArray<Conversation>, opts?: UseUnreadQueueOptions): Conversation[];
142
+
143
+ interface UseOutbox {
144
+ /** Unsent messages, oldest first: `queued` (offline), `sending`, `failed`. */
145
+ entries: OutboxEntry[];
146
+ /** How many are `queued` or `sending`. */
147
+ pending: number;
148
+ /** How many the server refused. */
149
+ failed: number;
150
+ /** Send one again now. A still-offline retry stays queued. */
151
+ retry: (id: Uuid) => Promise<void>;
152
+ /** Drop one that hasn't been sent. */
153
+ remove: (id: Uuid) => void;
154
+ /** Try every queued one now. */
155
+ flush: () => Promise<void>;
156
+ }
157
+ /**
158
+ * The client's outbox — for an "N messages waiting to send" banner or a
159
+ * list of failed sends. `useMessages` already shows these rows in their
160
+ * conversation; this is the cross-conversation view.
161
+ */
162
+ declare function useOutbox(opts?: {
163
+ conversationId?: Uuid;
164
+ client?: Poolse;
165
+ }): UseOutbox;
166
+
167
+ /**
168
+ * The client's timings so far, by name (`connect`, `firstConversations`,
169
+ * `firstMessages`, `cachedMessages`, `reconnect`, and the app's own),
170
+ * in milliseconds — re-rendering as new ones are recorded.
171
+ */
172
+ declare function useClientTimings(client?: Poolse): Record<string, number>;
173
+
174
+ interface ConversationSearchOptions {
175
+ /** Your own external id — left out of a direct chat's names. */
176
+ meExternalId?: string | null;
177
+ /** Names for members' external ids (what the list shows). */
178
+ labelFor?: (externalId: string) => string;
179
+ }
180
+ /**
181
+ * Conversations matching `query` (case-insensitive) by name, the other
182
+ * members' names in `labelFor` / external ids, and the last message.
183
+ * An empty query returns the list as is. What `<ConversationList query>`
184
+ * uses on web and React Native.
185
+ */
186
+ declare function filterConversations<T extends Conversation>(conversations: ReadonlyArray<T>, query: string, opts?: ConversationSearchOptions): T[];
187
+
54
188
  interface UseMeState {
55
189
  me: Me | null;
56
190
  loading: boolean;
@@ -195,8 +329,24 @@ interface UseMessagesState {
195
329
  hasMore: boolean;
196
330
  /** Load an older page (lower sequence numbers). Idempotent if no older messages exist. */
197
331
  loadMore: () => Promise<void>;
198
- /** Optimistically append + POST. Replaces the optimistic row with the server response on success. */
332
+ /**
333
+ * Optimistically append + POST. Replaces the optimistic row with the
334
+ * server response on success.
335
+ *
336
+ * With the client's outbox on (the default), a send that can't reach
337
+ * the server stays in the list as `local_status: 'queued'` and goes
338
+ * out by itself on reconnect (same id, so never twice); the promise
339
+ * rejects with `MessageQueuedError`, which is not a failure to show.
340
+ * A send the server refuses stays as `local_status: 'failed'` (with
341
+ * `local_error`) until `retry(id)` or `discard(id)`; the promise
342
+ * rejects with the server's error. With `outbox: false` a failed
343
+ * send is removed from the list and rejects, as before.
344
+ */
199
345
  send: (attrs: MessageCreateRequest) => Promise<Message>;
346
+ /** Send a queued or failed message again now (the Retry on a failed row). */
347
+ retry: (messageId: Uuid) => Promise<void>;
348
+ /** Remove a queued or failed message that hasn't been sent (the Delete on a failed row). */
349
+ discard: (messageId: Uuid) => void;
200
350
  /**
201
351
  * Edit a message you previously sent. Optimistically updates the
202
352
  * local row, rolls back on server error. Server enforces
@@ -227,6 +377,11 @@ interface UseMessagesState {
227
377
  * the user's devices).
228
378
  */
229
379
  markReadUpTo: (messageId: Uuid) => Promise<void>;
380
+ /**
381
+ * The messages shown came from the local cache and the server hasn't
382
+ * answered yet (or can't be reached: offline).
383
+ */
384
+ fromCache: boolean;
230
385
  /**
231
386
  * Re-fetch the newest page (PAGE_SIZE) and replace the cached
232
387
  * messages. Useful when the app returns from background or the
@@ -256,6 +411,13 @@ interface UseMessagesState {
256
411
  *
257
412
  * Re-mounting with the same `conversationId` reuses the underlying
258
413
  * channel — no extra socket traffic.
414
+ *
415
+ * The newest messages of every conversation opened are kept in the
416
+ * client's warm cache (`chat.cache`): opening it again — or switching
417
+ * back to its workspace — shows them at once while the page refetches
418
+ * quietly. With `config.storage` they are also stored, so the history
419
+ * is readable offline and right after a restart. Unsent messages from
420
+ * the outbox show at the end with their `local_status`.
259
421
  */
260
422
  declare function useMessages(conversationId: string): UseMessagesState;
261
423
 
@@ -830,4 +992,4 @@ declare function canEditOwnMessage(args: {
830
992
  now?: number;
831
993
  }): boolean;
832
994
 
833
- export { EDIT_WINDOW_MS, type GroupPosition, type MessageStream, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseLiveCall, type UseReadReceipts, type UseRoom, type UseRoomOptions, type UseUserState, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAppEvent, useAttachmentUpload, useAttachmentUrl, useCallRoom, useConversation, useConversationPresence, useConversations, useLiveCall, useMe, useMembers, useMessageStreams, useMessages, usePoolse, usePresence, usePresenceMany, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser, useUserPresence };
995
+ export { type ConversationSearchOptions, EDIT_WINDOW_MS, type GroupPosition, type MessageStream, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseLiveCall, type UseOutbox, type UseReadReceipts, type UseRoom, type UseRoomOptions, type UseUnreadQueue, type UseUnreadQueueOptions, type UseUnreadTotals, type UseUserState, canEditOwnMessage, computeGroupPosition, filterConversations, formatDayLabel, orderUnread, receiptsOf, sameDay, sameGroup, useAppEvent, useAttachmentUpload, useAttachmentUrl, useCallRoom, useClientTimings, useConversation, useConversationPresence, useConversations, useLiveCall, useMe, useMembers, useMessageStreams, useMessages, useOutbox, usePoolse, usePresence, usePresenceMany, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUnreadQueue, useUnreadTotals, useUser, useUserPresence };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,27 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { PoolseConfig, TrackActivityOptions, Poolse, Me, Uuid, Conversation, ConversationCreateRequest, Membership, MemberRole, Message, MessageCreateRequest, Presence, RealtimeStatus, Attachment, AttachmentUploadInput, PoolseUserProfile, AppEvent, CallRoomStatus, CallParticipant, CameraFacing, CallDeviceKind, CallDevice, LiveKitModule, LiveCall } from '@poolse/sdk';
3
- export { ApiError, ApiErrorCode, AppEvent, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallEndReason, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, CallParticipantStatus, Conversation, ConversationCreateRequest, ConversationReadEvent, DeviceKind, LinkPreview, LinkPreviewType, LiveCall, LiveCallMember, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageEdit, MessageEditList, MessageType, MessageUpdateRequest, NetworkError, NotificationPreferences, NotifyLevel, OwnMembership, OwnMembershipUpdateRequest, PoolseConfig, PoolseError, PoolseUserProfile, Presence, PresenceActivity, PresenceChangedEvent, PresenceState, RateLimitedError, ReadReceiptsState, RealtimeStatus, RoomSession, ThreadParticipant, ThreadUpdatedEvent, TrackActivityOptions, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, isTombstone, mergeMessage, parseCallLog, parseCallLogBody, toTombstone } from '@poolse/sdk';
2
+ import { Poolse, PoolseConfig, TrackActivityOptions, Conversation, Uuid, UnreadTotals, OutboxEntry, Me, ConversationCreateRequest, Membership, MemberRole, Message, MessageCreateRequest, Presence, RealtimeStatus, Attachment, AttachmentUploadInput, PoolseUserProfile, AppEvent, CallRoomStatus, CallParticipant, CameraFacing, CallDeviceKind, CallDevice, LiveKitModule, LiveCall } from '@poolse/sdk';
3
+ export { ApiError, ApiErrorCode, AppEvent, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallEndReason, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, CallParticipantStatus, Conversation, ConversationCreateRequest, ConversationReadEvent, DestroyOptions, DeviceKind, LinkPreview, LinkPreviewType, LiveCall, LiveCallMember, LocalMessageStatus, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageDiscardedError, MessageEdit, MessageEditList, MessageQueuedError, MessageType, MessageUpdateRequest, NetworkError, NotificationPreferences, NotifyLevel, OutboxEntry, OwnMembership, OwnMembershipUpdateRequest, Poolse, PoolseConfig, PoolseError, PoolseStorage, PoolseUserProfile, Presence, PresenceActivity, PresenceChangedEvent, PresenceState, RateLimitedError, ReadReceiptsState, RealtimeStatus, RoomSession, ThreadParticipant, ThreadUpdatedEvent, TimingEvent, TrackActivityOptions, UnreadSummary, UnreadTotals, Uuid, callLogDisplayFor, createIndexedDbStorage, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, isTombstone, memoryStorage, mergeMessage, parseCallLog, parseCallLogBody, toTombstone } from '@poolse/sdk';
4
4
  import { ReactNode } from 'react';
5
5
 
6
6
  interface PoolseProviderProps {
7
+ /**
8
+ * A client you created yourself (`new Poolse(config)`) — for several
9
+ * workspaces, keep one client per workspace outside React and hand
10
+ * each to its own provider. Providers side by side never share
11
+ * state. The provider does NOT destroy a client it was given: it
12
+ * stays connected and warm while its provider is unmounted or hidden,
13
+ * so switching back is a view change. Destroy it yourself on
14
+ * sign-out (`client.destroy({ clearStorage: true })`).
15
+ *
16
+ * Takes precedence over `config`.
17
+ */
18
+ client?: Poolse;
19
+ /**
20
+ * Put the client in the background while `true` (socket closed,
21
+ * reconnects when it turns `false`) — for a workspace that isn't on
22
+ * screen on a phone. See `Poolse.setBackground`.
23
+ */
24
+ background?: boolean;
7
25
  /**
8
26
  * SDK configuration. The provider builds the `Poolse` instance ONCE
9
27
  * per mount and reads `getToken` (and the other function-typed
@@ -16,7 +34,7 @@ interface PoolseProviderProps {
16
34
  * after mount is a no-op (the values are captured at construction
17
35
  * time); dev mode logs a warning when this happens.
18
36
  */
19
- config: PoolseConfig;
37
+ config?: PoolseConfig;
20
38
  /**
21
39
  * Report this device `active` / `idle` for presence from the browser
22
40
  * (`poolse.presence.trackActivity`): idle while the page is hidden,
@@ -39,10 +57,21 @@ interface PoolseProviderProps {
39
57
  * </PoolseProvider>
40
58
  * ```
41
59
  *
42
- * The `Poolse` instance is destroyed on unmount — closes the WebSocket
43
- * and drops every joined channel.
60
+ * A `Poolse` instance the provider built from `config` is destroyed on
61
+ * unmount — closes the WebSocket and drops every joined channel. One
62
+ * passed as `client` is left running.
63
+ *
64
+ * Several workspaces, side by side:
65
+ *
66
+ * ```tsx
67
+ * const acme = new Poolse({ apiUrl: 'https://chat.acme.example', getToken: acmeToken });
68
+ * const beta = new Poolse({ apiUrl: 'https://chat.beta.example', getToken: betaToken });
69
+ *
70
+ * <PoolseProvider client={acme}><Workspace /></PoolseProvider>
71
+ * <PoolseProvider client={beta}><Workspace /></PoolseProvider>
72
+ * ```
44
73
  */
45
- declare function PoolseProvider({ config, trackActivity, children }: PoolseProviderProps): react_jsx_runtime.JSX.Element;
74
+ declare function PoolseProvider({ client, config: configProp, background, trackActivity, children, }: PoolseProviderProps): react_jsx_runtime.JSX.Element;
46
75
  /**
47
76
  * Access the underlying `Poolse` instance. Most app code should prefer
48
77
  * higher-level hooks (`useMessages`, `useTyping`, etc.) but the raw
@@ -51,6 +80,111 @@ declare function PoolseProvider({ config, trackActivity, children }: PoolseProvi
51
80
  */
52
81
  declare function usePoolse(): Poolse;
53
82
 
83
+ interface UseUnreadTotals extends UnreadTotals {
84
+ /** Fetch the totals again. */
85
+ refresh: () => Promise<void>;
86
+ }
87
+ /**
88
+ * Unread and mention totals for one client — every conversation on
89
+ * that server, not just the loaded ones — kept live from realtime.
90
+ *
91
+ * Inside a provider it reads that provider's client; pass a client to
92
+ * read another one (a workspace rail outside every workspace's
93
+ * provider):
94
+ *
95
+ * ```tsx
96
+ * function RailIcon({ client }: { client: Poolse }) {
97
+ * const { unread, mentions } = useUnreadTotals(client);
98
+ * return <Badge count={mentions || unread} strong={mentions > 0} />;
99
+ * }
100
+ * ```
101
+ *
102
+ * Needs the server's `GET /v1/me/unread`; on a server without it the
103
+ * totals are the sum of the loaded conversation list (`source: 'local'`).
104
+ */
105
+ declare function useUnreadTotals(client?: Poolse): UseUnreadTotals;
106
+ interface UseUnreadQueueOptions {
107
+ /** Conversations with unread mentions come first. Default `false`. */
108
+ mentionsFirst?: boolean;
109
+ /** Leave some conversations out (muted ones, say). */
110
+ filter?: (conversation: Conversation) => boolean;
111
+ }
112
+ interface UseUnreadQueue {
113
+ /** Unread conversations in walk-through order (most recent activity first). */
114
+ queue: Conversation[];
115
+ /** The conversation being read now: stays put after it's marked read, until `next()`. */
116
+ current: Conversation | null;
117
+ /** How many unread conversations remain after `current`. */
118
+ remaining: number;
119
+ /** Mark `current` read and move to the next one. Returns it (null when caught up). */
120
+ next: () => Conversation | null;
121
+ /** Move to the next one without marking `current` read; it's not offered again until `reset()`. */
122
+ skip: () => Conversation | null;
123
+ /** Mark one conversation read up to its latest message. */
124
+ markRead: (conversationId: Uuid) => Promise<void>;
125
+ /** Offer skipped conversations again. */
126
+ reset: () => void;
127
+ }
128
+ /**
129
+ * Catch up on unreads: the unread conversations one after another —
130
+ * j/k on desktop, a swipe on phones — marking each read as you go.
131
+ * Built on the shared conversation list, so badges everywhere follow.
132
+ *
133
+ * ```tsx
134
+ * const { current, next, skip, remaining } = useUnreadQueue({ mentionsFirst: true });
135
+ * if (!current) return <p>All caught up.</p>;
136
+ * return <CatchUp conversation={current} onNext={next} onSkip={skip} left={remaining} />;
137
+ * ```
138
+ */
139
+ declare function useUnreadQueue(opts?: UseUnreadQueueOptions): UseUnreadQueue;
140
+ /** Unread conversations, most recent activity first (mentions first if asked). */
141
+ declare function orderUnread(conversations: ReadonlyArray<Conversation>, opts?: UseUnreadQueueOptions): Conversation[];
142
+
143
+ interface UseOutbox {
144
+ /** Unsent messages, oldest first: `queued` (offline), `sending`, `failed`. */
145
+ entries: OutboxEntry[];
146
+ /** How many are `queued` or `sending`. */
147
+ pending: number;
148
+ /** How many the server refused. */
149
+ failed: number;
150
+ /** Send one again now. A still-offline retry stays queued. */
151
+ retry: (id: Uuid) => Promise<void>;
152
+ /** Drop one that hasn't been sent. */
153
+ remove: (id: Uuid) => void;
154
+ /** Try every queued one now. */
155
+ flush: () => Promise<void>;
156
+ }
157
+ /**
158
+ * The client's outbox — for an "N messages waiting to send" banner or a
159
+ * list of failed sends. `useMessages` already shows these rows in their
160
+ * conversation; this is the cross-conversation view.
161
+ */
162
+ declare function useOutbox(opts?: {
163
+ conversationId?: Uuid;
164
+ client?: Poolse;
165
+ }): UseOutbox;
166
+
167
+ /**
168
+ * The client's timings so far, by name (`connect`, `firstConversations`,
169
+ * `firstMessages`, `cachedMessages`, `reconnect`, and the app's own),
170
+ * in milliseconds — re-rendering as new ones are recorded.
171
+ */
172
+ declare function useClientTimings(client?: Poolse): Record<string, number>;
173
+
174
+ interface ConversationSearchOptions {
175
+ /** Your own external id — left out of a direct chat's names. */
176
+ meExternalId?: string | null;
177
+ /** Names for members' external ids (what the list shows). */
178
+ labelFor?: (externalId: string) => string;
179
+ }
180
+ /**
181
+ * Conversations matching `query` (case-insensitive) by name, the other
182
+ * members' names in `labelFor` / external ids, and the last message.
183
+ * An empty query returns the list as is. What `<ConversationList query>`
184
+ * uses on web and React Native.
185
+ */
186
+ declare function filterConversations<T extends Conversation>(conversations: ReadonlyArray<T>, query: string, opts?: ConversationSearchOptions): T[];
187
+
54
188
  interface UseMeState {
55
189
  me: Me | null;
56
190
  loading: boolean;
@@ -195,8 +329,24 @@ interface UseMessagesState {
195
329
  hasMore: boolean;
196
330
  /** Load an older page (lower sequence numbers). Idempotent if no older messages exist. */
197
331
  loadMore: () => Promise<void>;
198
- /** Optimistically append + POST. Replaces the optimistic row with the server response on success. */
332
+ /**
333
+ * Optimistically append + POST. Replaces the optimistic row with the
334
+ * server response on success.
335
+ *
336
+ * With the client's outbox on (the default), a send that can't reach
337
+ * the server stays in the list as `local_status: 'queued'` and goes
338
+ * out by itself on reconnect (same id, so never twice); the promise
339
+ * rejects with `MessageQueuedError`, which is not a failure to show.
340
+ * A send the server refuses stays as `local_status: 'failed'` (with
341
+ * `local_error`) until `retry(id)` or `discard(id)`; the promise
342
+ * rejects with the server's error. With `outbox: false` a failed
343
+ * send is removed from the list and rejects, as before.
344
+ */
199
345
  send: (attrs: MessageCreateRequest) => Promise<Message>;
346
+ /** Send a queued or failed message again now (the Retry on a failed row). */
347
+ retry: (messageId: Uuid) => Promise<void>;
348
+ /** Remove a queued or failed message that hasn't been sent (the Delete on a failed row). */
349
+ discard: (messageId: Uuid) => void;
200
350
  /**
201
351
  * Edit a message you previously sent. Optimistically updates the
202
352
  * local row, rolls back on server error. Server enforces
@@ -227,6 +377,11 @@ interface UseMessagesState {
227
377
  * the user's devices).
228
378
  */
229
379
  markReadUpTo: (messageId: Uuid) => Promise<void>;
380
+ /**
381
+ * The messages shown came from the local cache and the server hasn't
382
+ * answered yet (or can't be reached: offline).
383
+ */
384
+ fromCache: boolean;
230
385
  /**
231
386
  * Re-fetch the newest page (PAGE_SIZE) and replace the cached
232
387
  * messages. Useful when the app returns from background or the
@@ -256,6 +411,13 @@ interface UseMessagesState {
256
411
  *
257
412
  * Re-mounting with the same `conversationId` reuses the underlying
258
413
  * channel — no extra socket traffic.
414
+ *
415
+ * The newest messages of every conversation opened are kept in the
416
+ * client's warm cache (`chat.cache`): opening it again — or switching
417
+ * back to its workspace — shows them at once while the page refetches
418
+ * quietly. With `config.storage` they are also stored, so the history
419
+ * is readable offline and right after a restart. Unsent messages from
420
+ * the outbox show at the end with their `local_status`.
259
421
  */
260
422
  declare function useMessages(conversationId: string): UseMessagesState;
261
423
 
@@ -830,4 +992,4 @@ declare function canEditOwnMessage(args: {
830
992
  now?: number;
831
993
  }): boolean;
832
994
 
833
- export { EDIT_WINDOW_MS, type GroupPosition, type MessageStream, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseLiveCall, type UseReadReceipts, type UseRoom, type UseRoomOptions, type UseUserState, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAppEvent, useAttachmentUpload, useAttachmentUrl, useCallRoom, useConversation, useConversationPresence, useConversations, useLiveCall, useMe, useMembers, useMessageStreams, useMessages, usePoolse, usePresence, usePresenceMany, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser, useUserPresence };
995
+ export { type ConversationSearchOptions, EDIT_WINDOW_MS, type GroupPosition, type MessageStream, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseLiveCall, type UseOutbox, type UseReadReceipts, type UseRoom, type UseRoomOptions, type UseUnreadQueue, type UseUnreadQueueOptions, type UseUnreadTotals, type UseUserState, canEditOwnMessage, computeGroupPosition, filterConversations, formatDayLabel, orderUnread, receiptsOf, sameDay, sameGroup, useAppEvent, useAttachmentUpload, useAttachmentUrl, useCallRoom, useClientTimings, useConversation, useConversationPresence, useConversations, useLiveCall, useMe, useMembers, useMessageStreams, useMessages, useOutbox, usePoolse, usePresence, usePresenceMany, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUnreadQueue, useUnreadTotals, useUser, useUserPresence };