Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Add default use case selection based on io.element.default_use_case .well-known key #9107

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/components/structures/MatrixChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -1261,7 +1262,13 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
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,
Expand Down
18 changes: 18 additions & 0 deletions src/utils/WellKnownUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}