Extract ValidatedServerConfig (#9054)

This commit is contained in:
Michael Weimann 2022-07-14 15:03:34 +02:00 committed by GitHub
parent 7b7181be18
commit 742b21ca46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 45 additions and 24 deletions

View file

@ -17,7 +17,7 @@ limitations under the License.
import { IClientWellKnown } from "matrix-js-sdk/src/matrix"; import { IClientWellKnown } from "matrix-js-sdk/src/matrix";
import { ValidatedServerConfig } from "./utils/AutoDiscoveryUtils"; import { ValidatedServerConfig } from "./utils/ValidatedServerConfig";
// Convention decision: All config options are lower_snake_case // Convention decision: All config options are lower_snake_case
// We use an isolated file for the interface so we can mess around with the eslint options. // We use an isolated file for the interface so we can mess around with the eslint options.

View file

@ -61,7 +61,7 @@ import ThemeController from "../../settings/controllers/ThemeController";
import { startAnyRegistrationFlow } from "../../Registration"; import { startAnyRegistrationFlow } from "../../Registration";
import { messageForSyncError } from '../../utils/ErrorUtils'; import { messageForSyncError } from '../../utils/ErrorUtils';
import ResizeNotifier from "../../utils/ResizeNotifier"; import ResizeNotifier from "../../utils/ResizeNotifier";
import AutoDiscoveryUtils, { ValidatedServerConfig } from "../../utils/AutoDiscoveryUtils"; import AutoDiscoveryUtils from "../../utils/AutoDiscoveryUtils";
import DMRoomMap from '../../utils/DMRoomMap'; import DMRoomMap from '../../utils/DMRoomMap';
import ThemeWatcher from "../../settings/watchers/ThemeWatcher"; import ThemeWatcher from "../../settings/watchers/ThemeWatcher";
import { FontWatcher } from '../../settings/watchers/FontWatcher'; import { FontWatcher } from '../../settings/watchers/FontWatcher';
@ -131,6 +131,7 @@ import { leaveRoomBehaviour } from "../../utils/leave-behaviour";
import VideoChannelStore from "../../stores/VideoChannelStore"; import VideoChannelStore from "../../stores/VideoChannelStore";
import { IRoomStateEventsActionPayload } from "../../actions/MatrixActionCreators"; import { IRoomStateEventsActionPayload } from "../../actions/MatrixActionCreators";
import { UseCaseSelection } from '../views/elements/UseCaseSelection'; import { UseCaseSelection } from '../views/elements/UseCaseSelection';
import { ValidatedServerConfig } from '../../utils/ValidatedServerConfig';
// legacy export // legacy export
export { default as Views } from "../../Views"; export { default as Views } from "../../Views";

View file

@ -24,7 +24,7 @@ import { createClient } from "matrix-js-sdk/src/matrix";
import { _t, _td } from '../../../languageHandler'; import { _t, _td } from '../../../languageHandler';
import Modal from "../../../Modal"; import Modal from "../../../Modal";
import PasswordReset from "../../../PasswordReset"; import PasswordReset from "../../../PasswordReset";
import AutoDiscoveryUtils, { ValidatedServerConfig } from "../../../utils/AutoDiscoveryUtils"; import AutoDiscoveryUtils from "../../../utils/AutoDiscoveryUtils";
import AuthPage from "../../views/auth/AuthPage"; import AuthPage from "../../views/auth/AuthPage";
import ServerPicker from "../../views/elements/ServerPicker"; import ServerPicker from "../../views/elements/ServerPicker";
import EmailField from "../../views/auth/EmailField"; import EmailField from "../../views/auth/EmailField";
@ -39,6 +39,7 @@ import AuthBody from "../../views/auth/AuthBody";
import PassphraseConfirmField from "../../views/auth/PassphraseConfirmField"; import PassphraseConfirmField from "../../views/auth/PassphraseConfirmField";
import AccessibleButton from '../../views/elements/AccessibleButton'; import AccessibleButton from '../../views/elements/AccessibleButton';
import StyledCheckbox from '../../views/elements/StyledCheckbox'; import StyledCheckbox from '../../views/elements/StyledCheckbox';
import { ValidatedServerConfig } from '../../../utils/ValidatedServerConfig';
enum Phase { enum Phase {
// Show the forgot password inputs // Show the forgot password inputs

View file

@ -23,7 +23,7 @@ import { _t, _td } from '../../../languageHandler';
import Login, { ISSOFlow, LoginFlow } from '../../../Login'; import Login, { ISSOFlow, LoginFlow } from '../../../Login';
import SdkConfig from '../../../SdkConfig'; import SdkConfig from '../../../SdkConfig';
import { messageForResourceLimitError } from '../../../utils/ErrorUtils'; import { messageForResourceLimitError } from '../../../utils/ErrorUtils';
import AutoDiscoveryUtils, { ValidatedServerConfig } from "../../../utils/AutoDiscoveryUtils"; import AutoDiscoveryUtils from "../../../utils/AutoDiscoveryUtils";
import AuthPage from "../../views/auth/AuthPage"; import AuthPage from "../../views/auth/AuthPage";
import PlatformPeg from '../../../PlatformPeg'; import PlatformPeg from '../../../PlatformPeg';
import SettingsStore from "../../../settings/SettingsStore"; import SettingsStore from "../../../settings/SettingsStore";
@ -37,6 +37,7 @@ import ServerPicker from "../../views/elements/ServerPicker";
import AuthBody from "../../views/auth/AuthBody"; import AuthBody from "../../views/auth/AuthBody";
import AuthHeader from "../../views/auth/AuthHeader"; import AuthHeader from "../../views/auth/AuthHeader";
import AccessibleButton from '../../views/elements/AccessibleButton'; import AccessibleButton from '../../views/elements/AccessibleButton';
import { ValidatedServerConfig } from '../../../utils/ValidatedServerConfig';
// These are used in several places, and come from the js-sdk's autodiscovery // These are used in several places, and come from the js-sdk's autodiscovery
// stuff. We define them here so that they'll be picked up by i18n. // stuff. We define them here so that they'll be picked up by i18n.

View file

@ -22,7 +22,7 @@ import { logger } from "matrix-js-sdk/src/logger";
import { _t, _td } from '../../../languageHandler'; import { _t, _td } from '../../../languageHandler';
import { messageForResourceLimitError } from '../../../utils/ErrorUtils'; import { messageForResourceLimitError } from '../../../utils/ErrorUtils';
import AutoDiscoveryUtils, { ValidatedServerConfig } from "../../../utils/AutoDiscoveryUtils"; import AutoDiscoveryUtils from "../../../utils/AutoDiscoveryUtils";
import * as Lifecycle from '../../../Lifecycle'; import * as Lifecycle from '../../../Lifecycle';
import { IMatrixClientCreds, MatrixClientPeg } from "../../../MatrixClientPeg"; import { IMatrixClientCreds, MatrixClientPeg } from "../../../MatrixClientPeg";
import AuthPage from "../../views/auth/AuthPage"; import AuthPage from "../../views/auth/AuthPage";
@ -39,6 +39,7 @@ import Spinner from "../../views/elements/Spinner";
import { AuthHeaderDisplay } from './header/AuthHeaderDisplay'; import { AuthHeaderDisplay } from './header/AuthHeaderDisplay';
import { AuthHeaderProvider } from './header/AuthHeaderProvider'; import { AuthHeaderProvider } from './header/AuthHeaderProvider';
import SettingsStore from '../../../settings/SettingsStore'; import SettingsStore from '../../../settings/SettingsStore';
import { ValidatedServerConfig } from '../../../utils/ValidatedServerConfig';
const debuglog = (...args: any[]) => { const debuglog = (...args: any[]) => {
if (SettingsStore.getValue("debug_registration")) { if (SettingsStore.getValue("debug_registration")) {

View file

@ -19,7 +19,7 @@ import classNames from 'classnames';
import { _t } from '../../../languageHandler'; import { _t } from '../../../languageHandler';
import SdkConfig from '../../../SdkConfig'; import SdkConfig from '../../../SdkConfig';
import { ValidatedServerConfig } from "../../../utils/AutoDiscoveryUtils"; import { ValidatedServerConfig } from '../../../utils/ValidatedServerConfig';
import AccessibleButton from "../elements/AccessibleButton"; import AccessibleButton from "../elements/AccessibleButton";
import withValidation, { IValidationResult } from "../elements/Validation"; import withValidation, { IValidationResult } from "../elements/Validation";
import Field from "../elements/Field"; import Field from "../elements/Field";

View file

@ -26,7 +26,7 @@ import { _t, _td } from '../../../languageHandler';
import SdkConfig from '../../../SdkConfig'; import SdkConfig from '../../../SdkConfig';
import { SAFE_LOCALPART_REGEX } from '../../../Registration'; import { SAFE_LOCALPART_REGEX } from '../../../Registration';
import withValidation, { IValidationResult } from '../elements/Validation'; import withValidation, { IValidationResult } from '../elements/Validation';
import { ValidatedServerConfig } from "../../../utils/AutoDiscoveryUtils"; import { ValidatedServerConfig } from '../../../utils/ValidatedServerConfig';
import EmailField from "./EmailField"; import EmailField from "./EmailField";
import PassphraseField from "./PassphraseField"; import PassphraseField from "./PassphraseField";
import Field from '../elements/Field'; import Field from '../elements/Field';

View file

@ -18,7 +18,7 @@ import React, { createRef } from "react";
import { AutoDiscovery } from "matrix-js-sdk/src/autodiscovery"; import { AutoDiscovery } from "matrix-js-sdk/src/autodiscovery";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import AutoDiscoveryUtils, { ValidatedServerConfig } from "../../../utils/AutoDiscoveryUtils"; import AutoDiscoveryUtils from "../../../utils/AutoDiscoveryUtils";
import BaseDialog from './BaseDialog'; import BaseDialog from './BaseDialog';
import { _t } from '../../../languageHandler'; import { _t } from '../../../languageHandler';
import AccessibleButton from "../elements/AccessibleButton"; import AccessibleButton from "../elements/AccessibleButton";
@ -27,6 +27,7 @@ import Field from "../elements/Field";
import StyledRadioButton from "../elements/StyledRadioButton"; import StyledRadioButton from "../elements/StyledRadioButton";
import TextWithTooltip from "../elements/TextWithTooltip"; import TextWithTooltip from "../elements/TextWithTooltip";
import withValidation, { IFieldState } from "../elements/Validation"; import withValidation, { IFieldState } from "../elements/Validation";
import { ValidatedServerConfig } from "../../../utils/ValidatedServerConfig";
interface IProps { interface IProps {
title?: string; title?: string;

View file

@ -17,7 +17,7 @@ limitations under the License.
import React from 'react'; import React from 'react';
import AccessibleButton from "./AccessibleButton"; import AccessibleButton from "./AccessibleButton";
import { ValidatedServerConfig } from "../../../utils/AutoDiscoveryUtils"; import { ValidatedServerConfig } from '../../../utils/ValidatedServerConfig';
import { _t } from "../../../languageHandler"; import { _t } from "../../../languageHandler";
import TextWithTooltip from "./TextWithTooltip"; import TextWithTooltip from "./TextWithTooltip";
import SdkConfig from "../../../SdkConfig"; import SdkConfig from "../../../SdkConfig";

View file

@ -21,26 +21,13 @@ import { logger } from "matrix-js-sdk/src/logger";
import { _t, _td, newTranslatableError } from "../languageHandler"; import { _t, _td, newTranslatableError } from "../languageHandler";
import { makeType } from "./TypeUtils"; import { makeType } from "./TypeUtils";
import SdkConfig from '../SdkConfig'; import SdkConfig from '../SdkConfig';
import { ValidatedServerConfig } from './ValidatedServerConfig';
const LIVELINESS_DISCOVERY_ERRORS: string[] = [ const LIVELINESS_DISCOVERY_ERRORS: string[] = [
AutoDiscovery.ERROR_INVALID_HOMESERVER, AutoDiscovery.ERROR_INVALID_HOMESERVER,
AutoDiscovery.ERROR_INVALID_IDENTITY_SERVER, AutoDiscovery.ERROR_INVALID_IDENTITY_SERVER,
]; ];
export class ValidatedServerConfig {
hsUrl: string;
hsName: string;
hsNameIsDifferent: string;
isUrl: string;
isDefault: boolean;
// when the server config is based on static URLs the hsName is not resolvable and things may wish to use hsUrl
isNameResolvable: boolean;
warning: string;
}
export interface IAuthComponentState { export interface IAuthComponentState {
serverIsAlive: boolean; serverIsAlive: boolean;
serverErrorIsFatal: boolean; serverErrorIsFatal: boolean;

View file

@ -0,0 +1,29 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
export class ValidatedServerConfig {
hsUrl: string;
hsName: string;
hsNameIsDifferent: string;
isUrl: string;
isDefault: boolean;
// when the server config is based on static URLs the hsName is not resolvable and things may wish to use hsUrl
isNameResolvable: boolean;
warning: string;
}

View file

@ -35,7 +35,7 @@ import {
import { MatrixClientPeg as peg } from '../../src/MatrixClientPeg'; import { MatrixClientPeg as peg } from '../../src/MatrixClientPeg';
import dis from '../../src/dispatcher/dispatcher'; import dis from '../../src/dispatcher/dispatcher';
import { makeType } from "../../src/utils/TypeUtils"; import { makeType } from "../../src/utils/TypeUtils";
import { ValidatedServerConfig } from "../../src/utils/AutoDiscoveryUtils"; import { ValidatedServerConfig } from "../../src/utils/ValidatedServerConfig";
import { EnhancedMap } from "../../src/utils/maps"; import { EnhancedMap } from "../../src/utils/maps";
import { AsyncStoreWithClient } from "../../src/stores/AsyncStoreWithClient"; import { AsyncStoreWithClient } from "../../src/stores/AsyncStoreWithClient";
import MatrixClientBackedSettingsHandler from "../../src/settings/handlers/MatrixClientBackedSettingsHandler"; import MatrixClientBackedSettingsHandler from "../../src/settings/handlers/MatrixClientBackedSettingsHandler";