stream-chat 10.0.0-rc.2 → 10.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -8
- package/dist/cjs/index.browser.js +15397 -12090
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +15349 -11991
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +15164 -11880
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelManager.d.ts +246 -6
- package/dist/types/CooldownTimer.d.ts +22 -8
- package/dist/types/EventHandlerPipeline.d.ts +12 -16
- package/dist/types/LiveLocationManager.d.ts +69 -6
- package/dist/types/api-client.d.ts +22 -9
- package/dist/types/channel.d.ts +550 -300
- package/dist/types/channel_state.d.ts +167 -22
- package/dist/types/client.d.ts +325 -305
- package/dist/types/configuration/ConfigController.d.ts +172 -0
- package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +192 -0
- package/dist/types/configuration/index.d.ts +3 -0
- package/dist/types/configuration/keys.d.ts +31 -0
- package/dist/types/configuration/shape.d.ts +58 -0
- package/dist/types/configuration/types.d.ts +206 -50
- package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +59 -0
- package/dist/types/configuration/utils/copyConfigPatch.d.ts +1 -0
- package/dist/types/configuration/utils/declarativeSlices.d.ts +24 -0
- package/dist/types/configuration/utils/deepFreezeConfig.d.ts +22 -0
- package/dist/types/configuration/utils/index.d.ts +1 -0
- package/dist/types/configuration/utils/serverAuthority.d.ts +49 -0
- package/dist/types/connection/ConnectionIdManager.d.ts +67 -0
- package/dist/types/connection/ConnectionRecoveryManager.d.ts +164 -0
- package/dist/types/connection/index.d.ts +4 -0
- package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +153 -0
- package/dist/types/connection/networkConnection/index.d.ts +3 -0
- package/dist/types/connection/networkConnection/reporters.d.ts +43 -0
- package/dist/types/connection/networkConnection/types.d.ts +55 -0
- package/dist/types/connection/wsConnection/StableWSConnection.d.ts +204 -0
- package/dist/types/connection/wsConnection/WSConnection.d.ts +168 -0
- package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +55 -0
- package/dist/types/connection/wsConnection/config.d.ts +51 -0
- package/dist/types/connection/wsConnection/index.d.ts +4 -0
- package/dist/types/connection/wsConnection/types.d.ts +99 -0
- package/dist/types/constants.d.ts +3 -1
- package/dist/types/entityStore/EntityStore.d.ts +160 -40
- package/dist/types/entityStore/StoreBackedItemIndex.d.ts +48 -29
- package/dist/types/entityStore/index.d.ts +0 -1
- package/dist/types/errors.d.ts +24 -4
- package/dist/types/formatMessageMemo.d.ts +5 -0
- package/dist/types/gen/chat/ChannelApi.d.ts +51 -23
- package/dist/types/gen/chat/ChatApi.d.ts +215 -168
- package/dist/types/gen/models/index.d.ts +2164 -557
- package/dist/types/gen/models/timestamp-guard.d.ts +22 -0
- package/dist/types/gen/moderation/ModerationApi.d.ts +39 -32
- package/dist/types/gen-imports.d.ts +1 -0
- package/dist/types/index.d.ts +20 -7
- package/dist/types/languageNames.d.ts +97 -0
- package/dist/types/logger.d.ts +1 -1
- package/dist/types/messageComposer/CustomDataManager.d.ts +7 -1
- package/dist/types/messageComposer/LocationComposer.d.ts +10 -4
- package/dist/types/messageComposer/attachmentIdentity.d.ts +11 -0
- package/dist/types/messageComposer/attachmentManager.d.ts +48 -10
- package/dist/types/messageComposer/attachmentUtils.d.ts +34 -0
- package/dist/types/messageComposer/configuration/commands.configuration.d.ts +1 -3
- package/dist/types/messageComposer/configuration/configuration.d.ts +9 -1
- package/dist/types/messageComposer/configuration/index.d.ts +0 -1
- package/dist/types/messageComposer/configuration/types.d.ts +57 -1
- package/dist/types/messageComposer/index.d.ts +1 -0
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +10 -4
- package/dist/types/messageComposer/messageComposer.d.ts +210 -14
- package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +20 -1
- package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +11 -0
- package/dist/types/messageComposer/middleware/messageComposer/types.d.ts +2 -2
- package/dist/types/messageComposer/middleware/pollComposer/index.d.ts +1 -0
- package/dist/types/messageComposer/middleware/pollComposer/state.d.ts +3 -2
- package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +9 -2
- package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +44 -0
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +2 -2
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +94 -229
- package/dist/types/messageComposer/pollComposer.d.ts +8 -3
- package/dist/types/messageComposer/textComposer.d.ts +9 -1
- package/dist/types/messageComposer/types.d.ts +7 -3
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +64 -8
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +48 -11
- package/dist/types/messageOperations/FailedSendCache.d.ts +34 -0
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +52 -6
- package/dist/types/messageOperations/MessageOperations.d.ts +94 -11
- package/dist/types/{entityStore → messageOperations}/applyReactionLocally.d.ts +8 -2
- package/dist/types/messageOperations/createMessageOperations.d.ts +11 -0
- package/dist/types/messageOperations/index.d.ts +7 -1
- package/dist/types/messageOperations/reflectReactionEvent.d.ts +24 -0
- package/dist/types/messageOperations/sendOrdering.d.ts +17 -0
- package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +28 -0
- package/dist/types/messageOperations/types.d.ts +66 -1
- package/dist/types/middleware.d.ts +8 -0
- package/dist/types/moderation.d.ts +18 -4
- package/dist/types/notifications/NotificationManager.d.ts +43 -2
- package/dist/types/notifications/types.d.ts +55 -42
- package/dist/types/offline-support/offline_support_api.d.ts +128 -12
- package/dist/types/offline-support/offline_sync_manager.d.ts +26 -5
- package/dist/types/offline-support/queueableOperations.d.ts +106 -0
- package/dist/types/offline-support/types.d.ts +77 -28
- package/dist/types/pagination/FilterBuilder.d.ts +1 -18
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -1
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +21 -3
- package/dist/types/pagination/filterCompiler.d.ts +5 -0
- package/dist/types/pagination/paginators/BasePaginator.d.ts +331 -7
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +54 -11
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +283 -66
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +10 -9
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +17 -1
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +8 -8
- package/dist/types/pagination/paginators/ThreadPaginator.d.ts +57 -0
- package/dist/types/pagination/paginators/index.d.ts +1 -0
- package/dist/types/pagination/utility.normalization.d.ts +29 -2
- package/dist/types/poll.d.ts +41 -14
- package/dist/types/poll_manager.d.ts +3 -2
- package/dist/types/poll_optimistic_votes.d.ts +61 -0
- package/dist/types/reminders/Reminder.d.ts +17 -7
- package/dist/types/reminders/ReminderManager.d.ts +34 -6
- package/dist/types/search/BaseSearchSource.d.ts +50 -25
- package/dist/types/search/ChannelMemberSearchSource.d.ts +11 -6
- package/dist/types/search/ChannelSearchSource.d.ts +27 -5
- package/dist/types/search/MessageSearchSource.d.ts +36 -6
- package/dist/types/search/SearchController.d.ts +44 -11
- package/dist/types/search/UserSearchSource.d.ts +11 -5
- package/dist/types/search/types.d.ts +14 -1
- package/dist/types/signing.d.ts +0 -157
- package/dist/types/thread.d.ts +118 -62
- package/dist/types/thread_manager.d.ts +124 -35
- package/dist/types/token_manager.d.ts +5 -8
- package/dist/types/types.d.ts +138 -562
- package/dist/types/types.utility.d.ts +8 -0
- package/dist/types/upload-utils.d.ts +20 -0
- package/dist/types/uploadManager.d.ts +50 -2
- package/dist/types/utils/FixedSizeQueueCache.d.ts +2 -0
- package/dist/types/utils/WithSubscriptions.d.ts +1 -1
- package/dist/types/utils/objectPath.d.ts +49 -0
- package/dist/types/utils/time.d.ts +85 -0
- package/dist/types/utils.d.ts +63 -40
- package/package.json +22 -33
- package/src/ChannelManager.ts +561 -109
- package/src/CooldownTimer.ts +55 -45
- package/src/EventHandlerPipeline.ts +13 -23
- package/src/LiveLocationManager.ts +191 -37
- package/src/api-client.ts +144 -53
- package/src/channel.ts +1573 -1050
- package/src/channel_state.ts +239 -129
- package/src/client.ts +843 -892
- package/src/client_state.ts +2 -2
- package/src/configuration/ConfigController.ts +298 -0
- package/src/configuration/InstanceConfigurationRegistry.ts +430 -0
- package/src/configuration/index.ts +7 -0
- package/src/configuration/keys.ts +86 -0
- package/src/configuration/shape.ts +776 -0
- package/src/configuration/types.ts +218 -60
- package/src/configuration/utils/applyInstanceConfiguration.ts +184 -0
- package/src/configuration/utils/copyConfigPatch.ts +61 -0
- package/src/configuration/utils/declarativeSlices.ts +81 -0
- package/src/configuration/utils/deepFreezeConfig.ts +33 -0
- package/src/configuration/utils/index.ts +5 -0
- package/src/configuration/utils/serverAuthority.ts +146 -0
- package/src/connection/ConnectionIdManager.ts +153 -0
- package/src/connection/ConnectionRecoveryManager.ts +371 -0
- package/src/connection/index.ts +4 -0
- package/src/connection/networkConnection/NetworkConnectionObserver.ts +281 -0
- package/src/connection/networkConnection/index.ts +3 -0
- package/src/connection/networkConnection/reporters.ts +85 -0
- package/src/connection/networkConnection/types.ts +60 -0
- package/src/{connection.ts → connection/wsConnection/StableWSConnection.ts} +242 -151
- package/src/connection/wsConnection/WSConnection.ts +345 -0
- package/src/connection/wsConnection/WSConnectionFallback.ts +259 -0
- package/src/connection/wsConnection/config.ts +108 -0
- package/src/connection/wsConnection/index.ts +4 -0
- package/src/connection/wsConnection/types.ts +101 -0
- package/src/constants.ts +5 -3
- package/src/entityStore/EntityStore.ts +350 -10
- package/src/entityStore/StoreBackedItemIndex.ts +66 -37
- package/src/entityStore/index.ts +0 -1
- package/src/errors.ts +40 -7
- package/src/formatMessageMemo.ts +23 -0
- package/src/gen/chat/ChannelApi.ts +230 -44
- package/src/gen/chat/ChatApi.ts +1047 -1745
- package/src/gen/models/index.ts +2378 -3721
- package/src/gen/models/timestamp-guard.ts +27 -0
- package/src/gen/moderation/ModerationApi.ts +218 -388
- package/src/gen-imports.ts +1 -0
- package/src/index.ts +82 -6
- package/src/languageNames.ts +103 -0
- package/src/logger.ts +1 -1
- package/src/messageComposer/CustomDataManager.ts +10 -1
- package/src/messageComposer/LocationComposer.ts +68 -20
- package/src/messageComposer/attachmentIdentity.ts +39 -0
- package/src/messageComposer/attachmentManager.ts +191 -68
- package/src/messageComposer/attachmentUtils.ts +58 -0
- package/src/messageComposer/configuration/commands.configuration.ts +1 -26
- package/src/messageComposer/configuration/configuration.ts +22 -3
- package/src/messageComposer/configuration/index.ts +0 -1
- package/src/messageComposer/configuration/types.ts +58 -1
- package/src/messageComposer/index.ts +1 -0
- package/src/messageComposer/linkPreviewsManager.ts +16 -10
- package/src/messageComposer/messageComposer.ts +487 -98
- package/src/messageComposer/middleware/attachmentManager/postUpload/AttachmentPostUploadMiddlewareExecutor.ts +1 -1
- package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +58 -33
- package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +7 -2
- package/src/messageComposer/middleware/attachmentManager/preUpload/blockedUploadNotification.ts +3 -2
- package/src/messageComposer/middleware/messageComposer/attachments.ts +98 -1
- package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +20 -10
- package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +7 -2
- package/src/messageComposer/middleware/messageComposer/types.ts +2 -7
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +11 -6
- package/src/messageComposer/middleware/pollComposer/index.ts +1 -0
- package/src/messageComposer/middleware/pollComposer/state.ts +43 -11
- package/src/messageComposer/middleware/pollComposer/types.ts +9 -2
- package/src/messageComposer/middleware/pollComposer/validation.ts +76 -0
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +3 -2
- package/src/messageComposer/middleware/textComposer/commands.ts +1 -2
- package/src/messageComposer/middleware/textComposer/mentions.ts +91 -39
- package/src/messageComposer/pollComposer.ts +11 -3
- package/src/messageComposer/textComposer.ts +36 -4
- package/src/messageComposer/types.ts +19 -14
- package/src/messageDelivery/MessageDeliveryReporter.ts +154 -53
- package/src/messageDelivery/MessageReceiptsTracker.ts +136 -64
- package/src/messageOperations/FailedSendCache.ts +90 -0
- package/src/messageOperations/MessageOperationStatePolicy.ts +269 -27
- package/src/messageOperations/MessageOperations.ts +340 -136
- package/src/{entityStore → messageOperations}/applyReactionLocally.ts +10 -3
- package/src/messageOperations/createMessageOperations.ts +192 -0
- package/src/messageOperations/index.ts +7 -0
- package/src/messageOperations/reflectReactionEvent.ts +51 -0
- package/src/messageOperations/sendOrdering.ts +28 -0
- package/src/messageOperations/settlePendingAttachmentUploads.ts +110 -0
- package/src/messageOperations/types.ts +74 -0
- package/src/middleware.ts +11 -0
- package/src/moderation.ts +47 -24
- package/src/notifications/NotificationManager.ts +73 -3
- package/src/notifications/configuration.ts +10 -8
- package/src/notifications/types.ts +58 -42
- package/src/offline-support/offline_support_api.ts +380 -197
- package/src/offline-support/offline_sync_manager.ts +105 -32
- package/src/offline-support/queueableOperations.ts +270 -0
- package/src/offline-support/types.ts +85 -39
- package/src/pagination/FilterBuilder.ts +1 -22
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +11 -7
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +25 -7
- package/src/pagination/filterCompiler.ts +17 -0
- package/src/pagination/paginators/BasePaginator.ts +731 -81
- package/src/pagination/paginators/ChannelPaginator.ts +210 -102
- package/src/pagination/paginators/MessageIntervalPaginator.ts +703 -193
- package/src/pagination/paginators/MessagePaginator.ts +45 -36
- package/src/pagination/paginators/PinnedMessagePaginator.ts +74 -28
- package/src/pagination/paginators/ReminderPaginator.ts +15 -13
- package/src/pagination/paginators/ThreadPaginator.ts +181 -0
- package/src/pagination/paginators/UserGroupPaginator.ts +8 -1
- package/src/pagination/paginators/index.ts +1 -0
- package/src/pagination/utility.normalization.ts +37 -9
- package/src/poll.ts +189 -112
- package/src/poll_manager.ts +14 -8
- package/src/poll_optimistic_votes.ts +335 -0
- package/src/reminders/Reminder.ts +34 -16
- package/src/reminders/ReminderManager.ts +68 -41
- package/src/reminders/ReminderTimer.ts +7 -6
- package/src/search/BaseSearchSource.ts +133 -40
- package/src/search/ChannelMemberSearchSource.ts +27 -18
- package/src/search/ChannelSearchSource.ts +61 -7
- package/src/search/MessageSearchSource.ts +133 -28
- package/src/search/SearchController.ts +93 -16
- package/src/search/UserSearchSource.ts +27 -13
- package/src/search/types.ts +14 -1
- package/src/signing.ts +1 -315
- package/src/thread.ts +503 -511
- package/src/thread_manager.ts +339 -204
- package/src/token_manager.ts +12 -32
- package/src/types.ts +159 -780
- package/src/types.utility.ts +14 -0
- package/src/upload-utils.ts +53 -0
- package/src/uploadManager.ts +85 -7
- package/src/utils/FixedSizeQueueCache.ts +5 -0
- package/src/utils/WithSubscriptions.ts +1 -1
- package/src/utils/objectPath.ts +67 -0
- package/src/utils/time.ts +104 -0
- package/src/utils.ts +209 -157
- package/dist/types/base64.d.ts +0 -2
- package/dist/types/configuration/InstanceConfigurationService.d.ts +0 -26
- package/dist/types/connection.d.ts +0 -146
- package/dist/types/connection_fallback.d.ts +0 -42
- package/dist/types/gen/model-decoders/decoders.d.ts +0 -3
- package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +0 -6
- package/dist/types/insights.d.ts +0 -58
- package/dist/types/pagination/utility.queryChannel.d.ts +0 -26
- package/dist/types/permissions.d.ts +0 -55
- package/dist/types/store.d.ts +0 -125
- package/src/base64.ts +0 -78
- package/src/configuration/InstanceConfigurationService.ts +0 -73
- package/src/connection_fallback.ts +0 -215
- package/src/gen/model-decoders/decoders.ts +0 -2680
- package/src/gen/model-decoders/event-decoder-mapping.ts +0 -198
- package/src/insights.ts +0 -83
- package/src/pagination/utility.queryChannel.ts +0 -84
- package/src/permissions.ts +0 -102
- package/src/store.ts +0 -304
|
@@ -4,7 +4,11 @@ import type {
|
|
|
4
4
|
UploadRequestFn,
|
|
5
5
|
UploadRequestOptions,
|
|
6
6
|
} from './configuration';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
isLocalImageAttachment,
|
|
9
|
+
isPendingUpload,
|
|
10
|
+
isUploadedAttachment,
|
|
11
|
+
} from './attachmentIdentity';
|
|
8
12
|
import {
|
|
9
13
|
createFileFromBlobs,
|
|
10
14
|
ensureIsLocalAttachment,
|
|
@@ -19,7 +23,8 @@ import {
|
|
|
19
23
|
AttachmentPostUploadMiddlewareExecutor,
|
|
20
24
|
AttachmentPreUploadMiddlewareExecutor,
|
|
21
25
|
} from './middleware/attachmentManager';
|
|
22
|
-
import { StateStore } from '
|
|
26
|
+
import { StateStore } from '@stream-io/state-store';
|
|
27
|
+
import { CORE_NOTIFICATION_TYPE } from '../notifications';
|
|
23
28
|
import { generateUUIDv4 } from '../utils';
|
|
24
29
|
import { DEFAULT_UPLOAD_SIZE_LIMIT_BYTES } from '../constants';
|
|
25
30
|
import type {
|
|
@@ -27,13 +32,20 @@ import type {
|
|
|
27
32
|
FileLike,
|
|
28
33
|
FileReference,
|
|
29
34
|
LocalAttachment,
|
|
35
|
+
LocalAttachmentUploadMetadata,
|
|
30
36
|
LocalNotImageAttachment,
|
|
31
37
|
LocalUploadAttachment,
|
|
32
38
|
UploadPermissionCheckResult,
|
|
33
39
|
} from './types';
|
|
34
|
-
import type {
|
|
40
|
+
import type {
|
|
41
|
+
ChannelResponse,
|
|
42
|
+
DraftMessage,
|
|
43
|
+
LocalMessage,
|
|
44
|
+
StreamRequestOptions,
|
|
45
|
+
} from '../types';
|
|
35
46
|
import type { MessageComposer } from './messageComposer';
|
|
36
47
|
import { mergeWithDiff } from '../utils/mergeWith';
|
|
48
|
+
import { isUploadCancellation } from '../uploadManager';
|
|
37
49
|
|
|
38
50
|
export type FileUploadFilter = (file: Partial<LocalUploadAttachment>) => boolean;
|
|
39
51
|
|
|
@@ -150,7 +162,11 @@ export class AttachmentManager {
|
|
|
150
162
|
set maxNumberOfFilesPerMessage(
|
|
151
163
|
maxNumberOfFilesPerMessage: AttachmentManagerConfig['maxNumberOfFilesPerMessage'],
|
|
152
164
|
) {
|
|
153
|
-
|
|
165
|
+
// No early return on "same value". The guard that used to be here compared against the *effective*
|
|
166
|
+
// value, while the write it skipped records the *requested* one — so asking for a value the server
|
|
167
|
+
// was currently masking recorded nothing, and the earlier request stayed in the patch layer to be
|
|
168
|
+
// honoured the moment the server relented. `ConfigController.write` already skips a publish when the
|
|
169
|
+
// resolved value does not move, which is the same guard applied to the right value.
|
|
154
170
|
this.composer.updateConfig({ attachments: { maxNumberOfFilesPerMessage } });
|
|
155
171
|
}
|
|
156
172
|
|
|
@@ -176,8 +192,36 @@ export class AttachmentManager {
|
|
|
176
192
|
return this.availableUploadSlots > 0;
|
|
177
193
|
}
|
|
178
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Whether uploaded bytes reach Stream, and therefore whether Stream's rules govern attachments here.
|
|
197
|
+
*
|
|
198
|
+
* Declared through {@link AttachmentManagerConfig.customCdn}, not inferred from `doUploadRequest`. A
|
|
199
|
+
* custom upload function says how files are sent, not where: wrapping the request to add retries,
|
|
200
|
+
* headers or a proxy through your own backend still ends at Stream. Inferring a different destination
|
|
201
|
+
* from it waived Stream's constraints for those integrators too.
|
|
202
|
+
*/
|
|
203
|
+
get usesStreamStorage() {
|
|
204
|
+
return !this.config.customCdn;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Whether this composer can accept a file right now — **the** answer to that question, for the SDK and
|
|
209
|
+
* for any UI deciding whether to offer an upload control. `uploadFiles` enforces exactly this; two
|
|
210
|
+
* predicates for one question could only agree by coincidence.
|
|
211
|
+
*
|
|
212
|
+
* - `config.enabled` — the configured answer, already ANDed with the channel type's `uploads` flag by
|
|
213
|
+
* the composer's server restrictions (which apply only when files go to Stream, for the same reason
|
|
214
|
+
* as below). The integrator's own switch, which nothing overrides.
|
|
215
|
+
* - a free slot under `maxNumberOfFilesPerMessage`.
|
|
216
|
+
* - the `upload-file` capability, **only when files go to Stream**. It governs Stream's upload
|
|
217
|
+
* endpoint, so on storage Stream does not host there is nothing for it to permit or refuse.
|
|
218
|
+
*/
|
|
179
219
|
get isUploadEnabled() {
|
|
180
|
-
return
|
|
220
|
+
return (
|
|
221
|
+
this.config.enabled &&
|
|
222
|
+
this.hasAvailableUploadSlots &&
|
|
223
|
+
(!this.usesStreamStorage || this.hasUploadPermission)
|
|
224
|
+
);
|
|
181
225
|
}
|
|
182
226
|
|
|
183
227
|
get successfulUploads() {
|
|
@@ -233,6 +277,7 @@ export class AttachmentManager {
|
|
|
233
277
|
...attachment,
|
|
234
278
|
localMetadata: {
|
|
235
279
|
...attachment.localMetadata,
|
|
280
|
+
uploadConfirmationPending: false,
|
|
236
281
|
uploadProgress: undefined,
|
|
237
282
|
uploadState: 'failed',
|
|
238
283
|
},
|
|
@@ -243,6 +288,24 @@ export class AttachmentManager {
|
|
|
243
288
|
this.state.next(initState({ message }));
|
|
244
289
|
};
|
|
245
290
|
|
|
291
|
+
/**
|
|
292
|
+
* Moves `source`'s attachments here, as they are, replacing this manager's own (whose uploads are
|
|
293
|
+
* cancelled) and leaving `source` with none. An upload still running keeps running: it isn't
|
|
294
|
+
* cancelled, and this manager attaches to it (`UploadManager` runs one request per attachment), so
|
|
295
|
+
* its result lands here. `source`'s list is emptied without touching the uploads, so clearing
|
|
296
|
+
* `source` afterwards doesn't cancel them either.
|
|
297
|
+
*
|
|
298
|
+
* @internal
|
|
299
|
+
*/
|
|
300
|
+
takeOver = (source: AttachmentManager) => {
|
|
301
|
+
this.cancelAttachmentUploads();
|
|
302
|
+
this.state.next({ ...source.state.getLatestValue() });
|
|
303
|
+
source.state.partialNext({ attachments: [] });
|
|
304
|
+
for (const attachment of this.attachments) {
|
|
305
|
+
if (isPendingUpload(attachment)) void this.uploadAndProcess(attachment);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
|
|
246
309
|
getSnapshot = (): AttachmentManagerSnapshot => {
|
|
247
310
|
const state = this.state.getLatestValue();
|
|
248
311
|
let hasUpdates = false;
|
|
@@ -332,9 +395,28 @@ export class AttachmentManager {
|
|
|
332
395
|
}
|
|
333
396
|
};
|
|
334
397
|
|
|
398
|
+
/**
|
|
399
|
+
* Releases a local preview URL the SDK minted, if it minted one.
|
|
400
|
+
*
|
|
401
|
+
* Only `blob:` URLs are ours to revoke: `toLocalUploadAttachment` puts a
|
|
402
|
+
* `URL.createObjectURL` result in `previewUri` for a `File`, but for a React Native
|
|
403
|
+
* `FileReference` it stores the caller's own native file URI, which must be left alone.
|
|
404
|
+
*/
|
|
405
|
+
private revokePreviewUri = (attachment: LocalAttachment) => {
|
|
406
|
+
const previewUri = (
|
|
407
|
+
attachment.localMetadata as Partial<LocalAttachmentUploadMetadata>
|
|
408
|
+
)?.previewUri;
|
|
409
|
+
|
|
410
|
+
if (previewUri?.startsWith('blob:')) URL.revokeObjectURL?.(previewUri);
|
|
411
|
+
};
|
|
412
|
+
|
|
335
413
|
removeAttachments = (localAttachmentIds: string[]) => {
|
|
336
414
|
if (!localAttachmentIds.length) return;
|
|
337
415
|
|
|
416
|
+
const removedAttachments = this.attachments.filter((attachment) =>
|
|
417
|
+
localAttachmentIds.includes(attachment.localMetadata?.id),
|
|
418
|
+
);
|
|
419
|
+
|
|
338
420
|
this.state.partialNext({
|
|
339
421
|
attachments: this.attachments.filter(
|
|
340
422
|
(attachment) => !localAttachmentIds.includes(attachment.localMetadata?.id),
|
|
@@ -344,6 +426,18 @@ export class AttachmentManager {
|
|
|
344
426
|
for (const id of localAttachmentIds) {
|
|
345
427
|
this.client.uploadManager.deleteUploadRecord(id);
|
|
346
428
|
}
|
|
429
|
+
|
|
430
|
+
// Removal is the end of the line for these attachments, so the preview blob goes with
|
|
431
|
+
// them - otherwise every removed (or cancelled mid-upload) attachment leaks one blob URL
|
|
432
|
+
// until the page unloads. Revoked after the record is deleted, so nothing is still
|
|
433
|
+
// rendering from it.
|
|
434
|
+
//
|
|
435
|
+
// Deliberately not done in `initState`/`restoreSnapshot`: those drop the composer's *view*
|
|
436
|
+
// of the attachments without ending their life. A finished upload has already had its
|
|
437
|
+
// `previewUri` revoked and removed by the post-upload middleware, and an unfinished one may
|
|
438
|
+
// still be rendered by whoever took it over (an optimistic message sent with the upload
|
|
439
|
+
// still in flight, for instance).
|
|
440
|
+
removedAttachments.forEach(this.revokePreviewUri);
|
|
347
441
|
};
|
|
348
442
|
|
|
349
443
|
getUploadConfigCheck = async (
|
|
@@ -491,8 +585,11 @@ export class AttachmentManager {
|
|
|
491
585
|
if (!attachment.localMetadata?.file) {
|
|
492
586
|
this.client.notifications.addError({
|
|
493
587
|
message: 'File is required for upload attachment',
|
|
494
|
-
origin: {
|
|
495
|
-
|
|
588
|
+
origin: {
|
|
589
|
+
emitter: 'AttachmentManager',
|
|
590
|
+
context: { attachment, composer: this.composer },
|
|
591
|
+
},
|
|
592
|
+
options: { type: CORE_NOTIFICATION_TYPE.attachmentFileMissing },
|
|
496
593
|
});
|
|
497
594
|
return;
|
|
498
595
|
}
|
|
@@ -500,8 +597,11 @@ export class AttachmentManager {
|
|
|
500
597
|
if (!attachment.localMetadata.id) {
|
|
501
598
|
this.client.notifications.addError({
|
|
502
599
|
message: 'Local upload attachment missing local id',
|
|
503
|
-
origin: {
|
|
504
|
-
|
|
600
|
+
origin: {
|
|
601
|
+
emitter: 'AttachmentManager',
|
|
602
|
+
context: { attachment, composer: this.composer },
|
|
603
|
+
},
|
|
604
|
+
options: { type: CORE_NOTIFICATION_TYPE.attachmentIdMissing },
|
|
505
605
|
});
|
|
506
606
|
return;
|
|
507
607
|
}
|
|
@@ -539,36 +639,35 @@ export class AttachmentManager {
|
|
|
539
639
|
}
|
|
540
640
|
: undefined;
|
|
541
641
|
|
|
542
|
-
const
|
|
543
|
-
progressHandler
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
...(options?.abortSignal ? { signal: options.abortSignal } : {}),
|
|
547
|
-
}
|
|
548
|
-
: undefined;
|
|
549
|
-
|
|
550
|
-
if (isFileReference(fileLike)) {
|
|
551
|
-
return this.channel[isImageFile(fileLike) ? 'sendImage' : 'sendFile'](
|
|
552
|
-
fileLike.uri,
|
|
553
|
-
fileLike.name,
|
|
554
|
-
fileLike.type,
|
|
555
|
-
undefined,
|
|
556
|
-
axiosUploadConfig,
|
|
557
|
-
);
|
|
558
|
-
}
|
|
642
|
+
const requestOptions: StreamRequestOptions = {
|
|
643
|
+
...(progressHandler ? { onUploadProgress: progressHandler } : {}),
|
|
644
|
+
...(options?.abortSignal ? { signal: options.abortSignal } : {}),
|
|
645
|
+
};
|
|
559
646
|
|
|
560
|
-
const file =
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
647
|
+
const file =
|
|
648
|
+
isFileReference(fileLike) || isFile(fileLike)
|
|
649
|
+
? fileLike
|
|
650
|
+
: createFileFromBlobs({
|
|
651
|
+
blobsArray: [fileLike],
|
|
652
|
+
fileName: generateFileName(fileLike.type),
|
|
653
|
+
mimeType: fileLike.type,
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
const {
|
|
657
|
+
duration: _duration,
|
|
658
|
+
// per-request artifact - `doUploadRequest`'s result is public API
|
|
659
|
+
metadata: _metadata,
|
|
660
|
+
...result
|
|
661
|
+
} = await this.channel[isImageFile(fileLike) ? 'uploadImage' : 'uploadFile'](
|
|
662
|
+
{ file },
|
|
663
|
+
requestOptions,
|
|
664
|
+
);
|
|
567
665
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
666
|
+
if (!result.file) {
|
|
667
|
+
throw new Error('The upload succeeded but the response carried no file URL');
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
return result as MinimumUploadRequestResult;
|
|
572
671
|
};
|
|
573
672
|
|
|
574
673
|
/**
|
|
@@ -601,10 +700,14 @@ export class AttachmentManager {
|
|
|
601
700
|
message: `The attachment upload was blocked`,
|
|
602
701
|
origin: {
|
|
603
702
|
emitter: 'AttachmentManager',
|
|
604
|
-
context: {
|
|
703
|
+
context: {
|
|
704
|
+
attachment,
|
|
705
|
+
blockedAttachment: localAttachment,
|
|
706
|
+
composer: this.composer,
|
|
707
|
+
},
|
|
605
708
|
},
|
|
606
709
|
options: {
|
|
607
|
-
type:
|
|
710
|
+
type: CORE_NOTIFICATION_TYPE.attachmentUploadBlocked,
|
|
608
711
|
metadata: {
|
|
609
712
|
reason: localAttachment.localMetadata.uploadPermissionCheck?.reason,
|
|
610
713
|
},
|
|
@@ -624,21 +727,30 @@ export class AttachmentManager {
|
|
|
624
727
|
...attachment.localMetadata,
|
|
625
728
|
uploadState: 'failed',
|
|
626
729
|
uploadProgress: undefined,
|
|
730
|
+
// `false`, not `undefined`: these updates go through `updateAttachment`, which merges
|
|
731
|
+
// via `mergeWith` — and that skips `undefined` source values, so `undefined` would
|
|
732
|
+
// leave a stale `true` in place.
|
|
733
|
+
uploadConfirmationPending: false,
|
|
627
734
|
},
|
|
628
735
|
};
|
|
629
736
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
737
|
+
// A cancellation is the user getting what they asked for, so it gets no error
|
|
738
|
+
// notification. This path predates the post-upload middleware chain and notifies
|
|
739
|
+
// directly, so it needs the same guard `createUploadErrorHandlerMiddleware` applies.
|
|
740
|
+
if (!isUploadCancellation(error)) {
|
|
741
|
+
this.client.notifications.addError({
|
|
742
|
+
message: 'Error uploading attachment',
|
|
743
|
+
origin: {
|
|
744
|
+
emitter: 'AttachmentManager',
|
|
745
|
+
context: { attachment, failedAttachment, composer: this.composer },
|
|
746
|
+
},
|
|
747
|
+
options: {
|
|
748
|
+
type: CORE_NOTIFICATION_TYPE.attachmentUploadFailed,
|
|
749
|
+
metadata: { reason },
|
|
750
|
+
originalError: error instanceof Error ? error : undefined,
|
|
751
|
+
},
|
|
752
|
+
});
|
|
753
|
+
}
|
|
642
754
|
|
|
643
755
|
this.updateAttachment(failedAttachment);
|
|
644
756
|
return failedAttachment;
|
|
@@ -659,6 +771,8 @@ export class AttachmentManager {
|
|
|
659
771
|
...attachment.localMetadata,
|
|
660
772
|
uploadState: 'finished',
|
|
661
773
|
uploadProgress: undefined,
|
|
774
|
+
// See the note in the failure branch: `undefined` cannot clear through `mergeWith`.
|
|
775
|
+
uploadConfirmationPending: false,
|
|
662
776
|
},
|
|
663
777
|
};
|
|
664
778
|
|
|
@@ -691,7 +805,7 @@ export class AttachmentManager {
|
|
|
691
805
|
mode: 'concurrent',
|
|
692
806
|
});
|
|
693
807
|
|
|
694
|
-
|
|
808
|
+
const attachment: LocalUploadAttachment = preUpload.state.attachment;
|
|
695
809
|
|
|
696
810
|
if (preUpload.status === 'discard') return attachment;
|
|
697
811
|
// todo: remove with the next major release as filtering can be done in middleware
|
|
@@ -703,6 +817,27 @@ export class AttachmentManager {
|
|
|
703
817
|
return preUpload.state.attachment;
|
|
704
818
|
}
|
|
705
819
|
|
|
820
|
+
return this.uploadAndProcess(attachment);
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
uploadFiles = async (files: FileReference[] | FileList | FileLike[]) => {
|
|
824
|
+
if (!this.isUploadEnabled) return;
|
|
825
|
+
|
|
826
|
+
const iterableFiles: FileReference[] | FileLike[] = isFileList(files)
|
|
827
|
+
? Array.from(files)
|
|
828
|
+
: files;
|
|
829
|
+
|
|
830
|
+
return await Promise.all(
|
|
831
|
+
iterableFiles.slice(0, this.availableUploadSlots).map(this.uploadFile),
|
|
832
|
+
);
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* Uploads `attachment` (or joins its upload already running, see {@link UploadManager.upload}) and
|
|
837
|
+
* runs the post-upload middleware over the result.
|
|
838
|
+
*/
|
|
839
|
+
private uploadAndProcess = async (initialAttachment: LocalUploadAttachment) => {
|
|
840
|
+
let attachment = initialAttachment;
|
|
706
841
|
let response: MinimumUploadRequestResult | undefined;
|
|
707
842
|
let error: Error | undefined;
|
|
708
843
|
try {
|
|
@@ -720,6 +855,8 @@ export class AttachmentManager {
|
|
|
720
855
|
...attachment.localMetadata,
|
|
721
856
|
uploadState: error ? 'failed' : 'finished',
|
|
722
857
|
uploadProgress: undefined,
|
|
858
|
+
// See the note in `uploadAttachment`: `undefined` cannot clear through `mergeWith`.
|
|
859
|
+
uploadConfirmationPending: false,
|
|
723
860
|
},
|
|
724
861
|
},
|
|
725
862
|
error,
|
|
@@ -738,22 +875,6 @@ export class AttachmentManager {
|
|
|
738
875
|
return attachment;
|
|
739
876
|
};
|
|
740
877
|
|
|
741
|
-
uploadFiles = async (files: FileReference[] | FileList | FileLike[]) => {
|
|
742
|
-
if (
|
|
743
|
-
(this.hasCustomDoUploadRequest && !this.hasAvailableUploadSlots) ||
|
|
744
|
-
(!this.hasCustomDoUploadRequest && !this.isUploadEnabled)
|
|
745
|
-
)
|
|
746
|
-
return;
|
|
747
|
-
|
|
748
|
-
const iterableFiles: FileReference[] | FileLike[] = isFileList(files)
|
|
749
|
-
? Array.from(files)
|
|
750
|
-
: files;
|
|
751
|
-
|
|
752
|
-
return await Promise.all(
|
|
753
|
-
iterableFiles.slice(0, this.availableUploadSlots).map(this.uploadFile),
|
|
754
|
-
);
|
|
755
|
-
};
|
|
756
|
-
|
|
757
878
|
private upload(attachment: LocalUploadAttachment) {
|
|
758
879
|
const localId = attachment.localMetadata.id;
|
|
759
880
|
|
|
@@ -764,6 +885,7 @@ export class AttachmentManager {
|
|
|
764
885
|
...attachment.localMetadata,
|
|
765
886
|
uploadState: 'uploading',
|
|
766
887
|
uploadProgress: this.config.trackUploadProgress ? 0 : undefined,
|
|
888
|
+
uploadConfirmationPending: false,
|
|
767
889
|
},
|
|
768
890
|
},
|
|
769
891
|
]);
|
|
@@ -778,6 +900,7 @@ export class AttachmentManager {
|
|
|
778
900
|
...attachment.localMetadata,
|
|
779
901
|
uploadState: 'uploading',
|
|
780
902
|
uploadProgress: nextUpload.uploadProgress,
|
|
903
|
+
uploadConfirmationPending: nextUpload.uploadConfirmationPending,
|
|
781
904
|
},
|
|
782
905
|
});
|
|
783
906
|
},
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { isLocalUploadAttachment } from './attachmentIdentity';
|
|
2
|
+
|
|
3
|
+
import type { Attachment } from '../types';
|
|
4
|
+
import type { LocalAttachment } from './types';
|
|
5
|
+
|
|
6
|
+
// Accessors reading values off an attachment payload — as opposed to `attachmentIdentity`, which
|
|
7
|
+
// answers what kind of attachment it is. Each exists because the answer is not a plain field read.
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The URL to render an attachment from, falling back to the local blob preview while its upload is
|
|
11
|
+
* in flight. Lives here because the preview is this package's: created by `AttachmentManager`,
|
|
12
|
+
* revoked by `settlePendingAttachmentUploads`.
|
|
13
|
+
*/
|
|
14
|
+
export const getAttachmentPreviewUrl = (
|
|
15
|
+
attachment?: Attachment | LocalAttachment,
|
|
16
|
+
...urls: (string | undefined)[]
|
|
17
|
+
): string | undefined => {
|
|
18
|
+
const resolved = urls.find(Boolean);
|
|
19
|
+
if (resolved) return resolved;
|
|
20
|
+
|
|
21
|
+
return isLocalUploadAttachment(attachment)
|
|
22
|
+
? attachment.localMetadata.previewUri
|
|
23
|
+
: undefined;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* An attachment's declared file size. v10 moved these fields under `attachment.custom`; the flat
|
|
28
|
+
* one remains a fallback for older or hand-built payloads. Where the field lives is this package's
|
|
29
|
+
* schema knowledge, not a UI SDK's.
|
|
30
|
+
*/
|
|
31
|
+
export const resolveAttachmentFileSize = (attachment?: {
|
|
32
|
+
custom?: { file_size?: number | string } | null;
|
|
33
|
+
file_size?: number | string;
|
|
34
|
+
}): number | string | undefined => attachment?.custom?.file_size ?? attachment?.file_size;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Size in bytes, preferring the held `File` — during an upload that is the only exact figure,
|
|
38
|
+
* since `file_size` may be absent until the server answers.
|
|
39
|
+
*/
|
|
40
|
+
export const resolveAttachmentFullByteSize = (attachment?: {
|
|
41
|
+
custom?: { file_size?: number | string } | null;
|
|
42
|
+
file_size?: number | string;
|
|
43
|
+
localMetadata?: { file?: { size?: unknown } } | null;
|
|
44
|
+
}): number | undefined => {
|
|
45
|
+
const fromFile = attachment?.localMetadata?.file?.size;
|
|
46
|
+
if (typeof fromFile === 'number' && Number.isFinite(fromFile) && fromFile >= 0) {
|
|
47
|
+
return fromFile;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const raw = resolveAttachmentFileSize(attachment);
|
|
51
|
+
if (typeof raw === 'number' && Number.isFinite(raw) && raw >= 0) return raw;
|
|
52
|
+
if (typeof raw === 'string') {
|
|
53
|
+
const parsed = parseFloat(raw);
|
|
54
|
+
if (Number.isFinite(parsed) && parsed >= 0) return parsed;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return undefined;
|
|
58
|
+
};
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CommandsConfig,
|
|
3
|
-
CommandSendValidator,
|
|
4
|
-
MessageComposerConfig,
|
|
5
|
-
} from './types';
|
|
6
|
-
import type { DeepPartial } from '../../types.utility';
|
|
1
|
+
import type { CommandsConfig, CommandSendValidator } from './types';
|
|
7
2
|
import { stripMentionTokens } from '../middleware';
|
|
8
3
|
|
|
9
4
|
export const MENTION_ONLY_COMMANDS = new Set(['mute', 'unmute', 'unban']);
|
|
@@ -33,23 +28,3 @@ export const defaultCommandSendabilityValidator: CommandSendValidator = ({
|
|
|
33
28
|
export const DEFAULT_COMMANDS_CONFIG: CommandsConfig = {
|
|
34
29
|
sendValidator: defaultCommandSendabilityValidator,
|
|
35
30
|
};
|
|
36
|
-
export const applyCommandValidatorOverride = (
|
|
37
|
-
targetConfig: MessageComposerConfig,
|
|
38
|
-
sourceConfig?: DeepPartial<MessageComposerConfig>,
|
|
39
|
-
) => {
|
|
40
|
-
const overrideValidator = sourceConfig?.commands?.sendValidator as
|
|
41
|
-
| CommandSendValidator
|
|
42
|
-
| undefined;
|
|
43
|
-
|
|
44
|
-
if (typeof overrideValidator === 'undefined') {
|
|
45
|
-
return targetConfig;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
...targetConfig,
|
|
50
|
-
commands: {
|
|
51
|
-
...targetConfig.commands,
|
|
52
|
-
sendValidator: overrideValidator,
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
};
|
|
@@ -5,14 +5,16 @@ import type {
|
|
|
5
5
|
LinkPreviewsManagerConfig,
|
|
6
6
|
LocationComposerConfig,
|
|
7
7
|
MessageComposerConfig,
|
|
8
|
+
PollComposerConfig,
|
|
8
9
|
TextComposerConfig,
|
|
9
10
|
} from './types';
|
|
10
11
|
import { generateUUIDv4 } from '../../utils';
|
|
12
|
+
import { deepFreezeConfig } from '../../configuration/utils/deepFreezeConfig';
|
|
11
13
|
import { DEFAULT_COMMANDS_CONFIG } from './commands.configuration';
|
|
12
14
|
|
|
13
15
|
export const DEFAULT_LINK_PREVIEW_MANAGER_CONFIG: LinkPreviewsManagerConfig = {
|
|
14
16
|
debounceURLEnrichmentMs: 1500,
|
|
15
|
-
enabled:
|
|
17
|
+
enabled: true,
|
|
16
18
|
findURLFn: (text: string): string[] =>
|
|
17
19
|
find(text, 'url', { defaultProtocol: 'https' }).reduce<string[]>((acc, link) => {
|
|
18
20
|
try {
|
|
@@ -30,8 +32,11 @@ export const DEFAULT_LINK_PREVIEW_MANAGER_CONFIG: LinkPreviewsManagerConfig = {
|
|
|
30
32
|
|
|
31
33
|
export const DEFAULT_ATTACHMENT_MANAGER_CONFIG: AttachmentManagerConfig = {
|
|
32
34
|
acceptedFiles: [], // an empty array means all files are accepted
|
|
35
|
+
customCdn: false,
|
|
36
|
+
enabled: true,
|
|
33
37
|
fileUploadFilter: () => true,
|
|
34
38
|
maxNumberOfFilesPerMessage: API_MAX_FILES_ALLOWED_PER_MESSAGE,
|
|
39
|
+
pendingUploadsEnabled: false,
|
|
35
40
|
trackUploadProgress: true,
|
|
36
41
|
};
|
|
37
42
|
|
|
@@ -40,16 +45,30 @@ export const DEFAULT_TEXT_COMPOSER_CONFIG: TextComposerConfig = {
|
|
|
40
45
|
publishTypingEvents: true,
|
|
41
46
|
};
|
|
42
47
|
|
|
48
|
+
export const DEFAULT_POLL_COMPOSER_CONFIG: PollComposerConfig = {
|
|
49
|
+
enabled: true,
|
|
50
|
+
};
|
|
51
|
+
|
|
43
52
|
export const DEFAULT_LOCATION_COMPOSER_CONFIG: LocationComposerConfig = {
|
|
44
53
|
enabled: true,
|
|
45
54
|
getDeviceId: () => generateUUIDv4(),
|
|
55
|
+
minShareDurationMs: 60 * 1000,
|
|
46
56
|
};
|
|
47
57
|
|
|
48
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Frozen, because `MessageComposer.requestedConfig` seeds its merge with a *shallow* spread of this
|
|
60
|
+
* object: any subtree no configuration layer names stays identical by reference to the one here, and is
|
|
61
|
+
* reachable through the public `composer.config`. Without the freeze,
|
|
62
|
+
* `composer.config.drafts.enabled = true` changed the default for every composer on every client in the
|
|
63
|
+
* process. See {@link deepFreezeConfig}.
|
|
64
|
+
*/
|
|
65
|
+
export const DEFAULT_COMPOSER_CONFIG: MessageComposerConfig = deepFreezeConfig({
|
|
49
66
|
attachments: DEFAULT_ATTACHMENT_MANAGER_CONFIG,
|
|
50
67
|
commands: DEFAULT_COMMANDS_CONFIG,
|
|
51
68
|
drafts: { enabled: false },
|
|
52
69
|
linkPreviews: DEFAULT_LINK_PREVIEW_MANAGER_CONFIG,
|
|
53
70
|
location: DEFAULT_LOCATION_COMPOSER_CONFIG,
|
|
71
|
+
polls: DEFAULT_POLL_COMPOSER_CONFIG,
|
|
72
|
+
retainCompositionOnSubmit: (composer) => !!composer.pollId,
|
|
54
73
|
text: DEFAULT_TEXT_COMPOSER_CONFIG,
|
|
55
|
-
};
|
|
74
|
+
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export * from './configuration';
|
|
2
2
|
export * from './types';
|
|
3
|
-
export { applyCommandValidatorOverride } from './commands.configuration';
|
|
4
3
|
export { DEFAULT_COMMANDS_CONFIG } from './commands.configuration';
|
|
5
4
|
export { defaultCommandSendabilityValidator } from './commands.configuration';
|
|
6
5
|
export { MENTION_ONLY_COMMANDS } from './commands.configuration';
|
|
@@ -64,6 +64,11 @@ export type CommandsConfig = {
|
|
|
64
64
|
};
|
|
65
65
|
|
|
66
66
|
export type AttachmentManagerConfig = {
|
|
67
|
+
/**
|
|
68
|
+
* Allows for toggling file attachments (defaults to `true`). The feature also has to be enabled at the
|
|
69
|
+
* channel-level config via `uploads`; the two are ANDed, so either side can switch it off.
|
|
70
|
+
*/
|
|
71
|
+
enabled: boolean;
|
|
67
72
|
// todo: document removal of noFiles prop showing how to achieve the same with custom fileUploadFilter function
|
|
68
73
|
/**
|
|
69
74
|
* Function that allows to prevent uploading files based on the functions output.
|
|
@@ -79,6 +84,29 @@ export type AttachmentManagerConfig = {
|
|
|
79
84
|
acceptedFiles: string[];
|
|
80
85
|
/** Function that allows to customize the upload request. */
|
|
81
86
|
doUploadRequest?: UploadRequestFn;
|
|
87
|
+
/**
|
|
88
|
+
* Whether a custom {@link AttachmentManagerConfig.doUploadRequest} stores files somewhere Stream does
|
|
89
|
+
* not host (defaults to `false`).
|
|
90
|
+
*
|
|
91
|
+
* Left `false`, uploads are treated as reaching Stream — which covers the built-in request *and* a
|
|
92
|
+
* custom one that still posts to Stream, such as a wrapper adding retries or headers, or a proxy
|
|
93
|
+
* through your own backend. Stream's rules then govern attachments: the `upload-file` capability and
|
|
94
|
+
* the channel type's `uploads` flag.
|
|
95
|
+
*
|
|
96
|
+
* Set it to `true` when the bytes never reach Stream. Stream has no say over storage it does not host,
|
|
97
|
+
* so neither rule applies and the feature is governed by {@link AttachmentManagerConfig.enabled} alone.
|
|
98
|
+
*
|
|
99
|
+
* Declared rather than inferred from the presence of `doUploadRequest`, because supplying an upload
|
|
100
|
+
* function says *how* files are sent, not *where* — and treating it as a destination waived Stream's
|
|
101
|
+
* constraints for integrators who were still uploading to Stream.
|
|
102
|
+
*/
|
|
103
|
+
customCdn: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* When `true`, a message may be sent while its attachments are still uploading (defaults to
|
|
106
|
+
* `false`). The message is composed and shown right away, and the send request waits for those
|
|
107
|
+
* uploads to settle before it goes out; if one of them fails, the whole message fails.
|
|
108
|
+
*/
|
|
109
|
+
pendingUploadsEnabled: boolean;
|
|
82
110
|
/**
|
|
83
111
|
* When `true`, the attachment manager sets `localMetadata.uploadProgress` and passes
|
|
84
112
|
* `options.onProgress` to `doUploadRequest` (built-in and custom). Set to `false` to disable
|
|
@@ -90,7 +118,14 @@ export type AttachmentManagerConfig = {
|
|
|
90
118
|
export type LinkPreviewsManagerConfig = {
|
|
91
119
|
/** Number of milliseconds to debounce firing the URL enrichment queries when typing (defaults to `1500`). */
|
|
92
120
|
debounceURLEnrichmentMs: number;
|
|
93
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* Allows for toggling URL enrichment and link previews in `MessageInput` (defaults to `true`).
|
|
123
|
+
*
|
|
124
|
+
* ANDed with the channel type's `url_enrichment`, so previews appear only where the server will
|
|
125
|
+
* actually enrich the message. `true` is the default for the same reason every other server-gated
|
|
126
|
+
* feature uses it: it means "no opinion — let the server decide". A `false` default double-gated the
|
|
127
|
+
* feature, leaving it off even where the server had enabled it.
|
|
128
|
+
*/
|
|
94
129
|
enabled: boolean;
|
|
95
130
|
/** Custom function to identify URLs in a string and request OG data */
|
|
96
131
|
findURLFn: (text: string) => string[];
|
|
@@ -106,6 +141,20 @@ export type LocationComposerConfig = {
|
|
|
106
141
|
enabled: boolean;
|
|
107
142
|
/** Function that provides a stable ID for the device from which the location is shared. */
|
|
108
143
|
getDeviceId: () => string;
|
|
144
|
+
/**
|
|
145
|
+
* Shortest live-location duration accepted as valid (defaults to 60s). A shorter `durationMs` makes
|
|
146
|
+
* the composed location invalid rather than clamping it, so this is a product decision about the
|
|
147
|
+
* minimum useful sharing window — not a protocol limit.
|
|
148
|
+
*/
|
|
149
|
+
minShareDurationMs: number;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export type PollComposerConfig = {
|
|
153
|
+
/**
|
|
154
|
+
* Allows for toggling poll composition (defaults to `true`). The feature also has to be enabled at the
|
|
155
|
+
* channel-level config via `polls`; the two are ANDed, so either side can switch it off.
|
|
156
|
+
*/
|
|
157
|
+
enabled: boolean;
|
|
109
158
|
};
|
|
110
159
|
|
|
111
160
|
export type MessageComposerConfig = {
|
|
@@ -119,6 +168,14 @@ export type MessageComposerConfig = {
|
|
|
119
168
|
linkPreviews: LinkPreviewsManagerConfig;
|
|
120
169
|
/** Configuration for the location composer */
|
|
121
170
|
location: LocationComposerConfig;
|
|
171
|
+
/** Configuration for the poll composer */
|
|
172
|
+
polls: PollComposerConfig;
|
|
173
|
+
/**
|
|
174
|
+
* Decides whether submitting keeps the composer's contents instead of clearing them, and whether
|
|
175
|
+
* the attachments composition step leaves unresolved uploads behind with them. Defaults to
|
|
176
|
+
* retaining for a poll message, which carries no text or attachments of its own.
|
|
177
|
+
*/
|
|
178
|
+
retainCompositionOnSubmit: (composer: MessageComposer) => boolean;
|
|
122
179
|
/** Maximum number of characters in a message */
|
|
123
180
|
text: TextComposerConfig;
|
|
124
181
|
};
|