Skip to content

Commit a6dec86

Browse files
committed
Add mobile registration and dispatch event for mobile postmessage dance
1 parent eae9d9e commit a6dec86

File tree

5 files changed

+79
-19
lines changed

5 files changed

+79
-19
lines changed

res/css/_components.pcss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
@import "./structures/auth/_ConfirmSessionLockTheftView.pcss";
9595
@import "./structures/auth/_Login.pcss";
9696
@import "./structures/auth/_LoginSplashView.pcss";
97+
@import "./structures/auth/_MobileRegistration.pcss";
9798
@import "./structures/auth/_Registration.pcss";
9899
@import "./structures/auth/_SessionLockStolenView.pcss";
99100
@import "./structures/auth/_SetupEncryptionBody.pcss";
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
Copyright 2024 New Vector Ltd.
3+
4+
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
5+
Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
.mx_MobileRegister_body {
9+
padding: 32px;
10+
}

src/components/structures/MatrixChat.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ import { cleanUpDraftsIfRequired } from "../../DraftCleaner";
140140
// legacy export
141141
export { default as Views } from "../../Views";
142142

143-
const AUTH_SCREENS = ["register", "login", "forgot_password", "start_sso", "start_cas", "welcome"];
143+
const AUTH_SCREENS = ["register", "mobile_register", "login", "forgot_password", "start_sso", "start_cas", "welcome"];
144144

145145
// Actions that are redirected through the onboarding process prior to being
146146
// re-dispatched. NOTE: some actions are non-trivial and would require
@@ -189,6 +189,7 @@ interface IState {
189189
register_session_id?: string;
190190
// eslint-disable-next-line camelcase
191191
register_id_sid?: string;
192+
isMobileRegistration?: boolean;
192193
// When showing Modal dialogs we need to set aria-hidden on the root app element
193194
// and disable it when there are no dialogs
194195
hideToSRUsers: boolean;
@@ -243,6 +244,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
243244
currentUserId: null,
244245

245246
hideToSRUsers: false,
247+
isMobileRegistration: false,
246248

247249
syncError: null, // If the current syncing status is ERROR, the error object, otherwise null.
248250
resizeNotifier: new ResizeNotifier(),
@@ -650,6 +652,9 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
650652
case "require_registration":
651653
startAnyRegistrationFlow(payload as any);
652654
break;
655+
case "start_mobile_registration":
656+
this.startRegistration(payload.params || {}, true);
657+
break;
653658
case "start_registration":
654659
if (Lifecycle.isSoftLogout()) {
655660
this.onSoftLogout();
@@ -946,7 +951,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
946951
});
947952
}
948953

