diff options
Diffstat (limited to 'src/screens/Messages/List/index.tsx')
-rw-r--r-- | src/screens/Messages/List/index.tsx | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/screens/Messages/List/index.tsx b/src/screens/Messages/List/index.tsx index 26b6df23b..7c67c59d3 100644 --- a/src/screens/Messages/List/index.tsx +++ b/src/screens/Messages/List/index.tsx @@ -1,16 +1,20 @@ -import React, {useCallback, useMemo, useState} from 'react' +import React, {useCallback, useEffect, useMemo, useState} from 'react' import {View} from 'react-native' import {ChatBskyConvoDefs} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' +import {useFocusEffect} from '@react-navigation/native' import {NativeStackScreenProps} from '@react-navigation/native-stack' +import {useAppState} from '#/lib/hooks/useAppState' import {useInitialNumToRender} from '#/lib/hooks/useInitialNumToRender' import {MessagesTabNavigatorParams} from '#/lib/routes/types' import {cleanError} from '#/lib/strings/errors' import {logger} from '#/logger' import {isNative} from '#/platform/detection' -import {useListConvos} from '#/state/queries/messages/list-converations' +import {MESSAGE_SCREEN_POLL_INTERVAL} from '#/state/messages/convo/const' +import {useMessagesEventBus} from '#/state/messages/events' +import {useListConvosQuery} from '#/state/queries/messages/list-converations' import {List} from '#/view/com/util/List' import {ViewHeader} from '#/view/com/util/ViewHeader' import {CenteredView} from '#/view/com/util/Views' @@ -52,7 +56,7 @@ export function MessagesScreen({navigation, route}: Props) { // this tab. We should immediately push to the conversation after pressing the notification. // After we push, reset with `setParams` so that this effect will fire next time we press a notification, even if // the conversation is the same as before - React.useEffect(() => { + useEffect(() => { if (pushToConversation) { navigation.navigate('MessagesConversation', { conversation: pushToConversation, @@ -61,6 +65,22 @@ export function MessagesScreen({navigation, route}: Props) { } }, [navigation, pushToConversation]) + // Request the poll interval to be 10s (or whatever the MESSAGE_SCREEN_POLL_INTERVAL is set to in the future) + // but only when the screen is active + const messagesBus = useMessagesEventBus() + const state = useAppState() + const isActive = state === 'active' + useFocusEffect( + useCallback(() => { + if (isActive) { + const unsub = messagesBus.requestPollInterval( + MESSAGE_SCREEN_POLL_INTERVAL, + ) + return () => unsub() + } + }, [messagesBus, isActive]), + ) + const renderButton = useCallback(() => { return ( <Link @@ -88,7 +108,7 @@ export function MessagesScreen({navigation, route}: Props) { isError, error, refetch, - } = useListConvos({refetchInterval: 15_000}) + } = useListConvosQuery() useRefreshOnFocus(refetch) |