stream-chat 10.0.0-rc.21 → 10.0.0-rc.23
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/cjs/index.browser.js +2196 -3902
- package/dist/cjs/index.browser.js.map +3 -3
- package/dist/cjs/index.node.js +2197 -3902
- package/dist/cjs/index.node.js.map +3 -3
- package/dist/esm/index.mjs +2199 -3905
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelManager.d.ts +120 -233
- package/dist/types/CooldownTimer.d.ts +8 -23
- package/dist/types/EventHandlerPipeline.d.ts +17 -37
- package/dist/types/LiveLocationManager.d.ts +22 -50
- package/dist/types/api-client.d.ts +9 -14
- package/dist/types/channel.d.ts +253 -448
- package/dist/types/channel_state.d.ts +48 -95
- package/dist/types/client.d.ts +245 -370
- package/dist/types/client_state.d.ts +1 -3
- package/dist/types/configuration/ConfigController.d.ts +30 -124
- package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +31 -123
- package/dist/types/configuration/keys.d.ts +5 -19
- package/dist/types/configuration/shape.d.ts +12 -29
- package/dist/types/configuration/types.d.ts +59 -87
- package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +13 -35
- package/dist/types/configuration/utils/copyConfigPatch.d.ts +8 -0
- package/dist/types/configuration/utils/declarativeSlices.d.ts +5 -16
- package/dist/types/configuration/utils/deepFreezeConfig.d.ts +3 -17
- package/dist/types/configuration/utils/serverAuthority.d.ts +9 -29
- package/dist/types/connection/ConnectionIdManager.d.ts +18 -40
- package/dist/types/connection/ConnectionRecoveryManager.d.ts +29 -120
- package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +32 -103
- package/dist/types/connection/networkConnection/reporters.d.ts +9 -32
- package/dist/types/connection/networkConnection/types.d.ts +12 -27
- package/dist/types/connection/wsConnection/StableWSConnection.d.ts +37 -116
- package/dist/types/connection/wsConnection/WSConnection.d.ts +41 -104
- package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +8 -16
- package/dist/types/connection/wsConnection/config.d.ts +8 -28
- package/dist/types/connection/wsConnection/types.d.ts +17 -70
- package/dist/types/entityStore/EntityStore.d.ts +153 -113
- package/dist/types/entityStore/StoreBackedItemIndex.d.ts +13 -46
- package/dist/types/errors.d.ts +7 -19
- package/dist/types/gen/chat/ChannelApi.d.ts +2 -1
- package/dist/types/gen/chat/ChatApi.d.ts +28 -14
- package/dist/types/gen/models/index.d.ts +769 -86
- package/dist/types/gen/moderation/ModerationApi.d.ts +4 -4
- package/dist/types/index.d.ts +2 -4
- package/dist/types/languageNames.d.ts +9 -24
- package/dist/types/logger.d.ts +1 -3
- package/dist/types/messageComposer/LocationComposer.d.ts +1 -1
- package/dist/types/messageComposer/attachmentIdentity.d.ts +1 -6
- package/dist/types/messageComposer/attachmentManager.d.ts +10 -32
- package/dist/types/messageComposer/attachmentUtils.d.ts +3 -14
- package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
- package/dist/types/messageComposer/configuration/types.d.ts +29 -56
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +6 -9
- package/dist/types/messageComposer/messageComposer.d.ts +30 -164
- package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +4 -14
- package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +2 -9
- package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +2 -4
- package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +7 -19
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +9 -0
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +11 -18
- package/dist/types/messageComposer/middleware/textComposer/textMiddlewareUtils.d.ts +9 -3
- package/dist/types/messageComposer/middleware/textComposer/types.d.ts +1 -6
- package/dist/types/messageComposer/pollComposer.d.ts +8 -4
- package/dist/types/messageComposer/textComposer.d.ts +3 -9
- package/dist/types/messageComposer/types.d.ts +5 -8
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +25 -79
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +15 -82
- package/dist/types/messageOperations/FailedSendCache.d.ts +4 -9
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +10 -20
- package/dist/types/messageOperations/MessageOperations.d.ts +20 -40
- package/dist/types/messageOperations/applyReactionLocally.d.ts +5 -22
- package/dist/types/messageOperations/createMessageOperations.d.ts +3 -5
- package/dist/types/messageOperations/reflectReactionEvent.d.ts +5 -13
- package/dist/types/messageOperations/sendOrdering.d.ts +4 -7
- package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +7 -15
- package/dist/types/messageOperations/types.d.ts +15 -30
- package/dist/types/middleware.d.ts +7 -5
- package/dist/types/moderation.d.ts +21 -14
- package/dist/types/notifications/NotificationManager.d.ts +8 -31
- package/dist/types/notifications/types.d.ts +19 -59
- package/dist/types/offline-support/offline_support_api.d.ts +145 -539
- package/dist/types/offline-support/offline_sync_manager.d.ts +18 -42
- package/dist/types/offline-support/queueableOperations.d.ts +24 -52
- package/dist/types/offline-support/types.d.ts +24 -187
- package/dist/types/pagination/ItemIndex.d.ts +4 -12
- package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +13 -0
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -4
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +2 -3
- package/dist/types/pagination/paginators/BasePaginator.d.ts +235 -622
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +67 -125
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +133 -292
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +69 -118
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +7 -26
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +2 -2
- package/dist/types/pagination/paginators/ThreadPaginator.d.ts +15 -23
- package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +2 -6
- package/dist/types/pagination/sortCompiler.d.ts +11 -22
- package/dist/types/pagination/utility.normalization.d.ts +5 -23
- package/dist/types/pagination/utility.search.d.ts +3 -8
- package/dist/types/poll.d.ts +14 -14
- package/dist/types/poll_manager.d.ts +11 -2
- package/dist/types/poll_optimistic_votes.d.ts +10 -14
- package/dist/types/reminders/Reminder.d.ts +4 -4
- package/dist/types/reminders/ReminderManager.d.ts +7 -20
- package/dist/types/search/BaseSearchSource.d.ts +7 -12
- package/dist/types/search/ChannelSearchSource.d.ts +7 -7
- package/dist/types/search/MessageSearchSource.d.ts +7 -9
- package/dist/types/search/SearchController.d.ts +17 -22
- package/dist/types/search/types.d.ts +6 -10
- package/dist/types/signing.d.ts +12 -3
- package/dist/types/thread.d.ts +23 -71
- package/dist/types/thread_manager.d.ts +45 -70
- package/dist/types/token_manager.d.ts +8 -13
- package/dist/types/types.d.ts +64 -125
- package/dist/types/types.utility.d.ts +3 -3
- package/dist/types/upload-utils.d.ts +5 -10
- package/dist/types/uploadManager.d.ts +17 -45
- package/dist/types/utils/FixedSizeQueueCache.d.ts +6 -11
- package/dist/types/utils/WithSubscriptions.d.ts +5 -15
- package/dist/types/utils/concurrency.d.ts +11 -19
- package/dist/types/utils/mergeWith/mergeWith.d.ts +8 -11
- package/dist/types/utils/mergeWith/mergeWithCore.d.ts +5 -13
- package/dist/types/utils/mergeWith/mergeWithDiff.d.ts +22 -0
- package/dist/types/utils/objectPath.d.ts +6 -41
- package/dist/types/utils/retryable.d.ts +8 -12
- package/dist/types/utils/throttling/throttle.d.ts +8 -23
- package/dist/types/utils/time.d.ts +24 -64
- package/dist/types/utils.d.ts +40 -86
- package/package.json +7 -2
- package/src/ChannelManager.ts +159 -300
- package/src/CooldownTimer.ts +11 -29
- package/src/EventHandlerPipeline.ts +21 -44
- package/src/LiveLocationManager.ts +35 -74
- package/src/api-client.ts +43 -61
- package/src/campaign.ts +1 -1
- package/src/channel.ts +396 -749
- package/src/channel_batch_updater.ts +1 -1
- package/src/channel_state.ts +50 -105
- package/src/client.ts +360 -588
- package/src/client_state.ts +1 -6
- package/src/configuration/ConfigController.ts +41 -157
- package/src/configuration/InstanceConfigurationRegistry.ts +42 -171
- package/src/configuration/index.ts +1 -1
- package/src/configuration/keys.ts +13 -32
- package/src/configuration/shape.ts +67 -70
- package/src/configuration/types.ts +60 -100
- package/src/configuration/utils/applyInstanceConfiguration.ts +21 -53
- package/src/configuration/utils/copyConfigPatch.ts +11 -32
- package/src/configuration/utils/declarativeSlices.ts +9 -39
- package/src/configuration/utils/deepFreezeConfig.ts +3 -17
- package/src/configuration/utils/index.ts +2 -4
- package/src/configuration/utils/serverAuthority.ts +20 -68
- package/src/connection/ConnectionIdManager.ts +20 -49
- package/src/connection/ConnectionRecoveryManager.ts +51 -178
- package/src/connection/networkConnection/NetworkConnectionObserver.ts +37 -114
- package/src/connection/networkConnection/reporters.ts +9 -36
- package/src/connection/networkConnection/types.ts +12 -27
- package/src/connection/wsConnection/StableWSConnection.ts +73 -193
- package/src/connection/wsConnection/WSConnection.ts +56 -131
- package/src/connection/wsConnection/WSConnectionFallback.ts +22 -31
- package/src/connection/wsConnection/config.ts +13 -48
- package/src/connection/wsConnection/types.ts +17 -70
- package/src/constants.ts +4 -4
- package/src/entityStore/EntityStore.ts +162 -167
- package/src/entityStore/StoreBackedItemIndex.ts +14 -47
- package/src/errors.ts +7 -19
- package/src/formatMessageMemo.ts +3 -9
- package/src/gen/chat/ChannelApi.ts +19 -0
- package/src/gen/chat/ChatApi.ts +87 -13
- package/src/gen/models/index.ts +793 -71
- package/src/gen/moderation/ModerationApi.ts +0 -4
- package/src/index.ts +10 -14
- package/src/languageNames.ts +9 -24
- package/src/logger.ts +1 -3
- package/src/messageComposer/LocationComposer.ts +7 -23
- package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
- package/src/messageComposer/attachmentIdentity.ts +2 -13
- package/src/messageComposer/attachmentManager.ts +17 -63
- package/src/messageComposer/attachmentUtils.ts +3 -17
- package/src/messageComposer/configuration/configuration.ts +5 -8
- package/src/messageComposer/configuration/types.ts +29 -56
- package/src/messageComposer/fileUtils.ts +1 -1
- package/src/messageComposer/linkPreviewsManager.ts +8 -20
- package/src/messageComposer/messageComposer.ts +54 -222
- package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +4 -16
- package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +1 -2
- package/src/messageComposer/middleware/messageComposer/attachments.ts +14 -40
- package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +3 -4
- package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +4 -11
- package/src/messageComposer/middleware/pollComposer/state.ts +2 -2
- package/src/messageComposer/middleware/pollComposer/types.ts +2 -4
- package/src/messageComposer/middleware/pollComposer/validation.ts +8 -26
- package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +1 -6
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +1 -2
- package/src/messageComposer/middleware/textComposer/commands.ts +11 -16
- package/src/messageComposer/middleware/textComposer/mentions.ts +32 -70
- package/src/messageComposer/middleware/textComposer/textMiddlewareUtils.ts +10 -4
- package/src/messageComposer/middleware/textComposer/types.ts +1 -6
- package/src/messageComposer/pollComposer.ts +11 -8
- package/src/messageComposer/textComposer.ts +9 -59
- package/src/messageComposer/types.ts +9 -12
- package/src/messageDelivery/MessageDeliveryReporter.ts +60 -113
- package/src/messageDelivery/MessageReceiptsTracker.ts +21 -105
- package/src/messageOperations/FailedSendCache.ts +4 -9
- package/src/messageOperations/MessageOperationStatePolicy.ts +40 -67
- package/src/messageOperations/MessageOperations.ts +33 -62
- package/src/messageOperations/applyReactionLocally.ts +9 -28
- package/src/messageOperations/createMessageOperations.ts +17 -33
- package/src/messageOperations/reflectReactionEvent.ts +5 -13
- package/src/messageOperations/sendOrdering.ts +4 -7
- package/src/messageOperations/settlePendingAttachmentUploads.ts +10 -21
- package/src/messageOperations/types.ts +15 -30
- package/src/middleware.ts +7 -10
- package/src/moderation.ts +25 -21
- package/src/notifications/NotificationManager.ts +11 -35
- package/src/notifications/types.ts +19 -59
- package/src/offline-support/offline_support_api.ts +178 -608
- package/src/offline-support/offline_sync_manager.ts +25 -69
- package/src/offline-support/queueableOperations.ts +31 -84
- package/src/offline-support/types.ts +25 -188
- package/src/pagination/ItemIndex.ts +4 -12
- package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +13 -62
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +4 -6
- package/src/pagination/filterCompiler.ts +11 -25
- package/src/pagination/paginators/BasePaginator.ts +422 -976
- package/src/pagination/paginators/ChannelPaginator.ts +130 -190
- package/src/pagination/paginators/MessageIntervalPaginator.ts +226 -457
- package/src/pagination/paginators/MessagePaginator.ts +135 -175
- package/src/pagination/paginators/PinnedMessagePaginator.ts +13 -38
- package/src/pagination/paginators/ReminderPaginator.ts +12 -15
- package/src/pagination/paginators/ThreadPaginator.ts +16 -26
- package/src/pagination/paginators/UserGroupPaginator.ts +6 -17
- package/src/pagination/paginators/stateThrottling.ts +5 -10
- package/src/pagination/sortCompiler.ts +23 -50
- package/src/pagination/utility.normalization.ts +8 -30
- package/src/pagination/utility.search.ts +4 -11
- package/src/poll.ts +19 -19
- package/src/poll_manager.ts +16 -20
- package/src/poll_optimistic_votes.ts +17 -22
- package/src/reminders/Reminder.ts +5 -6
- package/src/reminders/ReminderManager.ts +9 -34
- package/src/reminders/ReminderTimer.ts +1 -2
- package/src/search/BaseSearchSource.ts +14 -29
- package/src/search/ChannelSearchSource.ts +8 -8
- package/src/search/MessageSearchSource.ts +19 -25
- package/src/search/SearchController.ts +18 -24
- package/src/search/types.ts +6 -10
- package/src/segment.ts +1 -1
- package/src/signing.ts +23 -3
- package/src/thread.ts +72 -173
- package/src/thread_manager.ts +59 -76
- package/src/token_manager.ts +11 -21
- package/src/types.ts +78 -126
- package/src/types.utility.ts +3 -3
- package/src/upload-utils.ts +5 -10
- package/src/uploadManager.ts +22 -54
- package/src/utils/FixedSizeQueueCache.ts +13 -21
- package/src/utils/WithSubscriptions.ts +5 -15
- package/src/utils/concurrency.ts +16 -55
- package/src/utils/mergeWith/mergeWith.ts +10 -13
- package/src/utils/mergeWith/mergeWithCore.ts +24 -81
- package/src/utils/mergeWith/mergeWithDiff.ts +15 -33
- package/src/utils/objectPath.ts +6 -41
- package/src/utils/retryable.ts +10 -14
- package/src/utils/throttling/throttle.ts +9 -25
- package/src/utils/time.ts +26 -66
- package/src/utils.ts +72 -128
|
@@ -1 +1 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Batch channel updates are available in the server-side SDK.
|
package/src/channel_state.ts
CHANGED
|
@@ -30,41 +30,32 @@ type ChannelReadStatus = Record<
|
|
|
30
30
|
>;
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
* Whether this client holds a server-side watch on the channel
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* wanted: a watch lost to a dead socket should be restored on reconnect, one the consumer stopped
|
|
38
|
-
* deliberately must not be. The server keys watches by connection ID, so a dropped socket ends every
|
|
39
|
-
* watch this client held — even if it reconnects moments later with a fresh ID.
|
|
33
|
+
* Whether this client holds a server-side watch on the channel (channel events are delivered to it).
|
|
34
|
+
* Three values because a watch lost to a dropped socket should be restored on reconnect, while one the
|
|
35
|
+
* consumer stopped must not be. The server keys watches by connection ID, so a dropped socket ends
|
|
36
|
+
* every watch this client held.
|
|
40
37
|
*/
|
|
41
38
|
export const ChannelWatchStatus = {
|
|
42
|
-
/** Never watched, or the consumer stopped watching
|
|
39
|
+
/** Never watched, or the consumer stopped watching: do NOT re-watch. */
|
|
43
40
|
NotWatching: 'notWatching',
|
|
44
|
-
/** Was watching until the connection dropped
|
|
41
|
+
/** Was watching until the connection dropped: the watch is gone and SHOULD be restored. */
|
|
45
42
|
WasWatching: 'wasWatching',
|
|
46
|
-
/**
|
|
43
|
+
/** Holds a live watch. */
|
|
47
44
|
Watching: 'watching',
|
|
48
45
|
} as const;
|
|
49
46
|
|
|
50
47
|
export type ChannelWatchStatus =
|
|
51
48
|
(typeof ChannelWatchStatus)[keyof typeof ChannelWatchStatus];
|
|
52
49
|
|
|
53
|
-
/**
|
|
54
|
-
* Everything about watching this channel: who else is watching it, and whether *we* are.
|
|
55
|
-
*/
|
|
50
|
+
/** Who is watching the channel, and whether this client is. */
|
|
56
51
|
export type ChannelWatchState = {
|
|
57
52
|
watcherCount: number;
|
|
58
53
|
watchers: Record<string, UserResponse>;
|
|
59
54
|
/**
|
|
60
|
-
* See {@link ChannelWatchStatus}.
|
|
61
|
-
* (`channel.watch()`, `channel.query({ watch: true })`, `client.
|
|
62
|
-
* `WasWatching` when the
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* It is truthful by construction: `channel.watch()` and `client.queryChannels()` wait for a live
|
|
66
|
-
* socket rather than degrading, so a query carrying `watch: true` can only succeed against a
|
|
67
|
-
* connection ID that is actually current.
|
|
55
|
+
* See {@link ChannelWatchStatus}. Becomes `Watching` when a query with `watch: true` succeeds
|
|
56
|
+
* (`channel.watch()`, `channel.query({ watch: true })`, `client.queryChannelsAndHydrate()`, a
|
|
57
|
+
* thread query with `watch: true`), `WasWatching` when the connection is lost (only from
|
|
58
|
+
* `Watching`), and `NotWatching` on `channel.stopWatching()` or `channel.disconnect()`.
|
|
68
59
|
*/
|
|
69
60
|
watchStatus: ChannelWatchStatus;
|
|
70
61
|
};
|
|
@@ -80,16 +71,13 @@ export type ReadState = {
|
|
|
80
71
|
export type MembersState = {
|
|
81
72
|
members: Record<string, ChannelMemberResponse>;
|
|
82
73
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* incrementing per member event double-counted when several members changed at once.
|
|
87
|
-
* See https://github.com/GetStream/stream-chat-js/pull/1761.
|
|
74
|
+
* From `channel.data.member_count`. Set on query, watch and hydration (including the offline DB) and
|
|
75
|
+
* on `channel.updated`, not on `member.added` / `member.removed`: `channel.updated` fires on every
|
|
76
|
+
* member change and is authoritative, while counting per member event double-counts.
|
|
88
77
|
*/
|
|
89
78
|
memberCount: number;
|
|
90
79
|
};
|
|
91
80
|
|
|
92
|
-
/** The current user's own membership in this channel (role, pinned_at, archived_at, …). */
|
|
93
81
|
export type MembershipState = {
|
|
94
82
|
membership: ChannelMemberResponse;
|
|
95
83
|
};
|
|
@@ -98,16 +86,11 @@ export type OwnCapabilitiesState = {
|
|
|
98
86
|
ownCapabilities: string[];
|
|
99
87
|
};
|
|
100
88
|
|
|
101
|
-
/**
|
|
102
|
-
* The channel's server-provided `data` (name, image, frozen, hidden, blocked, config,
|
|
103
|
-
* `member_count`, `own_capabilities`, …), mirrored reactively so consumers can subscribe to
|
|
104
|
-
* channel-level changes via `useStateStore(channel.state, (s) => ({ data: s.data }))`.
|
|
105
|
-
*/
|
|
106
89
|
export type ChannelDataState = {
|
|
107
90
|
data: Channel['data'];
|
|
108
91
|
};
|
|
109
92
|
|
|
110
|
-
/** Whether
|
|
93
|
+
/** Whether this channel is muted for the current user, mirrored from `client.mutedChannels`. */
|
|
111
94
|
export type ChannelMuteStatus = {
|
|
112
95
|
muted: boolean;
|
|
113
96
|
/** Unix nanoseconds, as the API sends it. */
|
|
@@ -117,85 +100,63 @@ export type ChannelMuteStatus = {
|
|
|
117
100
|
};
|
|
118
101
|
|
|
119
102
|
/**
|
|
120
|
-
*
|
|
121
|
-
* `client.
|
|
122
|
-
* subscribable via `useStateStore(channel.state, (s) => ({ muteStatus: s.muteStatus }))`. Muted
|
|
123
|
-
* USERS remain client-global on `client.mutedUsersStore` and are NOT part of channel state.
|
|
103
|
+
* Kept in sync with `client.mutedChannels` (`notification.channel_mutes_updated`, `health.check`).
|
|
104
|
+
* Muted users are client-global (`client.mutedUsersStore`), not part of channel state.
|
|
124
105
|
*/
|
|
125
106
|
export type MuteStatusState = {
|
|
126
107
|
muteStatus: ChannelMuteStatus;
|
|
127
108
|
};
|
|
128
109
|
|
|
129
110
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* Read through the `channel.initialized` / `channel.offlineMode` / `channel.pendingDisposal`
|
|
133
|
-
* getters, which proxy this slice; `initialized` and `offlineMode` have setters too, while
|
|
134
|
-
* `pendingDisposal` is set only by `channel.disconnect()`.
|
|
111
|
+
* Read through the `channel.initialized` / `offlineMode` / `pendingDisposal` / `supersededBy`
|
|
112
|
+
* getters. Only `channel.disconnect()` sets `pendingDisposal`.
|
|
135
113
|
*/
|
|
136
114
|
export type ChannelLifecycleState = {
|
|
137
115
|
/**
|
|
138
|
-
* Whether a live server response
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* `
|
|
142
|
-
* Data restored from the offline database doesn't count (see `offlineMode`). Never reset.
|
|
116
|
+
* Whether a live server response (a query or a `queryChannels` result) was applied to this instance
|
|
117
|
+
* since it was created. `false`: nothing confirmed the channel yet, so it may or may not exist on
|
|
118
|
+
* the server. Data restored from the offline database does not count (see `offlineMode`).
|
|
119
|
+
* `watchStatus` tells whether the data is kept current. Never reset.
|
|
143
120
|
*/
|
|
144
121
|
initialized: boolean;
|
|
145
122
|
/**
|
|
146
|
-
* Whether the
|
|
147
|
-
*
|
|
148
|
-
* being watched yet.
|
|
123
|
+
* Whether the state was populated manually (e.g. offline hydration) rather than by a live query: the
|
|
124
|
+
* channel exists on the backend but is not watched yet.
|
|
149
125
|
*/
|
|
150
126
|
offlineMode: boolean;
|
|
151
127
|
/**
|
|
152
128
|
* Whether `channel.disconnect()` has run: the channel was deleted, the current user removed from
|
|
153
|
-
* it, the client disconnected, or nothing
|
|
154
|
-
* {@link Channel.pendingDisposal}: the instance is never revived.
|
|
129
|
+
* it, the client disconnected, or nothing uses it. Terminal, see {@link Channel.pendingDisposal}.
|
|
155
130
|
*/
|
|
156
131
|
pendingDisposal: boolean;
|
|
157
132
|
/**
|
|
158
|
-
* The stored instance that replaced this one: this
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
* messages and, when this one was open and it wasn't, its composer. Anything still holding this
|
|
162
|
-
* instance should switch to it. Set once.
|
|
133
|
+
* The stored instance that replaced this one: this one was created without an ID and, when the server
|
|
134
|
+
* answered with the cid, another instance was already stored under it. That instance took this one's
|
|
135
|
+
* server data, local messages and (if this one was open and it was not) its composer. Set once.
|
|
163
136
|
*/
|
|
164
137
|
supersededBy: Channel | undefined;
|
|
165
138
|
};
|
|
166
139
|
|
|
167
|
-
/**
|
|
168
|
-
* Whether the channel is currently being consumed — consumer-declared, never returned by the API.
|
|
169
|
-
* Mirrors `thread.state.active`.
|
|
170
|
-
*/
|
|
140
|
+
/** Consumer-declared, never returned by the API. */
|
|
171
141
|
export type ChannelActivationState = {
|
|
172
142
|
/**
|
|
173
|
-
* Whether a consumer
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* that the channel's own state is being consumed and takes precedence over bulk state writes —
|
|
177
|
-
* channel-list hydration does not re-seed the message list of an `active` channel (the channel's
|
|
178
|
-
* own `channel.reload()` owns that window).
|
|
143
|
+
* Whether a consumer declared this channel as the one it is reading, via `channel.activate()`. Its
|
|
144
|
+
* own state then takes precedence over bulk writes: channel-list hydration does not re-seed the
|
|
145
|
+
* message list of an `active` channel (`channel.reload()` owns that window).
|
|
179
146
|
*/
|
|
180
147
|
active: boolean;
|
|
181
148
|
};
|
|
182
149
|
|
|
183
150
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* `useStateStore(channel.state, (s) => ({ aiState: s.aiState }))`. Reset to `Idle` on unwatch /
|
|
187
|
-
* disconnect (a live server sends `ai_indicator.clear` when the AI response starts streaming).
|
|
151
|
+
* Driven by the `ai_indicator.update` / `.clear` / `.stop` events. Reset to `Idle` when the connection
|
|
152
|
+
* closes or goes unhealthy, as the `clear`/`stop` that ends a response is missed and not replayed.
|
|
188
153
|
*/
|
|
189
154
|
export type AIIndicatorState = {
|
|
190
155
|
aiState: AIState;
|
|
191
156
|
};
|
|
192
157
|
|
|
193
158
|
/**
|
|
194
|
-
*
|
|
195
|
-
* through this one `StateStore` and subscribed to with `useStateStore(channel.state, selector)`
|
|
196
|
-
* (mirroring `thread.state`).
|
|
197
|
-
*
|
|
198
|
-
* The shape is FLAT — subscribe to any slice via a selector, e.g.
|
|
159
|
+
* All per-channel reactive state, in one flat `StateStore`. Subscribe with a selector, e.g.
|
|
199
160
|
* `useStateStore(channel.state, (s) => ({ read: s.read }))`.
|
|
200
161
|
*/
|
|
201
162
|
export type ChannelStateData = ChannelWatchState &
|
|
@@ -211,11 +172,8 @@ export type ChannelStateData = ChannelWatchState &
|
|
|
211
172
|
AIIndicatorState;
|
|
212
173
|
|
|
213
174
|
/**
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
* It IS a `StateStore<ChannelStateData>` (so `useStateStore(channel.state, selector)` works,
|
|
217
|
-
* mirroring `thread.state`) while additionally exposing convenience getters/setters
|
|
218
|
-
* (`members`, `read`, `typing`, `watchers`, …) that read/write the same unified store.
|
|
175
|
+
* A `StateStore<ChannelStateData>` that also exposes getters/setters (`members`, `read`, `typing`,
|
|
176
|
+
* `watchers`, ...) over the same store.
|
|
219
177
|
*/
|
|
220
178
|
export class ChannelState extends StateStore<ChannelStateData> {
|
|
221
179
|
_channel: Channel;
|
|
@@ -247,20 +205,16 @@ export class ChannelState extends StateStore<ChannelStateData> {
|
|
|
247
205
|
}
|
|
248
206
|
|
|
249
207
|
/**
|
|
250
|
-
* The current user's unread
|
|
251
|
-
*
|
|
252
|
-
* place holding this value, so the count the unread badge reads can never drift from the count
|
|
253
|
-
* `channel.countUnread()` returns. Written through `Channel._setOwnUnreadCount`.
|
|
208
|
+
* The current user's unread count, derived from `read[ownUserId].unread_messages` so it cannot drift
|
|
209
|
+
* from `channel.countUnread()`. Written through `Channel._setOwnUnreadCount`.
|
|
254
210
|
*/
|
|
255
211
|
get unreadCount() {
|
|
256
|
-
//
|
|
257
|
-
// count off a dead instance should yield 0, not blow up.
|
|
212
|
+
// `_client` is read directly: `getClient()` throws on a channel pending disposal, which reads 0.
|
|
258
213
|
const userId = this._channel?._client?.userId;
|
|
259
214
|
if (!userId) return 0;
|
|
260
215
|
return this.getLatestValue().read[userId]?.unread_messages ?? 0;
|
|
261
216
|
}
|
|
262
217
|
|
|
263
|
-
/** The current user's own membership; store-backed so `useStateStore` can subscribe to it. */
|
|
264
218
|
get membership() {
|
|
265
219
|
return this.getLatestValue().membership;
|
|
266
220
|
}
|
|
@@ -294,17 +248,11 @@ export class ChannelState extends StateStore<ChannelStateData> {
|
|
|
294
248
|
}
|
|
295
249
|
|
|
296
250
|
get typing() {
|
|
297
|
-
return (
|
|
298
|
-
this._channel?.messageComposer?.textComposer.typing ?? this.getLatestValue().typing
|
|
299
|
-
);
|
|
251
|
+
return this.getLatestValue().typing;
|
|
300
252
|
}
|
|
301
253
|
|
|
302
254
|
set typing(typing: Record<string, Event>) {
|
|
303
255
|
this.partialNext({ typing });
|
|
304
|
-
|
|
305
|
-
if (this._channel?.messageComposer) {
|
|
306
|
-
this._channel.messageComposer.textComposer.setTyping(typing);
|
|
307
|
-
}
|
|
308
256
|
}
|
|
309
257
|
|
|
310
258
|
setTypingEvent(userID: string, event: Event) {
|
|
@@ -336,19 +284,17 @@ export class ChannelState extends StateStore<ChannelStateData> {
|
|
|
336
284
|
}
|
|
337
285
|
|
|
338
286
|
/**
|
|
339
|
-
*
|
|
340
|
-
*
|
|
287
|
+
* Adds the SDK-specific fields (`status`, `error`) to a message. Memoized per source object:
|
|
288
|
+
* callers share the result, so do not mutate it.
|
|
341
289
|
*
|
|
342
|
-
* @param message -
|
|
290
|
+
* @param message - The message from the API, or a local one.
|
|
291
|
+
* @returns The `LocalMessage`.
|
|
343
292
|
*/
|
|
344
293
|
formatMessage = (message: MessageResponse | LocalMessage) => formatMessage(message);
|
|
345
294
|
|
|
346
|
-
/**
|
|
347
|
-
* clean - Remove stale data such as users that stayed in typing state for more than 5 seconds
|
|
348
|
-
*/
|
|
295
|
+
/** Removes users typing for more than 7 seconds without a new event, dispatching `typing.stop`. */
|
|
349
296
|
clean() {
|
|
350
297
|
const now = nowNs();
|
|
351
|
-
// prevent old users from showing up as typing
|
|
352
298
|
for (const [userID, lastEvent] of Object.entries(this.typing)) {
|
|
353
299
|
const receivedAt = lastEvent.received_at ?? now;
|
|
354
300
|
if (nsToMs(now - receivedAt) > 7000) {
|
|
@@ -363,9 +309,8 @@ export class ChannelState extends StateStore<ChannelStateData> {
|
|
|
363
309
|
}
|
|
364
310
|
|
|
365
311
|
/**
|
|
366
|
-
* Resets the AI indicator to `Idle`. Called when the connection
|
|
367
|
-
*
|
|
368
|
-
* reconnect, so the indicator would otherwise stay stuck on "Generating". Noop when already `Idle`.
|
|
312
|
+
* Resets the AI indicator to `Idle`. Called when the connection closes or goes unhealthy: the
|
|
313
|
+
* `ai_indicator.clear`/`.stop` that ends a response is missed then and not replayed on reconnect.
|
|
369
314
|
*/
|
|
370
315
|
resetAIState() {
|
|
371
316
|
if (this.getLatestValue().aiState === AIStates.Idle) return;
|