stream-chat 10.0.0-rc.2 → 10.0.0-rc.21

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 (298) hide show
  1. package/README.md +11 -8
  2. package/dist/cjs/index.browser.js +15397 -12090
  3. package/dist/cjs/index.browser.js.map +4 -4
  4. package/dist/cjs/index.node.js +15349 -11991
  5. package/dist/cjs/index.node.js.map +4 -4
  6. package/dist/esm/index.mjs +15164 -11880
  7. package/dist/esm/index.mjs.map +4 -4
  8. package/dist/types/ChannelManager.d.ts +246 -6
  9. package/dist/types/CooldownTimer.d.ts +22 -8
  10. package/dist/types/EventHandlerPipeline.d.ts +12 -16
  11. package/dist/types/LiveLocationManager.d.ts +69 -6
  12. package/dist/types/api-client.d.ts +22 -9
  13. package/dist/types/channel.d.ts +550 -300
  14. package/dist/types/channel_state.d.ts +167 -22
  15. package/dist/types/client.d.ts +325 -305
  16. package/dist/types/configuration/ConfigController.d.ts +172 -0
  17. package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +192 -0
  18. package/dist/types/configuration/index.d.ts +3 -0
  19. package/dist/types/configuration/keys.d.ts +31 -0
  20. package/dist/types/configuration/shape.d.ts +58 -0
  21. package/dist/types/configuration/types.d.ts +206 -50
  22. package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +59 -0
  23. package/dist/types/configuration/utils/copyConfigPatch.d.ts +1 -0
  24. package/dist/types/configuration/utils/declarativeSlices.d.ts +24 -0
  25. package/dist/types/configuration/utils/deepFreezeConfig.d.ts +22 -0
  26. package/dist/types/configuration/utils/index.d.ts +1 -0
  27. package/dist/types/configuration/utils/serverAuthority.d.ts +49 -0
  28. package/dist/types/connection/ConnectionIdManager.d.ts +67 -0
  29. package/dist/types/connection/ConnectionRecoveryManager.d.ts +164 -0
  30. package/dist/types/connection/index.d.ts +4 -0
  31. package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +153 -0
  32. package/dist/types/connection/networkConnection/index.d.ts +3 -0
  33. package/dist/types/connection/networkConnection/reporters.d.ts +43 -0
  34. package/dist/types/connection/networkConnection/types.d.ts +55 -0
  35. package/dist/types/connection/wsConnection/StableWSConnection.d.ts +204 -0
  36. package/dist/types/connection/wsConnection/WSConnection.d.ts +168 -0
  37. package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +55 -0
  38. package/dist/types/connection/wsConnection/config.d.ts +51 -0
  39. package/dist/types/connection/wsConnection/index.d.ts +4 -0
  40. package/dist/types/connection/wsConnection/types.d.ts +99 -0
  41. package/dist/types/constants.d.ts +3 -1
  42. package/dist/types/entityStore/EntityStore.d.ts +160 -40
  43. package/dist/types/entityStore/StoreBackedItemIndex.d.ts +48 -29
  44. package/dist/types/entityStore/index.d.ts +0 -1
  45. package/dist/types/errors.d.ts +24 -4
  46. package/dist/types/formatMessageMemo.d.ts +5 -0
  47. package/dist/types/gen/chat/ChannelApi.d.ts +51 -23
  48. package/dist/types/gen/chat/ChatApi.d.ts +215 -168
  49. package/dist/types/gen/models/index.d.ts +2164 -557
  50. package/dist/types/gen/models/timestamp-guard.d.ts +22 -0
  51. package/dist/types/gen/moderation/ModerationApi.d.ts +39 -32
  52. package/dist/types/gen-imports.d.ts +1 -0
  53. package/dist/types/index.d.ts +20 -7
  54. package/dist/types/languageNames.d.ts +97 -0
  55. package/dist/types/logger.d.ts +1 -1
  56. package/dist/types/messageComposer/CustomDataManager.d.ts +7 -1
  57. package/dist/types/messageComposer/LocationComposer.d.ts +10 -4
  58. package/dist/types/messageComposer/attachmentIdentity.d.ts +11 -0
  59. package/dist/types/messageComposer/attachmentManager.d.ts +48 -10
  60. package/dist/types/messageComposer/attachmentUtils.d.ts +34 -0
  61. package/dist/types/messageComposer/configuration/commands.configuration.d.ts +1 -3
  62. package/dist/types/messageComposer/configuration/configuration.d.ts +9 -1
  63. package/dist/types/messageComposer/configuration/index.d.ts +0 -1
  64. package/dist/types/messageComposer/configuration/types.d.ts +57 -1
  65. package/dist/types/messageComposer/index.d.ts +1 -0
  66. package/dist/types/messageComposer/linkPreviewsManager.d.ts +10 -4
  67. package/dist/types/messageComposer/messageComposer.d.ts +210 -14
  68. package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +20 -1
  69. package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +11 -0
  70. package/dist/types/messageComposer/middleware/messageComposer/types.d.ts +2 -2
  71. package/dist/types/messageComposer/middleware/pollComposer/index.d.ts +1 -0
  72. package/dist/types/messageComposer/middleware/pollComposer/state.d.ts +3 -2
  73. package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +9 -2
  74. package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +44 -0
  75. package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +2 -2
  76. package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +94 -229
  77. package/dist/types/messageComposer/pollComposer.d.ts +8 -3
  78. package/dist/types/messageComposer/textComposer.d.ts +9 -1
  79. package/dist/types/messageComposer/types.d.ts +7 -3
  80. package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +64 -8
  81. package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +48 -11
  82. package/dist/types/messageOperations/FailedSendCache.d.ts +34 -0
  83. package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +52 -6
  84. package/dist/types/messageOperations/MessageOperations.d.ts +94 -11
  85. package/dist/types/{entityStore → messageOperations}/applyReactionLocally.d.ts +8 -2
  86. package/dist/types/messageOperations/createMessageOperations.d.ts +11 -0
  87. package/dist/types/messageOperations/index.d.ts +7 -1
  88. package/dist/types/messageOperations/reflectReactionEvent.d.ts +24 -0
  89. package/dist/types/messageOperations/sendOrdering.d.ts +17 -0
  90. package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +28 -0
  91. package/dist/types/messageOperations/types.d.ts +66 -1
  92. package/dist/types/middleware.d.ts +8 -0
  93. package/dist/types/moderation.d.ts +18 -4
  94. package/dist/types/notifications/NotificationManager.d.ts +43 -2
  95. package/dist/types/notifications/types.d.ts +55 -42
  96. package/dist/types/offline-support/offline_support_api.d.ts +128 -12
  97. package/dist/types/offline-support/offline_sync_manager.d.ts +26 -5
  98. package/dist/types/offline-support/queueableOperations.d.ts +106 -0
  99. package/dist/types/offline-support/types.d.ts +77 -28
  100. package/dist/types/pagination/FilterBuilder.d.ts +1 -18
  101. package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -1
  102. package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +21 -3
  103. package/dist/types/pagination/filterCompiler.d.ts +5 -0
  104. package/dist/types/pagination/paginators/BasePaginator.d.ts +331 -7
  105. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +54 -11
  106. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +283 -66
  107. package/dist/types/pagination/paginators/MessagePaginator.d.ts +10 -9
  108. package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +17 -1
  109. package/dist/types/pagination/paginators/ReminderPaginator.d.ts +8 -8
  110. package/dist/types/pagination/paginators/ThreadPaginator.d.ts +57 -0
  111. package/dist/types/pagination/paginators/index.d.ts +1 -0
  112. package/dist/types/pagination/utility.normalization.d.ts +29 -2
  113. package/dist/types/poll.d.ts +41 -14
  114. package/dist/types/poll_manager.d.ts +3 -2
  115. package/dist/types/poll_optimistic_votes.d.ts +61 -0
  116. package/dist/types/reminders/Reminder.d.ts +17 -7
  117. package/dist/types/reminders/ReminderManager.d.ts +34 -6
  118. package/dist/types/search/BaseSearchSource.d.ts +50 -25
  119. package/dist/types/search/ChannelMemberSearchSource.d.ts +11 -6
  120. package/dist/types/search/ChannelSearchSource.d.ts +27 -5
  121. package/dist/types/search/MessageSearchSource.d.ts +36 -6
  122. package/dist/types/search/SearchController.d.ts +44 -11
  123. package/dist/types/search/UserSearchSource.d.ts +11 -5
  124. package/dist/types/search/types.d.ts +14 -1
  125. package/dist/types/signing.d.ts +0 -157
  126. package/dist/types/thread.d.ts +118 -62
  127. package/dist/types/thread_manager.d.ts +124 -35
  128. package/dist/types/token_manager.d.ts +5 -8
  129. package/dist/types/types.d.ts +138 -562
  130. package/dist/types/types.utility.d.ts +8 -0
  131. package/dist/types/upload-utils.d.ts +20 -0
  132. package/dist/types/uploadManager.d.ts +50 -2
  133. package/dist/types/utils/FixedSizeQueueCache.d.ts +2 -0
  134. package/dist/types/utils/WithSubscriptions.d.ts +1 -1
  135. package/dist/types/utils/objectPath.d.ts +49 -0
  136. package/dist/types/utils/time.d.ts +85 -0
  137. package/dist/types/utils.d.ts +63 -40
  138. package/package.json +22 -33
  139. package/src/ChannelManager.ts +561 -109
  140. package/src/CooldownTimer.ts +55 -45
  141. package/src/EventHandlerPipeline.ts +13 -23
  142. package/src/LiveLocationManager.ts +191 -37
  143. package/src/api-client.ts +144 -53
  144. package/src/channel.ts +1573 -1050
  145. package/src/channel_state.ts +239 -129
  146. package/src/client.ts +843 -892
  147. package/src/client_state.ts +2 -2
  148. package/src/configuration/ConfigController.ts +298 -0
  149. package/src/configuration/InstanceConfigurationRegistry.ts +430 -0
  150. package/src/configuration/index.ts +7 -0
  151. package/src/configuration/keys.ts +86 -0
  152. package/src/configuration/shape.ts +776 -0
  153. package/src/configuration/types.ts +218 -60
  154. package/src/configuration/utils/applyInstanceConfiguration.ts +184 -0
  155. package/src/configuration/utils/copyConfigPatch.ts +61 -0
  156. package/src/configuration/utils/declarativeSlices.ts +81 -0
  157. package/src/configuration/utils/deepFreezeConfig.ts +33 -0
  158. package/src/configuration/utils/index.ts +5 -0
  159. package/src/configuration/utils/serverAuthority.ts +146 -0
  160. package/src/connection/ConnectionIdManager.ts +153 -0
  161. package/src/connection/ConnectionRecoveryManager.ts +371 -0
  162. package/src/connection/index.ts +4 -0
  163. package/src/connection/networkConnection/NetworkConnectionObserver.ts +281 -0
  164. package/src/connection/networkConnection/index.ts +3 -0
  165. package/src/connection/networkConnection/reporters.ts +85 -0
  166. package/src/connection/networkConnection/types.ts +60 -0
  167. package/src/{connection.ts → connection/wsConnection/StableWSConnection.ts} +242 -151
  168. package/src/connection/wsConnection/WSConnection.ts +345 -0
  169. package/src/connection/wsConnection/WSConnectionFallback.ts +259 -0
  170. package/src/connection/wsConnection/config.ts +108 -0
  171. package/src/connection/wsConnection/index.ts +4 -0
  172. package/src/connection/wsConnection/types.ts +101 -0
  173. package/src/constants.ts +5 -3
  174. package/src/entityStore/EntityStore.ts +350 -10
  175. package/src/entityStore/StoreBackedItemIndex.ts +66 -37
  176. package/src/entityStore/index.ts +0 -1
  177. package/src/errors.ts +40 -7
  178. package/src/formatMessageMemo.ts +23 -0
  179. package/src/gen/chat/ChannelApi.ts +230 -44
  180. package/src/gen/chat/ChatApi.ts +1047 -1745
  181. package/src/gen/models/index.ts +2378 -3721
  182. package/src/gen/models/timestamp-guard.ts +27 -0
  183. package/src/gen/moderation/ModerationApi.ts +218 -388
  184. package/src/gen-imports.ts +1 -0
  185. package/src/index.ts +82 -6
  186. package/src/languageNames.ts +103 -0
  187. package/src/logger.ts +1 -1
  188. package/src/messageComposer/CustomDataManager.ts +10 -1
  189. package/src/messageComposer/LocationComposer.ts +68 -20
  190. package/src/messageComposer/attachmentIdentity.ts +39 -0
  191. package/src/messageComposer/attachmentManager.ts +191 -68
  192. package/src/messageComposer/attachmentUtils.ts +58 -0
  193. package/src/messageComposer/configuration/commands.configuration.ts +1 -26
  194. package/src/messageComposer/configuration/configuration.ts +22 -3
  195. package/src/messageComposer/configuration/index.ts +0 -1
  196. package/src/messageComposer/configuration/types.ts +58 -1
  197. package/src/messageComposer/index.ts +1 -0
  198. package/src/messageComposer/linkPreviewsManager.ts +16 -10
  199. package/src/messageComposer/messageComposer.ts +487 -98
  200. package/src/messageComposer/middleware/attachmentManager/postUpload/AttachmentPostUploadMiddlewareExecutor.ts +1 -1
  201. package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +58 -33
  202. package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +7 -2
  203. package/src/messageComposer/middleware/attachmentManager/preUpload/blockedUploadNotification.ts +3 -2
  204. package/src/messageComposer/middleware/messageComposer/attachments.ts +98 -1
  205. package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +20 -10
  206. package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +7 -2
  207. package/src/messageComposer/middleware/messageComposer/types.ts +2 -7
  208. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +11 -6
  209. package/src/messageComposer/middleware/pollComposer/index.ts +1 -0
  210. package/src/messageComposer/middleware/pollComposer/state.ts +43 -11
  211. package/src/messageComposer/middleware/pollComposer/types.ts +9 -2
  212. package/src/messageComposer/middleware/pollComposer/validation.ts +76 -0
  213. package/src/messageComposer/middleware/textComposer/commandUtils.ts +3 -2
  214. package/src/messageComposer/middleware/textComposer/commands.ts +1 -2
  215. package/src/messageComposer/middleware/textComposer/mentions.ts +91 -39
  216. package/src/messageComposer/pollComposer.ts +11 -3
  217. package/src/messageComposer/textComposer.ts +36 -4
  218. package/src/messageComposer/types.ts +19 -14
  219. package/src/messageDelivery/MessageDeliveryReporter.ts +154 -53
  220. package/src/messageDelivery/MessageReceiptsTracker.ts +136 -64
  221. package/src/messageOperations/FailedSendCache.ts +90 -0
  222. package/src/messageOperations/MessageOperationStatePolicy.ts +269 -27
  223. package/src/messageOperations/MessageOperations.ts +340 -136
  224. package/src/{entityStore → messageOperations}/applyReactionLocally.ts +10 -3
  225. package/src/messageOperations/createMessageOperations.ts +192 -0
  226. package/src/messageOperations/index.ts +7 -0
  227. package/src/messageOperations/reflectReactionEvent.ts +51 -0
  228. package/src/messageOperations/sendOrdering.ts +28 -0
  229. package/src/messageOperations/settlePendingAttachmentUploads.ts +110 -0
  230. package/src/messageOperations/types.ts +74 -0
  231. package/src/middleware.ts +11 -0
  232. package/src/moderation.ts +47 -24
  233. package/src/notifications/NotificationManager.ts +73 -3
  234. package/src/notifications/configuration.ts +10 -8
  235. package/src/notifications/types.ts +58 -42
  236. package/src/offline-support/offline_support_api.ts +380 -197
  237. package/src/offline-support/offline_sync_manager.ts +105 -32
  238. package/src/offline-support/queueableOperations.ts +270 -0
  239. package/src/offline-support/types.ts +85 -39
  240. package/src/pagination/FilterBuilder.ts +1 -22
  241. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +11 -7
  242. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +25 -7
  243. package/src/pagination/filterCompiler.ts +17 -0
  244. package/src/pagination/paginators/BasePaginator.ts +731 -81
  245. package/src/pagination/paginators/ChannelPaginator.ts +210 -102
  246. package/src/pagination/paginators/MessageIntervalPaginator.ts +703 -193
  247. package/src/pagination/paginators/MessagePaginator.ts +45 -36
  248. package/src/pagination/paginators/PinnedMessagePaginator.ts +74 -28
  249. package/src/pagination/paginators/ReminderPaginator.ts +15 -13
  250. package/src/pagination/paginators/ThreadPaginator.ts +181 -0
  251. package/src/pagination/paginators/UserGroupPaginator.ts +8 -1
  252. package/src/pagination/paginators/index.ts +1 -0
  253. package/src/pagination/utility.normalization.ts +37 -9
  254. package/src/poll.ts +189 -112
  255. package/src/poll_manager.ts +14 -8
  256. package/src/poll_optimistic_votes.ts +335 -0
  257. package/src/reminders/Reminder.ts +34 -16
  258. package/src/reminders/ReminderManager.ts +68 -41
  259. package/src/reminders/ReminderTimer.ts +7 -6
  260. package/src/search/BaseSearchSource.ts +133 -40
  261. package/src/search/ChannelMemberSearchSource.ts +27 -18
  262. package/src/search/ChannelSearchSource.ts +61 -7
  263. package/src/search/MessageSearchSource.ts +133 -28
  264. package/src/search/SearchController.ts +93 -16
  265. package/src/search/UserSearchSource.ts +27 -13
  266. package/src/search/types.ts +14 -1
  267. package/src/signing.ts +1 -315
  268. package/src/thread.ts +503 -511
  269. package/src/thread_manager.ts +339 -204
  270. package/src/token_manager.ts +12 -32
  271. package/src/types.ts +159 -780
  272. package/src/types.utility.ts +14 -0
  273. package/src/upload-utils.ts +53 -0
  274. package/src/uploadManager.ts +85 -7
  275. package/src/utils/FixedSizeQueueCache.ts +5 -0
  276. package/src/utils/WithSubscriptions.ts +1 -1
  277. package/src/utils/objectPath.ts +67 -0
  278. package/src/utils/time.ts +104 -0
  279. package/src/utils.ts +209 -157
  280. package/dist/types/base64.d.ts +0 -2
  281. package/dist/types/configuration/InstanceConfigurationService.d.ts +0 -26
  282. package/dist/types/connection.d.ts +0 -146
  283. package/dist/types/connection_fallback.d.ts +0 -42
  284. package/dist/types/gen/model-decoders/decoders.d.ts +0 -3
  285. package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +0 -6
  286. package/dist/types/insights.d.ts +0 -58
  287. package/dist/types/pagination/utility.queryChannel.d.ts +0 -26
  288. package/dist/types/permissions.d.ts +0 -55
  289. package/dist/types/store.d.ts +0 -125
  290. package/src/base64.ts +0 -78
  291. package/src/configuration/InstanceConfigurationService.ts +0 -73
  292. package/src/connection_fallback.ts +0 -215
  293. package/src/gen/model-decoders/decoders.ts +0 -2680
  294. package/src/gen/model-decoders/event-decoder-mapping.ts +0 -198
  295. package/src/insights.ts +0 -83
  296. package/src/pagination/utility.queryChannel.ts +0 -84
  297. package/src/permissions.ts +0 -102
  298. package/src/store.ts +0 -304
