CI / Build & Quality Checks (pull_request) Successful in 2m40s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 8s
CI / Playwright smoke (e2e) (pull_request) Successful in 17m50s
A hung Synapse (accepts connections, never answers) kept sync SYNCING for up to 110 s (pollTimeout 30 s + the SDK's 80 s buffer), so no strip showed and Kuma was never asked. A watchdog now notices a /sync overdue by 45 s, confirms with a 5 s GET /_matrix/client/versions, then shows "Lotus Chat's server isn't responding…" and polls Kuma at once. Fixes #317 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
137 lines
4.4 KiB
TypeScript
137 lines
4.4 KiB
TypeScript
import { MatrixClient, SyncState } from 'matrix-js-sdk';
|
|
import React, { useCallback, useState } from 'react';
|
|
import { useAtomValue } from 'jotai';
|
|
import { Box, config, Line, Text } from 'folds';
|
|
import { useSyncState } from '../../hooks/useSyncState';
|
|
import { ContainerColor } from '../../styles/ContainerColor.css';
|
|
import { serverStatusAtom } from '../../state/serverStatus';
|
|
import { serverConfirmedUpSince } from '../../utils/kumaStatus';
|
|
import { homeserverStalledAtom } from '../../hooks/useHomeserverStall';
|
|
|
|
type StateData = {
|
|
current: SyncState | null;
|
|
previous: SyncState | null | undefined;
|
|
};
|
|
|
|
type SyncStatusProps = {
|
|
mx: MatrixClient;
|
|
};
|
|
export function SyncStatus({ mx }: SyncStatusProps) {
|
|
const serverStatus = useAtomValue(serverStatusAtom);
|
|
const stalled = useAtomValue(homeserverStalledAtom);
|
|
const [stateData, setStateData] = useState<StateData>({
|
|
current: null,
|
|
previous: undefined,
|
|
});
|
|
|
|
useSyncState(
|
|
mx,
|
|
useCallback((current, previous) => {
|
|
setStateData((s) => {
|
|
if (s.current === current && s.previous === previous) {
|
|
return s;
|
|
}
|
|
return { current, previous };
|
|
});
|
|
}, []),
|
|
);
|
|
|
|
// [Gitea #124] When Kuma confirms the homeserver is down, the status banner
|
|
// says so ("Lotus Chat's server is down…") instead of "Connection Lost!".
|
|
const serverDown = serverStatus.status?.homeserver === 'down';
|
|
// Only blame the user's connection when Kuma has checked the server since
|
|
// the drop and it was fine (a stale "up" from before proves nothing).
|
|
const serverUp = serverConfirmedUpSince(serverStatus.status, serverStatus.lostAt);
|
|
|
|
// [Gitea #317] Sync still says SYNCING, but the server has stopped answering.
|
|
if (stalled && stateData.current === SyncState.Syncing && !serverDown) {
|
|
return (
|
|
<Box direction="Column" shrink="No">
|
|
<Box
|
|
className={ContainerColor({ variant: 'Warning' })}
|
|
style={{ padding: `${config.space.S100} 0` }}
|
|
alignItems="Center"
|
|
justifyContent="Center"
|
|
role="status"
|
|
aria-live="polite"
|
|
>
|
|
<Text size="L400">
|
|
Lotus Chat's server isn't responding. Messages will send when it's back.
|
|
Still trying…
|
|
</Text>
|
|
</Box>
|
|
<Line variant="Warning" size="300" />
|
|
</Box>
|
|
);
|
|
}
|
|
|
|
if (
|
|
(stateData.current === SyncState.Prepared ||
|
|
stateData.current === SyncState.Syncing ||
|
|
stateData.current === SyncState.Catchup) &&
|
|
stateData.previous !== SyncState.Syncing
|
|
) {
|
|
return (
|
|
<Box direction="Column" shrink="No">
|
|
<Box
|
|
className={ContainerColor({ variant: 'Success' })}
|
|
style={{ padding: `${config.space.S100} 0` }}
|
|
alignItems="Center"
|
|
justifyContent="Center"
|
|
role="status"
|
|
aria-live="polite"
|
|
>
|
|
<Text size="L400">Connecting...</Text>
|
|
</Box>
|
|
<Line variant="Success" size="300" />
|
|
</Box>
|
|
);
|
|
}
|
|
|
|
if (stateData.current === SyncState.Reconnecting && !serverDown) {
|
|
return (
|
|
<Box direction="Column" shrink="No">
|
|
<Box
|
|
className={ContainerColor({ variant: 'Warning' })}
|
|
style={{ padding: `${config.space.S100} 0` }}
|
|
alignItems="Center"
|
|
justifyContent="Center"
|
|
role="status"
|
|
aria-live="polite"
|
|
>
|
|
<Text size="L400">
|
|
{serverUp
|
|
? "Connection lost. Our status checks say Lotus Chat's server is up, so it may be your internet connection. Reconnecting…"
|
|
: 'Connection Lost! Reconnecting...'}
|
|
</Text>
|
|
</Box>
|
|
<Line variant="Warning" size="300" />
|
|
</Box>
|
|
);
|
|
}
|
|
|
|
if (stateData.current === SyncState.Error && !serverDown) {
|
|
return (
|
|
<Box direction="Column" shrink="No">
|
|
<Box
|
|
className={ContainerColor({ variant: 'Critical' })}
|
|
style={{ padding: `${config.space.S100} 0` }}
|
|
alignItems="Center"
|
|
justifyContent="Center"
|
|
role="alert"
|
|
aria-live="assertive"
|
|
>
|
|
<Text size="L400">
|
|
{serverUp
|
|
? "Connection lost. Our status checks say Lotus Chat's server is up, so check your internet connection."
|
|
: 'Connection Lost!'}
|
|
</Text>
|
|
</Box>
|
|
<Line variant="Critical" size="300" />
|
|
</Box>
|
|
);
|
|
}
|
|
|
|
return null;
|
|
}
|