Skip to content

Commit 9715f1c

Browse files
Reenable guest access (ILAG)
Change-Id: Ib27f14148da05e3fdceba28f204316d3b6c880d4
1 parent 6fa9679 commit 9715f1c

File tree

4 files changed

+67
-90
lines changed

4 files changed

+67
-90
lines changed

src/Registration.js

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import dis from './dispatcher';
2424
import * as sdk from './index';
2525
import Modal from './Modal';
2626
import { _t } from './languageHandler';
27-
// import {MatrixClientPeg} from './MatrixClientPeg';
27+
import {MatrixClientPeg} from './MatrixClientPeg';
2828

2929
// Regex for what a "safe" or "Matrix-looking" localpart would be.
3030
// TODO: Update as needed for https://github.com/matrix-org/matrix-doc/issues/1514
@@ -42,29 +42,27 @@ export const SAFE_LOCALPART_REGEX = /^[a-z0-9=_\-./]+$/;
4242
*/
4343
export async function startAnyRegistrationFlow(options) {
4444
if (options === undefined) options = {};
45+
const flows = await _getRegistrationFlows();
46+
4547
// look for an ILAG compatible flow. We define this as one
4648
// which has only dummy or recaptcha flows. In practice it
4749
// would support any stage InteractiveAuth supports, just not
4850
// ones like email & msisdn which require the user to supply
4951
// the relevant details in advance. We err on the side of
5052
// caution though.
5153

52-
// XXX: ILAG is disabled for now,
53-
// see https://github.com/vector-im/riot-web/issues/8222
54-
55-
// const flows = await _getRegistrationFlows();
56-
// const hasIlagFlow = flows.some((flow) => {
57-
// return flow.stages.every((stage) => {
58-
// return ['m.login.dummy', 'm.login.recaptcha', 'm.login.terms'].includes(stage);
59-
// });
60-
// });
54+
const hasIlagFlow = flows.some((flow) => {
55+
return flow.stages.every((stage) => {
56+
return ['m.login.dummy', 'm.login.recaptcha', 'm.login.terms'].includes(stage);
57+
});
58+
});
6159

62-
// if (hasIlagFlow) {
63-
// dis.dispatch({
64-
// action: 'view_set_mxid',
65-
// go_home_on_cancel: options.go_home_on_cancel,
66-
// });
67-
//} else {
60+
if (hasIlagFlow) {
61+
dis.dispatch({
62+
action: 'view_set_mxid',
63+
go_home_on_cancel: options.go_home_on_cancel,
64+
});
65+
} else {
6866
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
6967
Modal.createTrackedDialog('Registration required', '', QuestionDialog, {
7068
title: _t("Registration Required"),
@@ -80,25 +78,24 @@ export async function startAnyRegistrationFlow(options) {
8078
}
8179
},
8280
});
83-
//}
81+
}
8482
}
8583

86-
// async function _getRegistrationFlows() {
87-
// try {
88-
// await MatrixClientPeg.get().register(
89-
// null,
90-
// null,
91-
// undefined,
92-
// {},
93-
// {},
94-
// );
95-
// console.log("Register request succeeded when it should have returned 401!");
96-
// } catch (e) {
97-
// if (e.httpStatus === 401) {
98-
// return e.data.flows;
99-
// }
100-
// throw e;
101-
// }
102-
// throw new Error("Register request succeeded when it should have returned 401!");
103-
// }
104-
84+
async function _getRegistrationFlows() {
85+
try {
86+
await MatrixClientPeg.get().register(
87+
null,
88+
null,
89+
undefined,
90+
{},
91+
{},
92+
);
93+
console.log("Register request succeeded when it should have returned 401!");
94+
} catch (e) {
95+
if (e.httpStatus === 401) {
96+
return e.data.flows;
97+
}
98+
throw e;
99+
}
100+
throw new Error("Register request succeeded when it should have returned 401!");
101+
}

src/components/structures/MessagePanel.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ export default class MessagePanel extends React.Component {
334334
return false; // no tile = no show
335335
}
336336

337+
// AMP don't show local echoes as they are broken with guests
338+
if (mxEv.status) {
339+
return false;
340+
}
341+
337342
// Always show highlighted event
338343
if (this.props.highlightedEventId === mxEv.getId()) return true;
339344

