@@ -75,7 +75,6 @@ import {
7575 ChannelContextValue ,
7676 ChannelProvider ,
7777} from '../../contexts/channelContext/ChannelContext' ;
78- import { useChannelState } from '../../contexts/channelsStateContext/useChannelState' ;
7978import { ChatContextValue , useChatContext } from '../../contexts/chatContext/ChatContext' ;
8079import {
8180 InputConfig ,
@@ -101,7 +100,7 @@ import {
101100 TranslationContextValue ,
102101 useTranslationContext ,
103102} from '../../contexts/translationContext/TranslationContext' ;
104- import { TypingProvider } from '../../contexts/typingContext/TypingContext' ;
103+ import { TypingContextValue , TypingProvider } from '../../contexts/typingContext/TypingContext' ;
105104import {
106105 LOLReaction ,
107106 LoveReaction ,
@@ -113,7 +112,6 @@ import { FlatList as FlatListDefault } from '../../native';
113112import { generateRandomId , ReactionData } from '../../utils/utils' ;
114113
115114import type { MessageType } from '../MessageList/hooks/useMessageList' ;
116- import type { UseChannelStateValue } from '../../contexts/channelsStateContext/useChannelState' ;
117115
118116import type {
119117 DefaultAttachmentType ,
@@ -202,7 +200,6 @@ export type ChannelPropsWithContext<
202200 'messages' | 'loadingMore' | 'loadingMoreRecent'
203201 >
204202 > &
205- UseChannelStateValue < At , Ch , Co , Ev , Me , Re , Us > &
206203 Partial <
207204 Pick <
208205 MessagesContextValue < At , Ch , Co , Ev , Me , Re , Us > ,
@@ -281,7 +278,6 @@ export type ChannelPropsWithContext<
281278 Partial <
282279 Pick < ThreadContextValue < At , Ch , Co , Ev , Me , Re , Us > , 'allowThreadMessagesInChannel' | 'thread' >
283280 > & {
284- shouldSyncChannel : boolean ;
285281 /**
286282 * Additional props passed to keyboard avoiding view
287283 */
@@ -363,10 +359,6 @@ export type ChannelPropsWithContext<
363359 quotedRepliesEnabled ?: boolean ;
364360 reactionsEnabled ?: boolean ;
365361 readEventsEnabled ?: boolean ;
366- /**
367- * Tells if channel is rendering a thread list
368- */
369- threadList ?: boolean ;
370362 threadRepliesEnabled ?: boolean ;
371363 typingEventsEnabled ?: boolean ;
372364 uploadsEnabled ?: boolean ;
@@ -386,9 +378,9 @@ const ChannelWithContext = <
386378 const {
387379 additionalKeyboardAvoidingViewProps,
388380 additionalTextInputProps,
381+ animatedLongPress,
389382 additionalTouchableProps,
390383 allowThreadMessagesInChannel = true ,
391- animatedLongPress,
392384 AttachButton = AttachButtonDefault ,
393385 Attachment = AttachmentDefault ,
394386 AttachmentActions = AttachmentActionsDefault ,
@@ -421,8 +413,8 @@ const ChannelWithContext = <
421413 EmptyStateIndicator = EmptyStateIndicatorDefault ,
422414 enforceUniqueReaction = false ,
423415 FileAttachment = FileAttachmentDefault ,
424- FileAttachmentGroup = FileAttachmentGroupDefault ,
425416 FileAttachmentIcon = FileIconDefault ,
417+ FileAttachmentGroup = FileAttachmentGroupDefault ,
426418 FileUploadPreview = FileUploadPreviewDefault ,
427419 flagMessage,
428420 FlatList = FlatListDefault ,
@@ -461,12 +453,12 @@ const ChannelWithContext = <
461453 loadingMore : loadingMoreProp ,
462454 loadingMoreRecent : loadingMoreRecentProp ,
463455 markdownRules,
456+ messageId,
464457 maxMessageLength : maxMessageLengthProp ,
465458 maxNumberOfFiles = 10 ,
466459 maxTimeBetweenGroupedMessages,
467460 mentionAllAppUsersEnabled = false ,
468461 mentionAllAppUsersQuery,
469- members,
470462 Message = MessageDefault ,
471463 messageActions,
472464 MessageAvatar = MessageAvatarDefault ,
@@ -475,11 +467,10 @@ const ChannelWithContext = <
475467 MessageDeleted = MessageDeletedDefault ,
476468 MessageFooter = MessageFooterDefault ,
477469 MessageHeader,
478- messageId,
479470 MessageList = MessageListDefault ,
480471 MessageReplies = MessageRepliesDefault ,
481472 MessageRepliesAvatars = MessageRepliesAvatarsDefault ,
482- messages,
473+ messages : messagesProp ,
483474 MessageSimple = MessageSimpleDefault ,
484475 MessageStatus = MessageStatusDefault ,
485476 MessageSystem = MessageSystemDefault ,
@@ -493,15 +484,14 @@ const ChannelWithContext = <
493484 onChangeText,
494485 onDoubleTapMessage,
495486 onLongPressMessage,
496- onPressInMessage,
497487 onPressMessage,
488+ onPressInMessage,
498489 openSuggestions,
499490 OverlayReactionList = OverlayReactionListDefault ,
500491 quotedRepliesEnabled : quotedRepliesEnabledProp ,
501492 quotedReply,
502493 ReactionList = ReactionListDefault ,
503494 reactionsEnabled : reactionsEnabledProp ,
504- read,
505495 readEventsEnabled : readEventsEnabledProp ,
506496 Reply = ReplyDefault ,
507497 retry,
@@ -510,32 +500,20 @@ const ChannelWithContext = <
510500 SendButton = SendButtonDefault ,
511501 sendImageAsync = false ,
512502 setInputRef,
513- setMembers,
514- setMessages,
515- setRead,
516- setThreadMessages,
517- setTyping,
518- setWatcherCount,
519- setWatchers,
520- shouldSyncChannel,
521503 ShowThreadMessageInChannelButton = ShowThreadMessageInChannelButtonDefault ,
522504 StickyHeader,
523505 supportedReactions = reactionData ,
524506 t,
525507 thread : threadProps ,
526- threadMessages,
527508 threadRepliesEnabled : threadRepliesEnabledProp ,
528509 threadReply,
529- typing,
530510 typingEventsEnabled : typingEventsEnabledProp ,
531511 TypingIndicator = TypingIndicatorDefault ,
532512 TypingIndicatorContainer = TypingIndicatorContainerDefault ,
533513 updateSuggestions,
534514 UploadProgressIndicator = UploadProgressIndicatorDefault ,
535515 uploadsEnabled : uploadsEnabledProp ,
536516 UrlPreview = CardDefault ,
537- watcherCount,
538- watchers,
539517 } = props ;
540518
541519 const {
@@ -554,13 +532,32 @@ const ChannelWithContext = <
554532 const [ loadingMore , setLoadingMore ] = useState ( false ) ;
555533
556534 const [ loadingMoreRecent , setLoadingMoreRecent ] = useState ( false ) ;
535+ const [ messages , setMessages ] = useState <
536+ PaginatedMessageListContextValue < At , Ch , Co , Ev , Me , Re , Us > [ 'messages' ]
537+ > ( [ ] ) ;
538+
539+ const [ members , setMembers ] = useState <
540+ ChannelContextValue < At , Ch , Co , Ev , Me , Re , Us > [ 'members' ]
541+ > ( { } ) ;
557542 const [ quotedMessage , setQuotedMessage ] =
558543 useState < boolean | MessageType < At , Ch , Co , Ev , Me , Re , Us > > ( false ) ;
544+ const [ read , setRead ] = useState < ChannelContextValue < At , Ch , Co , Ev , Me , Re , Us > [ 'read' ] > ( { } ) ;
559545 const [ thread , setThread ] = useState < ThreadContextValue < At , Ch , Co , Ev , Me , Re , Us > [ 'thread' ] > (
560546 threadProps || null ,
561547 ) ;
562548 const [ threadHasMore , setThreadHasMore ] = useState ( true ) ;
563549 const [ threadLoadingMore , setThreadLoadingMore ] = useState ( false ) ;
550+ const [ threadMessages , setThreadMessages ] = useState <
551+ ThreadContextValue < At , Ch , Co , Ev , Me , Re , Us > [ 'threadMessages' ]
552+ > ( ( threadProps ?. id && channel ?. state ?. threads ?. [ threadProps . id ] ) || [ ] ) ;
553+ const [ typing , setTyping ] = useState < TypingContextValue < At , Ch , Co , Ev , Me , Re , Us > [ 'typing' ] > (
554+ { } ,
555+ ) ;
556+ const [ watcherCount , setWatcherCount ] =
557+ useState < ChannelContextValue < At , Ch , Co , Ev , Me , Re , Us > [ 'watcherCount' ] > ( ) ;
558+ const [ watchers , setWatchers ] = useState <
559+ ChannelContextValue < At , Ch , Co , Ev , Me , Re , Us > [ 'watchers' ]
560+ > ( { } ) ;
564561
565562 const [ syncingChannel , setSyncingChannel ] = useState ( false ) ;
566563
@@ -569,7 +566,7 @@ const ChannelWithContext = <
569566 const channelId = channel ?. id || '' ;
570567 useEffect ( ( ) => {
571568 const initChannel = ( ) => {
572- if ( ! channel || ! shouldSyncChannel ) return ;
569+ if ( ! channel ) return ;
573570
574571 /**
575572 * Loading channel at first unread message requires channel to be initialized in the first place,
@@ -610,7 +607,7 @@ const ChannelWithContext = <
610607
611608 const threadPropsExists = ! ! threadProps ;
612609 useEffect ( ( ) => {
613- if ( threadProps && shouldSyncChannel ) {
610+ if ( threadProps ) {
614611 setThread ( threadProps ) ;
615612 if ( channel && threadProps ?. id ) {
616613 setThreadMessages ( channel . state . threads ?. [ threadProps . id ] || [ ] ) ;
@@ -689,7 +686,7 @@ const ChannelWithContext = <
689686 } ) ;
690687
691688 const connectionRecoveredHandler = ( ) => {
692- if ( channel && shouldSyncChannel ) {
689+ if ( channel ) {
693690 copyChannelState ( ) ;
694691 if ( thread ) {
695692 setThreadMessages ( [ ...channel . state . threads [ thread . id ] ] ) ;
@@ -698,31 +695,29 @@ const ChannelWithContext = <
698695 } ;
699696
700697 const connectionChangedHandler = ( event : ConnectionChangeEvent ) => {
701- if ( event . online && shouldSyncChannel ) {
698+ if ( event . online ) {
702699 resyncChannel ( ) ;
703700 }
704701 } ;
705702
706703 const handleEvent : EventHandler < At , Ch , Co , Ev , Me , Re , Us > = ( event ) => {
707- if ( shouldSyncChannel ) {
708- if ( thread ) {
709- const updatedThreadMessages =
710- ( thread . id && channel && channel . state . threads [ thread . id ] ) || threadMessages ;
711- setThreadMessages ( updatedThreadMessages ) ;
712- }
704+ if ( thread ) {
705+ const updatedThreadMessages =
706+ ( thread . id && channel && channel . state . threads [ thread . id ] ) || threadMessages ;
707+ setThreadMessages ( updatedThreadMessages ) ;
708+ }
713709
714- if ( channel && thread && event . message ?. id === thread . id ) {
715- const updatedThread = channel . state . formatMessage ( event . message ) ;
716- setThread ( updatedThread ) ;
717- }
710+ if ( channel && thread && event . message ?. id === thread . id ) {
711+ const updatedThread = channel . state . formatMessage ( event . message ) ;
712+ setThread ( updatedThread ) ;
713+ }
718714
719- if ( event . type === 'typing.start' || event . type === 'typing.stop' ) {
720- copyTypingState ( ) ;
721- } else if ( event . type === 'message.read' ) {
722- copyReadState ( ) ;
723- } else if ( channel ) {
724- copyChannelState ( ) ;
725- }
715+ if ( event . type === 'typing.start' || event . type === 'typing.stop' ) {
716+ copyTypingState ( ) ;
717+ } else if ( event . type === 'message.read' ) {
718+ copyReadState ( ) ;
719+ } else if ( channel ) {
720+ copyChannelState ( ) ;
726721 }
727722 } ;
728723
@@ -888,18 +883,12 @@ const ChannelWithContext = <
888883 const limit = 50 ;
889884 channel . state . threads [ parentID ] = [ ] ;
890885 const queryResponse = await channel . getReplies ( parentID , {
891- limit,
886+ limit : 50 ,
892887 } ) ;
893888
894889 const updatedHasMore = queryResponse . messages . length === limit ;
895890 const updatedThreadMessages = channel . state . threads [ parentID ] || [ ] ;
896891 loadMoreThreadFinished ( updatedHasMore , updatedThreadMessages ) ;
897- const { messages } = await channel . getMessagesById ( [ parentID ] ) ;
898- const [ threadMessage ] = messages ;
899- if ( threadMessage ) {
900- const formattedMessage = channel . state . formatMessage ( threadMessage ) ;
901- setThread ( formattedMessage ) ;
902- }
903892 } catch ( err ) {
904893 console . warn ( 'Thread loading request failed with error' , err ) ;
905894 setError ( err ) ;
@@ -1613,7 +1602,7 @@ const ChannelWithContext = <
16131602 loadingMoreRecentProp !== undefined ? loadingMoreRecentProp : loadingMoreRecent ,
16141603 loadMore,
16151604 loadMoreRecent,
1616- messages,
1605+ messages : messagesProp || messages ,
16171606 setLoadingMore,
16181607 setLoadingMoreRecent,
16191608 } ) ;
@@ -1792,52 +1781,13 @@ export const Channel = <
17921781 const { client } = useChatContext < At , Ch , Co , Ev , Me , Re , Us > ( ) ;
17931782 const { t } = useTranslationContext ( ) ;
17941783
1795- const shouldSyncChannel = props . thread ?. id ? ! ! props . threadList : true ;
1796-
1797- const {
1798- members,
1799- messages,
1800- read,
1801- setMembers,
1802- setMessages,
1803- setRead,
1804- setThreadMessages,
1805- setTyping,
1806- setWatcherCount,
1807- setWatchers,
1808- threadMessages,
1809- typing,
1810- watcherCount,
1811- watchers,
1812- } = useChannelState < At , Ch , Co , Ev , Me , Re , Us > (
1813- props . channel ,
1814- props . threadList ? props . thread ?. id : undefined ,
1815- ) ;
1816-
18171784 return (
18181785 < ChannelWithContext < At , Ch , Co , Ev , Me , Re , Us >
18191786 { ...{
18201787 client,
18211788 t,
18221789 } }
18231790 { ...props }
1824- shouldSyncChannel = { shouldSyncChannel }
1825- { ...{
1826- members,
1827- messages : props . messages || messages ,
1828- read,
1829- setMembers,
1830- setMessages,
1831- setRead,
1832- setThreadMessages,
1833- setTyping,
1834- setWatcherCount,
1835- setWatchers,
1836- threadMessages,
1837- typing,
1838- watcherCount,
1839- watchers,
1840- } }
18411791 />
18421792 ) ;
18431793} ;
0 commit comments