Merge pull request #5658 from matrix-org/travis/welcome-login

Add an optional config option to make the welcome page the login page
This commit is contained in:
Travis Ralston 2021-03-19 09:12:35 -06:00 committed by GitHub
commit 3caf07be87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 21 deletions

View file

@ -1,8 +1,5 @@
/* /*
Copyright 2015, 2016 OpenMarket Ltd Copyright 2015-2021 The Matrix.org Foundation C.I.C.
Copyright 2017 Vector Creations Ltd
Copyright 2017-2019 New Vector Ltd
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -81,6 +78,7 @@ import {UIFeature} from "../../settings/UIFeature";
import { CommunityPrototypeStore } from "../../stores/CommunityPrototypeStore"; import { CommunityPrototypeStore } from "../../stores/CommunityPrototypeStore";
import DialPadModal from "../views/voip/DialPadModal"; import DialPadModal from "../views/voip/DialPadModal";
import { showToast as showMobileGuideToast } from '../../toasts/MobileGuideToast'; import { showToast as showMobileGuideToast } from '../../toasts/MobileGuideToast';
import { shouldUseLoginForWelcome } from "../../utils/pages";
import SpaceStore from "../../stores/SpaceStore"; import SpaceStore from "../../stores/SpaceStore";
import SpaceRoomDirectory from "./SpaceRoomDirectory"; import SpaceRoomDirectory from "./SpaceRoomDirectory";
import {replaceableComponent} from "../../utils/replaceableComponent"; import {replaceableComponent} from "../../utils/replaceableComponent";
@ -608,12 +606,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
if (payload.screenAfterLogin) { if (payload.screenAfterLogin) {
this.screenAfterLogin = payload.screenAfterLogin; this.screenAfterLogin = payload.screenAfterLogin;
} }
this.setStateForNewView({ this.viewLogin();
view: Views.LOGIN,
});
this.notifyNewScreen('login');
ThemeController.isLogin = true;
this.themeWatcher.recheck();
break; break;
case 'start_password_recovery': case 'start_password_recovery':
this.setStateForNewView({ this.setStateForNewView({
@ -977,6 +970,9 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
} }
private viewWelcome() { private viewWelcome() {
if (shouldUseLoginForWelcome(SdkConfig.get())) {
return this.viewLogin();
}
this.setStateForNewView({ this.setStateForNewView({
view: Views.WELCOME, view: Views.WELCOME,
}); });
@ -985,6 +981,16 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
this.themeWatcher.recheck(); this.themeWatcher.recheck();
} }
private viewLogin(otherState?: any) {
this.setStateForNewView({
view: Views.LOGIN,
...otherState,
});
this.notifyNewScreen('login');
ThemeController.isLogin = true;
this.themeWatcher.recheck();
}
private viewHome(justRegistered = false) { private viewHome(justRegistered = false) {
// The home page requires the "logged in" view, so we'll set that. // The home page requires the "logged in" view, so we'll set that.
this.setStateForNewView({ this.setStateForNewView({
@ -1306,17 +1312,13 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
* Called when the session is logged out * Called when the session is logged out
*/ */
private onLoggedOut() { private onLoggedOut() {
this.notifyNewScreen('login'); this.viewLogin({
this.setStateForNewView({
view: Views.LOGIN,
ready: false, ready: false,
collapseLhs: false, collapseLhs: false,
currentRoomId: null, currentRoomId: null,
}); });
this.subTitleStatus = ''; this.subTitleStatus = '';
this.setPageSubtitle(); this.setPageSubtitle();
ThemeController.isLogin = true;
this.themeWatcher.recheck();
} }
/** /**

View file

@ -1,5 +1,5 @@
/* /*
Copyright 2019 New Vector Ltd Copyright 2019, 2021 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -14,12 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
export function getHomePageUrl(appConfig) { import { ConfigOptions } from "../SdkConfig";
export function getHomePageUrl(appConfig: ConfigOptions): string | null {
const pagesConfig = appConfig.embeddedPages; const pagesConfig = appConfig.embeddedPages;
let pageUrl = null; let pageUrl = pagesConfig?.homeUrl;
if (pagesConfig) {
pageUrl = pagesConfig.homeUrl;
}
if (!pageUrl) { if (!pageUrl) {
// This is a deprecated config option for the home page // This is a deprecated config option for the home page
// (despite the name, given we also now have a welcome // (despite the name, given we also now have a welcome
@ -29,3 +29,8 @@ export function getHomePageUrl(appConfig) {
return pageUrl; return pageUrl;
} }
export function shouldUseLoginForWelcome(appConfig: ConfigOptions): boolean {
const pagesConfig = appConfig.embeddedPages;
return pagesConfig?.loginForWelcome === true;
}