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
|
@@ -21,22 +21,11 @@ const localAttachmentToAttachment = (localAttachment: LocalAttachment) => {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* handle needed to await or retry the upload) and `previewUri` (so the message list can render
|
|
30
|
-
* the user's own file meanwhile) - while `message.attachments`, which goes to the API, carries
|
|
31
|
-
* only attachments that already resolved to a URL. `MessageOperations` fills in the rest once the
|
|
32
|
-
* uploads settle.
|
|
33
|
-
*
|
|
34
|
-
* That includes uploads that already `failed`: dropping them here is how a file the user attached
|
|
35
|
-
* disappears without trace, because the UI clears the composer on send. Riding along on the
|
|
36
|
-
* optimistic message instead keeps the preview visible and leaves the `file` handle in reach of
|
|
37
|
-
* `settlePendingAttachmentUploads`, which retries a failed upload rather than dropping it.
|
|
38
|
-
* `blocked` is the one state that stays behind - the server's upload configuration refused it, so
|
|
39
|
-
* no retry can ever settle it, and it belongs in the composer where the user can remove it.
|
|
24
|
+
* Composition when {@link AttachmentManagerConfig.pendingUploadsEnabled} is on. `message.attachments`
|
|
25
|
+
* (sent to the API) carries only resolved uploads; `MessageOperations` adds the rest once uploads
|
|
26
|
+
* settle. `localMessage.attachments` also carries pending and `failed` ones with their
|
|
27
|
+
* `localMetadata` (`id`, `file`, `previewUri`), so `settlePendingAttachmentUploads` can await or retry
|
|
28
|
+
* them, unless the composer retains its content. `blocked` uploads cannot be retried and stay put.
|
|
40
29
|
*/
|
|
41
30
|
const composeWithPendingUploads = ({
|
|
42
31
|
composer,
|
|
@@ -45,16 +34,11 @@ const composeWithPendingUploads = ({
|
|
|
45
34
|
composer: MessageComposer;
|
|
46
35
|
state: MessageComposerMiddlewareState;
|
|
47
36
|
}): MessageComposerMiddlewareState => {
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
// `UploadManager.upload` call would restart the request under an id whose in-flight entry had
|
|
51
|
-
// already been cleaned up. A retry from two places collides the same way. So both pending and
|
|
52
|
-
// failed uploads stay in the composer here, and ride along with the next message once they
|
|
53
|
-
// settle.
|
|
37
|
+
// When the composer keeps its content, unresolved uploads stay in it too: one `localMetadata.id`
|
|
38
|
+
// must not be owned by both the composer and the sent message.
|
|
54
39
|
const composerIsKeptAsDraft = composer.retainsCompositionOnSubmit;
|
|
55
40
|
|
|
56
|
-
// Composer order is
|
|
57
|
-
// settles.
|
|
41
|
+
// Composer order is kept in both payloads, so previews do not reshuffle when an upload settles.
|
|
58
42
|
const relevantAttachments = composer.attachmentManager.attachments.filter(
|
|
59
43
|
(attachment) =>
|
|
60
44
|
isFinishedUpload(attachment) ||
|
|
@@ -63,8 +47,7 @@ const composeWithPendingUploads = ({
|
|
|
63
47
|
);
|
|
64
48
|
|
|
65
49
|
const localAttachments = (state.localMessage.attachments ?? []).concat(
|
|
66
|
-
// Only a finished upload has a URL
|
|
67
|
-
// is what the message list joins to the live `uploadManager` record and what a retry needs.
|
|
50
|
+
// Only a finished upload has a URL; the rest keep `localMetadata` (joined to the upload record).
|
|
68
51
|
relevantAttachments.map((attachment) =>
|
|
69
52
|
isFinishedUpload(attachment) ? localAttachmentToAttachment(attachment) : attachment,
|
|
70
53
|
),
|
|
@@ -75,10 +58,8 @@ const composeWithPendingUploads = ({
|
|
|
75
58
|
|
|
76
59
|
if (!localAttachments.length && !messageAttachments.length) return state;
|
|
77
60
|
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
// as "remove every attachment", and a message whose uploads are all still in flight produces
|
|
81
|
-
// exactly that - no finished upload to put in `message.attachments` yet.
|
|
61
|
+
// `attachments` is set only when non-empty: on an edit the API reads an empty array as "remove every
|
|
62
|
+
// attachment".
|
|
82
63
|
return {
|
|
83
64
|
...state,
|
|
84
65
|
localMessage: localAttachments.length
|
|
@@ -97,15 +78,8 @@ const composeWithPendingUploads = ({
|
|
|
97
78
|
};
|
|
98
79
|
|
|
99
80
|
/**
|
|
100
|
-
* Composes the message's attachments.
|
|
101
|
-
*
|
|
102
|
-
* By default an upload still in flight blocks the send: the chain warns and discards the
|
|
103
|
-
* composition. With {@link AttachmentManagerConfig.pendingUploadsEnabled} on it composes
|
|
104
|
-
* anyway, leaving `message.attachments` without the unresolved ones — `MessageOperations` awaits
|
|
105
|
-
* those uploads and fills in the URLs before the request goes out.
|
|
106
|
-
*
|
|
107
|
-
* The config is read per composition rather than at construction, so `updateConfig` takes effect
|
|
108
|
-
* on the next send with no need to reinstall anything.
|
|
81
|
+
* Composes the message's attachments. An upload in flight blocks the send (warns and discards) unless
|
|
82
|
+
* {@link AttachmentManagerConfig.pendingUploadsEnabled} is on. The config is read per composition.
|
|
109
83
|
*/
|
|
110
84
|
export const createAttachmentsCompositionMiddleware = (
|
|
111
85
|
composer: MessageComposer,
|
|
@@ -143,7 +117,7 @@ export const createAttachmentsCompositionMiddleware = (
|
|
|
143
117
|
attachmentManager.successfulUploads.map(localAttachmentToAttachment),
|
|
144
118
|
);
|
|
145
119
|
|
|
146
|
-
//
|
|
120
|
+
// Do not add an empty `attachments` array to the payload.
|
|
147
121
|
if (!attachments.length) return forward();
|
|
148
122
|
|
|
149
123
|
return next({
|
|
@@ -39,7 +39,7 @@ export const createLinkPreviewsCompositionMiddleware = (
|
|
|
39
39
|
state.localMessage.attachments ?? []
|
|
40
40
|
).concat(linkPreviews);
|
|
41
41
|
|
|
42
|
-
//
|
|
42
|
+
// Do not add an empty `attachments` array to the payload.
|
|
43
43
|
if (!messageAttachments.length && !localAttachments.length) return forward();
|
|
44
44
|
|
|
45
45
|
const sendOptions = { ...state.sendOptions };
|
|
@@ -50,9 +50,8 @@ export const createLinkPreviewsCompositionMiddleware = (
|
|
|
50
50
|
sendOptions.skip_enrich_url = true;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
// the API reads it as "remove every attachment".
|
|
53
|
+
// `attachments` is set only when non-empty: on an edit the API reads an empty array as "remove
|
|
54
|
+
// every attachment".
|
|
56
55
|
return next({
|
|
57
56
|
...state,
|
|
58
57
|
message: messageAttachments.length
|
|
@@ -130,7 +130,7 @@ export const createTextComposerCompositionMiddleware = (
|
|
|
130
130
|
mentioned_users,
|
|
131
131
|
} = buildMentionCompositionMetadata({ mentions, text });
|
|
132
132
|
|
|
133
|
-
//
|
|
133
|
+
// Do not add empty text and mention metadata to the payload.
|
|
134
134
|
if (
|
|
135
135
|
!text &&
|
|
136
136
|
!mentioned_channel &&
|
|
@@ -19,14 +19,7 @@ export const createUserDataInjectionMiddleware = (
|
|
|
19
19
|
if (!composer.client.user) {
|
|
20
20
|
return forward();
|
|
21
21
|
}
|
|
22
|
-
//
|
|
23
|
-
// that provide no value for localMessage (and will never exist within message.user).
|
|
24
|
-
// This way we make sure that our localMessage is enriched with data as close as
|
|
25
|
-
// possible to the actual user.
|
|
26
|
-
// The cast below is needed because `client.user` is `ClientUser`, which makes every
|
|
27
|
-
// field but `id` optional — it is only fully populated once `connectUser` has run and
|
|
28
|
-
// the connection hello event has arrived.
|
|
29
|
-
|
|
22
|
+
// Leave out large properties that never exist on `message.user`.
|
|
30
23
|
const {
|
|
31
24
|
channel_mutes: _channel_mutes,
|
|
32
25
|
devices: _devices,
|
|
@@ -37,9 +30,9 @@ export const createUserDataInjectionMiddleware = (
|
|
|
37
30
|
...state,
|
|
38
31
|
localMessage: {
|
|
39
32
|
...state.localMessage,
|
|
40
|
-
// `
|
|
41
|
-
//
|
|
42
|
-
//
|
|
33
|
+
// `ClientUser` makes every field but `id` optional, so the cast holds only after connect.
|
|
34
|
+
// `blocked_user_ids` is optional on `OwnUserResponse` (omitted when nothing is blocked)
|
|
35
|
+
// but required on `UserResponse`.
|
|
43
36
|
user: {
|
|
44
37
|
...messageUser,
|
|
45
38
|
blocked_user_ids: messageUser.blocked_user_ids ?? [],
|
|
@@ -154,7 +154,7 @@ export const pollCompositionStateProcessors: Partial<
|
|
|
154
154
|
max_votes_allowed: clampMaxVotesAllowed(value),
|
|
155
155
|
}),
|
|
156
156
|
options: ({ value, data }) => {
|
|
157
|
-
//
|
|
157
|
+
// Whole-list update (e.g. drag-drop reordering).
|
|
158
158
|
if (Array.isArray(value)) {
|
|
159
159
|
return {
|
|
160
160
|
options: value.map((option) => ({
|
|
@@ -164,7 +164,7 @@ export const pollCompositionStateProcessors: Partial<
|
|
|
164
164
|
};
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
//
|
|
167
|
+
// Single option update.
|
|
168
168
|
const { index, text } = value;
|
|
169
169
|
const prevOptions = data.options || [];
|
|
170
170
|
|
|
@@ -21,10 +21,8 @@ export type UpdateFieldsData = Partial<Omit<PollComposerState['data'], 'options'
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* Field validation errors, keyed by field
|
|
25
|
-
*
|
|
26
|
-
* Values carry a stable {@link PollComposerValidationError.code} rather than being bare English, so a UI can
|
|
27
|
-
* localize them; see {@link POLL_COMPOSER_VALIDATION_CODE}.
|
|
24
|
+
* Field validation errors, keyed by field (`options` errors by option ID). Each carries a stable
|
|
25
|
+
* {@link PollComposerValidationError.code} for localization.
|
|
28
26
|
*/
|
|
29
27
|
export type PollComposerFieldErrors = Partial<
|
|
30
28
|
Omit<Record<keyof CreatePollRequest, PollComposerValidationError>, 'options'> & {
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* errors, rendered inline beside the input that produced them, and they never reach
|
|
6
|
-
* `NotificationManager` — routing them there would raise a toast per keystroke. `CORE_NOTIFICATION_TYPE`
|
|
7
|
-
* is the notification counterpart; the two sets are disjoint and neither substitutes for the other.
|
|
8
|
-
*
|
|
9
|
-
* **These values are public API.** UI SDKs key their translation tables on them, so renaming one is a
|
|
10
|
-
* breaking change.
|
|
2
|
+
* Identifiers for poll-composer field validation failures. They are rendered inline and never reach
|
|
3
|
+
* `NotificationManager` (unlike `CORE_NOTIFICATION_TYPE`). **Public API:** UI SDKs key translations on
|
|
4
|
+
* them, so renaming one is breaking.
|
|
11
5
|
*/
|
|
12
6
|
export const POLL_COMPOSER_VALIDATION_CODE = {
|
|
13
7
|
maxVotesNotNumeric: 'validation:poll:maxVotes:notNumeric',
|
|
@@ -21,13 +15,7 @@ export const POLL_COMPOSER_VALIDATION_CODE = {
|
|
|
21
15
|
export type PollComposerValidationCode =
|
|
22
16
|
(typeof POLL_COMPOSER_VALIDATION_CODE)[keyof typeof POLL_COMPOSER_VALIDATION_CODE];
|
|
23
17
|
|
|
24
|
-
/**
|
|
25
|
-
* Untranslated English for each code.
|
|
26
|
-
*
|
|
27
|
-
* Kept here rather than at the call sites so one code cannot end up with two different wordings, and
|
|
28
|
-
* so the whole set is reviewable in one place. This is a developer-facing fallback — the wording is
|
|
29
|
-
* not part of the public contract and may change in a minor release.
|
|
30
|
-
*/
|
|
18
|
+
/** Untranslated English fallback per code. The wording is not public contract. */
|
|
31
19
|
const POLL_COMPOSER_VALIDATION_MESSAGE: Record<PollComposerValidationCode, string> = {
|
|
32
20
|
[POLL_COMPOSER_VALIDATION_CODE.maxVotesNotNumeric]: 'Only numbers are allowed',
|
|
33
21
|
[POLL_COMPOSER_VALIDATION_CODE.maxVotesOutOfRange]: 'Type a number from 2 to 10',
|
|
@@ -38,13 +26,7 @@ const POLL_COMPOSER_VALIDATION_MESSAGE: Record<PollComposerValidationCode, strin
|
|
|
38
26
|
[POLL_COMPOSER_VALIDATION_CODE.optionEmpty]: 'Option is empty',
|
|
39
27
|
};
|
|
40
28
|
|
|
41
|
-
/**
|
|
42
|
-
* A poll-composer field validation failure.
|
|
43
|
-
*
|
|
44
|
-
* `code` is the stable identifier to resolve localized copy from. `message` carries untranslated
|
|
45
|
-
* English alongside it so a consumer with no i18n layer still renders something, and so an
|
|
46
|
-
* identifier a consumer does not recognize degrades to readable text instead of a blank field.
|
|
47
|
-
*/
|
|
29
|
+
/** A poll-composer field validation failure. `message` is an English fallback for `code`. */
|
|
48
30
|
export type PollComposerValidationError = {
|
|
49
31
|
/** Stable identifier. See {@link POLL_COMPOSER_VALIDATION_CODE}. */
|
|
50
32
|
code: PollComposerValidationCode;
|
|
@@ -65,10 +47,10 @@ export const pollComposerValidationError = (
|
|
|
65
47
|
});
|
|
66
48
|
|
|
67
49
|
/**
|
|
68
|
-
*
|
|
50
|
+
* Distinguishes a single failure from the per-option-ID record that `options` errors use.
|
|
69
51
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
52
|
+
* @param value - A field error entry.
|
|
53
|
+
* @returns Whether `value` is a single `PollComposerValidationError`.
|
|
72
54
|
*/
|
|
73
55
|
export const isPollComposerValidationError = (
|
|
74
56
|
value: unknown,
|
|
@@ -68,12 +68,7 @@ export class TextComposerMiddlewareExecutor<
|
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
const { query, searchSource } = result.state.suggestions ?? ({} as Suggestions);
|
|
71
|
-
|
|
72
|
-
* Catching error just for sanity purposes.
|
|
73
|
-
* The BaseSearchSource.search() method returns debounced result.
|
|
74
|
-
* That means the result of the previous search call as the debounced call result is unknown at the moment.
|
|
75
|
-
* Custom search source implementation should handle errors meaningfully internally.
|
|
76
|
-
*/
|
|
71
|
+
// `search` is debounced, so its errors are only logged. Custom sources should handle their own.
|
|
77
72
|
searchSource
|
|
78
73
|
?.search(query)
|
|
79
74
|
?.catch((error) =>
|
|
@@ -12,8 +12,7 @@ export const getRawCommandName = (text?: string) =>
|
|
|
12
12
|
text?.match(/^\/(\S+)(?:\s.*)?$/)?.[1];
|
|
13
13
|
|
|
14
14
|
export const getCompleteCommandInString = (text: string) => {
|
|
15
|
-
//
|
|
16
|
-
// the command name is extracted into a separate group
|
|
15
|
+
// `/name` followed by whitespace; captures the name.
|
|
17
16
|
const match = text.match(/^\/(\S+)\s+.*/);
|
|
18
17
|
const commandName = match && match[1];
|
|
19
18
|
return commandName;
|
|
@@ -33,7 +33,7 @@ export class CommandSearchSource extends BaseSearchSourceSync<CommandSuggestion>
|
|
|
33
33
|
const { items } = this.state.getLatestValue();
|
|
34
34
|
return {
|
|
35
35
|
...newState,
|
|
36
|
-
items, //
|
|
36
|
+
items, // kept to avoid flickering
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -48,7 +48,7 @@ export class CommandSearchSource extends BaseSearchSourceSync<CommandSuggestion>
|
|
|
48
48
|
);
|
|
49
49
|
|
|
50
50
|
if (searchQuery) {
|
|
51
|
-
//
|
|
51
|
+
// Alphabetical, with prefix matches first.
|
|
52
52
|
selectedCommands.sort((a, b) => {
|
|
53
53
|
let nameA = a.name?.toLowerCase();
|
|
54
54
|
let nameB = b.name?.toLowerCase();
|
|
@@ -58,7 +58,6 @@ export class CommandSearchSource extends BaseSearchSourceSync<CommandSuggestion>
|
|
|
58
58
|
if (nameB?.indexOf(searchQuery) === 0) {
|
|
59
59
|
nameB = `0${nameB}`;
|
|
60
60
|
}
|
|
61
|
-
// Should confirm possible null / undefined when TS is fully implemented
|
|
62
61
|
if (nameA != null && nameB != null) {
|
|
63
62
|
if (nameA < nameB) {
|
|
64
63
|
return -1;
|
|
@@ -86,19 +85,6 @@ export class CommandSearchSource extends BaseSearchSourceSync<CommandSuggestion>
|
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
87
|
|
|
89
|
-
/**
|
|
90
|
-
* TextComposer middleware for mentions
|
|
91
|
-
* Usage:
|
|
92
|
-
*
|
|
93
|
-
* const textComposer = new TextComposer(options);
|
|
94
|
-
*
|
|
95
|
-
* textComposer.use(createCommandsMiddleware(channel, { trigger: '//', minChars: 2 } ));
|
|
96
|
-
*
|
|
97
|
-
* @param channel
|
|
98
|
-
* @param {{ minChars: number; trigger: string }} options
|
|
99
|
-
* @returns
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
88
|
const DEFAULT_OPTIONS: TextComposerMiddlewareOptions = { minChars: 1, trigger: '/' };
|
|
103
89
|
|
|
104
90
|
export type CommandsMiddleware = Middleware<
|
|
@@ -106,6 +92,15 @@ export type CommandsMiddleware = Middleware<
|
|
|
106
92
|
'onChange' | 'onSuggestionItemSelect'
|
|
107
93
|
>;
|
|
108
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Suggests and activates slash commands.
|
|
97
|
+
*
|
|
98
|
+
* @param channel - The channel whose commands are suggested.
|
|
99
|
+
* @param options - Middleware options. Defaults to `trigger: '/'` and `minChars: 1`.
|
|
100
|
+
* @param options.composer - Used to refuse commands disabled by the editing or quoting state.
|
|
101
|
+
* @param options.searchSource - A search source to use instead of a new one. Its state is reset.
|
|
102
|
+
* @returns The commands middleware.
|
|
103
|
+
*/
|
|
109
104
|
export const createCommandsMiddleware = (
|
|
110
105
|
channel: Channel,
|
|
111
106
|
options?: Partial<TextComposerMiddlewareOptions> & {
|
|
@@ -95,10 +95,13 @@ export const calculateLevenshtein = (query: string, name: string) => {
|
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
export type MentionsSearchSourceOptions = SearchSourceOptions & {
|
|
98
|
-
/**
|
|
98
|
+
/** Base filters for the app-wide user query (`mentionAllAppUsers`). */
|
|
99
99
|
userFilters?: UserFilters;
|
|
100
100
|
userSort?: SortParamRequest[];
|
|
101
|
-
/**
|
|
101
|
+
/**
|
|
102
|
+
* Replaces the default `name` autocomplete filter of the channel member query, so the typed text
|
|
103
|
+
* is not applied.
|
|
104
|
+
*/
|
|
102
105
|
memberFilters?: MemberFilters;
|
|
103
106
|
memberSort?: SortParamRequest[];
|
|
104
107
|
searchOptions?: Omit<UserOptions, 'limit' | 'offset'>;
|
|
@@ -283,10 +286,7 @@ const DEFAULT_SUGGESTION_FACTORY_MAPPERS: {
|
|
|
283
286
|
return {
|
|
284
287
|
description: userGroup.description,
|
|
285
288
|
id: userGroup.id,
|
|
286
|
-
|
|
287
|
-
Currently, all members of the group are always returned. Groups are limited to 100 members.
|
|
288
|
-
The memberCount == len(members) will always be true unless we add pagination here in the future
|
|
289
|
-
*/
|
|
289
|
+
// All members are returned (groups hold at most 100), so `members.length` is the full count.
|
|
290
290
|
memberCount: userGroup.members?.length,
|
|
291
291
|
mentionType: 'user_group',
|
|
292
292
|
name: userGroup.name,
|
|
@@ -328,7 +328,7 @@ export class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> {
|
|
|
328
328
|
userSort,
|
|
329
329
|
...restOptions
|
|
330
330
|
} = options || {};
|
|
331
|
-
//
|
|
331
|
+
// A bare trigger shows suggestions, so the empty query must be allowed.
|
|
332
332
|
super({ ...restOptions, allowEmptySearchString: true });
|
|
333
333
|
this.client = channel.getClient();
|
|
334
334
|
this.channel = channel;
|
|
@@ -445,7 +445,7 @@ export class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> {
|
|
|
445
445
|
const { items } = this.state.getLatestValue();
|
|
446
446
|
return {
|
|
447
447
|
...newState,
|
|
448
|
-
items, //
|
|
448
|
+
items, // kept to avoid flickering
|
|
449
449
|
};
|
|
450
450
|
}
|
|
451
451
|
|
|
@@ -534,7 +534,7 @@ export class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> {
|
|
|
534
534
|
.sort((a, b) => {
|
|
535
535
|
if (!this.memberSort) return (a.name || '').localeCompare(b.name || '');
|
|
536
536
|
|
|
537
|
-
//
|
|
537
|
+
// Criteria apply in order.
|
|
538
538
|
for (const { field, direction } of this.memberSort) {
|
|
539
539
|
const aValue = a[field as keyof UserResponse];
|
|
540
540
|
const bValue = b[field as keyof UserResponse];
|
|
@@ -566,13 +566,11 @@ export class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> {
|
|
|
566
566
|
});
|
|
567
567
|
|
|
568
568
|
prepareQueryMembersParams = (searchQuery: string, offset = 0) => {
|
|
569
|
-
// QueryMembers
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
sort = this.memberSort.slice(0, 1);
|
|
575
|
-
} // todo: document the change - the sort is overridden, not merged
|
|
569
|
+
// QueryMembers accepts at most one sort item.
|
|
570
|
+
// todo: document the change - the sort is overridden, not merged
|
|
571
|
+
const sort: SortParamRequest[] = this.memberSort?.length
|
|
572
|
+
? this.memberSort.slice(0, 1)
|
|
573
|
+
: [{ field: 'user_id', direction: 1 }];
|
|
576
574
|
return {
|
|
577
575
|
// todo: document the change - the filter is overridden, not merged
|
|
578
576
|
filters:
|
|
@@ -733,8 +731,7 @@ export class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> {
|
|
|
733
731
|
: Promise.resolve([] as RoleMentionSuggestion[]),
|
|
734
732
|
]);
|
|
735
733
|
|
|
736
|
-
// On abort the requests
|
|
737
|
-
// empty results into the pagination cursors, corrupting them for the newer query.
|
|
734
|
+
// On abort the requests reject, and the fallbacks below would overwrite the newer query's cursors.
|
|
738
735
|
if (queryOptions.signal?.aborted) return { items: [] };
|
|
739
736
|
|
|
740
737
|
const userResults =
|
|
@@ -812,30 +809,19 @@ export class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> {
|
|
|
812
809
|
|
|
813
810
|
const DEFAULT_OPTIONS: TextComposerMiddlewareOptions = { minChars: 1, trigger: '@' };
|
|
814
811
|
|
|
815
|
-
/**
|
|
816
|
-
* TextComposer middleware for mentions
|
|
817
|
-
* Usage:
|
|
818
|
-
*
|
|
819
|
-
* const textComposer = new TextComposer(options);
|
|
820
|
-
*
|
|
821
|
-
* textComposer.use(createMentionsMiddleware(channel, {
|
|
822
|
-
* trigger: '$',
|
|
823
|
-
* minChars: 2
|
|
824
|
-
* }));
|
|
825
|
-
*
|
|
826
|
-
* @param channel
|
|
827
|
-
* @param {{
|
|
828
|
-
* minChars: number;
|
|
829
|
-
* trigger: string;
|
|
830
|
-
* }} options
|
|
831
|
-
* @returns
|
|
832
|
-
*/
|
|
833
|
-
|
|
834
812
|
export type MentionsMiddleware = Middleware<
|
|
835
813
|
TextComposerMiddlewareExecutorState<MentionSuggestion>,
|
|
836
814
|
'onChange' | 'onSuggestionItemSelect'
|
|
837
815
|
>;
|
|
838
816
|
|
|
817
|
+
/**
|
|
818
|
+
* Suggests and inserts mentions.
|
|
819
|
+
*
|
|
820
|
+
* @param channel - The channel to search mentions in.
|
|
821
|
+
* @param options - Middleware options. Defaults to `trigger: '@'` and `minChars: 1`.
|
|
822
|
+
* @param options.searchSource - A search source to use instead of a new one. Its state is reset.
|
|
823
|
+
* @returns The mentions middleware.
|
|
824
|
+
*/
|
|
839
825
|
export const createMentionsMiddleware = (
|
|
840
826
|
channel: Channel,
|
|
841
827
|
options?: Partial<TextComposerMiddlewareOptions> & {
|
|
@@ -851,12 +837,8 @@ export const createMentionsMiddleware = (
|
|
|
851
837
|
searchSource = new MentionsSearchSource(channel, { trigger: finalOptions.trigger });
|
|
852
838
|
}
|
|
853
839
|
searchSource.activate();
|
|
854
|
-
//
|
|
855
|
-
//
|
|
856
|
-
// can suppress the dropdown even when the text shape heuristic in `onChange`
|
|
857
|
-
// would otherwise let it reopen (which is wrong). Consumed on the first
|
|
858
|
-
// `onChange` after it's set, so any user driven event that triggers it would
|
|
859
|
-
// clear it.
|
|
840
|
+
// Cursor end of the last inserted mention. The next `onChange` (e.g. a controlled value echo) uses
|
|
841
|
+
// it to keep the dropdown closed, then clears it.
|
|
860
842
|
let lastInsertedMentionEndOffset: number | undefined;
|
|
861
843
|
return {
|
|
862
844
|
id: 'stream-io/text-composer/mentions-middleware',
|
|
@@ -867,12 +849,8 @@ export const createMentionsMiddleware = (
|
|
|
867
849
|
lastInsertedMentionEndOffset !== undefined &&
|
|
868
850
|
state.selection.end === lastInsertedMentionEndOffset;
|
|
869
851
|
lastInsertedMentionEndOffset = undefined;
|
|
870
|
-
//
|
|
871
|
-
//
|
|
872
|
-
// snapshots the previous TextComposer state so it can be restored on
|
|
873
|
-
// `clearCommand()`. Custom middleware is allowed to remove that effect,
|
|
874
|
-
// though, and in that opt-out case we must not silently drop mentions
|
|
875
|
-
// here just because the user typed a raw command like `/ban`.
|
|
852
|
+
// Prune stale mentions only outside command mode: a raw `/ban` typed without the
|
|
853
|
+
// `command.activate` effect (custom middleware may remove it) must not drop them.
|
|
876
854
|
const currentMentions =
|
|
877
855
|
state.command || state.text.trimStart().startsWith('/')
|
|
878
856
|
? state.mentionedUsers
|
|
@@ -903,23 +881,9 @@ export const createMentionsMiddleware = (
|
|
|
903
881
|
searchSource.resetStateAndActivate();
|
|
904
882
|
}
|
|
905
883
|
|
|
906
|
-
// The trigger
|
|
907
|
-
//
|
|
908
|
-
//
|
|
909
|
-
// trailing space boundary of a mention the user has already committed
|
|
910
|
-
// (post suggestion select or manual cursor placement back into that slot).
|
|
911
|
-
//
|
|
912
|
-
// Discriminate that case by checking, for each entity in
|
|
913
|
-
// `state.mentions`, whether the text immediately before the cursor
|
|
914
|
-
// ends with the entity's actual inserted textual form (`@<name|id> `)
|
|
915
|
-
// AND that form appears exactly once in the prefix. This:
|
|
916
|
-
// - avoids false positives when an entity's `id` happens to match a
|
|
917
|
-
// different `@<token>` the user just typed (e.g. user "John Doe"
|
|
918
|
-
// whose id is "john" and the user types a fresh `@ivan ` later);
|
|
919
|
-
// - avoids false positives when the user is refining a brand new
|
|
920
|
-
// mention whose query equals an already committed mention name
|
|
921
|
-
// (text has two `@<name> ` occurrences; only one is committed, the
|
|
922
|
-
// cursor is most likely on the new one being typed).
|
|
884
|
+
// The trigger regex also accepts `@<token><trailing-space>`, which would reopen the dropdown
|
|
885
|
+
// after a committed mention. Detect that case: the text before the cursor ends with an entity's
|
|
886
|
+
// inserted form (`@<name|id> `) that occurs exactly once (twice means a new one is being typed).
|
|
923
887
|
const triggerMatchesCommittedMention =
|
|
924
888
|
!!triggerWithToken &&
|
|
925
889
|
/\s$/.test(textBeforeCursor) &&
|
|
@@ -980,10 +944,8 @@ export const createMentionsMiddleware = (
|
|
|
980
944
|
text: state.text,
|
|
981
945
|
trigger: finalOptions.trigger,
|
|
982
946
|
});
|
|
983
|
-
//
|
|
984
|
-
//
|
|
985
|
-
// doesn't catch a reselection of the same entity (multiple
|
|
986
|
-
// occurrences of `@<name> ` in the text for exammple).
|
|
947
|
+
// Lets the next `onChange` keep the dropdown closed when the text heuristic cannot tell (e.g.
|
|
948
|
+
// repeated `@<name> ` occurrences).
|
|
987
949
|
lastInsertedMentionEndOffset = insertResult.selection.end;
|
|
988
950
|
return complete({
|
|
989
951
|
...state,
|
|
@@ -2,9 +2,15 @@ import type { TextSelection } from './types';
|
|
|
2
2
|
import { escapeCommandRegExp } from './commandUtils';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Finds the trigger-prefixed token that ends `text`.
|
|
6
|
+
*
|
|
7
|
+
* @param params.trigger - The trigger character, e.g. `@` or `/`.
|
|
8
|
+
* @param params.text - The text to search.
|
|
9
|
+
* @param params.isCommand - Require the trigger to start the text and the token to contain no
|
|
10
|
+
* whitespace. Defaults to `false`.
|
|
11
|
+
* @param params.acceptTrailingSpaces - Let the token span one whitespace character. Ignored with
|
|
12
|
+
* `isCommand`. Defaults to `true`.
|
|
13
|
+
* @returns The trimmed token with its trigger, or `null`.
|
|
8
14
|
*/
|
|
9
15
|
export const getTriggerCharWithToken = ({
|
|
10
16
|
trigger,
|
|
@@ -48,7 +54,7 @@ export const insertItemWithTrigger = ({
|
|
|
48
54
|
const beforeCursor = text.slice(0, selection.end);
|
|
49
55
|
const afterCursor = text.slice(selection.end);
|
|
50
56
|
|
|
51
|
-
// Replace the trigger and query with
|
|
57
|
+
// Replace the trigger and query with `insertText`.
|
|
52
58
|
const lastIndex = beforeCursor.lastIndexOf(trigger);
|
|
53
59
|
const newText = beforeCursor.slice(0, lastIndex) + insertText + afterCursor;
|
|
54
60
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MessageComposer } from '../../messageComposer';
|
|
2
2
|
import type { MessageComposerEffect } from '../../messageComposer';
|
|
3
|
-
import type { Command,
|
|
3
|
+
import type { Command, UserResponse } from '../../../types';
|
|
4
4
|
import type { TokenizationPayload } from './textMiddlewareUtils';
|
|
5
5
|
import type { SearchSource, SearchSourceSync } from '../../../search';
|
|
6
6
|
import type { CustomTextComposerSuggestion } from '../../types.custom';
|
|
@@ -126,11 +126,6 @@ export type TextComposerState<T extends Suggestion = Suggestion> = {
|
|
|
126
126
|
mentions?: MentionEntity[];
|
|
127
127
|
selection: TextSelection;
|
|
128
128
|
text: string;
|
|
129
|
-
/**
|
|
130
|
-
* Live typing events keyed by user id.
|
|
131
|
-
* Maps `user.id` -> latest typing event (`typing.start`/`typing.stop`) for that user.
|
|
132
|
-
*/
|
|
133
|
-
typing: Record<string, Event>;
|
|
134
129
|
command?: Command | null;
|
|
135
130
|
suggestions?: Suggestions<T>;
|
|
136
131
|
};
|
|
@@ -122,15 +122,18 @@ export class PollComposer {
|
|
|
122
122
|
/**
|
|
123
123
|
* Updates specified fields and generates relevant errors.
|
|
124
124
|
*
|
|
125
|
-
* @param
|
|
126
|
-
* @param
|
|
127
|
-
*
|
|
125
|
+
* @param params - The fields to update and any externally produced errors.
|
|
126
|
+
* @param params.data - Partial poll data with the fields to update.
|
|
127
|
+
* @param params.injectedFieldErrors - Errors produced externally that will take precedence over
|
|
128
|
+
* the errors generated in the middleware chain (optional).
|
|
128
129
|
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
updateFields = async ({
|
|
131
|
+
data,
|
|
132
|
+
injectedFieldErrors,
|
|
133
|
+
}: {
|
|
134
|
+
data: UpdateFieldsData;
|
|
135
|
+
injectedFieldErrors?: PollComposerFieldErrors;
|
|
136
|
+
}) => {
|
|
134
137
|
const { state, status } = await this.stateMiddlewareExecutor.execute({
|
|
135
138
|
eventName: 'handleFieldChange',
|
|
136
139
|
initialValue: {
|