File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed
src/modules/GroupChannel/context Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import { PubSubTypes } from '../../../lib/pubSub';
2828import { useMessageActions } from './hooks/useMessageActions' ;
2929import { usePreventDuplicateRequest } from './hooks/usePreventDuplicateRequest' ;
3030import { getIsReactionEnabled } from '../../../utils/getIsReactionEnabled' ;
31+ import { SCROLL_BUFFER } from '../../../utils/consts' ;
3132
3233type OnBeforeHandler < T > = ( params : T ) => T | Promise < T > ;
3334type MessageListQueryParamsType = Omit < MessageCollectionParams , 'filter' > & MessageFilterParams ;
@@ -180,7 +181,9 @@ export const GroupChannelProvider = (props: GroupChannelProviderProps) => {
180181 collectionCreator : getCollectionCreator ( currentChannel , messageListQueryParams ) ,
181182 shouldCountNewMessages : ( ) => ! isScrollBottomReached ,
182183 markAsRead : ( channels ) => {
183- if ( ! disableMarkAsRead && isScrollBottomReached ) {
184+ // isScrollBottomReached is a state that is updated after the render is completed.
185+ // So, we use scrollDistanceFromBottomRef to check quickly if the scroll is at the bottom.
186+ if ( ! disableMarkAsRead && scrollDistanceFromBottomRef . current <= SCROLL_BUFFER ) {
184187 channels . forEach ( ( it ) => markAsReadScheduler . push ( it ) ) ;
185188 }
186189 } ,
Original file line number Diff line number Diff line change @@ -47,6 +47,12 @@ export function useMessageListScroll(behavior: 'smooth' | 'auto') {
4747 const [ scrollPubSub ] = useState ( ( ) => pubSubFactory < ScrollTopics , ScrollTopicUnion > ( ) ) ;
4848 const [ isScrollBottomReached , setIsScrollBottomReached ] = useState ( false ) ;
4949
50+ // If there is no area to scroll, it is considered as scroll bottom reached.
51+ if ( isScrollBottomReached === false && scrollRef . current && scrollRef . current . scrollHeight <= scrollRef . current . clientHeight ) {
52+ scrollDistanceFromBottomRef . current = 0 ;
53+ setIsScrollBottomReached ( true ) ;
54+ }
55+
5056 useLayoutEffect ( ( ) => {
5157 const unsubscribes : { remove ( ) : void } [ ] = [ ] ;
5258
You can’t perform that action at this time.
0 commit comments