stream-chat 10.0.0-rc.9 → 10.0.1
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/README.md +7 -6
- package/dist/cjs/index.browser.js +21653 -19788
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +21693 -19796
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +21651 -19786
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelManager.d.ts +216 -135
- package/dist/types/CooldownTimer.d.ts +13 -27
- package/dist/types/EventHandlerPipeline.d.ts +18 -38
- package/dist/types/LiveLocationManager.d.ts +24 -52
- package/dist/types/api-client.d.ts +17 -5
- package/dist/types/channel.d.ts +432 -470
- package/dist/types/channel_state.d.ts +68 -112
- package/dist/types/client.d.ts +321 -435
- package/dist/types/client_state.d.ts +1 -3
- package/dist/types/configuration/ConfigController.d.ts +31 -125
- package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +32 -124
- 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 +64 -79
- package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +14 -36
- 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 +45 -0
- package/dist/types/connection/ConnectionRecoveryManager.d.ts +84 -0
- package/dist/types/connection/index.d.ts +4 -0
- package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +82 -0
- package/dist/types/connection/networkConnection/index.d.ts +3 -0
- package/dist/types/connection/networkConnection/reporters.d.ts +20 -0
- package/dist/types/connection/networkConnection/types.d.ts +40 -0
- package/dist/types/connection/wsConnection/StableWSConnection.d.ts +137 -0
- package/dist/types/connection/wsConnection/WSConnection.d.ts +105 -0
- package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +47 -0
- package/dist/types/connection/wsConnection/config.d.ts +31 -0
- package/dist/types/connection/wsConnection/index.d.ts +4 -0
- package/dist/types/connection/wsConnection/types.d.ts +46 -0
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/custom_types.d.ts +0 -2
- package/dist/types/entityStore/EntityStore.d.ts +226 -65
- package/dist/types/entityStore/StoreBackedItemIndex.d.ts +19 -33
- package/dist/types/entityStore/index.d.ts +0 -1
- package/dist/types/errors.d.ts +16 -19
- package/dist/types/formatMessageMemo.d.ts +5 -0
- package/dist/types/gen/chat/ChannelApi.d.ts +5 -1
- package/dist/types/gen/chat/ChatApi.d.ts +149 -105
- package/dist/types/gen/models/index.d.ts +2528 -690
- package/dist/types/gen/models/timestamp-guard.d.ts +22 -0
- package/dist/types/gen/moderation/ModerationApi.d.ts +33 -14
- package/dist/types/index.d.ts +10 -6
- package/dist/types/{i18n/languageNames.d.ts → languageNames.d.ts} +9 -24
- package/dist/types/logger.d.ts +1 -3
- package/dist/types/messageComposer/CustomDataManager.d.ts +7 -1
- package/dist/types/messageComposer/LocationComposer.d.ts +7 -1
- package/dist/types/messageComposer/attachmentIdentity.d.ts +24 -0
- package/dist/types/messageComposer/attachmentManager.d.ts +52 -24
- package/dist/types/messageComposer/attachmentUtils.d.ts +23 -0
- package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
- package/dist/types/messageComposer/configuration/types.d.ts +38 -50
- package/dist/types/messageComposer/index.d.ts +1 -0
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +12 -9
- package/dist/types/messageComposer/messageComposer.d.ts +60 -128
- package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +10 -1
- package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +4 -0
- package/dist/types/messageComposer/middleware/messageComposer/commandInjection.d.ts +5 -0
- package/dist/types/messageComposer/middleware/messageComposer/index.d.ts +2 -0
- package/dist/types/messageComposer/middleware/messageComposer/pollOnly.d.ts +6 -0
- package/dist/types/messageComposer/middleware/messageComposer/userDataInjection.d.ts +5 -0
- 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/commandUtils.d.ts +4 -0
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +11 -2
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +19 -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 +15 -5
- package/dist/types/messageComposer/textComposer.d.ts +14 -7
- package/dist/types/messageComposer/types.d.ts +27 -7
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +27 -80
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +40 -73
- package/dist/types/messageOperations/FailedSendCache.d.ts +29 -0
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +16 -22
- package/dist/types/messageOperations/MessageOperations.d.ts +63 -34
- package/dist/types/messageOperations/applyReactionLocally.d.ts +15 -0
- package/dist/types/messageOperations/createMessageOperations.d.ts +9 -0
- package/dist/types/messageOperations/index.d.ts +6 -4
- package/dist/types/messageOperations/reflectReactionEvent.d.ts +16 -0
- package/dist/types/messageOperations/sendOrdering.d.ts +14 -0
- package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +20 -0
- package/dist/types/messageOperations/types.d.ts +43 -14
- package/dist/types/middleware.d.ts +10 -0
- package/dist/types/moderation.d.ts +21 -14
- package/dist/types/notifications/NotificationManager.d.ts +10 -23
- package/dist/types/notifications/types.d.ts +21 -57
- package/dist/types/offline-support/offline_support_api.d.ts +150 -528
- package/dist/types/offline-support/offline_sync_manager.d.ts +21 -42
- package/dist/types/offline-support/queueableOperations.d.ts +35 -37
- package/dist/types/offline-support/types.d.ts +40 -186
- package/dist/types/pagination/FilterBuilder.d.ts +1 -18
- 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 +4 -5
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +19 -5
- package/dist/types/pagination/index.d.ts +1 -0
- package/dist/types/pagination/paginators/BasePaginator.d.ts +604 -550
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +123 -106
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +576 -334
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +239 -131
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +15 -26
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +4 -3
- package/dist/types/pagination/paginators/ThreadPaginator.d.ts +44 -0
- package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +5 -8
- package/dist/types/pagination/paginators/index.d.ts +1 -0
- 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 +34 -8
- package/dist/types/poll_manager.d.ts +12 -2
- package/dist/types/poll_optimistic_votes.d.ts +57 -0
- package/dist/types/reminders/Reminder.d.ts +11 -11
- package/dist/types/reminders/ReminderManager.d.ts +13 -25
- package/dist/types/search/BaseSearchSource.d.ts +10 -8
- package/dist/types/search/ChannelSearchSource.d.ts +16 -0
- package/dist/types/search/MessageSearchSource.d.ts +17 -0
- package/dist/types/search/SearchController.d.ts +26 -28
- package/dist/types/search/types.d.ts +6 -10
- package/dist/types/signing.d.ts +12 -3
- package/dist/types/thread.d.ts +63 -129
- package/dist/types/thread_manager.d.ts +95 -66
- package/dist/types/token_manager.d.ts +8 -13
- package/dist/types/types.d.ts +81 -199
- package/dist/types/types.utility.d.ts +3 -3
- package/dist/types/upload-utils.d.ts +5 -10
- package/dist/types/uploadManager.d.ts +31 -11
- package/dist/types/utils/FixedSizeQueueCache.d.ts +8 -11
- package/dist/types/utils/WithSubscriptions.d.ts +6 -16
- package/dist/types/utils/abort.d.ts +17 -0
- package/dist/types/utils/concurrency.d.ts +12 -20
- 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 +33 -57
- package/dist/types/utils.d.ts +72 -91
- package/package.json +14 -40
- package/src/ChannelManager.ts +494 -303
- package/src/CooldownTimer.ts +28 -38
- package/src/EventHandlerPipeline.ts +22 -45
- package/src/LiveLocationManager.ts +37 -76
- package/src/api-client.ts +113 -50
- package/src/campaign.ts +1 -1
- package/src/channel.ts +1067 -1276
- package/src/channel_batch_updater.ts +1 -1
- package/src/channel_state.ts +73 -168
- package/src/client.ts +744 -974
- package/src/client_state.ts +3 -8
- package/src/configuration/ConfigController.ts +42 -158
- package/src/configuration/InstanceConfigurationRegistry.ts +43 -172
- package/src/configuration/index.ts +1 -1
- package/src/configuration/keys.ts +13 -32
- package/src/configuration/shape.ts +169 -59
- package/src/configuration/types.ts +69 -92
- package/src/configuration/utils/applyInstanceConfiguration.ts +22 -54
- 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 +111 -0
- package/src/connection/ConnectionRecoveryManager.ts +257 -0
- package/src/connection/index.ts +4 -0
- package/src/connection/networkConnection/NetworkConnectionObserver.ts +204 -0
- package/src/connection/networkConnection/index.ts +3 -0
- package/src/connection/networkConnection/reporters.ts +58 -0
- package/src/connection/networkConnection/types.ts +45 -0
- package/src/{connection.ts → connection/wsConnection/StableWSConnection.ts} +230 -232
- package/src/connection/wsConnection/WSConnection.ts +270 -0
- package/src/connection/wsConnection/WSConnectionFallback.ts +250 -0
- package/src/connection/wsConnection/config.ts +73 -0
- package/src/connection/wsConnection/index.ts +4 -0
- package/src/connection/wsConnection/types.ts +48 -0
- package/src/constants.ts +6 -5
- package/src/custom_types.ts +0 -1
- package/src/entityStore/EntityStore.ts +415 -79
- package/src/entityStore/StoreBackedItemIndex.ts +37 -41
- package/src/entityStore/index.ts +0 -1
- package/src/errors.ts +39 -20
- package/src/formatMessageMemo.ts +17 -0
- package/src/gen/chat/ChannelApi.ts +122 -36
- package/src/gen/chat/ChatApi.ts +578 -1540
- package/src/gen/models/index.ts +2498 -3383
- package/src/gen/models/timestamp-guard.ts +27 -0
- package/src/gen/moderation/ModerationApi.ts +170 -367
- package/src/index.ts +22 -10
- package/src/languageNames.ts +88 -0
- package/src/logger.ts +1 -3
- package/src/messageComposer/CustomDataManager.ts +19 -6
- package/src/messageComposer/LocationComposer.ts +19 -23
- package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
- package/src/messageComposer/attachmentIdentity.ts +54 -0
- package/src/messageComposer/attachmentManager.ts +170 -185
- package/src/messageComposer/attachmentUtils.ts +44 -0
- package/src/messageComposer/configuration/configuration.ts +15 -8
- package/src/messageComposer/configuration/types.ts +38 -50
- package/src/messageComposer/fileUtils.ts +1 -1
- package/src/messageComposer/index.ts +1 -0
- package/src/messageComposer/linkPreviewsManager.ts +18 -21
- package/src/messageComposer/messageComposer.ts +223 -174
- package/src/messageComposer/middleware/attachmentManager/postUpload/AttachmentPostUploadMiddlewareExecutor.ts +1 -1
- package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +46 -33
- package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +4 -1
- package/src/messageComposer/middleware/attachmentManager/preUpload/blockedUploadNotification.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/MessageComposerMiddlewareExecutor.ts +6 -0
- package/src/messageComposer/middleware/messageComposer/attachments.ts +76 -5
- package/src/messageComposer/middleware/messageComposer/commandInjection.ts +10 -4
- package/src/messageComposer/middleware/messageComposer/customData.ts +17 -5
- package/src/messageComposer/middleware/messageComposer/index.ts +2 -0
- package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +22 -12
- package/src/messageComposer/middleware/messageComposer/pollOnly.ts +9 -1
- package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +12 -12
- 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 +8 -6
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +10 -3
- 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 +21 -9
- package/src/messageComposer/textComposer.ts +37 -57
- package/src/messageComposer/types.ts +39 -11
- package/src/messageDelivery/MessageDeliveryReporter.ts +86 -125
- package/src/messageDelivery/MessageReceiptsTracker.ts +88 -101
- package/src/messageOperations/FailedSendCache.ts +85 -0
- package/src/messageOperations/MessageOperationStatePolicy.ts +121 -112
- package/src/messageOperations/MessageOperations.ts +297 -175
- package/src/{entityStore → messageOperations}/applyReactionLocally.ts +9 -28
- package/src/messageOperations/createMessageOperations.ts +176 -0
- package/src/messageOperations/index.ts +6 -14
- package/src/messageOperations/reflectReactionEvent.ts +43 -0
- package/src/messageOperations/sendOrdering.ts +25 -0
- package/src/messageOperations/settlePendingAttachmentUploads.ts +98 -0
- package/src/messageOperations/types.ts +51 -13
- package/src/middleware.ts +13 -5
- package/src/moderation.ts +25 -21
- package/src/notifications/NotificationManager.ts +19 -28
- package/src/notifications/types.ts +21 -57
- package/src/offline-support/offline_support_api.ts +226 -669
- package/src/offline-support/offline_sync_manager.ts +51 -80
- package/src/offline-support/queueableOperations.ts +98 -73
- package/src/offline-support/types.ts +43 -186
- package/src/pagination/FilterBuilder.ts +1 -22
- package/src/pagination/ItemIndex.ts +4 -12
- package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +15 -63
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +53 -33
- package/src/pagination/filterCompiler.ts +11 -25
- package/src/pagination/index.ts +1 -0
- package/src/pagination/paginators/BasePaginator.ts +1415 -1041
- package/src/pagination/paginators/ChannelPaginator.ts +479 -217
- package/src/pagination/paginators/MessageIntervalPaginator.ts +1351 -772
- package/src/pagination/paginators/MessagePaginator.ts +518 -233
- package/src/pagination/paginators/PinnedMessagePaginator.ts +32 -40
- package/src/pagination/paginators/ReminderPaginator.ts +21 -16
- package/src/pagination/paginators/ThreadPaginator.ts +170 -0
- package/src/pagination/paginators/UserGroupPaginator.ts +16 -19
- package/src/pagination/paginators/index.ts +1 -0
- 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 +177 -98
- package/src/poll_manager.ts +24 -22
- package/src/poll_optimistic_votes.ts +335 -0
- package/src/reminders/Reminder.ts +16 -12
- package/src/reminders/ReminderManager.ts +22 -55
- package/src/reminders/ReminderTimer.ts +1 -2
- package/src/search/BaseSearchSource.ts +19 -25
- package/src/search/ChannelSearchSource.ts +43 -1
- package/src/search/MessageSearchSource.ts +77 -13
- package/src/search/SearchController.ts +39 -36
- package/src/search/types.ts +6 -10
- package/src/segment.ts +1 -1
- package/src/signing.ts +23 -3
- package/src/thread.ts +418 -703
- package/src/thread_manager.ts +300 -234
- package/src/token_manager.ts +12 -22
- package/src/types.ts +102 -216
- package/src/types.utility.ts +3 -3
- package/src/upload-utils.ts +5 -10
- package/src/uploadManager.ts +64 -18
- package/src/utils/FixedSizeQueueCache.ts +18 -21
- package/src/utils/WithSubscriptions.ts +6 -16
- package/src/utils/abort.ts +45 -0
- 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 +40 -60
- package/src/utils.ts +181 -174
- package/codegen/i18n/callSites.ts +0 -126
- package/codegen/i18n/generate.ts +0 -226
- package/codegen/i18n/guards.ts +0 -178
- package/codegen/i18n/index.ts +0 -29
- package/codegen/i18n/stringMaps.ts +0 -91
- package/codegen/i18n/types.ts +0 -100
- package/dist/cjs/i18n.browser.js +0 -1131
- package/dist/cjs/i18n.browser.js.map +0 -7
- package/dist/cjs/i18n.node.js +0 -1160
- package/dist/cjs/i18n.node.js.map +0 -7
- package/dist/esm/i18n-codegen.mjs +0 -409
- package/dist/esm/i18n-codegen.mjs.map +0 -7
- package/dist/esm/i18n.mjs +0 -1098
- package/dist/esm/i18n.mjs.map +0 -7
- package/dist/types/ConnectionRecoveryManager.d.ts +0 -156
- package/dist/types/connection.d.ts +0 -139
- package/dist/types/entityStore/applyReactionLocally.d.ts +0 -32
- package/dist/types/i18n/Streami18n.d.ts +0 -168
- package/dist/types/i18n/TranslationBuilder.d.ts +0 -70
- package/dist/types/i18n/TranslationStore.d.ts +0 -57
- package/dist/types/i18n/dayjs.d.ts +0 -104
- package/dist/types/i18n/formatters.d.ts +0 -91
- package/dist/types/i18n/index.d.ts +0 -15
- package/dist/types/i18n/translator.d.ts +0 -29
- package/dist/types/i18n/types.d.ts +0 -262
- package/dist/types/i18n-codegen/callSites.d.ts +0 -10
- package/dist/types/i18n-codegen/generate.d.ts +0 -15
- package/dist/types/i18n-codegen/guards.d.ts +0 -61
- package/dist/types/i18n-codegen/index.d.ts +0 -29
- package/dist/types/i18n-codegen/stringMaps.d.ts +0 -14
- package/dist/types/i18n-codegen/types.d.ts +0 -94
- package/dist/types/insights.d.ts +0 -56
- package/dist/types/messageOperations/optimistic.d.ts +0 -118
- package/dist/types/messageOperations/persistence.d.ts +0 -21
- package/dist/types/pagination/utility.queryChannel.d.ts +0 -26
- package/dist/types/store.d.ts +0 -125
- package/src/ConnectionRecoveryManager.ts +0 -293
- package/src/i18n/Streami18n.ts +0 -520
- package/src/i18n/TranslationBuilder.ts +0 -176
- package/src/i18n/TranslationStore.ts +0 -96
- package/src/i18n/dayjs.ts +0 -228
- package/src/i18n/formatters.ts +0 -461
- package/src/i18n/index.ts +0 -15
- package/src/i18n/languageNames.ts +0 -103
- package/src/i18n/translator.ts +0 -76
- package/src/i18n/types.ts +0 -375
- package/src/insights.ts +0 -82
- package/src/messageOperations/optimistic.ts +0 -257
- package/src/messageOperations/persistence.ts +0 -40
- package/src/pagination/utility.queryChannel.ts +0 -84
- package/src/store.ts +0 -304
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
AnyInterval,
|
|
2
3
|
ItemCoordinates,
|
|
3
4
|
PaginationQueryParams,
|
|
4
5
|
PaginationQueryReturnValue,
|
|
5
6
|
PaginationQueryShapeChangeIdentifier,
|
|
6
7
|
PaginatorOptions,
|
|
7
8
|
PaginatorState,
|
|
8
|
-
|
|
9
|
+
PlaceQueryPageParams,
|
|
9
10
|
SetPaginatorItemsParams,
|
|
10
11
|
} from './BasePaginator';
|
|
11
12
|
import { BasePaginator } from './BasePaginator';
|
|
@@ -16,7 +17,8 @@ import { FilterBuilder } from '../FilterBuilder';
|
|
|
16
17
|
import { makeComparator } from '../sortCompiler';
|
|
17
18
|
import { filterConstrainsField, itemMatchesFilter } from '../filterCompiler';
|
|
18
19
|
import { StoreBackedItemIndex } from '../../entityStore/StoreBackedItemIndex';
|
|
19
|
-
import {
|
|
20
|
+
import type { EntityStore } from '../../entityStore/EntityStore';
|
|
21
|
+
import { generateUUIDv4, runDetached } from '../../utils';
|
|
20
22
|
import type { StreamChat } from '../../client';
|
|
21
23
|
import type { Channel } from '../../channel';
|
|
22
24
|
import type {
|
|
@@ -31,44 +33,54 @@ import type { FieldToDataResolver, PathResolver } from '../types.normalization';
|
|
|
31
33
|
import { resolveDotPathValue } from '../utility.normalization';
|
|
32
34
|
import { isEqual } from '../../utils/mergeWith/mergeWithCore';
|
|
33
35
|
|
|
36
|
+
const hasSameItems = (current: Channel[] | undefined, next: Channel[] | undefined) => {
|
|
37
|
+
if (current === next) return false;
|
|
38
|
+
if (!current || !next || current.length !== next.length) return false;
|
|
39
|
+
for (let i = 0; i < next.length; i++) if (current[i] !== next[i]) return false;
|
|
40
|
+
return true;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The most loaded channels a reconnect re-queries (`recoverLoadedItems`). Those loaded past it are
|
|
45
|
+
* kept as they are, unverified.
|
|
46
|
+
*/
|
|
47
|
+
const MAX_RECOVERED_ITEMS = 150;
|
|
48
|
+
|
|
34
49
|
const DEFAULT_BACKEND_SORT: SortParamRequest[] = [
|
|
35
50
|
{ direction: -1, field: 'last_message_at' },
|
|
36
51
|
{ direction: -1, field: 'updated_at' },
|
|
37
52
|
];
|
|
38
53
|
|
|
39
54
|
/**
|
|
40
|
-
* The `queryChannels` request this paginator
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* rather than a `{ filters, sort, options }` wrapper: the same object goes on the wire, keys the
|
|
44
|
-
* offline-db cache and is compared for query-shape changes, so any field mapping in between would be a
|
|
45
|
-
* place for those three to drift apart. `MessageQueryShape` is likewise the request params themselves.
|
|
55
|
+
* The `queryChannels` request this paginator sends, plus the client-only `stateOptions`. It is the
|
|
56
|
+
* request's own shape because the same object goes on the wire, keys the offline-db cache and is
|
|
57
|
+
* compared for query-shape changes.
|
|
46
58
|
*/
|
|
47
59
|
export type ChannelQueryShape = QueryChannelsRequest & {
|
|
48
|
-
/** Not part of the request
|
|
60
|
+
/** Not part of the request: controls how the response is applied to client state. */
|
|
49
61
|
stateOptions?: ChannelStateOptions;
|
|
50
62
|
};
|
|
51
63
|
|
|
52
64
|
export type ChannelPaginatorState = PaginatorState<Channel>;
|
|
53
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Request options sent with every page query (`state`, `watch`, `presence`, `message_limit`, ...).
|
|
68
|
+
* `limit` and `offset` belong to the paginator: set the page size with `paginatorOptions.pageSize`.
|
|
69
|
+
*/
|
|
54
70
|
export type ChannelPaginatorRequestOptions = Partial<
|
|
55
71
|
Omit<ChannelOptions, 'offset' | 'limit'>
|
|
56
72
|
>;
|
|
57
73
|
|
|
58
74
|
export type ChannelSortComparatorFactoryParams = {
|
|
59
|
-
/**
|
|
75
|
+
/** The effective sort the comparator is built for (a backend-resolved template, if any). */
|
|
60
76
|
sort: SortParamRequest[];
|
|
61
|
-
/**
|
|
62
|
-
* The comparator `ChannelPaginator` would use for this sort. Delegate to it for the fields you do not
|
|
63
|
-
* want to handle yourself instead of reimplementing channel field resolution and the cid tiebreaker.
|
|
64
|
-
*/
|
|
77
|
+
/** The comparator `ChannelPaginator` would use: delegate to it for the fields you do not handle. */
|
|
65
78
|
defaultComparator: (a: Channel, b: Channel) => number;
|
|
66
79
|
};
|
|
67
80
|
|
|
68
81
|
/**
|
|
69
|
-
* Produces the comparator that orders
|
|
70
|
-
*
|
|
71
|
-
* `sortComparator` directly, a factory is not overwritten by later sort changes.
|
|
82
|
+
* Produces the comparator that orders the channels. Consulted on every rebuild (construction,
|
|
83
|
+
* `sort` change, backend-resolved predefined sort), so later sort changes do not overwrite it.
|
|
72
84
|
*/
|
|
73
85
|
export type ChannelSortComparatorFactory = (
|
|
74
86
|
params: ChannelSortComparatorFactoryParams,
|
|
@@ -84,12 +96,16 @@ export type ChannelPaginatorOptions = {
|
|
|
84
96
|
requestOptions?: ChannelPaginatorRequestOptions;
|
|
85
97
|
sort?: SortParamRequest[];
|
|
86
98
|
sortComparatorFactory?: ChannelSortComparatorFactory;
|
|
99
|
+
/**
|
|
100
|
+
* The channel store backing the list's index. Defaults to `client.channelManager`'s store, shared
|
|
101
|
+
* by every list.
|
|
102
|
+
*
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
store?: EntityStore<Channel>;
|
|
87
106
|
};
|
|
88
107
|
|
|
89
|
-
/**
|
|
90
|
-
* What identifies the query itself, as opposed to which page of it is being requested. Two shapes with
|
|
91
|
-
* the same identity continue one pagination; a different identity restarts it from the first page.
|
|
92
|
-
*/
|
|
108
|
+
/** The query without its page: shapes with the same identity continue one pagination. */
|
|
93
109
|
const getQueryIdentity = (queryShape: ChannelQueryShape | undefined) => {
|
|
94
110
|
if (!queryShape) return queryShape;
|
|
95
111
|
const {
|
|
@@ -113,10 +129,15 @@ const archivedFilterResolver: FieldToDataResolver<Channel> = {
|
|
|
113
129
|
resolve: (channel) => channel.state.membership.archived_at != null,
|
|
114
130
|
};
|
|
115
131
|
|
|
116
|
-
|
|
132
|
+
// Resolvers needing the user or the mute list use the list's client, not `channel.getClient()`: that
|
|
133
|
+
// throws on a disposed channel, which must still sort and filter so a list can locate and drop it.
|
|
134
|
+
|
|
135
|
+
const createAppBannedFilterResolver = (
|
|
136
|
+
client: StreamChat,
|
|
137
|
+
): FieldToDataResolver<Channel> => ({
|
|
117
138
|
matchesField: (field) => field === 'app_banned',
|
|
118
139
|
resolve: (channel) => {
|
|
119
|
-
const ownUserId =
|
|
140
|
+
const ownUserId = client.userId;
|
|
120
141
|
const otherMembers = Object.values(channel.state.members).filter(
|
|
121
142
|
({ user }) => user?.id !== ownUserId,
|
|
122
143
|
);
|
|
@@ -125,53 +146,53 @@ const appBannedFilterResolver: FieldToDataResolver<Channel> = {
|
|
|
125
146
|
const otherMember = otherMembers[0];
|
|
126
147
|
return otherMember.user?.banned ? 'only' : 'excluded';
|
|
127
148
|
},
|
|
128
|
-
};
|
|
149
|
+
});
|
|
129
150
|
|
|
130
|
-
const
|
|
151
|
+
const createHasUnreadFilterResolver = (
|
|
152
|
+
client: StreamChat,
|
|
153
|
+
): FieldToDataResolver<Channel> => ({
|
|
131
154
|
matchesField: (field) => field === 'has_unread',
|
|
132
155
|
resolve: (channel) => {
|
|
133
|
-
const ownUserId =
|
|
156
|
+
const ownUserId = client.userId;
|
|
134
157
|
return (
|
|
135
158
|
ownUserId &&
|
|
136
159
|
channel.state.read[ownUserId] &&
|
|
137
160
|
channel.state.read[ownUserId].unread_messages > 0
|
|
138
161
|
);
|
|
139
162
|
},
|
|
140
|
-
};
|
|
163
|
+
});
|
|
141
164
|
|
|
142
165
|
const hiddenFilterResolver: FieldToDataResolver<Channel> = {
|
|
143
166
|
matchesField: (field) => field === 'hidden',
|
|
144
|
-
// `hidden` is optional on
|
|
145
|
-
// hidden or shown) leaves `channel.data.hidden` undefined. Coerce to a boolean so `{ hidden: false }`
|
|
146
|
-
// matches those channels instead of comparing undefined against false.
|
|
167
|
+
// `hidden` is optional on the response: coerce so `{ hidden: false }` matches channels without it.
|
|
147
168
|
resolve: (channel) => !!channel.data?.hidden,
|
|
148
169
|
};
|
|
149
170
|
|
|
150
171
|
const lastUpdatedFilterResolver: FieldToDataResolver<Channel> = {
|
|
151
172
|
matchesField: (field) => field === 'last_updated',
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
// in different units and make `updated_at` win every comparison.
|
|
156
|
-
const lastMessageAt = channel.messagePaginator.lastMessageAt ?? null;
|
|
157
|
-
const updatedAt = channel.data?.updated_at;
|
|
158
|
-
return lastMessageAt !== null && updatedAt !== undefined
|
|
159
|
-
? Math.max(lastMessageAt, updatedAt)
|
|
160
|
-
: (lastMessageAt ?? updatedAt);
|
|
161
|
-
},
|
|
173
|
+
// the server uses the creation time for a channel without messages
|
|
174
|
+
resolve: (channel) =>
|
|
175
|
+
channel.messagePaginator.latestMessageAt ?? channel.data?.created_at,
|
|
162
176
|
};
|
|
163
177
|
|
|
164
178
|
const membersFilterResolver: FieldToDataResolver<Channel> = {
|
|
165
179
|
matchesField: (field) => field === 'members',
|
|
166
|
-
resolve: (channel) =>
|
|
167
|
-
channel.state.members
|
|
180
|
+
resolve: (channel) => {
|
|
181
|
+
const ids = channel.state.members
|
|
168
182
|
? Object.values(channel.state.members).reduce<string[]>((ids, member) => {
|
|
169
183
|
if (member.user?.id) {
|
|
170
184
|
ids.push(member.user?.id);
|
|
171
185
|
}
|
|
172
186
|
return ids;
|
|
173
187
|
}, [])
|
|
174
|
-
: []
|
|
188
|
+
: [];
|
|
189
|
+
// Only a page of a large channel's members may be loaded, but the own membership always is, so
|
|
190
|
+
// `members: { $in: [ownId] }` holds.
|
|
191
|
+
const { membership } = channel.state;
|
|
192
|
+
const ownId = membership?.user?.id ?? membership?.user_id;
|
|
193
|
+
if (ownId && !ids.includes(ownId)) ids.push(ownId);
|
|
194
|
+
return ids;
|
|
195
|
+
},
|
|
175
196
|
};
|
|
176
197
|
|
|
177
198
|
const memberUserNameFilterResolver: FieldToDataResolver<Channel> = {
|
|
@@ -187,67 +208,97 @@ const memberUserNameFilterResolver: FieldToDataResolver<Channel> = {
|
|
|
187
208
|
: [],
|
|
188
209
|
};
|
|
189
210
|
|
|
211
|
+
/** The own invite's status: `pending`, `accepted` or `rejected`, or `undefined` without an invite. */
|
|
212
|
+
const resolveOwnInviteStatus = (channel: Channel) => {
|
|
213
|
+
const { membership } = channel.state;
|
|
214
|
+
if (membership?.invite_accepted_at != null) return 'accepted';
|
|
215
|
+
if (membership?.invite_rejected_at != null) return 'rejected';
|
|
216
|
+
if (membership?.invited) return 'pending';
|
|
217
|
+
return undefined;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const inviteFilterResolver: FieldToDataResolver<Channel> = {
|
|
221
|
+
matchesField: (field) => field === 'invite',
|
|
222
|
+
resolve: resolveOwnInviteStatus,
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const joinedFilterResolver: FieldToDataResolver<Channel> = {
|
|
226
|
+
matchesField: (field) => field === 'joined',
|
|
227
|
+
// A member, unless the membership is a pending or rejected invite.
|
|
228
|
+
resolve: (channel) => {
|
|
229
|
+
const { membership } = channel.state;
|
|
230
|
+
const isMember = !!(membership?.user?.id ?? membership?.user_id);
|
|
231
|
+
const inviteStatus = resolveOwnInviteStatus(channel);
|
|
232
|
+
return isMember && inviteStatus !== 'pending' && inviteStatus !== 'rejected';
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
|
|
190
236
|
const pinnedFilterResolver: FieldToDataResolver<Channel> = {
|
|
191
237
|
matchesField: (field) => field === 'pinned',
|
|
192
238
|
resolve: (channel) => channel.state.membership.pinned_at != null,
|
|
193
239
|
};
|
|
194
240
|
|
|
195
|
-
const
|
|
241
|
+
const createMutedFilterResolver = (client: StreamChat): FieldToDataResolver<Channel> => ({
|
|
196
242
|
matchesField: (field) => field === 'muted',
|
|
197
|
-
//
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
243
|
+
// Mute state lives on the client (`client.mutedChannels`), not in `channel.data`.
|
|
244
|
+
resolve: (channel) => client._muteStatus(channel.cid).muted,
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* A channel field by path: from `channel.data`, else from `channel.data.custom` (where a response
|
|
249
|
+
* keeps `name` and custom fields). `type`, `id` and `cid` come from the instance, since
|
|
250
|
+
* `channel.data` has them only after a query.
|
|
251
|
+
*/
|
|
252
|
+
const resolveChannelDataValue = (channel: Channel, path: string) => {
|
|
253
|
+
if (path === 'type' || path === 'id' || path === 'cid') return channel[path];
|
|
254
|
+
const value = resolveDotPathValue(channel.data, path);
|
|
255
|
+
return value !== undefined ? value : resolveDotPathValue(channel.data?.custom, path);
|
|
202
256
|
};
|
|
203
257
|
|
|
204
258
|
const dataFieldFilterResolver: FieldToDataResolver<Channel> = {
|
|
205
259
|
matchesField: () => true,
|
|
206
|
-
resolve:
|
|
260
|
+
resolve: resolveChannelDataValue,
|
|
207
261
|
};
|
|
208
262
|
|
|
209
|
-
//
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
263
|
+
// Channel data is split between `Channel.data` and `Channel.state`.
|
|
264
|
+
const createChannelSortPathResolver = (client: StreamChat): PathResolver<Channel> => {
|
|
265
|
+
const hasUnreadResolver = createHasUnreadFilterResolver(client);
|
|
266
|
+
return (channel, path) => {
|
|
267
|
+
switch (path) {
|
|
268
|
+
case 'last_message_at':
|
|
269
|
+
return channel.messagePaginator.latestMessageAt;
|
|
270
|
+
case 'has_unread': {
|
|
271
|
+
return hasUnreadResolver.resolve(channel, path);
|
|
272
|
+
}
|
|
273
|
+
case 'last_updated': {
|
|
274
|
+
return lastUpdatedFilterResolver.resolve(channel, path) ?? 0;
|
|
275
|
+
}
|
|
276
|
+
case 'pinned_at':
|
|
277
|
+
return channel.state.membership.pinned_at;
|
|
278
|
+
case 'unread_count': {
|
|
279
|
+
const userId = client.userId;
|
|
280
|
+
// a channel without a read entry for the user has nothing unread
|
|
281
|
+
return userId ? (channel.state.read[userId]?.unread_messages ?? 0) : 0;
|
|
282
|
+
}
|
|
283
|
+
default:
|
|
284
|
+
return resolveChannelDataValue(channel, path);
|
|
225
285
|
}
|
|
226
|
-
|
|
227
|
-
return resolveDotPathValue(channel.data, path);
|
|
228
|
-
}
|
|
286
|
+
};
|
|
229
287
|
};
|
|
230
288
|
|
|
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
289
|
/**
|
|
234
|
-
* A paginated channel list.
|
|
290
|
+
* A paginated channel list. `staticFilters` are the filters this client asked for, `filterBuilder`
|
|
291
|
+
* adds dynamic ones from its reactive context (merged over the static ones on every build). For a
|
|
292
|
+
* `predefined_filter` query the backend reports what it applied (`predefinedFilter`), which wins
|
|
293
|
+
* over `staticFilters` in `effectiveFilters` (and over `sort` in `effectiveSort`).
|
|
235
294
|
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* two (and `effectiveSort` likewise for ordering).
|
|
241
|
-
* - purpose: `buildQueryFilters()` produces the filters sent to the server (and the offline-db query
|
|
242
|
-
* key), built from the local filters only; `buildMatchFilters()` produces the filters items are
|
|
243
|
-
* matched against locally, built from `effectiveFilters`. They are not interchangeable: sending the
|
|
244
|
-
* resolved filter back changes the query shape mid-pagination, and matching against the local filter
|
|
245
|
-
* admits channels the queried list excludes.
|
|
295
|
+
* `buildQueryFilters()` (sent to the server, offline-db query key) uses the local filters only and
|
|
296
|
+
* `buildMatchFilters()` (local matching) uses `effectiveFilters`. Do not swap them: sending the
|
|
297
|
+
* resolved filter back changes the query shape mid-pagination, and matching on the local filter
|
|
298
|
+
* admits channels the list excludes.
|
|
246
299
|
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
* `sortComparatorFactory` (constructor option or setter, consulted on every rebuild) or by overriding
|
|
250
|
-
* `buildSortComparator` in a subclass.
|
|
300
|
+
* `sortComparator` is derived from `effectiveSort` and rebuilt when it changes, so do not assign
|
|
301
|
+
* it: use `sortComparatorFactory` or override `buildSortComparator`.
|
|
251
302
|
*/
|
|
252
303
|
export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape> {
|
|
253
304
|
private readonly _id: string;
|
|
@@ -256,14 +307,29 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
256
307
|
protected _sort: SortParamRequest[] | undefined;
|
|
257
308
|
protected _options: ChannelPaginatorRequestOptions | undefined;
|
|
258
309
|
protected _channelStateOptions: ChannelStateOptions | undefined;
|
|
259
|
-
protected _nextQueryShape: ChannelQueryShape | undefined;
|
|
260
310
|
/** Backend-reported metadata of the last `predefined_filter` query (see `predefinedFilter`). */
|
|
261
311
|
protected _predefinedFilter: ParsedPredefinedFilterResponse | undefined;
|
|
312
|
+
/** Metadata of the in-flight response, committed by `placeQueryPage` on a first page only. */
|
|
313
|
+
private _pendingPredefinedFilter: ParsedPredefinedFilterResponse | undefined;
|
|
262
314
|
/**
|
|
263
|
-
*
|
|
264
|
-
*
|
|
315
|
+
* True while the loaded items came only from the offline cache (seeded by `setItems`, never
|
|
316
|
+
* confirmed by a query). The seed's offset and query shape would make the next query a
|
|
317
|
+
* continuation, but a cache has no pagination position, so `executeQuery` forces a first page that
|
|
318
|
+
* keeps the items.
|
|
265
319
|
*/
|
|
266
|
-
private
|
|
320
|
+
private _itemsLoadedFromOfflineDB = false;
|
|
321
|
+
/** The query in flight refreshes a cache-only interval, so its response replaces the interval. */
|
|
322
|
+
private _replaceOfflineSeedOnResponse = false;
|
|
323
|
+
/** The query handed to the sync manager, from the cache read until it runs. See `executeQuery`. */
|
|
324
|
+
private _queryAwaitingSync: ChannelQueryShape | undefined;
|
|
325
|
+
/** The cids of the page the latest query returned, `undefined` when it failed. */
|
|
326
|
+
private _lastPageCids: string[] | undefined;
|
|
327
|
+
/** Whether `recoverLoadedItems` runs: its pages own the list's position until it ends. */
|
|
328
|
+
private _isRecoveringLoadedItems = false;
|
|
329
|
+
/** A recovery asked for while one runs: the running pass stops and a new one starts. */
|
|
330
|
+
private _recoveryRequestedAgain = false;
|
|
331
|
+
/** A next page refused while recovering, queried once the recovery ends. See `executeQuery`. */
|
|
332
|
+
private _tailQueryAwaitingRecovery = false;
|
|
267
333
|
protected _sortComparatorFactory: ChannelSortComparatorFactory | undefined;
|
|
268
334
|
sortComparator: (a: Channel, b: Channel) => number;
|
|
269
335
|
filterBuilder: FilterBuilder<ChannelFilters>;
|
|
@@ -278,16 +344,22 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
278
344
|
requestOptions,
|
|
279
345
|
sort,
|
|
280
346
|
sortComparatorFactory,
|
|
347
|
+
store,
|
|
281
348
|
}: ChannelPaginatorOptions) {
|
|
282
349
|
super({
|
|
283
350
|
hasPaginationQueryShapeChanged,
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
351
|
+
// the index is this list's holder in the store: a channel stays stored while the list lists it
|
|
352
|
+
createItemIndex: (owner) =>
|
|
353
|
+
new StoreBackedItemIndex<Channel>({
|
|
354
|
+
getEntityId: (channel) => channel.cid,
|
|
355
|
+
holderName: 'channel-paginator',
|
|
356
|
+
owner: owner as ChannelPaginator,
|
|
357
|
+
store: store ?? client.channelManager?.channelStore,
|
|
358
|
+
}),
|
|
287
359
|
retryCount: DEFAULT_QUERY_CHANNELS_RETRY_COUNT,
|
|
288
360
|
...paginatorOptions,
|
|
289
361
|
});
|
|
290
|
-
const definedSort = sort
|
|
362
|
+
const definedSort = sort?.length ? sort : DEFAULT_BACKEND_SORT;
|
|
291
363
|
this.client = client;
|
|
292
364
|
this._id = id ?? `channel-paginator-${generateUUIDv4()}`;
|
|
293
365
|
this._sort = definedSort;
|
|
@@ -299,33 +371,35 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
299
371
|
this.sortComparator = this.buildSortComparator(definedSort);
|
|
300
372
|
this.setFilterResolvers([
|
|
301
373
|
archivedFilterResolver,
|
|
302
|
-
|
|
303
|
-
|
|
374
|
+
createAppBannedFilterResolver(client),
|
|
375
|
+
createHasUnreadFilterResolver(client),
|
|
304
376
|
hiddenFilterResolver,
|
|
377
|
+
inviteFilterResolver,
|
|
378
|
+
joinedFilterResolver,
|
|
305
379
|
lastUpdatedFilterResolver,
|
|
306
380
|
pinnedFilterResolver,
|
|
307
|
-
|
|
381
|
+
createMutedFilterResolver(client),
|
|
308
382
|
membersFilterResolver,
|
|
309
383
|
memberUserNameFilterResolver,
|
|
310
384
|
dataFieldFilterResolver,
|
|
311
385
|
]);
|
|
386
|
+
// Channels are reactive objects: republish only when the list's membership or order changes.
|
|
387
|
+
this.state.addPreprocessor((next, previous) => {
|
|
388
|
+
if (previous && hasSameItems(previous.items, next.items))
|
|
389
|
+
next.items = previous.items;
|
|
390
|
+
});
|
|
312
391
|
}
|
|
313
392
|
|
|
314
393
|
/**
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* `sortComparator` is derived state and is therefore reassigned on every rebuild — assigning to it
|
|
321
|
-
* directly does not survive a sort change or a predefined-filter response. To customize ordering,
|
|
322
|
-
* supply `sortComparatorFactory` (it is consulted on every rebuild and may delegate to
|
|
323
|
-
* `defaultComparator`), or override this method in a subclass.
|
|
394
|
+
* The single construction point of `sortComparator`, so every rebuild keeps the channel path
|
|
395
|
+
* resolver and the cid tiebreaker. Customize it with `sortComparatorFactory` (which may delegate
|
|
396
|
+
* to `defaultComparator`) or by overriding this method: assigning `sortComparator` directly is
|
|
397
|
+
* lost on the next rebuild.
|
|
324
398
|
*/
|
|
325
399
|
protected buildSortComparator(sort: SortParamRequest[]) {
|
|
326
400
|
const defaultComparator = makeComparator<Channel>({
|
|
327
401
|
sort,
|
|
328
|
-
resolvePathValue:
|
|
402
|
+
resolvePathValue: createChannelSortPathResolver(this.client),
|
|
329
403
|
tiebreaker: (l, r) => {
|
|
330
404
|
const leftId = this.getItemId(l);
|
|
331
405
|
const rightId = this.getItemId(r);
|
|
@@ -351,35 +425,26 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
351
425
|
}
|
|
352
426
|
|
|
353
427
|
get sort(): SortParamRequest[] {
|
|
354
|
-
return this._sort
|
|
428
|
+
return this._sort?.length ? this._sort : DEFAULT_BACKEND_SORT;
|
|
355
429
|
}
|
|
356
430
|
|
|
357
431
|
/**
|
|
358
|
-
* What the backend reported it
|
|
359
|
-
* `QueryChannelsResponse.predefined_filter
|
|
360
|
-
*
|
|
361
|
-
* of a normal query are not echoed back.
|
|
432
|
+
* What the backend reported it filtered and sorted by for the last first-page query
|
|
433
|
+
* (`QueryChannelsResponse.predefined_filter`: `name`, `filter`, and `sort` when the stored filter
|
|
434
|
+
* has a sort template). Set only for `predefined_filter` queries.
|
|
362
435
|
*/
|
|
363
436
|
get predefinedFilter(): ParsedPredefinedFilterResponse | undefined {
|
|
364
437
|
return this._predefinedFilter;
|
|
365
438
|
}
|
|
366
439
|
|
|
367
|
-
/**
|
|
368
|
-
* Filters this paginator matches items against client-side. A predefined filter resolved by the backend
|
|
369
|
-
* wins over the locally configured one: for such a query the local `filters` are not what the server
|
|
370
|
-
* applied, so matching against them would admit items the queried list excludes.
|
|
371
|
-
*/
|
|
440
|
+
/** Filters items are matched against locally: the backend-resolved one, else `staticFilters`. */
|
|
372
441
|
get effectiveFilters(): ChannelFilters | undefined {
|
|
373
442
|
return (
|
|
374
443
|
(this._predefinedFilter?.filter as ChannelFilters | undefined) ?? this.staticFilters
|
|
375
444
|
);
|
|
376
445
|
}
|
|
377
446
|
|
|
378
|
-
/**
|
|
379
|
-
* Sort this paginator orders items by. Mirrors `effectiveFilters`: a sort template carried by a
|
|
380
|
-
* backend-resolved predefined filter takes precedence over the requested sort, matching backend
|
|
381
|
-
* precedence rules.
|
|
382
|
-
*/
|
|
447
|
+
/** The sort items are ordered by: the backend-resolved predefined sort template, else `sort`. */
|
|
383
448
|
get effectiveSort(): SortParamRequest[] {
|
|
384
449
|
return (this._predefinedFilter?.sort as SortParamRequest[] | undefined) ?? this.sort;
|
|
385
450
|
}
|
|
@@ -414,10 +479,8 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
414
479
|
}
|
|
415
480
|
|
|
416
481
|
/**
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
* `sortComparator` — a sort change or a backend-resolved predefined sort will not discard it. Set to
|
|
420
|
-
* `undefined` to go back to the built-in ordering.
|
|
482
|
+
* Rebuilds the comparator immediately; later rebuilds consult the factory again, so a sort change
|
|
483
|
+
* does not discard it. `undefined` restores the built-in ordering.
|
|
421
484
|
*/
|
|
422
485
|
set sortComparatorFactory(factory: ChannelSortComparatorFactory | undefined) {
|
|
423
486
|
this._sortComparatorFactory = factory;
|
|
@@ -429,21 +492,16 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
429
492
|
}
|
|
430
493
|
|
|
431
494
|
/**
|
|
432
|
-
* Filters sent
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
* page to `hasPaginationQueryShapeChanged`.
|
|
495
|
+
* Filters sent with the next query and used as the offline-db query key. Built from the local
|
|
496
|
+
* filters only: the backend-resolved filter would change the query shape after the first response,
|
|
497
|
+
* so the next page would look like a first page.
|
|
436
498
|
*/
|
|
437
499
|
buildQueryFilters = (): ChannelFilters =>
|
|
438
500
|
this.filterBuilder.buildFilters({
|
|
439
501
|
baseFilters: { ...this.staticFilters },
|
|
440
502
|
});
|
|
441
503
|
|
|
442
|
-
/**
|
|
443
|
-
* Filters items are matched against locally — the `BasePaginator.buildMatchFilters` hook consumed by
|
|
444
|
-
* `matchesFilter`. Built from `effectiveFilters`, so a `predefined_filter` list matches what the
|
|
445
|
-
* backend applied rather than the local filters, which are not what produced the list.
|
|
446
|
-
*/
|
|
504
|
+
/** Filters items are matched against locally (`matchesFilter`), built from `effectiveFilters`. */
|
|
447
505
|
buildMatchFilters = (): ChannelFilters =>
|
|
448
506
|
this.filterBuilder.buildFilters({
|
|
449
507
|
baseFilters: { ...this.effectiveFilters },
|
|
@@ -452,22 +510,16 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
452
510
|
matchesFilter(channel: Channel): boolean {
|
|
453
511
|
const filters = this.buildMatchFilters();
|
|
454
512
|
|
|
455
|
-
//
|
|
456
|
-
//
|
|
457
|
-
//
|
|
458
|
-
// holds for a paginator whose filter resolvers were replaced (`setFilterResolvers`), which would
|
|
459
|
-
// otherwise leave `hidden` unresolvable and reject every channel.
|
|
513
|
+
// Like `queryChannels`, exclude hidden channels unless the filter asks for them. Not a synthetic
|
|
514
|
+
// `hidden: false` entry: with replaced resolvers (`setFilterResolvers`) `hidden` would be
|
|
515
|
+
// unresolvable and reject every channel.
|
|
460
516
|
if (channel.data?.hidden && !filterConstrainsField(filters, 'hidden')) return false;
|
|
461
517
|
return itemMatchesFilter<Channel>(channel, filters, {
|
|
462
518
|
resolvers: this._filterFieldToDataResolvers,
|
|
463
519
|
});
|
|
464
520
|
}
|
|
465
521
|
|
|
466
|
-
/**
|
|
467
|
-
* Commits the `predefined_filter` metadata of the response, or clears it when the response carried
|
|
468
|
-
* none (a plain `filter_conditions` query), so a switch away from a predefined filter cannot leave
|
|
469
|
-
* stale matching/ordering semantics behind.
|
|
470
|
-
*/
|
|
522
|
+
/** Commits the response's `predefined_filter` metadata, or clears it when there is none. */
|
|
471
523
|
protected applyPredefinedFilterResponse(
|
|
472
524
|
predefinedFilter: ParsedPredefinedFilterResponse | undefined,
|
|
473
525
|
) {
|
|
@@ -476,28 +528,41 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
476
528
|
}
|
|
477
529
|
|
|
478
530
|
/**
|
|
479
|
-
* The
|
|
480
|
-
*
|
|
481
|
-
*
|
|
531
|
+
* The metadata describes the query as a whole, so it is committed only when a first page lands (a
|
|
532
|
+
* failed query keeps the loaded list's). It is committed before `super`, which filters and ingests
|
|
533
|
+
* the page using `matchesFilter` and the comparator this metadata feeds.
|
|
482
534
|
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
535
|
+
* A recovery page (see `recoverLoadedItems`) starts where the one before it ended, so it extends
|
|
536
|
+
* the shown interval, though a page at a caller's shape would otherwise start one of its own.
|
|
485
537
|
*/
|
|
486
|
-
|
|
538
|
+
override placeQueryPage(params: PlaceQueryPageParams<Channel, ChannelQueryShape>) {
|
|
539
|
+
if (this._isRecoveringLoadedItems && params.startsSeparateInterval) {
|
|
540
|
+
params = { ...params, startsSeparateInterval: false };
|
|
541
|
+
}
|
|
542
|
+
this._lastPageCids = params.results?.items.map((channel) => channel.cid);
|
|
487
543
|
const pendingPredefinedFilter = this._pendingPredefinedFilter;
|
|
488
544
|
this._pendingPredefinedFilter = undefined;
|
|
489
545
|
if (params.isFirstPage && params.results) {
|
|
490
546
|
this.applyPredefinedFilterResponse(pendingPredefinedFilter);
|
|
491
547
|
}
|
|
492
|
-
|
|
548
|
+
const replaceOfflineSeed = this._replaceOfflineSeedOnResponse;
|
|
549
|
+
this._replaceOfflineSeedOnResponse = false;
|
|
550
|
+
if (replaceOfflineSeed && params.results) {
|
|
551
|
+
// The cache can be arbitrarily old and hold channels the server dropped (hidden, deleted,
|
|
552
|
+
// left): the page replaces the seed instead of merging into it.
|
|
553
|
+
this.clearItemStorage();
|
|
554
|
+
return super.placeQueryPage({ ...params, keepPreviousItems: false });
|
|
555
|
+
}
|
|
556
|
+
return super.placeQueryPage(params);
|
|
493
557
|
}
|
|
494
558
|
|
|
495
|
-
|
|
496
|
-
|
|
559
|
+
protected getNextQueryShape({
|
|
560
|
+
pageSize,
|
|
561
|
+
}: { pageSize?: number } = {}): ChannelQueryShape {
|
|
497
562
|
const shape: ChannelQueryShape = {
|
|
498
563
|
filter_conditions: this.buildQueryFilters(),
|
|
499
564
|
...this.options,
|
|
500
|
-
limit: this.pageSize,
|
|
565
|
+
limit: pageSize ?? this.pageSize,
|
|
501
566
|
offset: this.offset,
|
|
502
567
|
};
|
|
503
568
|
|
|
@@ -519,14 +584,11 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
519
584
|
}
|
|
520
585
|
|
|
521
586
|
/**
|
|
522
|
-
* Writes a cid order into the offline cache under the query that produced it.
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
* `predefined_filter` / `filter_values` / `sort_values` appear, without which two predefined-filter
|
|
528
|
-
* lists cannot be told apart. The duplication goes away once `convertFilterSortToQuery` derives the
|
|
529
|
-
* key from `options` (a change in that implementation plus a schema-version bump to flush stale rows).
|
|
587
|
+
* Writes a cid order into the offline cache under the query that produced it. `filters` and `sort`
|
|
588
|
+
* are passed apart from `options` (which already holds them) because the DB implementation derives
|
|
589
|
+
* the cache row key from them, while `options` carries the full request (`predefined_filter`, ...)
|
|
590
|
+
* that tells predefined-filter lists apart. The resolved `predefinedFilter` is stored with the
|
|
591
|
+
* order: a cache-seeded list has no response to learn it from.
|
|
530
592
|
*/
|
|
531
593
|
protected cacheCidsForQuery({
|
|
532
594
|
cids,
|
|
@@ -538,9 +600,10 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
538
600
|
this.client.offlineDb?.executeQuerySafely(
|
|
539
601
|
(db) =>
|
|
540
602
|
db.upsertCidsForQuery({
|
|
541
|
-
cids,
|
|
603
|
+
cids: cids.slice(0, this.pageSize),
|
|
542
604
|
filters: request.filter_conditions,
|
|
543
605
|
options: request,
|
|
606
|
+
predefinedFilter: this._predefinedFilter,
|
|
544
607
|
sort: request.sort,
|
|
545
608
|
}),
|
|
546
609
|
{ method: 'upsertCidsForQuery' },
|
|
@@ -548,15 +611,18 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
548
611
|
}
|
|
549
612
|
|
|
550
613
|
/**
|
|
551
|
-
* Persists the current cid order under the query that produced it.
|
|
552
|
-
* loaded list
|
|
553
|
-
* running; skipping those would leave the cached order stale until the next full re-query.
|
|
614
|
+
* Persists the current cid order under the query that produced it. Runs after every mutation of
|
|
615
|
+
* the loaded list, including live inserts and removals that reorder it without a query.
|
|
554
616
|
*/
|
|
555
617
|
protected persistLoadedCids() {
|
|
556
|
-
|
|
618
|
+
// Without a user the list is being emptied by `disconnectUser()`: what stays in the offline DB
|
|
619
|
+
// is the app's call (`resetDB()`).
|
|
620
|
+
if (!this.client.offlineDb || !this.client.userId) return;
|
|
557
621
|
|
|
558
622
|
this.cacheCidsForQuery({
|
|
559
|
-
cids: (this.items ?? [])
|
|
623
|
+
cids: (this.items ?? [])
|
|
624
|
+
.filter((channel) => !channel.isProvisional)
|
|
625
|
+
.map((channel) => channel.cid),
|
|
560
626
|
request: this.loadedQueryRequest,
|
|
561
627
|
});
|
|
562
628
|
}
|
|
@@ -574,16 +640,20 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
574
640
|
const { stateOptions: _, ...request } = queryShape;
|
|
575
641
|
|
|
576
642
|
try {
|
|
577
|
-
const
|
|
643
|
+
const cachedQuery = await this.client.offlineDb.getChannelsForQuery({
|
|
578
644
|
userId: this.client.user.id,
|
|
579
645
|
options: request,
|
|
580
646
|
});
|
|
581
647
|
|
|
582
|
-
if (
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
648
|
+
if (cachedQuery) {
|
|
649
|
+
if (cachedQuery.predefinedFilter) {
|
|
650
|
+
this.applyPredefinedFilterResponse(cachedQuery.predefinedFilter);
|
|
651
|
+
}
|
|
652
|
+
return this.client.hydrateChannels(
|
|
653
|
+
cachedQuery.channels,
|
|
654
|
+
{ offlineMode: true },
|
|
655
|
+
request,
|
|
656
|
+
);
|
|
587
657
|
}
|
|
588
658
|
} catch (error) {
|
|
589
659
|
chatLoggerSystem.getLogger('channel').error((error as Error).message);
|
|
@@ -609,73 +679,102 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
609
679
|
};
|
|
610
680
|
|
|
611
681
|
/**
|
|
612
|
-
*
|
|
613
|
-
*
|
|
614
|
-
*
|
|
615
|
-
*
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
* Only first-page queries defer; paginating an already loaded list is unaffected (as was the legacy
|
|
619
|
-
* `loadNext`).
|
|
682
|
+
* Defers a first-page query (or a page of a cache-seeded list) while the offline sync is in
|
|
683
|
+
* progress: the cached page is shown right away and the network query is handed to the sync
|
|
684
|
+
* manager, which re-runs it after reconciliation. Querying and persisting cids against unsynced
|
|
685
|
+
* local state would race the replay of pending mutations. Paginating a list loaded from the
|
|
686
|
+
* network is not deferred.
|
|
620
687
|
*/
|
|
621
688
|
async executeQuery(params: PaginationQueryParams<ChannelQueryShape> = {}) {
|
|
689
|
+
// The recovery's pages hold the position (`offset` restarts at 0 until the last one lands), so
|
|
690
|
+
// a page queried in between would fetch the wrong one. A refresh still runs.
|
|
691
|
+
if (this._isRecoveringLoadedItems && params.direction && params.reset !== 'yes') {
|
|
692
|
+
if (params.direction === 'tailward') this._tailQueryAwaitingRecovery = true;
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
622
695
|
const { offlineDb } = this.client;
|
|
623
|
-
|
|
696
|
+
|
|
697
|
+
const effectiveParams: PaginationQueryParams<ChannelQueryShape> =
|
|
698
|
+
this._itemsLoadedFromOfflineDB && params.reset !== 'yes'
|
|
699
|
+
? { ...params, keepPreviousItems: true, reset: 'yes' as const }
|
|
700
|
+
: params;
|
|
701
|
+
|
|
702
|
+
const queryShape = effectiveParams.queryShape ?? this.getNextQueryShape();
|
|
624
703
|
const shouldDeferUntilSynced =
|
|
625
704
|
!!offlineDb?.getChannelsForQuery &&
|
|
626
705
|
!!this.client.user?.id &&
|
|
627
|
-
!offlineDb.syncManager.
|
|
628
|
-
|
|
706
|
+
!offlineDb.syncManager.isSynced &&
|
|
707
|
+
// A cache-seeded list is not a loaded one, so paginating it defers too.
|
|
708
|
+
(this._itemsLoadedFromOfflineDB ||
|
|
709
|
+
this.isFirstPageQuery({ queryShape, reset: effectiveParams.reset }));
|
|
629
710
|
|
|
630
|
-
if (!shouldDeferUntilSynced) return await super.executeQuery(
|
|
711
|
+
if (!shouldDeferUntilSynced) return await super.executeQuery(effectiveParams);
|
|
712
|
+
|
|
713
|
+
if (
|
|
714
|
+
this._queryAwaitingSync &&
|
|
715
|
+
!this.config.hasPaginationQueryShapeChanged(this._queryAwaitingSync, queryShape)
|
|
716
|
+
) {
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
this._queryAwaitingSync = queryShape;
|
|
631
720
|
|
|
632
721
|
if (!this.isInitialized) {
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
722
|
+
let cachedChannels: Channel[] | undefined;
|
|
723
|
+
try {
|
|
724
|
+
cachedChannels = await this.preloadFirstPageFromOfflineDb({
|
|
725
|
+
...effectiveParams,
|
|
726
|
+
queryShape,
|
|
727
|
+
});
|
|
728
|
+
} catch (error) {
|
|
729
|
+
this._queryAwaitingSync = undefined;
|
|
730
|
+
throw error;
|
|
731
|
+
}
|
|
637
732
|
if (cachedChannels?.length) {
|
|
638
|
-
// Seed via `setItems
|
|
639
|
-
// actually appear within the adequate index.
|
|
733
|
+
// Seed via `setItems`, which ingests the page into the interval/index storage.
|
|
640
734
|
// TODO: Maybe find a better way to do this rather than 2 partialNext invocations
|
|
641
735
|
// running. This all happens so fast it should never be noticeable but it's
|
|
642
736
|
// a microoptimization.
|
|
643
737
|
this.setItems({ valueOrFactory: cachedChannels, isFirstPage: true });
|
|
738
|
+
this._itemsLoadedFromOfflineDB = true;
|
|
644
739
|
}
|
|
645
|
-
// Nothing is in flight while
|
|
646
|
-
//
|
|
740
|
+
// Nothing is in flight while waiting for the sync: `isLoading` would make `canExecuteQuery`
|
|
741
|
+
// reject the query scheduled below.
|
|
647
742
|
this.state.partialNext({ isLoading: false });
|
|
648
743
|
}
|
|
649
744
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
745
|
+
const refreshParams: PaginationQueryParams<ChannelQueryShape> = {
|
|
746
|
+
...effectiveParams,
|
|
747
|
+
keepPreviousItems: true,
|
|
748
|
+
...(this._itemsLoadedFromOfflineDB ? { reset: 'yes' as const } : {}),
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
// Already synced: the sync-status callback would never fire, so run the query now.
|
|
752
|
+
if (offlineDb.syncManager.isSynced) {
|
|
753
|
+
this._queryAwaitingSync = undefined;
|
|
754
|
+
return await super.executeQuery(refreshParams);
|
|
655
755
|
}
|
|
656
756
|
|
|
657
|
-
// When the sync completes, run the real query — but as a NON-DESTRUCTIVE refresh
|
|
658
|
-
// (`keepPreviousItems`) so the channels we already surfaced from the offline DB stay visible while it
|
|
659
|
-
// runs. Without this the re-run goes through the first-page reset path and re-preloads from the DB;
|
|
660
|
-
// if the sync invalidated the offline query cache (i.e. a channel changed while the app was closed),
|
|
661
|
-
// that re-preload returns nothing and the list blanks to a second skeleton before the fresh page lands.
|
|
662
757
|
offlineDb.syncManager.scheduleSyncStatusChangeCallback(this.id, async () => {
|
|
663
|
-
|
|
758
|
+
this._queryAwaitingSync = undefined;
|
|
759
|
+
await this.executeQuery(refreshParams);
|
|
664
760
|
});
|
|
665
761
|
}
|
|
666
762
|
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
763
|
+
protected override fetchQueryResponse = async ({
|
|
764
|
+
queryShape: preparedQueryShape,
|
|
765
|
+
}: PaginationQueryParams<ChannelQueryShape> = {}): Promise<
|
|
766
|
+
PaginationQueryReturnValue<Channel>
|
|
767
|
+
> => {
|
|
768
|
+
if (this._itemsLoadedFromOfflineDB) this._replaceOfflineSeedOnResponse = true;
|
|
769
|
+
// A query is going out: the items stop being cache-only, whatever the response.
|
|
770
|
+
this._itemsLoadedFromOfflineDB = false;
|
|
771
|
+
const queryShape = preparedQueryShape ?? this.getNextQueryShape();
|
|
772
|
+
const { stateOptions, ...request } = queryShape;
|
|
673
773
|
let items: Channel[];
|
|
674
774
|
if (this.config.doRequest) {
|
|
675
|
-
items = (await this.config.doRequest(
|
|
775
|
+
items = (await this.config.doRequest(queryShape)).items;
|
|
676
776
|
} else {
|
|
677
|
-
// withResponse
|
|
678
|
-
// predefined-filter list needs to know what the backend actually filtered and sorted by.
|
|
777
|
+
// `withResponse` exposes `predefined_filter`, which a predefined-filter list needs.
|
|
679
778
|
const response = await this.client.queryChannelsAndHydrate(request, {
|
|
680
779
|
...stateOptions,
|
|
681
780
|
withResponse: true,
|
|
@@ -686,19 +785,182 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
686
785
|
return { items };
|
|
687
786
|
};
|
|
688
787
|
|
|
689
|
-
|
|
788
|
+
private getLastPageCids() {
|
|
789
|
+
return this._lastPageCids;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* The reconnect refresh. Re-queries every loaded page, then drops the loaded channels no page
|
|
794
|
+
* returned that sort within the re-queried range: they were deleted, left, hidden, or no longer
|
|
795
|
+
* match the filter. Those sorting below it were not re-queried and stay.
|
|
796
|
+
*
|
|
797
|
+
* Each page asks for everything still to cover and the next one starts where it ended, so the
|
|
798
|
+
* server's page cap decides the step. A failed page removes nothing. At most
|
|
799
|
+
* {@link MAX_RECOVERED_ITEMS} channels are re-queried.
|
|
800
|
+
*
|
|
801
|
+
* Paging is held meanwhile: a next page asked for is queried once the recovery ends, as the list
|
|
802
|
+
* end that asked for it does not ask again when the recovery changed nothing. A query of the
|
|
803
|
+
* list's own already in flight is waited for, as it would make the recovery's refused.
|
|
804
|
+
*
|
|
805
|
+
* A call while a recovery runs returns at once and the running pass starts over from the first page
|
|
806
|
+
* once its page in flight lands, as the pages before were watched on a connection that is gone.
|
|
807
|
+
*/
|
|
808
|
+
recoverLoadedItems = async () => {
|
|
809
|
+
if (this._isRecoveringLoadedItems) {
|
|
810
|
+
this._recoveryRequestedAgain = true;
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
this._isRecoveringLoadedItems = true;
|
|
814
|
+
try {
|
|
815
|
+
do {
|
|
816
|
+
this._recoveryRequestedAgain = false;
|
|
817
|
+
await this.waitForQueryToSettle();
|
|
818
|
+
await this.recoverLoadedPages();
|
|
819
|
+
} while (this._recoveryRequestedAgain);
|
|
820
|
+
} finally {
|
|
821
|
+
this._isRecoveringLoadedItems = false;
|
|
822
|
+
}
|
|
823
|
+
if (!this._tailQueryAwaitingRecovery) return;
|
|
824
|
+
this._tailQueryAwaitingRecovery = false;
|
|
825
|
+
runDetached(this.toTail(), { context: 'ChannelPaginator.recoverLoadedItems' });
|
|
826
|
+
};
|
|
827
|
+
|
|
828
|
+
/** Resolves once the list has no query of its own in flight. */
|
|
829
|
+
private waitForQueryToSettle = () =>
|
|
830
|
+
new Promise<void>((resolve) => {
|
|
831
|
+
if (!this.isLoading) {
|
|
832
|
+
resolve();
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
const unsubscribe = this.state.subscribeWithSelector(
|
|
836
|
+
({ isLoading }) => ({ isLoading }),
|
|
837
|
+
({ isLoading }) => {
|
|
838
|
+
if (isLoading) return;
|
|
839
|
+
unsubscribe();
|
|
840
|
+
resolve();
|
|
841
|
+
},
|
|
842
|
+
);
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
private recoverLoadedPages = async () => {
|
|
846
|
+
const loadedCids = new Set((this.items ?? []).map((channel) => channel.cid));
|
|
847
|
+
const recoveredCount = Math.min(loadedCids.size, MAX_RECOVERED_ITEMS);
|
|
848
|
+
const returnedCids = new Set<string>();
|
|
849
|
+
let lastReturnedCid: string | undefined;
|
|
850
|
+
let reachedEnd = false;
|
|
851
|
+
const shape = this.getNextQueryShape();
|
|
852
|
+
let interval: AnyInterval | null = null;
|
|
853
|
+
let offset = 0;
|
|
854
|
+
let pageCount = 0;
|
|
855
|
+
do {
|
|
856
|
+
this._lastPageCids = undefined;
|
|
857
|
+
// the list's own query path, without publishing as the list is published once, below
|
|
858
|
+
const result = await this.executeQuery({
|
|
859
|
+
keepPreviousItems: true,
|
|
860
|
+
queryShape:
|
|
861
|
+
offset === 0 ? undefined : { ...shape, offset, limit: recoveredCount - offset },
|
|
862
|
+
reset: offset === 0 ? 'yes' : undefined,
|
|
863
|
+
silent: true,
|
|
864
|
+
updateState: false,
|
|
865
|
+
});
|
|
866
|
+
const page = this.getLastPageCids();
|
|
867
|
+
if (!result || !page || this._recoveryRequestedAgain) {
|
|
868
|
+
// the first page reset the position and no page commits one, so hand it back
|
|
869
|
+
this.state.partialNext({ offset: this.items?.length ?? 0 });
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
if (result.targetInterval) {
|
|
873
|
+
interval = result.targetInterval;
|
|
874
|
+
// we update immediately for the first page as most of the stuff that is going
|
|
875
|
+
// to move is going to do it to this page
|
|
876
|
+
this.setActiveInterval(interval, { updateState: offset === 0 });
|
|
877
|
+
}
|
|
878
|
+
// a page shorter than asked for, and than a page, is the end of the list
|
|
879
|
+
const requested =
|
|
880
|
+
offset === 0 ? Math.max(this.pageSize, loadedCids.size) : recoveredCount - offset;
|
|
881
|
+
if (page.length < Math.min(this.pageSize, requested)) reachedEnd = true;
|
|
882
|
+
if (!page.length) break;
|
|
883
|
+
pageCount++;
|
|
884
|
+
for (const channel of result.stateCandidate.items ?? [])
|
|
885
|
+
returnedCids.add(channel.cid);
|
|
886
|
+
lastReturnedCid = page[page.length - 1];
|
|
887
|
+
offset += page.length;
|
|
888
|
+
} while (offset < recoveredCount);
|
|
889
|
+
|
|
890
|
+
const lastReturned = lastReturnedCid
|
|
891
|
+
? this.client.channelManager.get(lastReturnedCid)
|
|
892
|
+
: undefined;
|
|
893
|
+
const isWithinRecoveredRange = (cid: string) => {
|
|
894
|
+
if (reachedEnd) return true;
|
|
895
|
+
const channel = this.getItem(cid);
|
|
896
|
+
if (!channel || !lastReturned) return false;
|
|
897
|
+
return this.sortComparator(channel, lastReturned) < 0;
|
|
898
|
+
};
|
|
899
|
+
this.batch(
|
|
900
|
+
() => {
|
|
901
|
+
for (const cid of loadedCids) {
|
|
902
|
+
if (!returnedCids.has(cid) && isWithinRecoveredRange(cid)) {
|
|
903
|
+
this.removeItem({ id: cid });
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
},
|
|
907
|
+
{ coalesce: true },
|
|
908
|
+
);
|
|
909
|
+
// the first page was published as it landed, so only later pages are left to show
|
|
910
|
+
if (interval && pageCount > 1) this.setActiveInterval(interval);
|
|
911
|
+
this.state.partialNext({
|
|
912
|
+
offset: this.items?.length ?? 0,
|
|
913
|
+
// optimistically assume we have more pages, at worst it's one extra pagination attempt
|
|
914
|
+
hasMoreTail: true,
|
|
915
|
+
});
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
/** The extracting step of the query pipeline: the response is the page. */
|
|
919
|
+
protected override extractQueryPage(
|
|
920
|
+
response: PaginationQueryReturnValue<Channel>,
|
|
921
|
+
_params: PaginationQueryParams<ChannelQueryShape>,
|
|
922
|
+
) {
|
|
923
|
+
return response;
|
|
924
|
+
}
|
|
690
925
|
|
|
691
926
|
setItems(params: SetPaginatorItemsParams<Channel>) {
|
|
692
927
|
super.setItems(params);
|
|
693
928
|
this.persistLoadedCids();
|
|
694
929
|
}
|
|
695
930
|
|
|
696
|
-
|
|
931
|
+
/**
|
|
932
|
+
* Places `channel` in the list if it matches, or drops it when it stops matching. A provisional
|
|
933
|
+
* channel (created from members, no ID yet) is refused: it is stored under a temporary cid. Another
|
|
934
|
+
* instance for a stored cid is replaced by the stored one (`ChannelManager.resolveListedChannel`).
|
|
935
|
+
*/
|
|
936
|
+
ingestItem(input: Channel): boolean {
|
|
937
|
+
if (input.isProvisional) return false;
|
|
938
|
+
const channel = this.client.channelManager.resolveListedChannel(input);
|
|
939
|
+
if (!channel) return false;
|
|
697
940
|
const changed = super.ingestItem(channel);
|
|
941
|
+
// A channel outside the result set is not held.
|
|
942
|
+
if (!this.matchesFilter(channel)) this._itemIndex.remove(channel.cid);
|
|
698
943
|
if (changed) this.persistLoadedCids();
|
|
699
944
|
return changed;
|
|
700
945
|
}
|
|
701
946
|
|
|
947
|
+
/** Entity-store subscriber. A channel publishes changes via `channel.state`: nothing to do. */
|
|
948
|
+
onEntitiesChanged(): void {
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
/** Entity-store subscriber: the store removed a channel this list holds (e.g. logout). */
|
|
953
|
+
onEntityRemoved(id: string, channel: unknown): void {
|
|
954
|
+
this.removeItem({ id, item: channel as Channel });
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
resetState() {
|
|
958
|
+
super.resetState();
|
|
959
|
+
this._itemIndex.clear();
|
|
960
|
+
this._queryAwaitingSync = undefined;
|
|
961
|
+
this._tailQueryAwaitingRecovery = false;
|
|
962
|
+
}
|
|
963
|
+
|
|
702
964
|
removeItem(params: { id?: string; item?: Channel }): ItemCoordinates {
|
|
703
965
|
const coordinates = super.removeItem(params);
|
|
704
966
|
if ((coordinates.state?.currentIndex ?? -1) > -1 || coordinates.interval) {
|