diff --git a/src/app/features/settings/about/About.tsx b/src/app/features/settings/about/About.tsx index 15c4b65a58..d51cae0d80 100644 --- a/src/app/features/settings/about/About.tsx +++ b/src/app/features/settings/about/About.tsx @@ -1,4 +1,4 @@ -import { Box, Text, IconButton, Icon, Icons, Scroll, Button, config, toRem } from 'folds'; +import { Box, Text, IconButton, Icon, Icons, Scroll, Button, config, toRem, Spinner } from 'folds'; import { Page, PageContent, PageHeader } from '$components/page'; import { SequenceCard } from '$components/sequence-card'; import { SettingTile } from '$components/setting-tile'; @@ -6,6 +6,141 @@ import CinnySVG from '$public/res/svg/cinny.svg'; import { clearCacheAndReload } from '$client/initMatrix'; import { useMatrixClient } from '$hooks/useMatrixClient'; import { SequenceCardStyle } from '$features/settings/styles.css'; +import { Method } from '$types/matrix-sdk'; +import { useState } from 'react'; + +export function HomeserverInfo() { + const mx = useMatrixClient(); + const [federationUrl, setFederationUrl] = useState(mx.baseUrl); + const [version, setVersion] = useState(undefined); + + // By default assume the federationUrl is the same as the baseUrl. + if (!version) + mx.http + .request(Method.Get, '/version', undefined, undefined, { + prefix: '/_matrix/federation/v1', + baseUrl: federationUrl, + }) + .then((fetched_version) => setVersion(fetched_version)) + .catch((error) => { + if (federationUrl === mx.baseUrl) { + // Maybe they are *not* the same actually. + mx.http + .request(Method.Get, '/server', undefined, undefined, { + prefix: '/.well-known/matrix', + baseUrl: `https://${mx.getSafeUserId().split(':')[1]}`, + }) + .then((well_known: any) => { + const newUrl = `https://${well_known['m.server'].split(':')[0]}`; + if (newUrl !== federationUrl) { + setFederationUrl(newUrl); + } + }) + .catch((error2) => setVersion({ error: error2 })); + } else { + setVersion({ error }); + } + }); + + return ( + + Homeserver + + + + + + {mx.baseUrl} + + } + /> + + {federationUrl !== mx.baseUrl && ( + + + {federationUrl} + + } + /> + + )} + {version ? ( + <> + {version.error && ( + + {version.error.message} + + )} + {version.server?.name && ( + + + + )} + {version.server?.version && ( + + + + )} + {version.server?.compiler && ( + + + + )} + + ) : ( + + + + )} + + ); +} type AboutProps = { requestClose: () => void; @@ -107,6 +242,7 @@ export function About({ requestClose }: AboutProps) { /> + Credits