Message List: Fix marking messages read when in background (#1467)

This commit is contained in:
Alexander Zinchuk 2021-09-25 12:36:12 +03:00
parent b3beaca5fc
commit 8834fe9ee7
2 changed files with 8 additions and 1 deletions

View File

@ -31,6 +31,7 @@ export default function useMessageObservers(
} = useIntersectionObserver({
rootRef: containerRef,
throttleMs: INTERSECTION_THROTTLE_FOR_READING,
isAutoUnfreezeDisabled: true,
}, (entries) => {
if (type !== 'thread') {
return;

View File

@ -32,6 +32,7 @@ export function useIntersectionObserver({
margin,
threshold,
isDisabled,
isAutoUnfreezeDisabled = false,
}: {
rootRef: RefObject<HTMLDivElement>;
throttleMs?: number;
@ -40,6 +41,7 @@ export function useIntersectionObserver({
margin?: number;
threshold?: number | number[];
isDisabled?: boolean;
isAutoUnfreezeDisabled?: boolean;
}, rootCallback?: RootCallback): Response {
const controllerRef = useRef<IntersectionController>();
const rootCallbackRef = useRef<RootCallback>();
@ -65,6 +67,10 @@ export function useIntersectionObserver({
const freeze = useCallback(() => {
freezeFlagsRef.current++;
if (isAutoUnfreezeDisabled) {
return;
}
if (autoUnfreezeTimeoutRef.current) {
clearTimeout(autoUnfreezeTimeoutRef.current);
autoUnfreezeTimeoutRef.current = undefined;
@ -81,7 +87,7 @@ export function useIntersectionObserver({
freezeFlagsRef.current = 1;
unfreeze();
}, AUTO_UNFREEZE_TIMEOUT);
}, [unfreeze]);
}, [isAutoUnfreezeDisabled, unfreeze]);
useHeavyAnimationCheck(freeze, unfreeze);