fix: dont use app focus all the time

pull/3020/head
William Grant 1 year ago
parent e6148c2939
commit 2a292f8134

@ -1,5 +1,5 @@
import classNames from 'classnames'; import classNames from 'classnames';
import { isEmpty, noop } from 'lodash'; import { isEmpty } from 'lodash';
import moment from 'moment'; import moment from 'moment';
import React, { createContext, useCallback, useContext, useLayoutEffect, useState } from 'react'; import React, { createContext, useCallback, useContext, useLayoutEffect, useState } from 'react';
import { InView } from 'react-intersection-observer'; import { InView } from 'react-intersection-observer';
@ -17,7 +17,6 @@ import {
getQuotedMessageToAnimate, getQuotedMessageToAnimate,
getShouldHighlightMessage, getShouldHighlightMessage,
} from '../../../../state/selectors/conversations'; } from '../../../../state/selectors/conversations';
import { getIsAppFocused } from '../../../../state/selectors/section';
import { useSelectedIsPrivate } from '../../../../state/selectors/selectedConversation'; import { useSelectedIsPrivate } from '../../../../state/selectors/selectedConversation';
import { canDisplayImage } from '../../../../types/Attachment'; import { canDisplayImage } from '../../../../types/Attachment';
import { ScrollToLoadedMessageContext } from '../../SessionMessagesListContainer'; import { ScrollToLoadedMessageContext } from '../../SessionMessagesListContainer';
@ -84,8 +83,6 @@ const StyledAvatarContainer = styled.div`
`; `;
export const MessageContent = (props: Props) => { export const MessageContent = (props: Props) => {
const isAppFocused = useSelector(getIsAppFocused);
const [highlight, setHighlight] = useState(false); const [highlight, setHighlight] = useState(false);
const [didScroll, setDidScroll] = useState(false); const [didScroll, setDidScroll] = useState(false);
const contentProps = useSelector((state: StateType) => const contentProps = useSelector((state: StateType) =>
@ -101,7 +98,7 @@ export const MessageContent = (props: Props) => {
const [imageBroken, setImageBroken] = useState(false); const [imageBroken, setImageBroken] = useState(false);
const onVisible = (inView: boolean, _: IntersectionObserverEntry) => { const onVisible = (inView: boolean, _: IntersectionObserverEntry) => {
if (isAppFocused && inView) { if (inView) {
if (isMessageVisible !== true) { if (isMessageVisible !== true) {
setMessageIsVisible(true); setMessageIsVisible(true);
} }
@ -185,7 +182,7 @@ export const MessageContent = (props: Props) => {
<InView <InView
id={`inview-content-${props.messageId}`} id={`inview-content-${props.messageId}`}
as={'div'} as={'div'}
onChange={isAppFocused ? onVisible : noop} onChange={onVisible}
threshold={0} threshold={0}
rootMargin="500px 0px 500px 0px" rootMargin="500px 0px 500px 0px"
triggerOnce={false} triggerOnce={false}

@ -144,7 +144,7 @@ export const ReadableMessage = (props: ReadableMessageProps) => {
} }
// this part is just handling the marking of the message as read if needed // this part is just handling the marking of the message as read if needed
if (inView && isAppFocused) { if (inView) {
if (isUnread) { if (isUnread) {
// TODOLATER this is pretty expensive and should instead use values from the redux store // TODOLATER this is pretty expensive and should instead use values from the redux store
const found = await Data.getMessageById(messageId); const found = await Data.getMessageById(messageId);

Loading…
Cancel
Save