Skip to content

Commit 64a1ff0

Browse files
committed
feat: handle command injection through middleware
1 parent 3c2aa69 commit 64a1ff0

File tree

7 files changed

+26
-45
lines changed

7 files changed

+26
-45
lines changed

package/src/components/AutoCompleteInput/AutoCompleteInput.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ type AutoCompleteInputPropsWithContext = TextInputProps &
4242
type AutoCompleteInputProps = Partial<AutoCompleteInputPropsWithContext>;
4343

4444
const textComposerStateSelector = (state: TextComposerState) => ({
45-
// TODO: Comment out once the commands PR has been merged on the LLC
46-
// command: state.command,
47-
command: null,
45+
command: state.command,
4846
text: state.text,
4947
});
5048

package/src/components/MessageInput/InputButtons.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ export type InputButtonsWithContextProps = Pick<
3535
Pick<OwnCapabilitiesContextValue, 'uploadFile'>;
3636

3737
const textComposerStateSelector = (state: TextComposerState) => ({
38-
// TODO: Comment out once the commands PR has been merged on the LLC
39-
// command: state.command,
40-
command: null,
38+
command: state.command,
4139
hasText: !!state.text,
4240
});
4341

package/src/components/MessageInput/MessageInput.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ type MessageInputPropsWithContext = Partial<
173173
Pick<MessageComposerAPIContextValue, 'clearEditingState'> & { editing: boolean };
174174

175175
const textComposerStateSelector = (state: TextComposerState) => ({
176-
// TODO: Comment out once the commands PR has been merged on the LLC
177-
// command: state.command,
178-
command: null,
176+
command: state.command,
179177
hasText: !!state.text,
180178
mentionedUsers: state.mentionedUsers,
181179
suggestions: state.suggestions,

package/src/components/MessageInput/SendButton.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@ export type SendButtonProps = Partial<Pick<MessageInputContextValue, 'sendMessag
2020
disabled: boolean;
2121
};
2222

23-
// TODO: Comment out once the commands PR has been merged on the LLC
24-
// @ts-ignore
25-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2623
const textComposerStateSelector = (state: TextComposerState) => ({
27-
// TODO: Comment out once the commands PR has been merged on the LLC
28-
// command: state.command,
29-
command: null,
24+
command: state.command,
3025
});
3126

3227
export const SendButton = (props: SendButtonProps) => {

package/src/components/MessageInput/components/CommandInput.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ export type CommandInputProps = Partial<
2222
disabled: boolean;
2323
};
2424
const textComposerStateSelector = (state: TextComposerState) => ({
25-
// TODO: Comment out once the commands PR has been merged on the LLC
26-
// command: state.command,
27-
command: null,
25+
command: state.command,
2826
text: state.text,
2927
});
3028

@@ -52,18 +50,15 @@ export const CommandInput = ({
5250
} = useTheme();
5351

5452
const onCloseHandler = () => {
55-
// TODO: Comment out once the commands PR has been merged on the LLC
56-
// textComposer.clearCommand();
53+
textComposer.clearCommand();
5754
messageComposer?.restore();
5855
};
5956

6057
if (!command) {
6158
return null;
6259
}
6360

64-
// TODO: Comment out once the commands PR has been merged on the LLC
65-
// const commandName = (command.name ?? '').toUpperCase();
66-
const commandName = '';
61+
const commandName = (command.name ?? '').toUpperCase();
6762

6863
return (
6964
<View style={[styles.autoCompleteInputContainer, autoCompleteInputContainer]}>

package/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export * from './types/types';
1515

1616
export * from './utils/patchMessageTextCommand';
1717
export * from './utils/i18n/Streami18n';
18+
export * from './utils/setupCommandUIMiddleware';
1819
export * from './utils/utils';
1920

2021
export { default as enTranslations } from './i18n/en.json';
Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
import {
2-
// createCommandInjectionMiddleware,
3-
// createCommandStringExtractionMiddleware,
4-
// createDraftCommandInjectionMiddleware,
2+
createCommandInjectionMiddleware,
3+
createCommandStringExtractionMiddleware,
4+
createDraftCommandInjectionMiddleware,
55
MessageComposer,
6-
// TextComposerMiddleware,
6+
TextComposerMiddleware,
77
} from 'stream-chat';
88

9-
// TODO: Comment out once the commands PR has been merged on the LLC
10-
// @ts-ignore
11-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
129
export const setupCommandUIMiddleware = (messageComposer: MessageComposer) => {
13-
// TODO: Comment out once the commands PR has been merged on the LLC
14-
// messageComposer.compositionMiddlewareExecutor.insert({
15-
// middleware: [createCommandInjectionMiddleware(messageComposer)],
16-
// position: { after: 'stream-io/message-composer-middleware/attachments' },
17-
// });
18-
//
19-
// messageComposer.draftCompositionMiddlewareExecutor.insert({
20-
// middleware: [createDraftCommandInjectionMiddleware(messageComposer)],
21-
// position: { after: 'stream-io/message-composer-middleware/draft-attachments' },
22-
// });
23-
//
24-
// messageComposer.textComposer.middlewareExecutor.insert({
25-
// middleware: [createCommandStringExtractionMiddleware() as TextComposerMiddleware],
26-
// position: { after: 'stream-io/text-composer/commands-middleware' },
27-
// });
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+
});
2824
};

0 commit comments

Comments
 (0)