11import React , { PropsWithChildren } from 'react' ;
22import { StyleSheet , View } from 'react-native' ;
33
4+ import { filterTypingUsers } from './utils/filterTypingUsers' ;
5+
46import {
57 ChatContextValue ,
68 useChatContext ,
79} from '../../contexts/chatContext/ChatContext' ;
810import { useTheme } from '../../contexts/themeContext/ThemeContext' ;
11+ import {
12+ ThreadContextValue ,
13+ useThreadContext ,
14+ } from '../../contexts/threadContext/ThreadContext' ;
915import {
1016 TypingContextValue ,
1117 useTypingContext ,
@@ -39,7 +45,8 @@ type TypingIndicatorContainerPropsWithContext<
3945 Re extends UnknownType = DefaultReactionType ,
4046 Us extends DefaultUserType = DefaultUserType
4147> = Pick < TypingContextValue < At , Ch , Co , Ev , Me , Re , Us > , 'typing' > &
42- Pick < ChatContextValue < At , Ch , Co , Ev , Me , Re , Us > , 'client' > ;
48+ Pick < ChatContextValue < At , Ch , Co , Ev , Me , Re , Us > , 'client' > &
49+ Pick < ThreadContextValue < At , Ch , Co , Ev , Me , Re , Us > , 'thread' > ;
4350
4451const TypingIndicatorContainerWithContext = <
4552 At extends UnknownType = DefaultAttachmentType ,
@@ -54,19 +61,16 @@ const TypingIndicatorContainerWithContext = <
5461 TypingIndicatorContainerPropsWithContext < At , Ch , Co , Ev , Me , Re , Us >
5562 > ,
5663) => {
57- const { children, client, typing } = props ;
64+ const { children, client, thread , typing } = props ;
5865
5966 const {
6067 theme : {
6168 messageList : { typingIndicatorContainer } ,
6269 } ,
6370 } = useTheme ( ) ;
64- const typingUsers = Object . values ( typing ) ;
71+ const typingUsers = filterTypingUsers ( { client , thread , typing } ) ;
6572
66- if (
67- ! typingUsers . length ||
68- ( typingUsers . length === 1 && typingUsers [ 0 ] . user ?. id === client ?. user ?. id )
69- ) {
73+ if ( ! typingUsers . length ) {
7074 return null ;
7175 }
7276
@@ -107,9 +111,13 @@ export const TypingIndicatorContainer = <
107111) => {
108112 const { typing } = useTypingContext < At , Ch , Co , Ev , Me , Re , Us > ( ) ;
109113 const { client } = useChatContext < At , Ch , Co , Ev , Me , Re , Us > ( ) ;
114+ const { thread } = useThreadContext < At , Ch , Co , Ev , Me , Re , Us > ( ) ;
110115
111116 return (
112- < TypingIndicatorContainerWithContext { ...{ client, typing } } { ...props } />
117+ < TypingIndicatorContainerWithContext
118+ { ...{ client, thread, typing } }
119+ { ...props }
120+ />
113121 ) ;
114122} ;
115123
0 commit comments