Message List: Disable polling when hidden (#6327)
This commit is contained in:
parent
789dec658c
commit
74d1fc97cb
@ -81,7 +81,7 @@ const Document = ({
|
||||
const [isFileIpDialogOpen, openFileIpDialog, closeFileIpDialog] = useFlag();
|
||||
const [shouldNotWarnAboutFiles, setShouldNotWarnAboutFiles] = useState(false);
|
||||
|
||||
const { fileName, size, timestamp, mimeType } = document;
|
||||
const { fileName, size, mimeType } = document;
|
||||
const extension = getDocumentExtension(document) || '';
|
||||
|
||||
const isIntersecting = useIsIntersecting(ref, observeIntersection);
|
||||
@ -190,7 +190,7 @@ const Document = ({
|
||||
name={fileName}
|
||||
extension={extension}
|
||||
size={size}
|
||||
timestamp={datetime || timestamp}
|
||||
timestamp={datetime}
|
||||
thumbnailDataUri={thumbDataUri}
|
||||
previewData={localBlobUrl || previewData}
|
||||
smaller={smaller}
|
||||
|
||||
@ -52,7 +52,7 @@ import {
|
||||
selectUserFullInfo,
|
||||
} from '../../global/selectors';
|
||||
import { selectIsChatRestricted } from '../../global/selectors/chats';
|
||||
import { selectActiveRestrictionReasons } from '../../global/selectors/messages';
|
||||
import { selectActiveRestrictionReasons, selectCurrentMessageList } from '../../global/selectors/messages';
|
||||
import animateScroll, { isAnimatingScroll, restartCurrentScrollAnimation } from '../../util/animateScroll';
|
||||
import buildClassName from '../../util/buildClassName';
|
||||
import { isUserId } from '../../util/entities/ids';
|
||||
@ -143,6 +143,7 @@ type StateProps = {
|
||||
canTranslate?: boolean;
|
||||
translationLanguage?: string;
|
||||
shouldAutoTranslate?: boolean;
|
||||
isActive?: boolean;
|
||||
};
|
||||
|
||||
enum Content {
|
||||
@ -184,6 +185,7 @@ const MessageList: FC<OwnProps & StateProps> = ({
|
||||
isChannelWithAvatars,
|
||||
canPost,
|
||||
isSynced,
|
||||
isActive,
|
||||
// eslint-disable-next-line @typescript-eslint/no-shadow
|
||||
isChatMonoforum,
|
||||
isReady,
|
||||
@ -381,7 +383,7 @@ const MessageList: FC<OwnProps & StateProps> = ({
|
||||
threadId, isChatWithSelf, channelJoinInfo]);
|
||||
|
||||
useInterval(() => {
|
||||
if (!messageIds || !messagesById || type === 'scheduled' || isAccountFrozen) return;
|
||||
if (!messageIds || !messagesById || type === 'scheduled' || isAccountFrozen || !isActive) return;
|
||||
if (!isChannelChat && !isGroupChat) return;
|
||||
|
||||
const ids = messageIds.filter((id) => {
|
||||
@ -395,7 +397,7 @@ const MessageList: FC<OwnProps & StateProps> = ({
|
||||
}, MESSAGE_REACTIONS_POLLING_INTERVAL);
|
||||
|
||||
useInterval(() => {
|
||||
if (!messageIds || !messagesById || type === 'scheduled') {
|
||||
if (!messageIds || !messagesById || type === 'scheduled' || !isActive) {
|
||||
return;
|
||||
}
|
||||
const storyDataList = messageIds.map((id) => messagesById[id]?.content.storyData).filter(Boolean);
|
||||
@ -417,7 +419,7 @@ const MessageList: FC<OwnProps & StateProps> = ({
|
||||
}, MESSAGE_STORY_POLLING_INTERVAL);
|
||||
|
||||
useInterval(() => {
|
||||
if (!messageIds || !messagesById || threadId !== MAIN_THREAD_ID || type === 'scheduled') {
|
||||
if (!messageIds || !messagesById || threadId !== MAIN_THREAD_ID || type === 'scheduled' || !isActive) {
|
||||
return;
|
||||
}
|
||||
const global = getGlobal();
|
||||
@ -430,7 +432,7 @@ const MessageList: FC<OwnProps & StateProps> = ({
|
||||
}, MESSAGE_COMMENTS_POLLING_INTERVAL, true);
|
||||
|
||||
useInterval(() => {
|
||||
if (!messageIds || !messagesById || threadId !== MAIN_THREAD_ID || type === 'scheduled') {
|
||||
if (!messageIds || !messagesById || threadId !== MAIN_THREAD_ID || type === 'scheduled' || !isActive) {
|
||||
return;
|
||||
}
|
||||
const ids = messageIds.filter((id) => messagesById[id]?.factCheck?.shouldFetch);
|
||||
@ -877,7 +879,12 @@ export default memo(withGlobal<OwnProps>(
|
||||
const shouldAutoTranslate = chat?.hasAutoTranslation;
|
||||
const translationLanguage = selectTranslationLanguage(global);
|
||||
|
||||
const currentMessageList = selectCurrentMessageList(global);
|
||||
const isActive = currentMessageList && currentMessageList.chatId === chatId
|
||||
&& currentMessageList.threadId === threadId && currentMessageList.type === type;
|
||||
|
||||
return {
|
||||
isActive,
|
||||
areAdsEnabled,
|
||||
isChatLoaded: true,
|
||||
isRestricted,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user