stream-chat 10.0.0-rc.9 → 10.0.0
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 +21650 -19790
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +21690 -19798
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +21755 -19895
- 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 +237 -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 +513 -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,23 +1,21 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
ExecuteQueryReturnValue,
|
|
4
|
-
Interval,
|
|
5
|
-
PostQueryReconcileParams,
|
|
6
|
-
} from './BasePaginator';
|
|
1
|
+
import type { BasePaginatorConfig, Interval, QueryPagePlacement } from './BasePaginator';
|
|
2
|
+
import { isLogicalInterval } from './BasePaginator';
|
|
7
3
|
import {
|
|
8
4
|
type MessagePaginatorOptions as BaseMessagePaginatorOptions,
|
|
9
5
|
getMessageCreatedAtTimestamp,
|
|
10
6
|
type JumpToMessageOptions,
|
|
11
7
|
MessageIntervalPaginator,
|
|
8
|
+
type MessageQueryResponse,
|
|
12
9
|
type MessageQueryShape,
|
|
13
10
|
} from './MessageIntervalPaginator';
|
|
14
|
-
import type { LocalMessage } from '../../types';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
11
|
+
import type { LocalMessage, TimestampNS, UserResponse } from '../../types';
|
|
12
|
+
import type { EntityStoreChangeBatch } from '../../entityStore/EntityStore';
|
|
13
|
+
import { asTimestampNS, nsToDate } from '../../utils/time';
|
|
14
|
+
import { isThreadOnlyReply } from '../../utils';
|
|
15
|
+
import { StateStore } from '@stream-io/state-store';
|
|
17
16
|
|
|
18
17
|
export type {
|
|
19
18
|
JumpToMessageOptions,
|
|
20
|
-
MergeNewestPageOptions,
|
|
21
19
|
MessageFocusReason,
|
|
22
20
|
MessageFocusSignal,
|
|
23
21
|
MessageFocusSignalState,
|
|
@@ -25,105 +23,101 @@ export type {
|
|
|
25
23
|
MessagePaginatorSort,
|
|
26
24
|
MessagePaginatorState,
|
|
27
25
|
MessageQueryShape,
|
|
28
|
-
|
|
26
|
+
PreparedExternalQuery,
|
|
27
|
+
ReconcileNewestMessagesOptions,
|
|
29
28
|
} from './MessageIntervalPaginator';
|
|
30
29
|
export { MessageIntervalPaginator } from './MessageIntervalPaginator';
|
|
31
30
|
|
|
32
31
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* advanced monotonically as newer messages are ingested.
|
|
32
|
+
* Whole-collection aggregates, independent of the active pagination interval. `latestMessageAt` is
|
|
33
|
+
* the time of the channel's latest message and orders the channel list
|
|
34
|
+
* (`channel.messagePaginator.latestMessageAt`): the later of
|
|
35
|
+
* {@link MessagePaginatorAggregateState.latestMessage}'s `created_at` and the `last_message_at` of
|
|
36
|
+
* the latest channel or thread response.
|
|
39
37
|
*/
|
|
40
38
|
export type MessagePaginatorAggregateState = {
|
|
41
39
|
/**
|
|
42
|
-
* The newest
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
40
|
+
* The newest message the client holds that counts as the channel's latest, from any loaded
|
|
41
|
+
* interval or from an event. Not necessarily the server's latest message: when the client does
|
|
42
|
+
* not hold that one, {@link MessagePaginator.latestMessageAt} is later than its `created_at` (see
|
|
43
|
+
* {@link MessagePaginator.latestMessage}). For display (latest-message preview, latest-reply
|
|
44
|
+
* avatar). A live reference: it advances to a strictly newer message, is refreshed in place on
|
|
45
|
+
* edit, soft-delete or reaction, and is recomputed when hard-removed. Follows
|
|
46
|
+
* `shouldAdvanceLatestMessage` (skips `error` and `ephemeral` messages and thread-only replies).
|
|
47
|
+
* `null` until one is ingested.
|
|
47
48
|
*
|
|
48
|
-
*
|
|
49
|
-
* the head interval while an older
|
|
50
|
-
* active* interval is impacted (see `BasePaginator.ingestItem`), so a `state`-derived latest would
|
|
51
|
-
* go stale in that case.
|
|
49
|
+
* It lives outside pagination `state`, which only emits when the active interval is affected: a
|
|
50
|
+
* message landing in the head interval while an older interval is active would go stale there.
|
|
52
51
|
*/
|
|
53
|
-
|
|
52
|
+
latestMessage: LocalMessage | null;
|
|
54
53
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
54
|
+
* The `last_message_at` of the latest channel or thread query result (`ChannelResponse` or
|
|
55
|
+
* `ThreadStateResponse`). It comes with the channel or thread data rather than with a message, so
|
|
56
|
+
* the message it refers to may not be loaded. Each query result that carries it replaces it (see
|
|
57
|
+
* {@link MessagePaginator.setQueriedLatestMessageAt}); events never set it, as a new message from
|
|
58
|
+
* an event updates {@link latestMessage} instead. When the newest message is hard-deleted, it
|
|
59
|
+
* moves back to the previous loaded message; a truncation clears it. `null` when the query
|
|
60
|
+
* reported no messages.
|
|
61
|
+
*
|
|
62
|
+
* {@link MessagePaginator.latestMessageAt} is the later of this and {@link latestMessage}'s
|
|
63
|
+
* `created_at`, so it can be later than the message shown as the latest.
|
|
60
64
|
*/
|
|
61
|
-
|
|
65
|
+
queriedLatestMessageAt: TimestampNS | null;
|
|
62
66
|
};
|
|
63
67
|
|
|
64
68
|
export type MessagePaginatorOptions = BaseMessagePaginatorOptions & {
|
|
65
69
|
/**
|
|
66
|
-
*
|
|
67
|
-
* state
|
|
68
|
-
*
|
|
69
|
-
* - 'snapshot' (default): retrieve the first unread message id from the unreadStateSnapshot state when jumping to the first unread message
|
|
70
|
-
* - 'read-state-only': retrieve the last read message id from the channel read state when jumping to the first unread message
|
|
70
|
+
* Where `jumpToTheFirstUnreadMessage()` reads the unread reference from: `'snapshot'`
|
|
71
|
+
* prefers `unreadStateSnapshot`, `'read-state-only'` uses only `channel.state.read[...]`.
|
|
72
|
+
* Defaults to `'snapshot'`.
|
|
71
73
|
*/
|
|
72
74
|
unreadReferencePolicy?: 'snapshot' | 'read-state-only';
|
|
73
75
|
};
|
|
74
76
|
|
|
75
77
|
export type UnreadSnapshotState = {
|
|
76
|
-
lastReadAt:
|
|
78
|
+
lastReadAt: TimestampNS | null;
|
|
77
79
|
unreadCount: number;
|
|
78
80
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* may mark the channel read immediately on open, while still wanting to render
|
|
82
|
-
* UI indicators that jump to the previously-unread location.
|
|
81
|
+
* First unread message ID. Decoupled from `channel.state.read[...]` because apps may mark the
|
|
82
|
+
* channel read on open yet still want UI that jumps to the previously unread location.
|
|
83
83
|
*/
|
|
84
84
|
firstUnreadMessageId: string | null;
|
|
85
|
-
/**
|
|
86
|
-
* Snapshot of the last read message id for the user (fallback when first unread
|
|
87
|
-
* is not known).
|
|
88
|
-
*/
|
|
85
|
+
/** Last read message ID, a fallback when the first unread is unknown. */
|
|
89
86
|
lastReadMessageId: string | null;
|
|
90
87
|
};
|
|
91
88
|
|
|
92
89
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* snapshot bump is skipped), so the "N new" separator/banner never flash for a message the user is
|
|
97
|
-
* already looking at. Defaults to `false` (assume not viewing until the SDK proves otherwise).
|
|
90
|
+
* Set by the owning SDK (the state layer has no viewport): `true` while the user views the latest
|
|
91
|
+
* messages (app foregrounded and newest message on screen). While live, an incoming message does
|
|
92
|
+
* not bump the unread count or snapshot. Defaults to `false`.
|
|
98
93
|
*/
|
|
99
94
|
export type LiveViewState = {
|
|
100
95
|
isViewingLive: boolean;
|
|
101
96
|
};
|
|
102
97
|
|
|
103
98
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* the "jump to first unread" navigation built on top of them.
|
|
99
|
+
* Adds the unread snapshot, the UI-driven live-view signal and "jump to first unread" navigation to
|
|
100
|
+
* {@link MessageIntervalPaginator}.
|
|
107
101
|
*/
|
|
108
102
|
export class MessagePaginator extends MessageIntervalPaginator {
|
|
103
|
+
protected get holderName() {
|
|
104
|
+
return 'message-paginator';
|
|
105
|
+
}
|
|
109
106
|
private unreadReferencePolicy: 'snapshot' | 'read-state-only';
|
|
110
107
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
108
|
+
* Unread reference state, independent of `channel.state.read`. Seeded on each first page;
|
|
109
|
+
* consumers may also set it before `markRead`.
|
|
113
110
|
*/
|
|
114
111
|
readonly unreadStateSnapshot: StateStore<UnreadSnapshotState>;
|
|
115
112
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* this store for reactivity, or read the current boolean directly via the {@link isViewingLive} getter.
|
|
113
|
+
* The "viewing the latest messages" signal ({@link LiveViewState}), set via {@link setViewingLive}
|
|
114
|
+
* and read by the channel to gate the unread bump on `message.new`.
|
|
119
115
|
*/
|
|
120
116
|
readonly liveViewState: StateStore<LiveViewState>;
|
|
121
117
|
/**
|
|
122
|
-
*
|
|
123
|
-
* from `state`
|
|
124
|
-
*
|
|
125
|
-
* emits when the aggregate actually changes (not on every scroll/pagination emission). This is
|
|
126
|
-
* distinct from the base's `intervalViews` interval-projection store.
|
|
118
|
+
* {@link MessagePaginatorAggregateState}, in a store apart from `state` so `latestMessage` can
|
|
119
|
+
* advance from inside a `state.next` updater (`ingestPage`) and subscribers only see aggregate
|
|
120
|
+
* changes.
|
|
127
121
|
*/
|
|
128
122
|
readonly aggregateState: StateStore<MessagePaginatorAggregateState>;
|
|
129
123
|
|
|
@@ -131,21 +125,14 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
131
125
|
{ unreadReferencePolicy = 'snapshot', ...options }: MessagePaginatorOptions,
|
|
132
126
|
builtInDefaults: Partial<BasePaginatorConfig<LocalMessage, MessageQueryShape>> = {},
|
|
133
127
|
) {
|
|
134
|
-
super(
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
options
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
// A default rather than a construction argument, so `paginatorOptions.stateThrottleMs` and a
|
|
143
|
-
// declarative registration both override it — and so a re-derivation restores it without the
|
|
144
|
-
// subclass having to re-inject it, which is what the old `initializeConfig` override existed for.
|
|
145
|
-
stateThrottleMs: 500,
|
|
146
|
-
...builtInDefaults,
|
|
147
|
-
},
|
|
148
|
-
);
|
|
128
|
+
super(options, {
|
|
129
|
+
// Coalesce live `state.items` publishes to one per 500ms (leading + trailing). Optimistic
|
|
130
|
+
// (local-user) writes bypass it via `EntityStore.flushSubscribers`. A default, so
|
|
131
|
+
// `stateThrottleMs` options and declarative registrations override it and a re-derivation
|
|
132
|
+
// restores it.
|
|
133
|
+
stateThrottleMs: 500,
|
|
134
|
+
...builtInDefaults,
|
|
135
|
+
});
|
|
149
136
|
this.unreadReferencePolicy = unreadReferencePolicy;
|
|
150
137
|
this.unreadStateSnapshot = new StateStore<UnreadSnapshotState>({
|
|
151
138
|
lastReadAt: null,
|
|
@@ -157,153 +144,476 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
157
144
|
isViewingLive: false,
|
|
158
145
|
});
|
|
159
146
|
this.aggregateState = new StateStore<MessagePaginatorAggregateState>({
|
|
160
|
-
|
|
161
|
-
|
|
147
|
+
latestMessage: null,
|
|
148
|
+
queriedLatestMessageAt: null,
|
|
162
149
|
});
|
|
163
150
|
}
|
|
164
151
|
|
|
165
152
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
153
|
+
* The time of the channel's latest message as far as the client knows: the later of
|
|
154
|
+
* {@link latestMessage}'s `created_at` and the `last_message_at` of the latest response (see
|
|
155
|
+
* {@link setQueriedLatestMessageAt}). Later than {@link latestMessage} when the server has newer
|
|
156
|
+
* messages the client does not hold. The channel-list sort key. **Derived** (never stored) so it
|
|
157
|
+
* cannot drift from {@link latestMessage}. A system message that does not move `last_message_at`
|
|
158
|
+
* (see {@link isSkippedSystemMessage}) does not count: the newest loaded message that does is
|
|
159
|
+
* used instead. `null` until a query sets it or a message is ingested.
|
|
169
160
|
*/
|
|
170
|
-
get
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
161
|
+
get latestMessageAt(): TimestampNS | null {
|
|
162
|
+
return this.latestMessageAtIncluding(this.latestMessageAtSource);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** The newest loaded message that moves `last_message_at`, which {@link latestMessageAt} reads. */
|
|
166
|
+
private get latestMessageAtSource(): LocalMessage | null {
|
|
167
|
+
const { latestMessage } = this.aggregateState.getLatestValue();
|
|
168
|
+
return this.isSkippedSystemMessage(latestMessage)
|
|
169
|
+
? this.recomputeLatestMessage({ counts: this.movesLastMessageAt })
|
|
170
|
+
: latestMessage;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* {@link latestMessageAt} as the server knows it (see {@link pageReachesHead}): an unsent latest
|
|
175
|
+
* message carries the device's clock, so the latest server-known message counts in its place.
|
|
176
|
+
*/
|
|
177
|
+
private get latestServerMessageAt(): TimestampNS | null {
|
|
178
|
+
const { latestMessage } = this.aggregateState.getLatestValue();
|
|
179
|
+
const isUnsent = !!latestMessage && !this.isServerConfirmedMessage(latestMessage);
|
|
180
|
+
return this.latestMessageAtIncluding(
|
|
181
|
+
isUnsent || this.isSkippedSystemMessage(latestMessage)
|
|
182
|
+
? this.recomputeLatestMessage({
|
|
183
|
+
counts: this.movesLastMessageAt,
|
|
184
|
+
serverConfirmedOnly: true,
|
|
185
|
+
})
|
|
186
|
+
: latestMessage,
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** The later of `message`'s `created_at` and the queried `last_message_at`. */
|
|
191
|
+
private latestMessageAtIncluding(message: LocalMessage | null): TimestampNS | null {
|
|
192
|
+
const { queriedLatestMessageAt } = this.aggregateState.getLatestValue();
|
|
193
|
+
const fromMessage = getMessageCreatedAtTimestamp(message);
|
|
194
|
+
if (fromMessage !== null && queriedLatestMessageAt !== null) {
|
|
195
|
+
return asTimestampNS(Math.max(fromMessage, queriedLatestMessageAt));
|
|
175
196
|
}
|
|
176
|
-
return fromMessage ??
|
|
197
|
+
return fromMessage ?? queriedLatestMessageAt;
|
|
177
198
|
}
|
|
178
199
|
|
|
179
200
|
/**
|
|
180
|
-
* The newest
|
|
181
|
-
*
|
|
182
|
-
*
|
|
201
|
+
* The newest message the client holds that counts as the channel's latest (see
|
|
202
|
+
* {@link shouldAdvanceLatestMessage}), from any loaded interval or from an event. Not necessarily
|
|
203
|
+
* the server's latest message: {@link latestMessageAt} is later than its `created_at` when the
|
|
204
|
+
* server has newer messages the client does not hold. `null` until a message is ingested (a
|
|
205
|
+
* `last_message_at` from a query sets {@link latestMessageAt} but leaves this `null`).
|
|
206
|
+
* Convenience read of {@link aggregateState}; subscribe to `aggregateState` for reactivity.
|
|
207
|
+
*
|
|
208
|
+
* It differs from {@link anchoredHeadItem}, the newest message of the interval known to reach the
|
|
209
|
+
* server's latest message, in two ways:
|
|
210
|
+
* - It skips messages that do not count: an `error` message can be `anchoredHeadItem` but never
|
|
211
|
+
* `latestMessage`.
|
|
212
|
+
* - It does not need that interval. A channel opened at its first unread message loads m40–m60
|
|
213
|
+
* while the server's newest is m95: `latestMessage` is m60, `latestMessageAt` is m95's time and
|
|
214
|
+
* `anchoredHeadItem` is `undefined`.
|
|
183
215
|
*/
|
|
184
|
-
get
|
|
185
|
-
return this.aggregateState.getLatestValue().
|
|
216
|
+
get latestMessage(): LocalMessage | null {
|
|
217
|
+
return this.aggregateState.getLatestValue().latestMessage;
|
|
186
218
|
}
|
|
187
219
|
|
|
188
220
|
/**
|
|
189
|
-
* The
|
|
190
|
-
*
|
|
191
|
-
* not
|
|
192
|
-
*
|
|
193
|
-
* `Channel._trackLastMessage` skip logic.
|
|
221
|
+
* The newest server-confirmed message of the interval that reaches the newest message (see
|
|
222
|
+
* {@link anchoredHeadItems}). Any message the interval holds counts, system messages included, but
|
|
223
|
+
* not an unsent one: its id is local. `undefined` while that interval is not loaded or holds no
|
|
224
|
+
* server-confirmed message.
|
|
194
225
|
*
|
|
195
|
-
*
|
|
196
|
-
|
|
197
|
-
|
|
226
|
+
* @internal
|
|
227
|
+
*/
|
|
228
|
+
get anchoredHeadServerConfirmedItem(): LocalMessage | undefined {
|
|
229
|
+
const head = this.anchoredHeadInterval;
|
|
230
|
+
return head ? this.getServerKnownEdges(head).head : undefined;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Whether `message` counts as the channel's latest message: not shadowed, not an `error` or
|
|
235
|
+
* `ephemeral` message (only the current user sees those, e.g. a failed command or a giphy preview)
|
|
236
|
+
* and, in the main list, not a thread-only reply. A reply list (`parentMessageId` set) holds only
|
|
237
|
+
* thread replies, so the thread-only rule does not apply there.
|
|
198
238
|
*/
|
|
199
|
-
protected
|
|
239
|
+
protected shouldAdvanceLatestMessage(message: LocalMessage): boolean {
|
|
200
240
|
if (message.shadowed) return false;
|
|
241
|
+
if (message.type === 'error' || message.type === 'ephemeral') return false;
|
|
201
242
|
if (this.parentMessageId) return true;
|
|
202
|
-
|
|
203
|
-
if (isThreadOnlyReply) return false;
|
|
204
|
-
const skipSystemMessage =
|
|
205
|
-
!!this.channel.serverConfig?.skip_last_msg_update_for_system_msgs &&
|
|
206
|
-
message.type === 'system';
|
|
207
|
-
return !skipSystemMessage;
|
|
243
|
+
return !isThreadOnlyReply(message);
|
|
208
244
|
}
|
|
209
245
|
|
|
210
246
|
/**
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
* updater (`ingestPage`). Returns `true` when the value moved.
|
|
215
|
-
*
|
|
216
|
-
* Called internally on ingest; also public for callers that advance the aggregate without a normal
|
|
217
|
-
* in-window ingest — e.g. offline pending-message replay, where the sent message has not yet been
|
|
218
|
-
* ingested via the `message.new` event.
|
|
247
|
+
* Whether `message` is a main-list system message that, with
|
|
248
|
+
* `skip_last_msg_update_for_system_msgs`, does not move the channel's `last_message_at` on the
|
|
249
|
+
* server. It is still shown as the {@link latestMessage}, but {@link latestMessageAt} skips it.
|
|
219
250
|
*/
|
|
220
|
-
|
|
221
|
-
|
|
251
|
+
private isSkippedSystemMessage(message: LocalMessage | null): boolean {
|
|
252
|
+
return (
|
|
253
|
+
!!message &&
|
|
254
|
+
!this.parentMessageId &&
|
|
255
|
+
message.type === 'system' &&
|
|
256
|
+
!!this.channel.serverConfig?.skip_last_msg_update_for_system_msgs
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Whether `message` counts for {@link latestMessageAt}. */
|
|
261
|
+
private movesLastMessageAt = (message: LocalMessage) =>
|
|
262
|
+
this.shouldAdvanceLatestMessage(message) && !this.isSkippedSystemMessage(message);
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Advances {@link latestMessage} (and so {@link latestMessageAt}) to `message` when it is newer
|
|
266
|
+
* and {@link shouldAdvanceLatestMessage} permits. Writes {@link aggregateState} only, so it is
|
|
267
|
+
* safe inside a `state.next` updater (`ingestPage`). Returns `true` when the value moved. Public
|
|
268
|
+
* for callers that advance it without an in-interval ingest, e.g. offline pending-message replay.
|
|
269
|
+
*/
|
|
270
|
+
trackLatestMessage(message: LocalMessage): boolean {
|
|
271
|
+
const current = this.aggregateState.getLatestValue().latestMessage;
|
|
272
|
+
if (!this.shouldAdvanceLatestMessage(message)) {
|
|
273
|
+
if (current?.id !== message.id) return false;
|
|
274
|
+
this.aggregateState.partialNext({
|
|
275
|
+
latestMessage: this.recomputeLatestMessage({ excludeId: message.id }),
|
|
276
|
+
});
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
222
279
|
const incoming = getMessageCreatedAtTimestamp(message);
|
|
223
280
|
if (incoming === null) return false;
|
|
224
|
-
|
|
225
|
-
//
|
|
226
|
-
// reaction, or quoted-message update all re-ingest the same id (same `created_at`). This keeps
|
|
227
|
-
// `lastMessage` a LIVE reference (so a preview shows "deleted"/edited text), and because
|
|
228
|
-
// `aggregateState` emits regardless of the active interval, it stays reactive off-window.
|
|
281
|
+
// An edit, soft-delete, reaction or quote update re-ingests the current latest (same ID and
|
|
282
|
+
// `created_at`): refresh it in place so `latestMessage` stays live.
|
|
229
283
|
if (current && current.id === message.id) {
|
|
230
|
-
this.aggregateState.partialNext({
|
|
284
|
+
this.aggregateState.partialNext({ latestMessage: message });
|
|
231
285
|
return true;
|
|
232
286
|
}
|
|
233
|
-
// Otherwise only
|
|
234
|
-
// timestamp
|
|
235
|
-
//
|
|
287
|
+
// Otherwise only a strictly newer message advances. Compare against the current message's own
|
|
288
|
+
// timestamp, not `latestMessageAt`: a queried `last_message_at` newer than the loaded interval
|
|
289
|
+
// would reject the message.
|
|
236
290
|
const currentTs = current ? getMessageCreatedAtTimestamp(current) : null;
|
|
237
291
|
if (currentTs !== null && incoming <= currentTs) return false;
|
|
238
|
-
this.aggregateState.partialNext({
|
|
292
|
+
this.aggregateState.partialNext({ latestMessage: message });
|
|
239
293
|
return true;
|
|
240
294
|
}
|
|
241
295
|
|
|
242
296
|
/**
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
297
|
+
* Sets {@link MessagePaginatorAggregateState.queriedLatestMessageAt} from a query result's
|
|
298
|
+
* `last_message_at` (a channel's, or a thread's for a reply list), which {@link latestMessageAt}
|
|
299
|
+
* then takes into account. Each result replaces the previous value, even with an earlier one:
|
|
300
|
+
* the newest message may have been hard-deleted, which no event reports with the new value. A
|
|
301
|
+
* message ingested after the result was produced, such as a new one from an event, still counts,
|
|
302
|
+
* through {@link latestMessage}. `null` clears it (no messages); `undefined` (not in the result)
|
|
303
|
+
* leaves it.
|
|
304
|
+
*/
|
|
305
|
+
setQueriedLatestMessageAt(value: TimestampNS | null | undefined) {
|
|
306
|
+
if (value === undefined) return;
|
|
307
|
+
const next = value !== null && Number.isFinite(value) ? value : null;
|
|
308
|
+
if (next === this.aggregateState.getLatestValue().queriedLatestMessageAt) return;
|
|
309
|
+
this.aggregateState.partialNext({ queriedLatestMessageAt: next });
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Clears the head mark of the head interval when it is stale (see {@link unmarkHead}). It is stale
|
|
314
|
+
* when its newest message is older than the `last_message_at` the latest query returned (see
|
|
315
|
+
* {@link setQueriedLatestMessageAt}): the channel has newer messages the interval lacks. The
|
|
316
|
+
* interval then stops being the head interval ({@link anchoredHeadItem} becomes `undefined`) and
|
|
317
|
+
* can load newer messages, and a message that then arrives from an event starts a separate head
|
|
318
|
+
* interval instead of joining it across the gap. Messages that exist only locally, such as a
|
|
319
|
+
* failed send, are left out of the comparison: they carry the device's clock.
|
|
320
|
+
*
|
|
321
|
+
* For example, the interval holds m1–m20 and the channel is not watched while m21–m25 are sent. A
|
|
322
|
+
* query returns m25's time: the interval can now load m21–m25, and m26 from an event does not land
|
|
323
|
+
* right after m20.
|
|
324
|
+
*
|
|
325
|
+
* Call it with each response that does not bring the newest messages up to date, before any page
|
|
326
|
+
* the response carries is placed: a page that reaches the newest message marks its own interval as
|
|
327
|
+
* the head. Call it only when no events were arriving before the response and nothing else
|
|
328
|
+
* brings the newest messages: while the channel is watched, a message the interval lacks is still
|
|
329
|
+
* on its way, and a re-watch that places the newest page settles the interval itself.
|
|
330
|
+
*/
|
|
331
|
+
unmarkStaleHead() {
|
|
332
|
+
const head = this.anchoredHeadInterval;
|
|
333
|
+
const { queriedLatestMessageAt } = this.aggregateState.getLatestValue();
|
|
334
|
+
if (!head || queriedLatestMessageAt === null) return;
|
|
335
|
+
let headNewestAt: TimestampNS | null = null;
|
|
336
|
+
for (const message of this.intervalToItems(head)) {
|
|
337
|
+
if (!this.isServerConfirmedMessage(message)) continue;
|
|
338
|
+
const createdAt = getMessageCreatedAtTimestamp(message);
|
|
339
|
+
if (createdAt !== null && (headNewestAt === null || createdAt > headNewestAt))
|
|
340
|
+
headNewestAt = createdAt;
|
|
341
|
+
}
|
|
342
|
+
if (headNewestAt !== null && headNewestAt >= queriedLatestMessageAt) return;
|
|
343
|
+
this.unmarkHead(head);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* A page reaches the newest message when its newest message is at or after
|
|
348
|
+
* {@link latestServerMessageAt}, as known before the page is ingested; one older than that is not
|
|
349
|
+
* the newest. That value comes from the latest response (`ChannelResponse` for a channel,
|
|
350
|
+
* `ThreadStateResponse` for a reply list, through {@link setQueriedLatestMessageAt}) and from the
|
|
351
|
+
* messages ingested since, such as new ones from events. `undefined` while it is not known.
|
|
246
352
|
*/
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
353
|
+
protected override pageReachesHead(page: LocalMessage[]): boolean | undefined {
|
|
354
|
+
const latestServerMessageAt = this.latestServerMessageAt;
|
|
355
|
+
if (latestServerMessageAt === null) return undefined;
|
|
356
|
+
// the page's newest message is at its head edge
|
|
357
|
+
const createdAt = getMessageCreatedAtTimestamp(
|
|
358
|
+
this.getPagePaginationEdges(page).head,
|
|
359
|
+
);
|
|
360
|
+
return createdAt !== null && createdAt >= latestServerMessageAt;
|
|
252
361
|
}
|
|
253
362
|
|
|
363
|
+
/**
|
|
364
|
+
* Ingests a single message, from an event or an operation such as a send. A message that starts
|
|
365
|
+
* the newest interval is placed by {@link ingestAsNewestInterval}. Any other goes into the
|
|
366
|
+
* interval it belongs to and the active interval stays active, except for the current user's new
|
|
367
|
+
* send (see {@link isOwnSendWhileOlderIntervalIsActive}): the newest interval holding it is
|
|
368
|
+
* shown, so the user sees what they sent.
|
|
369
|
+
*/
|
|
254
370
|
ingestItem(item: LocalMessage): boolean {
|
|
255
|
-
// Only items
|
|
256
|
-
// of items that no longer match). The advance writes the separate `aggregateState` store, so it
|
|
257
|
-
// is independent of `super`'s `state`/index mutations.
|
|
371
|
+
// Only items passing the filter advance the aggregate (`ingestItem` also removes the others).
|
|
258
372
|
if (this.matchesFilter(item)) {
|
|
259
|
-
this.
|
|
373
|
+
if (this.isNewNewestMessage(item)) return this.ingestAsNewestInterval(item);
|
|
374
|
+
this.trackLatestMessage(item);
|
|
375
|
+
}
|
|
376
|
+
// judged before ingesting, while the message is not held yet
|
|
377
|
+
const showsNewestInterval = this.isOwnSendWhileOlderIntervalIsActive(item);
|
|
378
|
+
const ingested = super.ingestItem(item);
|
|
379
|
+
const newest = this.anchoredHeadInterval;
|
|
380
|
+
if (ingested && showsNewestInterval && newest?.itemIds.includes(item.id)) {
|
|
381
|
+
this.showIntervalOfOwnSend(newest);
|
|
260
382
|
}
|
|
261
|
-
return
|
|
383
|
+
return ingested;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Whether `message` is the current user's own send (see {@link isOwnSend}) that the paginator
|
|
388
|
+
* does not hold yet, while the newest interval is loaded but another interval is active. A message
|
|
389
|
+
* already held (a retry of a failed send, a replayed send, its server confirmation) is not new.
|
|
390
|
+
*/
|
|
391
|
+
private isOwnSendWhileOlderIntervalIsActive(message: LocalMessage): boolean {
|
|
392
|
+
const newest = this.anchoredHeadInterval;
|
|
393
|
+
return (
|
|
394
|
+
!!newest &&
|
|
395
|
+
!this.isActiveInterval(newest) &&
|
|
396
|
+
!this.getItem(message.id) &&
|
|
397
|
+
this.isOwnSend(message)
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Shows the interval holding the current user's own send. The send decides the interval shown, so
|
|
403
|
+
* it claims the active interval as a jump does: a page a query claimed earlier is then only
|
|
404
|
+
* stored.
|
|
405
|
+
*/
|
|
406
|
+
private showIntervalOfOwnSend(interval: Interval) {
|
|
407
|
+
this.claimActiveInterval();
|
|
408
|
+
this.showLoadedInterval(interval);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* A message the paginator does not hold yet, at or after {@link latestMessageAt} (as known before
|
|
413
|
+
* it arrives), while no loaded interval reaches the newest message. It is then the newest message,
|
|
414
|
+
* so it starts the newest interval, as a page holding it would (see {@link pageReachesHead}).
|
|
415
|
+
*/
|
|
416
|
+
private isNewNewestMessage(message: LocalMessage): boolean {
|
|
417
|
+
if (this.anchoredHeadItem !== undefined || this.getItem(message.id)) return false;
|
|
418
|
+
const latestMessageAt = this.latestMessageAt;
|
|
419
|
+
const createdAt = getMessageCreatedAtTimestamp(message);
|
|
420
|
+
return latestMessageAt !== null && createdAt !== null && createdAt >= latestMessageAt;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* The logical-head items (ingested one by one, usually from events, rather than as part of a
|
|
425
|
+
* page) not older than `queriedLatestMessageAt`, the `last_message_at` of the latest channel or
|
|
426
|
+
* thread response; all of them when no response has set it. They were ingested after that
|
|
427
|
+
* response, one after another, so nothing is missing between them. Items older than that, such as
|
|
428
|
+
* a message arriving out of order, are left out.
|
|
429
|
+
*/
|
|
430
|
+
private get logicalHeadItemsSinceQueriedLatestMessageAt(): LocalMessage[] {
|
|
431
|
+
const { queriedLatestMessageAt } = this.aggregateState.getLatestValue();
|
|
432
|
+
return this.logicalHeadItems.filter((item) => {
|
|
433
|
+
const createdAt = getMessageCreatedAtTimestamp(item);
|
|
434
|
+
return (
|
|
435
|
+
queriedLatestMessageAt === null ||
|
|
436
|
+
(createdAt !== null && createdAt >= queriedLatestMessageAt)
|
|
437
|
+
);
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Starts the newest interval with `message`, together with the
|
|
443
|
+
* {@link logicalHeadItemsSinceQueriedLatestMessageAt} ingested before it. It can load older
|
|
444
|
+
* messages unless none are left to load (see {@link hasNoMessagesBeforeLiveMessages}). It becomes
|
|
445
|
+
* the active interval when no interval was active, when the logical head it takes items from was,
|
|
446
|
+
* or when `message` is the current user's own send (see {@link isOwnSend}), as every own send
|
|
447
|
+
* shows the newest interval (see {@link ingestItem}).
|
|
448
|
+
*/
|
|
449
|
+
private ingestAsNewestInterval(message: LocalMessage): boolean {
|
|
450
|
+
const liveHead = this.liveHeadLogical;
|
|
451
|
+
const interval = this.ingestPage({
|
|
452
|
+
page: [...this.logicalHeadItemsSinceQueriedLatestMessageAt, message],
|
|
453
|
+
isHead: true,
|
|
454
|
+
isTail: this.hasNoMessagesBeforeLiveMessages,
|
|
455
|
+
setActive: false,
|
|
456
|
+
});
|
|
457
|
+
if (!interval) return false;
|
|
458
|
+
|
|
459
|
+
if (this.isOwnSend(message)) {
|
|
460
|
+
this.showIntervalOfOwnSend(interval);
|
|
461
|
+
} else if (
|
|
462
|
+
!this._activeIntervalId ||
|
|
463
|
+
(!!liveHead && this.isActiveInterval(liveHead))
|
|
464
|
+
) {
|
|
465
|
+
this.showLoadedInterval(interval);
|
|
466
|
+
}
|
|
467
|
+
return true;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Whether no message older than the live messages is left to load: no interval of queried messages
|
|
472
|
+
* is loaded and the list reports no older messages, as after a newest page that came back empty.
|
|
473
|
+
* A list never queried, or one holding an interval (a jumped-to one, or one whose head mark was
|
|
474
|
+
* cleared), has older messages to load.
|
|
475
|
+
*/
|
|
476
|
+
private get hasNoMessagesBeforeLiveMessages(): boolean {
|
|
477
|
+
return (
|
|
478
|
+
this.hasMoreTail === false &&
|
|
479
|
+
this.itemIntervals.every((interval) => isLogicalInterval(interval))
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Whether `message` is one the current user is sending from this device: status `sending` and
|
|
485
|
+
* authored by the client's user. The same user's message from another device arrives
|
|
486
|
+
* server-confirmed and is not one.
|
|
487
|
+
*/
|
|
488
|
+
private isOwnSend(message: LocalMessage): boolean {
|
|
489
|
+
return message.status === 'sending' && this.isOwnMessage(message);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** Whether the client's user wrote `message`; never for a paginator without a client. */
|
|
493
|
+
private isOwnMessage(message: LocalMessage): boolean {
|
|
494
|
+
const userId = this.channel.getClient?.()?.userId;
|
|
495
|
+
return !!userId && message.user?.id === userId;
|
|
262
496
|
}
|
|
263
497
|
|
|
264
498
|
ingestPage(
|
|
265
499
|
params: Parameters<MessageIntervalPaginator['ingestPage']>[0],
|
|
266
500
|
): Interval | null {
|
|
267
501
|
const interval = super.ingestPage(params);
|
|
268
|
-
// Advance from each page item; the monotonic max over the page yields the newest. Comparison is
|
|
269
|
-
// by `created_at` against `aggregateState` (no index lookup), so order vs `super` is irrelevant.
|
|
270
502
|
if (params.page?.length) {
|
|
271
|
-
for (const item of params.page) this.
|
|
503
|
+
for (const item of params.page) this.trackLatestMessage(item);
|
|
272
504
|
}
|
|
273
505
|
return interval;
|
|
274
506
|
}
|
|
275
507
|
|
|
508
|
+
onEntitiesChanged(batch: EntityStoreChangeBatch) {
|
|
509
|
+
super.onEntitiesChanged(batch);
|
|
510
|
+
const { latestMessage } = this.aggregateState.getLatestValue();
|
|
511
|
+
if (!latestMessage || !batch.changedIds.has(latestMessage.id)) return;
|
|
512
|
+
const stored = this.getItem(latestMessage.id);
|
|
513
|
+
if (!stored) return;
|
|
514
|
+
this.aggregateState.partialNext({
|
|
515
|
+
latestMessage: this.shouldAdvanceLatestMessage(stored)
|
|
516
|
+
? stored
|
|
517
|
+
: this.recomputeLatestMessage({ excludeId: stored.id }),
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
reflectUserUpdate(user: UserResponse) {
|
|
522
|
+
super.reflectUserUpdate(user);
|
|
523
|
+
const { latestMessage } = this.aggregateState.getLatestValue();
|
|
524
|
+
if (latestMessage?.user?.id !== user.id) return;
|
|
525
|
+
this.aggregateState.partialNext({ latestMessage: { ...latestMessage, user } });
|
|
526
|
+
}
|
|
527
|
+
|
|
276
528
|
removeItem(
|
|
277
529
|
params: Parameters<MessageIntervalPaginator['removeItem']>[0],
|
|
278
530
|
): ReturnType<MessageIntervalPaginator['removeItem']> {
|
|
279
531
|
const removedId =
|
|
280
532
|
params.id ?? (params.item ? this.getItemId(params.item) : undefined);
|
|
281
|
-
const
|
|
282
|
-
|
|
533
|
+
const { latestMessage, queriedLatestMessageAt } =
|
|
534
|
+
this.aggregateState.getLatestValue();
|
|
535
|
+
const wasLatest = !!removedId && latestMessage?.id === removedId;
|
|
536
|
+
// A skipped system message can be the latest without moving `last_message_at`, so the message
|
|
537
|
+
// that did can be another one.
|
|
538
|
+
const latestMessageAtSource = removedId ? this.latestMessageAtSource : null;
|
|
539
|
+
const wasLatestMessageAtSource =
|
|
540
|
+
!!removedId && latestMessageAtSource?.id === removedId;
|
|
283
541
|
const result = super.removeItem(params);
|
|
284
|
-
if (wasLatest)
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
542
|
+
if (!wasLatest && !wasLatestMessageAtSource) return result;
|
|
543
|
+
// A tracked message was hard-removed; fall back to the newest still-loaded message that counts,
|
|
544
|
+
// which `trackLatestMessage` cannot do (it only advances).
|
|
545
|
+
const previousAt = wasLatestMessageAtSource
|
|
546
|
+
? getMessageCreatedAtTimestamp(
|
|
547
|
+
this.recomputeLatestMessage({ counts: this.movesLastMessageAt }),
|
|
548
|
+
)
|
|
549
|
+
: null;
|
|
550
|
+
const removedAt = getMessageCreatedAtTimestamp(latestMessageAtSource);
|
|
551
|
+
const isQueriedFromRemovedMessage =
|
|
552
|
+
wasLatestMessageAtSource &&
|
|
553
|
+
queriedLatestMessageAt !== null &&
|
|
554
|
+
removedAt !== null &&
|
|
555
|
+
queriedLatestMessageAt <= removedAt;
|
|
556
|
+
// The server moves `last_message_at` back to the previous message without sending it, so the
|
|
557
|
+
// queried value takes the previous loaded message's time. With none loaded the new value is
|
|
558
|
+
// unknown, and it stays.
|
|
559
|
+
this.aggregateState.partialNext({
|
|
560
|
+
latestMessage: wasLatest ? this.recomputeLatestMessage() : latestMessage,
|
|
561
|
+
queriedLatestMessageAt:
|
|
562
|
+
isQueriedFromRemovedMessage && previousAt !== null
|
|
563
|
+
? previousAt
|
|
564
|
+
: queriedLatestMessageAt,
|
|
565
|
+
});
|
|
289
566
|
return result;
|
|
290
567
|
}
|
|
291
568
|
|
|
569
|
+
truncate(params: Parameters<MessageIntervalPaginator['truncate']>[0]) {
|
|
570
|
+
super.truncate(params);
|
|
571
|
+
const { latestMessage, queriedLatestMessageAt } =
|
|
572
|
+
this.aggregateState.getLatestValue();
|
|
573
|
+
const isTruncated = (timestamp: TimestampNS | null) =>
|
|
574
|
+
timestamp !== null && timestamp < params.truncatedAt;
|
|
575
|
+
const isLatestMessageTruncated = isTruncated(
|
|
576
|
+
getMessageCreatedAtTimestamp(latestMessage),
|
|
577
|
+
);
|
|
578
|
+
const isQueriedLatestMessageAtTruncated = isTruncated(queriedLatestMessageAt);
|
|
579
|
+
if (!isLatestMessageTruncated && !isQueriedLatestMessageAtTruncated) return;
|
|
580
|
+
this.aggregateState.partialNext({
|
|
581
|
+
latestMessage: isLatestMessageTruncated
|
|
582
|
+
? this.recomputeLatestMessage()
|
|
583
|
+
: latestMessage,
|
|
584
|
+
queriedLatestMessageAt: isQueriedLatestMessageAtTruncated
|
|
585
|
+
? null
|
|
586
|
+
: queriedLatestMessageAt,
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
|
|
292
590
|
/**
|
|
293
|
-
* The still-loaded message with the greatest `created_at` that
|
|
294
|
-
* {@link
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
591
|
+
* The still-loaded message with the greatest `created_at` that `counts` (by default
|
|
592
|
+
* {@link shouldAdvanceLatestMessage}), from the interval that reaches the newest message and the
|
|
593
|
+
* {@link logicalHeadItemsSinceQueriedLatestMessageAt}. An interval reached by a jump is not
|
|
594
|
+
* searched, nor an out-of-order older message: neither is the channel's previous message. Used to
|
|
595
|
+
* recompute the tracked latest after the current one is removed or stops counting;
|
|
596
|
+
* `serverConfirmedOnly` skips unsent messages and `excludeId` skips that message. `null` when
|
|
597
|
+
* nothing loaded qualifies. It compares timestamps rather than positions, so it holds for any
|
|
598
|
+
* `itemOrder` / `requestSort`.
|
|
301
599
|
*/
|
|
302
|
-
private
|
|
600
|
+
private recomputeLatestMessage({
|
|
601
|
+
counts = (message) => this.shouldAdvanceLatestMessage(message),
|
|
602
|
+
excludeId,
|
|
603
|
+
serverConfirmedOnly = false,
|
|
604
|
+
}: {
|
|
605
|
+
counts?: (message: LocalMessage) => boolean;
|
|
606
|
+
excludeId?: string;
|
|
607
|
+
serverConfirmedOnly?: boolean;
|
|
608
|
+
} = {}): LocalMessage | null {
|
|
303
609
|
let latest: LocalMessage | null = null;
|
|
304
610
|
let latestTimestamp = -Infinity;
|
|
305
|
-
for (const item of
|
|
306
|
-
|
|
611
|
+
for (const item of [
|
|
612
|
+
...this.anchoredHeadItems,
|
|
613
|
+
...this.logicalHeadItemsSinceQueriedLatestMessageAt,
|
|
614
|
+
]) {
|
|
615
|
+
if (item.id === excludeId || !counts(item)) continue;
|
|
616
|
+
if (serverConfirmedOnly && !this.isServerConfirmedMessage(item)) continue;
|
|
307
617
|
const timestamp = getMessageCreatedAtTimestamp(item);
|
|
308
618
|
if (timestamp === null || timestamp <= latestTimestamp) continue;
|
|
309
619
|
latest = item;
|
|
@@ -313,23 +623,18 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
313
623
|
}
|
|
314
624
|
|
|
315
625
|
/**
|
|
316
|
-
* (Re)
|
|
626
|
+
* (Re)seeds the unread snapshot from the own read state. Runs once a first page and the rest of
|
|
627
|
+
* its response are in (the paginator's own first-page queries, `watch()` and the channel-list
|
|
628
|
+
* hydrate, when these place one), and the SDK calls it again when a channel is reopened from a
|
|
629
|
+
* cached paginator (no first-page query), so the separator, unread count and jump target follow
|
|
630
|
+
* the current read boundary.
|
|
317
631
|
*
|
|
318
|
-
*
|
|
319
|
-
* (
|
|
320
|
-
* reflects the CURRENT read boundary rather than one frozen at the very first open. Without a
|
|
321
|
-
* re-seed the separator position, unread count and "jump to first unread" target all go stale
|
|
322
|
-
* across reopens.
|
|
323
|
-
*
|
|
324
|
-
* `firstUnreadMessageId` is intentionally reset to `null`: it represents an EXPLICIT mark-unread
|
|
325
|
-
* (set by `notification.mark_unread`), not a live/computed boundary. Persisting a computed value
|
|
326
|
-
* here would make the channel look explicitly marked-unread and suppress auto-mark-read.
|
|
632
|
+
* `firstUnreadMessageId` is reset to `null`: it holds only an explicit mark-unread
|
|
633
|
+
* (`notification.mark_unread`), and a computed value would suppress auto-mark-read.
|
|
327
634
|
*/
|
|
328
635
|
seedUnreadSnapshot = () => {
|
|
329
|
-
//
|
|
330
|
-
//
|
|
331
|
-
// torn down while that request was in flight, reading the client below throws (the channel is
|
|
332
|
-
// pending disposal), so guard against that.
|
|
636
|
+
// The query awaits the network before this runs: the channel may be pending disposal by then,
|
|
637
|
+
// and `getClient()` throws.
|
|
333
638
|
if (this.channel.pendingDisposal) return;
|
|
334
639
|
const ownUserId = this.channel.getClient().user?.id;
|
|
335
640
|
const ownReadState = ownUserId ? this.channel.state.read[ownUserId] : undefined;
|
|
@@ -343,38 +648,30 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
343
648
|
};
|
|
344
649
|
|
|
345
650
|
/**
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
651
|
+
* Applies the rest of the response, then takes the unread snapshot after a first-page query, from
|
|
652
|
+
* the read state the response brought. A viewed channel is marked read right after it opens, so
|
|
653
|
+
* the snapshot keeps the unread state from before, for unread UI indicators.
|
|
349
654
|
*/
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
if (
|
|
356
|
-
this.seedUnreadSnapshot();
|
|
357
|
-
}
|
|
358
|
-
return result;
|
|
655
|
+
protected override applyQueryResponseRest(
|
|
656
|
+
response: MessageQueryResponse,
|
|
657
|
+
placeParams: QueryPagePlacement<MessageQueryShape>,
|
|
658
|
+
) {
|
|
659
|
+
super.applyQueryResponseRest(response, placeParams);
|
|
660
|
+
if (placeParams.isFirstPage) this.seedUnreadSnapshot();
|
|
359
661
|
}
|
|
360
662
|
|
|
361
663
|
/**
|
|
362
|
-
* Jumps to the unread reference message.
|
|
363
|
-
*
|
|
364
|
-
* IMPORTANT: This intentionally does *not* rely on `channel.state.read[ownUserId]` only,
|
|
365
|
-
* because apps may mark a channel read immediately after opening it, while still
|
|
366
|
-
* wanting to keep "jump to unread" UI indicators alive (based on a snapshot).
|
|
664
|
+
* Jumps to the unread reference message. It does not rely on `channel.state.read` alone, since
|
|
665
|
+
* apps may mark a channel read on open yet keep "jump to unread" UI alive from the snapshot.
|
|
367
666
|
*
|
|
368
667
|
* Resolution order:
|
|
369
|
-
* 1
|
|
370
|
-
* 2
|
|
371
|
-
*
|
|
372
|
-
* 3
|
|
668
|
+
* 1. an explicit first-unread ID (snapshot or read state): jump to it;
|
|
669
|
+
* 2. the last-read timestamp: infer the first unread message from the loaded interval, or from a
|
|
670
|
+
* `created_at_around` query when the interval does not straddle the boundary, and jump to it;
|
|
671
|
+
* 3. the last-read ID, when no timestamp is known.
|
|
373
672
|
*
|
|
374
|
-
* The
|
|
375
|
-
*
|
|
376
|
-
* only used as a fallback when we cannot infer an unread boundary. The inference is NOT persisted
|
|
377
|
-
* back into the snapshot (that is reserved for explicit mark-unread).
|
|
673
|
+
* The inference is not written to the snapshot: `firstUnreadMessageId` is reserved for an explicit
|
|
674
|
+
* mark-unread (it would suppress auto-mark-read).
|
|
378
675
|
*/
|
|
379
676
|
jumpToTheFirstUnreadMessage = async (options?: JumpToMessageOptions) => {
|
|
380
677
|
const ownUserId = this.channel.getClient().user?.id;
|
|
@@ -393,8 +690,6 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
393
690
|
const lastReadAtFromReadState = ownReadState?.last_read ?? null;
|
|
394
691
|
const lastReadIdFromReadState = ownReadState?.last_read_message_id ?? null;
|
|
395
692
|
|
|
396
|
-
// 1) A stable first-unread id is known (mark-unread, or a previously persisted inference):
|
|
397
|
-
// jump straight to it.
|
|
398
693
|
const firstUnreadMessageId = firstUnreadFromSnapshot ?? firstUnreadFromReadState;
|
|
399
694
|
if (firstUnreadMessageId) {
|
|
400
695
|
return await this.jumpToMessage(firstUnreadMessageId, {
|
|
@@ -404,24 +699,11 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
404
699
|
}
|
|
405
700
|
|
|
406
701
|
const lastReadMessageId = lastReadIdFromSnapshot ?? lastReadIdFromReadState;
|
|
407
|
-
//
|
|
408
|
-
//
|
|
409
|
-
//
|
|
410
|
-
// the read-state `last_read` to ~now and clears the server unread — so preferring read-state
|
|
411
|
-
// would make a later banner tap infer "nothing unread" and jump to the latest message. The
|
|
412
|
-
// snapshot is kept fresh on genuine catch-up (the SDK's mark-read resets it), so it is only
|
|
413
|
-
// "frozen" precisely while there are unreads to jump to.
|
|
702
|
+
// The snapshot timestamp wins over the read state's: the snapshot is the frozen boundary the
|
|
703
|
+
// "N new" banner renders from, while mark-read on open advances the read state to ~now, so a
|
|
704
|
+
// banner tap would infer nothing unread and jump to the latest message.
|
|
414
705
|
const lastReadAt = lastReadAtFromSnapshot ?? lastReadAtFromReadState;
|
|
415
706
|
|
|
416
|
-
// 2) No explicit first-unread id, but we know when the channel was last read. Infer the first
|
|
417
|
-
// unread message from that timestamp so we land ON (and highlight) the first unread message
|
|
418
|
-
// instead of the last read one. Prefer the already-loaded window (the common "a few unreads at
|
|
419
|
-
// the bottom" case — no extra request); only query a page around last-read when the loaded
|
|
420
|
-
// window does not straddle the boundary (i.e. every loaded message is newer than last-read).
|
|
421
|
-
//
|
|
422
|
-
// We deliberately do NOT persist the inferred boundary back into the snapshot: writing
|
|
423
|
-
// `firstUnreadMessageId` would make the channel look explicitly marked-unread and suppress
|
|
424
|
-
// auto-mark-read at the bottom. The separator reads the (re-seeded) snapshot directly.
|
|
425
707
|
const lastReadBoundary =
|
|
426
708
|
lastReadAt != null && Number.isFinite(lastReadAt) ? lastReadAt : null;
|
|
427
709
|
|
|
@@ -436,13 +718,16 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
436
718
|
|
|
437
719
|
if (!inferredLastReadMessageId) {
|
|
438
720
|
const result = await this.executeQuery({
|
|
721
|
+
claimsActiveInterval: true,
|
|
439
722
|
queryShape: {
|
|
440
723
|
// `created_at_around` is a request field and still takes a `Date`.
|
|
441
724
|
created_at_around: nsToDate(lastReadBoundary),
|
|
442
|
-
limit: options?.pageSize,
|
|
725
|
+
limit: options?.pageSize ?? this.pageSize,
|
|
443
726
|
},
|
|
444
727
|
updateState: false,
|
|
445
728
|
});
|
|
729
|
+
// a later claim decides the active interval, and the page stays stored
|
|
730
|
+
if (result?.isSuperseded) return false;
|
|
446
731
|
if (result) {
|
|
447
732
|
({
|
|
448
733
|
firstUnreadMessageId: inferredFirstUnreadMessageId,
|
|
@@ -464,7 +749,6 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
464
749
|
}
|
|
465
750
|
}
|
|
466
751
|
|
|
467
|
-
// 3) Last resort: jump to the known last-read message when that is all we have.
|
|
468
752
|
if (lastReadMessageId) {
|
|
469
753
|
return await this.jumpToMessage(lastReadMessageId, {
|
|
470
754
|
...options,
|
|
@@ -480,18 +764,14 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
480
764
|
return this.unreadStateSnapshot.getLatestValue();
|
|
481
765
|
};
|
|
482
766
|
|
|
483
|
-
/**
|
|
484
|
-
* Set the UI-driven "viewing the latest messages" signal (see {@link LiveViewState}). Called by
|
|
485
|
-
* the SDK from its message-list viewability + app-state tracking. No-ops when unchanged.
|
|
486
|
-
*
|
|
487
|
-
* Intentionally NOT reset by `clearStateAndCache` — it is an external input owned by the SDK, not
|
|
488
|
-
* derived pagination state.
|
|
489
|
-
*/
|
|
490
|
-
/** Current "viewing the latest messages" boolean (convenience read of {@link liveViewState}). */
|
|
491
767
|
get isViewingLive(): boolean {
|
|
492
768
|
return this.liveViewState.getLatestValue().isViewingLive;
|
|
493
769
|
}
|
|
494
770
|
|
|
771
|
+
/**
|
|
772
|
+
* Sets the live-view signal ({@link LiveViewState}). Not reset by `clearStateAndCache`: it is an
|
|
773
|
+
* external input owned by the SDK.
|
|
774
|
+
*/
|
|
495
775
|
setViewingLive = (isViewingLive: boolean) => {
|
|
496
776
|
if (this.isViewingLive === isViewingLive) return;
|
|
497
777
|
this.liveViewState.next({ isViewingLive });
|
|
@@ -509,6 +789,6 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
509
789
|
clearStateAndCache() {
|
|
510
790
|
super.clearStateAndCache();
|
|
511
791
|
this.clearUnreadSnapshot();
|
|
512
|
-
this.aggregateState.next({
|
|
792
|
+
this.aggregateState.next({ latestMessage: null, queriedLatestMessageAt: null });
|
|
513
793
|
}
|
|
514
794
|
}
|