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