@@ -14,24 +14,25 @@ import { chatLoggerSystem } from '../../logger';
14
14
  import type { FilterBuilderOptions } from '../FilterBuilder';
15
15
  import { FilterBuilder } from '../FilterBuilder';
16
16
  import { makeComparator } from '../sortCompiler';
17
- import { itemMatchesFilter } from '../filterCompiler';
17
+ import { filterConstrainsField, itemMatchesFilter } from '../filterCompiler';
18
18
  import { StoreBackedItemIndex } from '../../entityStore/StoreBackedItemIndex';
19
+ import type { EntityStore } from '../../entityStore/EntityStore';
19
20
  import { generateUUIDv4 } from '../../utils';
20
21
  import type { StreamChat } from '../../client';
21
22
  import type { Channel } from '../../channel';
22
23
  import type {
23
24
  ChannelFilters,
24
25
  ChannelOptions,
25
- ChannelSort,
26
26
  ChannelStateOptions,
27
27
  ParsedPredefinedFilterResponse,
28
28
  QueryChannelsRequest,
29
+ SortParamRequest,
29
30
  } from '../../types';
30
31
  import type { FieldToDataResolver, PathResolver } from '../types.normalization';
31
32
  import { resolveDotPathValue } from '../utility.normalization';
32
33
  import { isEqual } from '../../utils/mergeWith/mergeWithCore';
