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' ;
2
9
import {
3
10
AIStateIndicator ,
4
11
Channel ,
@@ -8,13 +15,19 @@ import {
8
15
Chat ,
9
16
ChatView ,
10
17
MessageInput ,
11
- StreamMessage ,
18
+ SendButtonProps ,
12
19
Thread ,
13
20
ThreadList ,
14
21
useCreateChatClient ,
22
+ useMessageComposer ,
15
23
VirtualizedMessageList as MessageList ,
16
24
Window ,
17
25
} from 'stream-chat-react' ;
26
+ import { createTextComposerEmojiMiddleware } from 'stream-chat-react/emojis' ;
27
+ import { init , SearchIndex } from 'emoji-mart' ;
28
+ import data from '@emoji-mart/data' ;
29
+
30
+ init ( { data } ) ;
18
31
19
32
const params = new Proxy ( new URLSearchParams ( window . location . search ) , {
20
33
get : ( searchParams , property ) => searchParams . get ( property as string ) ,
@@ -40,40 +53,30 @@ const filters: ChannelFilters = {
40
53
const options : ChannelOptions = { limit : 5 , presence : true , state : true } ;
41
54
const sort : ChannelSort = { pinned_at : 1 , last_message_at : - 1 , updated_at : - 1 } ;
42
55
43
- type LocalAttachmentType = Record < string , unknown > ;
44
- type LocalChannelType = Record < string , unknown > ;
45
- type LocalCommandType = string ;
46
- type LocalEventType = Record < string , unknown > ;
47
- type LocalMemberType = Record < string , unknown > ;
48
- type LocalMessageType = Record < string , unknown > ;
49
- type LocalPollOptionType = Record < string , unknown > ;
50
- type LocalPollType = Record < string , unknown > ;
51
- type LocalReactionType = Record < string , unknown > ;
52
- type LocalUserType = Record < string , unknown > ;
53
-
54
- type StreamChatGenerics = {
55
- attachmentType : LocalAttachmentType ;
56
- channelType : LocalChannelType ;
57
- commandType : LocalCommandType ;
58
- eventType : LocalEventType ;
59
- memberType : LocalMemberType ;
60
- messageType : LocalMessageType ;
61
- pollOptionType : LocalPollOptionType ;
62
- pollType : LocalPollType ;
63
- reactionType : LocalReactionType ;
64
- userType : LocalUserType ;
65
- } ;
66
-
67
- const isMessageAIGenerated = ( message : StreamMessage < StreamChatGenerics > ) =>
68
- ! ! message ?. ai_generated ;
56
+ // @ts -ignore
57
+ const isMessageAIGenerated = ( message : LocalMessage ) => ! ! message ?. ai_generated ;
69
58
70
59
const App = ( ) => {
71
- const chatClient = useCreateChatClient < StreamChatGenerics > ( {
60
+ const chatClient = useCreateChatClient ( {
72
61
apiKey,
73
62
tokenOrProvider : userToken ,
74
63
userData : { id : userId } ,
75
64
} ) ;
76
65
66
+ useEffect ( ( ) => {
67
+ if ( ! chatClient ) return ;
68
+
69
+ chatClient . setMessageComposerSetupFunction ( ( { composer } ) => {
70
+ composer . textComposer . middlewareExecutor . insert ( {
71
+ middleware : [
72
+ createTextComposerEmojiMiddleware ( SearchIndex ) as TextComposerMiddleware ,
73
+ ] ,
74
+ position : { before : 'stream-io/text-composer/mentions-middleware' } ,
75
+ unique : true ,
76
+ } ) ;
77
+ } ) ;
78
+ } , [ chatClient ] ) ;
79
+
77
80
if ( ! chatClient ) return < > Loading...</ > ;
78
81
79
82
return (
@@ -89,12 +92,12 @@ const App = () => {
89
92
showChannelSearch
90
93
additionalChannelSearchProps = { { searchForChannels : true } }
91
94
/>
92
- < Channel >
95
+ < Channel emojiSearchIndex = { SearchIndex } >
93
96
< Window >
94
97
< ChannelHeader Avatar = { ChannelAvatar } />
95
98
< MessageList returnAllReadData />
96
99
< AIStateIndicator />
97
- < MessageInput focus />
100
+ < MessageInput focus audioRecordingEnabled />
98
101
</ Window >
99
102
< Thread virtualized />
100
103
</ Channel >
0 commit comments