From 1e77308175fb684fbc0ed8ac61e966d4396622f2 Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Tue, 21 Jan 2025 18:20:30 +0100 Subject: [PATCH] Chat Info: Rerender status every minute (#5441) --- src/components/common/PrivateChatInfo.tsx | 5 +++++ src/hooks/schedulers/useIntervalForceUpdate.ts | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/hooks/schedulers/useIntervalForceUpdate.ts diff --git a/src/components/common/PrivateChatInfo.tsx b/src/components/common/PrivateChatInfo.tsx index 1e6c3a67d..b366be498 100644 --- a/src/components/common/PrivateChatInfo.tsx +++ b/src/components/common/PrivateChatInfo.tsx @@ -16,6 +16,7 @@ import { selectChatMessages, selectUser, selectUserStatus } from '../../global/s import buildClassName from '../../util/buildClassName'; import renderText from './helpers/renderText'; +import useIntervalForceUpdate from '../../hooks/schedulers/useIntervalForceUpdate'; import useLastCallback from '../../hooks/useLastCallback'; import useOldLang from '../../hooks/useOldLang'; @@ -66,6 +67,8 @@ type StateProps = isSynced?: boolean; }; +const UPDATE_INTERVAL = 1000 * 60; // 1 min + const PrivateChatInfo: FC = ({ customPeer, typingStatus, @@ -116,6 +119,8 @@ const PrivateChatInfo: FC = ({ } }, [userId, withFullInfo, withMediaViewer, isSynced]); + useIntervalForceUpdate(UPDATE_INTERVAL); + const handleAvatarViewerOpen = useLastCallback( (e: React.MouseEvent, hasMedia: boolean) => { if (user && hasMedia) { diff --git a/src/hooks/schedulers/useIntervalForceUpdate.ts b/src/hooks/schedulers/useIntervalForceUpdate.ts new file mode 100644 index 000000000..ea10366f2 --- /dev/null +++ b/src/hooks/schedulers/useIntervalForceUpdate.ts @@ -0,0 +1,8 @@ +import useForceUpdate from '../useForceUpdate'; +import useInterval from './useInterval'; + +export default function useIntervalForceUpdate(interval?: number) { + const forceUpdate = useForceUpdate(); + + useInterval(forceUpdate, interval, true); +}