stream-chat 10.0.0-rc.9 → 10.0.0
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 +7 -6
- package/dist/cjs/index.browser.js +21650 -19790
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +21690 -19798
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +21755 -19895
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelManager.d.ts +216 -135
- package/dist/types/CooldownTimer.d.ts +13 -27
- package/dist/types/EventHandlerPipeline.d.ts +18 -38
- package/dist/types/LiveLocationManager.d.ts +24 -52
- package/dist/types/api-client.d.ts +17 -5
- package/dist/types/channel.d.ts +432 -470
- package/dist/types/channel_state.d.ts +68 -112
- package/dist/types/client.d.ts +321 -435
- package/dist/types/client_state.d.ts +1 -3
- package/dist/types/configuration/ConfigController.d.ts +31 -125
- package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +32 -124
- 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 +64 -79
- package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +14 -36
- 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 +45 -0
- package/dist/types/connection/ConnectionRecoveryManager.d.ts +84 -0
- package/dist/types/connection/index.d.ts +4 -0
- package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +82 -0
- package/dist/types/connection/networkConnection/index.d.ts +3 -0
- package/dist/types/connection/networkConnection/reporters.d.ts +20 -0
- package/dist/types/connection/networkConnection/types.d.ts +40 -0
- package/dist/types/connection/wsConnection/StableWSConnection.d.ts +137 -0
- package/dist/types/connection/wsConnection/WSConnection.d.ts +105 -0
- package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +47 -0
- package/dist/types/connection/wsConnection/config.d.ts +31 -0
- package/dist/types/connection/wsConnection/index.d.ts +4 -0
- package/dist/types/connection/wsConnection/types.d.ts +46 -0
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/custom_types.d.ts +0 -2
- package/dist/types/entityStore/EntityStore.d.ts +226 -65
- package/dist/types/entityStore/StoreBackedItemIndex.d.ts +19 -33
- package/dist/types/entityStore/index.d.ts +0 -1
- package/dist/types/errors.d.ts +16 -19
- package/dist/types/formatMessageMemo.d.ts +5 -0
- package/dist/types/gen/chat/ChannelApi.d.ts +5 -1
- package/dist/types/gen/chat/ChatApi.d.ts +149 -105
- package/dist/types/gen/models/index.d.ts +2528 -690
- package/dist/types/gen/models/timestamp-guard.d.ts +22 -0
- package/dist/types/gen/moderation/ModerationApi.d.ts +33 -14
- package/dist/types/index.d.ts +10 -6
- package/dist/types/{i18n/languageNames.d.ts → languageNames.d.ts} +9 -24
- package/dist/types/logger.d.ts +1 -3
- package/dist/types/messageComposer/CustomDataManager.d.ts +7 -1
- package/dist/types/messageComposer/LocationComposer.d.ts +7 -1
- package/dist/types/messageComposer/attachmentIdentity.d.ts +24 -0
- package/dist/types/messageComposer/attachmentManager.d.ts +52 -24
- package/dist/types/messageComposer/attachmentUtils.d.ts +23 -0
- package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
- package/dist/types/messageComposer/configuration/types.d.ts +38 -50
- package/dist/types/messageComposer/index.d.ts +1 -0
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +12 -9
- package/dist/types/messageComposer/messageComposer.d.ts +60 -128
- package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +10 -1
- package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +4 -0
- package/dist/types/messageComposer/middleware/messageComposer/commandInjection.d.ts +5 -0
- package/dist/types/messageComposer/middleware/messageComposer/index.d.ts +2 -0
- package/dist/types/messageComposer/middleware/messageComposer/pollOnly.d.ts +6 -0
- package/dist/types/messageComposer/middleware/messageComposer/userDataInjection.d.ts +5 -0
- 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/commandUtils.d.ts +4 -0
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +11 -2
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +19 -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 +15 -5
- package/dist/types/messageComposer/textComposer.d.ts +14 -7
- package/dist/types/messageComposer/types.d.ts +27 -7
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +27 -80
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +40 -73
- package/dist/types/messageOperations/FailedSendCache.d.ts +29 -0
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +16 -22
- package/dist/types/messageOperations/MessageOperations.d.ts +63 -34
- package/dist/types/messageOperations/applyReactionLocally.d.ts +15 -0
- package/dist/types/messageOperations/createMessageOperations.d.ts +9 -0
- package/dist/types/messageOperations/index.d.ts +6 -4
- package/dist/types/messageOperations/reflectReactionEvent.d.ts +16 -0
- package/dist/types/messageOperations/sendOrdering.d.ts +14 -0
- package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +20 -0
- package/dist/types/messageOperations/types.d.ts +43 -14
- package/dist/types/middleware.d.ts +10 -0
- package/dist/types/moderation.d.ts +21 -14
- package/dist/types/notifications/NotificationManager.d.ts +10 -23
- package/dist/types/notifications/types.d.ts +21 -57
- package/dist/types/offline-support/offline_support_api.d.ts +150 -528
- package/dist/types/offline-support/offline_sync_manager.d.ts +21 -42
- package/dist/types/offline-support/queueableOperations.d.ts +35 -37
- package/dist/types/offline-support/types.d.ts +40 -186
- package/dist/types/pagination/FilterBuilder.d.ts +1 -18
- 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 +4 -5
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +19 -5
- package/dist/types/pagination/index.d.ts +1 -0
- package/dist/types/pagination/paginators/BasePaginator.d.ts +604 -550
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +123 -106
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +576 -334
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +237 -131
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +15 -26
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +4 -3
- package/dist/types/pagination/paginators/ThreadPaginator.d.ts +44 -0
- package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +5 -8
- package/dist/types/pagination/paginators/index.d.ts +1 -0
- 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 +34 -8
- package/dist/types/poll_manager.d.ts +12 -2
- package/dist/types/poll_optimistic_votes.d.ts +57 -0
- package/dist/types/reminders/Reminder.d.ts +11 -11
- package/dist/types/reminders/ReminderManager.d.ts +13 -25
- package/dist/types/search/BaseSearchSource.d.ts +10 -8
- package/dist/types/search/ChannelSearchSource.d.ts +16 -0
- package/dist/types/search/MessageSearchSource.d.ts +17 -0
- package/dist/types/search/SearchController.d.ts +26 -28
- package/dist/types/search/types.d.ts +6 -10
- package/dist/types/signing.d.ts +12 -3
- package/dist/types/thread.d.ts +63 -129
- package/dist/types/thread_manager.d.ts +95 -66
- package/dist/types/token_manager.d.ts +8 -13
- package/dist/types/types.d.ts +81 -199
- package/dist/types/types.utility.d.ts +3 -3
- package/dist/types/upload-utils.d.ts +5 -10
- package/dist/types/uploadManager.d.ts +31 -11
- package/dist/types/utils/FixedSizeQueueCache.d.ts +8 -11
- package/dist/types/utils/WithSubscriptions.d.ts +6 -16
- package/dist/types/utils/abort.d.ts +17 -0
- package/dist/types/utils/concurrency.d.ts +12 -20
- 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 +33 -57
- package/dist/types/utils.d.ts +72 -91
- package/package.json +14 -40
- package/src/ChannelManager.ts +494 -303
- package/src/CooldownTimer.ts +28 -38
- package/src/EventHandlerPipeline.ts +22 -45
- package/src/LiveLocationManager.ts +37 -76
- package/src/api-client.ts +113 -50
- package/src/campaign.ts +1 -1
- package/src/channel.ts +1067 -1276
- package/src/channel_batch_updater.ts +1 -1
- package/src/channel_state.ts +73 -168
- package/src/client.ts +744 -974
- package/src/client_state.ts +3 -8
- package/src/configuration/ConfigController.ts +42 -158
- package/src/configuration/InstanceConfigurationRegistry.ts +43 -172
- package/src/configuration/index.ts +1 -1
- package/src/configuration/keys.ts +13 -32
- package/src/configuration/shape.ts +169 -59
- package/src/configuration/types.ts +69 -92
- package/src/configuration/utils/applyInstanceConfiguration.ts +22 -54
- 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 +111 -0
- package/src/connection/ConnectionRecoveryManager.ts +257 -0
- package/src/connection/index.ts +4 -0
- package/src/connection/networkConnection/NetworkConnectionObserver.ts +204 -0
- package/src/connection/networkConnection/index.ts +3 -0
- package/src/connection/networkConnection/reporters.ts +58 -0
- package/src/connection/networkConnection/types.ts +45 -0
- package/src/{connection.ts → connection/wsConnection/StableWSConnection.ts} +230 -232
- package/src/connection/wsConnection/WSConnection.ts +270 -0
- package/src/connection/wsConnection/WSConnectionFallback.ts +250 -0
- package/src/connection/wsConnection/config.ts +73 -0
- package/src/connection/wsConnection/index.ts +4 -0
- package/src/connection/wsConnection/types.ts +48 -0
- package/src/constants.ts +6 -5
- package/src/custom_types.ts +0 -1
- package/src/entityStore/EntityStore.ts +415 -79
- package/src/entityStore/StoreBackedItemIndex.ts +37 -41
- package/src/entityStore/index.ts +0 -1
- package/src/errors.ts +39 -20
- package/src/formatMessageMemo.ts +17 -0
- package/src/gen/chat/ChannelApi.ts +122 -36
- package/src/gen/chat/ChatApi.ts +578 -1540
- package/src/gen/models/index.ts +2498 -3383
- package/src/gen/models/timestamp-guard.ts +27 -0
- package/src/gen/moderation/ModerationApi.ts +170 -367
- package/src/index.ts +22 -10
- package/src/languageNames.ts +88 -0
- package/src/logger.ts +1 -3
- package/src/messageComposer/CustomDataManager.ts +19 -6
- package/src/messageComposer/LocationComposer.ts +19 -23
- package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
- package/src/messageComposer/attachmentIdentity.ts +54 -0
- package/src/messageComposer/attachmentManager.ts +170 -185
- package/src/messageComposer/attachmentUtils.ts +44 -0
- package/src/messageComposer/configuration/configuration.ts +15 -8
- package/src/messageComposer/configuration/types.ts +38 -50
- package/src/messageComposer/fileUtils.ts +1 -1
- package/src/messageComposer/index.ts +1 -0
- package/src/messageComposer/linkPreviewsManager.ts +18 -21
- package/src/messageComposer/messageComposer.ts +223 -174
- package/src/messageComposer/middleware/attachmentManager/postUpload/AttachmentPostUploadMiddlewareExecutor.ts +1 -1
- package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +46 -33
- package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +4 -1
- package/src/messageComposer/middleware/attachmentManager/preUpload/blockedUploadNotification.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/MessageComposerMiddlewareExecutor.ts +6 -0
- package/src/messageComposer/middleware/messageComposer/attachments.ts +76 -5
- package/src/messageComposer/middleware/messageComposer/commandInjection.ts +10 -4
- package/src/messageComposer/middleware/messageComposer/customData.ts +17 -5
- package/src/messageComposer/middleware/messageComposer/index.ts +2 -0
- package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +22 -12
- package/src/messageComposer/middleware/messageComposer/pollOnly.ts +9 -1
- package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +12 -12
- 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 +8 -6
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +10 -3
- 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 +21 -9
- package/src/messageComposer/textComposer.ts +37 -57
- package/src/messageComposer/types.ts +39 -11
- package/src/messageDelivery/MessageDeliveryReporter.ts +86 -125
- package/src/messageDelivery/MessageReceiptsTracker.ts +88 -101
- package/src/messageOperations/FailedSendCache.ts +85 -0
- package/src/messageOperations/MessageOperationStatePolicy.ts +121 -112
- package/src/messageOperations/MessageOperations.ts +297 -175
- package/src/{entityStore → messageOperations}/applyReactionLocally.ts +9 -28
- package/src/messageOperations/createMessageOperations.ts +176 -0
- package/src/messageOperations/index.ts +6 -14
- package/src/messageOperations/reflectReactionEvent.ts +43 -0
- package/src/messageOperations/sendOrdering.ts +25 -0
- package/src/messageOperations/settlePendingAttachmentUploads.ts +98 -0
- package/src/messageOperations/types.ts +51 -13
- package/src/middleware.ts +13 -5
- package/src/moderation.ts +25 -21
- package/src/notifications/NotificationManager.ts +19 -28
- package/src/notifications/types.ts +21 -57
- package/src/offline-support/offline_support_api.ts +226 -669
- package/src/offline-support/offline_sync_manager.ts +51 -80
- package/src/offline-support/queueableOperations.ts +98 -73
- package/src/offline-support/types.ts +43 -186
- package/src/pagination/FilterBuilder.ts +1 -22
- package/src/pagination/ItemIndex.ts +4 -12
- package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +15 -63
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +53 -33
- package/src/pagination/filterCompiler.ts +11 -25
- package/src/pagination/index.ts +1 -0
- package/src/pagination/paginators/BasePaginator.ts +1415 -1041
- package/src/pagination/paginators/ChannelPaginator.ts +479 -217
- package/src/pagination/paginators/MessageIntervalPaginator.ts +1351 -772
- package/src/pagination/paginators/MessagePaginator.ts +513 -233
- package/src/pagination/paginators/PinnedMessagePaginator.ts +32 -40
- package/src/pagination/paginators/ReminderPaginator.ts +21 -16
- package/src/pagination/paginators/ThreadPaginator.ts +170 -0
- package/src/pagination/paginators/UserGroupPaginator.ts +16 -19
- package/src/pagination/paginators/index.ts +1 -0
- 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 +177 -98
- package/src/poll_manager.ts +24 -22
- package/src/poll_optimistic_votes.ts +335 -0
- package/src/reminders/Reminder.ts +16 -12
- package/src/reminders/ReminderManager.ts +22 -55
- package/src/reminders/ReminderTimer.ts +1 -2
- package/src/search/BaseSearchSource.ts +19 -25
- package/src/search/ChannelSearchSource.ts +43 -1
- package/src/search/MessageSearchSource.ts +77 -13
- package/src/search/SearchController.ts +39 -36
- package/src/search/types.ts +6 -10
- package/src/segment.ts +1 -1
- package/src/signing.ts +23 -3
- package/src/thread.ts +418 -703
- package/src/thread_manager.ts +300 -234
- package/src/token_manager.ts +12 -22
- package/src/types.ts +102 -216
- package/src/types.utility.ts +3 -3
- package/src/upload-utils.ts +5 -10
- package/src/uploadManager.ts +64 -18
- package/src/utils/FixedSizeQueueCache.ts +18 -21
- package/src/utils/WithSubscriptions.ts +6 -16
- package/src/utils/abort.ts +45 -0
- 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 +40 -60
- package/src/utils.ts +181 -174
- package/codegen/i18n/callSites.ts +0 -126
- package/codegen/i18n/generate.ts +0 -226
- package/codegen/i18n/guards.ts +0 -178
- package/codegen/i18n/index.ts +0 -29
- package/codegen/i18n/stringMaps.ts +0 -91
- package/codegen/i18n/types.ts +0 -100
- package/dist/cjs/i18n.browser.js +0 -1131
- package/dist/cjs/i18n.browser.js.map +0 -7
- package/dist/cjs/i18n.node.js +0 -1160
- package/dist/cjs/i18n.node.js.map +0 -7
- package/dist/esm/i18n-codegen.mjs +0 -409
- package/dist/esm/i18n-codegen.mjs.map +0 -7
- package/dist/esm/i18n.mjs +0 -1098
- package/dist/esm/i18n.mjs.map +0 -7
- package/dist/types/ConnectionRecoveryManager.d.ts +0 -156
- package/dist/types/connection.d.ts +0 -139
- package/dist/types/entityStore/applyReactionLocally.d.ts +0 -32
- package/dist/types/i18n/Streami18n.d.ts +0 -168
- package/dist/types/i18n/TranslationBuilder.d.ts +0 -70
- package/dist/types/i18n/TranslationStore.d.ts +0 -57
- package/dist/types/i18n/dayjs.d.ts +0 -104
- package/dist/types/i18n/formatters.d.ts +0 -91
- package/dist/types/i18n/index.d.ts +0 -15
- package/dist/types/i18n/translator.d.ts +0 -29
- package/dist/types/i18n/types.d.ts +0 -262
- package/dist/types/i18n-codegen/callSites.d.ts +0 -10
- package/dist/types/i18n-codegen/generate.d.ts +0 -15
- package/dist/types/i18n-codegen/guards.d.ts +0 -61
- package/dist/types/i18n-codegen/index.d.ts +0 -29
- package/dist/types/i18n-codegen/stringMaps.d.ts +0 -14
- package/dist/types/i18n-codegen/types.d.ts +0 -94
- package/dist/types/insights.d.ts +0 -56
- package/dist/types/messageOperations/optimistic.d.ts +0 -118
- package/dist/types/messageOperations/persistence.d.ts +0 -21
- package/dist/types/pagination/utility.queryChannel.d.ts +0 -26
- package/dist/types/store.d.ts +0 -125
- package/src/ConnectionRecoveryManager.ts +0 -293
- package/src/i18n/Streami18n.ts +0 -520
- package/src/i18n/TranslationBuilder.ts +0 -176
- package/src/i18n/TranslationStore.ts +0 -96
- package/src/i18n/dayjs.ts +0 -228
- package/src/i18n/formatters.ts +0 -461
- package/src/i18n/index.ts +0 -15
- package/src/i18n/languageNames.ts +0 -103
- package/src/i18n/translator.ts +0 -76
- package/src/i18n/types.ts +0 -375
- package/src/insights.ts +0 -82
- package/src/messageOperations/optimistic.ts +0 -257
- package/src/messageOperations/persistence.ts +0 -40
- package/src/pagination/utility.queryChannel.ts +0 -84
- package/src/store.ts +0 -304
|
@@ -2,13 +2,12 @@ import type { Event, EventPayload, LocalMessage } from '../types';
|
|
|
2
2
|
import type { ExecuteBatchDBQueriesType, OfflineDBApi, OfflineDBState, PendingTask, PrepareBatchDBQueries } from './types';
|
|
3
3
|
import type { StreamChat } from '../client';
|
|
4
4
|
import { OfflineDBSyncManager } from './offline_sync_manager';
|
|
5
|
-
import { StateStore } from '
|
|
5
|
+
import { StateStore } from '@stream-io/state-store';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* offline data.
|
|
7
|
+
* Base class for an offline DB. A subclass provides the storage by implementing the abstract
|
|
8
|
+
* {@link OfflineDBApi} members; the event handlers, channel guards and pending-task queue are built
|
|
9
|
+
* on them. A handler takes `execute`, which defaults to `true`: with `false` it returns its
|
|
10
|
+
* queries unexecuted, for one `executeSqlBatch`.
|
|
12
11
|
*
|
|
13
12
|
* @abstract
|
|
14
13
|
*/
|
|
@@ -18,423 +17,123 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
|
|
|
18
17
|
state: StateStore<OfflineDBState>;
|
|
19
18
|
constructor({ client, syncMaxEventCount, }: {
|
|
20
19
|
client: StreamChat;
|
|
21
|
-
/**
|
|
22
|
-
* Optional positive cap forwarded to the {@link OfflineDBSyncManager}, which
|
|
23
|
-
* owns sync. `undefined` or any non-positive value means "no limit". See
|
|
24
|
-
* {@link OfflineDBSyncManager.syncMaxEventCount}.
|
|
25
|
-
*/
|
|
20
|
+
/** Forwarded to {@link OfflineDBSyncManager.syncMaxEventCount}. */
|
|
26
21
|
syncMaxEventCount?: number;
|
|
27
22
|
});
|
|
28
|
-
/**
|
|
29
|
-
* Inserts a reaction into the DB.
|
|
30
|
-
* Will write to:
|
|
31
|
-
* - The reactions table with the new reaction
|
|
32
|
-
* - The message table with the message containing the new reaction
|
|
33
|
-
* - The users table with any users associated
|
|
34
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
35
|
-
* already executed).
|
|
36
|
-
*
|
|
37
|
-
* @param {DBInsertReactionType} options
|
|
38
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
39
|
-
*/
|
|
23
|
+
/** Writes the reaction, the message carrying it and the associated users. */
|
|
40
24
|
abstract insertReaction: OfflineDBApi['insertReaction'];
|
|
41
|
-
/**
|
|
42
|
-
* Upserts the list of CIDs for a filter + sort query hash.
|
|
43
|
-
* Will write to only the table containing the cids.
|
|
44
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
45
|
-
* already executed).
|
|
46
|
-
*
|
|
47
|
-
* @param {DBUpsertCidsForQueryType} options
|
|
48
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
49
|
-
*/
|
|
25
|
+
/** Upserts the CIDs for a filter + sort query hash (cids table only). */
|
|
50
26
|
abstract upsertCidsForQuery: OfflineDBApi['upsertCidsForQuery'];
|
|
51
27
|
/**
|
|
52
|
-
* Upserts the channels
|
|
53
|
-
*
|
|
54
|
-
* tables.
|
|
55
|
-
* Will write to:
|
|
56
|
-
* - The channels table with the channel data
|
|
57
|
-
* - The messages table with each message associated
|
|
58
|
-
* - The reactions table if the messages contain reactions
|
|
59
|
-
* - The users table with all users associated
|
|
60
|
-
* - The members table for membership and members
|
|
61
|
-
* - The polls table for any messages that are polls
|
|
62
|
-
* - The reads table for each user
|
|
63
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
64
|
-
* already executed).
|
|
65
|
-
*
|
|
66
|
-
* @param {DBUpsertChannelsType} options
|
|
67
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
28
|
+
* Upserts the channels and their messages, reactions, users, members, polls (for poll messages)
|
|
29
|
+
* and reads, each kind into its own table.
|
|
68
30
|
*/
|
|
69
31
|
abstract upsertChannels: OfflineDBApi['upsertChannels'];
|
|
70
|
-
/**
|
|
71
|
-
* Upserts the current active user's sync status.
|
|
72
|
-
* Will only write to the sync status table.
|
|
73
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
74
|
-
* already executed).
|
|
75
|
-
*
|
|
76
|
-
* @param {DBUpsertUserSyncStatusType} options
|
|
77
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
78
|
-
*/
|
|
32
|
+
/** Upserts the current user's sync status (sync status table only). */
|
|
79
33
|
abstract upsertUserSyncStatus: OfflineDBApi['upsertUserSyncStatus'];
|
|
80
|
-
/**
|
|
81
|
-
* Upserts the app settings for the current Stream App into the DB. It
|
|
82
|
-
* is only intended to be run once per lifecycle of the app.
|
|
83
|
-
* Will only write to the respective app settings table.
|
|
84
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
85
|
-
* already executed).
|
|
86
|
-
*
|
|
87
|
-
* @param {DBUpsertAppSettingsType} options
|
|
88
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
89
|
-
*/
|
|
34
|
+
/** Upserts the app settings (app settings table only). Meant to run once per app lifecycle. */
|
|
90
35
|
abstract upsertAppSettings: OfflineDBApi['upsertAppSettings'];
|
|
91
|
-
/**
|
|
92
|
-
* Upserts a poll fully in the DB.
|
|
93
|
-
* Will write to the polls table. It should not update the message
|
|
94
|
-
* associated due to how the poll state works.
|
|
95
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
96
|
-
* already executed).
|
|
97
|
-
*
|
|
98
|
-
* @param {DBUpsertPollType} options
|
|
99
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
100
|
-
*/
|
|
36
|
+
/** Upserts a poll (polls table only). It does not update the poll's message. */
|
|
101
37
|
abstract upsertPoll: OfflineDBApi['upsertPoll'];
|
|
102
|
-
/**
|
|
103
|
-
* Upserts only the channel.data for the provided channels in the DB.
|
|
104
|
-
* Will only write to the channels table.
|
|
105
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
106
|
-
* already executed).
|
|
107
|
-
*
|
|
108
|
-
* @param {DBUpsertChannelDataType} options
|
|
109
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
110
|
-
*/
|
|
38
|
+
/** Upserts only `channel.data` (channels table only). */
|
|
111
39
|
abstract upsertChannelData: OfflineDBApi['upsertChannelData'];
|
|
112
|
-
/**
|
|
113
|
-
* Upserts the provided reads in the DB.
|
|
114
|
-
* Will write to:
|
|
115
|
-
* - The reads table
|
|
116
|
-
* - The users table for each user associated with a read
|
|
117
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
118
|
-
* already executed).
|
|
119
|
-
*
|
|
120
|
-
* @param {DBUpsertReadsType} options
|
|
121
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
122
|
-
*/
|
|
40
|
+
/** Upserts the reads and the users they reference. */
|
|
123
41
|
abstract upsertReads: OfflineDBApi['upsertReads'];
|
|
124
|
-
/**
|
|
125
|
-
* Upserts the messages in the DB.
|
|
126
|
-
* Will write to:
|
|
127
|
-
* - The messages table
|
|
128
|
-
* - The reads table
|
|
129
|
-
* - The polls table (if any messages contain polls)
|
|
130
|
-
* - The reactions table (if any messages contain reactions)
|
|
131
|
-
* - The users table
|
|
132
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
133
|
-
* already executed).
|
|
134
|
-
*
|
|
135
|
-
* @param {DBUpsertMessagesType} options
|
|
136
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
137
|
-
*/
|
|
42
|
+
/** Upserts the messages with their reads, polls, reactions and users. */
|
|
138
43
|
abstract upsertMessages: OfflineDBApi['upsertMessages'];
|
|
139
|
-
/**
|
|
140
|
-
* Upserts the members in the DB.
|
|
141
|
-
* Will write to:
|
|
142
|
-
* - The users table (for each user associated with a member)
|
|
143
|
-
* - The members table
|
|
144
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
145
|
-
* already executed).
|
|
146
|
-
*
|
|
147
|
-
* @param {DBUpsertMembersType} options
|
|
148
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
149
|
-
*/
|
|
44
|
+
/** Upserts the members and their users. */
|
|
150
45
|
abstract upsertMembers: OfflineDBApi['upsertMembers'];
|
|
151
46
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* Will write to the reactions table.
|
|
156
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
157
|
-
* already executed).
|
|
158
|
-
*
|
|
159
|
-
* @param {DBUpdateReactionType} options
|
|
160
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
47
|
+
* Applies a reaction as a `reaction.updated` event would: it assumes `enforce_unique` and
|
|
48
|
+
* replaces the user's other reactions. Also writes the reacting user and the message's reaction
|
|
49
|
+
* groups.
|
|
161
50
|
*/
|
|
162
51
|
abstract updateReaction: OfflineDBApi['updateReaction'];
|
|
163
|
-
/**
|
|
164
|
-
* Updates a single message in the DB. This is used as a faster
|
|
165
|
-
* alternative to upsertMessages with more optimized queries.
|
|
166
|
-
* Will write to the messages table.
|
|
167
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
168
|
-
* already executed).
|
|
169
|
-
*
|
|
170
|
-
* @param {DBUpdateMessageType} options
|
|
171
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
172
|
-
*/
|
|
52
|
+
/** Updates a single message (messages table only) with leaner queries than `upsertMessages`. */
|
|
173
53
|
abstract updateMessage: OfflineDBApi['updateMessage'];
|
|
174
|
-
/**
|
|
175
|
-
* Fetches the provided draft from the DB. Should return as close to
|
|
176
|
-
* the server side DraftResponse as possible.
|
|
177
|
-
*
|
|
178
|
-
* @param {DBGetDraftType} options
|
|
179
|
-
* @returns {Promise<DraftResponse | null>}
|
|
180
|
-
*/
|
|
54
|
+
/** Returns the draft as close to the server's `DraftResponse` as possible. */
|
|
181
55
|
abstract getDraft: OfflineDBApi['getDraft'];
|
|
182
|
-
/**
|
|
183
|
-
* Upserts a draft in the DB.
|
|
184
|
-
* Will write to the draft table upserting the draft.
|
|
185
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
186
|
-
* already executed).
|
|
187
|
-
*
|
|
188
|
-
* @param {DBUpsertDraftType} options
|
|
189
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
190
|
-
*/
|
|
56
|
+
/** Upserts a draft (drafts table only). */
|
|
191
57
|
abstract upsertDraft: OfflineDBApi['upsertDraft'];
|
|
192
|
-
/**
|
|
193
|
-
* Deletes a draft from the DB.
|
|
194
|
-
* Will write to the draft table removing the draft.
|
|
195
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
196
|
-
* already executed).
|
|
197
|
-
*
|
|
198
|
-
* @param {DBDeleteDraftType} options
|
|
199
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
200
|
-
*/
|
|
58
|
+
/** Deletes a draft (drafts table only). */
|
|
201
59
|
abstract deleteDraft: OfflineDBApi['deleteDraft'];
|
|
202
60
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* for aggregating and serialization of all of the data. Should return as close to
|
|
206
|
-
* the server side ChannelStateResponseFields as possible.
|
|
207
|
-
*
|
|
208
|
-
* @param {DBGetChannelsType} options
|
|
209
|
-
* @returns {Promise<Omit<ChannelStateResponseFields, 'duration'>[] | null>}
|
|
61
|
+
* Returns each channel with all its stored data aggregated, as close to the server's
|
|
62
|
+
* `ChannelStateResponseFields` as possible. The implementation does the aggregation.
|
|
210
63
|
*/
|
|
211
64
|
abstract getChannels: OfflineDBApi['getChannels'];
|
|
212
65
|
/**
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* The implementation itself is responsible for aggregating and serialization of all of the data.
|
|
216
|
-
* Should return as close to the server side ChannelStateResponseFields as possible.
|
|
217
|
-
*
|
|
218
|
-
* @param {DBGetChannelsForQueryType} options
|
|
219
|
-
* @returns {Promise<Omit<ChannelStateResponseFields, 'duration'>[] | null>}
|
|
66
|
+
* The channels last cached for a filters + sort hash, in query order, with the predefined filter
|
|
67
|
+
* that produced them. Channels are aggregated as in `getChannels`.
|
|
220
68
|
*/
|
|
221
69
|
abstract getChannelsForQuery: OfflineDBApi['getChannelsForQuery'];
|
|
222
|
-
/**
|
|
223
|
-
* Will return a list of all available CIDs in the DB. The same can be achieved
|
|
224
|
-
* by fetching all channels, however this is meant to be much faster as a query.
|
|
225
|
-
*
|
|
226
|
-
* @returns {Promise<string[]>}
|
|
227
|
-
*/
|
|
70
|
+
/** All CIDs in the DB. Much cheaper than fetching all channels. */
|
|
228
71
|
abstract getAllChannelCids: OfflineDBApi['getAllChannelCids'];
|
|
229
|
-
/**
|
|
230
|
-
* Fetches the timestamp of the last sync of the DB.
|
|
231
|
-
*
|
|
232
|
-
* @param {DBGetLastSyncedAtType} options
|
|
233
|
-
* @returns {Promise<string | undefined>}
|
|
234
|
-
*/
|
|
235
72
|
abstract getLastSyncedAt: OfflineDBApi['getLastSyncedAt'];
|
|
236
|
-
/**
|
|
237
|
-
* Fetches all pending tasks from the DB. It will return them in an
|
|
238
|
-
* ordered fashion by the time they were created.
|
|
239
|
-
*
|
|
240
|
-
* @param {DBGetPendingTasksType} [conditions]
|
|
241
|
-
* @returns {Promise<PendingTask[]>}
|
|
242
|
-
*/
|
|
73
|
+
/** Pending tasks ordered by creation time, optionally only one message's. */
|
|
243
74
|
abstract getPendingTasks: OfflineDBApi['getPendingTasks'];
|
|
244
|
-
/**
|
|
245
|
-
* Fetches the app settings stored in the DB. Is mainly meant to be used
|
|
246
|
-
* only while offline and opening the application, as we only update the
|
|
247
|
-
* app settings whenever they are fetched again so it has the potential to
|
|
248
|
-
* be stale.
|
|
249
|
-
*
|
|
250
|
-
* @param {DBGetAppSettingsType} options
|
|
251
|
-
* @returns {Promise<GetApplicationResponse | null>}
|
|
252
|
-
*/
|
|
75
|
+
/** The stored app settings. They only refresh when fetched again, so they can be stale. */
|
|
253
76
|
abstract getAppSettings: OfflineDBApi['getAppSettings'];
|
|
254
|
-
/**
|
|
255
|
-
* Fetches reactions from the DB for a given filter & sort hash and
|
|
256
|
-
* for a given message ID.
|
|
257
|
-
*
|
|
258
|
-
* @param {DBGetReactionsType} options
|
|
259
|
-
* @returns {Promise<ReactionResponse[] | null>}
|
|
260
|
-
*/
|
|
261
77
|
abstract getReactions: OfflineDBApi['getReactions'];
|
|
262
|
-
/**
|
|
263
|
-
* Executes multiple queries in a batched fashion. It will also be done
|
|
264
|
-
* within a transaction.
|
|
265
|
-
*
|
|
266
|
-
* @param {ExecuteBatchDBQueriesType} queries
|
|
267
|
-
* @returns {Promise<unknown>}
|
|
268
|
-
*/
|
|
78
|
+
/** Runs the queries in one transaction. */
|
|
269
79
|
abstract executeSqlBatch: OfflineDBApi['executeSqlBatch'];
|
|
270
|
-
/**
|
|
271
|
-
* Adds a pending task to the pending tasks table. Can only be one of the
|
|
272
|
-
* supported types of pending tasks, otherwise its execution will throw.
|
|
273
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
274
|
-
* already executed).
|
|
275
|
-
*
|
|
276
|
-
* @param {PendingTask} task
|
|
277
|
-
* @returns {Promise<() => Promise<void>>}
|
|
278
|
-
*/
|
|
80
|
+
/** Adds a pending task. Executing a task of an unsupported type throws. */
|
|
279
81
|
abstract addPendingTask: OfflineDBApi['addPendingTask'];
|
|
280
|
-
/**
|
|
281
|
-
* Updates a pending task in the DB, given its ID.
|
|
282
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
283
|
-
* already executed).
|
|
284
|
-
*
|
|
285
|
-
* @param {DBUpdatePendingTaskType} options
|
|
286
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
287
|
-
*/
|
|
288
82
|
abstract updatePendingTask: OfflineDBApi['updatePendingTask'];
|
|
289
|
-
/**
|
|
290
|
-
* Deletes a pending task from the DB, given its ID.
|
|
291
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
292
|
-
* already executed).
|
|
293
|
-
*
|
|
294
|
-
* @param {DBDeletePendingTaskType} options
|
|
295
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
296
|
-
*/
|
|
297
83
|
abstract deletePendingTask: OfflineDBApi['deletePendingTask'];
|
|
298
|
-
/**
|
|
299
|
-
* Deletes a reaction from the DB.
|
|
300
|
-
* Will write to the reactions table removing the reaction.
|
|
301
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
302
|
-
* already executed).
|
|
303
|
-
*
|
|
304
|
-
* @param {DBDeleteReactionType} options
|
|
305
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
306
|
-
*/
|
|
307
84
|
abstract deleteReaction: OfflineDBApi['deleteReaction'];
|
|
308
|
-
/**
|
|
309
|
-
* Deletes a member from the DB.
|
|
310
|
-
* Will only write to the members table.
|
|
311
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
312
|
-
* already executed).
|
|
313
|
-
*
|
|
314
|
-
* @param {DBDeleteMemberType} options
|
|
315
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
316
|
-
*/
|
|
317
85
|
abstract deleteMember: OfflineDBApi['deleteMember'];
|
|
318
|
-
/**
|
|
319
|
-
* Deletes a channel from the DB.
|
|
320
|
-
* It will also delete all other entities associated with the channel in
|
|
321
|
-
* a cascading fashion (messages, reactions, members etc.).
|
|
322
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
323
|
-
* already executed).
|
|
324
|
-
*
|
|
325
|
-
* @param {DBDeleteChannelType} options
|
|
326
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
327
|
-
*/
|
|
86
|
+
/** Deletes the channel and everything associated with it (messages, reactions, members, ...). */
|
|
328
87
|
abstract deleteChannel: OfflineDBApi['deleteChannel'];
|
|
329
|
-
/**
|
|
330
|
-
* Deletes multiple messages for a given channel. Works as `channel.truncated` would.
|
|
331
|
-
* Should remove entities primarily from the messages table and then from all associated
|
|
332
|
-
* tables in a cascading fashion (reactions, polls etc.).
|
|
333
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
334
|
-
* already executed).
|
|
335
|
-
*
|
|
336
|
-
* @param {DBDeleteMessagesForChannelType} options
|
|
337
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
338
|
-
*/
|
|
88
|
+
/** Deletes a channel's messages as `channel.truncated` would, cascading to their reactions. */
|
|
339
89
|
abstract deleteMessagesForChannel: OfflineDBApi['deleteMessagesForChannel'];
|
|
340
|
-
/**
|
|
341
|
-
* Deletes all pending tasks from the DB.
|
|
342
|
-
* Will only update the pending tasks table.
|
|
343
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
344
|
-
* already executed).
|
|
345
|
-
*
|
|
346
|
-
* @param {DBDropPendingTasksType} options
|
|
347
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
348
|
-
*/
|
|
90
|
+
/** Deletes all pending tasks of a message (pending tasks table only). */
|
|
349
91
|
abstract dropPendingTasks: OfflineDBApi['dropPendingTasks'];
|
|
350
|
-
/**
|
|
351
|
-
* Deletes a message from the DB.
|
|
352
|
-
* All other entities associated with the message will also be deleted
|
|
353
|
-
* in a cascading fashion (reactions, polls etc.).
|
|
354
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
355
|
-
* already executed).
|
|
356
|
-
*
|
|
357
|
-
* @param {DBDeleteMessageType} options
|
|
358
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
359
|
-
*/
|
|
92
|
+
/** Deletes the message and cascades to its reactions, polls, etc. */
|
|
360
93
|
abstract hardDeleteMessage: OfflineDBApi['hardDeleteMessage'];
|
|
361
|
-
/**
|
|
362
|
-
* Updates a message with a deleted_at value in the DB.
|
|
363
|
-
* Will only update the messages table, as the message is simply marked
|
|
364
|
-
* as deleted and not removed from the DB.
|
|
365
|
-
* Will return the prepared queries for delayed execution (even if they are
|
|
366
|
-
* already executed).
|
|
367
|
-
*
|
|
368
|
-
* @param {DBDeleteMessageType} options
|
|
369
|
-
* @returns {Promise<ExecuteBatchDBQueriesType>}
|
|
370
|
-
*/
|
|
94
|
+
/** Sets `deleted_at` on the message (messages table only) instead of removing it. */
|
|
371
95
|
abstract softDeleteMessage: OfflineDBApi['softDeleteMessage'];
|
|
372
|
-
/**
|
|
373
|
-
* Drops all tables and reinitializes the connection to the DB.
|
|
374
|
-
*
|
|
375
|
-
* @returns {Promise<unknown>}
|
|
376
|
-
*/
|
|
96
|
+
/** Drops all tables and reinitializes the DB connection. */
|
|
377
97
|
abstract resetDB: OfflineDBApi['resetDB'];
|
|
378
|
-
/**
|
|
379
|
-
* A utility query that checks whether a specific channel exists in the DB.
|
|
380
|
-
* Technically the same as actually fetching that channel through other queries,
|
|
381
|
-
* but much faster.
|
|
382
|
-
*
|
|
383
|
-
* @param {DBChannelExistsType} options
|
|
384
|
-
* @returns {Promise<boolean>}
|
|
385
|
-
*/
|
|
98
|
+
/** Whether the channel is in the DB. Much cheaper than fetching it. */
|
|
386
99
|
abstract channelExists: OfflineDBApi['channelExists'];
|
|
387
|
-
/**
|
|
388
|
-
* Initializes the DB (typically creating a simple file handle as a connection pointer for
|
|
389
|
-
* SQLite and likely similar for other DBs).
|
|
390
|
-
*
|
|
391
|
-
* @returns {Promise<boolean>}
|
|
392
|
-
*/
|
|
100
|
+
/** Opens the DB connection (for SQLite, typically a file handle). */
|
|
393
101
|
abstract initializeDB: OfflineDBApi['initializeDB'];
|
|
394
102
|
/**
|
|
395
|
-
* Initializes the DB
|
|
396
|
-
* It will update the DBs reactive state with initialization values.
|
|
103
|
+
* Initializes the DB and its sync manager for a user, and updates `state`.
|
|
397
104
|
*
|
|
398
|
-
* @param userId -
|
|
105
|
+
* @param userId - The user ID for which we want to initialize.
|
|
399
106
|
*/
|
|
400
107
|
init: (userId: string) => Promise<void>;
|
|
401
108
|
/**
|
|
402
|
-
* Checks whether the DB
|
|
109
|
+
* Checks whether the DB is already initialized for a user.
|
|
403
110
|
*
|
|
404
|
-
* @param userId -
|
|
111
|
+
* @param userId - The user ID for which we want to check initialization.
|
|
112
|
+
* @returns Whether the DB is initialized for `userId`.
|
|
405
113
|
*/
|
|
406
114
|
shouldInitialize(userId: string): boolean;
|
|
407
115
|
/**
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
* and silently. Only really meant to be used for write queries that need to
|
|
411
|
-
* be run in synchronous functions.
|
|
116
|
+
* Runs a write query detached, for synchronous callers. A failure is logged, not thrown. No-op
|
|
117
|
+
* until the DB is initialized.
|
|
412
118
|
*
|
|
413
|
-
* @param queryCallback -
|
|
414
|
-
* @param method -
|
|
415
|
-
* is logged on failure)
|
|
119
|
+
* @param queryCallback - A callback wrapping all query logic that is to be executed.
|
|
120
|
+
* @param options.method - The method name logged on failure.
|
|
416
121
|
*/
|
|
417
122
|
executeQuerySafely: <T>(queryCallback: (db: AbstractOfflineDB) => Promise<T>, { method }: {
|
|
418
123
|
method: string;
|
|
419
124
|
}) => void;
|
|
420
125
|
/**
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
126
|
+
* Runs `createQueries` so they cannot fail on the channel's foreign key. When the channel is
|
|
127
|
+
* not in the DB it is upserted first, from the event's channel or else the one in state. If
|
|
128
|
+
* neither exists the queries are dropped.
|
|
424
129
|
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
* @param event - The WS event we are trying to process.
|
|
434
|
-
* @param event.execute - Whether to immediately execute the operation (optional, defaults to `true`).
|
|
435
|
-
* @param event.forceUpdate - Whether to upsert the channel data anyway (optional, defaults to `false`).
|
|
436
|
-
* @param createQueries - A callback that creates the queries to execute.
|
|
437
|
-
* @returns The list of prepared queries (executed when `execute` is `true`).
|
|
130
|
+
* @param options.event - The WS event we are trying to process.
|
|
131
|
+
* @param options.execute - Whether to immediately execute the queries. Defaults to `true`.
|
|
132
|
+
* @param options.forceUpdate - Whether to upsert the channel data even when it is stored.
|
|
133
|
+
* Defaults to `false`.
|
|
134
|
+
* @param createQueries - Builds the queries. It receives the effective `execute` flag and must run
|
|
135
|
+
* its queries when that is `true`, because the fast path relies on that write throwing.
|
|
136
|
+
* @returns The prepared queries.
|
|
438
137
|
*/
|
|
439
138
|
queriesWithChannelGuard: ({ event, execute, forceUpdate, }: {
|
|
440
139
|
event: Extract<Event, {
|
|
@@ -447,115 +146,90 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
|
|
|
447
146
|
forceUpdate?: boolean;
|
|
448
147
|
}, createQueries: (executeOverride?: boolean) => Promise<PrepareBatchDBQueries[]>) => Promise<PrepareBatchDBQueries[]>;
|
|
449
148
|
/**
|
|
450
|
-
* Prepends the channel row to `createQueries`' output
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
* Skips the write entirely when neither can supply it: without a channel row the queries would fail
|
|
454
|
-
* anyway, and dropping the event is what the caller expects.
|
|
149
|
+
* Prepends the channel row to `createQueries`' output, sourced from the event or else the
|
|
150
|
+
* in-memory channel. Returns no queries when neither can supply it.
|
|
455
151
|
*/
|
|
456
152
|
private queriesBehindChannelGuard;
|
|
457
153
|
/**
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
* the number of unreads.
|
|
154
|
+
* Upserts the message and, when another user sent it, the current user's read (from
|
|
155
|
+
* `channel.state`). The channel guard upserts a missing channel row only with `execute: false`;
|
|
156
|
+
* with `execute: true` (the default) the row is not guarded.
|
|
462
157
|
*
|
|
463
|
-
* @param payload.event -
|
|
464
|
-
* @param payload.execute - Whether to immediately execute the
|
|
158
|
+
* @param payload.event - The WS event we are trying to process.
|
|
159
|
+
* @param payload.execute - Whether to immediately execute the queries. Defaults to `true`.
|
|
160
|
+
* @returns The prepared queries.
|
|
465
161
|
*/
|
|
466
162
|
handleNewMessage: ({ event, execute, }: {
|
|
467
163
|
event: EventPayload<"message.new">;
|
|
468
164
|
execute?: boolean;
|
|
469
165
|
}) => Promise<PrepareBatchDBQueries[]>;
|
|
470
166
|
/**
|
|
471
|
-
*
|
|
472
|
-
* it should hard delete or soft delete the message.
|
|
167
|
+
* Hard or soft deletes the message, depending on `event.hard_delete`.
|
|
473
168
|
*
|
|
474
|
-
* @param payload.event -
|
|
475
|
-
* @param payload.execute - Whether to immediately execute the
|
|
169
|
+
* @param payload.event - The WS event we are trying to process.
|
|
170
|
+
* @param payload.execute - Whether to immediately execute the queries. Defaults to `true`.
|
|
171
|
+
* @returns The prepared queries.
|
|
476
172
|
*/
|
|
477
173
|
handleDeleteMessage: ({ event, execute, }: {
|
|
478
174
|
event: EventPayload<"message.deleted">;
|
|
479
175
|
execute?: boolean;
|
|
480
176
|
}) => Promise<PrepareBatchDBQueries[]>;
|
|
481
177
|
/**
|
|
482
|
-
*
|
|
483
|
-
* state as well as the DB. We want to drop all pending tasks and finally hard
|
|
484
|
-
* delete the message from the DB.
|
|
178
|
+
* Drops the message's pending tasks and hard deletes it.
|
|
485
179
|
*
|
|
486
180
|
* @param payload.messageId - The ID of the message we want to remove.
|
|
487
|
-
* @param payload.execute - Whether to immediately execute the
|
|
181
|
+
* @param payload.execute - Whether to immediately execute the queries. Defaults to `true`.
|
|
182
|
+
* @returns The prepared queries.
|
|
488
183
|
*/
|
|
489
184
|
handleRemoveMessage: ({ messageId, execute, }: {
|
|
490
185
|
messageId: string;
|
|
491
186
|
execute?: boolean;
|
|
492
187
|
}) => Promise<PrepareBatchDBQueries[]>;
|
|
493
188
|
/**
|
|
494
|
-
* Hard
|
|
495
|
-
* {@link hardDeleteMessage} calls: collects each delete's queries (`execute: false`) and runs them
|
|
496
|
-
* as one batch. Used e.g. by destructive reconciliation on reconnect to mirror a set of in-memory
|
|
497
|
-
* removals into the DB. No-op for an empty set.
|
|
189
|
+
* Hard deletes the messages in one transaction.
|
|
498
190
|
*
|
|
499
|
-
* @param payload.ids - The
|
|
500
|
-
* @param payload.execute - Whether to immediately execute the
|
|
191
|
+
* @param payload.ids - The IDs of the messages to hard delete.
|
|
192
|
+
* @param payload.execute - Whether to immediately execute the queries. Defaults to `true`.
|
|
193
|
+
* @returns The prepared queries.
|
|
501
194
|
*/
|
|
502
195
|
hardDeleteMessages: ({ ids, execute, }: {
|
|
503
196
|
ids: string[];
|
|
504
197
|
execute?: boolean;
|
|
505
198
|
}) => Promise<PrepareBatchDBQueries[]>;
|
|
506
199
|
/**
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
* {@link upsertMessages}, so every implementation inherits it and no custom offline DB has to
|
|
512
|
-
* implement anything new (same reasoning as {@link hardDeleteMessages}).
|
|
200
|
+
* Upserts a message and writes its channel row when that row is missing (the first optimistic
|
|
201
|
+
* write in a new channel can precede the channel's persistence). Upserts because an UPDATE no-ops
|
|
202
|
+
* on a missing row. When the row is missing and the channel is not loaded in memory, or the
|
|
203
|
+
* message has no `cid`, nothing is written.
|
|
513
204
|
*
|
|
514
|
-
*
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
* UPDATE — it no-ops when the row does not exist yet, which is exactly the write-ahead case.
|
|
518
|
-
*
|
|
519
|
-
* @param payload.message - The message to persist. Its `cid` decides which channel row is guarded.
|
|
520
|
-
* @param payload.execute - Whether to immediately execute the operation (optional, defaults to `true`).
|
|
205
|
+
* @param payload.message - The message to persist. Its `cid` decides the guarded channel row.
|
|
206
|
+
* @param payload.execute - Whether to immediately execute the queries. Defaults to `true`.
|
|
207
|
+
* @returns The prepared queries.
|
|
521
208
|
*/
|
|
522
209
|
upsertMessageWithChannelGuard: ({ message, execute, }: {
|
|
523
210
|
message: LocalMessage;
|
|
524
211
|
execute?: boolean;
|
|
525
212
|
}) => Promise<ExecuteBatchDBQueriesType>;
|
|
526
|
-
/**
|
|
527
|
-
* Writes the channel row ahead of the messages so the insert cannot fail on the `cid` foreign key.
|
|
528
|
-
* Skips the write when there is nothing to build a channel row from — the message stays correct in
|
|
529
|
-
* memory either way, and an insert that cannot resolve its foreign key is not worth attempting.
|
|
530
|
-
*/
|
|
213
|
+
/** Writes the channel row ahead of the messages. Skips the write when no row can be built. */
|
|
531
214
|
private upsertMessageBehindChannelGuard;
|
|
532
215
|
/**
|
|
533
|
-
* The
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
* Concrete, composed from the existing {@link getChannels} primitive, so it adds nothing to
|
|
537
|
-
* {@link OfflineDBApi} that a custom offline DB would have to implement.
|
|
538
|
-
*
|
|
539
|
-
* This is the buffer that lets a failed message survive. v9 recovered such messages by diffing a
|
|
540
|
-
* second, lagging copy of the message list (the React SDK state) against `channel.state`; with a
|
|
541
|
-
* single reactive source of truth the persisted row is the only place that memory can be
|
|
542
|
-
* re-populated from — see `Channel.reload`.
|
|
216
|
+
* The channel's persisted messages with a local `failed` status, which `Channel.reload` and
|
|
217
|
+
* `Thread.reload` re-ingest. Built on {@link getChannels}, so a custom offline DB implements
|
|
218
|
+
* nothing extra.
|
|
543
219
|
*
|
|
544
220
|
* @param payload.cid - The channel whose failed messages to read.
|
|
221
|
+
* @returns The failed messages, formatted.
|
|
545
222
|
*/
|
|
546
223
|
getFailedMessages: ({ cid, }: {
|
|
547
224
|
cid: string;
|
|
548
225
|
}) => Promise<LocalMessage[]>;
|
|
549
226
|
/**
|
|
550
|
-
*
|
|
551
|
-
* present in the event, or optionally rely on the hard override in unreadMessages.
|
|
552
|
-
* The unreadMessages argument is useful for cases where we know the exact number of unreads
|
|
553
|
-
* (for example reading an entire channel), but `unread_messages` might not necessarily exist
|
|
554
|
-
* in the event (or it exists with a stale value if we know what we want to ultimately update to).
|
|
227
|
+
* Upserts the reads of a read event.
|
|
555
228
|
*
|
|
556
229
|
* @param payload.event - The WS event we are trying to process.
|
|
557
|
-
* @param payload.unreadMessages - An override of `unread_messages
|
|
558
|
-
* @param payload.execute - Whether to immediately execute the
|
|
230
|
+
* @param payload.unreadMessages - An override of `event.unread_messages`.
|
|
231
|
+
* @param payload.execute - Whether to immediately execute the queries. Defaults to `true`.
|
|
232
|
+
* @returns The prepared queries.
|
|
559
233
|
*/
|
|
560
234
|
handleRead: ({ event, unreadMessages, execute, }: {
|
|
561
235
|
event: EventPayload<"message.read" | "message.read_locally" | "notification.mark_read" | "notification.mark_unread">;
|
|
@@ -563,180 +237,128 @@ export declare abstract class AbstractOfflineDB implements OfflineDBApi {
|
|
|
563
237
|
execute?: boolean;
|
|
564
238
|
}) => Promise<PrepareBatchDBQueries[]>;
|
|
565
239
|
/**
|
|
566
|
-
*
|
|
567
|
-
* of each event with a channel guard and also forces an update of member_count
|
|
568
|
-
* for the respective channel if applicable.
|
|
240
|
+
* Removes or upserts the member, forcing a channel upsert so `member_count` updates.
|
|
569
241
|
*
|
|
570
|
-
* @param payload.event -
|
|
571
|
-
* @param payload.execute - Whether to immediately execute the
|
|
242
|
+
* @param payload.event - The WS event we are trying to process.
|
|
243
|
+
* @param payload.execute - Whether to immediately execute the queries. Defaults to `true`.
|
|
244
|
+
* @returns The prepared queries.
|
|
572
245
|
*/
|
|
573
246
|
handleMemberEvent: ({ event, execute, }: {
|
|
574
247
|
event: EventPayload<`member.${string}`>;
|
|
575
248
|
execute?: boolean;
|
|
576
249
|
}) => Promise<PrepareBatchDBQueries[]>;
|
|
577
250
|
/**
|
|
578
|
-
*
|
|
579
|
-
* event handler within a channel guard.
|
|
251
|
+
* Updates the message behind the channel guard. Thread replies are ignored.
|
|
580
252
|
*
|
|
581
|
-
* @param payload.event -
|
|
582
|
-
* @param payload.execute - Whether to immediately execute the
|
|
253
|
+
* @param payload.event - The WS event we are trying to process.
|
|
254
|
+
* @param payload.execute - Whether to immediately execute the queries. Defaults to `true`.
|
|
255
|
+
* @returns The prepared queries.
|
|
583
256
|
*/
|
|
584
257
|
handleMessageUpdatedEvent: ({ event, execute, }: {
|
|
585
258
|
event: EventPayload<"message.updated" | "message.undeleted">;
|
|
586
259
|
execute?: boolean;
|
|
587
260
|
}) => Promise<PrepareBatchDBQueries[]>;
|
|
588
261
|
/**
|
|
589
|
-
*
|
|
590
|
-
* handler because event.channel.hidden does not arrive with the baseline event, so a
|
|
591
|
-
* simple upsertion is not enough.
|
|
592
|
-
* It will update the hidden property of a channel to true if handling the `channel.hidden`
|
|
593
|
-
* event and to false if handling `channel.visible`.
|
|
262
|
+
* Sets `hidden` from the event type, as the event's channel does not carry it.
|
|
594
263
|
*
|
|
595
|
-
* @param payload. -
|
|
596
|
-
* @param payload.execute - Whether to immediately execute the
|
|
264
|
+
* @param payload.event - The WS event we are trying to process.
|
|
265
|
+
* @param payload.execute - Whether to immediately execute the queries. Defaults to `true`.
|
|
266
|
+
* @returns The prepared queries.
|
|
597
267
|
*/
|
|
598
268
|
handleChannelVisibilityEvent: ({ event, execute, }: {
|
|
599
269
|
event: EventPayload<"channel.visible" | "channel.hidden">;
|
|
600
270
|
execute?: boolean;
|
|
601
271
|
}) => Promise<ExecuteBatchDBQueriesType>;
|
|
602
272
|
/**
|
|
603
|
-
*
|
|
604
|
-
* removing all messages and relying on truncated_at as well. It will also upsert
|
|
605
|
-
* reads adequately (and calculate the correct unread messages when truncating).
|
|
273
|
+
* Deletes the channel's messages (before `truncated_at` when set) and upserts the reads.
|
|
606
274
|
*
|
|
607
|
-
* @param payload.event -
|
|
608
|
-
* @param payload.execute - Whether to immediately execute the
|
|
275
|
+
* @param payload.event - The WS event we are trying to process.
|
|
276
|
+
* @param payload.execute - Whether to immediately execute the queries. Defaults to `true`.
|
|
277
|
+
* @returns The prepared queries.
|
|
609
278
|
*/
|
|
610
279
|
handleChannelTruncatedEvent: ({ event, execute, }: {
|
|
611
280
|
event: EventPayload<"channel.truncated">;
|
|
612
281
|
execute?: boolean;
|
|
613
282
|
}) => Promise<PrepareBatchDBQueries[]>;
|
|
614
283
|
/**
|
|
615
|
-
*
|
|
616
|
-
* within a channel guard and maps them like so:
|
|
617
|
-
* - reaction.new -> insertReaction
|
|
618
|
-
* - reaction.updated -> updateReaction
|
|
619
|
-
* - reaction.deleted -> deleteReaction
|
|
284
|
+
* Maps `reaction.new`, `.updated` and `.deleted` to the matching reaction write.
|
|
620
285
|
*
|
|
621
|
-
* @param payload.event -
|
|
622
|
-
* @param payload.execute - Whether to immediately execute the
|
|
286
|
+
* @param payload.event - The WS event we are trying to process.
|
|
287
|
+
* @param payload.execute - Whether to immediately execute the queries. Defaults to `true`.
|
|
288
|
+
* @returns The prepared queries.
|
|
623
289
|
*/
|
|
624
290
|
handleReactionEvent: ({ event, execute, }: {
|
|
625
291
|
event: EventPayload<`reaction.${string}`>;
|
|
626
292
|
execute?: boolean;
|
|
627
293
|
}) => Promise<PrepareBatchDBQueries[]>;
|
|
628
294
|
/**
|
|
629
|
-
*
|
|
630
|
-
* - draft.updated -> updateDraft
|
|
631
|
-
* - draft.deleted -> deleteDraft
|
|
295
|
+
* Maps `draft.updated` and `draft.deleted` to `upsertDraft` and `deleteDraft`.
|
|
632
296
|
*
|
|
633
|
-
* @param payload.event -
|
|
634
|
-
* @param payload.execute - Whether to immediately execute the
|
|
297
|
+
* @param payload.event - The WS event we are trying to process.
|
|
298
|
+
* @param payload.execute - Whether to immediately execute the queries. Defaults to `true`.
|
|
299
|
+
* @returns The prepared queries.
|
|
635
300
|
*/
|
|
636
301
|
handleDraftEvent: ({ event, execute, }: {
|
|
637
302
|
event: EventPayload<`draft.${string}`>;
|
|
638
303
|
execute?: boolean;
|
|
639
304
|
}) => Promise<ExecuteBatchDBQueriesType>;
|
|
640
305
|
/**
|
|
641
|
-
*
|
|
642
|
-
* event.type for all events we are currently handling. It is used to both
|
|
643
|
-
* react on WS events as well as process the sync API events.
|
|
306
|
+
* Routes an event to its handler by type. Used for WS events and for sync events.
|
|
644
307
|
*
|
|
645
|
-
* @param payload.event -
|
|
646
|
-
* @param payload.execute - Whether to immediately execute the
|
|
308
|
+
* @param payload.event - The WS event we are trying to process.
|
|
309
|
+
* @param payload.execute - Whether to immediately execute the queries. Defaults to `true`.
|
|
310
|
+
* @returns The prepared queries.
|
|
647
311
|
*/
|
|
648
312
|
handleEvent: ({ event, execute, }: {
|
|
649
313
|
event: Event;
|
|
650
314
|
execute?: boolean;
|
|
651
315
|
}) => Promise<ExecuteBatchDBQueriesType>;
|
|
652
316
|
/**
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
* 1. Execute the task immediately
|
|
657
|
-
* 2. If this fails, checks if the failure was due to something valid for a pending task
|
|
658
|
-
* 3. If it is, it will insert the task in the pending tasks table
|
|
659
|
-
*
|
|
660
|
-
* It will return the response from the execution if it succeeded.
|
|
317
|
+
* Executes the task now. On an {@link isEphemeral} failure the task goes to
|
|
318
|
+
* `handleAddPendingTask`, and the error is rethrown. With an unhealthy socket it fails with an
|
|
319
|
+
* `OfflineError` without executing.
|
|
661
320
|
*
|
|
662
|
-
*
|
|
663
|
-
*
|
|
664
|
-
* the
|
|
321
|
+
* The payload carries the request options, including an `AbortSignal`. It is live while the task
|
|
322
|
+
* runs now, but a replay from the table gets an inert `{}` when the store serializes the payload
|
|
323
|
+
* (always across a restart), and `ApiClient` then runs the request uncancellable.
|
|
665
324
|
*
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
* - A task that reaches the pending-tasks table survives only as far as the concrete
|
|
669
|
-
* implementation's storage allows. {@link OfflineDBApi.addPendingTask} and
|
|
670
|
-
* {@link OfflineDBApi.getPendingTasks} make no serialization promise either way: a store that
|
|
671
|
-
* hands back the object it was given keeps the signal live, while one that encodes the payload
|
|
672
|
-
* (as a SQLite-backed store does) revives it as an inert `{}`. Across a process restart it is
|
|
673
|
-
* always the latter.
|
|
674
|
-
*
|
|
675
|
-
* `ApiClient` drops a signal it cannot listen to rather than handing it to axios (which would
|
|
676
|
-
* throw), so a replay that lost its signal simply runs uncancellable.
|
|
677
|
-
*
|
|
678
|
-
* Note that cancelling is not a way to drop a queued task after the fact — an aborted request is
|
|
679
|
-
* a definitive rejection ({@link isEphemeral} is `false` for it), so it is never queued in the
|
|
680
|
-
* first place.
|
|
681
|
-
*
|
|
682
|
-
* @param task - the pending task we want to execute
|
|
325
|
+
* @param payload.task - The pending task we want to execute.
|
|
326
|
+
* @returns The response of the task's request.
|
|
683
327
|
*/
|
|
684
328
|
queueTask: <T>({ task }: {
|
|
685
329
|
task: PendingTask;
|
|
686
330
|
}) => Promise<T>;
|
|
331
|
+
/** A definitive rejection (non-retryable server error or a cancelled request) is not queued. */
|
|
332
|
+
private shouldSkipQueueingTask;
|
|
333
|
+
private isPendingSendMessageTask;
|
|
687
334
|
/**
|
|
688
|
-
*
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
* retryable server code). A non retryable server response (i.e bad request, not allowed etc) is
|
|
692
|
-
* skipped since retrying it would never succeed, and so is a request the caller cancelled via
|
|
693
|
-
* `StreamRequestOptions.signal` - replaying it would defeat the point of aborting.
|
|
335
|
+
* Folds an edit of a never-sent message into its queued `send-message` task, so a replay sends
|
|
336
|
+
* the edited text once. The send task keeps its row and so its place in the queue. With no send
|
|
337
|
+
* task the edit is queued on its own if `isMessageUpdateReplayable` allows it.
|
|
694
338
|
*
|
|
695
|
-
*
|
|
339
|
+
* A queued send is the only reliable sign the server never saw the message (a `failed` status can
|
|
340
|
+
* also come from a rejected edit). The payloads are already `MessageRequest`s, so they merge by
|
|
341
|
+
* plain spread: normalizing again would turn a flattened `mentioned_users` into `[undefined]`.
|
|
696
342
|
*/
|
|
697
|
-
private
|
|
698
|
-
private mergeFailedMessageUpdateIntoPendingSendMessage;
|
|
699
|
-
private isPendingSendMessageTask;
|
|
700
|
-
private handleOfflineFailedUpdateMessagePendingTask;
|
|
343
|
+
private handleUpdateMessagePendingTask;
|
|
701
344
|
/**
|
|
702
|
-
*
|
|
703
|
-
*
|
|
345
|
+
* Stores the task. An edit of a never-sent message is folded into its queued send instead. With no
|
|
346
|
+
* queued send, an edit `isMessageUpdateReplayable` refuses (attachments still on local URLs) is
|
|
347
|
+
* dropped.
|
|
348
|
+
*
|
|
349
|
+
* @param payload.task - The pending task to store.
|
|
704
350
|
*/
|
|
705
351
|
handleAddPendingTask: ({ task }: {
|
|
706
352
|
task: PendingTask;
|
|
707
353
|
}) => Promise<void>;
|
|
708
354
|
/**
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
* - Updating a message
|
|
712
|
-
* - Deleting a message
|
|
713
|
-
* - Sending a reaction
|
|
714
|
-
* - Removing a reaction
|
|
715
|
-
* - Sending a message
|
|
716
|
-
* - Creating a draft
|
|
717
|
-
* - Deleting a draft
|
|
718
|
-
* It will throw if we try to execute a pending task that is not supported.
|
|
719
|
-
*
|
|
720
|
-
* @param task - The task we want to execute
|
|
721
|
-
* @param isPendingTask - a control value telling us if it's an actual pending task being executed
|
|
722
|
-
* or delayed execution
|
|
723
|
-
*/
|
|
724
|
-
/**
|
|
725
|
-
* Replays one queued operation, through the {@link QUEUEABLE_OPERATIONS} registry rather than a
|
|
726
|
-
* per-type branch here — the same registry a first attempt resolves through, so the two cannot
|
|
727
|
-
* describe different requests.
|
|
728
|
-
*
|
|
729
|
-
* @param task - the task to run.
|
|
730
|
-
* @param isPendingTask - whether this is a replay rather than a first attempt. A first attempt has an
|
|
731
|
-
* optimistic layer above it that settles local state; a replay does not, so some operations have to
|
|
732
|
-
* settle it themselves (see `onReplay`).
|
|
355
|
+
* Runs the task through {@link QUEUEABLE_OPERATIONS}. With `isPendingTask` (a replay) it also
|
|
356
|
+
* runs the operation's `onReplay`.
|
|
733
357
|
*/
|
|
734
358
|
private executeTask;
|
|
735
359
|
/**
|
|
736
|
-
*
|
|
737
|
-
*
|
|
738
|
-
* it is going to remove the pending task from the DB even if execution fails, otherwise
|
|
739
|
-
* it will keep it for the next time we try to execute all pending taks.
|
|
360
|
+
* Replays the pending tasks in order and deletes each one that succeeded or was definitively
|
|
361
|
+
* rejected. A task that failed for an ephemeral reason stays for the next run.
|
|
740
362
|
*/
|
|
741
363
|
executePendingTasks: () => Promise<void>;
|
|
742
364
|
}
|