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
package/src/channel.ts
CHANGED
|
@@ -28,6 +28,7 @@ import { copyConfigPatch } from './configuration/utils/copyConfigPatch';
|
|
|
28
28
|
import { deepFreezeConfig } from './configuration/utils/deepFreezeConfig';
|
|
29
29
|
import { mergeServerRestrictions } from './configuration/utils/serverAuthority';
|
|
30
30
|
import type { ServerRestrictions } from './configuration/utils/serverAuthority';
|
|
31
|
+
import type { CustomEventData } from './custom_types';
|
|
31
32
|
import type { ChannelDeclarativeConfig } from './configuration/types';
|
|
32
33
|
import {
|
|
33
34
|
mergeDeclarativeMessageOperationsConfig,
|
|
@@ -35,6 +36,7 @@ import {
|
|
|
35
36
|
toDeclarativePaginatorConfig,
|
|
36
37
|
} from './configuration/utils/declarativeSlices';
|
|
37
38
|
import type {
|
|
39
|
+
AddMembersRequest,
|
|
38
40
|
AIState,
|
|
39
41
|
BanUserOptions,
|
|
40
42
|
ChannelGetOrCreateRequest,
|
|
@@ -42,21 +44,22 @@ import type {
|
|
|
42
44
|
ChannelMemberResponse,
|
|
43
45
|
ChannelResponse,
|
|
44
46
|
ChannelStateResponseFields,
|
|
45
|
-
ChannelUpdateOptions,
|
|
46
47
|
Command,
|
|
47
48
|
Event,
|
|
48
49
|
EventHandler,
|
|
49
50
|
EventPayload,
|
|
50
51
|
EventType,
|
|
51
52
|
FileUploadInput,
|
|
53
|
+
FilterTagsRequest,
|
|
54
|
+
InviteMembersRequest,
|
|
52
55
|
LocalMessage,
|
|
53
56
|
MarkReadRequest,
|
|
54
57
|
MarkReadResponse,
|
|
55
58
|
MessagePaginationParams,
|
|
56
|
-
MessageRequest,
|
|
57
59
|
MessageResponse,
|
|
58
60
|
MessageSetType,
|
|
59
61
|
QueryMembersPayload,
|
|
62
|
+
RemoveMembersRequest,
|
|
60
63
|
SharedLocation,
|
|
61
64
|
StreamRequestOptions,
|
|
62
65
|
StreamResponse,
|
|
@@ -70,7 +73,6 @@ import { AIStates } from './types';
|
|
|
70
73
|
import type { StateStore } from '@stream-io/state-store';
|
|
71
74
|
import type { Unsubscribe } from '@stream-io/state-store';
|
|
72
75
|
import type {
|
|
73
|
-
ChannelMemberRequest as Gen_ChannelMemberRequest,
|
|
74
76
|
ChannelPushPreferencesResponse as Gen_ChannelPushPreferencesResponse,
|
|
75
77
|
MuteChannelRequest as Gen_MuteChannelRequest,
|
|
76
78
|
UnmuteChannelRequest as Gen_UnmuteChannelRequest,
|
|
@@ -83,14 +85,7 @@ import { ChannelApi } from './gen/chat/ChannelApi';
|
|
|
83
85
|
|
|
84
86
|
const logger = chatLoggerSystem.getLogger('channel');
|
|
85
87
|
|
|
86
|
-
/**
|
|
87
|
-
* The message-operation vocabulary, re-exported so it has a public path: `src/messageOperations` is
|
|
88
|
-
* not part of the root barrel, while `src/index.ts` re-exports this module wholesale.
|
|
89
|
-
*
|
|
90
|
-
* `OperationParams<K>` and `OperationRequestFn<K>` are the one spelling for every operation's
|
|
91
|
-
* parameters and request function — both derived from `MessageOperationSpec`, so adding an operation
|
|
92
|
-
* kind extends them rather than needing a new hand-written pair.
|
|
93
|
-
*/
|
|
88
|
+
/** Re-exported here because `src/messageOperations` is not in the root barrel. */
|
|
94
89
|
export type {
|
|
95
90
|
DefaultOperationRequest,
|
|
96
91
|
MessageOperationSpec,
|
|
@@ -106,11 +101,8 @@ export type CustomMarkReadRequestFn = (params: {
|
|
|
106
101
|
}) => Promise<Partial<StreamResponse<MarkReadResponse>> | null>;
|
|
107
102
|
|
|
108
103
|
/**
|
|
109
|
-
* A channel's
|
|
110
|
-
*
|
|
111
|
-
* Not `ChannelConfigWithInfo`, which is the generated type for the channel *type's server*
|
|
112
|
-
* configuration behind {@link Channel.serverConfig}. The two are related: the gates below are the
|
|
113
|
-
* server's flags already ANDed with what the integrator registered.
|
|
104
|
+
* A channel's resolved configuration, returned by {@link Channel.config}. The gates are the server's
|
|
105
|
+
* flags (see {@link Channel.serverConfig}) ANDed with what the integrator registered.
|
|
114
106
|
*/
|
|
115
107
|
export type ChannelConfig = {
|
|
116
108
|
requestHandlers?: {
|
|
@@ -121,71 +113,39 @@ export type ChannelConfig = {
|
|
|
121
113
|
updateMessageRequest?: OperationRequestFn<'update'>;
|
|
122
114
|
};
|
|
123
115
|
/**
|
|
124
|
-
* Typing indicators
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* This is the channel-wide gate, read by {@link Channel.keystroke} and {@link Channel.stopTyping}.
|
|
128
|
-
* `messageComposer.text.publishTypingEvents` sits on top of it as a per-composer refinement — a thread
|
|
129
|
-
* composer can stay quiet while the channel still permits typing events.
|
|
116
|
+
* Typing indicators. Defaults to enabled. ANDed with the channel type's `typing_events`. Read by
|
|
117
|
+
* {@link Channel.keystroke} and {@link Channel.stopTyping}.
|
|
118
|
+
* `messageComposer.text.publishTypingEvents` further switches them off per composer.
|
|
130
119
|
*/
|
|
131
120
|
typingEvents: { enabled: boolean };
|
|
132
121
|
/**
|
|
133
|
-
* Read receipts
|
|
134
|
-
*
|
|
135
|
-
* {@link Channel.markRead} and {@link Channel.markUnread}.
|
|
122
|
+
* Read receipts. `enabled` is ANDed with the channel type's `read_events`. Read by
|
|
123
|
+
* {@link Channel.markRead} and {@link Channel.markUnread}. Defaults to `true`.
|
|
136
124
|
*
|
|
137
|
-
* `localUnreadCountEnabled`
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* counting locally is what an integrator does *because* the server declines to.
|
|
125
|
+
* `localUnreadCountEnabled` applies only while `enabled` is false: the channel keeps counting
|
|
126
|
+
* unread messages and {@link Channel.markReadLocally} resets the count, sending nothing to the
|
|
127
|
+
* server. The server does not restrict it. Defaults to `false`.
|
|
141
128
|
*/
|
|
142
129
|
readEvents: { enabled: boolean; localUnreadCountEnabled: boolean };
|
|
143
|
-
/**
|
|
144
|
-
* Threaded replies for this channel (defaults to enabled). ANDed with the channel type's `replies`.
|
|
145
|
-
*/
|
|
130
|
+
/** Threaded replies. Defaults to enabled. ANDed with the channel type's `replies`. */
|
|
146
131
|
replies: { enabled: boolean };
|
|
147
132
|
/**
|
|
148
|
-
* Message reminders
|
|
149
|
-
* type's `user_message_reminders`.
|
|
133
|
+
* Message reminders. Defaults to enabled. ANDed with the channel type's `user_message_reminders`.
|
|
150
134
|
*/
|
|
151
135
|
userMessageReminders: { enabled: boolean };
|
|
152
|
-
/**
|
|
153
|
-
* Delivery receipts (defaults to enabled). ANDed with the channel type's `delivery_events`.
|
|
154
|
-
*/
|
|
136
|
+
/** Delivery receipts. Defaults to enabled. ANDed with the channel type's `delivery_events`. */
|
|
155
137
|
deliveryEvents: { enabled: boolean };
|
|
156
138
|
/**
|
|
157
|
-
* The slash commands
|
|
158
|
-
*
|
|
159
|
-
* Named for availability rather than enablement on purpose: whether any given command can be *used*
|
|
160
|
-
* right now is `messageComposer.isCommandDisabled(command)`, which depends on the message context —
|
|
161
|
-
* editing and quoting disable different ones. A list called `enabledCommands` would routinely contain
|
|
162
|
-
* disabled entries.
|
|
163
|
-
*
|
|
164
|
-
* **Server-owned, and the one field here the integrator cannot set.** It is a list rather than a gate,
|
|
165
|
-
* so there is nothing to AND and no intent to express — the server's answer simply *is* the value, and
|
|
166
|
-
* it is absent from the declarative tree for that reason.
|
|
167
|
-
*
|
|
168
|
-
* It lives on the resolved configuration anyway so that consumers never need a second place to look:
|
|
169
|
-
* every question about what this channel permits is answered by `config`. Reading the raw
|
|
170
|
-
* {@link Channel.serverConfig} instead is what made a UI show features the client had disabled — the
|
|
171
|
-
* gates below have a client half, and mixing the two sources meant sometimes reading only one.
|
|
139
|
+
* The slash commands the channel type offers. Server-owned: the integrator cannot set it. Whether a
|
|
140
|
+
* command can be used right now is `messageComposer.isCommandDisabled(command)`.
|
|
172
141
|
*/
|
|
173
142
|
availableCommands: Command[];
|
|
174
143
|
};
|
|
175
144
|
|
|
176
145
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*/
|
|
181
|
-
/**
|
|
182
|
-
* The fields of the declarative `channel` slice that a channel resolves for **itself**.
|
|
183
|
-
*
|
|
184
|
-
* The slice also carries `messagePaginator`, `pinnedMessagesPaginator` and `messageOperations`, which are
|
|
185
|
-
* handed to those objects directly (see {@link Channel.initializeConfig}). Passing the whole slice to the
|
|
186
|
-
* controller published them on `channel.config` as well, where nothing read them: `ChannelConfig` does not
|
|
187
|
-
* declare them, and a registration against one of them notified every `configState` subscriber for a change
|
|
188
|
-
* that did not concern the channel.
|
|
146
|
+
* The fields of the declarative `channel` slice that the channel resolves for itself. The rest
|
|
147
|
+
* (`messagePaginator`, `pinnedMessagesPaginator`, `messageOperations`) go to those objects, see
|
|
148
|
+
* {@link Channel.initializeConfig}.
|
|
189
149
|
*/
|
|
190
150
|
const ownDeclarativeConfig = (
|
|
191
151
|
slice?: ChannelDeclarativeConfig,
|
|
@@ -220,42 +180,29 @@ export const DEFAULT_CHANNEL_CONFIG: ChannelConfig = deepFreezeConfig({
|
|
|
220
180
|
userMessageReminders: { enabled: true },
|
|
221
181
|
});
|
|
222
182
|
|
|
223
|
-
/**
|
|
224
|
-
* The Channel class manages its own state.
|
|
225
|
-
*/
|
|
226
183
|
export class Channel extends ChannelApi {
|
|
227
184
|
_client: StreamChat;
|
|
228
185
|
_data: ChannelInput;
|
|
229
186
|
cid: string;
|
|
230
|
-
/** */
|
|
231
187
|
listeners: Map<EventType, Set<EventHandler>>;
|
|
232
188
|
state: ChannelState;
|
|
233
189
|
lastKeyStroke?: Date;
|
|
234
190
|
lastTypingEvent: Date | null;
|
|
235
191
|
isTyping: boolean;
|
|
236
|
-
/** Re-entrancy guard for {@link Channel.reload}
|
|
192
|
+
/** Re-entrancy guard for {@link Channel.reload}. */
|
|
237
193
|
private _reloading = false;
|
|
238
|
-
/** Refcount
|
|
194
|
+
/** Refcount behind the `active` flag: several consumers can hold one instance. */
|
|
239
195
|
private _activeRefCount = 0;
|
|
240
196
|
private _channelQueriesInFlight = 0;
|
|
241
197
|
/**
|
|
242
|
-
* The watch {@link Channel.ensureWatched} started and is
|
|
243
|
-
*
|
|
244
|
-
* another request; `watch()` calls are not recorded here.
|
|
198
|
+
* The watch {@link Channel.ensureWatched} started and is awaiting. Later `ensureWatched()` calls with
|
|
199
|
+
* the same options wait for it. `watch()` calls are not recorded here.
|
|
245
200
|
*/
|
|
246
201
|
private _ensureWatchedInFlight?: {
|
|
247
202
|
options: ChannelGetOrCreateRequest;
|
|
248
203
|
promise: Promise<unknown>;
|
|
249
204
|
};
|
|
250
205
|
push_preferences?: Gen_ChannelPushPreferencesResponse;
|
|
251
|
-
/**
|
|
252
|
-
* The shared configuration machinery. Owned rather than inherited — `Channel` already extends
|
|
253
|
-
* `ChannelApi`, so single inheritance is spent.
|
|
254
|
-
*
|
|
255
|
-
* `mergeSlice: 'deep'` because the config has nested groups: registering `typingEvents.enabled` must
|
|
256
|
-
* not drop `readEvents`. `applyAuthority` is what makes `channel.config` the *whole* answer rather
|
|
257
|
-
* than the client's half — see {@link serverRestrictions}.
|
|
258
|
-
*/
|
|
259
206
|
private readonly configController: ConfigController<ChannelConfig>;
|
|
260
207
|
public readonly messageComposer: MessageComposer;
|
|
261
208
|
public readonly messageReceiptsTracker: MessageReceiptsTracker;
|
|
@@ -263,24 +210,19 @@ export class Channel extends ChannelApi {
|
|
|
263
210
|
public readonly messagePaginator: MessagePaginator;
|
|
264
211
|
public readonly pinnedMessagesPaginator: PinnedMessagePaginator;
|
|
265
212
|
public readonly cooldownTimer: CooldownTimer;
|
|
266
|
-
/**
|
|
267
|
-
* Teardown for this channel's configuration subscription, released by {@link disconnect}. Left
|
|
268
|
-
* subscribed, a disconnected channel would stay in the configuration store's handler set for good.
|
|
269
|
-
*/
|
|
270
213
|
private unsubscribeConfiguration?: Unsubscribe;
|
|
271
|
-
/** Teardown for the server-config re-derivation subscription, released by {@link disconnect}. */
|
|
272
214
|
private unsubscribeServerConfig?: Unsubscribe;
|
|
273
|
-
/** The declarative slice last derived from, so a late server
|
|
215
|
+
/** The declarative slice last derived from, so a late server config can re-derive from it. */
|
|
274
216
|
private declarativeConfig?: Partial<ChannelConfig>;
|
|
275
217
|
|
|
276
218
|
/**
|
|
277
|
-
* Creates
|
|
219
|
+
* Creates an uninitialized channel. Without an `id` its `cid` is a temporary one built from
|
|
220
|
+
* `data.members`, until the server answers.
|
|
278
221
|
*
|
|
279
222
|
* @param client - The chat client.
|
|
280
|
-
* @param type - The type
|
|
281
|
-
* @param id - The ID
|
|
282
|
-
* @param data -
|
|
283
|
-
* @returns A new uninitialized channel.
|
|
223
|
+
* @param type - The channel type.
|
|
224
|
+
* @param id - The channel ID, or `undefined` for a channel created from members.
|
|
225
|
+
* @param data - Data for the channel (members, custom fields).
|
|
284
226
|
*/
|
|
285
227
|
constructor(
|
|
286
228
|
client: StreamChat,
|
|
@@ -301,46 +243,38 @@ export class Channel extends ChannelApi {
|
|
|
301
243
|
super(client, type, id);
|
|
302
244
|
|
|
303
245
|
this._client = client;
|
|
304
|
-
// this._data is used for the requests...
|
|
305
246
|
this._data = { ...data };
|
|
306
|
-
//
|
|
307
|
-
//
|
|
247
|
+
// Without an ID the cid is a temporary one: the key the channel is stored under
|
|
248
|
+
// (`ensure({ members })`).
|
|
308
249
|
this.cid =
|
|
309
250
|
(!id && generateChannelTempCid(type, (data.members ?? []).map(getMemberUserId))) ||
|
|
310
251
|
`${type}:${id}`;
|
|
311
252
|
this.listeners = new Map();
|
|
312
|
-
// perhaps the state variable should be private
|
|
313
253
|
this.state = new ChannelState(this);
|
|
314
254
|
// after the state exists: the `data` setter writes to it
|
|
315
255
|
this.data = data as Partial<ChannelResponse>;
|
|
316
256
|
this.lastTypingEvent = null;
|
|
317
257
|
this.isTyping = false;
|
|
318
258
|
|
|
319
|
-
// Read the
|
|
320
|
-
//
|
|
321
|
-
// initial cursor/offset), so configuring them afterwards would silently do nothing.
|
|
259
|
+
// Read before the sub-objects are built: some of their fields are read once at construction
|
|
260
|
+
// (`unreadReferencePolicy`, the initial cursor/offset).
|
|
322
261
|
const declarativeConfig = client.config.getConfig('channel') ?? undefined;
|
|
323
|
-
// The
|
|
324
|
-
//
|
|
262
|
+
// The shared `messagePaginator` key applies to every MessagePaginator (channel and threads); the
|
|
263
|
+
// channel's own slice overrides it.
|
|
325
264
|
const messagePaginatorConfig = mergeDeclarativePaginatorConfig(
|
|
326
265
|
client.config.getConfig('messagePaginator') ?? undefined,
|
|
327
266
|
declarativeConfig?.messagePaginator,
|
|
328
267
|
);
|
|
329
268
|
|
|
330
|
-
// The composer reads its own key (`messageComposer`) from the client, so nothing is passed here —
|
|
331
|
-
// composer configuration is deliberately not nested under `channel`.
|
|
332
269
|
this.messageComposer = new MessageComposer({
|
|
333
270
|
client: this._client,
|
|
334
271
|
compositionContext: this,
|
|
335
272
|
});
|
|
336
273
|
|
|
337
|
-
// Created before MessageReceiptsTracker and CooldownTimer
|
|
338
|
-
// (receipts resolve read cursors via findItemByTimestamp; CooldownTimer.refresh reads the
|
|
339
|
-
// latest window at construction).
|
|
274
|
+
// Created before MessageReceiptsTracker and CooldownTimer, which read it.
|
|
340
275
|
this.messagePaginator = new MessagePaginator({
|
|
341
276
|
channel: this,
|
|
342
|
-
//
|
|
343
|
-
// put a non-config key into the paginator's published `config` — see `toDeclarativePaginatorConfig`.
|
|
277
|
+
// A constructor argument, not config (`toDeclarativePaginatorConfig` drops it).
|
|
344
278
|
unreadReferencePolicy: messagePaginatorConfig?.unreadReferencePolicy,
|
|
345
279
|
paginatorOptions: {
|
|
346
280
|
declarativeConfig: toDeclarativePaginatorConfig(messagePaginatorConfig),
|
|
@@ -359,9 +293,7 @@ export class Channel extends ChannelApi {
|
|
|
359
293
|
|
|
360
294
|
this.messageOperations = createMessageOperations(this);
|
|
361
295
|
|
|
362
|
-
//
|
|
363
|
-
// after connect may already be muted). Kept in sync afterwards by the client fan-out on
|
|
364
|
-
// `notification.channel_mutes_updated` / `health.check`.
|
|
296
|
+
// A channel created after connect may already be muted.
|
|
365
297
|
this._syncMuteStatus();
|
|
366
298
|
|
|
367
299
|
this.configController = new ConfigController<ChannelConfig>({
|
|
@@ -369,13 +301,8 @@ export class Channel extends ChannelApi {
|
|
|
369
301
|
initialSlice: ownDeclarativeConfig(declarativeConfig),
|
|
370
302
|
// Nested groups: naming `typingEvents.enabled` must not drop `readEvents`.
|
|
371
303
|
mergeSlice: 'deep',
|
|
372
|
-
// Frozen so a nested write throws
|
|
373
|
-
//
|
|
374
|
-
// time, so the resolved config holds new unfrozen objects rather than the frozen defaults.
|
|
375
|
-
//
|
|
376
|
-
// Copied first, because a subtree of the resolved object and the matching subtree of the slice
|
|
377
|
-
// stored in `client.config` can be the same object — so freezing one freezes the other, and the
|
|
378
|
-
// paginators that resolve from that slice could no longer merge into it.
|
|
304
|
+
// Frozen so a nested write throws. Copied first: a subtree of the resolved config can be the same
|
|
305
|
+
// object as one in the slice stored in `client.config`, and freezing it would freeze that slice.
|
|
379
306
|
applyAuthority: (requested) =>
|
|
380
307
|
deepFreezeConfig(
|
|
381
308
|
copyConfigPatch({
|
|
@@ -383,58 +310,41 @@ export class Channel extends ChannelApi {
|
|
|
383
310
|
requested,
|
|
384
311
|
this.serverRestrictions,
|
|
385
312
|
) as ChannelConfig),
|
|
386
|
-
// Assigned
|
|
387
|
-
// server owns this one outright.
|
|
313
|
+
// Assigned, not merged: the deep merge would concatenate the lists.
|
|
388
314
|
availableCommands: this.serverConfig?.commands ?? [],
|
|
389
315
|
}),
|
|
390
316
|
) as ChannelConfig,
|
|
391
317
|
});
|
|
392
318
|
|
|
393
|
-
// The server
|
|
394
|
-
//
|
|
395
|
-
//
|
|
396
|
-
// server-side would keep a channel that believes read receipts are on.
|
|
397
|
-
//
|
|
398
|
-
// Selected by cid, and `this.cid` is read at selection time rather than captured: a channel created
|
|
399
|
-
// from members alone starts on a temporary cid and adopts the server's in `query()`, which assigns
|
|
400
|
-
// it *before* calling `_addChannelConfig`, so the write that carries the config is already selecting
|
|
401
|
-
// under the real key.
|
|
319
|
+
// The server config usually arrives after construction: re-derive when it lands. `this.cid` is read
|
|
320
|
+
// at selection time because `query()` swaps a temporary cid for the real one before
|
|
321
|
+
// `_addChannelConfig`.
|
|
402
322
|
this.unsubscribeServerConfig = client.channelServerConfigsStore.subscribeWithSelector(
|
|
403
323
|
({ configs }) => ({ channelConfig: configs[this.cid] }),
|
|
404
324
|
() => this.configController.rederive(this.declarativeConfig),
|
|
405
325
|
);
|
|
406
326
|
|
|
407
|
-
//
|
|
408
|
-
//
|
|
409
|
-
// mutable half through the same code a reset uses.
|
|
327
|
+
// The same derivation `config.reset()` runs. The sub-objects were already configured by their
|
|
328
|
+
// constructors; this re-applies the mutable half.
|
|
410
329
|
this.initializeConfig(declarativeConfig);
|
|
411
330
|
|
|
412
|
-
// Last
|
|
413
|
-
// A throwing setup function is contained by the helper, so it cannot break
|
|
414
|
-
// `client.channelManager.ensure()`.
|
|
331
|
+
// Last in the constructor: setup functions may reach every sub-object. Their errors are contained.
|
|
415
332
|
this.unsubscribeConfiguration = applyInstanceConfiguration({
|
|
416
333
|
args: { channel: this },
|
|
417
334
|
config: client.config,
|
|
418
335
|
key: 'channel',
|
|
419
336
|
applyConfig: (config) => this.initializeConfig(config),
|
|
420
|
-
// Reads the slice
|
|
421
|
-
// the declarative store has been cleared, so this correctly derives the un-configured baseline.
|
|
337
|
+
// Reads the slice fresh: reset clears the declarative store before calling this.
|
|
422
338
|
reinitializeConfig: () =>
|
|
423
339
|
this.initializeConfig(client.config.getConfig('channel') ?? undefined),
|
|
424
|
-
//
|
|
425
|
-
//
|
|
426
|
-
//
|
|
340
|
+
// The message paginator and message operations also derive from these shared keys, so a change
|
|
341
|
+
// re-runs the full cycle (declarative, then setup function) to keep the setup function's
|
|
342
|
+
// overrides.
|
|
427
343
|
alsoWatch: ['messagePaginator', 'messageOperations'],
|
|
428
344
|
});
|
|
429
345
|
}
|
|
430
346
|
|
|
431
|
-
/**
|
|
432
|
-
* The configuration fields this channel's *type* decides server-side.
|
|
433
|
-
*
|
|
434
|
-
* Both are boolean gates, so `mergeServerRestrictions` ANDs them with what was requested: either the
|
|
435
|
-
* server or the integrator may switch a feature off, and neither can widen. Re-read on every
|
|
436
|
-
* derivation rather than captured, so a flag that changes mid-session is picked up.
|
|
437
|
-
*/
|
|
347
|
+
/** Flags the channel type decides server-side (ANDed with the requested ones). */
|
|
438
348
|
private get serverRestrictions(): ServerRestrictions<ChannelConfig> {
|
|
439
349
|
const channelConfig = this.serverConfig;
|
|
440
350
|
|
|
@@ -448,29 +358,21 @@ export class Channel extends ChannelApi {
|
|
|
448
358
|
}
|
|
449
359
|
|
|
450
360
|
/**
|
|
451
|
-
*
|
|
361
|
+
* Re-derives the configuration of the channel, its paginators and its message operations from the
|
|
362
|
+
* declarative slice. Runs at construction, on every change to the `channel`, `messagePaginator` or
|
|
363
|
+
* `messageOperations` configuration, and on `client.config.reset()`.
|
|
452
364
|
*
|
|
453
|
-
*
|
|
454
|
-
* `requestHandlers`; each sub-object derives its own configuration, so the knowledge of what
|
|
455
|
-
* `messagePaginator.pageSize` means stays inside the paginator.
|
|
365
|
+
* @param declarativeConfig - The channel's declarative slice (optional).
|
|
456
366
|
*/
|
|
457
367
|
initializeConfig(declarativeConfig?: ChannelDeclarativeConfig): void {
|
|
458
|
-
// Remembered so the server-config subscription can re-derive from the same slice without being
|
|
459
|
-
// handed it again — the server's answer arrives on its own schedule, not the tree's.
|
|
460
368
|
this.declarativeConfig = declarativeConfig as Partial<ChannelConfig> | undefined;
|
|
461
369
|
|
|
462
|
-
//
|
|
463
|
-
//
|
|
464
|
-
//
|
|
465
|
-
//
|
|
466
|
-
// The no-op guard that used to live here is now the controller's: it skips the publish when the
|
|
467
|
-
// resolved value is deep-equal to the last one, which matters because this runs on every
|
|
468
|
-
// `alsoWatch` key change too (a `messagePaginator` or `messageOperations` registration re-runs the
|
|
469
|
-
// whole `channel` cycle), so the no-op publishes outnumber the real ones.
|
|
370
|
+
// Replaces, so a handler dropped from the declarative tree disappears. Direct writes to
|
|
371
|
+
// `configState.requestHandlers` must be re-applied afterwards.
|
|
372
|
+
// The controller skips the publish when the resolved config is deep-equal to the last one.
|
|
470
373
|
this.configController.initialize(ownDeclarativeConfig(declarativeConfig));
|
|
471
374
|
|
|
472
|
-
//
|
|
473
|
-
// every thread's replies — and the per-parent slice overrides it.
|
|
375
|
+
// Shared key first, the channel's own slice overrides it.
|
|
474
376
|
this.messagePaginator.initializeConfig(
|
|
475
377
|
toDeclarativePaginatorConfig(
|
|
476
378
|
mergeDeclarativePaginatorConfig(
|
|
@@ -479,14 +381,12 @@ export class Channel extends ChannelApi {
|
|
|
479
381
|
),
|
|
480
382
|
),
|
|
481
383
|
);
|
|
482
|
-
//
|
|
384
|
+
// No shared key: the pinned paginator has a single parent.
|
|
483
385
|
this.pinnedMessagesPaginator.initializeConfig(
|
|
484
386
|
declarativeConfig?.pinnedMessagesPaginator,
|
|
485
387
|
);
|
|
486
388
|
|
|
487
|
-
//
|
|
488
|
-
// per-parent override — the same shape as `messagePaginator`. Defaults are spread first so a field
|
|
489
|
-
// dropped from the declarative tree returns to its default rather than lingering.
|
|
389
|
+
// Shared key with a per-parent override, as for `messagePaginator`.
|
|
490
390
|
this.messageOperations.initializeConfig(
|
|
491
391
|
mergeDeclarativeMessageOperationsConfig(
|
|
492
392
|
this.getClient().config.getConfig('messageOperations') ?? undefined,
|
|
@@ -496,71 +396,42 @@ export class Channel extends ChannelApi {
|
|
|
496
396
|
}
|
|
497
397
|
|
|
498
398
|
/**
|
|
499
|
-
* Returns the chat client for this channel.
|
|
500
|
-
* {@link Channel.pendingDisposal}.
|
|
399
|
+
* Returns the chat client for this channel.
|
|
501
400
|
*
|
|
502
401
|
* @returns The chat client.
|
|
402
|
+
* @throws If the channel is pending disposal ({@link Channel.pendingDisposal}).
|
|
503
403
|
*/
|
|
504
404
|
getClient(): StreamChat {
|
|
505
405
|
if (this.pendingDisposal) throw this.disposedError();
|
|
506
406
|
return this._client;
|
|
507
407
|
}
|
|
508
408
|
|
|
509
|
-
/** What a call on a disposed instance fails with: it is done for good, and how to get a live one. */
|
|
510
409
|
private disposedError() {
|
|
511
410
|
return new Error(
|
|
512
411
|
`Channel ${this.cid} is pending disposal and cannot be used. Get a fresh instance via client.channelManager.ensure().`,
|
|
513
412
|
);
|
|
514
413
|
}
|
|
515
414
|
|
|
516
|
-
/**
|
|
517
|
-
* Resolved configuration, as a store. Delegates rather than holding a copy, so the field and the
|
|
518
|
-
* controller's store cannot drift.
|
|
519
|
-
*
|
|
520
|
-
* Still directly writable, and deliberately so: the React SDK installs per-component request handlers
|
|
521
|
-
* by calling `partialNext({ requestHandlers })` on it. That write bypasses the controller, which is
|
|
522
|
-
* why `requestHandlers` is the one field a re-derivation replaces wholesale — see
|
|
523
|
-
* {@link initializeConfig}.
|
|
524
|
-
*/
|
|
525
415
|
get configState(): StateStore<ChannelConfig> {
|
|
526
416
|
return this.configController.state;
|
|
527
417
|
}
|
|
528
418
|
|
|
529
|
-
/**
|
|
530
|
-
* This channel's **resolved** configuration — the shape every configurable class exposes.
|
|
531
|
-
*
|
|
532
|
-
* Not to be confused with {@link serverConfig}, which is this channel's configuration as the
|
|
533
|
-
* server reports it. This one has already folded that in: `typingEvents.enabled` is the server's
|
|
534
|
-
* `typing_events` ANDed with whatever the integrator registered, so it is the whole answer. The
|
|
535
|
-
* near-collision is why the server side became `serverConfig`, a getter that says what it
|
|
536
|
-
* is.
|
|
537
|
-
*/
|
|
538
419
|
get config(): Readonly<ChannelConfig> {
|
|
539
420
|
return this.configController.value;
|
|
540
421
|
}
|
|
541
422
|
|
|
542
423
|
/**
|
|
543
|
-
*
|
|
544
|
-
* `
|
|
545
|
-
*
|
|
546
|
-
* Mostly a property of the channel *type*, but not only: a channel's own `config_overrides` narrow it
|
|
547
|
-
* for that channel alone, which is why the cache behind this is keyed by cid rather than by type. See
|
|
548
|
-
* `StreamChat._addChannelConfig`.
|
|
549
|
-
*
|
|
550
|
-
* `undefined` until this channel has been queried or watched — there is nothing to fall back on that
|
|
551
|
-
* would not be another channel's overrides. {@link config} covers that case with its defaults.
|
|
552
|
-
*
|
|
553
|
-
* Distinct from {@link config}, which is this instance's resolved configuration and already has the
|
|
554
|
-
* relevant flags below folded into it. Prefer `config` when deciding whether a feature is available:
|
|
555
|
-
* this getter answers only the server's half, so gating UI on it offers features the client has
|
|
556
|
-
* already disabled.
|
|
424
|
+
* The channel's configuration as the server reports it (`uploads`, `typing_events`, `commands`, ...),
|
|
425
|
+
* including this channel's `config_overrides`. `undefined` until the channel is queried or watched.
|
|
426
|
+
* Gate features on {@link config} instead: it also folds in what the integrator disabled.
|
|
557
427
|
*/
|
|
558
428
|
get serverConfig() {
|
|
559
429
|
return this.getClient().channelServerConfigs[this.cid];
|
|
560
430
|
}
|
|
561
431
|
|
|
562
432
|
/**
|
|
563
|
-
* Sends a message to this channel.
|
|
433
|
+
* Sends a message to this channel. Strips `localMetadata` from attachments and drops those whose
|
|
434
|
+
* upload never completed.
|
|
564
435
|
*
|
|
565
436
|
* @param ...args - `[request, requestOptions]`. `request` holds the message body and optional
|
|
566
437
|
* flags such as `skip_enrich_url`, `skip_push`, and `keep_channel_hidden`; `requestOptions`
|
|
@@ -587,11 +458,12 @@ export class Channel extends ChannelApi {
|
|
|
587
458
|
}
|
|
588
459
|
|
|
589
460
|
/**
|
|
590
|
-
*
|
|
461
|
+
* Uploads a file to this channel's file endpoint (multipart).
|
|
591
462
|
*
|
|
592
463
|
* @param request - Upload payload. `request.file` is the file to upload.
|
|
593
|
-
* @param requestOptions - Per-request options, e.g. `onUploadProgress` or an abort `signal`
|
|
594
|
-
*
|
|
464
|
+
* @param requestOptions - Per-request options, e.g. `onUploadProgress` or an abort `signal`
|
|
465
|
+
* (optional).
|
|
466
|
+
* @returns The upload response, with the CDN URL in `file`.
|
|
595
467
|
*/
|
|
596
468
|
override async uploadChannelFile(
|
|
597
469
|
request?: Omit<UploadChannelFileRequest, 'file'> & { file?: FileUploadInput },
|
|
@@ -604,11 +476,12 @@ export class Channel extends ChannelApi {
|
|
|
604
476
|
}
|
|
605
477
|
|
|
606
478
|
/**
|
|
607
|
-
*
|
|
479
|
+
* Uploads an image to this channel's image endpoint (multipart).
|
|
608
480
|
*
|
|
609
481
|
* @param request - Upload payload. `request.file` is the image to upload.
|
|
610
|
-
* @param requestOptions - Per-request options, e.g. `onUploadProgress` or an abort `signal`
|
|
611
|
-
*
|
|
482
|
+
* @param requestOptions - Per-request options, e.g. `onUploadProgress` or an abort `signal`
|
|
483
|
+
* (optional).
|
|
484
|
+
* @returns The upload response, with the CDN URL in `file`.
|
|
612
485
|
*/
|
|
613
486
|
override async uploadChannelImage(
|
|
614
487
|
request?: Omit<UploadChannelRequest, 'file'> & { file?: FileUploadInput },
|
|
@@ -620,37 +493,36 @@ export class Channel extends ChannelApi {
|
|
|
620
493
|
);
|
|
621
494
|
}
|
|
622
495
|
|
|
623
|
-
/**
|
|
624
|
-
* Alias for {@link uploadChannelFile}, mirroring `client.uploadFile`.
|
|
625
|
-
*/
|
|
496
|
+
/** Alias for {@link uploadChannelFile}. */
|
|
626
497
|
uploadFile = (...args: Parameters<Channel['uploadChannelFile']>) =>
|
|
627
498
|
this.uploadChannelFile(...args);
|
|
628
499
|
|
|
629
|
-
/** Alias for {@link uploadChannelImage}
|
|
500
|
+
/** Alias for {@link uploadChannelImage}. */
|
|
630
501
|
uploadImage = (...args: Parameters<Channel['uploadChannelImage']>) =>
|
|
631
502
|
this.uploadChannelImage(...args);
|
|
632
503
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
504
|
+
/**
|
|
505
|
+
* Deletes a file uploaded to this channel, the same request shape as `client.deleteFile`.
|
|
506
|
+
*
|
|
507
|
+
* @param request - The file to delete. `request.url` is its URL.
|
|
508
|
+
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
509
|
+
* into the request (optional).
|
|
510
|
+
* @returns The server response.
|
|
511
|
+
*/
|
|
512
|
+
deleteFile(request: { url: string }, requestOptions?: StreamRequestOptions) {
|
|
513
|
+
return this.deleteChannelFile(request, requestOptions);
|
|
639
514
|
}
|
|
640
515
|
|
|
641
516
|
/**
|
|
642
|
-
*
|
|
517
|
+
* Deletes an image uploaded to this channel, the same request shape as `client.deleteImage`.
|
|
643
518
|
*
|
|
644
|
-
* @param request -
|
|
519
|
+
* @param request - The image to delete. `request.url` is its URL.
|
|
645
520
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
646
521
|
* into the request (optional).
|
|
647
522
|
* @returns The server response.
|
|
648
523
|
*/
|
|
649
|
-
|
|
650
|
-
request
|
|
651
|
-
requestOptions?: StreamRequestOptions,
|
|
652
|
-
) {
|
|
653
|
-
return await super.sendEvent(request, requestOptions);
|
|
524
|
+
deleteImage(request: { url: string }, requestOptions?: StreamRequestOptions) {
|
|
525
|
+
return this.deleteChannelImage(request, requestOptions);
|
|
654
526
|
}
|
|
655
527
|
|
|
656
528
|
/**
|
|
@@ -683,7 +555,6 @@ export class Channel extends ChannelApi {
|
|
|
683
555
|
user_id: (m.user_id ?? m.user?.id) as string,
|
|
684
556
|
}));
|
|
685
557
|
}
|
|
686
|
-
// Return a list of members
|
|
687
558
|
return await this.getClient().queryMembers(
|
|
688
559
|
{
|
|
689
560
|
payload: {
|
|
@@ -696,12 +567,11 @@ export class Channel extends ChannelApi {
|
|
|
696
567
|
}
|
|
697
568
|
|
|
698
569
|
/**
|
|
699
|
-
*
|
|
700
|
-
* server-returned channel onto `this.data`.
|
|
570
|
+
* Updates the channel and stores the returned channel in `this.data`.
|
|
701
571
|
*
|
|
702
572
|
* @param ...args - `[request, requestOptions]`. `request` is the channel update payload, e.g.
|
|
703
|
-
* `{ data: { name: 'foo' }, message }`; `requestOptions` carries per-request options
|
|
704
|
-
* abort `signal` and is never serialized into the request.
|
|
573
|
+
* `{ data: { custom: { name: 'foo' } }, message }`; `requestOptions` carries per-request options
|
|
574
|
+
* such as an abort `signal` and is never serialized into the request.
|
|
705
575
|
* @returns The server response.
|
|
706
576
|
*/
|
|
707
577
|
override async update(...args: Parameters<ChannelApi['update']>) {
|
|
@@ -711,10 +581,10 @@ export class Channel extends ChannelApi {
|
|
|
711
581
|
}
|
|
712
582
|
|
|
713
583
|
/**
|
|
714
|
-
*
|
|
584
|
+
* Partially updates the channel's properties and stores the returned channel in `this.data`.
|
|
715
585
|
*
|
|
716
586
|
* @param update - The partial update request.
|
|
717
|
-
* @param
|
|
587
|
+
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
718
588
|
* into the request (optional).
|
|
719
589
|
* @returns The server response.
|
|
720
590
|
*/
|
|
@@ -733,7 +603,6 @@ export class Channel extends ChannelApi {
|
|
|
733
603
|
[...currentCapabilities].sort().join() !== [...newCapabilities].sort().join();
|
|
734
604
|
|
|
735
605
|
this.data = channel;
|
|
736
|
-
// If the capabiltities are changed, we trigger the `capabilities.changed` event.
|
|
737
606
|
if (capabilitiesChanged) {
|
|
738
607
|
this.getClient().dispatchEvent({
|
|
739
608
|
type: 'capabilities.changed',
|
|
@@ -749,7 +618,7 @@ export class Channel extends ChannelApi {
|
|
|
749
618
|
* Enables slow mode.
|
|
750
619
|
*
|
|
751
620
|
* @param coolDownInterval - The cooldown interval in seconds.
|
|
752
|
-
* @param
|
|
621
|
+
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
753
622
|
* into the request (optional).
|
|
754
623
|
* @returns The server response.
|
|
755
624
|
*/
|
|
@@ -760,16 +629,11 @@ export class Channel extends ChannelApi {
|
|
|
760
629
|
/**
|
|
761
630
|
* Disables slow mode.
|
|
762
631
|
*
|
|
763
|
-
* @param _request - Unused. Holds the request position so `requestOptions` stays the
|
|
764
|
-
* second argument, as on the generated methods; pass `undefined`.
|
|
765
632
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
766
633
|
* into the request (optional).
|
|
767
634
|
* @returns The server response.
|
|
768
635
|
*/
|
|
769
|
-
async disableSlowMode(
|
|
770
|
-
_request?: Record<string, never>,
|
|
771
|
-
requestOptions?: StreamRequestOptions,
|
|
772
|
-
) {
|
|
636
|
+
async disableSlowMode(requestOptions?: StreamRequestOptions) {
|
|
773
637
|
return await this.update({ cooldown: 0 }, requestOptions);
|
|
774
638
|
}
|
|
775
639
|
|
|
@@ -780,7 +644,7 @@ export class Channel extends ChannelApi {
|
|
|
780
644
|
const result = await queueOrRun({
|
|
781
645
|
channel: this,
|
|
782
646
|
client: this.getClient(),
|
|
783
|
-
// Nothing to key a queue entry on without a message
|
|
647
|
+
// Nothing to key a queue entry on without a message ID, so it runs but is not queued.
|
|
784
648
|
queue: !!messageId,
|
|
785
649
|
task: {
|
|
786
650
|
channelId: this.id,
|
|
@@ -806,8 +670,7 @@ export class Channel extends ChannelApi {
|
|
|
806
670
|
requestOptions?: StreamRequestOptions,
|
|
807
671
|
) {
|
|
808
672
|
this._checkHasId();
|
|
809
|
-
// Picked
|
|
810
|
-
// `channel_cid`, timestamps, …), and the request is sent as given.
|
|
673
|
+
// Picked, not spread: callers pass a whole shared location whose extra fields must not be sent.
|
|
811
674
|
const { latitude, longitude, message_id } = payload;
|
|
812
675
|
const location = await this.getClient().updateLiveLocation(
|
|
813
676
|
{ end_at: new Date(), latitude, longitude, message_id },
|
|
@@ -822,13 +685,13 @@ export class Channel extends ChannelApi {
|
|
|
822
685
|
/**
|
|
823
686
|
* Accepts an invitation to the channel.
|
|
824
687
|
*
|
|
825
|
-
* @param options -
|
|
688
|
+
* @param options - Other channel update options to send with it. Defaults to `{}`.
|
|
826
689
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
827
690
|
* into the request (optional).
|
|
828
691
|
* @returns The server response.
|
|
829
692
|
*/
|
|
830
693
|
async acceptInvite(
|
|
831
|
-
options:
|
|
694
|
+
options: NonNullable<Parameters<ChannelApi['update']>[0]> = {},
|
|
832
695
|
requestOptions?: StreamRequestOptions,
|
|
833
696
|
) {
|
|
834
697
|
return await this.update({ accept_invite: true, ...options }, requestOptions);
|
|
@@ -837,13 +700,13 @@ export class Channel extends ChannelApi {
|
|
|
837
700
|
/**
|
|
838
701
|
* Rejects an invitation to the channel.
|
|
839
702
|
*
|
|
840
|
-
* @param options -
|
|
703
|
+
* @param options - Other channel update options to send with it. Defaults to `{}`.
|
|
841
704
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
842
705
|
* into the request (optional).
|
|
843
706
|
* @returns The server response.
|
|
844
707
|
*/
|
|
845
708
|
async rejectInvite(
|
|
846
|
-
options:
|
|
709
|
+
options: NonNullable<Parameters<ChannelApi['update']>[0]> = {},
|
|
847
710
|
requestOptions?: StreamRequestOptions,
|
|
848
711
|
) {
|
|
849
712
|
return await this.update({ reject_invite: true, ...options }, requestOptions);
|
|
@@ -852,17 +715,15 @@ export class Channel extends ChannelApi {
|
|
|
852
715
|
/**
|
|
853
716
|
* Adds members to the channel.
|
|
854
717
|
*
|
|
855
|
-
* @param
|
|
856
|
-
* @param
|
|
857
|
-
* @param
|
|
718
|
+
* @param request - The members to add, and any other channel update option.
|
|
719
|
+
* @param request.members - User IDs, or member requests (`{ user_id, channel_role?, custom? }`).
|
|
720
|
+
* @param request.message - Message object for channel members notification (optional).
|
|
858
721
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
859
722
|
* into the request (optional).
|
|
860
723
|
* @returns The server response.
|
|
861
724
|
*/
|
|
862
725
|
async addMembers(
|
|
863
|
-
members
|
|
864
|
-
message?: MessageRequest,
|
|
865
|
-
options: ChannelUpdateOptions = {},
|
|
726
|
+
{ members, ...options }: AddMembersRequest,
|
|
866
727
|
requestOptions?: StreamRequestOptions,
|
|
867
728
|
) {
|
|
868
729
|
return await this.update(
|
|
@@ -870,7 +731,6 @@ export class Channel extends ChannelApi {
|
|
|
870
731
|
add_members: members.map((member) =>
|
|
871
732
|
typeof member === 'string' ? { user_id: member } : member,
|
|
872
733
|
),
|
|
873
|
-
message,
|
|
874
734
|
...options,
|
|
875
735
|
},
|
|
876
736
|
requestOptions,
|
|
@@ -880,61 +740,49 @@ export class Channel extends ChannelApi {
|
|
|
880
740
|
/**
|
|
881
741
|
* Adds filter tags to the channel.
|
|
882
742
|
*
|
|
883
|
-
* @param
|
|
884
|
-
* @param
|
|
885
|
-
* @param
|
|
743
|
+
* @param request - The tags to add, and any other channel update option.
|
|
744
|
+
* @param request.tags - The tags to add.
|
|
745
|
+
* @param request.message - Message object for channel members notification (optional).
|
|
886
746
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
887
747
|
* into the request (optional).
|
|
888
748
|
* @returns The server response.
|
|
889
749
|
*/
|
|
890
750
|
async addFilterTags(
|
|
891
|
-
tags:
|
|
892
|
-
message?: MessageRequest,
|
|
893
|
-
options: ChannelUpdateOptions = {},
|
|
751
|
+
{ tags, ...options }: FilterTagsRequest,
|
|
894
752
|
requestOptions?: StreamRequestOptions,
|
|
895
753
|
) {
|
|
896
|
-
return await this.update(
|
|
897
|
-
{ add_filter_tags: tags, message, ...options },
|
|
898
|
-
requestOptions,
|
|
899
|
-
);
|
|
754
|
+
return await this.update({ add_filter_tags: tags, ...options }, requestOptions);
|
|
900
755
|
}
|
|
901
756
|
|
|
902
757
|
/**
|
|
903
758
|
* Removes filter tags from the channel.
|
|
904
759
|
*
|
|
905
|
-
* @param
|
|
906
|
-
* @param
|
|
907
|
-
* @param
|
|
760
|
+
* @param request - The tags to remove, and any other channel update option.
|
|
761
|
+
* @param request.tags - The tags to remove.
|
|
762
|
+
* @param request.message - Message object for channel members notification (optional).
|
|
908
763
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
909
764
|
* into the request (optional).
|
|
910
765
|
* @returns The server response.
|
|
911
766
|
*/
|
|
912
767
|
async removeFilterTags(
|
|
913
|
-
tags:
|
|
914
|
-
message?: MessageRequest,
|
|
915
|
-
options: ChannelUpdateOptions = {},
|
|
768
|
+
{ tags, ...options }: FilterTagsRequest,
|
|
916
769
|
requestOptions?: StreamRequestOptions,
|
|
917
770
|
) {
|
|
918
|
-
return await this.update(
|
|
919
|
-
{ remove_filter_tags: tags, message, ...options },
|
|
920
|
-
requestOptions,
|
|
921
|
-
);
|
|
771
|
+
return await this.update({ remove_filter_tags: tags, ...options }, requestOptions);
|
|
922
772
|
}
|
|
923
773
|
|
|
924
774
|
/**
|
|
925
775
|
* Invite members to the channel.
|
|
926
776
|
*
|
|
927
|
-
* @param
|
|
928
|
-
* @param
|
|
929
|
-
* @param
|
|
777
|
+
* @param request - The members to invite, and any other channel update option.
|
|
778
|
+
* @param request.members - User IDs, or member requests (`{ user_id, custom }`).
|
|
779
|
+
* @param request.message - Message object for channel members notification (optional).
|
|
930
780
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
931
781
|
* into the request (optional).
|
|
932
782
|
* @returns The server response.
|
|
933
783
|
*/
|
|
934
784
|
async inviteMembers(
|
|
935
|
-
members
|
|
936
|
-
message?: MessageRequest,
|
|
937
|
-
options: ChannelUpdateOptions = {},
|
|
785
|
+
{ members, ...options }: InviteMembersRequest,
|
|
938
786
|
requestOptions?: StreamRequestOptions,
|
|
939
787
|
) {
|
|
940
788
|
return await this.update(
|
|
@@ -942,7 +790,6 @@ export class Channel extends ChannelApi {
|
|
|
942
790
|
invites: members.map((member) =>
|
|
943
791
|
typeof member === 'string' ? { user_id: member } : member,
|
|
944
792
|
),
|
|
945
|
-
message,
|
|
946
793
|
...options,
|
|
947
794
|
},
|
|
948
795
|
requestOptions,
|
|
@@ -952,38 +799,29 @@ export class Channel extends ChannelApi {
|
|
|
952
799
|
/**
|
|
953
800
|
* Removes members from the channel.
|
|
954
801
|
*
|
|
955
|
-
* @param
|
|
956
|
-
* @param
|
|
957
|
-
* @param
|
|
802
|
+
* @param request - The members to remove, and any other channel update option.
|
|
803
|
+
* @param request.members - The user IDs to remove.
|
|
804
|
+
* @param request.message - Message object for channel members notification (optional).
|
|
958
805
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
959
806
|
* into the request (optional).
|
|
960
807
|
* @returns The server response.
|
|
961
808
|
*/
|
|
962
809
|
async removeMembers(
|
|
963
|
-
members:
|
|
964
|
-
message?: MessageRequest,
|
|
965
|
-
options: ChannelUpdateOptions = {},
|
|
810
|
+
{ members, ...options }: RemoveMembersRequest,
|
|
966
811
|
requestOptions?: StreamRequestOptions,
|
|
967
812
|
) {
|
|
968
|
-
return await this.update(
|
|
969
|
-
{ remove_members: members, message, ...options },
|
|
970
|
-
requestOptions,
|
|
971
|
-
);
|
|
813
|
+
return await this.update({ remove_members: members, ...options }, requestOptions);
|
|
972
814
|
}
|
|
973
815
|
|
|
974
816
|
/**
|
|
975
|
-
* Mutes the
|
|
976
|
-
*
|
|
977
|
-
* @example
|
|
978
|
-
* // with expiration
|
|
979
|
-
* await channel.mute({ expiration: moment.duration(2, 'weeks') });
|
|
817
|
+
* Mutes the channel.
|
|
980
818
|
*
|
|
981
819
|
* @example
|
|
982
|
-
* //
|
|
983
|
-
* await channel.mute({
|
|
820
|
+
* // with expiration (two weeks)
|
|
821
|
+
* await channel.mute({ expiration: 14 * 24 * 60 * 60 * 1000 });
|
|
984
822
|
*
|
|
985
|
-
* @param options - Mute options (optional
|
|
986
|
-
* @param options.expiration -
|
|
823
|
+
* @param options - Mute options (optional).
|
|
824
|
+
* @param options.expiration - Mute duration in milliseconds (optional).
|
|
987
825
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
988
826
|
* into the request (optional).
|
|
989
827
|
* @returns The server response.
|
|
@@ -1001,14 +839,12 @@ export class Channel extends ChannelApi {
|
|
|
1001
839
|
}
|
|
1002
840
|
|
|
1003
841
|
/**
|
|
1004
|
-
* Unmutes the
|
|
842
|
+
* Unmutes the channel.
|
|
1005
843
|
*
|
|
1006
844
|
* @example
|
|
1007
|
-
*
|
|
1008
|
-
* await channel.unmute({ user_id: userId });
|
|
845
|
+
* await channel.unmute();
|
|
1009
846
|
*
|
|
1010
|
-
* @param options - Unmute options (optional
|
|
1011
|
-
* @param options.user_id - User ID (optional).
|
|
847
|
+
* @param options - Unmute options (optional).
|
|
1012
848
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
1013
849
|
* into the request (optional).
|
|
1014
850
|
* @returns The server response.
|
|
@@ -1029,77 +865,66 @@ export class Channel extends ChannelApi {
|
|
|
1029
865
|
}
|
|
1030
866
|
|
|
1031
867
|
/**
|
|
1032
|
-
* Archives the current
|
|
868
|
+
* Archives the channel for the current user.
|
|
1033
869
|
*
|
|
1034
870
|
* @example
|
|
1035
871
|
* await channel.archive();
|
|
1036
872
|
*
|
|
1037
|
-
* @param _request - Unused. Holds the request position so `requestOptions` stays the
|
|
1038
|
-
* second argument, as on the generated methods; pass `undefined`.
|
|
1039
873
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
1040
874
|
* into the request (optional).
|
|
1041
875
|
* @returns The server response.
|
|
1042
876
|
*/
|
|
1043
|
-
async archive(
|
|
877
|
+
async archive(requestOptions?: StreamRequestOptions) {
|
|
1044
878
|
return await this.updateMemberPartial({ set: { archived: true } }, requestOptions);
|
|
1045
879
|
}
|
|
1046
880
|
|
|
1047
881
|
/**
|
|
1048
|
-
* Unarchives the current
|
|
882
|
+
* Unarchives the channel for the current user.
|
|
1049
883
|
*
|
|
1050
884
|
* @example
|
|
1051
885
|
* await channel.unarchive();
|
|
1052
886
|
*
|
|
1053
|
-
* @param _request - Unused. Holds the request position so `requestOptions` stays the
|
|
1054
|
-
* second argument, as on the generated methods; pass `undefined`.
|
|
1055
887
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
1056
888
|
* into the request (optional).
|
|
1057
889
|
* @returns The server response.
|
|
1058
890
|
*/
|
|
1059
|
-
async unarchive(
|
|
1060
|
-
_request?: Record<string, never>,
|
|
1061
|
-
requestOptions?: StreamRequestOptions,
|
|
1062
|
-
) {
|
|
891
|
+
async unarchive(requestOptions?: StreamRequestOptions) {
|
|
1063
892
|
return await this.updateMemberPartial({ set: { archived: false } }, requestOptions);
|
|
1064
893
|
}
|
|
1065
894
|
|
|
1066
895
|
/**
|
|
1067
|
-
* Pins the current
|
|
896
|
+
* Pins the channel for the current user.
|
|
1068
897
|
*
|
|
1069
898
|
* @example
|
|
1070
899
|
* await channel.pin();
|
|
1071
900
|
*
|
|
1072
|
-
* @param _request - Unused. Holds the request position so `requestOptions` stays the
|
|
1073
|
-
* second argument, as on the generated methods; pass `undefined`.
|
|
1074
901
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
1075
902
|
* into the request (optional).
|
|
1076
903
|
* @returns The server response.
|
|
1077
904
|
*/
|
|
1078
|
-
async pin(
|
|
905
|
+
async pin(requestOptions?: StreamRequestOptions) {
|
|
1079
906
|
return await this.updateMemberPartial({ set: { pinned: true } }, requestOptions);
|
|
1080
907
|
}
|
|
1081
908
|
|
|
1082
909
|
/**
|
|
1083
|
-
* Unpins the current
|
|
910
|
+
* Unpins the channel for the current user.
|
|
1084
911
|
*
|
|
1085
912
|
* @example
|
|
1086
913
|
* await channel.unpin();
|
|
1087
914
|
*
|
|
1088
|
-
* @param _request - Unused. Holds the request position so `requestOptions` stays the
|
|
1089
|
-
* second argument, as on the generated methods; pass `undefined`.
|
|
1090
915
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
1091
916
|
* into the request (optional).
|
|
1092
917
|
* @returns The server response.
|
|
1093
918
|
*/
|
|
1094
|
-
async unpin(
|
|
919
|
+
async unpin(requestOptions?: StreamRequestOptions) {
|
|
1095
920
|
return await this.updateMemberPartial({ set: { pinned: false } }, requestOptions);
|
|
1096
921
|
}
|
|
1097
922
|
|
|
1098
923
|
/**
|
|
1099
|
-
* Returns the mute status
|
|
924
|
+
* Returns the mute status of the channel.
|
|
1100
925
|
*
|
|
1101
|
-
* @returns
|
|
1102
|
-
*
|
|
926
|
+
* @returns `{ muted, createdAt, expiresAt }`, the timestamps in unix nanoseconds as the API sends
|
|
927
|
+
* them.
|
|
1103
928
|
*/
|
|
1104
929
|
muteStatus() {
|
|
1105
930
|
this._checkHasId();
|
|
@@ -1107,10 +932,8 @@ export class Channel extends ChannelApi {
|
|
|
1107
932
|
}
|
|
1108
933
|
|
|
1109
934
|
/**
|
|
1110
|
-
* Recomputes
|
|
1111
|
-
*
|
|
1112
|
-
* churn subscribers. Called from the constructor and by the client whenever `mutedChannels`
|
|
1113
|
-
* updates. Unlike `muteStatus()`, this does not require the channel to be initialized.
|
|
935
|
+
* Recomputes `state.muteStatus` from `client.mutedChannels`, publishing only on change (the client
|
|
936
|
+
* calls this on every `mutedChannels` update). Unlike `muteStatus()`, it needs no channel ID.
|
|
1114
937
|
*/
|
|
1115
938
|
_syncMuteStatus() {
|
|
1116
939
|
if (this.pendingDisposal) return;
|
|
@@ -1141,21 +964,15 @@ export class Channel extends ChannelApi {
|
|
|
1141
964
|
}
|
|
1142
965
|
|
|
1143
966
|
/**
|
|
1144
|
-
*
|
|
1145
|
-
* Call this on every keystroke.
|
|
967
|
+
* Call on every keystroke: sends `typing.start` at most every 2 seconds.
|
|
1146
968
|
*
|
|
1147
969
|
* @see {@link https://getstream.io/chat/docs/typing_indicators/?language=js|Docs}
|
|
1148
970
|
*
|
|
1149
|
-
* @param parentId -
|
|
1150
|
-
* @param options - Optional override carrying a `user_id` (optional).
|
|
971
|
+
* @param parentId - The parent message ID, for a typing event in a thread (optional).
|
|
1151
972
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
1152
973
|
* into the request (optional).
|
|
1153
974
|
*/
|
|
1154
|
-
async keystroke(
|
|
1155
|
-
parentId?: string,
|
|
1156
|
-
options?: { user_id: string },
|
|
1157
|
-
requestOptions?: StreamRequestOptions,
|
|
1158
|
-
) {
|
|
975
|
+
async keystroke(parentId?: string, requestOptions?: StreamRequestOptions) {
|
|
1159
976
|
if (!this._isTypingIndicatorsEnabled()) {
|
|
1160
977
|
return;
|
|
1161
978
|
}
|
|
@@ -1163,7 +980,6 @@ export class Channel extends ChannelApi {
|
|
|
1163
980
|
const diff = this.lastTypingEvent && now.getTime() - this.lastTypingEvent.getTime();
|
|
1164
981
|
this.lastKeyStroke = now;
|
|
1165
982
|
this.isTyping = true;
|
|
1166
|
-
// send a typing.start every 2 seconds
|
|
1167
983
|
if (diff === null || diff > 2000) {
|
|
1168
984
|
this.lastTypingEvent = new Date();
|
|
1169
985
|
await this.sendEvent(
|
|
@@ -1171,9 +987,6 @@ export class Channel extends ChannelApi {
|
|
|
1171
987
|
event: {
|
|
1172
988
|
type: 'typing.start',
|
|
1173
989
|
parent_id: parentId,
|
|
1174
|
-
...(options || {}),
|
|
1175
|
-
created_at: nowNs(),
|
|
1176
|
-
custom: {},
|
|
1177
990
|
},
|
|
1178
991
|
},
|
|
1179
992
|
requestOptions,
|
|
@@ -1182,12 +995,11 @@ export class Channel extends ChannelApi {
|
|
|
1182
995
|
}
|
|
1183
996
|
|
|
1184
997
|
/**
|
|
1185
|
-
*
|
|
1186
|
-
* Typically used by the server connected to the AI service to notify clients of state changes.
|
|
998
|
+
* Notifies watchers of a message's AI state. Meant for the server connected to the AI service.
|
|
1187
999
|
*
|
|
1188
1000
|
* @param messageId - The ID of the message associated with the AI state.
|
|
1189
1001
|
* @param state - The new state of the AI process, e.g. thinking, generating.
|
|
1190
|
-
* @param options -
|
|
1002
|
+
* @param options - Additional details for the event. Defaults to `{}`.
|
|
1191
1003
|
* @param options.ai_message - Additional message detail to include in the event (optional).
|
|
1192
1004
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
1193
1005
|
* into the request (optional).
|
|
@@ -1201,12 +1013,13 @@ export class Channel extends ChannelApi {
|
|
|
1201
1013
|
await this.sendEvent(
|
|
1202
1014
|
{
|
|
1203
1015
|
event: {
|
|
1204
|
-
...options,
|
|
1205
1016
|
type: 'ai_indicator.update',
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1017
|
+
// The API reads these fields from `custom`. They aren't app custom data, hence the assertion.
|
|
1018
|
+
custom: {
|
|
1019
|
+
...options,
|
|
1020
|
+
message_id: messageId,
|
|
1021
|
+
ai_state: state,
|
|
1022
|
+
} as CustomEventData,
|
|
1210
1023
|
},
|
|
1211
1024
|
},
|
|
1212
1025
|
requestOptions,
|
|
@@ -1217,21 +1030,14 @@ export class Channel extends ChannelApi {
|
|
|
1217
1030
|
* Sends an event to notify watchers to clear the typing/thinking UI when the AI response starts streaming.
|
|
1218
1031
|
* Typically used by the server connected to the AI service to inform clients that the AI response has started.
|
|
1219
1032
|
*
|
|
1220
|
-
* @param _request - Unused. Holds the request position so `requestOptions` stays the
|
|
1221
|
-
* second argument, as on the generated methods; pass `undefined`.
|
|
1222
1033
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
1223
1034
|
* into the request (optional).
|
|
1224
1035
|
*/
|
|
1225
|
-
async clearAIIndicator(
|
|
1226
|
-
_request?: Record<string, never>,
|
|
1227
|
-
requestOptions?: StreamRequestOptions,
|
|
1228
|
-
) {
|
|
1036
|
+
async clearAIIndicator(requestOptions?: StreamRequestOptions) {
|
|
1229
1037
|
await this.sendEvent(
|
|
1230
1038
|
{
|
|
1231
1039
|
event: {
|
|
1232
1040
|
type: 'ai_indicator.clear',
|
|
1233
|
-
created_at: nowNs(),
|
|
1234
|
-
custom: {},
|
|
1235
1041
|
},
|
|
1236
1042
|
},
|
|
1237
1043
|
requestOptions,
|
|
@@ -1242,21 +1048,14 @@ export class Channel extends ChannelApi {
|
|
|
1242
1048
|
* Sends an event to stop AI response generation, leaving the message in its current state.
|
|
1243
1049
|
* Triggered by the user to halt the AI response process.
|
|
1244
1050
|
*
|
|
1245
|
-
* @param _request - Unused. Holds the request position so `requestOptions` stays the
|
|
1246
|
-
* second argument, as on the generated methods; pass `undefined`.
|
|
1247
1051
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
1248
1052
|
* into the request (optional).
|
|
1249
1053
|
*/
|
|
1250
|
-
async stopAIResponse(
|
|
1251
|
-
_request?: Record<string, never>,
|
|
1252
|
-
requestOptions?: StreamRequestOptions,
|
|
1253
|
-
) {
|
|
1054
|
+
async stopAIResponse(requestOptions?: StreamRequestOptions) {
|
|
1254
1055
|
await this.sendEvent(
|
|
1255
1056
|
{
|
|
1256
1057
|
event: {
|
|
1257
1058
|
type: 'ai_indicator.stop',
|
|
1258
|
-
created_at: nowNs(),
|
|
1259
|
-
custom: {},
|
|
1260
1059
|
},
|
|
1261
1060
|
},
|
|
1262
1061
|
requestOptions,
|
|
@@ -1264,20 +1063,13 @@ export class Channel extends ChannelApi {
|
|
|
1264
1063
|
}
|
|
1265
1064
|
|
|
1266
1065
|
/**
|
|
1267
|
-
*
|
|
1066
|
+
* Resets the typing state and sends `typing.stop`.
|
|
1268
1067
|
*
|
|
1269
|
-
* @
|
|
1270
|
-
*
|
|
1271
|
-
* @param parentId - Set this field to `message.id` to indicate that the typing event is happening in a thread (optional).
|
|
1272
|
-
* @param options - Optional override carrying a `user_id` (optional).
|
|
1068
|
+
* @param parentId - The parent message ID, for a typing event in a thread (optional).
|
|
1273
1069
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
1274
1070
|
* into the request (optional).
|
|
1275
1071
|
*/
|
|
1276
|
-
async stopTyping(
|
|
1277
|
-
parentId?: string,
|
|
1278
|
-
options?: { user_id: string },
|
|
1279
|
-
requestOptions?: StreamRequestOptions,
|
|
1280
|
-
) {
|
|
1072
|
+
async stopTyping(parentId?: string, requestOptions?: StreamRequestOptions) {
|
|
1281
1073
|
if (!this._isTypingIndicatorsEnabled()) {
|
|
1282
1074
|
return;
|
|
1283
1075
|
}
|
|
@@ -1288,9 +1080,6 @@ export class Channel extends ChannelApi {
|
|
|
1288
1080
|
event: {
|
|
1289
1081
|
type: 'typing.stop',
|
|
1290
1082
|
parent_id: parentId,
|
|
1291
|
-
...(options || {}),
|
|
1292
|
-
created_at: nowNs(),
|
|
1293
|
-
custom: {},
|
|
1294
1083
|
},
|
|
1295
1084
|
},
|
|
1296
1085
|
requestOptions,
|
|
@@ -1298,11 +1087,9 @@ export class Channel extends ChannelApi {
|
|
|
1298
1087
|
}
|
|
1299
1088
|
|
|
1300
1089
|
_isTypingIndicatorsEnabled(): boolean {
|
|
1301
|
-
// nobody to tell
|
|
1090
|
+
// No ID yet: nobody to tell.
|
|
1302
1091
|
if (this.isProvisional) return false;
|
|
1303
|
-
// The resolved value
|
|
1304
|
-
// with what the integrator registered, so a client-side `typingEvents.enabled: false` is honoured
|
|
1305
|
-
// too. The other two axes are runtime facts no configuration can express.
|
|
1092
|
+
// The resolved value (server `typing_events` ANDed with the client's setting), not the raw flag.
|
|
1306
1093
|
const { typingEvents } = this.configController.value;
|
|
1307
1094
|
if (!typingEvents.enabled || !this.getClient().wsConnection?.isHealthy) {
|
|
1308
1095
|
return false;
|
|
@@ -1311,26 +1098,25 @@ export class Channel extends ChannelApi {
|
|
|
1311
1098
|
}
|
|
1312
1099
|
|
|
1313
1100
|
/**
|
|
1314
|
-
*
|
|
1315
|
-
*
|
|
1316
|
-
*
|
|
1101
|
+
* Marks read through `MessageDeliveryReporter`: uses the `markReadRequest` handler if set, marks
|
|
1102
|
+
* read locally when read events are off and `localUnreadCountEnabled` is set, and drops the
|
|
1103
|
+
* delivery candidate when a request went out. `markRead()` does none of this.
|
|
1317
1104
|
*
|
|
1318
|
-
*
|
|
1319
|
-
*
|
|
1320
|
-
* @param data - Mark read options (optional, defaults to `{}`).
|
|
1105
|
+
* @param data - Mark read options. Defaults to `{}`.
|
|
1106
|
+
* @returns The server response, or `null` when no request went out.
|
|
1321
1107
|
*/
|
|
1322
1108
|
async markReadViaReporter(data: MarkReadRequest = {}) {
|
|
1323
1109
|
return await this.getClient().messageDeliveryReporter.markRead(this, data);
|
|
1324
1110
|
}
|
|
1325
1111
|
|
|
1326
1112
|
/**
|
|
1327
|
-
*
|
|
1328
|
-
* channel to be initialized and respects the `read_events` channel config.
|
|
1113
|
+
* Marks the channel read.
|
|
1329
1114
|
*
|
|
1330
1115
|
* @param ...args - `[data, requestOptions]`. `data` holds the mark-read options;
|
|
1331
1116
|
* `requestOptions` carries per-request options such as an abort `signal` and is never
|
|
1332
1117
|
* serialized into the request.
|
|
1333
|
-
* @returns The server response
|
|
1118
|
+
* @returns The server response.
|
|
1119
|
+
* @throws If the channel is not initialized or read events are disabled.
|
|
1334
1120
|
*/
|
|
1335
1121
|
override async markRead(...args: Parameters<ChannelApi['markRead']>) {
|
|
1336
1122
|
this._checkInitialized();
|
|
@@ -1344,11 +1130,7 @@ export class Channel extends ChannelApi {
|
|
|
1344
1130
|
return await super.markRead(...args);
|
|
1345
1131
|
}
|
|
1346
1132
|
|
|
1347
|
-
/**
|
|
1348
|
-
* Whether a live server response was applied to this instance since it was created — see
|
|
1349
|
-
* {@link ChannelLifecycleState.initialized}. Store-backed and reactive: subscribe via
|
|
1350
|
-
* `useStateStore(channel.state, (s) => ({ initialized: s.initialized }))`.
|
|
1351
|
-
*/
|
|
1133
|
+
/** See {@link ChannelLifecycleState.initialized}. */
|
|
1352
1134
|
get initialized() {
|
|
1353
1135
|
return this.state.getLatestValue().initialized;
|
|
1354
1136
|
}
|
|
@@ -1358,37 +1140,26 @@ export class Channel extends ChannelApi {
|
|
|
1358
1140
|
}
|
|
1359
1141
|
|
|
1360
1142
|
/**
|
|
1361
|
-
* Whether the channel has no
|
|
1362
|
-
*
|
|
1363
|
-
* the temporary one built from the members. A channel with an id is never provisional, whether or
|
|
1364
|
-
* not the server has it: requests for it go to the server, which answers for it.
|
|
1143
|
+
* Whether the channel has no ID yet: it was built from members and the server assigns the ID when its
|
|
1144
|
+
* query is answered. Until then only that query can be sent and the cid is a temporary one.
|
|
1365
1145
|
*
|
|
1366
|
-
* Not reactive
|
|
1367
|
-
*
|
|
1146
|
+
* Not reactive: subscribe to {@link Channel.initialized}, which turns `true` with the response that
|
|
1147
|
+
* sets `id`.
|
|
1368
1148
|
*/
|
|
1369
1149
|
get isProvisional() {
|
|
1370
1150
|
return !this.id;
|
|
1371
1151
|
}
|
|
1372
1152
|
|
|
1373
1153
|
/**
|
|
1374
|
-
*
|
|
1375
|
-
*
|
|
1376
|
-
*
|
|
1377
|
-
* A superseded instance receives no events (they go to the stored instance under its cid) and
|
|
1378
|
-
* reports `watchStatus: NotWatching`. Use the successor from then on: switch a UI showing this
|
|
1379
|
-
* instance to it, as `ChatView` does. `ensureWatched()` resolves with it.
|
|
1380
|
-
*
|
|
1381
|
-
* The SDK never disconnects a superseded instance on its own before logout, as the app may still
|
|
1382
|
-
* hold it. Call {@link Channel.disconnect} on it once nothing uses it.
|
|
1154
|
+
* See {@link ChannelLifecycleState.supersededBy}. A superseded instance receives no events and
|
|
1155
|
+
* reports `watchStatus: NotWatching`: use its successor (`ensureWatched()` resolves with it). The SDK
|
|
1156
|
+
* does not disconnect it before logout, so call {@link Channel.disconnect} once nothing uses it.
|
|
1383
1157
|
*/
|
|
1384
1158
|
get supersededBy() {
|
|
1385
1159
|
return this.state.getLatestValue().supersededBy;
|
|
1386
1160
|
}
|
|
1387
1161
|
|
|
1388
|
-
/**
|
|
1389
|
-
* Whether the channel was initialized by manually populating its state (offline hydration) rather
|
|
1390
|
-
* than a live watch. Store-backed and reactive.
|
|
1391
|
-
*/
|
|
1162
|
+
/** See {@link ChannelLifecycleState.offlineMode}. */
|
|
1392
1163
|
get offlineMode() {
|
|
1393
1164
|
return this.state.getLatestValue().offlineMode;
|
|
1394
1165
|
}
|
|
@@ -1398,12 +1169,10 @@ export class Channel extends ChannelApi {
|
|
|
1398
1169
|
}
|
|
1399
1170
|
|
|
1400
1171
|
/**
|
|
1401
|
-
*
|
|
1402
|
-
*
|
|
1403
|
-
*
|
|
1404
|
-
*
|
|
1405
|
-
* with the store. The assigned object itself is never changed; editing `channel.data.x` in place
|
|
1406
|
-
* doesn't reach the state.
|
|
1172
|
+
* Reads `state.data`. Assigning publishes `data`, `memberCount` and `ownCapabilities` in one update.
|
|
1173
|
+
* If the object omits `member_count` or `own_capabilities`, the last known values are carried onto
|
|
1174
|
+
* a copy (the assigned object is not changed). Editing `channel.data.x` in place does not reach
|
|
1175
|
+
* the state.
|
|
1407
1176
|
*/
|
|
1408
1177
|
get data(): Partial<ChannelResponse> | undefined {
|
|
1409
1178
|
return this.state.getLatestValue().data;
|
|
@@ -1415,7 +1184,7 @@ export class Channel extends ChannelApi {
|
|
|
1415
1184
|
typeof next?.member_count !== 'number' && typeof previous?.member_count === 'number'
|
|
1416
1185
|
? previous.member_count
|
|
1417
1186
|
: undefined;
|
|
1418
|
-
// `own_capabilities` stays undefined until known, so "not loaded" isn't read as "none"
|
|
1187
|
+
// `own_capabilities` stays undefined until known, so "not loaded" isn't read as "none"
|
|
1419
1188
|
const carriedCapabilities =
|
|
1420
1189
|
!Array.isArray(next?.own_capabilities) && Array.isArray(previous?.own_capabilities)
|
|
1421
1190
|
? [...previous.own_capabilities]
|
|
@@ -1440,27 +1209,15 @@ export class Channel extends ChannelApi {
|
|
|
1440
1209
|
}
|
|
1441
1210
|
|
|
1442
1211
|
/**
|
|
1443
|
-
*
|
|
1444
|
-
*
|
|
1445
|
-
*
|
|
1446
|
-
* One-way and terminal — read-only, set only by {@link Channel.disconnect}, and nothing revives
|
|
1447
|
-
* the instance. Its resources are already released ({@link Channel.disconnect} disposes the
|
|
1448
|
-
* paginators and unregisters the subscriptions), so nothing should touch it. It stays in the
|
|
1449
|
-
* channel store until `client.channelManager.releaseUnusedChannels()` drops it, and until then the
|
|
1450
|
-
* SDK treats it as not stored: `client.channelManager.ensure(…)` gives a fresh instance for its
|
|
1451
|
-
* cid, lists refuse it, and recovery never re-watches it. The offline DB refuses it as a source of
|
|
1452
|
-
* `channel.data`, and `getClient()` throws on it, so a reference held across a `disconnectUser()`
|
|
1453
|
-
* fails loudly instead of quietly requesting on a client with no user.
|
|
1212
|
+
* See {@link ChannelLifecycleState.pendingDisposal}. Set only by {@link Channel.disconnect} and never
|
|
1213
|
+
* reverted: `getClient()` throws, `client.channelManager.ensure()` returns a fresh instance for the
|
|
1214
|
+
* cid, and lists and recovery skip it.
|
|
1454
1215
|
*/
|
|
1455
1216
|
get pendingDisposal() {
|
|
1456
1217
|
return this.state.getLatestValue().pendingDisposal;
|
|
1457
1218
|
}
|
|
1458
1219
|
|
|
1459
|
-
/**
|
|
1460
|
-
* Whether this client holds a server-side watch on the channel, and if not, whether it should be
|
|
1461
|
-
* restored — see {@link ChannelWatchStatus}. Store-backed and reactive: subscribe via
|
|
1462
|
-
* `useStateStore(channel.state, (s) => ({ watchStatus: s.watchStatus }))`.
|
|
1463
|
-
*/
|
|
1220
|
+
/** See {@link ChannelWatchStatus}. */
|
|
1464
1221
|
get watchStatus() {
|
|
1465
1222
|
return this.state.getLatestValue().watchStatus;
|
|
1466
1223
|
}
|
|
@@ -1470,8 +1227,8 @@ export class Channel extends ChannelApi {
|
|
|
1470
1227
|
}
|
|
1471
1228
|
|
|
1472
1229
|
/**
|
|
1473
|
-
* Whether a query for this channel (`watch()`, `query()`, `create()`)
|
|
1474
|
-
*
|
|
1230
|
+
* Whether a query for this channel (`watch()`, `query()`, `create()`) awaits its response. The
|
|
1231
|
+
* channel store keeps the channel meanwhile.
|
|
1475
1232
|
*
|
|
1476
1233
|
* @internal
|
|
1477
1234
|
*/
|
|
@@ -1479,32 +1236,19 @@ export class Channel extends ChannelApi {
|
|
|
1479
1236
|
return this._channelQueriesInFlight > 0;
|
|
1480
1237
|
}
|
|
1481
1238
|
|
|
1482
|
-
/**
|
|
1483
|
-
* Whether a consumer has declared this channel as the one it is currently consuming (see
|
|
1484
|
-
* {@link Channel.activate}). Reactive — subscribe via
|
|
1485
|
-
* `useStateStore(channel.state, (s) => ({ active: s.active }))`.
|
|
1486
|
-
*/
|
|
1239
|
+
/** See {@link Channel.activate}. */
|
|
1487
1240
|
get active() {
|
|
1488
1241
|
return this.state.getLatestValue().active;
|
|
1489
1242
|
}
|
|
1490
1243
|
|
|
1491
1244
|
/**
|
|
1492
|
-
* Declares that a consumer is
|
|
1493
|
-
*
|
|
1494
|
-
*
|
|
1495
|
-
* nothing.
|
|
1496
|
-
*
|
|
1497
|
-
* While active, the channel's own state takes precedence over bulk state writes: channel-list
|
|
1498
|
-
* hydration does not re-seed its message list (its own `channel.reload()` owns that window).
|
|
1499
|
-
*
|
|
1500
|
-
* An active channel also stays in the channel store. Once the last consumer releases it, it is
|
|
1501
|
-
* kept only while something else uses it (a watch, a channel list, a claim). A superseded channel
|
|
1502
|
-
* (see {@link ChannelLifecycleState.supersededBy}) is never disconnected by its release: the app
|
|
1503
|
-
* may still hold it. It ends at logout, or when the app calls {@link Channel.disconnect}.
|
|
1245
|
+
* Declares that a consumer is consuming this channel's own state and returns its release function.
|
|
1246
|
+
* Refcounted: the channel stays active until the last consumer releases, and releasing twice is a
|
|
1247
|
+
* no-op.
|
|
1504
1248
|
*
|
|
1505
|
-
*
|
|
1506
|
-
*
|
|
1507
|
-
* the returned release does nothing
|
|
1249
|
+
* While active, channel-list hydration does not re-seed the message list (`channel.reload()` owns
|
|
1250
|
+
* it) and the channel stays in the channel store. A disposed channel is not activated: a warning is
|
|
1251
|
+
* logged and the returned release does nothing.
|
|
1508
1252
|
*/
|
|
1509
1253
|
activate = (): (() => void) => {
|
|
1510
1254
|
if (this.pendingDisposal) {
|
|
@@ -1528,12 +1272,13 @@ export class Channel extends ChannelApi {
|
|
|
1528
1272
|
};
|
|
1529
1273
|
|
|
1530
1274
|
/**
|
|
1531
|
-
* Marks the channel
|
|
1275
|
+
* Marks the channel unread from a message.
|
|
1532
1276
|
*
|
|
1533
1277
|
* @param ...args - `[data, requestOptions]`. `data` holds the mark-unread options;
|
|
1534
1278
|
* `requestOptions` carries per-request options such as an abort `signal` and is never
|
|
1535
1279
|
* serialized into the request.
|
|
1536
|
-
* @returns
|
|
1280
|
+
* @returns The server response.
|
|
1281
|
+
* @throws If the channel is not initialized or read events are disabled.
|
|
1537
1282
|
*/
|
|
1538
1283
|
override async markUnread(...args: Parameters<ChannelApi['markUnread']>) {
|
|
1539
1284
|
this._checkInitialized();
|
|
@@ -1548,15 +1293,13 @@ export class Channel extends ChannelApi {
|
|
|
1548
1293
|
}
|
|
1549
1294
|
|
|
1550
1295
|
/**
|
|
1551
|
-
* Resets
|
|
1552
|
-
*
|
|
1553
|
-
* `
|
|
1554
|
-
*
|
|
1555
|
-
* delivery-report network sync), so the read-state update lives in one place. When offline support
|
|
1556
|
-
* is enabled, the offline DB persists the reset for read-events-disabled channels, so the local
|
|
1557
|
-
* count stays consistent across app restarts.
|
|
1296
|
+
* Resets the unread count without a backend call, for channels with read events disabled (e.g.
|
|
1297
|
+
* livestreams) that set `readEvents.localUnreadCountEnabled`. Dispatches the client-only
|
|
1298
|
+
* `message.read_locally` event, handled like `message.read` minus the delivery-report sync. With
|
|
1299
|
+
* offline support the reset is persisted.
|
|
1558
1300
|
*
|
|
1559
|
-
* @returns The dispatched `message.read_locally` event, or `undefined` if there is no connected
|
|
1301
|
+
* @returns The dispatched `message.read_locally` event, or `undefined` if there is no connected
|
|
1302
|
+
* user.
|
|
1560
1303
|
*/
|
|
1561
1304
|
markReadLocally() {
|
|
1562
1305
|
const client = this.getClient();
|
|
@@ -1578,7 +1321,10 @@ export class Channel extends ChannelApi {
|
|
|
1578
1321
|
}
|
|
1579
1322
|
|
|
1580
1323
|
/**
|
|
1581
|
-
*
|
|
1324
|
+
* Sends `typing.stop` after a second without a keystroke, drops stale typing users, and resets a
|
|
1325
|
+
* stuck AI indicator while the connection is unhealthy. Run by the client's cleaning interval.
|
|
1326
|
+
*
|
|
1327
|
+
* @internal
|
|
1582
1328
|
*/
|
|
1583
1329
|
clean() {
|
|
1584
1330
|
if (this.lastKeyStroke) {
|
|
@@ -1591,10 +1337,8 @@ export class Channel extends ChannelApi {
|
|
|
1591
1337
|
|
|
1592
1338
|
this.state.clean();
|
|
1593
1339
|
|
|
1594
|
-
//
|
|
1595
|
-
//
|
|
1596
|
-
// path clears the indicator itself. Gate on health, not staleness — a healthy connection must
|
|
1597
|
-
// never cut off a long-running response.
|
|
1340
|
+
// Clears an AI indicator stuck because the ending clear/stop was missed while offline. Gated on
|
|
1341
|
+
// health, not staleness: a healthy connection must not cut off a long-running response.
|
|
1598
1342
|
const client = this.getClient();
|
|
1599
1343
|
if (!client.wsConnection?.isHealthy) {
|
|
1600
1344
|
this.state.resetAIState();
|
|
@@ -1602,33 +1346,23 @@ export class Channel extends ChannelApi {
|
|
|
1602
1346
|
}
|
|
1603
1347
|
|
|
1604
1348
|
/**
|
|
1605
|
-
* Watches the channel unless it is watched already
|
|
1606
|
-
*
|
|
1607
|
-
*
|
|
1608
|
-
*
|
|
1349
|
+
* Watches the channel unless it is watched already. A call made while an earlier `ensureWatched()`
|
|
1350
|
+
* with the same options is in flight waits for that request instead of sending another. `watch()` and
|
|
1351
|
+
* `query()` always send theirs. An already watched channel sends nothing, so `options` (such as a
|
|
1352
|
+
* message window) apply only when the call watches it.
|
|
1609
1353
|
*
|
|
1610
|
-
*
|
|
1611
|
-
* and are not joined by this method. A channel already watched sends nothing, so `options` such as
|
|
1612
|
-
* a message window apply only when the call watches it; use the message paginator to load a window.
|
|
1613
|
-
*
|
|
1614
|
-
* Resolves with the instance to use from now on: this one, or the one that superseded it
|
|
1615
|
-
* ({@link Channel.supersededBy}). A channel created from members is superseded when its watch
|
|
1616
|
-
* answers with a cid another instance is already stored under; that instance is the one stored,
|
|
1617
|
-
* listed and receiving events, so it is the one this ensures watched and resolves with.
|
|
1618
|
-
*
|
|
1619
|
-
* Rejects as the watch does, and every caller waiting for that watch gets its rejection. The next
|
|
1620
|
-
* call sends a new request.
|
|
1354
|
+
* Rejects as the watch does, for every caller waiting on it. The next call sends a new request.
|
|
1621
1355
|
*
|
|
1622
1356
|
* @param options - Options for the watch request (optional). Calls join only a watch with the same
|
|
1623
1357
|
* options.
|
|
1624
|
-
* @returns The instance to use,
|
|
1625
|
-
*
|
|
1358
|
+
* @returns The instance to use: this one, or the one that superseded it
|
|
1359
|
+
* ({@link Channel.supersededBy}).
|
|
1626
1360
|
*/
|
|
1627
1361
|
async ensureWatched(options?: ChannelGetOrCreateRequest): Promise<Channel> {
|
|
1628
1362
|
if (this.supersededBy) return this.supersededBy.ensureWatched(options);
|
|
1629
1363
|
if (this.watchStatus === ChannelWatchStatus.Watching) return this;
|
|
1630
1364
|
const requested = options ?? {};
|
|
1631
|
-
//
|
|
1365
|
+
// Deep equality: key order doesn't matter.
|
|
1632
1366
|
if (
|
|
1633
1367
|
this._ensureWatchedInFlight &&
|
|
1634
1368
|
isEqual(this._ensureWatchedInFlight.options, requested)
|
|
@@ -1647,18 +1381,17 @@ export class Channel extends ChannelApi {
|
|
|
1647
1381
|
return this.afterEnsuredWatch(options);
|
|
1648
1382
|
}
|
|
1649
1383
|
|
|
1650
|
-
/** This instance, or its successor if the watch just superseded it (see `ensureWatched`). */
|
|
1651
1384
|
private afterEnsuredWatch(options?: ChannelGetOrCreateRequest) {
|
|
1652
1385
|
return this.supersededBy ? this.supersededBy.ensureWatched(options) : this;
|
|
1653
1386
|
}
|
|
1654
1387
|
|
|
1655
1388
|
/**
|
|
1656
|
-
* Loads the initial
|
|
1389
|
+
* Loads the initial state and watches for changes. The latest message page is loaded when this
|
|
1390
|
+
* resolves.
|
|
1657
1391
|
*
|
|
1658
1392
|
* @param options - Additional options for the query endpoint (optional).
|
|
1659
1393
|
* @param requestOptions - Per-request options such as an abort `signal` (optional). The signal
|
|
1660
|
-
*
|
|
1661
|
-
* wait with it.
|
|
1394
|
+
* also ends the wait for a live socket.
|
|
1662
1395
|
* @returns The server response.
|
|
1663
1396
|
*/
|
|
1664
1397
|
async watch(
|
|
@@ -1673,41 +1406,22 @@ export class Channel extends ChannelApi {
|
|
|
1673
1406
|
|
|
1674
1407
|
const combined = { ...defaultOptions, ...options };
|
|
1675
1408
|
|
|
1676
|
-
//
|
|
1677
|
-
//
|
|
1678
|
-
// `watchStatus = Watching` is truthful by construction — while a call asking for neither goes out
|
|
1679
|
-
// with no socket at all.
|
|
1409
|
+
// `ApiClient` holds a request that watches or subscribes to presence until the handshake yields a
|
|
1410
|
+
// connection ID, so `watch: true` binds to a current one and `watchStatus = Watching` is truthful.
|
|
1680
1411
|
const state = await this.query(combined, 'latest', requestOptions);
|
|
1681
1412
|
this.data = state.channel;
|
|
1682
1413
|
|
|
1683
|
-
// The message paginator is seeded synchronously inside query() (before read-state hydration),
|
|
1684
|
-
// so a channel opened via watch() alone — a deep-link restore, a search result, a freshly
|
|
1685
|
-
// created DM — already has its latest page loaded here.
|
|
1686
|
-
|
|
1687
1414
|
logger.withExtraTags('watch', this.cid).info('Started watching the channel.');
|
|
1688
1415
|
return state;
|
|
1689
1416
|
}
|
|
1690
1417
|
|
|
1691
1418
|
/**
|
|
1692
|
-
* Re-
|
|
1693
|
-
* {@link Thread.reload}. Used on reconnect
|
|
1694
|
-
*
|
|
1695
|
-
* of it by diffing the re-queried page.
|
|
1696
|
-
*
|
|
1697
|
-
* This is intentionally thin: it only re-issues `watch()` with a limit sized to the loaded window
|
|
1698
|
-
* (`items.length`, so the whole loaded window is refreshed — not the smaller channel-list page). The
|
|
1699
|
-
* actual fold + destructive reconciliation happens inside `query()` → `seedFirstPageSync`
|
|
1700
|
-
* (the same path the channel-list re-hydrate and connection recovery use), driven by the loaded-id
|
|
1701
|
-
* snapshot `query()` captures before its await. Owning that single path is what lets the SDK stop
|
|
1702
|
-
* passing the reconciliation window/snapshot itself.
|
|
1419
|
+
* Re-watches the channel and refreshes its whole loaded message window (the channel analog of
|
|
1420
|
+
* {@link Thread.reload}). Used on reconnect. Hard deletes reach other clients through no event, so
|
|
1421
|
+
* `query()` (`seedFirstPageSync`) reconciles them by diffing the re-queried page.
|
|
1703
1422
|
*
|
|
1704
|
-
*
|
|
1705
|
-
*
|
|
1706
|
-
* fell out are re-ingested below. The offline DB is consulted alongside the in-memory window, because
|
|
1707
|
-
* a failed message can be absent from memory and still be the user's unsent work — a cold boot starts
|
|
1708
|
-
* with an empty paginator, and an eviction can drop it mid-session. v9 got this from a second, lagging
|
|
1709
|
-
* copy of the list (the React SDK's own state); with one reactive source of truth the persisted row is
|
|
1710
|
-
* that buffer.
|
|
1423
|
+
* Failed (unsent) messages are kept: any that fell out of the window are re-ingested. The offline DB
|
|
1424
|
+
* is read too, since a failed message can be absent from memory (cold boot, eviction).
|
|
1711
1425
|
*/
|
|
1712
1426
|
async reload() {
|
|
1713
1427
|
if (this._reloading || (!this.initialized && !this.offlineMode)) return;
|
|
@@ -1719,14 +1433,13 @@ export class Channel extends ChannelApi {
|
|
|
1719
1433
|
Math.max(headItems.length, paginator.pageSize ?? 0) || undefined;
|
|
1720
1434
|
const offlineDb = this.getClient().offlineDb;
|
|
1721
1435
|
const failedInMemory = headItems.filter((message) => message.status === 'failed');
|
|
1722
|
-
// Read before the
|
|
1723
|
-
// one is already in the paginator and does not need re-ingesting.
|
|
1436
|
+
// Read before the watch: a message that fails during the reload is already in the paginator.
|
|
1724
1437
|
const failedInDb = offlineDb
|
|
1725
1438
|
? await offlineDb.getFailedMessages({ cid: this.cid })
|
|
1726
1439
|
: [];
|
|
1727
1440
|
const failedById = new Map<string, LocalMessage>();
|
|
1728
1441
|
for (const message of [...failedInDb, ...failedInMemory]) {
|
|
1729
|
-
// In-memory wins
|
|
1442
|
+
// In-memory wins: it is at least as fresh as the persisted row.
|
|
1730
1443
|
failedById.set(message.id, message);
|
|
1731
1444
|
}
|
|
1732
1445
|
const failedBefore = [...failedById.values()];
|
|
@@ -1735,8 +1448,7 @@ export class Channel extends ChannelApi {
|
|
|
1735
1448
|
this.offlineMode = false;
|
|
1736
1449
|
|
|
1737
1450
|
if (failedBefore.length) {
|
|
1738
|
-
//
|
|
1739
|
-
// reingested after the watch() query.
|
|
1451
|
+
// Re-ingest the failed messages the watch() query dropped.
|
|
1740
1452
|
const visible = new Set((paginator.items ?? []).map((message) => message.id));
|
|
1741
1453
|
paginator.batch(
|
|
1742
1454
|
() => {
|
|
@@ -1763,7 +1475,7 @@ export class Channel extends ChannelApi {
|
|
|
1763
1475
|
override async stopWatching(...args: Parameters<ChannelApi['stopWatching']>) {
|
|
1764
1476
|
const response = await super.stopWatching(...args);
|
|
1765
1477
|
|
|
1766
|
-
//
|
|
1478
|
+
// Unlike a connection loss, this is not restored on reconnect.
|
|
1767
1479
|
this.watchStatus = ChannelWatchStatus.NotWatching;
|
|
1768
1480
|
|
|
1769
1481
|
logger.withExtraTags('stopWatching', this.cid).info('Stopped watching the channel.');
|
|
@@ -1772,19 +1484,19 @@ export class Channel extends ChannelApi {
|
|
|
1772
1484
|
}
|
|
1773
1485
|
|
|
1774
1486
|
/**
|
|
1775
|
-
* Retrieves
|
|
1487
|
+
* Retrieves messages of this channel by ID.
|
|
1776
1488
|
*
|
|
1777
|
-
* @param messageIds - The IDs of the messages to retrieve
|
|
1489
|
+
* @param messageIds - The IDs of the messages to retrieve.
|
|
1778
1490
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
1779
1491
|
* into the request (optional).
|
|
1780
|
-
* @returns
|
|
1492
|
+
* @returns The server response.
|
|
1781
1493
|
*/
|
|
1782
1494
|
getMessagesById(messageIds: string[], requestOptions?: StreamRequestOptions) {
|
|
1783
1495
|
return this.getManyMessages({ ids: messageIds }, requestOptions);
|
|
1784
1496
|
}
|
|
1785
1497
|
|
|
1786
1498
|
/**
|
|
1787
|
-
* Returns
|
|
1499
|
+
* Returns when the current user last marked the channel read.
|
|
1788
1500
|
*
|
|
1789
1501
|
* @returns The last-read timestamp in unix nanoseconds, `null` if never read, or `undefined` if
|
|
1790
1502
|
* the user is unset.
|
|
@@ -1804,9 +1516,7 @@ export class Channel extends ChannelApi {
|
|
|
1804
1516
|
if (message.user?.id && this.getClient().userMuteStatus(message.user.id))
|
|
1805
1517
|
return false;
|
|
1806
1518
|
|
|
1807
|
-
//
|
|
1808
|
-
// unread count (e.g. livestreams where read events are disabled). See
|
|
1809
|
-
// `readEvents.localUnreadCountEnabled`.
|
|
1519
|
+
// Not counted when read events are disabled, unless `readEvents.localUnreadCountEnabled` is set.
|
|
1810
1520
|
if (!this.config.readEvents.localUnreadCountEnabled && !channelHasReadEvents(this)) {
|
|
1811
1521
|
return false;
|
|
1812
1522
|
}
|
|
@@ -1818,14 +1528,14 @@ export class Channel extends ChannelApi {
|
|
|
1818
1528
|
}
|
|
1819
1529
|
|
|
1820
1530
|
/**
|
|
1821
|
-
*
|
|
1531
|
+
* Counts the unread messages.
|
|
1822
1532
|
*
|
|
1823
|
-
* @param lastRead - The time
|
|
1824
|
-
*
|
|
1825
|
-
* @returns
|
|
1533
|
+
* @param lastRead - The time the user read a message, in unix nanoseconds (optional). Defaults to
|
|
1534
|
+
* the current user's read state.
|
|
1535
|
+
* @returns The unread count.
|
|
1826
1536
|
*/
|
|
1827
1537
|
countUnread(lastRead?: TimestampNS | null) {
|
|
1828
|
-
// Nullish, not
|
|
1538
|
+
// Nullish, not falsy: `0` is a valid timestamp.
|
|
1829
1539
|
if (lastRead == null) return this.state.unreadCount;
|
|
1830
1540
|
let count = 0;
|
|
1831
1541
|
const latestMessages = this.messagePaginator.headItems;
|
|
@@ -1839,9 +1549,9 @@ export class Channel extends ChannelApi {
|
|
|
1839
1549
|
}
|
|
1840
1550
|
|
|
1841
1551
|
/**
|
|
1842
|
-
*
|
|
1552
|
+
* Counts the unread messages that mention the current user.
|
|
1843
1553
|
*
|
|
1844
|
-
* @returns
|
|
1554
|
+
* @returns The unread mentions count.
|
|
1845
1555
|
*/
|
|
1846
1556
|
countUnreadMentions() {
|
|
1847
1557
|
const lastRead = this.lastRead();
|
|
@@ -1863,7 +1573,7 @@ export class Channel extends ChannelApi {
|
|
|
1863
1573
|
}
|
|
1864
1574
|
|
|
1865
1575
|
/**
|
|
1866
|
-
* Creates
|
|
1576
|
+
* Creates the channel without watching it.
|
|
1867
1577
|
*
|
|
1868
1578
|
* @param options - Channel query options (optional).
|
|
1869
1579
|
* @returns The server response.
|
|
@@ -1879,12 +1589,9 @@ export class Channel extends ChannelApi {
|
|
|
1879
1589
|
};
|
|
1880
1590
|
|
|
1881
1591
|
/**
|
|
1882
|
-
*
|
|
1883
|
-
*
|
|
1884
|
-
*
|
|
1885
|
-
* another instance already holds that cid (stored by an event or a list while this one was in
|
|
1886
|
-
* flight), that instance stays the one stored, since something may be using it, and takes over
|
|
1887
|
-
* from this one ({@link ChannelManager.supersedeChannel}), which also drops this one's entry.
|
|
1592
|
+
* Moves this channel, created without an ID, from its temporary cid to the one the server gave it.
|
|
1593
|
+
* If another instance already holds that cid, it stays stored and takes over from this one
|
|
1594
|
+
* ({@link ChannelManager.supersedeChannel}).
|
|
1888
1595
|
*/
|
|
1889
1596
|
private storeUnderServerCid(
|
|
1890
1597
|
response: ChannelStateResponseFields,
|
|
@@ -1897,8 +1604,7 @@ export class Channel extends ChannelApi {
|
|
|
1897
1604
|
this.cid = serverCid;
|
|
1898
1605
|
const isStoredUnderOldCid =
|
|
1899
1606
|
storedUnder !== serverCid && channelManager.get(storedUnder) === this;
|
|
1900
|
-
// A channel
|
|
1901
|
-
// superseded by it, as `ensure()` would give a fresh instance for its cid.
|
|
1607
|
+
// A disconnected channel is replaced by this instance, not superseded by it.
|
|
1902
1608
|
if (channelManager.get(serverCid)?.pendingDisposal) {
|
|
1903
1609
|
channelManager.removeChannel(serverCid);
|
|
1904
1610
|
}
|
|
@@ -1927,27 +1633,24 @@ export class Channel extends ChannelApi {
|
|
|
1927
1633
|
}
|
|
1928
1634
|
|
|
1929
1635
|
/**
|
|
1930
|
-
* Queries the API
|
|
1636
|
+
* Queries the API for messages, members and other channel fields.
|
|
1931
1637
|
*
|
|
1932
|
-
* @param options - The query options
|
|
1933
|
-
* @param messageSetToAddToIfDoesNotExist -
|
|
1934
|
-
*
|
|
1935
|
-
*
|
|
1936
|
-
* used for loading a specific message and its surroundings (optional, defaults to `'current'`).
|
|
1638
|
+
* @param options - The query options. Defaults to `{}`.
|
|
1639
|
+
* @param messageSetToAddToIfDoesNotExist - `'latest'` is what the open paths (`watch`,
|
|
1640
|
+
* `create`) pass: it seeds the message paginator with the fetched page. Other values do not
|
|
1641
|
+
* seed it. Defaults to `'current'`.
|
|
1937
1642
|
* @param requestOptions - Per-request options such as an abort `signal`. Never serialized
|
|
1938
1643
|
* into the request (optional).
|
|
1939
|
-
* @returns
|
|
1644
|
+
* @returns The query response.
|
|
1940
1645
|
*/
|
|
1941
1646
|
async query(
|
|
1942
1647
|
options: ChannelGetOrCreateRequest = {},
|
|
1943
1648
|
messageSetToAddToIfDoesNotExist: MessageSetType = 'current',
|
|
1944
1649
|
requestOptions?: StreamRequestOptions,
|
|
1945
1650
|
) {
|
|
1946
|
-
//
|
|
1947
|
-
// a watch whose events go to the instance now stored for the cid. Refused before it is sent.
|
|
1651
|
+
// Refused: a watch would register events that go to the instance now stored for the cid.
|
|
1948
1652
|
if (this.pendingDisposal) throw this.disposedError();
|
|
1949
|
-
//
|
|
1950
|
-
// channel that is being loaded
|
|
1653
|
+
// Counted until the response is applied, so the channel store keeps a channel being loaded.
|
|
1951
1654
|
this._channelQueriesInFlight += 1;
|
|
1952
1655
|
try {
|
|
1953
1656
|
return await this.runQuery(
|
|
@@ -1965,12 +1668,9 @@ export class Channel extends ChannelApi {
|
|
|
1965
1668
|
messageSetToAddToIfDoesNotExist: MessageSetType,
|
|
1966
1669
|
requestOptions?: StreamRequestOptions,
|
|
1967
1670
|
) {
|
|
1968
|
-
//
|
|
1969
|
-
//
|
|
1970
|
-
//
|
|
1971
|
-
// hard-delete (in the snapshot, absent from the page) from a message that arrives live
|
|
1972
|
-
// during the fetch (not in the snapshot). Captured here — the only place with the pre-await state —
|
|
1973
|
-
// so callers (channel.reload, watch) need not thread it. Empty on a cold open, so it is harmless.
|
|
1671
|
+
// Loaded IDs snapshotted before the await, for a latest-window (re)seed: `seedFirstPageSync`
|
|
1672
|
+
// tells an offline hard delete (in the snapshot, absent from the page) from a message that
|
|
1673
|
+
// arrived during the fetch (not in the snapshot).
|
|
1974
1674
|
// TODO(perf/cleanup): `headItems` materializes full message objects (intervalToItems) just to map
|
|
1975
1675
|
// them down to ids. A cheaper, clearer equivalent is a straight copy of the paginator index's own
|
|
1976
1676
|
// id set — expose `memberIds` on StoreBackedItemIndex (e.g. `snapshotMembers()` returning
|
|
@@ -1982,19 +1682,14 @@ export class Channel extends ChannelApi {
|
|
|
1982
1682
|
? new Set(this.messagePaginator.headItems.map((message) => message.id))
|
|
1983
1683
|
: undefined;
|
|
1984
1684
|
|
|
1985
|
-
//
|
|
1986
|
-
//
|
|
1987
|
-
// that already knows how much to fetch passes an explicit messages.limit, which is respected as-is:
|
|
1988
|
-
// a reconnect/re-hydrate sizes it to the loaded window (channel.reload → items.length), and
|
|
1989
|
-
// pagination/around pass their own cursors + limit.
|
|
1685
|
+
// An open query asks for the paginator's pageSize, not the server's default. An explicit
|
|
1686
|
+
// `messages.limit` wins (`reload` sizes it to the loaded window).
|
|
1990
1687
|
const requestedPageSize = options?.messages?.limit ?? this.messagePaginator.pageSize;
|
|
1991
1688
|
|
|
1992
1689
|
const queryPayload: ChannelGetOrCreateRequest = {
|
|
1993
1690
|
data: this._data,
|
|
1994
1691
|
state: true,
|
|
1995
1692
|
...options,
|
|
1996
|
-
// Ask the server for exactly the initial-open page size (not its default), so the loaded window
|
|
1997
|
-
// matches the paginator's pageSize. Explicit messages (reconnect/around/pagination) pass through.
|
|
1998
1693
|
messages:
|
|
1999
1694
|
options?.messages ??
|
|
2000
1695
|
(messageSetToAddToIfDoesNotExist === 'latest'
|
|
@@ -2013,7 +1708,6 @@ export class Channel extends ChannelApi {
|
|
|
2013
1708
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
2014
1709
|
const channel = state.channel!;
|
|
2015
1710
|
|
|
2016
|
-
// update the channel id if it was missing
|
|
2017
1711
|
if (!this.id) {
|
|
2018
1712
|
this.id = channel.id;
|
|
2019
1713
|
this.storeUnderServerCid(state, { watch: queryPayload.watch });
|
|
@@ -2021,47 +1715,35 @@ export class Channel extends ChannelApi {
|
|
|
2021
1715
|
|
|
2022
1716
|
this.getClient()._addChannelConfig(channel);
|
|
2023
1717
|
|
|
2024
|
-
// The composer
|
|
2025
|
-
//
|
|
2026
|
-
//
|
|
2027
|
-
//
|
|
2028
|
-
//
|
|
2029
|
-
// Restrictions, not a request: passing the server's value to `updateConfig` would record a server
|
|
2030
|
-
// *permission* as something the client asked for, and so re-enable a feature an integrator had
|
|
2031
|
-
// deliberately turned off (**DV-18**).
|
|
1718
|
+
// The composer's server config arrives here for a channel opened via `ensure({ type, id })`. A
|
|
1719
|
+
// composer with registered subscriptions hears it through the store, one without is told here.
|
|
1720
|
+
// Applied as restrictions: `updateConfig` would record a server permission as a client request and
|
|
1721
|
+
// re-enable a feature the integrator turned off.
|
|
2032
1722
|
this.messageComposer.applyServerRestrictions();
|
|
2033
1723
|
|
|
2034
|
-
//
|
|
2035
|
-
//
|
|
2036
|
-
// against this paginator. Seeding first guarantees the tracker sees a populated timeline; a
|
|
2037
|
-
// later async seed would run after the reconcile and mislabel delivery status. Only the
|
|
2038
|
-
// latest-page open paths (watch/create) pass 'latest' — the paginator's own pagination queries
|
|
2039
|
-
// use 'current' and must not be reseeded as a first page here.
|
|
1724
|
+
// Seeded before `_initializeState`: `MessageReceiptsTracker` resolves read/delivered cursors
|
|
1725
|
+
// against this paginator, so it must be populated first. Pagination queries pass 'current'.
|
|
2040
1726
|
if (messageSetToAddToIfDoesNotExist === 'latest' && Array.isArray(state.messages)) {
|
|
2041
|
-
//
|
|
2042
|
-
//
|
|
2043
|
-
// not the latest page — the paginator must reconcile it with jump semantics.
|
|
1727
|
+
// The query's pagination options go through: an around-message query returns a jump window, which
|
|
1728
|
+
// the paginator reconciles with jump semantics.
|
|
2044
1729
|
this.messagePaginator.seedFirstPageSync(
|
|
2045
1730
|
state.messages.map(formatMessage),
|
|
2046
1731
|
requestedPageSize,
|
|
2047
1732
|
options?.messages,
|
|
2048
|
-
// Re-
|
|
1733
|
+
// Re-seeding a loaded window reconciles it instead of blanking it.
|
|
2049
1734
|
{ candidateIds, reconcile: true },
|
|
2050
1735
|
);
|
|
2051
1736
|
}
|
|
2052
1737
|
|
|
2053
1738
|
if (this.supersededBy) {
|
|
2054
|
-
//
|
|
2055
|
-
// took over the watch (`supersedeChannel`), so this one receives none.
|
|
1739
|
+
// The stored instance took over the watch (`supersedeChannel`), so this one receives no events.
|
|
2056
1740
|
this.watchStatus = ChannelWatchStatus.NotWatching;
|
|
2057
1741
|
} else if (queryPayload.watch) {
|
|
2058
|
-
//
|
|
2059
|
-
// as a watcher. Only ever set here because a `watch: false` query does NOT unwatch
|
|
2060
|
-
// server-side, so it must not clear the flag.
|
|
1742
|
+
// Set only here: a `watch: false` query does not unwatch server-side, so it must not clear it.
|
|
2061
1743
|
this.watchStatus = ChannelWatchStatus.Watching;
|
|
2062
1744
|
}
|
|
2063
1745
|
|
|
2064
|
-
//
|
|
1746
|
+
// Seeds read, members, pinned and thread-cleanup state (messages live in the paginator).
|
|
2065
1747
|
this._initializeState(state);
|
|
2066
1748
|
// The queried page is the latest set unless this was a jump/around query.
|
|
2067
1749
|
const isLatestMessageSet =
|
|
@@ -2084,8 +1766,7 @@ export class Channel extends ChannelApi {
|
|
|
2084
1766
|
.sort()
|
|
2085
1767
|
.join();
|
|
2086
1768
|
this.data = channel;
|
|
2087
|
-
//
|
|
2088
|
-
// handles by reading it.
|
|
1769
|
+
// One update before the events below: the offline DB reads it when handling them.
|
|
2089
1770
|
this.state.partialNext({ initialized: true, offlineMode: false });
|
|
2090
1771
|
|
|
2091
1772
|
if (areCapabilitiesChanged) {
|
|
@@ -2117,7 +1798,7 @@ export class Channel extends ChannelApi {
|
|
|
2117
1798
|
}
|
|
2118
1799
|
|
|
2119
1800
|
/**
|
|
2120
|
-
* Bans a user from
|
|
1801
|
+
* Bans a user from this channel.
|
|
2121
1802
|
*
|
|
2122
1803
|
* @param targetUserId - The user to ban.
|
|
2123
1804
|
* @param options - Ban options.
|
|
@@ -2135,7 +1816,6 @@ export class Channel extends ChannelApi {
|
|
|
2135
1816
|
|
|
2136
1817
|
/**
|
|
2137
1818
|
* Hides the channel from `queryChannels` for the user until a message is added.
|
|
2138
|
-
* If `clear_history` is set to `true`, all messages will be removed for the user.
|
|
2139
1819
|
*
|
|
2140
1820
|
* @param ...args - `[request, requestOptions]`. Pass `request: { clear_history: true }` to clear
|
|
2141
1821
|
* message history for the user; `requestOptions` carries per-request options such as an abort
|
|
@@ -2147,7 +1827,7 @@ export class Channel extends ChannelApi {
|
|
|
2147
1827
|
}
|
|
2148
1828
|
|
|
2149
1829
|
/**
|
|
2150
|
-
* Removes the hidden status
|
|
1830
|
+
* Removes the hidden status of the channel.
|
|
2151
1831
|
*
|
|
2152
1832
|
* @param ...args - `[request, requestOptions]`. `request` is the show-channel payload;
|
|
2153
1833
|
* `requestOptions` carries per-request options such as an abort `signal` and is never
|
|
@@ -2159,7 +1839,7 @@ export class Channel extends ChannelApi {
|
|
|
2159
1839
|
}
|
|
2160
1840
|
|
|
2161
1841
|
/**
|
|
2162
|
-
* Removes the bans
|
|
1842
|
+
* Removes the bans of a user on this channel.
|
|
2163
1843
|
*
|
|
2164
1844
|
* @param targetUserId - The user to unban.
|
|
2165
1845
|
* @param options - Unban options (optional).
|
|
@@ -2176,12 +1856,11 @@ export class Channel extends ChannelApi {
|
|
|
2176
1856
|
}
|
|
2177
1857
|
|
|
2178
1858
|
/**
|
|
2179
|
-
* Casts
|
|
1859
|
+
* Casts a vote on a poll. `removeVote()` removes one.
|
|
2180
1860
|
*
|
|
2181
1861
|
* @param ...args - `[pathParams, request, requestOptions]`. `pathParams` holds the target
|
|
2182
|
-
* `message_id` and `poll_id`; `request` holds the vote to cast
|
|
2183
|
-
*
|
|
2184
|
-
* serialized into the request.
|
|
1862
|
+
* `message_id` and `poll_id`; `request` holds the vote to cast; `requestOptions` carries
|
|
1863
|
+
* per-request options such as an abort `signal` and is never serialized into the request.
|
|
2185
1864
|
* @returns The poll vote response.
|
|
2186
1865
|
*/
|
|
2187
1866
|
async vote(...args: Parameters<ChatApi['castPollVote']>) {
|
|
@@ -2198,10 +1877,7 @@ export class Channel extends ChannelApi {
|
|
|
2198
1877
|
return await super.createDraft(...args);
|
|
2199
1878
|
}
|
|
2200
1879
|
|
|
2201
|
-
/**
|
|
2202
|
-
* Creates or updates a draft message in a channel. If offline support is enabled, the
|
|
2203
|
-
* call is queued so it is replayed on reconnect.
|
|
2204
|
-
*/
|
|
1880
|
+
/** Creates or updates a draft. With offline support the call is queued and replayed on reconnect. */
|
|
2205
1881
|
override async createDraft(...args: Parameters<ChannelApi['createDraft']>) {
|
|
2206
1882
|
this._checkHasId();
|
|
2207
1883
|
|
|
@@ -2224,10 +1900,7 @@ export class Channel extends ChannelApi {
|
|
|
2224
1900
|
return await super.deleteDraft(...args);
|
|
2225
1901
|
}
|
|
2226
1902
|
|
|
2227
|
-
/**
|
|
2228
|
-
* Deletes a draft message from a channel or a thread. If offline support is enabled, the
|
|
2229
|
-
* call is queued so it is replayed on reconnect.
|
|
2230
|
-
*/
|
|
1903
|
+
/** Deletes a draft. With offline support the call is queued and replayed on reconnect. */
|
|
2231
1904
|
override async deleteDraft(...args: Parameters<ChannelApi['deleteDraft']>) {
|
|
2232
1905
|
this._checkHasId();
|
|
2233
1906
|
|
|
@@ -2247,7 +1920,7 @@ export class Channel extends ChannelApi {
|
|
|
2247
1920
|
}
|
|
2248
1921
|
|
|
2249
1922
|
/**
|
|
2250
|
-
* Listens to events on this channel.
|
|
1923
|
+
* Listens to events on this channel. A callback alone listens to all events.
|
|
2251
1924
|
*
|
|
2252
1925
|
* @example
|
|
2253
1926
|
* channel.on('message.new', (event) => {
|
|
@@ -2259,17 +1932,23 @@ export class Channel extends ChannelApi {
|
|
|
2259
1932
|
* console.log(event.type);
|
|
2260
1933
|
* });
|
|
2261
1934
|
*
|
|
2262
|
-
* @param
|
|
2263
|
-
* @param
|
|
1935
|
+
* @param eventType - The event type to listen for.
|
|
1936
|
+
* @param callback - Called with each event of that type.
|
|
2264
1937
|
* @returns An object with an `unsubscribe()` method.
|
|
2265
1938
|
*/
|
|
2266
|
-
on<T extends EventType
|
|
1939
|
+
on<T extends EventType>(
|
|
2267
1940
|
eventType: T,
|
|
2268
1941
|
callback: EventHandler<T>,
|
|
2269
1942
|
): { unsubscribe: () => void };
|
|
1943
|
+
/**
|
|
1944
|
+
* Listens to all events on this channel.
|
|
1945
|
+
*
|
|
1946
|
+
* @param callback - Called with every event.
|
|
1947
|
+
* @returns An object with an `unsubscribe()` method.
|
|
1948
|
+
*/
|
|
2270
1949
|
on(callback: EventHandler): { unsubscribe: () => void };
|
|
2271
1950
|
on(
|
|
2272
|
-
callbackOrString: EventHandler |
|
|
1951
|
+
callbackOrString: EventHandler | EventType,
|
|
2273
1952
|
callbackOrNothing?: EventHandler,
|
|
2274
1953
|
): { unsubscribe: () => void } {
|
|
2275
1954
|
const key = callbackOrNothing ? (callbackOrString as EventType) : 'all';
|
|
@@ -2302,14 +1981,22 @@ export class Channel extends ChannelApi {
|
|
|
2302
1981
|
}
|
|
2303
1982
|
|
|
2304
1983
|
/**
|
|
2305
|
-
* Removes
|
|
1984
|
+
* Removes a listener for one event type.
|
|
2306
1985
|
*
|
|
2307
|
-
* @param
|
|
2308
|
-
* @param
|
|
1986
|
+
* @param eventType - The event type it listens to.
|
|
1987
|
+
* @param callback - The listener to remove.
|
|
1988
|
+
*/
|
|
1989
|
+
off<T extends EventType>(eventType: T, callback: EventHandler<T>): void;
|
|
1990
|
+
/**
|
|
1991
|
+
* Removes a listener for all events.
|
|
1992
|
+
*
|
|
1993
|
+
* @param callback - The listener to remove.
|
|
2309
1994
|
*/
|
|
2310
|
-
off<T extends EventType | string>(eventType: T, callback: EventHandler): void;
|
|
2311
1995
|
off(callback: EventHandler): void;
|
|
2312
|
-
off(
|
|
1996
|
+
off(
|
|
1997
|
+
callbackOrString: EventHandler | EventType,
|
|
1998
|
+
callbackOrNothing?: EventHandler,
|
|
1999
|
+
): void {
|
|
2313
2000
|
const key = callbackOrNothing ? (callbackOrString as EventType) : 'all';
|
|
2314
2001
|
const callback = callbackOrNothing
|
|
2315
2002
|
? callbackOrNothing
|
|
@@ -2379,12 +2066,9 @@ export class Channel extends ChannelApi {
|
|
|
2379
2066
|
}
|
|
2380
2067
|
|
|
2381
2068
|
/**
|
|
2382
|
-
* Sets the current user's unread count
|
|
2383
|
-
* `
|
|
2384
|
-
* `state.unreadCount` derives from — so channel-wide resets (`channel.truncated`, "all channels
|
|
2385
|
-
* read") must route through here rather than writing a count of their own.
|
|
2069
|
+
* Sets the current user's unread count in `read[userId].unread_messages`, the one place it lives
|
|
2070
|
+
* (`state.unreadCount` derives from it). Returns whether the count changed.
|
|
2386
2071
|
*/
|
|
2387
|
-
/** @returns whether the count actually changed, so callers can react only to the channels it did. */
|
|
2388
2072
|
_setOwnUnreadCount(unreadCount: number): boolean {
|
|
2389
2073
|
if (this.pendingDisposal) return false;
|
|
2390
2074
|
|
|
@@ -2392,7 +2076,7 @@ export class Channel extends ChannelApi {
|
|
|
2392
2076
|
if (!userId) return false;
|
|
2393
2077
|
|
|
2394
2078
|
const currentUserReadState = this.state.read[userId];
|
|
2395
|
-
//
|
|
2079
|
+
// Only updates an existing read entry, never creates one.
|
|
2396
2080
|
if (!currentUserReadState || currentUserReadState.unread_messages === unreadCount) {
|
|
2397
2081
|
return false;
|
|
2398
2082
|
}
|
|
@@ -2414,6 +2098,15 @@ export class Channel extends ChannelApi {
|
|
|
2414
2098
|
.debug(`Received an event of type "${event.type}".`, { event });
|
|
2415
2099
|
|
|
2416
2100
|
const channelState = channel.state;
|
|
2101
|
+
|
|
2102
|
+
// The server unhides a channel on any new message without sending `channel.visible`.
|
|
2103
|
+
if (
|
|
2104
|
+
(event.type === 'message.new' || event.type === 'notification.message_new') &&
|
|
2105
|
+
channel.data?.hidden
|
|
2106
|
+
) {
|
|
2107
|
+
channel.data = { ...channel.data, hidden: false };
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2417
2110
|
switch (event.type) {
|
|
2418
2111
|
case 'typing.start':
|
|
2419
2112
|
if (event.user?.id) {
|
|
@@ -2436,31 +2129,28 @@ export class Channel extends ChannelApi {
|
|
|
2436
2129
|
case 'ai_indicator.stop':
|
|
2437
2130
|
channelState.partialNext({ aiState: AIStates.Stop });
|
|
2438
2131
|
break;
|
|
2439
|
-
// `notification.mark_read` is the only read signal for a channel the user is not watching
|
|
2440
|
-
// `message.read` goes to watchers only. `message.read_locally` is the local stand-in when read
|
|
2441
|
-
// events are disabled
|
|
2132
|
+
// `notification.mark_read` is the only read signal for a channel the user is not watching
|
|
2133
|
+
// (`message.read` goes to watchers only). `message.read_locally` is the local stand-in when read
|
|
2134
|
+
// events are disabled. All share the `message.read` logic.
|
|
2442
2135
|
case 'notification.mark_read':
|
|
2443
2136
|
case 'message.read_locally':
|
|
2444
2137
|
case 'message.read':
|
|
2445
2138
|
if (
|
|
2446
2139
|
event.user?.id &&
|
|
2447
2140
|
event.created_at != null &&
|
|
2448
|
-
// A thread read
|
|
2449
|
-
// `thread` object
|
|
2450
|
-
// `message.read` with the thread itself; reading the channel off either would reset
|
|
2451
|
-
// its unread count.
|
|
2141
|
+
// A thread read (`thread_id` on `notification.mark_read`, `thread` on `message.read`) is the
|
|
2142
|
+
// `thread` object's business and must not reset the channel's unread count.
|
|
2452
2143
|
!(event.type === 'notification.mark_read' && event.thread_id) &&
|
|
2453
2144
|
!('thread' in event && event.thread)
|
|
2454
2145
|
) {
|
|
2455
2146
|
const eventUser = event.user;
|
|
2456
2147
|
const readAt = event.created_at;
|
|
2457
|
-
|
|
2148
|
+
this._upsertReadState(
|
|
2458
2149
|
eventUser.id,
|
|
2459
2150
|
(currentUserReadState) => {
|
|
2460
2151
|
const currentDeliveredAt = currentUserReadState?.last_delivered_at;
|
|
2461
2152
|
|
|
2462
2153
|
return {
|
|
2463
|
-
// preserve delivery information already known for user
|
|
2464
2154
|
...currentUserReadState,
|
|
2465
2155
|
last_read: readAt,
|
|
2466
2156
|
last_read_message_id: event.last_read_message_id,
|
|
@@ -2480,14 +2170,13 @@ export class Channel extends ChannelApi {
|
|
|
2480
2170
|
},
|
|
2481
2171
|
{ changedUserIds: [eventUser.id] },
|
|
2482
2172
|
);
|
|
2483
|
-
void userReadState;
|
|
2484
2173
|
|
|
2485
2174
|
const client = this.getClient();
|
|
2486
2175
|
const isOwnEvent = event.user?.id === client.user?.id;
|
|
2487
2176
|
|
|
2488
2177
|
if (isOwnEvent) {
|
|
2489
|
-
// Delivery reporting buffers a `markChannelsDelivered`
|
|
2490
|
-
//
|
|
2178
|
+
// Delivery reporting buffers a `markChannelsDelivered` request, which a local read must not
|
|
2179
|
+
// trigger: only the server `message.read` syncs.
|
|
2491
2180
|
if (event.type === 'message.read') {
|
|
2492
2181
|
client.syncDeliveredCandidates([this]);
|
|
2493
2182
|
}
|
|
@@ -2499,11 +2188,9 @@ export class Channel extends ChannelApi {
|
|
|
2499
2188
|
if (event.user?.id && event.created_at != null) {
|
|
2500
2189
|
const eventUser = event.user;
|
|
2501
2190
|
const createdAt = event.created_at;
|
|
2502
|
-
// `last_delivered_at`
|
|
2503
|
-
//
|
|
2504
|
-
//
|
|
2505
|
-
// comparisons below are unit-consistent; an absent or unparseable value falls back to
|
|
2506
|
-
// `created_at`, which is already in that unit.
|
|
2191
|
+
// `last_delivered_at` arrives as RFC3339 (the spec declares a bare string) while `created_at`
|
|
2192
|
+
// is unix nanoseconds. Normalized to nanoseconds, falling back to `created_at` when absent or
|
|
2193
|
+
// unparseable.
|
|
2507
2194
|
// TODO: report upstream — this field should be a `date-time` like every other timestamp.
|
|
2508
2195
|
const parsedDeliveredAt = event.last_delivered_at
|
|
2509
2196
|
? Date.parse(event.last_delivered_at)
|
|
@@ -2511,7 +2198,7 @@ export class Channel extends ChannelApi {
|
|
|
2511
2198
|
const resolvedDeliveredAt = Number.isFinite(parsedDeliveredAt)
|
|
2512
2199
|
? msToNs(parsedDeliveredAt)
|
|
2513
2200
|
: createdAt;
|
|
2514
|
-
|
|
2201
|
+
this._upsertReadState(
|
|
2515
2202
|
eventUser.id,
|
|
2516
2203
|
(currentUserReadState) => {
|
|
2517
2204
|
const currentDeliveredAt = currentUserReadState?.last_delivered_at;
|
|
@@ -2535,13 +2222,11 @@ export class Channel extends ChannelApi {
|
|
|
2535
2222
|
},
|
|
2536
2223
|
{ changedUserIds: [eventUser.id] },
|
|
2537
2224
|
);
|
|
2538
|
-
void userReadState;
|
|
2539
2225
|
|
|
2540
2226
|
const client = this.getClient();
|
|
2541
2227
|
const isOwnEvent = event.user?.id === client.user?.id;
|
|
2542
2228
|
|
|
2543
|
-
//
|
|
2544
|
-
// already confirmed from own user from another device
|
|
2229
|
+
// Do not report deliveries the own user already confirmed from another device.
|
|
2545
2230
|
if (isOwnEvent) {
|
|
2546
2231
|
client.syncDeliveredCandidates([this]);
|
|
2547
2232
|
}
|
|
@@ -2571,10 +2256,8 @@ export class Channel extends ChannelApi {
|
|
|
2571
2256
|
this.messagePaginator.removeItem({ id: event.message.id });
|
|
2572
2257
|
this.pinnedMessagesPaginator.removeItem({ id: event.message.id });
|
|
2573
2258
|
} else {
|
|
2574
|
-
// A soft delete changes
|
|
2575
|
-
//
|
|
2576
|
-
// therefore reaches every holder through the store, where an `ingestItem` per
|
|
2577
|
-
// collection would make each of them re-emit its own window on top of the fan-out.
|
|
2259
|
+
// A soft delete changes neither `created_at` nor `pinned`: one store write reaches every
|
|
2260
|
+
// holder, where an `ingestItem` per collection would re-emit each window.
|
|
2578
2261
|
const store = this.getClient().messageStore;
|
|
2579
2262
|
if (store.has(event.message.id)) store.upsert(formattedMessage);
|
|
2580
2263
|
}
|
|
@@ -2602,33 +2285,25 @@ export class Channel extends ChannelApi {
|
|
|
2602
2285
|
case 'message.new':
|
|
2603
2286
|
if (event.message) {
|
|
2604
2287
|
const client = this.getClient();
|
|
2605
|
-
/* if message belongs to current user, always assume timestamp is changed to filter it out and add again to avoid duplication */
|
|
2606
2288
|
const ownMessage = event.user?.id === client.user?.id;
|
|
2607
2289
|
const isThreadMessage =
|
|
2608
2290
|
event.message.parent_id && !event.message.show_in_channel;
|
|
2609
2291
|
|
|
2610
2292
|
if (!isThreadMessage) {
|
|
2611
|
-
// ingestItem advances the
|
|
2612
|
-
//
|
|
2613
|
-
// head interval, not the active one, so the view is preserved without an isUpToDate flag.
|
|
2293
|
+
// `ingestItem` advances the tracked latest message. A message arriving while the viewer
|
|
2294
|
+
// is in an older window lands in the head interval, leaving the view as it is.
|
|
2614
2295
|
const formattedMessage = formatMessage(event.message);
|
|
2615
2296
|
this.messagePaginator.ingestItem(formattedMessage);
|
|
2616
|
-
//
|
|
2297
|
+
// Added only when pinned (`matchesFilter`).
|
|
2617
2298
|
this.pinnedMessagesPaginator.ingestItem(formattedMessage);
|
|
2618
2299
|
}
|
|
2619
2300
|
|
|
2620
|
-
//
|
|
2621
|
-
// 1. the message is mine
|
|
2622
|
-
// 2. the message is a thread reply from any user
|
|
2301
|
+
// The back-end does not count own messages or thread replies as unread.
|
|
2623
2302
|
const preventUnreadCountUpdate = ownMessage || isThreadMessage;
|
|
2624
2303
|
if (preventUnreadCountUpdate) break;
|
|
2625
2304
|
|
|
2626
|
-
// The own unread
|
|
2627
|
-
//
|
|
2628
|
-
// message that does not count as unread (silent/shadowed/muted) never bumps it, and neither
|
|
2629
|
-
// does one arriving while the user is viewing the latest messages — the SDK is about to mark
|
|
2630
|
-
// it read itself, and the count/snapshot would flash until it does. The other users' rows
|
|
2631
|
-
// are receipt bookkeeping and keep their blanket bump.
|
|
2305
|
+
// The own row bumps only for a message that counts as unread and arrives outside the live
|
|
2306
|
+
// view (the SDK marks it read there). Other users' rows always bump: they are receipt data.
|
|
2632
2307
|
const countsAsOwnUnread =
|
|
2633
2308
|
!this.messagePaginator.isViewingLive &&
|
|
2634
2309
|
this._countMessageAsUnread(event.message);
|
|
@@ -2656,7 +2331,7 @@ export class Channel extends ChannelApi {
|
|
|
2656
2331
|
last_delivered_message_id: eventMessageId,
|
|
2657
2332
|
};
|
|
2658
2333
|
} else if (userId === ownUserId && !countsAsOwnUnread) {
|
|
2659
|
-
//
|
|
2334
|
+
// Not counted as own unread: leave the row untouched.
|
|
2660
2335
|
continue;
|
|
2661
2336
|
} else {
|
|
2662
2337
|
nextReadState[userId] = {
|
|
@@ -2667,11 +2342,9 @@ export class Channel extends ChannelApi {
|
|
|
2667
2342
|
}
|
|
2668
2343
|
}
|
|
2669
2344
|
|
|
2670
|
-
//
|
|
2671
|
-
//
|
|
2672
|
-
//
|
|
2673
|
-
// accumulating. `last_read` is epoch: nothing has been read, which is exactly how
|
|
2674
|
-
// every "no last read" consumer already treats a missing value.
|
|
2345
|
+
// Seeds the own row when the channel has none (uninitialized, or queried with
|
|
2346
|
+
// `state: false` so `_initializeState` never ran): the count needs a row to live in.
|
|
2347
|
+
// `last_read` is the epoch: nothing has been read.
|
|
2675
2348
|
if (ownUserId && countsAsOwnUnread && !currentReadState[ownUserId]) {
|
|
2676
2349
|
nextReadState[ownUserId] = {
|
|
2677
2350
|
last_read: asTimestampNS(0),
|
|
@@ -2700,23 +2373,28 @@ export class Channel extends ChannelApi {
|
|
|
2700
2373
|
if (event.message) {
|
|
2701
2374
|
this._extendEventWithOwnReactions(event);
|
|
2702
2375
|
const formattedMessage = formatMessage(event.message);
|
|
2703
|
-
|
|
2376
|
+
const { parent_id: parentId, show_in_channel: shownInChannel } = event.message;
|
|
2377
|
+
const isThreadReply = !!parentId && !shownInChannel;
|
|
2378
|
+
const { threads } = this.getClient();
|
|
2379
|
+
// to avoid double state publish
|
|
2380
|
+
const isAppliedByThread =
|
|
2381
|
+
!!parentId && threads.hasSubscriptions && !!threads.get(parentId);
|
|
2382
|
+
if (!isThreadReply && !isAppliedByThread) {
|
|
2704
2383
|
this.messagePaginator.ingestItem(formattedMessage);
|
|
2705
2384
|
this.messagePaginator.reflectQuotedMessageUpdate(formattedMessage);
|
|
2706
|
-
//
|
|
2385
|
+
// Added on pin, removed on unpin (`matchesFilter`).
|
|
2707
2386
|
this.pinnedMessagesPaginator.ingestItem(formattedMessage);
|
|
2708
2387
|
this.pinnedMessagesPaginator.reflectQuotedMessageUpdate(formattedMessage);
|
|
2709
2388
|
}
|
|
2710
2389
|
}
|
|
2711
2390
|
break;
|
|
2712
2391
|
case 'channel.truncated': {
|
|
2392
|
+
if (event.channel) channel.data = { ...channel.data, ...event.channel };
|
|
2713
2393
|
const truncatedAt = event.channel?.truncated_at;
|
|
2714
2394
|
if (truncatedAt != null) {
|
|
2715
2395
|
this._setOwnUnreadCount(this.countUnread(truncatedAt));
|
|
2716
|
-
// Partial truncation
|
|
2717
|
-
// the
|
|
2718
|
-
// channel-wide read/unread context is reset by the truncation, so drop the unread snapshot
|
|
2719
|
-
// too (clearStateAndCache did this for the full-truncate branch).
|
|
2396
|
+
// Partial truncation keeps messages newer than the cutoff, so the paginator is not wiped. It
|
|
2397
|
+
// resets the channel-wide read context, so the unread snapshot goes too.
|
|
2720
2398
|
this.messagePaginator.truncate({ truncatedAt });
|
|
2721
2399
|
this.messagePaginator.clearUnreadSnapshot();
|
|
2722
2400
|
this.pinnedMessagesPaginator.truncate({ truncatedAt });
|
|
@@ -2789,7 +2467,6 @@ export class Channel extends ChannelApi {
|
|
|
2789
2467
|
this._upsertReadState(
|
|
2790
2468
|
eventUser.id,
|
|
2791
2469
|
(currentUserReadState) => ({
|
|
2792
|
-
// keep the message delivery info
|
|
2793
2470
|
...currentUserReadState,
|
|
2794
2471
|
first_unread_message_id: event.first_unread_message_id,
|
|
2795
2472
|
last_read: lastReadAt,
|
|
@@ -2892,9 +2569,8 @@ export class Channel extends ChannelApi {
|
|
|
2892
2569
|
}
|
|
2893
2570
|
|
|
2894
2571
|
_callChannelListeners = (event: WSEvent) => {
|
|
2895
|
-
// Snapshot
|
|
2896
|
-
//
|
|
2897
|
-
// must not be invoked for it.
|
|
2572
|
+
// Snapshot: a listener added while handling an event must not be invoked for it (`on` adds in
|
|
2573
|
+
// place and iterating a `Set` visits entries appended mid-iteration).
|
|
2898
2574
|
const listeners = [
|
|
2899
2575
|
...(this.listeners.get('all') ?? []),
|
|
2900
2576
|
...(this.listeners.get(event.type) ?? []),
|
|
@@ -2906,10 +2582,9 @@ export class Channel extends ChannelApi {
|
|
|
2906
2582
|
};
|
|
2907
2583
|
|
|
2908
2584
|
/**
|
|
2909
|
-
*
|
|
2910
|
-
*
|
|
2911
|
-
*
|
|
2912
|
-
* Note: only id is optional, cid is defined as string, so TS won't complain about a missing check there.
|
|
2585
|
+
* Throws if the channel has no ID (created from members only). Narrows `id` to `string`. Call it
|
|
2586
|
+
* before any request that uses `this.cid`: it is a string (possibly temporary) even without an ID,
|
|
2587
|
+
* so TypeScript does not flag a missing check.
|
|
2913
2588
|
*/
|
|
2914
2589
|
_checkHasId(): asserts this is this & { id: string } {
|
|
2915
2590
|
if (!this.id) {
|
|
@@ -2919,9 +2594,7 @@ export class Channel extends ChannelApi {
|
|
|
2919
2594
|
}
|
|
2920
2595
|
}
|
|
2921
2596
|
|
|
2922
|
-
/**
|
|
2923
|
-
* Checks if channel has been queried/initialized. Call this when a method relies on data only available after channel is queried from API.
|
|
2924
|
-
*/
|
|
2597
|
+
/** Throws unless the channel was queried or populated from the offline DB. */
|
|
2925
2598
|
_checkInitialized() {
|
|
2926
2599
|
if (!this.initialized && !this.offlineMode) {
|
|
2927
2600
|
throw Error(
|
|
@@ -2933,7 +2606,6 @@ export class Channel extends ChannelApi {
|
|
|
2933
2606
|
_initializeState(state: ChannelStateResponseFields) {
|
|
2934
2607
|
const { state: clientState, user, userID } = this.getClient();
|
|
2935
2608
|
|
|
2936
|
-
// add the members and users
|
|
2937
2609
|
if (state.members) {
|
|
2938
2610
|
this._hydrateMembers({ members: state.members });
|
|
2939
2611
|
}
|
|
@@ -2946,14 +2618,10 @@ export class Channel extends ChannelApi {
|
|
|
2946
2618
|
}
|
|
2947
2619
|
}
|
|
2948
2620
|
|
|
2949
|
-
//
|
|
2950
|
-
//
|
|
2951
|
-
// advances it from ingested messages; both feed the same monotonic max, so this additionally
|
|
2952
|
-
// covers the path where the paginator seed is skipped (an already-loaded channel the viewer has
|
|
2953
|
-
// jumped away from, where re-seeding would clobber their window).
|
|
2621
|
+
// The first-page seed also advances `lastMessageAt` (one monotonic max). This covers the path where
|
|
2622
|
+
// that seed is skipped: an already-loaded channel the viewer jumped away from.
|
|
2954
2623
|
this.messagePaginator.seedLastMessageAt(state.channel?.last_message_at);
|
|
2955
2624
|
|
|
2956
|
-
// Seed the pinned-messages paginator from the same response.
|
|
2957
2625
|
this.pinnedMessagesPaginator.seedFirstPageSync(
|
|
2958
2626
|
(state.pinned_messages || []).map(formatMessage),
|
|
2959
2627
|
this.pinnedMessagesPaginator.pageSize,
|
|
@@ -2964,7 +2632,6 @@ export class Channel extends ChannelApi {
|
|
|
2964
2632
|
if (state.watcher_count !== undefined) {
|
|
2965
2633
|
this.state.watcher_count = state.watcher_count;
|
|
2966
2634
|
}
|
|
2967
|
-
// convert the arrays into objects for easier syncing...
|
|
2968
2635
|
if (state.watchers) {
|
|
2969
2636
|
for (const watcher of state.watchers) {
|
|
2970
2637
|
if (watcher) {
|
|
@@ -2974,9 +2641,8 @@ export class Channel extends ChannelApi {
|
|
|
2974
2641
|
}
|
|
2975
2642
|
}
|
|
2976
2643
|
|
|
2977
|
-
//
|
|
2978
|
-
//
|
|
2979
|
-
// that everything up to this point is not marked as unread
|
|
2644
|
+
// Initialized to the last message (or now, if empty) so nothing up to here counts as unread. A
|
|
2645
|
+
// member's entry is overwritten below.
|
|
2980
2646
|
const readUpdates: ChannelState['read'] = {};
|
|
2981
2647
|
if (userID != null) {
|
|
2982
2648
|
const last_read = this.messagePaginator.lastMessageAt ?? nowNs();
|
|
@@ -2989,7 +2655,6 @@ export class Channel extends ChannelApi {
|
|
|
2989
2655
|
}
|
|
2990
2656
|
}
|
|
2991
2657
|
|
|
2992
|
-
// apply read state if part of the state
|
|
2993
2658
|
if (state.read) {
|
|
2994
2659
|
for (const read of state.read) {
|
|
2995
2660
|
readUpdates[read.user.id] = {
|
|
@@ -3029,9 +2694,8 @@ export class Channel extends ChannelApi {
|
|
|
3029
2694
|
if (!event.message) {
|
|
3030
2695
|
return;
|
|
3031
2696
|
}
|
|
3032
|
-
//
|
|
3033
|
-
//
|
|
3034
|
-
// own_reactions on its own reply store.
|
|
2697
|
+
// Enriched from the paginator, which owns the channel message list. Thread-only replies are not in
|
|
2698
|
+
// it: the Thread object preserves their `own_reactions`.
|
|
3035
2699
|
const message = this.messagePaginator.getItem(event.message.id);
|
|
3036
2700
|
if (message) {
|
|
3037
2701
|
event.message.own_reactions = message.own_reactions;
|
|
@@ -3043,12 +2707,7 @@ export class Channel extends ChannelApi {
|
|
|
3043
2707
|
overrideCurrentState = true,
|
|
3044
2708
|
}: {
|
|
3045
2709
|
members: ChannelMemberResponse[];
|
|
3046
|
-
/**
|
|
3047
|
-
* If set to `true` then `ChannelState.members` will be overriden with the newly
|
|
3048
|
-
* provided `members`, setting this property to `false` will merge current `ChannelState.members`
|
|
3049
|
-
* object with the newly provided `members`
|
|
3050
|
-
* (new members with the same `userId` will replace the old ones).
|
|
3051
|
-
*/
|
|
2710
|
+
/** `true` replaces `state.members`. `false` merges (a new member replaces one with the same ID). */
|
|
3052
2711
|
overrideCurrentState?: boolean;
|
|
3053
2712
|
}) {
|
|
3054
2713
|
const clientState = this.getClient().state;
|
|
@@ -3066,7 +2725,7 @@ export class Channel extends ChannelApi {
|
|
|
3066
2725
|
|
|
3067
2726
|
if (overrideCurrentState) {
|
|
3068
2727
|
this.state.members = newMembersById;
|
|
3069
|
-
} else if (
|
|
2728
|
+
} else if (members.length) {
|
|
3070
2729
|
this.state.members = {
|
|
3071
2730
|
...this.state.members,
|
|
3072
2731
|
...newMembersById,
|
|
@@ -3075,48 +2734,36 @@ export class Channel extends ChannelApi {
|
|
|
3075
2734
|
}
|
|
3076
2735
|
|
|
3077
2736
|
/**
|
|
3078
|
-
*
|
|
3079
|
-
*
|
|
3080
|
-
*
|
|
3081
|
-
*
|
|
3082
|
-
* server keeps a watch this connection held until the connection ends. Calling it again does
|
|
3083
|
-
* nothing, and nothing revives the instance.
|
|
3084
|
-
*
|
|
3085
|
-
* The SDK calls it when a channel ends: deleted, the current user removed from it, the user
|
|
3086
|
-
* logged out, or released as unused. Call it yourself to finish an instance you are done with.
|
|
3087
|
-
*
|
|
3088
|
-
* It doesn't remove the channel from the channel store, as parts of the app may still use the
|
|
3089
|
-
* instance: a stored instance stays there, and in the lists showing it, finished, until the next
|
|
3090
|
-
* `client.channelManager.releaseUnusedChannels()` removes it (or an end the SDK handles: deleted,
|
|
3091
|
-
* removed from it, logout). Meanwhile `client.channelManager.ensure(…)` gives a fresh instance
|
|
3092
|
-
* for its cid.
|
|
2737
|
+
* Ends the instance for good: unsubscribes from the configuration and the server config, stops the
|
|
2738
|
+
* receipts tracker and the cooldown timer, disposes both paginators, then sets
|
|
2739
|
+
* `pendingDisposal: true` and `watchStatus: NotWatching`. It sends no request, so the server keeps a
|
|
2740
|
+
* watch this connection held until the connection ends. Calling it again does nothing.
|
|
3093
2741
|
*
|
|
3094
|
-
*
|
|
2742
|
+
* The SDK calls it when a channel ends (deleted, current user removed, logout, released as unused).
|
|
2743
|
+
* It does not remove the channel from the channel store. The SDK's own ends remove it; after a
|
|
2744
|
+
* direct call it stays until `client.channelManager.releaseUnusedChannels()`, or until `ensure()`
|
|
2745
|
+
* for the same cid replaces it.
|
|
3095
2746
|
*/
|
|
3096
2747
|
disconnect() {
|
|
3097
|
-
//
|
|
2748
|
+
// Once only: a second run would drop subscription counts other consumers hold.
|
|
3098
2749
|
if (this.pendingDisposal) return;
|
|
3099
2750
|
logger.withExtraTags('disconnect', this.cid).info('Disconnecting the channel.');
|
|
3100
2751
|
|
|
3101
|
-
//
|
|
3102
|
-
//
|
|
2752
|
+
// Subscriptions are released before `pendingDisposal` flips, so no handler runs on a
|
|
2753
|
+
// half-disconnected channel.
|
|
3103
2754
|
|
|
3104
|
-
// Runs the `'channel'` setup function's teardown and
|
|
3105
|
-
// store's subscribers. Cleared so a repeated `disconnect` cannot double-run it.
|
|
2755
|
+
// Runs the `'channel'` setup function's teardown and unsubscribes from the configuration store.
|
|
3106
2756
|
this.unsubscribeConfiguration?.();
|
|
3107
2757
|
this.unsubscribeConfiguration = undefined;
|
|
3108
2758
|
this.unsubscribeServerConfig?.();
|
|
3109
2759
|
this.unsubscribeServerConfig = undefined;
|
|
3110
2760
|
this.messageReceiptsTracker.unregisterSubscriptions();
|
|
3111
2761
|
this.cooldownTimer.unregisterSubscriptions();
|
|
3112
|
-
//
|
|
3113
|
-
// (and its whole message graph) through its subscriber registry. The channel is being discarded
|
|
3114
|
-
// here (pending disposal + removed from the channel store, never reused), mirroring Thread teardown.
|
|
2762
|
+
// Otherwise the message store keeps this channel and its messages alive through its subscribers.
|
|
3115
2763
|
this.messagePaginator.dispose();
|
|
3116
2764
|
this.pinnedMessagesPaginator.dispose();
|
|
3117
2765
|
|
|
3118
|
-
// One update, last, so subscribers see both together. A deleted channel
|
|
3119
|
-
// removed from) must not be re-watched — see #2599.
|
|
2766
|
+
// One update, last, so subscribers see both together. A deleted channel must not be re-watched.
|
|
3120
2767
|
this.state.partialNext({
|
|
3121
2768
|
pendingDisposal: true,
|
|
3122
2769
|
watchStatus: ChannelWatchStatus.NotWatching,
|