@@ -694,7 +694,8 @@ const ChannelWithContext = <
694694 const [ deleted , setDeleted ] = useState < boolean > ( false ) ;
695695 const [ editing , setEditing ] = useState < MessageType < StreamChatGenerics > | undefined > ( undefined ) ;
696696 const [ error , setError ] = useState < Error | boolean > ( false ) ;
697- const [ lastRead , setLastRead ] = useState < ChannelContextValue < StreamChatGenerics > [ 'lastRead' ] > ( ) ;
697+ const lastRead = useRef < Date | undefined > ( new Date ( ) ) ;
698+
698699 const [ quotedMessage , setQuotedMessage ] = useState < MessageType < StreamChatGenerics > | undefined > (
699700 undefined ,
700701 ) ;
@@ -824,7 +825,6 @@ const ChannelWithContext = <
824825 useEffect ( ( ) => {
825826 let listener : ReturnType < typeof channel . on > ;
826827 const initChannel = async ( ) => {
827- setLastRead ( new Date ( ) ) ;
828828 const unreadCount = channel . countUnread ( ) ;
829829 if ( ! channel || ! shouldSyncChannel || channel . offlineMode ) {
830830 return ;
@@ -950,14 +950,15 @@ const ChannelWithContext = <
950950 return ;
951951 }
952952
953+ lastRead . current = new Date ( ) ;
953954 if ( doMarkReadRequest ) {
954955 doMarkReadRequest ( channel , updateChannelUnreadState ? setChannelUnreadState : undefined ) ;
955956 } else {
956957 try {
957958 const response = await channel . markRead ( ) ;
958959 if ( updateChannelUnreadState && response && lastRead ) {
959960 setChannelUnreadState ( {
960- last_read : lastRead ,
961+ last_read : lastRead . current ,
961962 last_read_message_id : response ?. event . last_read_message_id ,
962963 unread_messages : 0 ,
963964 } ) ;
@@ -1725,7 +1726,7 @@ const ChannelWithContext = <
17251726 hideStickyDateHeader,
17261727 highlightedMessageId,
17271728 isChannelActive : shouldSyncChannel ,
1728- lastRead,
1729+ lastRead : lastRead . current ,
17291730 loadChannelAroundMessage,
17301731 loadChannelAtFirstUnreadMessage,
17311732 loading : channelMessagesState . loading ,
@@ -1738,7 +1739,7 @@ const ChannelWithContext = <
17381739 reloadChannel,
17391740 scrollToFirstUnreadThreshold,
17401741 setChannelUnreadState,
1741- setLastRead,
1742+ setLastRead : ( ) => { } ,
17421743 setTargetedMessage,
17431744 StickyHeader,
17441745 targetedMessage,
0 commit comments