@@ -6,7 +6,10 @@ import {
66 MessageInput as DefaultMessageInput ,
77 MessageInputProps ,
88} from '../MessageInput/MessageInput' ;
9-
9+ import {
10+ ChatContextValue ,
11+ useChatContext ,
12+ } from '../../contexts/chatContext/ChatContext' ;
1013import {
1114 MessagesContextValue ,
1215 useMessagesContext ,
@@ -37,10 +40,11 @@ type ThreadPropsWithContext<
3740 Me extends UnknownType = DefaultMessageType ,
3841 Re extends UnknownType = DefaultReactionType ,
3942 Us extends UnknownType = DefaultUserType
40- > = Pick < MessagesContextValue < At , Ch , Co , Ev , Me , Re , Us > , 'MessageList' > &
43+ > = Pick < ChatContextValue < At , Ch , Co , Ev , Me , Re , Us > , 'client' > &
44+ Pick < MessagesContextValue < At , Ch , Co , Ev , Me , Re , Us > , 'MessageList' > &
4145 Pick <
4246 ThreadContextValue < At , Ch , Co , Ev , Me , Re , Us > ,
43- 'closeThread' | 'loadMoreThread' | 'thread'
47+ 'closeThread' | 'loadMoreThread' | 'reloadThread' | ' thread'
4448 > & {
4549 /**
4650 * Additional props for underlying MessageInput component.
@@ -90,10 +94,12 @@ const ThreadWithContext = <
9094 additionalMessageInputProps,
9195 additionalMessageListProps,
9296 autoFocus = true ,
97+ client,
9398 closeThread,
9499 closeThreadOnDismount = true ,
95100 disabled,
96101 loadMoreThread,
102+ reloadThread,
97103 MessageInput = DefaultMessageInput ,
98104 MessageList,
99105 onThreadDismount,
@@ -108,6 +114,18 @@ const ThreadWithContext = <
108114 if ( thread ?. id && thread . reply_count ) {
109115 loadMoreThreadAsync ( ) ;
110116 }
117+
118+ const recoveredHandler = client . on ( 'connection.recovered' , reloadThread ) ;
119+ const changedHandler = client . on ( 'connection.changed' , ( event ) => {
120+ if ( event . online ) {
121+ reloadThread ( ) ;
122+ }
123+ } ) ;
124+
125+ return ( ) => {
126+ recoveredHandler . unsubscribe ( ) ;
127+ changedHandler . unsubscribe ( ) ;
128+ } ;
111129 } , [ ] ) ;
112130
113131 useEffect (
@@ -170,23 +188,23 @@ export const Thread = <
170188> (
171189 props : ThreadProps < At , Ch , Co , Ev , Me , Re , Us > ,
172190) => {
191+ const { client } = useChatContext < At , Ch , Co , Ev , Me , Re , Us > ( ) ;
173192 const { MessageList } = useMessagesContext < At , Ch , Co , Ev , Me , Re , Us > ( ) ;
174- const { closeThread, loadMoreThread, thread } = useThreadContext <
175- At ,
176- Ch ,
177- Co ,
178- Ev ,
179- Me ,
180- Re ,
181- Us
182- > ( ) ;
193+ const {
194+ closeThread,
195+ loadMoreThread,
196+ reloadThread,
197+ thread,
198+ } = useThreadContext < At , Ch , Co , Ev , Me , Re , Us > ( ) ;
183199
184200 return (
185201 < ThreadWithContext < At , Ch , Co , Ev , Me , Re , Us >
186202 { ...{
203+ client,
187204 closeThread,
188205 loadMoreThread,
189206 MessageList,
207+ reloadThread,
190208 thread,
191209 } }
192210 { ...props }
0 commit comments