src/components/structures/RoomView.js

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,65 +1010,34 @@ export default createReactClass({
10101010
onJoinButtonClicked: function(ev) {
10111011
const cli = MatrixClientPeg.get();
10121012

1013-
// If the user is a ROU, allow them to transition to a PWLU
10141013
if (cli && cli.isGuest()) {
1015-
// Join this room once the user has registered and logged in
1016-
// (If we failed to peek, we may not have a valid room object.)
1017-
dis.dispatch({
1018-
action: 'do_after_sync_prepared',
1019-
deferred_action: {
1020-
action: 'view_room',
1021-
room_id: this._getRoomId(),
1022-
},
1023-
});
10241014

1025-
// Don't peek whilst registering otherwise getPendingEventList complains
1026-
// Do this by indicating our intention to join
1015+
const payload = {
1016+
action: 'view_room',
1017+
auto_join: true,
1018+
};
10271019

1028-
// XXX: ILAG is disabled for now,
1029-
// see https://github.com/vector-im/riot-web/issues/8222
1030-
dis.dispatch({action: 'require_registration'});
1031-
// dis.dispatch({
1032-
// action: 'will_join',
1033-
// });
1034-
1035-
// const SetMxIdDialog = sdk.getComponent('views.dialogs.SetMxIdDialog');
1036-
// const close = Modal.createTrackedDialog('Set MXID', '', SetMxIdDialog, {
1037-
// homeserverUrl: cli.getHomeserverUrl(),
1038-
// onFinished: (submitted, credentials) => {
1039-
// if (submitted) {
1040-
// this.props.onRegistered(credentials);
1041-
// } else {
1042-
// dis.dispatch({
1043-
// action: 'cancel_after_sync_prepared',
1044-
// });
1045-
// dis.dispatch({
1046-
// action: 'cancel_join',
1047-
// });
1048-
// }
1049-
// },
1050-
// onDifferentServerClicked: (ev) => {
1051-
// dis.dispatch({action: 'start_registration'});
1052-
// close();
1053-
// },
1054-
// onLoginClick: (ev) => {
1055-
// dis.dispatch({action: 'start_login'});
1056-
// close();
1057-
// },
1058-
// }).close;
1059-
// return;
1060-
} else {
1061-
Promise.resolve().then(() => {
1062-
const signUrl = this.props.thirdPartyInvite ?
1063-
this.props.thirdPartyInvite.inviteSignUrl : undefined;
1064-
dis.dispatch({
1065-
action: 'join_room',
1066-
opts: { inviteSignUrl: signUrl, viaServers: this.props.viaServers },
1067-
});
1068-
return Promise.resolve();
1069-
});
1020+
// It's not really possible to join Matrix rooms by ID because the HS has no way to know
1021+
// which servers to start querying. However, there's no other way to join rooms in
1022+
// this list without aliases at present, so if roomAlias isn't set here we have no
1023+
// choice but to supply the ID.
1024+
payload.room_id = this.state.roomId;
1025+
1026+
dis.dispatch(payload);
1027+
1028+
return;
10701029
}
10711030

1031+
Promise.resolve().then(() => {
1032+
const signUrl = this.props.thirdPartyInvite ?
1033+
this.props.thirdPartyInvite.inviteSignUrl : undefined;
1034+
dis.dispatch({
1035+
action: 'join_room',
1036+
opts: { inviteSignUrl: signUrl, viaServers: this.props.viaServers },
1037+
});
1038+
return Promise.resolve();
1039+
});
1040+
10721041
},
10731042

10741043
onMessageListScroll: function(ev) {
@@ -1675,6 +1644,7 @@ export default createReactClass({
16751644
oobData={this.props.oobData}
16761645
signUrl={this.props.thirdPartyInvite ? this.props.thirdPartyInvite.inviteSignUrl : null}
16771646
room={this.state.room}
1647+
guest_can_join={true}
16781648
/>
16791649
</ErrorBoundary>
16801650
</div>

src/components/views/rooms/RoomPreviewBar.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ export default createReactClass({
8383
// If given, this will be how the room is referred to (eg.
8484
// in error messages).
8585
roomAlias: PropTypes.string,
86+
// Are guests allowed to enter the room?
87+
guest_can_join: PropTypes.bool,
8688
},
8789

8890
getDefaultProps: function() {
@@ -146,6 +148,9 @@ export default createReactClass({
146148
const isGuest = MatrixClientPeg.get().isGuest();
147149

148150
if (isGuest) {
151+
if (this.props.guest_can_join) {
152+
return MessageCase.ViewingRoom;
153+
}
149154
return MessageCase.NotLoggedIn;
150155
}
151156

0 commit comments

Comments
 (0)