Skip to content

Commit 47063ca

Browse files
committed
chore: introduce prop to enable async attachments
1 parent 6421a45 commit 47063ca

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import throttle from 'lodash/throttle';
77
import { lookup } from 'mime-types';
88
import {
99
Channel as ChannelClass,
10-
ChannelResponse,
1110
ChannelState,
1211
Channel as ChannelType,
1312
DeleteMessageOptions,
@@ -495,7 +494,10 @@ export type ChannelPropsWithContext = Pick<ChannelContextValue, 'channel'> &
495494
} & Partial<
496495
Pick<
497496
InputMessageInputContextValue,
498-
'openPollCreationDialog' | 'CreatePollContent' | 'StopMessageStreamingButton'
497+
| 'openPollCreationDialog'
498+
| 'CreatePollContent'
499+
| 'StopMessageStreamingButton'
500+
| 'allowSendBeforeAttachmentsUpload'
499501
>
500502
>;
501503

@@ -571,6 +573,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
571573
EmptyStateIndicator = EmptyStateIndicatorDefault,
572574
enableMessageGroupingByUser = true,
573575
enableOfflineSupport,
576+
allowSendBeforeAttachmentsUpload = enableOfflineSupport,
574577
enableSwipeToReply = true,
575578
enforceUniqueReaction = false,
576579
FileAttachment = FileAttachmentDefault,
@@ -1772,6 +1775,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
17721775

17731776
const inputMessageInputContext = useCreateInputMessageInputContext({
17741777
additionalTextInputProps,
1778+
allowSendBeforeAttachmentsUpload,
17751779
asyncMessagesLockDistance,
17761780
asyncMessagesMinimumPressDuration,
17771781
asyncMessagesMultiSendEnabled,

package/src/components/Channel/hooks/useCreateInputMessageInputContext.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { InputMessageInputContextValue } from '../../../contexts/messageInp
44

55
export const useCreateInputMessageInputContext = ({
66
additionalTextInputProps,
7+
allowSendBeforeAttachmentsUpload,
78
asyncMessagesLockDistance,
89
asyncMessagesMinimumPressDuration,
910
asyncMessagesMultiSendEnabled,
@@ -70,6 +71,7 @@ export const useCreateInputMessageInputContext = ({
7071
const inputMessageInputContext: InputMessageInputContextValue = useMemo(
7172
() => ({
7273
additionalTextInputProps,
74+
allowSendBeforeAttachmentsUpload,
7375
asyncMessagesLockDistance,
7476
asyncMessagesMinimumPressDuration,
7577
asyncMessagesMultiSendEnabled,
@@ -128,7 +130,13 @@ export const useCreateInputMessageInputContext = ({
128130
VideoRecorderSelectorIcon,
129131
}),
130132
// eslint-disable-next-line react-hooks/exhaustive-deps
131-
[compressImageQuality, channelId, CreatePollContent, showPollCreationDialog],
133+
[
134+
compressImageQuality,
135+
channelId,
136+
CreatePollContent,
137+
showPollCreationDialog,
138+
allowSendBeforeAttachmentsUpload,
139+
],
132140
);
133141

134142
return inputMessageInputContext;

package/src/contexts/messageInputContext/MessageInputContext.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ export type InputMessageInputContextValue = {
328328
* @see See https://reactnative.dev/docs/textinput#reference
329329
*/
330330
additionalTextInputProps?: TextInputProps;
331+
allowSendBeforeAttachmentsUpload?: boolean;
331332
closePollCreationDialog?: () => void;
332333
/**
333334
* Compress image with quality (from 0 to 1, where 1 is best quality).
@@ -411,7 +412,7 @@ export const MessageInputProvider = ({
411412
}>) => {
412413
const { closePicker, openPicker, selectedPicker, setSelectedPicker } =
413414
useAttachmentPickerContext();
414-
const { client, enableOfflineSupport } = useChatContext();
415+
const { client } = useChatContext();
415416
const channelCapabilities = useOwnCapabilitiesContext();
416417

417418
const { uploadAbortControllerRef } = useChannelContext();
@@ -425,7 +426,10 @@ export const MessageInputProvider = ({
425426
const defaultOpenPollCreationDialog = useCallback(() => setShowPollCreationDialog(true), []);
426427
const closePollCreationDialog = useCallback(() => setShowPollCreationDialog(false), []);
427428

428-
const { openPollCreationDialog: openPollCreationDialogFromContext } = value;
429+
const {
430+
openPollCreationDialog: openPollCreationDialogFromContext,
431+
allowSendBeforeAttachmentsUpload,
432+
} = value;
429433

430434
const { endsAt: cooldownEndsAt, start: startCooldown } = useCooldown();
431435

@@ -443,7 +447,7 @@ export const MessageInputProvider = ({
443447
attachmentManager.setCustomUploadFn(value.doFileUploadRequest);
444448
}
445449

446-
if (enableOfflineSupport) {
450+
if (allowSendBeforeAttachmentsUpload) {
447451
messageComposer.compositionMiddlewareExecutor.replace([
448452
createAttachmentsCompositionMiddleware(messageComposer),
449453
]);
@@ -452,7 +456,12 @@ export const MessageInputProvider = ({
452456
createDraftAttachmentsCompositionMiddleware(messageComposer),
453457
]);
454458
}
455-
}, [value.doFileUploadRequest, enableOfflineSupport, messageComposer, attachmentManager]);
459+
}, [
460+
value.doFileUploadRequest,
461+
allowSendBeforeAttachmentsUpload,
462+
messageComposer,
463+
attachmentManager,
464+
]);
456465

457466
/**
458467
* Function for capturing a photo and uploading it

0 commit comments

Comments
 (0)