Skip to content

Commit de44ec3

Browse files
authored
1 parent 314f63a commit de44ec3

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/modules/GroupChannel/context/GroupChannelProvider.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { PubSubTypes } from '../../../lib/pubSub';
2828
import { useMessageActions } from './hooks/useMessageActions';
2929
import { usePreventDuplicateRequest } from './hooks/usePreventDuplicateRequest';
3030
import { getIsReactionEnabled } from '../../../utils/getIsReactionEnabled';
31+
import { SCROLL_BUFFER } from '../../../utils/consts';
3132

3233
type OnBeforeHandler<T> = (params: T) => T | Promise<T>;
3334
type 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
},

src/modules/GroupChannel/context/hooks/useMessageListScroll.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)