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' ;
29import {
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' ;
1826import { init , SearchIndex } from 'emoji-mart' ;
1927import data from '@emoji-mart/data' ;
2028
@@ -44,7 +52,24 @@ const filters: ChannelFilters = {
4452const options : ChannelOptions = { limit : 5 , presence : true , state : true } ;
4553const 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
4974const 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