Skip to content

Commit fc00aa4

Browse files
committed
fix: remove isCommandUIEnabled from channel context
1 parent dac2a5d commit fc00aa4

File tree

5 files changed

+31
-31
lines changed

5 files changed

+31
-31
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ export type ChannelPropsWithContext = Pick<ChannelContextValue, 'channel'> &
279279
| 'EmptyStateIndicator'
280280
| 'enableMessageGroupingByUser'
281281
| 'enforceUniqueReaction'
282-
| 'isCommandUIEnabled'
283282
| 'hideStickyDateHeader'
284283
| 'hideDateSeparators'
285284
| 'LoadingIndicator'
@@ -1694,7 +1693,6 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
16941693
hideStickyDateHeader,
16951694
highlightedMessageId,
16961695
isChannelActive: shouldSyncChannel,
1697-
isCommandUIEnabled: isCommandUIEnabled ?? !!clientChannelConfig?.commands?.length,
16981696
lastRead,
16991697
loadChannelAroundMessage,
17001698
loadChannelAtFirstUnreadMessage,
@@ -1769,7 +1767,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
17691767
FileUploadPreview,
17701768
handleAttachButtonPress,
17711769
hasCameraPicker,
1772-
hasCommands: hasCommands ?? (getChannelConfigSafely()?.commands ?? []).length > 0,
1770+
hasCommands: hasCommands ?? !!clientChannelConfig?.commands?.length,
17731771
hasFilePicker,
17741772
hasImagePicker,
17751773
ImageAttachmentUploadPreview,
@@ -1779,7 +1777,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
17791777
InputButtons,
17801778
InputEditingStateHeader,
17811779
InputReplyStateHeader,
1782-
isCommandUIEnabled,
1780+
isCommandUIEnabled: isCommandUIEnabled ?? !!clientChannelConfig?.commands?.length,
17831781
MoreOptionsButton,
17841782
openPollCreationDialog,
17851783
SendButton,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const useCreateChannelContext = ({
1010
enableMessageGroupingByUser,
1111
enforceUniqueReaction,
1212
error,
13-
isCommandUIEnabled,
1413
hideDateSeparators,
1514
hideStickyDateHeader,
1615
highlightedMessageId,
@@ -59,7 +58,6 @@ export const useCreateChannelContext = ({
5958
hideStickyDateHeader,
6059
highlightedMessageId,
6160
isChannelActive,
62-
isCommandUIEnabled,
6361
lastRead,
6462
loadChannelAroundMessage,
6563
loadChannelAtFirstUnreadMessage,

package/src/contexts/channelContext/ChannelContext.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ export type ChannelContextValue = {
4949
*/
5050
enforceUniqueReaction: boolean;
5151
error: boolean | Error;
52-
/**
53-
* When set to false, it will disable giphy command on MessageInput component.
54-
*/
55-
isCommandUIEnabled: boolean;
5652
/**
5753
* Hide inline date separators on channel
5854
*/

package/src/contexts/messageInputContext/MessageInputContext.tsx

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ import { Alert, Keyboard, Linking, TextInput, TextInputProps } from 'react-nativ
1111

1212
import { BottomSheetHandleProps } from '@gorhom/bottom-sheet';
1313
import {
14-
createCommandInjectionMiddleware,
15-
createCommandStringExtractionMiddleware,
16-
createDraftCommandInjectionMiddleware,
1714
LocalMessage,
1815
Message,
1916
SendMessageOptions,
2017
StreamChat,
2118
Message as StreamMessage,
22-
TextComposerMiddleware,
2319
UpdateMessageOptions,
2420
UploadRequestFn,
2521
UserResponse,
@@ -67,6 +63,7 @@ import {
6763
import { isDocumentPickerAvailable, MediaTypes, NativeHandlers } from '../../native';
6864
import { File } from '../../types/types';
6965
import { compressedImageURI } from '../../utils/compressImage';
66+
import { setupCommandUIMiddleware } from '../../utils/setupCommandUIMiddleware';
7067
import {
7168
AttachmentPickerIconProps,
7269
useAttachmentPickerContext,
@@ -428,7 +425,7 @@ export const MessageInputProvider = ({
428425
useAttachmentPickerContext();
429426
const { client, enableOfflineSupport } = useChatContext();
430427

431-
const { isCommandUIEnabled, uploadAbortControllerRef } = useChannelContext();
428+
const { uploadAbortControllerRef } = useChannelContext();
432429
const { clearEditingState } = useMessageComposerAPIContext();
433430
const { thread } = useThreadContext();
434431
const { t } = useTranslationContext();
@@ -462,21 +459,8 @@ export const MessageInputProvider = ({
462459
attachmentManager.setCustomUploadFn(value.doFileUploadRequest);
463460
}
464461

465-
if (isCommandUIEnabled) {
466-
messageComposer.compositionMiddlewareExecutor.insert({
467-
middleware: [createCommandInjectionMiddleware(messageComposer)],
468-
position: { after: 'stream-io/message-composer-middleware/attachments' },
469-
});
470-
471-
messageComposer.draftCompositionMiddlewareExecutor.insert({
472-
middleware: [createDraftCommandInjectionMiddleware(messageComposer)],
473-
position: { after: 'stream-io/message-composer-middleware/draft-attachments' },
474-
});
475-
476-
messageComposer.textComposer.middlewareExecutor.insert({
477-
middleware: [createCommandStringExtractionMiddleware() as TextComposerMiddleware],
478-
position: { after: 'stream-io/text-composer/commands-middleware' },
479-
});
462+
if (value.isCommandUIEnabled) {
463+
setupCommandUIMiddleware(messageComposer);
480464
}
481465

482466
if (enableOfflineSupport) {
@@ -490,7 +474,7 @@ export const MessageInputProvider = ({
490474
}
491475
}, [
492476
value.doFileUploadRequest,
493-
isCommandUIEnabled,
477+
value.isCommandUIEnabled,
494478
enableOfflineSupport,
495479
messageComposer,
496480
attachmentManager,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
createCommandInjectionMiddleware,
3+
createCommandStringExtractionMiddleware,
4+
createDraftCommandInjectionMiddleware,
5+
MessageComposer,
6+
TextComposerMiddleware,
7+
} from 'stream-chat';
8+
9+
export const setupCommandUIMiddleware = (messageComposer: MessageComposer) => {
10+
messageComposer.compositionMiddlewareExecutor.insert({
11+
middleware: [createCommandInjectionMiddleware(messageComposer)],
12+
position: { after: 'stream-io/message-composer-middleware/attachments' },
13+
});
14+
15+
messageComposer.draftCompositionMiddlewareExecutor.insert({
16+
middleware: [createDraftCommandInjectionMiddleware(messageComposer)],
17+
position: { after: 'stream-io/message-composer-middleware/draft-attachments' },
18+
});
19+
20+
messageComposer.textComposer.middlewareExecutor.insert({
21+
middleware: [createCommandStringExtractionMiddleware() as TextComposerMiddleware],
22+
position: { after: 'stream-io/text-composer/commands-middleware' },
23+
});
24+
};

0 commit comments

Comments
 (0)