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

Commit fcd7a15

Browse files
authored
Merge pull request #1601 from matrix-org/luke/groups-guest-flow
Add group features as starting points for ILAG
2 parents 7893927 + 0d174ff commit fcd7a15

File tree

2 files changed

+42
-48
lines changed

2 files changed

+42
-48
lines changed

src/components/structures/GroupView.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -435,14 +435,15 @@ export default React.createClass({
435435
},
436436

437437
componentWillMount: function() {
438+
this._matrixClient = MatrixClientPeg.get();
439+
this._matrixClient.on("Group.myMembership", this._onGroupMyMembership);
440+
438441
this._changeAvatarComponent = null;
439442
this._initGroupStore(this.props.groupId, true);
440-
441-
MatrixClientPeg.get().on("Group.myMembership", this._onGroupMyMembership);
442443
},
443444

444445
componentWillUnmount: function() {
445-
MatrixClientPeg.get().removeListener("Group.myMembership", this._onGroupMyMembership);
446+
this._matrixClient.removeListener("Group.myMembership", this._onGroupMyMembership);
446447
this._groupStore.removeAllListeners();
447448
},
448449

@@ -464,11 +465,11 @@ export default React.createClass({
464465
},
465466

466467
_initGroupStore: function(groupId, firstInit) {
467-
const group = MatrixClientPeg.get().getGroup(groupId);
468+
const group = this._matrixClient.getGroup(groupId);
468469
if (group && group.inviter && group.inviter.userId) {
469470
this._fetchInviterProfile(group.inviter.userId);
470471
}
471-
this._groupStore = GroupStoreCache.getGroupStore(MatrixClientPeg.get(), groupId);
472+
this._groupStore = GroupStoreCache.getGroupStore(this._matrixClient, groupId);
472473
this._groupStore.registerListener(() => {
473474
const summary = this._groupStore.getSummary();
474475
if (summary.profile) {
@@ -486,7 +487,7 @@ export default React.createClass({
486487
groupRooms: this._groupStore.getGroupRooms(),
487488
groupRoomsLoading: !this._groupStore.isStateReady(GroupStore.STATE_KEY.GroupRooms),
488489
isUserMember: this._groupStore.getGroupMembers().some(
489-
(m) => m.userId === MatrixClientPeg.get().credentials.userId,
490+
(m) => m.userId === this._matrixClient.credentials.userId,
490491
),
491492
error: null,
492493
});
@@ -506,7 +507,7 @@ export default React.createClass({
506507
this.setState({
507508
inviterProfileBusy: true,
508509
});
509-
MatrixClientPeg.get().getProfileInfo(userId).then((resp) => {
510+
this._matrixClient.getProfileInfo(userId).then((resp) => {
510511
this.setState({
511512
inviterProfile: {
512513
avatarUrl: resp.avatar_url,
@@ -571,7 +572,7 @@ export default React.createClass({
571572
if (!file) return;
572573

573574
this.setState({uploadingAvatar: true});
574-
MatrixClientPeg.get().uploadContent(file).then((url) => {
575+
this._matrixClient.uploadContent(file).then((url) => {
575576
const newProfileForm = Object.assign(this.state.profileForm, { avatar_url: url });
576577
this.setState({
577578
uploadingAvatar: false,
@@ -591,7 +592,7 @@ export default React.createClass({
591592
_onSaveClick: function() {
592593
this.setState({saving: true});
593594
const savePromise = this.state.isUserPrivileged ?
594-
MatrixClientPeg.get().setGroupProfile(this.props.groupId, this.state.profileForm) :
595+
this._matrixClient.setGroupProfile(this.props.groupId, this.state.profileForm) :
595596
Promise.resolve();
596597
savePromise.then((result) => {
597598
this.setState({
@@ -630,7 +631,7 @@ export default React.createClass({
630631

631632
_onRejectInviteClick: function() {
632633
this.setState({membershipBusy: true});
633-
MatrixClientPeg.get().leaveGroup(this.props.groupId).then(() => {
634+
this._matrixClient.leaveGroup(this.props.groupId).then(() => {
634635
// don't reset membershipBusy here: wait for the membership change to come down the sync
635636
}).catch((e) => {
636637
this.setState({membershipBusy: false});
@@ -653,7 +654,7 @@ export default React.createClass({
653654
if (!confirmed) return;
654655

655656
this.setState({membershipBusy: true});
656-
MatrixClientPeg.get().leaveGroup(this.props.groupId).then(() => {
657+
this._matrixClient.leaveGroup(this.props.groupId).then(() => {
657658
// don't reset membershipBusy here: wait for the membership change to come down the sync
658659
}).catch((e) => {
659660
this.setState({membershipBusy: false});
@@ -829,7 +830,7 @@ export default React.createClass({
829830
const Spinner = sdk.getComponent("elements.Spinner");
830831
const BaseAvatar = sdk.getComponent("avatars.BaseAvatar");
831832

832-
const group = MatrixClientPeg.get().getGroup(this.props.groupId);
833+
const group = this._matrixClient.getGroup(this.props.groupId);
833834
if (!group) return null;
834835

835836
if (group.myMembership === 'invite') {
@@ -839,7 +840,7 @@ export default React.createClass({
839840
</div>;
840841
}
841842
const httpInviterAvatar = this.state.inviterProfile ?
842-
MatrixClientPeg.get().mxcUrlToHttp(
843+
this._matrixClient.mxcUrlToHttp(
843844
this.state.inviterProfile.avatarUrl, 36, 36,
844845
) : null;
845846

src/components/structures/MatrixChat.js

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ const VIEWS = {
7474
LOGGED_IN: 6,
7575
};
7676

77+
// Actions that are redirected through the onboarding process prior to being
78+
// re-dispatched. NOTE: some actions are non-trivial and would require
79+
// re-factoring to be included in this list in future.
80+
const ONBOARDING_FLOW_STARTERS = [
81+
'view_user_settings',
82+
'view_create_chat',
83+
'view_create_room',
84+
'view_my_groups',
85+
'view_group',
86+
];
87+
7788
module.exports = React.createClass({
7889
// we export this so that the integration tests can use it :-S
7990
statics: {
@@ -374,6 +385,22 @@ module.exports = React.createClass({
374385
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
375386
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
376387

388+
// Start the onboarding process for certain actions
389+
if (MatrixClientPeg.get() && MatrixClientPeg.get().isGuest() &&
390+
ONBOARDING_FLOW_STARTERS.includes(payload.action)
391+
) {
392+
// This will cause `payload` to be dispatched later, once a
393+
// sync has reached the "prepared" state. Setting a matrix ID
394+
// will cause a full login and sync and finally the deferred
395+
// action will be dispatched.
396+
dis.dispatch({
397+
action: 'do_after_sync_prepared',
398+
deferred_action: payload,
399+
});
400+
dis.dispatch({action: 'view_set_mxid'});
401+
return;
402+
}
403+
377404
switch (payload.action) {
378405
case 'logout':
379406
Lifecycle.logout();
@@ -463,16 +490,6 @@ module.exports = React.createClass({
463490
this._viewIndexedRoom(payload.roomIndex);
464491
break;
465492
case 'view_user_settings':
466-
if (MatrixClientPeg.get().isGuest()) {
467-
dis.dispatch({
468-
action: 'do_after_sync_prepared',
469-
deferred_action: {
470-
action: 'view_user_settings',
471-
},
472-
});
473-
dis.dispatch({action: 'view_set_mxid'});
474-
break;
475-
}
476493
this._setPage(PageTypes.UserSettings);
477494
this.notifyNewScreen('settings');
478495
break;
@@ -509,7 +526,7 @@ module.exports = React.createClass({
509526
this._chatCreateOrReuse(payload.user_id, payload.go_home_on_cancel);
510527
break;
511528
case 'view_create_chat':
512-
this._createChat();
529+
showStartChatInviteDialog();
513530
break;
514531
case 'view_invite':
515532
showRoomInviteDialog(payload.roomId);
@@ -750,31 +767,7 @@ module.exports = React.createClass({
750767
}).close;
751768
},
752769

753-
_createChat: function() {
754-
if (MatrixClientPeg.get().isGuest()) {
755-
dis.dispatch({
756-
action: 'do_after_sync_prepared',
757-
deferred_action: {
758-
action: 'view_create_chat',
759-
},
760-
});
761-
dis.dispatch({action: 'view_set_mxid'});
762-
return;
763-
}
764-
showStartChatInviteDialog();
765-
},
766-
767770
_createRoom: function() {
768-
if (MatrixClientPeg.get().isGuest()) {
769-
dis.dispatch({
770-
action: 'do_after_sync_prepared',
771-
deferred_action: {
772-
action: 'view_create_room',
773-
},
774-
});
775-
dis.dispatch({action: 'view_set_mxid'});
776-
return;
777-
}
778771
const CreateRoomDialog = sdk.getComponent('dialogs.CreateRoomDialog');
779772
Modal.createTrackedDialog('Create Room', '', CreateRoomDialog, {
780773
onFinished: (shouldCreate, name, noFederate) => {

0 commit comments

Comments
 (0)