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.
Files changed (269) hide show
  1. package/dist/cjs/index.browser.js +2196 -3902
  2. package/dist/cjs/index.browser.js.map +3 -3
  3. package/dist/cjs/index.node.js +2197 -3902
  4. package/dist/cjs/index.node.js.map +3 -3
  5. package/dist/esm/index.mjs +2199 -3905
  6. package/dist/esm/index.mjs.map +4 -4
  7. package/dist/types/ChannelManager.d.ts +120 -233
  8. package/dist/types/CooldownTimer.d.ts +8 -23
  9. package/dist/types/EventHandlerPipeline.d.ts +17 -37
  10. package/dist/types/LiveLocationManager.d.ts +22 -50
  11. package/dist/types/api-client.d.ts +9 -14
  12. package/dist/types/channel.d.ts +253 -448
  13. package/dist/types/channel_state.d.ts +48 -95
  14. package/dist/types/client.d.ts +245 -370
  15. package/dist/types/client_state.d.ts +1 -3
  16. package/dist/types/configuration/ConfigController.d.ts +30 -124
  17. package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +31 -123
  18. package/dist/types/configuration/keys.d.ts +5 -19
  19. package/dist/types/configuration/shape.d.ts +12 -29
  20. package/dist/types/configuration/types.d.ts +59 -87
  21. package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +13 -35
  22. package/dist/types/configuration/utils/copyConfigPatch.d.ts +8 -0
  23. package/dist/types/configuration/utils/declarativeSlices.d.ts +5 -16
  24. package/dist/types/configuration/utils/deepFreezeConfig.d.ts +3 -17
  25. package/dist/types/configuration/utils/serverAuthority.d.ts +9 -29
  26. package/dist/types/connection/ConnectionIdManager.d.ts +18 -40
  27. package/dist/types/connection/ConnectionRecoveryManager.d.ts +29 -120
  28. package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +32 -103
  29. package/dist/types/connection/networkConnection/reporters.d.ts +9 -32
  30. package/dist/types/connection/networkConnection/types.d.ts +12 -27
  31. package/dist/types/connection/wsConnection/StableWSConnection.d.ts +37 -116
  32. package/dist/types/connection/wsConnection/WSConnection.d.ts +41 -104
  33. package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +8 -16
  34. package/dist/types/connection/wsConnection/config.d.ts +8 -28
  35. package/dist/types/connection/wsConnection/types.d.ts +17 -70
  36. package/dist/types/entityStore/EntityStore.d.ts +153 -113
  37. package/dist/types/entityStore/StoreBackedItemIndex.d.ts +13 -46
  38. package/dist/types/errors.d.ts +7 -19
  39. package/dist/types/gen/chat/ChannelApi.d.ts +2 -1
  40. package/dist/types/gen/chat/ChatApi.d.ts +28 -14
  41. package/dist/types/gen/models/index.d.ts +769 -86
  42. package/dist/types/gen/moderation/ModerationApi.d.ts +4 -4
  43. package/dist/types/index.d.ts +2 -4
  44. package/dist/types/languageNames.d.ts +9 -24
  45. package/dist/types/logger.d.ts +1 -3
  46. package/dist/types/messageComposer/LocationComposer.d.ts +1 -1
  47. package/dist/types/messageComposer/attachmentIdentity.d.ts +1 -6
  48. package/dist/types/messageComposer/attachmentManager.d.ts +10 -32
  49. package/dist/types/messageComposer/attachmentUtils.d.ts +3 -14
  50. package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
  51. package/dist/types/messageComposer/configuration/types.d.ts +29 -56
  52. package/dist/types/messageComposer/linkPreviewsManager.d.ts +6 -9
  53. package/dist/types/messageComposer/messageComposer.d.ts +30 -164
  54. package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +4 -14
  55. package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +2 -9
  56. package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +2 -4
  57. package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +7 -19
  58. package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +9 -0
  59. package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +11 -18
  60. package/dist/types/messageComposer/middleware/textComposer/textMiddlewareUtils.d.ts +9 -3
  61. package/dist/types/messageComposer/middleware/textComposer/types.d.ts +1 -6
  62. package/dist/types/messageComposer/pollComposer.d.ts +8 -4
  63. package/dist/types/messageComposer/textComposer.d.ts +3 -9
  64. package/dist/types/messageComposer/types.d.ts +5 -8
  65. package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +25 -79
  66. package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +15 -82
  67. package/dist/types/messageOperations/FailedSendCache.d.ts +4 -9
  68. package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +10 -20
  69. package/dist/types/messageOperations/MessageOperations.d.ts +20 -40
  70. package/dist/types/messageOperations/applyReactionLocally.d.ts +5 -22
  71. package/dist/types/messageOperations/createMessageOperations.d.ts +3 -5
  72. package/dist/types/messageOperations/reflectReactionEvent.d.ts +5 -13
  73. package/dist/types/messageOperations/sendOrdering.d.ts +4 -7
  74. package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +7 -15
  75. package/dist/types/messageOperations/types.d.ts +15 -30
  76. package/dist/types/middleware.d.ts +7 -5
  77. package/dist/types/moderation.d.ts +21 -14
  78. package/dist/types/notifications/NotificationManager.d.ts +8 -31
  79. package/dist/types/notifications/types.d.ts +19 -59
  80. package/dist/types/offline-support/offline_support_api.d.ts +145 -539
  81. package/dist/types/offline-support/offline_sync_manager.d.ts +18 -42
  82. package/dist/types/offline-support/queueableOperations.d.ts +24 -52
  83. package/dist/types/offline-support/types.d.ts +24 -187
  84. package/dist/types/pagination/ItemIndex.d.ts +4 -12
  85. package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +13 -0
  86. package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -4
  87. package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +2 -3
  88. package/dist/types/pagination/paginators/BasePaginator.d.ts +235 -622
  89. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +67 -125
  90. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +133 -292
  91. package/dist/types/pagination/paginators/MessagePaginator.d.ts +69 -118
  92. package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +7 -26
  93. package/dist/types/pagination/paginators/ReminderPaginator.d.ts +2 -2
  94. package/dist/types/pagination/paginators/ThreadPaginator.d.ts +15 -23
  95. package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +2 -6
  96. package/dist/types/pagination/sortCompiler.d.ts +11 -22
  97. package/dist/types/pagination/utility.normalization.d.ts +5 -23
  98. package/dist/types/pagination/utility.search.d.ts +3 -8
  99. package/dist/types/poll.d.ts +14 -14
  100. package/dist/types/poll_manager.d.ts +11 -2
  101. package/dist/types/poll_optimistic_votes.d.ts +10 -14
  102. package/dist/types/reminders/Reminder.d.ts +4 -4
  103. package/dist/types/reminders/ReminderManager.d.ts +7 -20
  104. package/dist/types/search/BaseSearchSource.d.ts +7 -12
  105. package/dist/types/search/ChannelSearchSource.d.ts +7 -7
  106. package/dist/types/search/MessageSearchSource.d.ts +7 -9
  107. package/dist/types/search/SearchController.d.ts +17 -22
  108. package/dist/types/search/types.d.ts +6 -10
  109. package/dist/types/signing.d.ts +12 -3
  110. package/dist/types/thread.d.ts +23 -71
  111. package/dist/types/thread_manager.d.ts +45 -70
  112. package/dist/types/token_manager.d.ts +8 -13
  113. package/dist/types/types.d.ts +64 -125
  114. package/dist/types/types.utility.d.ts +3 -3
  115. package/dist/types/upload-utils.d.ts +5 -10
  116. package/dist/types/uploadManager.d.ts +17 -45
  117. package/dist/types/utils/FixedSizeQueueCache.d.ts +6 -11
  118. package/dist/types/utils/WithSubscriptions.d.ts +5 -15
  119. package/dist/types/utils/concurrency.d.ts +11 -19
  120. package/dist/types/utils/mergeWith/mergeWith.d.ts +8 -11
  121. package/dist/types/utils/mergeWith/mergeWithCore.d.ts +5 -13
  122. package/dist/types/utils/mergeWith/mergeWithDiff.d.ts +22 -0
  123. package/dist/types/utils/objectPath.d.ts +6 -41
  124. package/dist/types/utils/retryable.d.ts +8 -12
  125. package/dist/types/utils/throttling/throttle.d.ts +8 -23
  126. package/dist/types/utils/time.d.ts +24 -64
  127. package/dist/types/utils.d.ts +40 -86
  128. package/package.json +7 -2
  129. package/src/ChannelManager.ts +159 -300
  130. package/src/CooldownTimer.ts +11 -29
  131. package/src/EventHandlerPipeline.ts +21 -44
  132. package/src/LiveLocationManager.ts +35 -74
  133. package/src/api-client.ts +43 -61
  134. package/src/campaign.ts +1 -1
  135. package/src/channel.ts +396 -749
  136. package/src/channel_batch_updater.ts +1 -1
  137. package/src/channel_state.ts +50 -105
  138. package/src/client.ts +360 -588
  139. package/src/client_state.ts +1 -6
  140. package/src/configuration/ConfigController.ts +41 -157
  141. package/src/configuration/InstanceConfigurationRegistry.ts +42 -171
  142. package/src/configuration/index.ts +1 -1
  143. package/src/configuration/keys.ts +13 -32
  144. package/src/configuration/shape.ts +67 -70
  145. package/src/configuration/types.ts +60 -100
  146. package/src/configuration/utils/applyInstanceConfiguration.ts +21 -53
  147. package/src/configuration/utils/copyConfigPatch.ts +11 -32
  148. package/src/configuration/utils/declarativeSlices.ts +9 -39
  149. package/src/configuration/utils/deepFreezeConfig.ts +3 -17
  150. package/src/configuration/utils/index.ts +2 -4
  151. package/src/configuration/utils/serverAuthority.ts +20 -68
  152. package/src/connection/ConnectionIdManager.ts +20 -49
  153. package/src/connection/ConnectionRecoveryManager.ts +51 -178
  154. package/src/connection/networkConnection/NetworkConnectionObserver.ts +37 -114
  155. package/src/connection/networkConnection/reporters.ts +9 -36
  156. package/src/connection/networkConnection/types.ts +12 -27
  157. package/src/connection/wsConnection/StableWSConnection.ts +73 -193
  158. package/src/connection/wsConnection/WSConnection.ts +56 -131
  159. package/src/connection/wsConnection/WSConnectionFallback.ts +22 -31
  160. package/src/connection/wsConnection/config.ts +13 -48
  161. package/src/connection/wsConnection/types.ts +17 -70
  162. package/src/constants.ts +4 -4
  163. package/src/entityStore/EntityStore.ts +162 -167
  164. package/src/entityStore/StoreBackedItemIndex.ts +14 -47
  165. package/src/errors.ts +7 -19
  166. package/src/formatMessageMemo.ts +3 -9
  167. package/src/gen/chat/ChannelApi.ts +19 -0
  168. package/src/gen/chat/ChatApi.ts +87 -13
  169. package/src/gen/models/index.ts +793 -71
  170. package/src/gen/moderation/ModerationApi.ts +0 -4
  171. package/src/index.ts +10 -14
  172. package/src/languageNames.ts +9 -24
  173. package/src/logger.ts +1 -3
  174. package/src/messageComposer/LocationComposer.ts +7 -23
  175. package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
  176. package/src/messageComposer/attachmentIdentity.ts +2 -13
  177. package/src/messageComposer/attachmentManager.ts +17 -63
  178. package/src/messageComposer/attachmentUtils.ts +3 -17
  179. package/src/messageComposer/configuration/configuration.ts +5 -8
  180. package/src/messageComposer/configuration/types.ts +29 -56
  181. package/src/messageComposer/fileUtils.ts +1 -1
  182. package/src/messageComposer/linkPreviewsManager.ts +8 -20
  183. package/src/messageComposer/messageComposer.ts +54 -222
  184. package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +4 -16
  185. package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +1 -2
  186. package/src/messageComposer/middleware/messageComposer/attachments.ts +14 -40
  187. package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +3 -4
  188. package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
  189. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +4 -11
  190. package/src/messageComposer/middleware/pollComposer/state.ts +2 -2
  191. package/src/messageComposer/middleware/pollComposer/types.ts +2 -4
  192. package/src/messageComposer/middleware/pollComposer/validation.ts +8 -26
  193. package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +1 -6
  194. package/src/messageComposer/middleware/textComposer/commandUtils.ts +1 -2
  195. package/src/messageComposer/middleware/textComposer/commands.ts +11 -16
  196. package/src/messageComposer/middleware/textComposer/mentions.ts +32 -70
  197. package/src/messageComposer/middleware/textComposer/textMiddlewareUtils.ts +10 -4
  198. package/src/messageComposer/middleware/textComposer/types.ts +1 -6
  199. package/src/messageComposer/pollComposer.ts +11 -8
  200. package/src/messageComposer/textComposer.ts +9 -59
  201. package/src/messageComposer/types.ts +9 -12
  202. package/src/messageDelivery/MessageDeliveryReporter.ts +60 -113
  203. package/src/messageDelivery/MessageReceiptsTracker.ts +21 -105
  204. package/src/messageOperations/FailedSendCache.ts +4 -9
  205. package/src/messageOperations/MessageOperationStatePolicy.ts +40 -67
  206. package/src/messageOperations/MessageOperations.ts +33 -62
  207. package/src/messageOperations/applyReactionLocally.ts +9 -28
  208. package/src/messageOperations/createMessageOperations.ts +17 -33
  209. package/src/messageOperations/reflectReactionEvent.ts +5 -13
  210. package/src/messageOperations/sendOrdering.ts +4 -7
  211. package/src/messageOperations/settlePendingAttachmentUploads.ts +10 -21
  212. package/src/messageOperations/types.ts +15 -30
  213. package/src/middleware.ts +7 -10
  214. package/src/moderation.ts +25 -21
  215. package/src/notifications/NotificationManager.ts +11 -35
  216. package/src/notifications/types.ts +19 -59
  217. package/src/offline-support/offline_support_api.ts +178 -608
  218. package/src/offline-support/offline_sync_manager.ts +25 -69
  219. package/src/offline-support/queueableOperations.ts +31 -84
  220. package/src/offline-support/types.ts +25 -188
  221. package/src/pagination/ItemIndex.ts +4 -12
  222. package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
  223. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +13 -62
  224. package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
  225. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +4 -6
  226. package/src/pagination/filterCompiler.ts +11 -25
  227. package/src/pagination/paginators/BasePaginator.ts +422 -976
  228. package/src/pagination/paginators/ChannelPaginator.ts +130 -190
  229. package/src/pagination/paginators/MessageIntervalPaginator.ts +226 -457
  230. package/src/pagination/paginators/MessagePaginator.ts +135 -175
  231. package/src/pagination/paginators/PinnedMessagePaginator.ts +13 -38
  232. package/src/pagination/paginators/ReminderPaginator.ts +12 -15
  233. package/src/pagination/paginators/ThreadPaginator.ts +16 -26
  234. package/src/pagination/paginators/UserGroupPaginator.ts +6 -17
  235. package/src/pagination/paginators/stateThrottling.ts +5 -10
  236. package/src/pagination/sortCompiler.ts +23 -50
  237. package/src/pagination/utility.normalization.ts +8 -30
  238. package/src/pagination/utility.search.ts +4 -11
  239. package/src/poll.ts +19 -19
  240. package/src/poll_manager.ts +16 -20
  241. package/src/poll_optimistic_votes.ts +17 -22
  242. package/src/reminders/Reminder.ts +5 -6
  243. package/src/reminders/ReminderManager.ts +9 -34
  244. package/src/reminders/ReminderTimer.ts +1 -2
  245. package/src/search/BaseSearchSource.ts +14 -29
  246. package/src/search/ChannelSearchSource.ts +8 -8
  247. package/src/search/MessageSearchSource.ts +19 -25
  248. package/src/search/SearchController.ts +18 -24
  249. package/src/search/types.ts +6 -10
  250. package/src/segment.ts +1 -1
  251. package/src/signing.ts +23 -3
  252. package/src/thread.ts +72 -173
  253. package/src/thread_manager.ts +59 -76
  254. package/src/token_manager.ts +11 -21
  255. package/src/types.ts +78 -126
  256. package/src/types.utility.ts +3 -3
  257. package/src/upload-utils.ts +5 -10
  258. package/src/uploadManager.ts +22 -54
  259. package/src/utils/FixedSizeQueueCache.ts +13 -21
  260. package/src/utils/WithSubscriptions.ts +5 -15
  261. package/src/utils/concurrency.ts +16 -55
  262. package/src/utils/mergeWith/mergeWith.ts +10 -13
  263. package/src/utils/mergeWith/mergeWithCore.ts +24 -81
  264. package/src/utils/mergeWith/mergeWithDiff.ts +15 -33
  265. package/src/utils/objectPath.ts +6 -41
  266. package/src/utils/retryable.ts +10 -14
  267. package/src/utils/throttling/throttle.ts +9 -25
  268. package/src/utils/time.ts +26 -66
  269. package/src/utils.ts +72 -128
