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

Commit

Permalink
Add well known use case selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Jul 26, 2022
1 parent d2b942d commit 03dc160
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
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;
}

0 comments on commit 03dc160

Please sign in to comment.