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
package/src/thread_manager.ts
CHANGED
|
@@ -26,10 +26,8 @@ const eventCarriesOwnUser = (
|
|
|
26
26
|
|
|
27
27
|
export type ThreadManagerConfig = {
|
|
28
28
|
/**
|
|
29
|
-
* Minimum gap between thread-list reloads triggered by connection recovery
|
|
30
|
-
*
|
|
31
|
-
* Read when subscriptions are registered, since the throttle captures the interval in a closure — a
|
|
32
|
-
* change applies from the next `registerSubscriptions()`, not retroactively.
|
|
29
|
+
* Minimum gap between thread-list reloads triggered by connection recovery, in milliseconds.
|
|
30
|
+
* Defaults to 1000. Read in `registerSubscriptions()`, so a change applies from the next call.
|
|
33
31
|
*/
|
|
34
32
|
connectionRecoveryThrottleMs: number;
|
|
35
33
|
};
|
|
@@ -41,19 +39,12 @@ export const DEFAULT_THREAD_MANAGER_CONFIG: ThreadManagerConfig = deepFreezeConf
|
|
|
41
39
|
/** Manager-level state. The list itself lives on {@link ThreadManager.paginator}. */
|
|
42
40
|
export type ThreadManagerState = {
|
|
43
41
|
active: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Whether the thread manager has been activated at least once in the current
|
|
46
|
-
* session (i.e. `activate()` was called). Used to avoid requerying threads
|
|
47
|
-
* on connection recovery for consumers that never actually activate the manager.
|
|
48
|
-
*/
|
|
42
|
+
/** Whether `activate()` was called this session. Recovery skips the reload when it never was. */
|
|
49
43
|
wasActivatedAtLeastOnce: boolean;
|
|
50
44
|
/** A listed thread got a reply since the latest reload, so the list order may be out of date. */
|
|
51
45
|
isThreadOrderStale: boolean;
|
|
52
46
|
unreadThreadCount: number;
|
|
53
|
-
/**
|
|
54
|
-
* List of threads that haven't been loaded in the list, but have received new messages
|
|
55
|
-
* since the latest reload. Useful to display a banner prompting to reload the thread list.
|
|
56
|
-
*/
|
|
47
|
+
/** Threads not in the list that got new messages since the latest reload (for a banner). */
|
|
57
48
|
unseenThreadIds: string[];
|
|
58
49
|
};
|
|
59
50
|
|
|
@@ -78,24 +69,20 @@ export class ThreadManager extends WithSubscriptions {
|
|
|
78
69
|
public readonly paginator: ThreadPaginator;
|
|
79
70
|
private client: StreamChat;
|
|
80
71
|
/**
|
|
81
|
-
* Every live thread, held by the list
|
|
82
|
-
*
|
|
72
|
+
* Every live thread, held by the list and/or `REGISTERED_HOLDER` (opened this session). A thread
|
|
73
|
+
* leaves once neither holds it.
|
|
83
74
|
*/
|
|
84
75
|
private readonly threadStore = new EntityStore<Thread>({ getEntityId: getThreadId });
|
|
85
|
-
/** A reload is in flight; a second one is dropped
|
|
76
|
+
/** A reload is in flight; a second one is dropped. */
|
|
86
77
|
private isReloadInFlight = false;
|
|
87
78
|
/**
|
|
88
|
-
* A local `pendingDisposal` listener
|
|
89
|
-
*
|
|
79
|
+
* A local `pendingDisposal` listener per channel with a listed or opened thread, removed when the
|
|
80
|
+
* channel is disposed or on reset.
|
|
90
81
|
*/
|
|
91
82
|
private readonly disposalListeners = new Map<Channel, Unsubscribe>();
|
|
92
83
|
|
|
93
|
-
/** The shared configuration machinery — see {@link ConfigController}. */
|
|
94
84
|
private readonly configController: ConfigController<ThreadManagerConfig>;
|
|
95
|
-
|
|
96
|
-
* Resolved configuration, as a store — the shape every configurable class exposes
|
|
97
|
-
* (`configState` / `config` / `updateConfig`).
|
|
98
|
-
*/
|
|
85
|
+
|
|
99
86
|
get configState(): StateStore<ThreadManagerConfig> {
|
|
100
87
|
return this.configController.state;
|
|
101
88
|
}
|
|
@@ -109,67 +96,58 @@ export class ThreadManager extends WithSubscriptions {
|
|
|
109
96
|
this.client = client;
|
|
110
97
|
this.state = new StateStore<ThreadManagerState>(THREAD_MANAGER_INITIAL_STATE);
|
|
111
98
|
this.paginator = new ThreadPaginator({ client, store: this.threadStore });
|
|
112
|
-
//
|
|
99
|
+
// A listed or opened thread keeps its channel.
|
|
113
100
|
client.channelManager.channelStore.addClaim({
|
|
114
101
|
heldBy: () => this.registeredThreads.map((thread) => thread.channel),
|
|
115
102
|
name: 'threads',
|
|
116
103
|
});
|
|
117
|
-
// Every thread
|
|
118
|
-
// `registerSubscriptions()
|
|
104
|
+
// Every listed thread gets its channel's disposal listener, independent of
|
|
105
|
+
// `registerSubscriptions()`.
|
|
119
106
|
this.paginator.state.subscribeWithSelector(
|
|
120
107
|
({ items }) => ({ items }),
|
|
121
108
|
({ items }) => items?.forEach(this.listenForDisposal),
|
|
122
109
|
);
|
|
123
110
|
}
|
|
124
111
|
|
|
125
|
-
/** The current resolved configuration. `Readonly` — change it through {@link updateConfig}. */
|
|
126
112
|
public get config(): Readonly<ThreadManagerConfig> {
|
|
127
113
|
return this.configState.getLatestValue();
|
|
128
114
|
}
|
|
129
115
|
|
|
130
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* Merges a partial configuration into the resolved config.
|
|
118
|
+
*
|
|
119
|
+
* @param config - The fields to change.
|
|
120
|
+
*/
|
|
131
121
|
public updateConfig(config: Partial<ThreadManagerConfig>) {
|
|
132
122
|
this.configController.patch(config);
|
|
133
123
|
}
|
|
134
124
|
|
|
135
125
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* The derivation entry point every configurable entity exposes, so the owner routes a slice here and
|
|
139
|
-
* knows nothing about ThreadManager's defaults or merge semantics. This logic used to live in the owner,
|
|
140
|
-
* which is how `reset()` became a no-op for the client key (F4) and how a registered
|
|
141
|
-
* `notifications.sortComparator` became unremovable (G8) — an owner writing another object's
|
|
142
|
-
* derivation gets that object's rules wrong sooner or later.
|
|
126
|
+
* Re-derives the configuration from the declarative slice.
|
|
143
127
|
*
|
|
144
|
-
*
|
|
145
|
-
* every field of `ThreadManagerConfig` is required and present in the defaults, so a patch naming all of
|
|
146
|
-
* them amounts to a replacement. `NotificationManager` cannot do this — its `sortComparator` is
|
|
147
|
-
* optional with no default, so a patch can never remove one — which is why it replaces outright.
|
|
128
|
+
* @param config - The declarative slice (optional).
|
|
148
129
|
*/
|
|
149
130
|
public initializeConfig(config?: Partial<ThreadManagerConfig>) {
|
|
150
131
|
this.configController.initialize(config);
|
|
151
132
|
}
|
|
152
133
|
|
|
153
134
|
/**
|
|
154
|
-
* The live thread for `id`: one in the list, or one opened this session
|
|
155
|
-
* list
|
|
156
|
-
* membership is `paginator.getItem(id)`.
|
|
135
|
+
* The live thread for `id`: one in the list, or one opened this session. `paginator.items` holds
|
|
136
|
+
* the list only; list membership is `paginator.getItem(id)`.
|
|
157
137
|
*/
|
|
158
138
|
public get = (id: string): Thread | undefined => this.threadStore.get(id);
|
|
159
139
|
|
|
160
140
|
/**
|
|
161
|
-
* Returns the thread for `parentMessage`, creating
|
|
162
|
-
*
|
|
141
|
+
* Returns the thread for `parentMessage`, creating and registering it if needed. Use it instead
|
|
142
|
+
* of `new Thread()`: the thread list reuses this instance if it later loads the same thread. A
|
|
143
|
+
* created thread starts stale and loads its data when first opened, unless the parent has no
|
|
144
|
+
* replies in a watched channel (nothing to load: `getThread` would 404, the first reply arrives
|
|
145
|
+
* as an event). In an unwatched channel the parent's `reply_count` may miss newer replies, so it
|
|
146
|
+
* always loads.
|
|
163
147
|
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
* A thread created here only has its parent message. It starts stale and loads its thread data
|
|
168
|
-
* (participants, read state, replies) once, the first time it's opened, when it may have any: when
|
|
169
|
-
* the parent has replies, and when the channel isn't watched, as the parent's `reply_count` then
|
|
170
|
-
* misses the replies sent since. A parent without replies in a watched channel has nothing to load
|
|
171
|
-
* yet (`getThread` would answer 404): the thread starts up to date, and its first reply arrives as
|
|
172
|
-
* an event.
|
|
148
|
+
* @param params.channel - The channel of the parent message.
|
|
149
|
+
* @param params.parentMessage - The thread's parent message.
|
|
150
|
+
* @returns The registered thread.
|
|
173
151
|
*/
|
|
174
152
|
public ensure = ({
|
|
175
153
|
channel,
|
|
@@ -187,7 +165,23 @@ export class ThreadManager extends WithSubscriptions {
|
|
|
187
165
|
};
|
|
188
166
|
|
|
189
167
|
/**
|
|
190
|
-
*
|
|
168
|
+
* The registered instance for a thread a query just built, else the query's own, so events keep
|
|
169
|
+
* reaching the one managed instance. A stale registered thread is refreshed from the query unless
|
|
170
|
+
* it is active (it reloads itself).
|
|
171
|
+
*
|
|
172
|
+
* @internal
|
|
173
|
+
*/
|
|
174
|
+
public resolveQueried = (incoming: Thread): Thread => {
|
|
175
|
+
const stored = this.threadStore.get(incoming.id);
|
|
176
|
+
if (!stored) return incoming;
|
|
177
|
+
if (stored.hasStaleState && !stored.state.getLatestValue().active) {
|
|
178
|
+
stored.hydrateState(incoming);
|
|
179
|
+
}
|
|
180
|
+
return stored;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Every registered thread: the list's plus the opened ones.
|
|
191
185
|
*
|
|
192
186
|
* @internal
|
|
193
187
|
*/
|
|
@@ -196,9 +190,8 @@ export class ThreadManager extends WithSubscriptions {
|
|
|
196
190
|
}
|
|
197
191
|
|
|
198
192
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
* channel is disposed or the user disconnects.
|
|
193
|
+
* Keeps `thread` for the session: resolvable through {@link ThreadManager.get} and subscribed
|
|
194
|
+
* whether or not the list holds it, until its channel is disposed or the user disconnects.
|
|
202
195
|
*
|
|
203
196
|
* @internal
|
|
204
197
|
*/
|
|
@@ -223,7 +216,7 @@ export class ThreadManager extends WithSubscriptions {
|
|
|
223
216
|
this.listenForDisposal(thread);
|
|
224
217
|
};
|
|
225
218
|
|
|
226
|
-
/** Releases the `REGISTERED_HOLDER` hold
|
|
219
|
+
/** Releases the `REGISTERED_HOLDER` hold, and unsubscribes the thread unless listed. */
|
|
227
220
|
private release = (thread: Thread) => {
|
|
228
221
|
this.threadStore.unlink(thread.id, REGISTERED_HOLDER);
|
|
229
222
|
if (this.hasSubscriptions && !this.paginator.items?.includes(thread)) {
|
|
@@ -295,10 +288,9 @@ export class ThreadManager extends WithSubscriptions {
|
|
|
295
288
|
};
|
|
296
289
|
|
|
297
290
|
/**
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
* `master`. A thread follows its channel's `watchStatus` itself, so watch events need no routing.
|
|
291
|
+
* Routes client events to the threads in the store by ID. A message event reaches the thread the
|
|
292
|
+
* message replies in and the thread it starts; quoted-message updates stay within the reply's own
|
|
293
|
+
* thread. A thread follows its channel's `watchStatus` itself.
|
|
302
294
|
*/
|
|
303
295
|
private subscribeThreadEvents = () => {
|
|
304
296
|
const threadsOf = (message?: { id: string; parent_id?: string }) =>
|
|
@@ -357,7 +349,6 @@ export class ThreadManager extends WithSubscriptions {
|
|
|
357
349
|
};
|
|
358
350
|
|
|
359
351
|
private subscribeUnreadThreadsCountChange = () => {
|
|
360
|
-
// initiate
|
|
361
352
|
const { unread_threads: unreadThreadCount = 0 } =
|
|
362
353
|
(this.client.user as OwnUserResponse) ?? {};
|
|
363
354
|
this.state.partialNext({ unreadThreadCount });
|
|
@@ -392,8 +383,8 @@ export class ThreadManager extends WithSubscriptions {
|
|
|
392
383
|
(nextValue) => ({ threads: nextValue.items ?? [] }),
|
|
393
384
|
({ threads: nextThreads }, prev) => {
|
|
394
385
|
const { threads: prevThreads = [] } = prev ?? {};
|
|
395
|
-
// Left the list and
|
|
396
|
-
// publishes before it unlinks the list's hold.
|
|
386
|
+
// Left the list and not opened. Checks `REGISTERED_HOLDER`, not `threadStore.get`:
|
|
387
|
+
// `removeItem` publishes before it unlinks the list's hold.
|
|
397
388
|
const listed = new Set(nextThreads);
|
|
398
389
|
const removedThreads = prevThreads.filter(
|
|
399
390
|
(thread) =>
|
|
@@ -429,15 +420,7 @@ export class ThreadManager extends WithSubscriptions {
|
|
|
429
420
|
}
|
|
430
421
|
}).unsubscribe;
|
|
431
422
|
|
|
432
|
-
/**
|
|
433
|
-
* Reloads the thread list once recovery after a reconnect has finished.
|
|
434
|
-
*
|
|
435
|
-
* `connection.recovered` on its own is the whole condition, with no drop timestamp to gate on:
|
|
436
|
-
* `ConnectionRecoveryManager` dispatches it on every reconnect path, so it already implies a drop.
|
|
437
|
-
*
|
|
438
|
-
* Anything that does need the drop timestamp should read `client.wsConnection.state.lastUnhealthyAt`,
|
|
439
|
-
* which is written on every status transition.
|
|
440
|
-
*/
|
|
423
|
+
/** Reloads the thread list once recovery after a reconnect finished (`connection.recovered`). */
|
|
441
424
|
private subscribeReloadOnConnectionRecovered = () => {
|
|
442
425
|
const throttledHandleConnectionRecovered = throttle(
|
|
443
426
|
() => {
|
|
@@ -460,8 +443,8 @@ export class ThreadManager extends WithSubscriptions {
|
|
|
460
443
|
/**
|
|
461
444
|
* Loads the first page, or re-queries a loaded list in place, sized to what is loaded plus the
|
|
462
445
|
* unseen threads. Skipped once loaded unless forced or something changed; the list survives a
|
|
463
|
-
* failure.
|
|
464
|
-
*
|
|
446
|
+
* failure. Dropped while another reload is in flight. Only the first load shows
|
|
447
|
+
* `paginator.isLoading`.
|
|
465
448
|
*/
|
|
466
449
|
public reload = async ({ force = false } = {}) => {
|
|
467
450
|
if (this.isReloadInFlight) return;
|
package/src/token_manager.ts
CHANGED
|
@@ -6,11 +6,7 @@ import type { TokenOrProvider } from './types';
|
|
|
6
6
|
const logger = chatLoggerSystem.getLogger('token-manager');
|
|
7
7
|
|
|
8
8
|
export type TokenManagerMinimalUser = { id: string; anon?: boolean };
|
|
9
|
-
/**
|
|
10
|
-
* TokenManager
|
|
11
|
-
*
|
|
12
|
-
* Handles all the operations around user token.
|
|
13
|
-
*/
|
|
9
|
+
/** Holds the user token, either static or loaded from a provider. */
|
|
14
10
|
export class TokenManager {
|
|
15
11
|
loadTokenPromise: Promise<string> | null;
|
|
16
12
|
type: 'static' | 'provider';
|
|
@@ -18,9 +14,6 @@ export class TokenManager {
|
|
|
18
14
|
tokenProvider?: TokenOrProvider;
|
|
19
15
|
user?: TokenManagerMinimalUser;
|
|
20
16
|
private _isAnonymous = false;
|
|
21
|
-
/**
|
|
22
|
-
* Initializes the token manager.
|
|
23
|
-
*/
|
|
24
17
|
constructor() {
|
|
25
18
|
this.loadTokenPromise = null;
|
|
26
19
|
|
|
@@ -32,11 +25,11 @@ export class TokenManager {
|
|
|
32
25
|
}
|
|
33
26
|
|
|
34
27
|
/**
|
|
35
|
-
* Sets
|
|
36
|
-
* or a promise that resolves to a token string.
|
|
28
|
+
* Sets a static token or a token provider, then loads the token.
|
|
37
29
|
*
|
|
38
|
-
* @param tokenOrProvider - A token string or an async provider that
|
|
30
|
+
* @param tokenOrProvider - A token string, or an async provider that resolves to one.
|
|
39
31
|
* @param user - The user the token belongs to.
|
|
32
|
+
* @throws When the token is not a string or function, or a string token does not match `user.id`.
|
|
40
33
|
*/
|
|
41
34
|
setTokenOrProvider = async (
|
|
42
35
|
tokenOrProvider: TokenOrProvider,
|
|
@@ -60,8 +53,10 @@ export class TokenManager {
|
|
|
60
53
|
};
|
|
61
54
|
|
|
62
55
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
56
|
+
* Clears the token, the provider and the user. Called by the client on `disconnectUser()` and
|
|
57
|
+
* after an anonymous `createGuest()`.
|
|
58
|
+
*
|
|
59
|
+
* @internal
|
|
65
60
|
*/
|
|
66
61
|
reset = () => {
|
|
67
62
|
this._isAnonymous = false;
|
|
@@ -72,9 +67,8 @@ export class TokenManager {
|
|
|
72
67
|
this.loadTokenPromise = null;
|
|
73
68
|
};
|
|
74
69
|
|
|
75
|
-
// Validates the user token.
|
|
76
70
|
validateToken = (tokenOrProvider: TokenOrProvider, user: TokenManagerMinimalUser) => {
|
|
77
|
-
//
|
|
71
|
+
// Anonymous users may have an empty token.
|
|
78
72
|
if (user && user.anon && !tokenOrProvider) return;
|
|
79
73
|
|
|
80
74
|
if (
|
|
@@ -86,7 +80,6 @@ export class TokenManager {
|
|
|
86
80
|
}
|
|
87
81
|
|
|
88
82
|
if (typeof tokenOrProvider === 'string') {
|
|
89
|
-
// Allow empty token for anonymous users
|
|
90
83
|
if (user.anon && tokenOrProvider === '') return;
|
|
91
84
|
|
|
92
85
|
const tokenUserId = UserFromToken(tokenOrProvider);
|
|
@@ -101,12 +94,10 @@ export class TokenManager {
|
|
|
101
94
|
}
|
|
102
95
|
};
|
|
103
96
|
|
|
104
|
-
//
|
|
105
|
-
// case a function should wait.
|
|
97
|
+
// The in-flight token load, for callers that must wait for it.
|
|
106
98
|
tokenReady = () => this.loadTokenPromise;
|
|
107
99
|
|
|
108
|
-
// Fetches
|
|
109
|
-
// In case of static token, it will simply resolve to static token.
|
|
100
|
+
// Fetches the token from the provider and stores it. A static token resolves as is.
|
|
110
101
|
loadToken = () => {
|
|
111
102
|
// eslint-disable-next-line no-async-promise-executor
|
|
112
103
|
this.loadTokenPromise = new Promise(async (resolve, reject) => {
|
|
@@ -132,7 +123,6 @@ export class TokenManager {
|
|
|
132
123
|
return this.loadTokenPromise;
|
|
133
124
|
};
|
|
134
125
|
|
|
135
|
-
// Returns a current token
|
|
136
126
|
getToken = () => {
|
|
137
127
|
if (this.token) {
|
|
138
128
|
return this.token;
|