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
|
@@ -32,44 +32,48 @@ import type { FieldToDataResolver, PathResolver } from '../types.normalization';
|
|
|
32
32
|
import { resolveDotPathValue } from '../utility.normalization';
|
|
33
33
|
import { isEqual } from '../../utils/mergeWith/mergeWithCore';
|
|
34
34
|
|
|
35
|
+
const hasSameItems = (current: Channel[] | undefined, next: Channel[] | undefined) => {
|
|
36
|
+
if (current === next) return false;
|
|
37
|
+
if (!current || !next || current.length !== next.length) return false;
|
|
38
|
+
for (let i = 0; i < next.length; i++) if (current[i] !== next[i]) return false;
|
|
39
|
+
return true;
|
|
40
|
+
};
|
|
41
|
+
|
|
35
42
|
const DEFAULT_BACKEND_SORT: SortParamRequest[] = [
|
|
36
43
|
{ direction: -1, field: 'last_message_at' },
|
|
37
44
|
{ direction: -1, field: 'updated_at' },
|
|
38
45
|
];
|
|
39
46
|
|
|
40
47
|
/**
|
|
41
|
-
* The `queryChannels` request this paginator
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* rather than a `{ filters, sort, options }` wrapper: the same object goes on the wire, keys the
|
|
45
|
-
* offline-db cache and is compared for query-shape changes, so any field mapping in between would be a
|
|
46
|
-
* place for those three to drift apart. `MessageQueryShape` is likewise the request params themselves.
|
|
48
|
+
* The `queryChannels` request this paginator sends, plus the client-only `stateOptions`. It is the
|
|
49
|
+
* request's own shape because the same object goes on the wire, keys the offline-db cache and is
|
|
50
|
+
* compared for query-shape changes.
|
|
47
51
|
*/
|
|
48
52
|
export type ChannelQueryShape = QueryChannelsRequest & {
|
|
49
|
-
/** Not part of the request
|
|
53
|
+
/** Not part of the request: controls how the response is applied to client state. */
|
|
50
54
|
stateOptions?: ChannelStateOptions;
|
|
51
55
|
};
|
|
52
56
|
|
|
53
57
|
export type ChannelPaginatorState = PaginatorState<Channel>;
|
|
54
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Request options sent with every page query (`state`, `watch`, `presence`, `message_limit`, ...).
|
|
61
|
+
* `limit` and `offset` belong to the paginator: set the page size with `paginatorOptions.pageSize`.
|
|
62
|
+
*/
|
|
55
63
|
export type ChannelPaginatorRequestOptions = Partial<
|
|
56
64
|
Omit<ChannelOptions, 'offset' | 'limit'>
|
|
57
65
|
>;
|
|
58
66
|
|
|
59
67
|
export type ChannelSortComparatorFactoryParams = {
|
|
60
|
-
/**
|
|
68
|
+
/** The effective sort the comparator is built for (a backend-resolved template, if any). */
|
|
61
69
|
sort: SortParamRequest[];
|
|
62
|
-
/**
|
|
63
|
-
* The comparator `ChannelPaginator` would use for this sort. Delegate to it for the fields you do not
|
|
64
|
-
* want to handle yourself instead of reimplementing channel field resolution and the cid tiebreaker.
|
|
65
|
-
*/
|
|
70
|
+
/** The comparator `ChannelPaginator` would use: delegate to it for the fields you do not handle. */
|
|
66
71
|
defaultComparator: (a: Channel, b: Channel) => number;
|
|
67
72
|
};
|
|
68
73
|
|
|
69
74
|
/**
|
|
70
|
-
* Produces the comparator that orders
|
|
71
|
-
*
|
|
72
|
-
* `sortComparator` directly, a factory is not overwritten by later sort changes.
|
|
75
|
+
* Produces the comparator that orders the channels. Consulted on every rebuild (construction,
|
|
76
|
+
* `sort` change, backend-resolved predefined sort), so later sort changes do not overwrite it.
|
|
73
77
|
*/
|
|
74
78
|
export type ChannelSortComparatorFactory = (
|
|
75
79
|
params: ChannelSortComparatorFactoryParams,
|
|
@@ -86,18 +90,15 @@ export type ChannelPaginatorOptions = {
|
|
|
86
90
|
sort?: SortParamRequest[];
|
|
87
91
|
sortComparatorFactory?: ChannelSortComparatorFactory;
|
|
88
92
|
/**
|
|
89
|
-
* The channel store the list's index
|
|
90
|
-
*
|
|
93
|
+
* The channel store backing the list's index. Defaults to `client.channelManager`'s store, shared
|
|
94
|
+
* by every list.
|
|
91
95
|
*
|
|
92
96
|
* @internal
|
|
93
97
|
*/
|
|
94
98
|
store?: EntityStore<Channel>;
|
|
95
99
|
};
|
|
96
100
|
|
|
97
|
-
/**
|
|
98
|
-
* What identifies the query itself, as opposed to which page of it is being requested. Two shapes with
|
|
99
|
-
* the same identity continue one pagination; a different identity restarts it from the first page.
|
|
100
|
-
*/
|
|
101
|
+
/** The query without its page: shapes with the same identity continue one pagination. */
|
|
101
102
|
const getQueryIdentity = (queryShape: ChannelQueryShape | undefined) => {
|
|
102
103
|
if (!queryShape) return queryShape;
|
|
103
104
|
const {
|
|
@@ -121,9 +122,8 @@ const archivedFilterResolver: FieldToDataResolver<Channel> = {
|
|
|
121
122
|
resolve: (channel) => channel.state.membership.archived_at != null,
|
|
122
123
|
};
|
|
123
124
|
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
// for it), and a disposed channel must still sort and filter, so that a list can locate it to drop it.
|
|
125
|
+
// Resolvers needing the user or the mute list use the list's client, not `channel.getClient()`: that
|
|
126
|
+
// throws on a disposed channel, which must still sort and filter so a list can locate and drop it.
|
|
127
127
|
|
|
128
128
|
const createAppBannedFilterResolver = (
|
|
129
129
|
client: StreamChat,
|
|
@@ -157,24 +157,15 @@ const createHasUnreadFilterResolver = (
|
|
|
157
157
|
|
|
158
158
|
const hiddenFilterResolver: FieldToDataResolver<Channel> = {
|
|
159
159
|
matchesField: (field) => field === 'hidden',
|
|
160
|
-
// `hidden` is optional on
|
|
161
|
-
// hidden or shown) leaves `channel.data.hidden` undefined. Coerce to a boolean so `{ hidden: false }`
|
|
162
|
-
// matches those channels instead of comparing undefined against false.
|
|
160
|
+
// `hidden` is optional on the response: coerce so `{ hidden: false }` matches channels without it.
|
|
163
161
|
resolve: (channel) => !!channel.data?.hidden,
|
|
164
162
|
};
|
|
165
163
|
|
|
166
164
|
const lastUpdatedFilterResolver: FieldToDataResolver<Channel> = {
|
|
167
165
|
matchesField: (field) => field === 'last_updated',
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
// in different units and make `updated_at` win every comparison.
|
|
172
|
-
const lastMessageAt = channel.messagePaginator.lastMessageAt ?? null;
|
|
173
|
-
const updatedAt = channel.data?.updated_at;
|
|
174
|
-
return lastMessageAt !== null && updatedAt !== undefined
|
|
175
|
-
? Math.max(lastMessageAt, updatedAt)
|
|
176
|
-
: (lastMessageAt ?? updatedAt);
|
|
177
|
-
},
|
|
166
|
+
// the server uses the creation time for a channel without messages
|
|
167
|
+
resolve: (channel) =>
|
|
168
|
+
channel.messagePaginator.lastMessageAt ?? channel.data?.created_at,
|
|
178
169
|
};
|
|
179
170
|
|
|
180
171
|
const membersFilterResolver: FieldToDataResolver<Channel> = {
|
|
@@ -188,8 +179,8 @@ const membersFilterResolver: FieldToDataResolver<Channel> = {
|
|
|
188
179
|
return ids;
|
|
189
180
|
}, [])
|
|
190
181
|
: [];
|
|
191
|
-
// Only a page of a large channel's members may be loaded, but the
|
|
192
|
-
//
|
|
182
|
+
// Only a page of a large channel's members may be loaded, but the own membership always is, so
|
|
183
|
+
// `members: { $in: [ownId] }` holds.
|
|
193
184
|
const { membership } = channel.state;
|
|
194
185
|
const ownId = membership?.user?.id ?? membership?.user_id;
|
|
195
186
|
if (ownId && !ids.includes(ownId)) ids.push(ownId);
|
|
@@ -217,21 +208,14 @@ const pinnedFilterResolver: FieldToDataResolver<Channel> = {
|
|
|
217
208
|
|
|
218
209
|
const createMutedFilterResolver = (client: StreamChat): FieldToDataResolver<Channel> => ({
|
|
219
210
|
matchesField: (field) => field === 'muted',
|
|
220
|
-
//
|
|
221
|
-
// the client so `{ muted: true/false }` matches client-side, rather than letting the generic
|
|
222
|
-
// data resolver read a non-existent `channel.data.muted` (which would resolve to undefined and
|
|
223
|
-
// never equal a boolean filter value).
|
|
211
|
+
// Mute state lives on the client (`client.mutedChannels`), not in `channel.data`.
|
|
224
212
|
resolve: (channel) => client._muteStatus(channel.cid).muted,
|
|
225
213
|
});
|
|
226
214
|
|
|
227
215
|
/**
|
|
228
|
-
* A channel field by path: from `channel.data`,
|
|
229
|
-
* `
|
|
230
|
-
* `
|
|
231
|
-
*
|
|
232
|
-
* `type`, `id` and `cid` come from the instance, which has them from construction, while
|
|
233
|
-
* `channel.data` has them only after a query: a stored channel an event reaches before its first
|
|
234
|
-
* query (such as one a thread created) must still match `{ type: … }`.
|
|
216
|
+
* A channel field by path: from `channel.data`, else from `channel.data.custom` (where a response
|
|
217
|
+
* keeps `name` and custom fields). `type`, `id` and `cid` come from the instance, since
|
|
218
|
+
* `channel.data` has them only after a query.
|
|
235
219
|
*/
|
|
236
220
|
const resolveChannelDataValue = (channel: Channel, path: string) => {
|
|
237
221
|
if (path === 'type' || path === 'id' || path === 'cid') return channel[path];
|
|
@@ -244,7 +228,7 @@ const dataFieldFilterResolver: FieldToDataResolver<Channel> = {
|
|
|
244
228
|
resolve: resolveChannelDataValue,
|
|
245
229
|
};
|
|
246
230
|
|
|
247
|
-
//
|
|
231
|
+
// Channel data is split between `Channel.data` and `Channel.state`.
|
|
248
232
|
const createChannelSortPathResolver = (client: StreamChat): PathResolver<Channel> => {
|
|
249
233
|
const hasUnreadResolver = createHasUnreadFilterResolver(client);
|
|
250
234
|
return (channel, path) => {
|
|
@@ -271,23 +255,18 @@ const createChannelSortPathResolver = (client: StreamChat): PathResolver<Channel
|
|
|
271
255
|
};
|
|
272
256
|
|
|
273
257
|
/**
|
|
274
|
-
* A paginated channel list.
|
|
258
|
+
* A paginated channel list. `staticFilters` are the filters this client asked for, `filterBuilder`
|
|
259
|
+
* adds dynamic ones from its reactive context (merged over the static ones on every build). For a
|
|
260
|
+
* `predefined_filter` query the backend reports what it applied (`predefinedFilter`), which wins
|
|
261
|
+
* over `staticFilters` in `effectiveFilters` (and over `sort` in `effectiveSort`).
|
|
275
262
|
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
* two (and `effectiveSort` likewise for ordering).
|
|
281
|
-
* - purpose: `buildQueryFilters()` produces the filters sent to the server (and the offline-db query
|
|
282
|
-
* key), built from the local filters only; `buildMatchFilters()` produces the filters items are
|
|
283
|
-
* matched against locally, built from `effectiveFilters`. They are not interchangeable: sending the
|
|
284
|
-
* resolved filter back changes the query shape mid-pagination, and matching against the local filter
|
|
285
|
-
* admits channels the queried list excludes.
|
|
263
|
+
* `buildQueryFilters()` (sent to the server, offline-db query key) uses the local filters only and
|
|
264
|
+
* `buildMatchFilters()` (local matching) uses `effectiveFilters`. Do not swap them: sending the
|
|
265
|
+
* resolved filter back changes the query shape mid-pagination, and matching on the local filter
|
|
266
|
+
* admits channels the list excludes.
|
|
286
267
|
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
* `sortComparatorFactory` (constructor option or setter, consulted on every rebuild) or by overriding
|
|
290
|
-
* `buildSortComparator` in a subclass.
|
|
268
|
+
* `sortComparator` is derived from `effectiveSort` and rebuilt when it changes, so do not assign
|
|
269
|
+
* it: use `sortComparatorFactory` or override `buildSortComparator`.
|
|
291
270
|
*/
|
|
292
271
|
export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape> {
|
|
293
272
|
private readonly _id: string;
|
|
@@ -299,20 +278,19 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
299
278
|
protected _nextQueryShape: ChannelQueryShape | undefined;
|
|
300
279
|
/** Backend-reported metadata of the last `predefined_filter` query (see `predefinedFilter`). */
|
|
301
280
|
protected _predefinedFilter: ParsedPredefinedFilterResponse | undefined;
|
|
302
|
-
/**
|
|
303
|
-
* Predefined-filter metadata from the response of the query currently in flight. Held until
|
|
304
|
-
* `postQueryReconcile` decides whether it should be committed (first page only).
|
|
305
|
-
*/
|
|
281
|
+
/** Metadata of the in-flight response, committed by `postQueryReconcile` on a first page only. */
|
|
306
282
|
private _pendingPredefinedFilter: ParsedPredefinedFilterResponse | undefined;
|
|
307
283
|
/**
|
|
308
|
-
* True while the loaded items came
|
|
309
|
-
* confirmed by a query.
|
|
310
|
-
*
|
|
311
|
-
*
|
|
284
|
+
* True while the loaded items came only from the offline cache (seeded by `setItems`, never
|
|
285
|
+
* confirmed by a query). The seed's offset and query shape would make the next query a
|
|
286
|
+
* continuation, but a cache has no pagination position, so `executeQuery` forces a first page that
|
|
287
|
+
* keeps the items.
|
|
312
288
|
*/
|
|
313
289
|
private _itemsLoadedFromOfflineDB = false;
|
|
314
290
|
/** The query in flight refreshes a cache-only window, so its response replaces the window. */
|
|
315
291
|
private _replaceOfflineSeedOnResponse = false;
|
|
292
|
+
/** The query handed to the sync manager, from the cache read until it runs. See `executeQuery`. */
|
|
293
|
+
private _queryAwaitingSync: ChannelQueryShape | undefined;
|
|
316
294
|
protected _sortComparatorFactory: ChannelSortComparatorFactory | undefined;
|
|
317
295
|
sortComparator: (a: Channel, b: Channel) => number;
|
|
318
296
|
filterBuilder: FilterBuilder<ChannelFilters>;
|
|
@@ -364,18 +342,18 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
364
342
|
memberUserNameFilterResolver,
|
|
365
343
|
dataFieldFilterResolver,
|
|
366
344
|
]);
|
|
345
|
+
// Channels are reactive objects: republish only when the list's membership or order changes.
|
|
346
|
+
this.state.addPreprocessor((next, previous) => {
|
|
347
|
+
if (previous && hasSameItems(previous.items, next.items))
|
|
348
|
+
next.items = previous.items;
|
|
349
|
+
});
|
|
367
350
|
}
|
|
368
351
|
|
|
369
352
|
/**
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
* `sortComparator` is derived state and is therefore reassigned on every rebuild — assigning to it
|
|
376
|
-
* directly does not survive a sort change or a predefined-filter response. To customize ordering,
|
|
377
|
-
* supply `sortComparatorFactory` (it is consulted on every rebuild and may delegate to
|
|
378
|
-
* `defaultComparator`), or override this method in a subclass.
|
|
353
|
+
* The single construction point of `sortComparator`, so every rebuild keeps the channel path
|
|
354
|
+
* resolver and the cid tiebreaker. Customize it with `sortComparatorFactory` (which may delegate
|
|
355
|
+
* to `defaultComparator`) or by overriding this method: assigning `sortComparator` directly is
|
|
356
|
+
* lost on the next rebuild.
|
|
379
357
|
*/
|
|
380
358
|
protected buildSortComparator(sort: SortParamRequest[]) {
|
|
381
359
|
const defaultComparator = makeComparator<Channel>({
|
|
@@ -410,31 +388,22 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
410
388
|
}
|
|
411
389
|
|
|
412
390
|
/**
|
|
413
|
-
* What the backend reported it
|
|
414
|
-
* `QueryChannelsResponse.predefined_filter
|
|
415
|
-
*
|
|
416
|
-
* of a normal query are not echoed back.
|
|
391
|
+
* What the backend reported it filtered and sorted by for the last first-page query
|
|
392
|
+
* (`QueryChannelsResponse.predefined_filter`: `name`, `filter`, and `sort` when the stored filter
|
|
393
|
+
* has a sort template). Set only for `predefined_filter` queries.
|
|
417
394
|
*/
|
|
418
395
|
get predefinedFilter(): ParsedPredefinedFilterResponse | undefined {
|
|
419
396
|
return this._predefinedFilter;
|
|
420
397
|
}
|
|
421
398
|
|
|
422
|
-
/**
|
|
423
|
-
* Filters this paginator matches items against client-side. A predefined filter resolved by the backend
|
|
424
|
-
* wins over the locally configured one: for such a query the local `filters` are not what the server
|
|
425
|
-
* applied, so matching against them would admit items the queried list excludes.
|
|
426
|
-
*/
|
|
399
|
+
/** Filters items are matched against locally: the backend-resolved one, else `staticFilters`. */
|
|
427
400
|
get effectiveFilters(): ChannelFilters | undefined {
|
|
428
401
|
return (
|
|
429
402
|
(this._predefinedFilter?.filter as ChannelFilters | undefined) ?? this.staticFilters
|
|
430
403
|
);
|
|
431
404
|
}
|
|
432
405
|
|
|
433
|
-
/**
|
|
434
|
-
* Sort this paginator orders items by. Mirrors `effectiveFilters`: a sort template carried by a
|
|
435
|
-
* backend-resolved predefined filter takes precedence over the requested sort, matching backend
|
|
436
|
-
* precedence rules.
|
|
437
|
-
*/
|
|
406
|
+
/** The sort items are ordered by: the backend-resolved predefined sort template, else `sort`. */
|
|
438
407
|
get effectiveSort(): SortParamRequest[] {
|
|
439
408
|
return (this._predefinedFilter?.sort as SortParamRequest[] | undefined) ?? this.sort;
|
|
440
409
|
}
|
|
@@ -469,10 +438,8 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
469
438
|
}
|
|
470
439
|
|
|
471
440
|
/**
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
* `sortComparator` — a sort change or a backend-resolved predefined sort will not discard it. Set to
|
|
475
|
-
* `undefined` to go back to the built-in ordering.
|
|
441
|
+
* Rebuilds the comparator immediately; later rebuilds consult the factory again, so a sort change
|
|
442
|
+
* does not discard it. `undefined` restores the built-in ordering.
|
|
476
443
|
*/
|
|
477
444
|
set sortComparatorFactory(factory: ChannelSortComparatorFactory | undefined) {
|
|
478
445
|
this._sortComparatorFactory = factory;
|
|
@@ -484,21 +451,16 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
484
451
|
}
|
|
485
452
|
|
|
486
453
|
/**
|
|
487
|
-
* Filters sent
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
* page to `hasPaginationQueryShapeChanged`.
|
|
454
|
+
* Filters sent with the next query and used as the offline-db query key. Built from the local
|
|
455
|
+
* filters only: the backend-resolved filter would change the query shape after the first response,
|
|
456
|
+
* so the next page would look like a first page.
|
|
491
457
|
*/
|
|
492
458
|
buildQueryFilters = (): ChannelFilters =>
|
|
493
459
|
this.filterBuilder.buildFilters({
|
|
494
460
|
baseFilters: { ...this.staticFilters },
|
|
495
461
|
});
|
|
496
462
|
|
|
497
|
-
/**
|
|
498
|
-
* Filters items are matched against locally — the `BasePaginator.buildMatchFilters` hook consumed by
|
|
499
|
-
* `matchesFilter`. Built from `effectiveFilters`, so a `predefined_filter` list matches what the
|
|
500
|
-
* backend applied rather than the local filters, which are not what produced the list.
|
|
501
|
-
*/
|
|
463
|
+
/** Filters items are matched against locally (`matchesFilter`), built from `effectiveFilters`. */
|
|
502
464
|
buildMatchFilters = (): ChannelFilters =>
|
|
503
465
|
this.filterBuilder.buildFilters({
|
|
504
466
|
baseFilters: { ...this.effectiveFilters },
|
|
@@ -507,22 +469,16 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
507
469
|
matchesFilter(channel: Channel): boolean {
|
|
508
470
|
const filters = this.buildMatchFilters();
|
|
509
471
|
|
|
510
|
-
//
|
|
511
|
-
//
|
|
512
|
-
//
|
|
513
|
-
// holds for a paginator whose filter resolvers were replaced (`setFilterResolvers`), which would
|
|
514
|
-
// otherwise leave `hidden` unresolvable and reject every channel.
|
|
472
|
+
// Like `queryChannels`, exclude hidden channels unless the filter asks for them. Not a synthetic
|
|
473
|
+
// `hidden: false` entry: with replaced resolvers (`setFilterResolvers`) `hidden` would be
|
|
474
|
+
// unresolvable and reject every channel.
|
|
515
475
|
if (channel.data?.hidden && !filterConstrainsField(filters, 'hidden')) return false;
|
|
516
476
|
return itemMatchesFilter<Channel>(channel, filters, {
|
|
517
477
|
resolvers: this._filterFieldToDataResolvers,
|
|
518
478
|
});
|
|
519
479
|
}
|
|
520
480
|
|
|
521
|
-
/**
|
|
522
|
-
* Commits the `predefined_filter` metadata of the response, or clears it when the response carried
|
|
523
|
-
* none (a plain `filter_conditions` query), so a switch away from a predefined filter cannot leave
|
|
524
|
-
* stale matching/ordering semantics behind.
|
|
525
|
-
*/
|
|
481
|
+
/** Commits the response's `predefined_filter` metadata, or clears it when there is none. */
|
|
526
482
|
protected applyPredefinedFilterResponse(
|
|
527
483
|
predefinedFilter: ParsedPredefinedFilterResponse | undefined,
|
|
528
484
|
) {
|
|
@@ -531,12 +487,9 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
531
487
|
}
|
|
532
488
|
|
|
533
489
|
/**
|
|
534
|
-
* The
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
*
|
|
538
|
-
* Committing before `super` matters: the base implementation filters and ingests the page using
|
|
539
|
-
* `matchesFilter` and the comparators this metadata feeds.
|
|
490
|
+
* The metadata describes the query as a whole, so it is committed only when a first page lands (a
|
|
491
|
+
* failed query keeps the loaded list's). It is committed before `super`, which filters and ingests
|
|
492
|
+
* the page using `matchesFilter` and the comparator this metadata feeds.
|
|
540
493
|
*/
|
|
541
494
|
postQueryReconcile(params: PostQueryReconcileParams<Channel, ChannelQueryShape>) {
|
|
542
495
|
const pendingPredefinedFilter = this._pendingPredefinedFilter;
|
|
@@ -547,16 +500,14 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
547
500
|
const replaceOfflineSeed = this._replaceOfflineSeedOnResponse;
|
|
548
501
|
this._replaceOfflineSeedOnResponse = false;
|
|
549
502
|
if (replaceOfflineSeed && params.results) {
|
|
550
|
-
// The cache can be arbitrarily old
|
|
551
|
-
// the
|
|
552
|
-
// page replaces it.
|
|
503
|
+
// The cache can be arbitrarily old and hold channels the server dropped (hidden, deleted,
|
|
504
|
+
// left): the page replaces the seed instead of merging into it.
|
|
553
505
|
this.clearItemStorage();
|
|
554
506
|
return super.postQueryReconcile({ ...params, keepPreviousItems: false });
|
|
555
507
|
}
|
|
556
508
|
return super.postQueryReconcile(params);
|
|
557
509
|
}
|
|
558
510
|
|
|
559
|
-
// invoked inside BasePaginator.executeQuery() to keep it as a query descriptor;
|
|
560
511
|
protected getNextQueryShape({
|
|
561
512
|
pageSize,
|
|
562
513
|
}: { pageSize?: number } = {}): ChannelQueryShape {
|
|
@@ -585,19 +536,11 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
585
536
|
}
|
|
586
537
|
|
|
587
538
|
/**
|
|
588
|
-
* Writes a cid order into the offline cache under the query that produced it.
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
* `predefined_filter` / `filter_values` / `sort_values` appear, without which two predefined-filter
|
|
594
|
-
* lists cannot be told apart. The duplication goes away once `convertFilterSortToQuery` derives the
|
|
595
|
-
* key from `options` (a change in that implementation plus a schema-version bump to flush stale rows).
|
|
596
|
-
*
|
|
597
|
-
* The resolved `predefinedFilter` rides along with the order it produced: a cache-seeded list has no
|
|
598
|
-
* response to learn it from, and without it `effectiveFilters` / `effectiveSort` fall back to the
|
|
599
|
-
* local filters and the default sort - i.e. it would match and order by a different rule than the
|
|
600
|
-
* one the cached order came from.
|
|
539
|
+
* Writes a cid order into the offline cache under the query that produced it. `filters` and `sort`
|
|
540
|
+
* are passed apart from `options` (which already holds them) because the DB implementation derives
|
|
541
|
+
* the cache row key from them, while `options` carries the full request (`predefined_filter`, ...)
|
|
542
|
+
* that tells predefined-filter lists apart. The resolved `predefinedFilter` is stored with the
|
|
543
|
+
* order: a cache-seeded list has no response to learn it from.
|
|
601
544
|
*/
|
|
602
545
|
protected cacheCidsForQuery({
|
|
603
546
|
cids,
|
|
@@ -620,13 +563,12 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
620
563
|
}
|
|
621
564
|
|
|
622
565
|
/**
|
|
623
|
-
* Persists the current cid order under the query that produced it.
|
|
624
|
-
* loaded list
|
|
625
|
-
* running; skipping those would leave the cached order stale until the next full re-query.
|
|
566
|
+
* Persists the current cid order under the query that produced it. Runs after every mutation of
|
|
567
|
+
* the loaded list, including live inserts and removals that reorder it without a query.
|
|
626
568
|
*/
|
|
627
569
|
protected persistLoadedCids() {
|
|
628
|
-
// Without a
|
|
629
|
-
//
|
|
570
|
+
// Without a user the list is being emptied by `disconnectUser()`: what stays in the offline DB
|
|
571
|
+
// is the app's call (`resetDB()`).
|
|
630
572
|
if (!this.client.offlineDb || !this.client.userId) return;
|
|
631
573
|
|
|
632
574
|
this.cacheCidsForQuery({
|
|
@@ -661,7 +603,7 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
661
603
|
}
|
|
662
604
|
return this.client.hydrateChannels(cachedQuery.channels, {
|
|
663
605
|
offlineMode: true,
|
|
664
|
-
skipInitialization: [], //
|
|
606
|
+
skipInitialization: [], // an empty array clears existing channel messages (no duplicates)
|
|
665
607
|
});
|
|
666
608
|
}
|
|
667
609
|
} catch (error) {
|
|
@@ -688,14 +630,11 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
688
630
|
};
|
|
689
631
|
|
|
690
632
|
/**
|
|
691
|
-
*
|
|
692
|
-
*
|
|
693
|
-
*
|
|
694
|
-
*
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
* Only first-page queries defer; paginating an already loaded list is unaffected (as was the legacy
|
|
698
|
-
* `loadNext`).
|
|
633
|
+
* Defers a first-page query (or a page of a cache-seeded list) while the offline sync is in
|
|
634
|
+
* progress: the cached page is shown right away and the network query is handed to the sync
|
|
635
|
+
* manager, which re-runs it after reconciliation. Querying and persisting cids against unsynced
|
|
636
|
+
* local state would race the replay of pending mutations. Paginating a list loaded from the
|
|
637
|
+
* network is not deferred.
|
|
699
638
|
*/
|
|
700
639
|
async executeQuery(params: PaginationQueryParams<ChannelQueryShape> = {}) {
|
|
701
640
|
const { offlineDb } = this.client;
|
|
@@ -710,28 +649,41 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
710
649
|
!!offlineDb?.getChannelsForQuery &&
|
|
711
650
|
!!this.client.user?.id &&
|
|
712
651
|
!offlineDb.syncManager.isSynced &&
|
|
713
|
-
//
|
|
652
|
+
// A cache-seeded list is not a loaded one, so paginating it defers too.
|
|
714
653
|
(this._itemsLoadedFromOfflineDB ||
|
|
715
654
|
this.isFirstPageQuery({ queryShape, reset: effectiveParams.reset }));
|
|
716
655
|
|
|
717
656
|
if (!shouldDeferUntilSynced) return await super.executeQuery(effectiveParams);
|
|
718
657
|
|
|
658
|
+
if (
|
|
659
|
+
this._queryAwaitingSync &&
|
|
660
|
+
!this.config.hasPaginationQueryShapeChanged(this._queryAwaitingSync, queryShape)
|
|
661
|
+
) {
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
this._queryAwaitingSync = queryShape;
|
|
665
|
+
|
|
719
666
|
if (!this.isInitialized) {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
667
|
+
let cachedChannels: Channel[] | undefined;
|
|
668
|
+
try {
|
|
669
|
+
cachedChannels = await this.preloadFirstPageFromOfflineDb({
|
|
670
|
+
...effectiveParams,
|
|
671
|
+
queryShape,
|
|
672
|
+
});
|
|
673
|
+
} catch (error) {
|
|
674
|
+
this._queryAwaitingSync = undefined;
|
|
675
|
+
throw error;
|
|
676
|
+
}
|
|
724
677
|
if (cachedChannels?.length) {
|
|
725
|
-
// Seed via `setItems
|
|
726
|
-
// actually appear within the adequate index.
|
|
678
|
+
// Seed via `setItems`, which ingests the page into the interval/index storage.
|
|
727
679
|
// TODO: Maybe find a better way to do this rather than 2 partialNext invocations
|
|
728
680
|
// running. This all happens so fast it should never be noticeable but it's
|
|
729
681
|
// a microoptimization.
|
|
730
682
|
this.setItems({ valueOrFactory: cachedChannels, isFirstPage: true });
|
|
731
683
|
this._itemsLoadedFromOfflineDB = true;
|
|
732
684
|
}
|
|
733
|
-
// Nothing is in flight while
|
|
734
|
-
//
|
|
685
|
+
// Nothing is in flight while waiting for the sync: `isLoading` would make `canExecuteQuery`
|
|
686
|
+
// reject the query scheduled below.
|
|
735
687
|
this.state.partialNext({ isLoading: false });
|
|
736
688
|
}
|
|
737
689
|
|
|
@@ -741,23 +693,22 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
741
693
|
...(this._itemsLoadedFromOfflineDB ? { reset: 'yes' as const } : {}),
|
|
742
694
|
};
|
|
743
695
|
|
|
744
|
-
//
|
|
745
|
-
// Otherwise, the sync status change will never fire and so `executeQuery` will never really be
|
|
746
|
-
// run.
|
|
696
|
+
// Already synced: the sync-status callback would never fire, so run the query now.
|
|
747
697
|
if (offlineDb.syncManager.isSynced) {
|
|
698
|
+
this._queryAwaitingSync = undefined;
|
|
748
699
|
return await super.executeQuery(refreshParams);
|
|
749
700
|
}
|
|
750
701
|
|
|
751
702
|
offlineDb.syncManager.scheduleSyncStatusChangeCallback(this.id, async () => {
|
|
703
|
+
this._queryAwaitingSync = undefined;
|
|
752
704
|
await this.executeQuery(refreshParams);
|
|
753
705
|
});
|
|
754
706
|
}
|
|
755
707
|
|
|
756
708
|
query = async (): Promise<PaginationQueryReturnValue<Channel>> => {
|
|
757
709
|
if (this._itemsLoadedFromOfflineDB) this._replaceOfflineSeedOnResponse = true;
|
|
758
|
-
// A query is going out
|
|
710
|
+
// A query is going out: the items stop being cache-only, whatever the response.
|
|
759
711
|
this._itemsLoadedFromOfflineDB = false;
|
|
760
|
-
// get the params only if they were not generated previously
|
|
761
712
|
if (!this._nextQueryShape) {
|
|
762
713
|
this._nextQueryShape = this.getNextQueryShape();
|
|
763
714
|
}
|
|
@@ -766,8 +717,7 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
766
717
|
if (this.config.doRequest) {
|
|
767
718
|
items = (await this.config.doRequest(this._nextQueryShape)).items;
|
|
768
719
|
} else {
|
|
769
|
-
// withResponse
|
|
770
|
-
// predefined-filter list needs to know what the backend actually filtered and sorted by.
|
|
720
|
+
// `withResponse` exposes `predefined_filter`, which a predefined-filter list needs.
|
|
771
721
|
const response = await this.client.queryChannelsAndHydrate(request, {
|
|
772
722
|
...stateOptions,
|
|
773
723
|
withResponse: true,
|
|
@@ -786,45 +736,35 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
786
736
|
}
|
|
787
737
|
|
|
788
738
|
/**
|
|
789
|
-
* Places `channel` in the list if it matches, or drops it
|
|
790
|
-
* channel (created from members,
|
|
791
|
-
*
|
|
792
|
-
* cid. It is listed once it has its id, as the channels in a server page always do. Another
|
|
793
|
-
* instance for a stored cid (a superseded one, or one made with `new Channel()`) is replaced by
|
|
794
|
-
* the stored instance (see `ChannelManager.resolveListedChannel`).
|
|
739
|
+
* Places `channel` in the list if it matches, or drops it when it stops matching. A provisional
|
|
740
|
+
* channel (created from members, no ID yet) is refused: it is stored under a temporary cid. Another
|
|
741
|
+
* instance for a stored cid is replaced by the stored one (`ChannelManager.resolveListedChannel`).
|
|
795
742
|
*/
|
|
796
743
|
ingestItem(input: Channel): boolean {
|
|
797
744
|
if (input.isProvisional) return false;
|
|
798
|
-
// the stored instance, never another one for the same cid (see `resolveListedChannel`)
|
|
799
745
|
const channel = this.client.channelManager.resolveListedChannel(input);
|
|
800
746
|
if (!channel) return false;
|
|
801
747
|
const changed = super.ingestItem(channel);
|
|
802
|
-
//
|
|
748
|
+
// A channel outside the result set is not held.
|
|
803
749
|
if (!this.matchesFilter(channel)) this._itemIndex.remove(channel.cid);
|
|
804
750
|
if (changed) this.persistLoadedCids();
|
|
805
751
|
return changed;
|
|
806
752
|
}
|
|
807
753
|
|
|
808
|
-
/**
|
|
809
|
-
* Entity-store subscriber (as the owner of its index). A channel publishes its own changes through
|
|
810
|
-
* `channel.state`, so the list has nothing to re-project when the store reports a change.
|
|
811
|
-
*/
|
|
754
|
+
/** Entity-store subscriber. A channel publishes changes via `channel.state`: nothing to do. */
|
|
812
755
|
onEntitiesChanged(): void {
|
|
813
756
|
return;
|
|
814
757
|
}
|
|
815
758
|
|
|
816
|
-
/**
|
|
817
|
-
* Entity-store subscriber: the store removed a channel this list holds (a known end, logout), so
|
|
818
|
-
* the list drops it from its windows.
|
|
819
|
-
*/
|
|
759
|
+
/** Entity-store subscriber: the store removed a channel this list holds (e.g. logout). */
|
|
820
760
|
onEntityRemoved(id: string, channel: unknown): void {
|
|
821
761
|
this.removeItem({ id, item: channel as Channel });
|
|
822
762
|
}
|
|
823
763
|
|
|
824
764
|
resetState() {
|
|
825
765
|
super.resetState();
|
|
826
|
-
// nothing is listed anymore, so the list holds no channels
|
|
827
766
|
this._itemIndex.clear();
|
|
767
|
+
this._queryAwaitingSync = undefined;
|
|
828
768
|
}
|
|
829
769
|
|
|
830
770
|
removeItem(params: { id?: string; item?: Channel }): ItemCoordinates {
|