Skip to content

Commit 067a43a

Browse files
committed
feat(examples): add textComposerEmojiMiddleware to message composer
1 parent 29ae50e commit 067a43a

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

examples/vite/src/App.tsx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { ChannelFilters, ChannelOptions, ChannelSort } from 'stream-chat';
1+
import { useEffect } from 'react';
2+
import {
3+
ChannelFilters,
4+
ChannelOptions,
5+
ChannelSort,
6+
LocalMessage,
7+
TextComposerMiddleware,
8+
} from 'stream-chat';
29
import {
310
AIStateIndicator,
411
Channel,
@@ -8,13 +15,14 @@ import {
815
Chat,
916
ChatView,
1017
MessageInput,
11-
StreamMessage,
1218
Thread,
1319
ThreadList,
20+
useChatContext,
1421
useCreateChatClient,
1522
VirtualizedMessageList as MessageList,
1623
Window,
1724
} from 'stream-chat-react';
25+
import { createTextComposerEmojiMiddleware } from 'stream-chat-react/emojis';
1826
import { init, SearchIndex } from 'emoji-mart';
1927
import data from '@emoji-mart/data';
2028

@@ -44,7 +52,24 @@ const filters: ChannelFilters = {
4452
const options: ChannelOptions = { limit: 5, presence: true, state: true };
4553
const sort: ChannelSort = { pinned_at: 1, last_message_at: -1, updated_at: -1 };
4654

47-
const isMessageAIGenerated = (message: StreamMessage) => !!message?.ai_generated;
55+
// @ts-ignore
56+
const isMessageAIGenerated = (message: LocalMessage) => !!message?.ai_generated;
57+
58+
const Component = () => {
59+
const { client } = useChatContext();
60+
useEffect(() => {
61+
client.setMessageComposerApplyModifications(({ composer }) => {
62+
composer.textComposer.middlewareExecutor.insert({
63+
middleware: [
64+
createTextComposerEmojiMiddleware(SearchIndex) as TextComposerMiddleware,
65+
],
66+
position: { before: 'stream-io/mentions-middleware' },
67+
unique: true,
68+
});
69+
});
70+
}, [client]);
71+
return null;
72+
};
4873

4974
const App = () => {
5075
const chatClient = useCreateChatClient({
@@ -57,6 +82,7 @@ const App = () => {
5782

5883
return (
5984
<Chat client={chatClient} isMessageAIGenerated={isMessageAIGenerated}>
85+
<Component />
6086
<ChatView>
6187
<ChatView.Selector />
6288
<ChatView.Channels>
@@ -73,7 +99,7 @@ const App = () => {
7399
<ChannelHeader Avatar={ChannelAvatar} />
74100
<MessageList returnAllReadData />
75101
<AIStateIndicator />
76-
<MessageInput focus />
102+
<MessageInput focus audioRecordingEnabled />
77103
</Window>
78104
<Thread virtualized />
79105
</Channel>

0 commit comments

Comments
 (0)