33
34
 
34
- const DEFAULT_BACKEND_SORT: ChannelSort = [
35
+ const DEFAULT_BACKEND_SORT: SortParamRequest[] = [
35
36
  { direction: -1, field: 'last_message_at' },
36
37
  { direction: -1, field: 'updated_at' },
37
38
  ];
@@ -57,7 +58,7 @@ export type ChannelPaginatorRequestOptions = Partial<
57
58
 
58
59
  export type ChannelSortComparatorFactoryParams = {
59
60
  /** Sort the comparator is being built for — the effective sort, so a backend-resolved sort template. */
60
- sort: ChannelSort;
61
+ sort: SortParamRequest[];
61
62
  /**
62
63
  * The comparator `ChannelPaginator` would use for this sort. Delegate to it for the fields you do not
63
64
  * want to handle yourself instead of reimplementing channel field resolution and the cid tiebreaker.
@@ -82,8 +83,15 @@ export type ChannelPaginatorOptions = {
82
83
  id?: string;
83
84
  paginatorOptions?: PaginatorOptions<Channel, ChannelQueryShape>;
84
85
  requestOptions?: ChannelPaginatorRequestOptions;
85
- sort?: ChannelSort;
86
+ sort?: SortParamRequest[];
86
87
  sortComparatorFactory?: ChannelSortComparatorFactory;
88
+ /**
89
+ * The channel store the list's index holds its channels in. Defaults to `client.channelManager`'s
90
+ * store, so every list shares one instance per cid and keeps the channels it lists stored.
91
+ *
92
+ * @internal
93
+ */
94
+ store?: EntityStore<Channel>;
87
95
  };
88
96
 
89
97
  /**
@@ -110,13 +118,19 @@ const hasPaginationQueryShapeChanged: PaginationQueryShapeChangeIdentifier<
110
118
 
111
119
  const archivedFilterResolver: FieldToDataResolver<Channel> = {
112
120
  matchesField: (field) => field === 'archived',
113
- resolve: (channel) => !!channel.state.membership.archived_at,
121
+ resolve: (channel) => channel.state.membership.archived_at != null,
114
122
  };
115
123
 
116
- const appBannedFilterResolver: FieldToDataResolver<Channel> = {
124
+ // The resolvers that need the current user or the client's mute list read them from the list's own
125
+ // client, not through `channel.getClient()`: that throws once the channel is disposed (to stop requests
126
+ // for it), and a disposed channel must still sort and filter, so that a list can locate it to drop it.
127
+
128
+ const createAppBannedFilterResolver = (
129
+ client: StreamChat,
130
+ ): FieldToDataResolver<Channel> => ({
117
131
  matchesField: (field) => field === 'app_banned',
118
132
  resolve: (channel) => {
119
- const ownUserId = channel.getClient().user?.id;
133
+ const ownUserId = client.userId;
120
134
  const otherMembers = Object.values(channel.state.members).filter(
121
135
  ({ user }) => user?.id !== ownUserId,
122
136
  );
@@ -125,19 +139,21 @@ const appBannedFilterResolver: FieldToDataResolver<Channel> = {
125
139
  const otherMember = otherMembers[0];
126
140
  return otherMember.user?.banned ? 'only' : 'excluded';
127
141
  },
128
- };
142
+ });
129
143
 
130
- const hasUnreadFilterResolver: FieldToDataResolver<Channel> = {
144
+ const createHasUnreadFilterResolver = (
145
+ client: StreamChat,
146
+ ): FieldToDataResolver<Channel> => ({
131
147
  matchesField: (field) => field === 'has_unread',
132
148
  resolve: (channel) => {
133
- const ownUserId = channel.getClient().user?.id;
149
+ const ownUserId = client.userId;
134
150
  return (
135
151
  ownUserId &&
136
152
  channel.state.read[ownUserId] &&
137
153
  channel.state.read[ownUserId].unread_messages > 0
138
154
  );
139
155
  },
140
- };
156
+ });
141
157
 
142
158
  const hiddenFilterResolver: FieldToDataResolver<Channel> = {
143
159
  matchesField: (field) => field === 'hidden',
@@ -150,11 +166,11 @@ const hiddenFilterResolver: FieldToDataResolver<Channel> = {
150
166
  const lastUpdatedFilterResolver: FieldToDataResolver<Channel> = {
151
167
  matchesField: (field) => field === 'last_updated',
152
168
  resolve: (channel) => {
153
- // combination of last_message_at and updated_at
154
- const lastMessageAt = channel.messagePaginator.lastMessageAt?.getTime() ?? null;
155
- const updatedAt = channel.data?.updated_at
156
- ? new Date(channel.data?.updated_at).getTime()
157
- : undefined;
169
+ // combination of last_message_at and updated_at — both already wire timestamps, so they are
170
+ // directly comparable. Deriving one of them through `new Date(...).getTime()` would put the two
171
+ // in different units and make `updated_at` win every comparison.
172
+ const lastMessageAt = channel.messagePaginator.lastMessageAt ?? null;
173
+ const updatedAt = channel.data?.updated_at;
158
174
  return lastMessageAt !== null && updatedAt !== undefined
159
175
  ? Math.max(lastMessageAt, updatedAt)
160
176
  : (lastMessageAt ?? updatedAt);
@@ -163,15 +179,22 @@ const lastUpdatedFilterResolver: FieldToDataResolver<Channel> = {
163
179
 
164
180
  const membersFilterResolver: FieldToDataResolver<Channel> = {
165
181
  matchesField: (field) => field === 'members',
166
- resolve: (channel) =>
167
- channel.state.members
182
+ resolve: (channel) => {
183
+ const ids = channel.state.members
168
184
  ? Object.values(channel.state.members).reduce<string[]>((ids, member) => {
169
185
  if (member.user?.id) {
170
186
  ids.push(member.user?.id);
171
187
  }
172
188
  return ids;
173
189
  }, [])
174
- : [],
190
+ : [];
191
+ // Only a page of a large channel's members may be loaded, but the current user's membership is
192
+ // always there, so `members: { $in: [ownId] }` holds even when they aren't in that page.
193
+ const { membership } = channel.state;
194
+ const ownId = membership?.user?.id ?? membership?.user_id;
195
+ if (ownId && !ids.includes(ownId)) ids.push(ownId);
196
+ return ids;
197
+ },
175
198
  };
176
199
 
177
200
  const memberUserNameFilterResolver: FieldToDataResolver<Channel> = {
@@ -189,47 +212,64 @@ const memberUserNameFilterResolver: FieldToDataResolver<Channel> = {
189
212
 
190
213
  const pinnedFilterResolver: FieldToDataResolver<Channel> = {
191
214
  matchesField: (field) => field === 'pinned',
192
- resolve: (channel) => !!channel.state.membership.pinned_at,
215
+ resolve: (channel) => channel.state.membership.pinned_at != null,
193
216
  };
194
217
 
195
- const mutedFilterResolver: FieldToDataResolver<Channel> = {
218
+ const createMutedFilterResolver = (client: StreamChat): FieldToDataResolver<Channel> => ({
196
219
  matchesField: (field) => field === 'muted',
197
220
  // UserMuteResponse state lives on the client (client.mutedChannels), not on channel.data — resolve it via
198
221
  // the client so `{ muted: true/false }` matches client-side, rather than letting the generic
199
222
  // data resolver read a non-existent `channel.data.muted` (which would resolve to undefined and
200
223
  // never equal a boolean filter value).
201
- resolve: (channel) => channel.getClient()._muteStatus(channel.cid).muted,
224
+ resolve: (channel) => client._muteStatus(channel.cid).muted,
225
+ });
226
+
227
+ /**
228
+ * A channel field by path: from `channel.data`, or, for a field it doesn't have, from
229
+ * `channel.data.custom`, where a channel response keeps `name` and the app's custom fields. So
230
+ * `{ name: … }` and `{ color: … }` match what `{ 'custom.name': … }` and `{ 'custom.color': … }` do.
231
+ *
232
+ * `type`, `id` and `cid` come from the instance, which has them from construction, while
233
+ * `channel.data` has them only after a query: a stored channel an event reaches before its first
234
+ * query (such as one a thread created) must still match `{ type: … }`.
235
+ */
236
+ const resolveChannelDataValue = (channel: Channel, path: string) => {
237
+ if (path === 'type' || path === 'id' || path === 'cid') return channel[path];
238
+ const value = resolveDotPathValue(channel.data, path);
239
+ return value !== undefined ? value : resolveDotPathValue(channel.data?.custom, path);
202
240
  };
203
241
 
204
242
  const dataFieldFilterResolver: FieldToDataResolver<Channel> = {
205
243
  matchesField: () => true,
206
- resolve: (channel, path) => resolveDotPathValue(channel.data, path),
244
+ resolve: resolveChannelDataValue,
207
245
  };
208
246
 
209
247
  // very, very unfortunately channel data is dispersed btw Channel.data and Channel.state
210
- const channelSortPathResolver: PathResolver<Channel> = (channel, path) => {
211
- switch (path) {
212
- case 'last_message_at':
213
- return channel.messagePaginator.lastMessageAt;
214
- case 'has_unread': {
215
- return hasUnreadFilterResolver.resolve(channel, path);
216
- }
217
- case 'last_updated': {
218
- return lastUpdatedFilterResolver.resolve(channel, path) ?? 0;
219
- }
220
- case 'pinned_at':
221
- return channel.state.membership.pinned_at;
222
- case 'unread_count': {
223
- const userId = channel.getClient().user?.id;
224
- return userId ? channel.state.read[userId].unread_messages : 0;
248
+ const createChannelSortPathResolver = (client: StreamChat): PathResolver<Channel> => {
249
+ const hasUnreadResolver = createHasUnreadFilterResolver(client);
250
+ return (channel, path) => {
251
+ switch (path) {
252
+ case 'last_message_at':
253
+ return channel.messagePaginator.lastMessageAt;
254
+ case 'has_unread': {
255
+ return hasUnreadResolver.resolve(channel, path);
256
+ }
257
+ case 'last_updated': {
258
+ return lastUpdatedFilterResolver.resolve(channel, path) ?? 0;
259
+ }
260
+ case 'pinned_at':
261
+ return channel.state.membership.pinned_at;
262
+ case 'unread_count': {
263
+ const userId = client.userId;
264
+ // a channel without a read entry for the user has nothing unread
265
+ return userId ? (channel.state.read[userId]?.unread_messages ?? 0) : 0;
266
+ }
267
+ default:
268
+ return resolveChannelDataValue(channel, path);
225
269
  }
226
- default:
227
- return resolveDotPathValue(channel.data, path);
228
- }
270
+ };
229
271
  };
230
272
 
231
- // todo: maybe items could be just an array of {cid: string} and the data would be retrieved from client.activeChannels
232
- // todo: maybe we should introduce client._cache.channels that would be reactive and orchestrator would subscribe to client._cache.channels state to keep all the dependent state in sync
233
273
  /**
234
274
  * A paginated channel list. Filters are described along three independent axes — the names follow them:
235
275
  *
@@ -253,7 +293,7 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
253
293
  private readonly _id: string;
254
294
  private client: StreamChat;
255
295
  protected _staticFilters: ChannelFilters | undefined;
256
- protected _sort: ChannelSort | undefined;
296
+ protected _sort: SortParamRequest[] | undefined;
257
297
  protected _options: ChannelPaginatorRequestOptions | undefined;
258
298
  protected _channelStateOptions: ChannelStateOptions | undefined;
259
299
  protected _nextQueryShape: ChannelQueryShape | undefined;
@@ -264,6 +304,15 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
264
304
  * `postQueryReconcile` decides whether it should be committed (first page only).
265
305
  */
266
306
  private _pendingPredefinedFilter: ParsedPredefinedFilterResponse | undefined;
307
+ /**
308
+ * True while the loaded items came ONLY from the offline cache - seeded by `setItems`, never
309
+ * confirmed by a query. Such a state has no pagination position worth continuing from, so the seed
310
+ * records `offset = <cache size>` and a query shape, which is what makes the next query look like a
311
+ * continuation rather than a first page. See `executeQuery`.
312
+ */
313
+ private _itemsLoadedFromOfflineDB = false;
314
+ /** The query in flight refreshes a cache-only window, so its response replaces the window. */
315
+ private _replaceOfflineSeedOnResponse = false;
267
316
  protected _sortComparatorFactory: ChannelSortComparatorFactory | undefined;
268
317
  sortComparator: (a: Channel, b: Channel) => number;
269
318
  filterBuilder: FilterBuilder<ChannelFilters>;
@@ -278,16 +327,22 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
278
327
  requestOptions,
279
328
  sort,
280
329
  sortComparatorFactory,
330
+ store,
281
331
  }: ChannelPaginatorOptions) {
282
332
  super({
283
333
  hasPaginationQueryShapeChanged,
284
- itemIndex: new StoreBackedItemIndex<Channel>({
285
- getEntityId: (channel) => channel.cid,
286
- }),
334
+ // the index is this list's holder in the store: a channel stays stored while the list lists it
335
+ createItemIndex: (owner) =>
336
+ new StoreBackedItemIndex<Channel>({
337
+ getEntityId: (channel) => channel.cid,
338
+ holderName: 'channel-paginator',
339
+ owner: owner as ChannelPaginator,
340
+ store: store ?? client.channelManager?.channelStore,
341
+ }),
287
342
  retryCount: DEFAULT_QUERY_CHANNELS_RETRY_COUNT,
288
343
  ...paginatorOptions,
289
344
  });
290
- const definedSort = sort ?? DEFAULT_BACKEND_SORT;
345
+ const definedSort = sort?.length ? sort : DEFAULT_BACKEND_SORT;
291
346
  this.client = client;
292
347
  this._id = id ?? `channel-paginator-${generateUUIDv4()}`;
293
348
  this._sort = definedSort;
@@ -299,12 +354,12 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
299
354
  this.sortComparator = this.buildSortComparator(definedSort);
300
355
  this.setFilterResolvers([
301
356
  archivedFilterResolver,
302
- appBannedFilterResolver,
303
- hasUnreadFilterResolver,
357
+ createAppBannedFilterResolver(client),
358
+ createHasUnreadFilterResolver(client),
304
359
  hiddenFilterResolver,
305
360
  lastUpdatedFilterResolver,
306
361
  pinnedFilterResolver,
307
- mutedFilterResolver,
362
+ createMutedFilterResolver(client),
308
363
  membersFilterResolver,
309
364
  memberUserNameFilterResolver,
310
365
  dataFieldFilterResolver,
@@ -322,10 +377,10 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
322
377
  * supply `sortComparatorFactory` (it is consulted on every rebuild and may delegate to
323
378
  * `defaultComparator`), or override this method in a subclass.
324
379
  */
325
- protected buildSortComparator(sort: ChannelSort) {
380
+ protected buildSortComparator(sort: SortParamRequest[]) {
326
381
  const defaultComparator = makeComparator<Channel>({
327
382
  sort,
328
- resolvePathValue: channelSortPathResolver,
383
+ resolvePathValue: createChannelSortPathResolver(this.client),
329
384
  tiebreaker: (l, r) => {
330
385
  const leftId = this.getItemId(l);
331
386
  const rightId = this.getItemId(r);
@@ -350,8 +405,8 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
350
405
  return this._staticFilters;
351
406
  }
352
407
 
353
- get sort(): ChannelSort {
354
- return this._sort ?? DEFAULT_BACKEND_SORT;
408
+ get sort(): SortParamRequest[] {
409
+ return this._sort?.length ? this._sort : DEFAULT_BACKEND_SORT;
355
410
  }
356
411
 
357
412
  /**
@@ -380,8 +435,8 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
380
435
  * backend-resolved predefined filter takes precedence over the requested sort, matching backend
381
436
  * precedence rules.
382
437
  */
383
- get effectiveSort(): ChannelSort {
384
- return (this._predefinedFilter?.sort as ChannelSort | undefined) ?? this.sort;
438
+ get effectiveSort(): SortParamRequest[] {
439
+ return (this._predefinedFilter?.sort as SortParamRequest[] | undefined) ?? this.sort;
385
440
  }
386
441
 
387
442
  get options(): ChannelOptions | undefined {
@@ -396,7 +451,7 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
396
451
  this._staticFilters = filters;
397
452
  }
398
453
 
399
- set sort(sort: ChannelSort | undefined) {
454
+ set sort(sort: SortParamRequest[] | undefined) {
400
455
  this._sort = sort;
401
456
  this.sortComparator = this.buildSortComparator(this.effectiveSort);
402
457
  }
@@ -452,32 +507,12 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
452
507
  matchesFilter(channel: Channel): boolean {
453
508
  const filters = this.buildMatchFilters();
454
509
 
455
- const LOGICAL_FILTER_OPERATORS = ['$and', '$or', '$nor'] as const;
456
-
457
- /**
458
- * Whether a filter constrains `hidden` anywhere — at the top level or nested inside a logical
459
- * operator, both of which the filter compiler evaluates. A filter that mentions `hidden` at all opts
460
- * out of the "exclude hidden channels" default (see `ChannelPaginator.matchesFilter`), so
461
- * `{ $or: [{ hidden: true }, …] }` is not silently overruled by it.
462
- *
463
- * Recursion is limited to logical operators on purpose: a `hidden` key anywhere else (e.g. inside
464
- * `{ custom: { hidden: … } }`) is a different field, not a constraint on the channel's hidden state.
465
- */
466
- const filterConstrainsHidden = (filters: unknown): boolean => {
467
- if (!filters || typeof filters !== 'object') return false;
468
- if (Array.isArray(filters)) return filters.some(filterConstrainsHidden);
469
- const node = filters as Record<string, unknown>;
470
- if ('hidden' in node) return true;
471
- return LOGICAL_FILTER_OPERATORS.some((operator) =>
472
- filterConstrainsHidden(node[operator]),
473
- );
474
- };
475
510
  // Mirror `queryChannels`, which excludes hidden channels unless the filter asks for them —
476
511
  // otherwise a channel hidden while the list is open keeps matching and stays visible until the next
477
512
  // query. Applied here rather than as a synthetic `hidden: false` filter entry so the default also
478
513
  // holds for a paginator whose filter resolvers were replaced (`setFilterResolvers`), which would
479
514
  // otherwise leave `hidden` unresolvable and reject every channel.
480
- if (channel.data?.hidden && !filterConstrainsHidden(filters)) return false;
515
+ if (channel.data?.hidden && !filterConstrainsField(filters, 'hidden')) return false;
481
516
  return itemMatchesFilter<Channel>(channel, filters, {
482
517
  resolvers: this._filterFieldToDataResolvers,
483
518
  });
@@ -509,15 +544,26 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
509
544
  if (params.isFirstPage && params.results) {
510
545
  this.applyPredefinedFilterResponse(pendingPredefinedFilter);
511
546
  }
547
+ const replaceOfflineSeed = this._replaceOfflineSeedOnResponse;
548
+ this._replaceOfflineSeedOnResponse = false;
549
+ if (replaceOfflineSeed && params.results) {
550
+ // The cache can be arbitrarily old, so merging into it is out of question as it might keep channels
551
+ // the server no longer returns (hidden, deleted, left). The seed stays on screen until now, then the
552
+ // page replaces it.
553
+ this.clearItemStorage();
554
+ return super.postQueryReconcile({ ...params, keepPreviousItems: false });
555
+ }
512
556
  return super.postQueryReconcile(params);
513
557
  }
514
558
 
515
559
  // invoked inside BasePaginator.executeQuery() to keep it as a query descriptor;
516
- protected getNextQueryShape(): ChannelQueryShape {
560
+ protected getNextQueryShape({
561
+ pageSize,
562
+ }: { pageSize?: number } = {}): ChannelQueryShape {
517
563
  const shape: ChannelQueryShape = {
518
564
  filter_conditions: this.buildQueryFilters(),
519
565
  ...this.options,
520
- limit: this.pageSize,
566
+ limit: pageSize ?? this.pageSize,
521
567
  offset: this.offset,
522
568
  };
523
569
 
@@ -547,6 +593,11 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
547
593
  * `predefined_filter` / `filter_values` / `sort_values` appear, without which two predefined-filter
548
594
  * lists cannot be told apart. The duplication goes away once `convertFilterSortToQuery` derives the
549
595
  * key from `options` (a change in that implementation plus a schema-version bump to flush stale rows).
596
+ *
597
+ * The resolved `predefinedFilter` rides along with the order it produced: a cache-seeded list has no
598
+ * response to learn it from, and without it `effectiveFilters` / `effectiveSort` fall back to the
599
+ * local filters and the default sort - i.e. it would match and order by a different rule than the
600
+ * one the cached order came from.
550
601
  */
551
602
  protected cacheCidsForQuery({
552
603
  cids,
@@ -558,9 +609,10 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
558
609
  this.client.offlineDb?.executeQuerySafely(
559
610
  (db) =>
560
611
  db.upsertCidsForQuery({
561
- cids,
612
+ cids: cids.slice(0, this.pageSize),
562
613
  filters: request.filter_conditions,
563
614
  options: request,
615
+ predefinedFilter: this._predefinedFilter,
564
616
  sort: request.sort,
565
617
  }),
566
618
  { method: 'upsertCidsForQuery' },
@@ -573,10 +625,14 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
573
625
  * running; skipping those would leave the cached order stale until the next full re-query.
574
626
  */
575
627
  protected persistLoadedCids() {
576
- if (!this.client.offlineDb) return;
628
+ // Without a connected user the list is being emptied by `disconnectUser()`: what stays in the
629
+ // offline DB is the app's call (`resetDB()`), so nothing is written.
630
+ if (!this.client.offlineDb || !this.client.userId) return;
577
631
 
578
632
  this.cacheCidsForQuery({
579
- cids: (this.items ?? []).map((channel) => channel.cid),
633
+ cids: (this.items ?? [])
634
+ .filter((channel) => !channel.isProvisional)
635
+ .map((channel) => channel.cid),
580
636
  request: this.loadedQueryRequest,
581
637
  });
582
638
  }
@@ -594,13 +650,16 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
594
650
  const { stateOptions: _, ...request } = queryShape;
595
651
 
596
652
  try {
597
- const channelsFromDB = await this.client.offlineDb.getChannelsForQuery({
653
+ const cachedQuery = await this.client.offlineDb.getChannelsForQuery({
598
654
  userId: this.client.user.id,
599
655
  options: request,
600
656
  });
601
657
 
602
- if (channelsFromDB) {
603
- return this.client.hydrateActiveChannels(channelsFromDB, {
658
+ if (cachedQuery) {
659
+ if (cachedQuery.predefinedFilter) {
660
+ this.applyPredefinedFilterResponse(cachedQuery.predefinedFilter);
661
+ }
662
+ return this.client.hydrateChannels(cachedQuery.channels, {
604
663
  offlineMode: true,
605
664
  skipInitialization: [], // passing empty array will clear out the existing messages from channel state, this removes the possibility of duplicate messages
606
665
  });
@@ -640,18 +699,26 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
640
699
  */
641
700
  async executeQuery(params: PaginationQueryParams<ChannelQueryShape> = {}) {
642
701
  const { offlineDb } = this.client;
643
- const queryShape = params.queryShape ?? this.getNextQueryShape();
702
+
703
+ const effectiveParams: PaginationQueryParams<ChannelQueryShape> =
704
+ this._itemsLoadedFromOfflineDB && params.reset !== 'yes'
705
+ ? { ...params, keepPreviousItems: true, reset: 'yes' as const }
706
+ : params;
707
+
708
+ const queryShape = effectiveParams.queryShape ?? this.getNextQueryShape();
644
709
  const shouldDeferUntilSynced =
645
710
  !!offlineDb?.getChannelsForQuery &&
646
711
  !!this.client.user?.id &&
647
- !offlineDb.syncManager.syncStatus &&
648
- this.isFirstPageQuery({ queryShape, reset: params.reset });
712
+ !offlineDb.syncManager.isSynced &&
713
+ // Items seeded from the cache are not an already loaded list, so paginating them has to defer too.
714
+ (this._itemsLoadedFromOfflineDB ||
715
+ this.isFirstPageQuery({ queryShape, reset: effectiveParams.reset }));
649
716
 
650
- if (!shouldDeferUntilSynced) return await super.executeQuery(params);
717
+ if (!shouldDeferUntilSynced) return await super.executeQuery(effectiveParams);
651
718
 
652
719
  if (!this.isInitialized) {
653
720
  const cachedChannels = await this.preloadFirstPageFromOfflineDb({
654
- ...params,
721
+ ...effectiveParams,
655
722
  queryShape,
656
723
  });
657
724
  if (cachedChannels?.length) {
@@ -661,30 +728,35 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
661
728
  // running. This all happens so fast it should never be noticeable but it's
662
729
  // a microoptimization.
663
730
  this.setItems({ valueOrFactory: cachedChannels, isFirstPage: true });
731
+ this._itemsLoadedFromOfflineDB = true;
664
732
  }
665
733
  // Nothing is in flight while we wait for the sync; leaving `isLoading` true would make
666
734
  // `canExecuteQuery` reject the query scheduled below.
667
735
  this.state.partialNext({ isLoading: false });
668
736
  }
669
737
 
738
+ const refreshParams: PaginationQueryParams<ChannelQueryShape> = {
739
+ ...effectiveParams,
740
+ keepPreviousItems: true,
741
+ ...(this._itemsLoadedFromOfflineDB ? { reset: 'yes' as const } : {}),
742
+ };
743
+
670
744
  // Check if everything is synced up already and if so, just run the actual queryChannels request.
671
745
  // Otherwise, the sync status change will never fire and so `executeQuery` will never really be
672
746
  // run.
673
- if (offlineDb.syncManager.syncStatus) {
674
- return await super.executeQuery({ ...params, keepPreviousItems: true });
747
+ if (offlineDb.syncManager.isSynced) {
748
+ return await super.executeQuery(refreshParams);
675
749
  }
676
750
 
677
- // When the sync completes, run the real query — but as a NON-DESTRUCTIVE refresh
678
- // (`keepPreviousItems`) so the channels we already surfaced from the offline DB stay visible while it
679
- // runs. Without this the re-run goes through the first-page reset path and re-preloads from the DB;
680
- // if the sync invalidated the offline query cache (i.e. a channel changed while the app was closed),
681
- // that re-preload returns nothing and the list blanks to a second skeleton before the fresh page lands.
682
751
  offlineDb.syncManager.scheduleSyncStatusChangeCallback(this.id, async () => {
683
- await this.executeQuery({ ...params, keepPreviousItems: true });
752
+ await this.executeQuery(refreshParams);
684
753
  });
685
754
  }
686
755
 
687
756
  query = async (): Promise<PaginationQueryReturnValue<Channel>> => {
757
+ if (this._itemsLoadedFromOfflineDB) this._replaceOfflineSeedOnResponse = true;
758
+ // A query is going out, so whatever it returns the items are no longer cache-only.
759
+ this._itemsLoadedFromOfflineDB = false;
688
760
  // get the params only if they were not generated previously
689
761
  if (!this._nextQueryShape) {
690
762
  this._nextQueryShape = this.getNextQueryShape();
@@ -713,12 +785,48 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
713
785
  this.persistLoadedCids();
714
786
  }
715
787
 
716
- ingestItem(channel: Channel): boolean {
788
+ /**
789
+ * Places `channel` in the list if it matches, or drops it if it no longer does. A provisional
790
+ * channel (created from members, still without an id) is refused: it is stored under a temporary
791
+ * cid until its first query gives it the real one, and a list holding it would keep the temporary
792
+ * cid. It is listed once it has its id, as the channels in a server page always do. Another
793
+ * instance for a stored cid (a superseded one, or one made with `new Channel()`) is replaced by
794
+ * the stored instance (see `ChannelManager.resolveListedChannel`).
795
+ */
796
+ ingestItem(input: Channel): boolean {
797
+ if (input.isProvisional) return false;
798
+ // the stored instance, never another one for the same cid (see `resolveListedChannel`)
799
+ const channel = this.client.channelManager.resolveListedChannel(input);
800
+ if (!channel) return false;
717
801
  const changed = super.ingestItem(channel);
802
+ // a channel that left the result set is no longer listed, so the list stops holding it
803
+ if (!this.matchesFilter(channel)) this._itemIndex.remove(channel.cid);
718
804
  if (changed) this.persistLoadedCids();
719
805
  return changed;
720
806
  }
721
807
 
808
+ /**
809
+ * Entity-store subscriber (as the owner of its index). A channel publishes its own changes through
810
+ * `channel.state`, so the list has nothing to re-project when the store reports a change.
811
+ */
812
+ onEntitiesChanged(): void {
813
+ return;
814
+ }
815
+
816
+ /**
817
+ * Entity-store subscriber: the store removed a channel this list holds (a known end, logout), so
818
+ * the list drops it from its windows.
819
+ */
820
+ onEntityRemoved(id: string, channel: unknown): void {
821
+ this.removeItem({ id, item: channel as Channel });
822
+ }
823
+
824
+ resetState() {
825
+ super.resetState();
826
+ // nothing is listed anymore, so the list holds no channels
827
+ this._itemIndex.clear();
828
+ }
829
+
722
830
  removeItem(params: { id?: string; item?: Channel }): ItemCoordinates {
723
831
  const coordinates = super.removeItem(params);
724
832
  if ((coordinates.state?.currentIndex ?? -1) > -1 || coordinates.interval) {