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