949-
private async startRegistration(params: { [key: string]: string }): Promise<void> {
954+
private async startRegistration(params: { [key: string]: string }, isMobileRegistration?: boolean): Promise<void> {
950955
if (!SettingsStore.getValue(UIFeature.Registration)) {
951956
this.showScreen("welcome");
952957
return;
@@ -976,12 +981,15 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
976981
newState.register_client_secret = params.client_secret;
977982
newState.register_session_id = params.session_id;
978983
newState.register_id_sid = params.sid;
984+
newState.register_id_sid = params.sid;
979985
}
980986

987+
newState.isMobileRegistration = isMobileRegistration; //&& SettingsStore.getValue("Registration.mobileRegistrationHelper");
988+
981989
this.setStateForNewView(newState);
982990
ThemeController.isLogin = true;
983991
this.themeWatcher.recheck();
984-
this.notifyNewScreen("register");
992+
this.notifyNewScreen(isMobileRegistration ? "mobile_register" : "register");
985993
}
986994

987995
// switch view to the given room
@@ -1721,6 +1729,11 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
17211729
params: params,
17221730
});
17231731
PerformanceMonitor.instance.start(PerformanceEntryNames.REGISTER);
1732+
} else if (screen === "mobile_register") {
1733+
dis.dispatch({
1734+
action: "start_mobile_registration",
1735+
params: params,
1736+
});
17241737
} else if (screen === "login") {
17251738
dis.dispatch({
17261739
action: "start_login",
@@ -2080,6 +2093,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
20802093
onServerConfigChange={this.onServerConfigChange}
20812094
defaultDeviceDisplayName={this.props.defaultDeviceDisplayName}
20822095
fragmentAfterLogin={fragmentAfterLogin}
2096+
mobileRegister={this.state.isMobileRegistration}
20832097
{...this.getServerProperties()}
20842098
/>
20852099
);

src/components/structures/auth/Registration.tsx

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ const debuglog = (...args: any[]): void => {
5353
}
5454
};
5555

56+
export interface MobileRegistrationResponse {
57+
user_id: string;
58+
home_server: string;
59+
access_token: string;
60+
device_id: string;
61+
}
62+
5663
interface IProps {
5764
serverConfig: ValidatedServerConfig;
5865
defaultDeviceDisplayName?: string;
@@ -62,7 +69,7 @@ interface IProps {
6269
sessionId?: string;
6370
idSid?: string;
6471
fragmentAfterLogin?: string;
65-
72+
mobileRegister?: boolean;
6673
// Called when the user has logged in. Params:
6774
// - object with userId, deviceId, homeserverUrl, identityServerUrl, accessToken
6875
// - The user's password, if available and applicable (may be cached in memory
@@ -410,18 +417,33 @@ export default class Registration extends React.Component<IProps, IState> {
410417
debuglog("Registration: ui auth finished:", { hasEmail, hasAccessToken });
411418
// don’t log in if we found a session for a different user
412419
if (hasAccessToken && !newState.differentLoggedInUserId) {
413-
await this.props.onLoggedIn(
414-
{
415-
userId,
416-
deviceId: (response as RegisterResponse).device_id!,
417-
homeserverUrl: this.state.matrixClient.getHomeserverUrl(),
418-
identityServerUrl: this.state.matrixClient.getIdentityServerUrl(),
419-
accessToken,
420-
},
421-
this.state.formVals.password!,
422-
);
420+
if (this.props.mobileRegister) {
421+
const mobileResponse: MobileRegistrationResponse = {
422+
user_id: userId,
423+
home_server: this.state.matrixClient.getHomeserverUrl(),
424+
access_token: accessToken,
425+
device_id: (response as RegisterResponse).device_id!,
426+
};
427+
const event = new CustomEvent<MobileRegistrationResponse>("mobileregistrationresponse", {
428+
detail: mobileResponse,
429+
});
430+
document.dispatchEvent(event);
431+
newState.busy = false;
432+
newState.completedNoSignin = true;
433+
} else {
434+
await this.props.onLoggedIn(
435+
{
436+
userId,
437+
deviceId: (response as RegisterResponse).device_id!,
438+
homeserverUrl: this.state.matrixClient.getHomeserverUrl(),
439+
identityServerUrl: this.state.matrixClient.getIdentityServerUrl(),
440+
accessToken,
441+
},
442+
this.state.formVals.password!,
443+
);
423444

424-
this.setupPushers();
445+
this.setupPushers();
446+
}
425447
} else {
426448
newState.busy = false;
427449
newState.completedNoSignin = true;
@@ -558,7 +580,7 @@ export default class Registration extends React.Component<IProps, IState> {
558580
);
559581
} else if (this.state.matrixClient && this.state.flows.length) {
560582
let ssoSection: JSX.Element | undefined;
561-
if (this.state.ssoFlow) {
583+
if (!this.props.mobileRegister && this.state.ssoFlow) {
562584
let continueWithSection;
563585
const providers = this.state.ssoFlow.identity_providers || [];
564586
// when there is only a single (or 0) providers we show a wide button with `Continue with X` text
@@ -591,7 +613,6 @@ export default class Registration extends React.Component<IProps, IState> {
591613
</React.Fragment>
592614
);
593615
}
594-
595616
return (
596617
<React.Fragment>
597618
{ssoSection}
@@ -660,7 +681,9 @@ export default class Registration extends React.Component<IProps, IState> {
660681
let body;
661682
if (this.state.completedNoSignin) {
662683
let regDoneText;
663-
if (this.state.differentLoggedInUserId) {
684+
if (this.props.mobileRegister) {
685+
regDoneText = undefined;
686+
} else if (this.state.differentLoggedInUserId) {
664687
regDoneText = (
665688
<div>
666689
<p>
@@ -717,6 +740,8 @@ export default class Registration extends React.Component<IProps, IState> {
717740
{regDoneText}
718741
</div>
719742
);
743+
} else if (this.props.mobileRegister) {
744+
body = this.renderRegisterComponent();
720745
} else {
721746
body = (
722747
<Fragment>
@@ -746,7 +771,13 @@ export default class Registration extends React.Component<IProps, IState> {
746771
</Fragment>
747772
);
748773
}
749-
774+
if (this.props.mobileRegister) {
775+
return (
776+
<Fragment>
777+
<div className="mx_MobileRegister_body">{body}</div>
778+
</Fragment>
779+
);
780+
}
750781
return (
751782
<AuthPage>
752783
<AuthHeader />

src/settings/Settings.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,10 @@ export const SETTINGS: { [setting: string]: ISetting } = {
876876
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
877877
default: null,
878878
},
879+
"Registration.mobileRegistrationHelper": {
880+
supportedLevels: [SettingLevel.CONFIG],
881+
default: false,
882+
},
879883
"autocompleteDelay": {
880884
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
881885
default: 200,

0 commit comments

Comments
 (0)