stream-chat 10.0.0-rc.21 → 10.0.0-rc.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.browser.js +2196 -3902
- package/dist/cjs/index.browser.js.map +3 -3
- package/dist/cjs/index.node.js +2197 -3902
- package/dist/cjs/index.node.js.map +3 -3
- package/dist/esm/index.mjs +2199 -3905
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelManager.d.ts +120 -233
- package/dist/types/CooldownTimer.d.ts +8 -23
- package/dist/types/EventHandlerPipeline.d.ts +17 -37
- package/dist/types/LiveLocationManager.d.ts +22 -50
- package/dist/types/api-client.d.ts +9 -14
- package/dist/types/channel.d.ts +253 -448
- package/dist/types/channel_state.d.ts +48 -95
- package/dist/types/client.d.ts +245 -370
- package/dist/types/client_state.d.ts +1 -3
- package/dist/types/configuration/ConfigController.d.ts +30 -124
- package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +31 -123
- package/dist/types/configuration/keys.d.ts +5 -19
- package/dist/types/configuration/shape.d.ts +12 -29
- package/dist/types/configuration/types.d.ts +59 -87
- package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +13 -35
- package/dist/types/configuration/utils/copyConfigPatch.d.ts +8 -0
- package/dist/types/configuration/utils/declarativeSlices.d.ts +5 -16
- package/dist/types/configuration/utils/deepFreezeConfig.d.ts +3 -17
- package/dist/types/configuration/utils/serverAuthority.d.ts +9 -29
- package/dist/types/connection/ConnectionIdManager.d.ts +18 -40
- package/dist/types/connection/ConnectionRecoveryManager.d.ts +29 -120
- package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +32 -103
- package/dist/types/connection/networkConnection/reporters.d.ts +9 -32
- package/dist/types/connection/networkConnection/types.d.ts +12 -27
- package/dist/types/connection/wsConnection/StableWSConnection.d.ts +37 -116
- package/dist/types/connection/wsConnection/WSConnection.d.ts +41 -104
- package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +8 -16
- package/dist/types/connection/wsConnection/config.d.ts +8 -28
- package/dist/types/connection/wsConnection/types.d.ts +17 -70
- package/dist/types/entityStore/EntityStore.d.ts +153 -113
- package/dist/types/entityStore/StoreBackedItemIndex.d.ts +13 -46
- package/dist/types/errors.d.ts +7 -19
- package/dist/types/gen/chat/ChannelApi.d.ts +2 -1
- package/dist/types/gen/chat/ChatApi.d.ts +28 -14
- package/dist/types/gen/models/index.d.ts +769 -86
- package/dist/types/gen/moderation/ModerationApi.d.ts +4 -4
- package/dist/types/index.d.ts +2 -4
- package/dist/types/languageNames.d.ts +9 -24
- package/dist/types/logger.d.ts +1 -3
- package/dist/types/messageComposer/LocationComposer.d.ts +1 -1
- package/dist/types/messageComposer/attachmentIdentity.d.ts +1 -6
- package/dist/types/messageComposer/attachmentManager.d.ts +10 -32
- package/dist/types/messageComposer/attachmentUtils.d.ts +3 -14
- package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
- package/dist/types/messageComposer/configuration/types.d.ts +29 -56
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +6 -9
- package/dist/types/messageComposer/messageComposer.d.ts +30 -164
- package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +4 -14
- package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +2 -9
- package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +2 -4
- package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +7 -19
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +9 -0
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +11 -18
- package/dist/types/messageComposer/middleware/textComposer/textMiddlewareUtils.d.ts +9 -3
- package/dist/types/messageComposer/middleware/textComposer/types.d.ts +1 -6
- package/dist/types/messageComposer/pollComposer.d.ts +8 -4
- package/dist/types/messageComposer/textComposer.d.ts +3 -9
- package/dist/types/messageComposer/types.d.ts +5 -8
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +25 -79
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +15 -82
- package/dist/types/messageOperations/FailedSendCache.d.ts +4 -9
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +10 -20
- package/dist/types/messageOperations/MessageOperations.d.ts +20 -40
- package/dist/types/messageOperations/applyReactionLocally.d.ts +5 -22
- package/dist/types/messageOperations/createMessageOperations.d.ts +3 -5
- package/dist/types/messageOperations/reflectReactionEvent.d.ts +5 -13
- package/dist/types/messageOperations/sendOrdering.d.ts +4 -7
- package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +7 -15
- package/dist/types/messageOperations/types.d.ts +15 -30
- package/dist/types/middleware.d.ts +7 -5
- package/dist/types/moderation.d.ts +21 -14
- package/dist/types/notifications/NotificationManager.d.ts +8 -31
- package/dist/types/notifications/types.d.ts +19 -59
- package/dist/types/offline-support/offline_support_api.d.ts +145 -539
- package/dist/types/offline-support/offline_sync_manager.d.ts +18 -42
- package/dist/types/offline-support/queueableOperations.d.ts +24 -52
- package/dist/types/offline-support/types.d.ts +24 -187
- package/dist/types/pagination/ItemIndex.d.ts +4 -12
- package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +13 -0
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -4
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +2 -3
- package/dist/types/pagination/paginators/BasePaginator.d.ts +235 -622
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +67 -125
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +133 -292
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +69 -118
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +7 -26
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +2 -2
- package/dist/types/pagination/paginators/ThreadPaginator.d.ts +15 -23
- package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +2 -6
- package/dist/types/pagination/sortCompiler.d.ts +11 -22
- package/dist/types/pagination/utility.normalization.d.ts +5 -23
- package/dist/types/pagination/utility.search.d.ts +3 -8
- package/dist/types/poll.d.ts +14 -14
- package/dist/types/poll_manager.d.ts +11 -2
- package/dist/types/poll_optimistic_votes.d.ts +10 -14
- package/dist/types/reminders/Reminder.d.ts +4 -4
- package/dist/types/reminders/ReminderManager.d.ts +7 -20
- package/dist/types/search/BaseSearchSource.d.ts +7 -12
- package/dist/types/search/ChannelSearchSource.d.ts +7 -7
- package/dist/types/search/MessageSearchSource.d.ts +7 -9
- package/dist/types/search/SearchController.d.ts +17 -22
- package/dist/types/search/types.d.ts +6 -10
- package/dist/types/signing.d.ts +12 -3
- package/dist/types/thread.d.ts +23 -71
- package/dist/types/thread_manager.d.ts +45 -70
- package/dist/types/token_manager.d.ts +8 -13
- package/dist/types/types.d.ts +64 -125
- package/dist/types/types.utility.d.ts +3 -3
- package/dist/types/upload-utils.d.ts +5 -10
- package/dist/types/uploadManager.d.ts +17 -45
- package/dist/types/utils/FixedSizeQueueCache.d.ts +6 -11
- package/dist/types/utils/WithSubscriptions.d.ts +5 -15
- package/dist/types/utils/concurrency.d.ts +11 -19
- package/dist/types/utils/mergeWith/mergeWith.d.ts +8 -11
- package/dist/types/utils/mergeWith/mergeWithCore.d.ts +5 -13
- package/dist/types/utils/mergeWith/mergeWithDiff.d.ts +22 -0
- package/dist/types/utils/objectPath.d.ts +6 -41
- package/dist/types/utils/retryable.d.ts +8 -12
- package/dist/types/utils/throttling/throttle.d.ts +8 -23
- package/dist/types/utils/time.d.ts +24 -64
- package/dist/types/utils.d.ts +40 -86
- package/package.json +7 -2
- package/src/ChannelManager.ts +159 -300
- package/src/CooldownTimer.ts +11 -29
- package/src/EventHandlerPipeline.ts +21 -44
- package/src/LiveLocationManager.ts +35 -74
- package/src/api-client.ts +43 -61
- package/src/campaign.ts +1 -1
- package/src/channel.ts +396 -749
- package/src/channel_batch_updater.ts +1 -1
- package/src/channel_state.ts +50 -105
- package/src/client.ts +360 -588
- package/src/client_state.ts +1 -6
- package/src/configuration/ConfigController.ts +41 -157
- package/src/configuration/InstanceConfigurationRegistry.ts +42 -171
- package/src/configuration/index.ts +1 -1
- package/src/configuration/keys.ts +13 -32
- package/src/configuration/shape.ts +67 -70
- package/src/configuration/types.ts +60 -100
- package/src/configuration/utils/applyInstanceConfiguration.ts +21 -53
- package/src/configuration/utils/copyConfigPatch.ts +11 -32
- package/src/configuration/utils/declarativeSlices.ts +9 -39
- package/src/configuration/utils/deepFreezeConfig.ts +3 -17
- package/src/configuration/utils/index.ts +2 -4
- package/src/configuration/utils/serverAuthority.ts +20 -68
- package/src/connection/ConnectionIdManager.ts +20 -49
- package/src/connection/ConnectionRecoveryManager.ts +51 -178
- package/src/connection/networkConnection/NetworkConnectionObserver.ts +37 -114
- package/src/connection/networkConnection/reporters.ts +9 -36
- package/src/connection/networkConnection/types.ts +12 -27
- package/src/connection/wsConnection/StableWSConnection.ts +73 -193
- package/src/connection/wsConnection/WSConnection.ts +56 -131
- package/src/connection/wsConnection/WSConnectionFallback.ts +22 -31
- package/src/connection/wsConnection/config.ts +13 -48
- package/src/connection/wsConnection/types.ts +17 -70
- package/src/constants.ts +4 -4
- package/src/entityStore/EntityStore.ts +162 -167
- package/src/entityStore/StoreBackedItemIndex.ts +14 -47
- package/src/errors.ts +7 -19
- package/src/formatMessageMemo.ts +3 -9
- package/src/gen/chat/ChannelApi.ts +19 -0
- package/src/gen/chat/ChatApi.ts +87 -13
- package/src/gen/models/index.ts +793 -71
- package/src/gen/moderation/ModerationApi.ts +0 -4
- package/src/index.ts +10 -14
- package/src/languageNames.ts +9 -24
- package/src/logger.ts +1 -3
- package/src/messageComposer/LocationComposer.ts +7 -23
- package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
- package/src/messageComposer/attachmentIdentity.ts +2 -13
- package/src/messageComposer/attachmentManager.ts +17 -63
- package/src/messageComposer/attachmentUtils.ts +3 -17
- package/src/messageComposer/configuration/configuration.ts +5 -8
- package/src/messageComposer/configuration/types.ts +29 -56
- package/src/messageComposer/fileUtils.ts +1 -1
- package/src/messageComposer/linkPreviewsManager.ts +8 -20
- package/src/messageComposer/messageComposer.ts +54 -222
- package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +4 -16
- package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +1 -2
- package/src/messageComposer/middleware/messageComposer/attachments.ts +14 -40
- package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +3 -4
- package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +4 -11
- package/src/messageComposer/middleware/pollComposer/state.ts +2 -2
- package/src/messageComposer/middleware/pollComposer/types.ts +2 -4
- package/src/messageComposer/middleware/pollComposer/validation.ts +8 -26
- package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +1 -6
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +1 -2
- package/src/messageComposer/middleware/textComposer/commands.ts +11 -16
- package/src/messageComposer/middleware/textComposer/mentions.ts +32 -70
- package/src/messageComposer/middleware/textComposer/textMiddlewareUtils.ts +10 -4
- package/src/messageComposer/middleware/textComposer/types.ts +1 -6
- package/src/messageComposer/pollComposer.ts +11 -8
- package/src/messageComposer/textComposer.ts +9 -59
- package/src/messageComposer/types.ts +9 -12
- package/src/messageDelivery/MessageDeliveryReporter.ts +60 -113
- package/src/messageDelivery/MessageReceiptsTracker.ts +21 -105
- package/src/messageOperations/FailedSendCache.ts +4 -9
- package/src/messageOperations/MessageOperationStatePolicy.ts +40 -67
- package/src/messageOperations/MessageOperations.ts +33 -62
- package/src/messageOperations/applyReactionLocally.ts +9 -28
- package/src/messageOperations/createMessageOperations.ts +17 -33
- package/src/messageOperations/reflectReactionEvent.ts +5 -13
- package/src/messageOperations/sendOrdering.ts +4 -7
- package/src/messageOperations/settlePendingAttachmentUploads.ts +10 -21
- package/src/messageOperations/types.ts +15 -30
- package/src/middleware.ts +7 -10
- package/src/moderation.ts +25 -21
- package/src/notifications/NotificationManager.ts +11 -35
- package/src/notifications/types.ts +19 -59
- package/src/offline-support/offline_support_api.ts +178 -608
- package/src/offline-support/offline_sync_manager.ts +25 -69
- package/src/offline-support/queueableOperations.ts +31 -84
- package/src/offline-support/types.ts +25 -188
- package/src/pagination/ItemIndex.ts +4 -12
- package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +13 -62
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +4 -6
- package/src/pagination/filterCompiler.ts +11 -25
- package/src/pagination/paginators/BasePaginator.ts +422 -976
- package/src/pagination/paginators/ChannelPaginator.ts +130 -190
- package/src/pagination/paginators/MessageIntervalPaginator.ts +226 -457
- package/src/pagination/paginators/MessagePaginator.ts +135 -175
- package/src/pagination/paginators/PinnedMessagePaginator.ts +13 -38
- package/src/pagination/paginators/ReminderPaginator.ts +12 -15
- package/src/pagination/paginators/ThreadPaginator.ts +16 -26
- package/src/pagination/paginators/UserGroupPaginator.ts +6 -17
- package/src/pagination/paginators/stateThrottling.ts +5 -10
- package/src/pagination/sortCompiler.ts +23 -50
- package/src/pagination/utility.normalization.ts +8 -30
- package/src/pagination/utility.search.ts +4 -11
- package/src/poll.ts +19 -19
- package/src/poll_manager.ts +16 -20
- package/src/poll_optimistic_votes.ts +17 -22
- package/src/reminders/Reminder.ts +5 -6
- package/src/reminders/ReminderManager.ts +9 -34
- package/src/reminders/ReminderTimer.ts +1 -2
- package/src/search/BaseSearchSource.ts +14 -29
- package/src/search/ChannelSearchSource.ts +8 -8
- package/src/search/MessageSearchSource.ts +19 -25
- package/src/search/SearchController.ts +18 -24
- package/src/search/types.ts +6 -10
- package/src/segment.ts +1 -1
- package/src/signing.ts +23 -3
- package/src/thread.ts +72 -173
- package/src/thread_manager.ts +59 -76
- package/src/token_manager.ts +11 -21
- package/src/types.ts +78 -126
- package/src/types.utility.ts +3 -3
- package/src/upload-utils.ts +5 -10
- package/src/uploadManager.ts +22 -54
- package/src/utils/FixedSizeQueueCache.ts +13 -21
- package/src/utils/WithSubscriptions.ts +5 -15
- package/src/utils/concurrency.ts +16 -55
- package/src/utils/mergeWith/mergeWith.ts +10 -13
- package/src/utils/mergeWith/mergeWithCore.ts +24 -81
- package/src/utils/mergeWith/mergeWithDiff.ts +15 -33
- package/src/utils/objectPath.ts +6 -41
- package/src/utils/retryable.ts +10 -14
- package/src/utils/throttling/throttle.ts +9 -25
- package/src/utils/time.ts +26 -66
- package/src/utils.ts +72 -128
|
@@ -11,7 +11,8 @@ import {
|
|
|
11
11
|
MessageIntervalPaginator,
|
|
12
12
|
type MessageQueryShape,
|
|
13
13
|
} from './MessageIntervalPaginator';
|
|
14
|
-
import type { LocalMessage, TimestampNS } from '../../types';
|
|
14
|
+
import type { LocalMessage, TimestampNS, UserResponse } from '../../types';
|
|
15
|
+
import type { EntityStoreChangeBatch } from '../../entityStore/EntityStore';
|
|
15
16
|
import { asTimestampNS, nsToDate } from '../../utils/time';
|
|
16
17
|
import { StateStore } from '@stream-io/state-store';
|
|
17
18
|
|
|
@@ -30,44 +31,37 @@ export type {
|
|
|
30
31
|
export { MessageIntervalPaginator } from './MessageIntervalPaginator';
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* not a page of it). `lastMessageAt` is effectively `MAX(created_at)` over the channel-relevant
|
|
36
|
-
* messages and is the source of truth for channel-list ordering
|
|
34
|
+
* Whole-collection aggregates, independent of the active pagination window. `lastMessageAt` is the
|
|
35
|
+
* max `created_at` over the channel-relevant messages and orders the channel list
|
|
37
36
|
* (`channel.messagePaginator.lastMessageAt`): seeded from `ChannelResponse.last_message_at`, then
|
|
38
37
|
* advanced monotonically as newer messages are ingested.
|
|
39
38
|
*/
|
|
40
39
|
export type MessagePaginatorAggregateState = {
|
|
41
40
|
/**
|
|
42
|
-
* The newest channel-relevant message, for display (
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
41
|
+
* The newest channel-relevant message, for display (last-message preview, latest-reply avatar). A
|
|
42
|
+
* live reference: it advances to a strictly newer message, is refreshed in place on edit,
|
|
43
|
+
* soft-delete or reaction, and is recomputed when hard-removed. Follows `shouldAdvanceLastMessage`
|
|
44
|
+
* (skips system messages per `skip_last_msg_update_for_system_msgs`, and thread-only replies).
|
|
45
|
+
* `null` until one is ingested.
|
|
47
46
|
*
|
|
48
|
-
*
|
|
49
|
-
* the head interval while an older window is active
|
|
50
|
-
* active* interval is impacted (see `BasePaginator.ingestItem`), so a `state`-derived latest would
|
|
51
|
-
* go stale in that case.
|
|
47
|
+
* It lives outside pagination `state`, which only emits when the active interval is affected: a
|
|
48
|
+
* message landing in the head interval while an older window is active would go stale there.
|
|
52
49
|
*/
|
|
53
50
|
lastMessage: LocalMessage | null;
|
|
54
51
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* never drift out of sync.
|
|
52
|
+
* `ChannelResponse.last_message_at` floor, for channels whose newest message is not loaded. Kept
|
|
53
|
+
* apart from {@link lastMessage} so it can outrank a stale or absent loaded message for sorting
|
|
54
|
+
* without replacing the display message. {@link MessagePaginator.lastMessageAt} is the max of
|
|
55
|
+
* the two.
|
|
60
56
|
*/
|
|
61
57
|
seededLastMessageAt: TimestampNS | null;
|
|
62
58
|
};
|
|
63
59
|
|
|
64
60
|
export type MessagePaginatorOptions = BaseMessagePaginatorOptions & {
|
|
65
61
|
/**
|
|
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
|
|
62
|
+
* Where `jumpToTheFirstUnreadMessage()` reads the unread reference from: `'snapshot'`
|
|
63
|
+
* prefers `unreadStateSnapshot`, `'read-state-only'` uses only `channel.state.read[...]`.
|
|
64
|
+
* Defaults to `'snapshot'`.
|
|
71
65
|
*/
|
|
72
66
|
unreadReferencePolicy?: 'snapshot' | 'read-state-only';
|
|
73
67
|
};
|
|
@@ -76,34 +70,26 @@ export type UnreadSnapshotState = {
|
|
|
76
70
|
lastReadAt: TimestampNS | null;
|
|
77
71
|
unreadCount: number;
|
|
78
72
|
/**
|
|
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.
|
|
73
|
+
* First unread message ID. Decoupled from `channel.state.read[...]` because apps may mark the
|
|
74
|
+
* channel read on open yet still want UI that jumps to the previously unread location.
|
|
83
75
|
*/
|
|
84
76
|
firstUnreadMessageId: string | null;
|
|
85
|
-
/**
|
|
86
|
-
* Snapshot of the last read message id for the user (fallback when first unread
|
|
87
|
-
* is not known).
|
|
88
|
-
*/
|
|
77
|
+
/** Last read message ID, a fallback when the first unread is unknown. */
|
|
89
78
|
lastReadMessageId: string | null;
|
|
90
79
|
};
|
|
91
80
|
|
|
92
81
|
/**
|
|
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).
|
|
82
|
+
* Set by the owning SDK (the state layer has no viewport): `true` while the user views the latest
|
|
83
|
+
* messages (app foregrounded and newest message on screen). While live, an incoming message does
|
|
84
|
+
* not bump the unread count or snapshot. Defaults to `false`.
|
|
98
85
|
*/
|
|
99
86
|
export type LiveViewState = {
|
|
100
87
|
isViewingLive: boolean;
|
|
101
88
|
};
|
|
102
89
|
|
|
103
90
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* the "jump to first unread" navigation built on top of them.
|
|
91
|
+
* Adds the unread snapshot, the UI-driven live-view signal and "jump to first unread" navigation to
|
|
92
|
+
* {@link MessageIntervalPaginator}.
|
|
107
93
|
*/
|
|
108
94
|
export class MessagePaginator extends MessageIntervalPaginator {
|
|
109
95
|
protected get holderName() {
|
|
@@ -111,22 +97,19 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
111
97
|
}
|
|
112
98
|
private unreadReferencePolicy: 'snapshot' | 'read-state-only';
|
|
113
99
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
100
|
+
* Unread reference state, independent of `channel.state.read`. Seeded on each first page;
|
|
101
|
+
* consumers may also set it before `markRead`.
|
|
116
102
|
*/
|
|
117
103
|
readonly unreadStateSnapshot: StateStore<UnreadSnapshotState>;
|
|
118
104
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* this store for reactivity, or read the current boolean directly via the {@link isViewingLive} getter.
|
|
105
|
+
* The "viewing the latest messages" signal ({@link LiveViewState}), set via {@link setViewingLive}
|
|
106
|
+
* and read by the channel to gate the unread bump on `message.new`.
|
|
122
107
|
*/
|
|
123
108
|
readonly liveViewState: StateStore<LiveViewState>;
|
|
124
109
|
/**
|
|
125
|
-
*
|
|
126
|
-
* from `state`
|
|
127
|
-
*
|
|
128
|
-
* emits when the aggregate actually changes (not on every scroll/pagination emission). This is
|
|
129
|
-
* distinct from the base's `intervalViews` interval-projection store.
|
|
110
|
+
* {@link MessagePaginatorAggregateState}, in a store apart from `state` so `lastMessageAt` can
|
|
111
|
+
* advance from inside a `state.next` updater (`ingestPage`) and subscribers only see aggregate
|
|
112
|
+
* changes.
|
|
130
113
|
*/
|
|
131
114
|
readonly aggregateState: StateStore<MessagePaginatorAggregateState>;
|
|
132
115
|
|
|
@@ -134,21 +117,14 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
134
117
|
{ unreadReferencePolicy = 'snapshot', ...options }: MessagePaginatorOptions,
|
|
135
118
|
builtInDefaults: Partial<BasePaginatorConfig<LocalMessage, MessageQueryShape>> = {},
|
|
136
119
|
) {
|
|
137
|
-
super(
|
|
138
|
-
//
|
|
139
|
-
//
|
|
140
|
-
options
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// A default rather than a construction argument, so `paginatorOptions.stateThrottleMs` and a
|
|
146
|
-
// declarative registration both override it — and so a re-derivation restores it without the
|
|
147
|
-
// subclass having to re-inject it, which is what the old `initializeConfig` override existed for.
|
|
148
|
-
stateThrottleMs: 500,
|
|
149
|
-
...builtInDefaults,
|
|
150
|
-
},
|
|
151
|
-
);
|
|
120
|
+
super(options, {
|
|
121
|
+
// Coalesce live `state.items` publishes to one per 500ms (leading + trailing). Optimistic
|
|
122
|
+
// (local-user) writes bypass it via `EntityStore.flushSubscribers`. A default, so
|
|
123
|
+
// `stateThrottleMs` options and declarative registrations override it and a re-derivation
|
|
124
|
+
// restores it.
|
|
125
|
+
stateThrottleMs: 500,
|
|
126
|
+
...builtInDefaults,
|
|
127
|
+
});
|
|
152
128
|
this.unreadReferencePolicy = unreadReferencePolicy;
|
|
153
129
|
this.unreadStateSnapshot = new StateStore<UnreadSnapshotState>({
|
|
154
130
|
lastReadAt: null,
|
|
@@ -167,8 +143,7 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
167
143
|
|
|
168
144
|
/**
|
|
169
145
|
* Channel-list sort key: the later of the newest loaded message's `created_at` and the server seed.
|
|
170
|
-
*
|
|
171
|
-
* message is ingested.
|
|
146
|
+
* Derived, so it cannot drift from {@link lastMessage}. `null` until seeded or a message arrives.
|
|
172
147
|
*/
|
|
173
148
|
get lastMessageAt(): TimestampNS | null {
|
|
174
149
|
const { lastMessage, seededLastMessageAt } = this.aggregateState.getLatestValue();
|
|
@@ -180,24 +155,18 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
180
155
|
}
|
|
181
156
|
|
|
182
157
|
/**
|
|
183
|
-
* The newest channel-relevant message (
|
|
184
|
-
*
|
|
185
|
-
* ingested (a server-only seed advances {@link lastMessageAt} but leaves this `null`).
|
|
158
|
+
* The tracked newest channel-relevant message ({@link aggregateState}), for display. `null` until
|
|
159
|
+
* one is ingested (a server-only seed advances {@link lastMessageAt} but not this).
|
|
186
160
|
*/
|
|
187
161
|
get lastMessage(): LocalMessage | null {
|
|
188
162
|
return this.aggregateState.getLatestValue().lastMessage;
|
|
189
163
|
}
|
|
190
164
|
|
|
191
165
|
/**
|
|
192
|
-
*
|
|
193
|
-
* the
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* `Channel._trackLastMessage` skip logic.
|
|
197
|
-
*
|
|
198
|
-
* These exclusions are specific to the MAIN channel list. A reply list (thread paginator, which has
|
|
199
|
-
* a `parentMessageId`) is made ENTIRELY of thread replies — there the newest reply is exactly the
|
|
200
|
-
* "latest message", so the exclusions are skipped and only the base rule applies.
|
|
166
|
+
* Whether `message` may become the "latest message" behind `channel.state.last_message_at`: not
|
|
167
|
+
* shadowed and, in the main list, not a thread-only reply nor (with
|
|
168
|
+
* `skip_last_msg_update_for_system_msgs`) a system message. A reply list (`parentMessageId` set)
|
|
169
|
+
* holds only thread replies, so only the shadow rule applies there.
|
|
201
170
|
*/
|
|
202
171
|
protected shouldAdvanceLastMessage(message: LocalMessage): boolean {
|
|
203
172
|
if (message.shadowed) return false;
|
|
@@ -211,31 +180,24 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
211
180
|
}
|
|
212
181
|
|
|
213
182
|
/**
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
* Called internally on ingest; also public for callers that advance the aggregate without a normal
|
|
220
|
-
* in-window ingest — e.g. offline pending-message replay, where the sent message has not yet been
|
|
221
|
-
* ingested via the `message.new` event.
|
|
183
|
+
* Advances the tracked latest message (and so {@link lastMessageAt}) to `message` when it is newer
|
|
184
|
+
* and {@link shouldAdvanceLastMessage} permits. Writes {@link aggregateState} only, so it is safe
|
|
185
|
+
* inside a `state.next` updater (`ingestPage`). Returns `true` when the value moved. Public for
|
|
186
|
+
* callers that advance it without an in-window ingest, e.g. offline pending-message replay.
|
|
222
187
|
*/
|
|
223
188
|
trackLastMessage(message: LocalMessage): boolean {
|
|
224
189
|
if (!this.shouldAdvanceLastMessage(message)) return false;
|
|
225
190
|
const incoming = getMessageCreatedAtTimestamp(message);
|
|
226
191
|
if (incoming === null) return false;
|
|
227
192
|
const current = this.aggregateState.getLatestValue().lastMessage;
|
|
228
|
-
//
|
|
229
|
-
//
|
|
230
|
-
// `lastMessage` a LIVE reference (so a preview shows "deleted"/edited text), and because
|
|
231
|
-
// `aggregateState` emits regardless of the active interval, it stays reactive off-window.
|
|
193
|
+
// An edit, soft-delete, reaction or quote update re-ingests the current latest (same ID and
|
|
194
|
+
// `created_at`): refresh it in place so `lastMessage` stays live.
|
|
232
195
|
if (current && current.id === message.id) {
|
|
233
196
|
this.aggregateState.partialNext({ lastMessage: message });
|
|
234
197
|
return true;
|
|
235
198
|
}
|
|
236
|
-
// Otherwise only
|
|
237
|
-
// timestamp
|
|
238
|
-
// the loaded window would reject the very message it was derived from.
|
|
199
|
+
// Otherwise only a strictly newer message advances. Compare against the current message's own
|
|
200
|
+
// timestamp, not `lastMessageAt`: a seed newer than the loaded window would reject the message.
|
|
239
201
|
const currentTs = current ? getMessageCreatedAtTimestamp(current) : null;
|
|
240
202
|
if (currentTs !== null && incoming <= currentTs) return false;
|
|
241
203
|
this.aggregateState.partialNext({ lastMessage: message });
|
|
@@ -243,9 +205,8 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
243
205
|
}
|
|
244
206
|
|
|
245
207
|
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* past it (e.g. from ingested messages), so seed order does not matter.
|
|
208
|
+
* Seeds {@link lastMessageAt} from `ChannelResponse.last_message_at`. Monotonic: a value not newer
|
|
209
|
+
* than the current seed is ignored, so seed order does not matter.
|
|
249
210
|
*/
|
|
250
211
|
seedLastMessageAt(value: TimestampNS | null | undefined) {
|
|
251
212
|
if (value == null || !Number.isFinite(value)) return;
|
|
@@ -255,9 +216,7 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
255
216
|
}
|
|
256
217
|
|
|
257
218
|
ingestItem(item: LocalMessage): boolean {
|
|
258
|
-
// Only items
|
|
259
|
-
// of items that no longer match). The advance writes the separate `aggregateState` store, so it
|
|
260
|
-
// is independent of `super`'s `state`/index mutations.
|
|
219
|
+
// Only items passing the filter advance the aggregate (`ingestItem` also removes the others).
|
|
261
220
|
if (this.matchesFilter(item)) {
|
|
262
221
|
this.trackLastMessage(item);
|
|
263
222
|
}
|
|
@@ -268,39 +227,76 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
268
227
|
params: Parameters<MessageIntervalPaginator['ingestPage']>[0],
|
|
269
228
|
): Interval | null {
|
|
270
229
|
const interval = super.ingestPage(params);
|
|
271
|
-
// Advance from each page item; the monotonic max over the page yields the newest. Comparison is
|
|
272
|
-
// by `created_at` against `aggregateState` (no index lookup), so order vs `super` is irrelevant.
|
|
273
230
|
if (params.page?.length) {
|
|
274
231
|
for (const item of params.page) this.trackLastMessage(item);
|
|
275
232
|
}
|
|
276
233
|
return interval;
|
|
277
234
|
}
|
|
278
235
|
|
|
236
|
+
onEntitiesChanged(batch: EntityStoreChangeBatch) {
|
|
237
|
+
super.onEntitiesChanged(batch);
|
|
238
|
+
const { lastMessage } = this.aggregateState.getLatestValue();
|
|
239
|
+
if (!lastMessage || !batch.changedIds.has(lastMessage.id)) return;
|
|
240
|
+
const stored = this.getItem(lastMessage.id);
|
|
241
|
+
if (stored) this.aggregateState.partialNext({ lastMessage: stored });
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
reflectUserUpdate(user: UserResponse) {
|
|
245
|
+
super.reflectUserUpdate(user);
|
|
246
|
+
const { lastMessage } = this.aggregateState.getLatestValue();
|
|
247
|
+
if (lastMessage?.user?.id !== user.id) return;
|
|
248
|
+
this.aggregateState.partialNext({ lastMessage: { ...lastMessage, user } });
|
|
249
|
+
}
|
|
250
|
+
|
|
279
251
|
removeItem(
|
|
280
252
|
params: Parameters<MessageIntervalPaginator['removeItem']>[0],
|
|
281
253
|
): ReturnType<MessageIntervalPaginator['removeItem']> {
|
|
282
254
|
const removedId =
|
|
283
255
|
params.id ?? (params.item ? this.getItemId(params.item) : undefined);
|
|
284
|
-
const
|
|
285
|
-
|
|
256
|
+
const { lastMessage, seededLastMessageAt } = this.aggregateState.getLatestValue();
|
|
257
|
+
const wasLatest = !!removedId && lastMessage?.id === removedId;
|
|
286
258
|
const result = super.removeItem(params);
|
|
287
259
|
if (wasLatest) {
|
|
288
|
-
// The tracked latest was hard-removed
|
|
289
|
-
|
|
290
|
-
|
|
260
|
+
// The tracked latest was hard-removed: recompute it, since `trackLastMessage` only advances.
|
|
261
|
+
const previous = this.recomputeLastMessage();
|
|
262
|
+
const previousAt = getMessageCreatedAtTimestamp(previous);
|
|
263
|
+
const removedAt = getMessageCreatedAtTimestamp(lastMessage);
|
|
264
|
+
const isSeedFromRemovedMessage =
|
|
265
|
+
seededLastMessageAt !== null &&
|
|
266
|
+
removedAt !== null &&
|
|
267
|
+
seededLastMessageAt <= removedAt;
|
|
268
|
+
// The server moves `last_message_at` back to the previous message without sending it, so the
|
|
269
|
+
// seed takes the previous loaded message's time. With none loaded the new value is unknown,
|
|
270
|
+
// and the seed stays.
|
|
271
|
+
this.aggregateState.partialNext({
|
|
272
|
+
lastMessage: previous,
|
|
273
|
+
seededLastMessageAt:
|
|
274
|
+
isSeedFromRemovedMessage && previousAt !== null
|
|
275
|
+
? previousAt
|
|
276
|
+
: seededLastMessageAt,
|
|
277
|
+
});
|
|
291
278
|
}
|
|
292
279
|
return result;
|
|
293
280
|
}
|
|
294
281
|
|
|
282
|
+
truncate(params: Parameters<MessageIntervalPaginator['truncate']>[0]) {
|
|
283
|
+
super.truncate(params);
|
|
284
|
+
const { lastMessage, seededLastMessageAt } = this.aggregateState.getLatestValue();
|
|
285
|
+
const isTruncated = (timestamp: TimestampNS | null) =>
|
|
286
|
+
timestamp !== null && timestamp < params.truncatedAt;
|
|
287
|
+
const isLastMessageTruncated = isTruncated(getMessageCreatedAtTimestamp(lastMessage));
|
|
288
|
+
const isSeedTruncated = isTruncated(seededLastMessageAt);
|
|
289
|
+
if (!isLastMessageTruncated && !isSeedTruncated) return;
|
|
290
|
+
this.aggregateState.partialNext({
|
|
291
|
+
lastMessage: isLastMessageTruncated ? this.recomputeLastMessage() : lastMessage,
|
|
292
|
+
seededLastMessageAt: isSeedTruncated ? null : seededLastMessageAt,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
295
296
|
/**
|
|
296
|
-
* The
|
|
297
|
-
* {@link shouldAdvanceLastMessage}
|
|
298
|
-
*
|
|
299
|
-
* loaded qualifies.
|
|
300
|
-
*
|
|
301
|
-
* "Latest" is defined by `created_at` (matching {@link trackLastMessage}), NOT by the paginator's
|
|
302
|
-
* display order — so this compares timestamps rather than assuming a position, and stays correct
|
|
303
|
-
* whatever `itemOrder` / `requestSort` are configured to.
|
|
297
|
+
* The message in `headItems` with the greatest `created_at` that passes
|
|
298
|
+
* {@link shouldAdvanceLastMessage}, or `null`. It compares timestamps rather than positions, so it
|
|
299
|
+
* holds for any `itemOrder` / `requestSort`.
|
|
304
300
|
*/
|
|
305
301
|
private recomputeLastMessage(): LocalMessage | null {
|
|
306
302
|
let latest: LocalMessage | null = null;
|
|
@@ -316,23 +312,16 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
316
312
|
}
|
|
317
313
|
|
|
318
314
|
/**
|
|
319
|
-
* (Re)
|
|
315
|
+
* (Re)seeds the unread snapshot from the own read state. Runs after the first-page query, and the
|
|
316
|
+
* SDK calls it again when a channel is reopened from a cached paginator (no first-page query), so
|
|
317
|
+
* the separator, unread count and jump target follow the current read boundary.
|
|
320
318
|
*
|
|
321
|
-
*
|
|
322
|
-
* (
|
|
323
|
-
* reflects the CURRENT read boundary rather than one frozen at the very first open. Without a
|
|
324
|
-
* re-seed the separator position, unread count and "jump to first unread" target all go stale
|
|
325
|
-
* across reopens.
|
|
326
|
-
*
|
|
327
|
-
* `firstUnreadMessageId` is intentionally reset to `null`: it represents an EXPLICIT mark-unread
|
|
328
|
-
* (set by `notification.mark_unread`), not a live/computed boundary. Persisting a computed value
|
|
329
|
-
* here would make the channel look explicitly marked-unread and suppress auto-mark-read.
|
|
319
|
+
* `firstUnreadMessageId` is reset to `null`: it holds only an explicit mark-unread
|
|
320
|
+
* (`notification.mark_unread`), and a computed value would suppress auto-mark-read.
|
|
330
321
|
*/
|
|
331
322
|
seedUnreadSnapshot = () => {
|
|
332
|
-
//
|
|
333
|
-
//
|
|
334
|
-
// disconnected (`disconnect()`) while that request was in flight, reading the client below
|
|
335
|
-
// throws, so guard against that.
|
|
323
|
+
// The query awaits the network before this runs: the channel may be pending disposal by then,
|
|
324
|
+
// and `getClient()` throws.
|
|
336
325
|
if (this.channel.pendingDisposal) return;
|
|
337
326
|
const ownUserId = this.channel.getClient().user?.id;
|
|
338
327
|
const ownReadState = ownUserId ? this.channel.state.read[ownUserId] : undefined;
|
|
@@ -345,11 +334,7 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
345
334
|
});
|
|
346
335
|
};
|
|
347
336
|
|
|
348
|
-
/**
|
|
349
|
-
* Invokes super.postQueryReconcile() and takes an unread state snapshot on the first-page query.
|
|
350
|
-
* The snapshot has to be taken immediately after the query as the viewed channel is marked read
|
|
351
|
-
* immediately after opening it. The snapshot can be used to display unread UI indicators.
|
|
352
|
-
*/
|
|
337
|
+
/** Also seeds the unread snapshot on a first page, before the opened channel is marked read. */
|
|
353
338
|
postQueryReconcile(
|
|
354
339
|
params: PostQueryReconcileParams<LocalMessage, MessageQueryShape>,
|
|
355
340
|
): ExecuteQueryReturnValue<LocalMessage> {
|
|
@@ -362,22 +347,17 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
362
347
|
}
|
|
363
348
|
|
|
364
349
|
/**
|
|
365
|
-
* Jumps to the unread reference message.
|
|
366
|
-
*
|
|
367
|
-
* IMPORTANT: This intentionally does *not* rely on `channel.state.read[ownUserId]` only,
|
|
368
|
-
* because apps may mark a channel read immediately after opening it, while still
|
|
369
|
-
* wanting to keep "jump to unread" UI indicators alive (based on a snapshot).
|
|
350
|
+
* Jumps to the unread reference message. It does not rely on `channel.state.read` alone, since
|
|
351
|
+
* apps may mark a channel read on open yet keep "jump to unread" UI alive from the snapshot.
|
|
370
352
|
*
|
|
371
353
|
* Resolution order:
|
|
372
|
-
* 1
|
|
373
|
-
* 2
|
|
374
|
-
*
|
|
375
|
-
* 3
|
|
354
|
+
* 1. an explicit first-unread ID (snapshot or read state): jump to it;
|
|
355
|
+
* 2. the last-read timestamp: infer the first unread message from the loaded window, or from a
|
|
356
|
+
* `created_at_around` query when the window does not straddle the boundary, and jump to it;
|
|
357
|
+
* 3. the last-read ID, when no timestamp is known.
|
|
376
358
|
*
|
|
377
|
-
* The
|
|
378
|
-
*
|
|
379
|
-
* only used as a fallback when we cannot infer an unread boundary. The inference is NOT persisted
|
|
380
|
-
* back into the snapshot (that is reserved for explicit mark-unread).
|
|
359
|
+
* The inference is not written to the snapshot: `firstUnreadMessageId` is reserved for an explicit
|
|
360
|
+
* mark-unread (it would suppress auto-mark-read).
|
|
381
361
|
*/
|
|
382
362
|
jumpToTheFirstUnreadMessage = async (options?: JumpToMessageOptions) => {
|
|
383
363
|
const ownUserId = this.channel.getClient().user?.id;
|
|
@@ -396,8 +376,6 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
396
376
|
const lastReadAtFromReadState = ownReadState?.last_read ?? null;
|
|
397
377
|
const lastReadIdFromReadState = ownReadState?.last_read_message_id ?? null;
|
|
398
378
|
|
|
399
|
-
// 1) A stable first-unread id is known (mark-unread, or a previously persisted inference):
|
|
400
|
-
// jump straight to it.
|
|
401
379
|
const firstUnreadMessageId = firstUnreadFromSnapshot ?? firstUnreadFromReadState;
|
|
402
380
|
if (firstUnreadMessageId) {
|
|
403
381
|
return await this.jumpToMessage(firstUnreadMessageId, {
|
|
@@ -407,24 +385,11 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
407
385
|
}
|
|
408
386
|
|
|
409
387
|
const lastReadMessageId = lastReadIdFromSnapshot ?? lastReadIdFromReadState;
|
|
410
|
-
//
|
|
411
|
-
//
|
|
412
|
-
//
|
|
413
|
-
// the read-state `last_read` to ~now and clears the server unread — so preferring read-state
|
|
414
|
-
// would make a later banner tap infer "nothing unread" and jump to the latest message. The
|
|
415
|
-
// snapshot is kept fresh on genuine catch-up (the SDK's mark-read resets it), so it is only
|
|
416
|
-
// "frozen" precisely while there are unreads to jump to.
|
|
388
|
+
// The snapshot timestamp wins over the read state's: the snapshot is the frozen boundary the
|
|
389
|
+
// "N new" banner renders from, while mark-read on open advances the read state to ~now, so a
|
|
390
|
+
// banner tap would infer nothing unread and jump to the latest message.
|
|
417
391
|
const lastReadAt = lastReadAtFromSnapshot ?? lastReadAtFromReadState;
|
|
418
392
|
|
|
419
|
-
// 2) No explicit first-unread id, but we know when the channel was last read. Infer the first
|
|
420
|
-
// unread message from that timestamp so we land ON (and highlight) the first unread message
|
|
421
|
-
// instead of the last read one. Prefer the already-loaded window (the common "a few unreads at
|
|
422
|
-
// the bottom" case — no extra request); only query a page around last-read when the loaded
|
|
423
|
-
// window does not straddle the boundary (i.e. every loaded message is newer than last-read).
|
|
424
|
-
//
|
|
425
|
-
// We deliberately do NOT persist the inferred boundary back into the snapshot: writing
|
|
426
|
-
// `firstUnreadMessageId` would make the channel look explicitly marked-unread and suppress
|
|
427
|
-
// auto-mark-read at the bottom. The separator reads the (re-seeded) snapshot directly.
|
|
428
393
|
const lastReadBoundary =
|
|
429
394
|
lastReadAt != null && Number.isFinite(lastReadAt) ? lastReadAt : null;
|
|
430
395
|
|
|
@@ -442,7 +407,7 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
442
407
|
queryShape: {
|
|
443
408
|
// `created_at_around` is a request field and still takes a `Date`.
|
|
444
409
|
created_at_around: nsToDate(lastReadBoundary),
|
|
445
|
-
limit: options?.pageSize,
|
|
410
|
+
limit: options?.pageSize ?? this.pageSize,
|
|
446
411
|
},
|
|
447
412
|
updateState: false,
|
|
448
413
|
});
|
|
@@ -467,7 +432,6 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
467
432
|
}
|
|
468
433
|
}
|
|
469
434
|
|
|
470
|
-
// 3) Last resort: jump to the known last-read message when that is all we have.
|
|
471
435
|
if (lastReadMessageId) {
|
|
472
436
|
return await this.jumpToMessage(lastReadMessageId, {
|
|
473
437
|
...options,
|
|
@@ -483,18 +447,14 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
483
447
|
return this.unreadStateSnapshot.getLatestValue();
|
|
484
448
|
};
|
|
485
449
|
|
|
486
|
-
/**
|
|
487
|
-
* Set the UI-driven "viewing the latest messages" signal (see {@link LiveViewState}). Called by
|
|
488
|
-
* the SDK from its message-list viewability + app-state tracking. No-ops when unchanged.
|
|
489
|
-
*
|
|
490
|
-
* Intentionally NOT reset by `clearStateAndCache` — it is an external input owned by the SDK, not
|
|
491
|
-
* derived pagination state.
|
|
492
|
-
*/
|
|
493
|
-
/** Current "viewing the latest messages" boolean (convenience read of {@link liveViewState}). */
|
|
494
450
|
get isViewingLive(): boolean {
|
|
495
451
|
return this.liveViewState.getLatestValue().isViewingLive;
|
|
496
452
|
}
|
|
497
453
|
|
|
454
|
+
/**
|
|
455
|
+
* Sets the live-view signal ({@link LiveViewState}). Not reset by `clearStateAndCache`: it is an
|
|
456
|
+
* external input owned by the SDK.
|
|
457
|
+
*/
|
|
498
458
|
setViewingLive = (isViewingLive: boolean) => {
|
|
499
459
|
if (this.isViewingLive === isViewingLive) return;
|
|
500
460
|
this.liveViewState.next({ isViewingLive });
|
|
@@ -33,23 +33,12 @@ export type PinnedMessagePaginatorOptions = {
|
|
|
33
33
|
const PINNED_AT_SORT: SortParamRequest[] = [{ field: 'pinned_at', direction: 1 }];
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* The channel's pinned messages, ordered by `pinned_at` ascending (oldest-pinned first). Extends
|
|
37
|
+
* {@link MessageIntervalPaginator} rather than {@link MessagePaginator}: pinned messages are a subset
|
|
38
|
+
* of the channel and take no part in read/unread or delivery-receipt tracking.
|
|
37
39
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* the channel and thread message timelines). By extending the base rather than {@link MessagePaginator}
|
|
41
|
-
* it simply never gets the unread surface.
|
|
42
|
-
*
|
|
43
|
-
* Differences from the main list:
|
|
44
|
-
* - fetches from the `/pinned_messages` endpoint (`channel.getPinnedMessages`) rather than
|
|
45
|
-
* `channel.query({ messages })`;
|
|
46
|
-
* - includes only pinned, non-shadowed messages (`shouldIncludeMessageInInterval`), and filters on
|
|
47
|
-
* `{ cid, pinned: true }` so `ingestItem` auto-adds on pin and auto-removes on unpin;
|
|
48
|
-
* - orders by `pinned_at` ascending (oldest-pinned first), matching the legacy
|
|
49
|
-
* `channel.state.pinnedMessages` order.
|
|
50
|
-
*
|
|
51
|
-
* Navigation (`jumpToMessage` / `jumpToTheLatestMessage`) is inherited and meaningful — the endpoint
|
|
52
|
-
* supports `id_around` — but no unread-coupled navigation exists.
|
|
40
|
+
* Fetches through `channel.getPinnedMessages`, includes only pinned, non-shadowed messages and
|
|
41
|
+
* matches `{ cid, pinned: true }`, so `ingestItem` adds on pin and removes on unpin.
|
|
53
42
|
*/
|
|
54
43
|
export class PinnedMessagePaginator extends MessageIntervalPaginator {
|
|
55
44
|
protected get holderName() {
|
|
@@ -65,9 +54,7 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
|
|
|
65
54
|
super({
|
|
66
55
|
channel,
|
|
67
56
|
id: id ?? `pinned-message-paginator-${generateUUIDv4()}`,
|
|
68
|
-
//
|
|
69
|
-
// pinned message shares the single canonical copy with the main list / thread and reflects
|
|
70
|
-
// reactions & edits applied elsewhere. A caller may still inject a custom `itemIndex`.
|
|
57
|
+
// Omitted: the inherited store-backed index shares one copy of each message with the main list.
|
|
71
58
|
itemIndex,
|
|
72
59
|
paginatorOptions,
|
|
73
60
|
});
|
|
@@ -75,11 +62,7 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
|
|
|
75
62
|
this.installPinnedMessageBehaviour();
|
|
76
63
|
}
|
|
77
64
|
|
|
78
|
-
/**
|
|
79
|
-
* Memoized for the reason {@link MessageIntervalPaginator}'s overlay is: the base derivation folds
|
|
80
|
-
* this in and skips the publish when nothing moved, which needs stable references. Both close over
|
|
81
|
-
* `this` and over a fixed `pinned_at` sort, so there is nothing to rebuild.
|
|
82
|
-
*/
|
|
65
|
+
/** Memoized: stable references let the base derivation skip a publish when nothing moved. */
|
|
83
66
|
private pinnedBehaviour?: Partial<BasePaginatorConfig<LocalMessage, MessageQueryShape>>;
|
|
84
67
|
|
|
85
68
|
private buildPinnedBehaviour(): Partial<
|
|
@@ -93,9 +76,8 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
|
|
|
93
76
|
tiebreaker: this.pinnedTiebreaker,
|
|
94
77
|
}),
|
|
95
78
|
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
// them by direction.
|
|
79
|
+
// The base `query` passes the resolved shape (including `id_around` jumps) as `options`.
|
|
80
|
+
// Both cursors are returned and the base gates them by direction.
|
|
99
81
|
doRequest: async (
|
|
100
82
|
options: MessageQueryShape,
|
|
101
83
|
): Promise<{ cursor?: PaginatorCursor; items: LocalMessage[] }> => {
|
|
@@ -117,11 +99,7 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
|
|
|
117
99
|
return leftId < rightId ? -1 : leftId > rightId ? 1 : 0;
|
|
118
100
|
};
|
|
119
101
|
|
|
120
|
-
/**
|
|
121
|
-
* The ordering and request behaviour that makes this a *pinned*-message paginator, contributed to the
|
|
122
|
-
* base derivation so a re-derivation cannot drop it and does not need a second write to restore it.
|
|
123
|
-
* Spread over the interval overlay, so this class's `pinned_at` comparator wins.
|
|
124
|
-
*/
|
|
102
|
+
/** Adds the pinned ordering and request behaviour to the derivation, over the interval overlay. */
|
|
125
103
|
protected override getBehaviourOverrides(): Partial<
|
|
126
104
|
BasePaginatorConfig<LocalMessage, MessageQueryShape>
|
|
127
105
|
> {
|
|
@@ -129,12 +107,9 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
|
|
|
129
107
|
}
|
|
130
108
|
|
|
131
109
|
private installPinnedMessageBehaviour(): void {
|
|
132
|
-
//
|
|
133
|
-
// the
|
|
134
|
-
//
|
|
135
|
-
//
|
|
136
|
-
// A plain field rather than config, so a re-derivation never touches it — which is why only the
|
|
137
|
-
// constructor sets it.
|
|
110
|
+
// Ascending `pinned_at` keeps the head edge (most recently pinned) at the end of an interval,
|
|
111
|
+
// like the base's `created_at` ascending. A plain field rather than config, so a re-derivation
|
|
112
|
+
// never touches it and only the constructor sets it.
|
|
138
113
|
this.sortComparator = makeComparator<LocalMessage>({
|
|
139
114
|
sort: PINNED_AT_SORT,
|
|
140
115
|
resolvePathValue: resolveDotPathValue,
|