@@ -4,11 +4,11 @@ import { TouchableOpacity } from 'react-native-gesture-handler';
44import { useNavigation } from '@react-navigation/core' ;
55
66import {
7- MessageInputContextValue ,
87 Search ,
98 SendRight ,
109 useChannelContext ,
11- useMessageInputContext ,
10+ useMessageComposer ,
11+ useStateStore ,
1212 useTheme ,
1313} from 'stream-chat-react-native' ;
1414
@@ -19,11 +19,16 @@ import { useAppContext } from '../context/AppContext';
1919import { SendUp } from '../icons/SendUp' ;
2020import { useLegacyColors } from '../theme/useLegacyColors' ;
2121
22- type NewDirectMessagingSendButtonPropsWithContext = Pick <
23- MessageInputContextValue ,
24- 'giphyActive' | 'sendMessage'
25- > & {
22+ import type { TextComposerState } from 'stream-chat' ;
23+
24+ const textComposerStateSelector = ( state : TextComposerState ) => ( {
25+ command : state . command ,
26+ } ) ;
27+
28+ type NewDirectMessagingSendButtonPropsWithContext = {
2629 /** Disables the button */ disabled : boolean ;
30+ giphyActive : boolean ;
31+ sendMessage : ( ) => Promise < void > ;
2732} ;
2833
2934const SendButtonWithContext = ( props : NewDirectMessagingSendButtonPropsWithContext ) => {
@@ -97,8 +102,9 @@ export const NewDirectMessagingSendButton = (props: SendButtonProps) => {
97102 const navigation = useNavigation < NewDirectMessagingScreenNavigationProp > ( ) ;
98103 const { channel } = useChannelContext ( ) ;
99104 const { selectedUserIds, reset } = useUserSearchContext ( ) ;
100-
101- const { giphyActive, text } = useMessageInputContext ( ) ;
105+ const messageComposer = useMessageComposer ( ) ;
106+ const { command } = useStateStore ( messageComposer . textComposer . state , textComposerStateSelector ) ;
107+ const giphyActive = command ?. name === 'giphy' ;
102108
103109 const sendMessage = async ( ) => {
104110 if ( ! channel ) {
@@ -107,14 +113,21 @@ export const NewDirectMessagingSendButton = (props: SendButtonProps) => {
107113 if ( ! chatClient || ! chatClient . user ) {
108114 return ;
109115 }
116+
117+ const composition = await messageComposer . compose ( ) ;
118+ if ( ! composition ?. message ) {
119+ return ;
120+ }
121+
110122 const members = [ chatClient . user . id , ...selectedUserIds ] ;
111123 channel . initialized = false ;
112124 const newChannel = chatClient . channel ( 'messaging' , {
113125 members,
114126 } ) ;
115127 try {
116128 await newChannel . watch ( ) ;
117- await newChannel . sendMessage ( { text } ) ;
129+ await newChannel . sendMessage ( composition . message , composition . sendOptions ) ;
130+ messageComposer . clear ( ) ;
118131 navigation . replace ( 'ChannelScreen' , {
119132 channelId : newChannel . id ,
120133 } ) ;
0 commit comments