@@ -92,13 +92,12 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
92
92
}
93
93
} ) ;
94
94
95
- const isNewLineExistInChannelRef = useRef ( false ) ;
95
+ const [ isNewLineExistInChannel , setIsNewLineExistInChannel ] = useState ( false ) ;
96
96
const hasSeenNewLineRef = useRef ( false ) ;
97
97
const hasUserMarkedAsUnreadRef = useRef ( false ) ;
98
98
99
99
useEffect ( ( ) => {
100
- isNewLineExistInChannelRef . current =
101
- channel . myLastRead < ( channel . lastMessage ?. createdAt ?? Number . MIN_SAFE_INTEGER ) ;
100
+ setIsNewLineExistInChannel ( channel . myLastRead < ( channel . lastMessage ?. createdAt ?? Number . MIN_SAFE_INTEGER ) ) ;
102
101
} , [ channel . url ] ) ;
103
102
104
103
const onNewLineSeenChange = useFreshCallback ( ( hasSeenNewLine : boolean ) => {
@@ -114,7 +113,7 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
114
113
if (
115
114
! scrolledAwayFromBottom &&
116
115
! hasUserMarkedAsUnreadRef . current &&
117
- ( hasSeenNewLineRef . current || ! isNewLineExistInChannelRef . current )
116
+ ( hasSeenNewLineRef . current || ! isNewLineExistInChannel )
118
117
) {
119
118
confirmAndMarkAsRead ( channels ) ;
120
119
}
@@ -154,7 +153,7 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
154
153
}
155
154
} else if ( ctx ?. source === GroupChannelEventSource . EVENT_CHANNEL_UNREAD ) {
156
155
if ( ctx . userIds . includes ( currentUser ?. userId ?? '' ) ) {
157
- isNewLineExistInChannelRef . current = true ;
156
+ setIsNewLineExistInChannel ( true ) ;
158
157
groupChannelPubSub . publish ( { type : 'ON_MARKED_AS_UNREAD_BY_CURRENT_USER' } ) ;
159
158
}
160
159
}
@@ -281,7 +280,7 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
281
280
if ( ! value ) {
282
281
resetNewMessages ( ) ;
283
282
if ( sbOptions . uikit . groupChannel . channel . enableMarkAsUnread ) {
284
- if ( ! hasUserMarkedAsUnreadRef . current && ( hasSeenNewLineRef . current || ! isNewLineExistInChannelRef . current ) ) {
283
+ if ( ! hasUserMarkedAsUnreadRef . current && ( hasSeenNewLineRef . current || ! isNewLineExistInChannel ) ) {
285
284
confirmAndMarkAsRead ( [ channel ] ) ;
286
285
}
287
286
}
@@ -331,7 +330,7 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
331
330
onPressMediaMessage = { _onPressMediaMessage }
332
331
flatListComponent = { flatListComponent }
333
332
flatListProps = { memoizedFlatListProps }
334
- isNewLineExistInChannel = { isNewLineExistInChannelRef . current }
333
+ isNewLineExistInChannel = { isNewLineExistInChannel }
335
334
onNewLineSeenChange = { onNewLineSeenChange }
336
335
onUserMarkedAsUnreadChange = { onUserMarkedAsUnreadChange }
337
336
/>
0 commit comments