@@ -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 (defaults to 1000ms).
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 (the paginator's own index over this store) and/or
82
- * `REGISTERED_HOLDER` (opened this session). A thread leaves once neither holds it.
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 (`master`'s `pagination.isLoading` guard). */
76
+ /** A reload is in flight; a second one is dropped. */
86
77
  private isReloadInFlight = false;
87
78
  /**
88
- * A local `pendingDisposal` listener (a state subscription, not a server watch) per channel instance
89
- * that has had a listed or opened thread; removed when that channel is disposed or on reset.
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
- // a thread keeps its channel, whether listed or opened
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 entering the list gets its channel's disposal listener. Set up here rather than in
118
- // `registerSubscriptions()`, so it doesn't depend on a UI having mounted.
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
- /** Merges a partial configuration into the resolved config and notifies subscribers. */
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
- * Rebuilds the resolved configuration from package defaults plus the declarative slice.
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
- * Routed through {@link updateConfig} rather than replacing the store, which is exact here because
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 (e.g. from a message
155
- * list). Resolve threads through this, not `paginator.items`, which is the list only; 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 it if it doesn't exist yet. Use this to open a
162
- * thread instead of calling `new Thread()`.
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
- * The returned thread is registered right away. If the thread list loads it before the UI
165
- * activates it, the list reuses this instance instead of creating a duplicate.
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
- * Every registered thread — the list's plus the opened ones.
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
- * Called by `thread.activate()`. Keeps `thread` for the session: it resolves through
200
- * {@link ThreadManager.get} and stays subscribed whether or not the list holds it, until its
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 on `thread`; the list's own diff unsubscribes it if it is still listed. */
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
- * Hands client events to the threads in the store by id, as `PollManager` does for polls: a thread
299
- * doesn't listen to the client itself. A message event goes to the thread the message is a reply
300
- * in and the thread it starts; quoted-message updates stay within the reply's own thread, as on
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 wasn't opened. Asks for `REGISTERED_HOLDER`, not `threadStore.get`: `removeItem`
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. Guarded only against another reload, as on `master`. A reload of a loaded list shows
464
- * no loading state; the first load shows through `paginator.isLoading`.
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;
@@ -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 the static string token or token provider. A token provider should return a token string
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 returns one.
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
- * Resets the token manager.
64
- * Useful for client disconnection or switching user.
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
- // allow empty token for anon user
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
- // Resolves when token is ready. This function is simply to check if loadToken is in progress, in which
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 a token from tokenProvider function and sets in tokenManager.
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;