diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index db0d84e3d0d..93f6613d870 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -137,6 +137,7 @@ import { TimelineRenderingType } from "../../contexts/RoomContext"; import { UseCaseSelection } from '../views/elements/UseCaseSelection'; import { ValidatedServerConfig } from '../../utils/ValidatedServerConfig'; import { isLocalRoom } from '../../utils/localRoom/isLocalRoom'; +import { getDefaultUseCase } from '../../utils/WellKnownUtils'; // legacy export export { default as Views } from "../../Views"; @@ -1261,7 +1262,13 @@ export default class MatrixChat extends React.PureComponent { MatrixClientPeg.currentUserIsJustRegistered() && SettingsStore.getValue("FTUE.useCaseSelection") === null ) { - this.setStateForNewView({ view: Views.USE_CASE_SELECTION }); + const defaultUseCase = getDefaultUseCase(); + if (defaultUseCase) { + // Skip presenting selection + this.onShowPostLoginScreen(defaultUseCase); + } else { + this.setStateForNewView({ view: Views.USE_CASE_SELECTION }); + } // Listen to changes in settings and hide the use case screen if appropriate - this is necessary because // account settings can still be changing at this point in app init (due to the initial sync being cached, diff --git a/src/utils/WellKnownUtils.ts b/src/utils/WellKnownUtils.ts index 451f956f16f..ba7dfe3c4af 100644 --- a/src/utils/WellKnownUtils.ts +++ b/src/utils/WellKnownUtils.ts @@ -16,10 +16,13 @@ limitations under the License. import { IClientWellKnown } from 'matrix-js-sdk/src/client'; import { UnstableValue } from 'matrix-js-sdk/src/NamespacedValue'; +import { logger } from 'matrix-js-sdk/src/logger'; import { MatrixClientPeg } from '../MatrixClientPeg'; +import { UseCase } from '../settings/enums/UseCase'; const CALL_BEHAVIOUR_WK_KEY = "io.element.call_behaviour"; +const DEFAULT_USE_CASE = "io.element.default_use_case"; const E2EE_WK_KEY = "io.element.e2ee"; const E2EE_WK_KEY_DEPRECATED = "im.vector.riot.e2ee"; export const TILE_SERVER_WK_KEY = new UnstableValue( @@ -113,3 +116,18 @@ export function getSecureBackupSetupMethods(): SecureBackupSetupMethod[] { } return wellKnown["secure_backup_setup_methods"]; } + +export function getDefaultUseCase(): UseCase | undefined { + return defaultUseCaseFromWellKnown(MatrixClientPeg.get().getClientWellKnown()); +} + +export function defaultUseCaseFromWellKnown( + clientWellKnown?: IClientWellKnown | undefined, +): UseCase { + const useCase = clientWellKnown?.[DEFAULT_USE_CASE] + if (useCase !== undefined && !Object.values(UseCase).includes(useCase)) { + logger.warn(`.well-known use case '${useCase} isn't a valid use case.'`); + return undefined; + } + return useCase; +} \ No newline at end of file