diff --git a/src/GroupAddressPicker.js b/src/GroupAddressPicker.js index c4b3744575..ef9010cbf2 100644 --- a/src/GroupAddressPicker.js +++ b/src/GroupAddressPicker.js @@ -114,7 +114,7 @@ function _onGroupInviteFinished(groupId, addrs) { function _onGroupAddRoomFinished(groupId, addrs, addRoomsPublicly) { const matrixClient = MatrixClientPeg.get(); - const groupStore = GroupStoreCache.getGroupStore(matrixClient, groupId); + const groupStore = GroupStoreCache.getGroupStore(groupId); const errorList = []; return Promise.all(addrs.map((addr) => { return groupStore diff --git a/src/components/structures/GroupView.js b/src/components/structures/GroupView.js index 45befdd60f..5ffb97c6ed 100644 --- a/src/components/structures/GroupView.js +++ b/src/components/structures/GroupView.js @@ -469,7 +469,7 @@ export default React.createClass({ if (group && group.inviter && group.inviter.userId) { this._fetchInviterProfile(group.inviter.userId); } - this._groupStore = GroupStoreCache.getGroupStore(this._matrixClient, groupId); + this._groupStore = GroupStoreCache.getGroupStore(groupId); this._groupStore.registerListener(() => { const summary = this._groupStore.getSummary(); if (summary.profile) { @@ -495,7 +495,19 @@ export default React.createClass({ this._onEditClick(); } }); + let willDoOnboarding = false; this._groupStore.on('error', (err) => { + if (err.errcode === 'M_GUEST_ACCESS_FORBIDDEN' && !willDoOnboarding) { + dis.dispatch({ + action: 'do_after_sync_prepared', + deferred_action: { + action: 'view_group', + group_id: groupId, + }, + }); + dis.dispatch({action: 'view_set_mxid'}); + willDoOnboarding = true; + } this.setState({ summary: null, error: err, diff --git a/src/components/views/dialogs/AddressPickerDialog.js b/src/components/views/dialogs/AddressPickerDialog.js index bb9f300f9d..837d2f5349 100644 --- a/src/components/views/dialogs/AddressPickerDialog.js +++ b/src/components/views/dialogs/AddressPickerDialog.js @@ -244,7 +244,7 @@ module.exports = React.createClass({ _doNaiveGroupRoomSearch: function(query) { const lowerCaseQuery = query.toLowerCase(); - const groupStore = GroupStoreCache.getGroupStore(MatrixClientPeg.get(), this.props.groupId); + const groupStore = GroupStoreCache.getGroupStore(this.props.groupId); const results = []; groupStore.getGroupRooms().forEach((r) => { const nameMatch = (r.name || '').toLowerCase().includes(lowerCaseQuery); diff --git a/src/components/views/groups/GroupMemberInfo.js b/src/components/views/groups/GroupMemberInfo.js index 17a4828a79..305aec8cdd 100644 --- a/src/components/views/groups/GroupMemberInfo.js +++ b/src/components/views/groups/GroupMemberInfo.js @@ -59,9 +59,7 @@ module.exports = React.createClass({ }, _initGroupStore(groupId) { - this._groupStore = GroupStoreCache.getGroupStore( - this.context.matrixClient, this.props.groupId, - ); + this._groupStore = GroupStoreCache.getGroupStore(this.props.groupId); this._groupStore.registerListener(this.onGroupStoreUpdated); }, diff --git a/src/components/views/groups/GroupMemberList.js b/src/components/views/groups/GroupMemberList.js index f2ade68176..71c168f5e6 100644 --- a/src/components/views/groups/GroupMemberList.js +++ b/src/components/views/groups/GroupMemberList.js @@ -20,17 +20,12 @@ import sdk from '../../../index'; import GroupStoreCache from '../../../stores/GroupStoreCache'; import GeminiScrollbar from 'react-gemini-scrollbar'; import PropTypes from 'prop-types'; -import withMatrixClient from '../../../wrappers/withMatrixClient'; const INITIAL_LOAD_NUM_MEMBERS = 30; -export default withMatrixClient(React.createClass({ +export default React.createClass({ displayName: 'GroupMemberList', - contextTypes: { - matrixClient: PropTypes.object.isRequired, - }, - propTypes: { groupId: PropTypes.string.isRequired, }, @@ -49,7 +44,7 @@ export default withMatrixClient(React.createClass({ }, _initGroupStore: function(groupId) { - this._groupStore = GroupStoreCache.getGroupStore(this.context.matrixClient, groupId); + this._groupStore = GroupStoreCache.getGroupStore(groupId); this._groupStore.registerListener(() => { this._fetchMembers(); }); @@ -174,4 +169,4 @@ export default withMatrixClient(React.createClass({ ); }, -})); +}); diff --git a/src/components/views/groups/GroupPublicityToggle.js b/src/components/views/groups/GroupPublicityToggle.js index ec910adcf5..0fcabb4ef8 100644 --- a/src/components/views/groups/GroupPublicityToggle.js +++ b/src/components/views/groups/GroupPublicityToggle.js @@ -16,7 +16,6 @@ limitations under the License. import React from 'react'; import PropTypes from 'prop-types'; -import { MatrixClient } from 'matrix-js-sdk'; import sdk from '../../../index'; import GroupStoreCache from '../../../stores/GroupStoreCache'; import GroupStore from '../../../stores/GroupStore'; @@ -29,10 +28,6 @@ export default React.createClass({ groupId: PropTypes.string.isRequired, }, - contextTypes: { - matrixClient: PropTypes.instanceOf(MatrixClient), - }, - getInitialState() { return { busy: false, @@ -46,7 +41,7 @@ export default React.createClass({ }, _initGroupStore: function(groupId) { - this._groupStore = GroupStoreCache.getGroupStore(this.context.matrixClient, groupId); + this._groupStore = GroupStoreCache.getGroupStore(groupId); this._groupStore.registerListener(() => { this.setState({ isGroupPublicised: this._groupStore.getGroupPublicity(), diff --git a/src/components/views/groups/GroupRoomInfo.js b/src/components/views/groups/GroupRoomInfo.js index 6241a2e357..fa4ed89ae0 100644 --- a/src/components/views/groups/GroupRoomInfo.js +++ b/src/components/views/groups/GroupRoomInfo.js @@ -61,9 +61,7 @@ module.exports = React.createClass({ }, _initGroupStore(groupId) { - this._groupStore = GroupStoreCache.getGroupStore( - this.context.matrixClient, this.props.groupId, - ); + this._groupStore = GroupStoreCache.getGroupStore(this.props.groupId); this._groupStore.registerListener(this.onGroupStoreUpdated); }, diff --git a/src/components/views/groups/GroupRoomList.js b/src/components/views/groups/GroupRoomList.js index ff27d093b2..189fa944e2 100644 --- a/src/components/views/groups/GroupRoomList.js +++ b/src/components/views/groups/GroupRoomList.js @@ -19,15 +19,10 @@ import sdk from '../../../index'; import GroupStoreCache from '../../../stores/GroupStoreCache'; import GeminiScrollbar from 'react-gemini-scrollbar'; import PropTypes from 'prop-types'; -import {MatrixClient} from 'matrix-js-sdk'; const INITIAL_LOAD_NUM_ROOMS = 30; export default React.createClass({ - contextTypes: { - matrixClient: React.PropTypes.instanceOf(MatrixClient).isRequired, - }, - propTypes: { groupId: PropTypes.string.isRequired, }, @@ -46,7 +41,7 @@ export default React.createClass({ }, _initGroupStore: function(groupId) { - this._groupStore = GroupStoreCache.getGroupStore(this.context.matrixClient, groupId); + this._groupStore = GroupStoreCache.getGroupStore(groupId); this._groupStore.registerListener(() => { this._fetchRooms(); }); diff --git a/src/stores/GroupStore.js b/src/stores/GroupStore.js index cb8b77ceb7..8d95d1975b 100644 --- a/src/stores/GroupStore.js +++ b/src/stores/GroupStore.js @@ -17,6 +17,7 @@ limitations under the License. import EventEmitter from 'events'; import { groupMemberFromApiObject, groupRoomFromApiObject } from '../groups'; import FlairStore from './FlairStore'; +import MatrixClientPeg from '../MatrixClientPeg'; /** * Stores the group summary for a room and provides an API to change it and @@ -31,13 +32,12 @@ export default class GroupStore extends EventEmitter { GroupRooms: 'GroupRooms', }; - constructor(matrixClient, groupId) { + constructor(groupId) { super(); if (!groupId) { throw new Error('GroupStore needs a valid groupId to be created'); } this.groupId = groupId; - this._matrixClient = matrixClient; this._summary = {}; this._rooms = []; this._members = []; @@ -50,7 +50,7 @@ export default class GroupStore extends EventEmitter { } _fetchMembers() { - this._matrixClient.getGroupUsers(this.groupId).then((result) => { + MatrixClientPeg.get().getGroupUsers(this.groupId).then((result) => { this._members = result.chunk.map((apiMember) => { return groupMemberFromApiObject(apiMember); }); @@ -61,7 +61,7 @@ export default class GroupStore extends EventEmitter { this.emit('error', err); }); - this._matrixClient.getGroupInvitedUsers(this.groupId).then((result) => { + MatrixClientPeg.get().getGroupInvitedUsers(this.groupId).then((result) => { this._invitedMembers = result.chunk.map((apiMember) => { return groupMemberFromApiObject(apiMember); }); @@ -78,7 +78,7 @@ export default class GroupStore extends EventEmitter { } _fetchSummary() { - this._matrixClient.getGroupSummary(this.groupId).then((resp) => { + MatrixClientPeg.get().getGroupSummary(this.groupId).then((resp) => { this._summary = resp; this._ready[GroupStore.STATE_KEY.Summary] = true; this._notifyListeners(); @@ -88,7 +88,7 @@ export default class GroupStore extends EventEmitter { } _fetchRooms() { - this._matrixClient.getGroupRooms(this.groupId).then((resp) => { + MatrixClientPeg.get().getGroupRooms(this.groupId).then((resp) => { this._rooms = resp.chunk.map((apiRoom) => { return groupRoomFromApiObject(apiRoom); }); @@ -145,19 +145,19 @@ export default class GroupStore extends EventEmitter { } addRoomToGroup(roomId, isPublic) { - return this._matrixClient + return MatrixClientPeg.get() .addRoomToGroup(this.groupId, roomId, isPublic) .then(this._fetchRooms.bind(this)); } updateGroupRoomVisibility(roomId, isPublic) { - return this._matrixClient + return MatrixClientPeg.get() .updateGroupRoomVisibility(this.groupId, roomId, isPublic) .then(this._fetchRooms.bind(this)); } removeRoomFromGroup(roomId) { - return this._matrixClient + return MatrixClientPeg.get() .removeRoomFromGroup(this.groupId, roomId) // Room might be in the summary, refresh just in case .then(this._fetchSummary.bind(this)) @@ -165,12 +165,12 @@ export default class GroupStore extends EventEmitter { } inviteUserToGroup(userId) { - return this._matrixClient.inviteUserToGroup(this.groupId, userId) + return MatrixClientPeg.get().inviteUserToGroup(this.groupId, userId) .then(this._fetchMembers.bind(this)); } acceptGroupInvite() { - return this._matrixClient.acceptGroupInvite(this.groupId) + return MatrixClientPeg.get().acceptGroupInvite(this.groupId) // The user might be able to see more rooms now .then(this._fetchRooms.bind(this)) // The user should now appear as a member @@ -178,33 +178,33 @@ export default class GroupStore extends EventEmitter { } addRoomToGroupSummary(roomId, categoryId) { - return this._matrixClient + return MatrixClientPeg.get() .addRoomToGroupSummary(this.groupId, roomId, categoryId) .then(this._fetchSummary.bind(this)); } addUserToGroupSummary(userId, roleId) { - return this._matrixClient + return MatrixClientPeg.get() .addUserToGroupSummary(this.groupId, userId, roleId) .then(this._fetchSummary.bind(this)); } removeRoomFromGroupSummary(roomId) { - return this._matrixClient + return MatrixClientPeg.get() .removeRoomFromGroupSummary(this.groupId, roomId) .then(this._fetchSummary.bind(this)); } removeUserFromGroupSummary(userId) { - return this._matrixClient + return MatrixClientPeg.get() .removeUserFromGroupSummary(this.groupId, userId) .then(this._fetchSummary.bind(this)); } setGroupPublicity(isPublished) { - return this._matrixClient + return MatrixClientPeg.get() .setGroupPublicity(this.groupId, isPublished) - .then(() => { FlairStore.invalidatePublicisedGroups(this._matrixClient.credentials.userId); }) + .then(() => { FlairStore.invalidatePublicisedGroups(MatrixClientPeg.get().credentials.userId); }) .then(this._fetchSummary.bind(this)); } } diff --git a/src/stores/GroupStoreCache.js b/src/stores/GroupStoreCache.js index df5ffcda5e..3264b197d7 100644 --- a/src/stores/GroupStoreCache.js +++ b/src/stores/GroupStoreCache.js @@ -21,12 +21,12 @@ class GroupStoreCache { this.groupStore = null; } - getGroupStore(matrixClient, groupId) { + getGroupStore(groupId) { if (!this.groupStore || this.groupStore.groupId !== groupId) { // This effectively throws away the reference to any previous GroupStore, // allowing it to be GCd once the components referencing it have stopped // referencing it. - this.groupStore = new GroupStore(matrixClient, groupId); + this.groupStore = new GroupStore(groupId); } this.groupStore._fetchSummary(); return this.groupStore; diff --git a/src/utils/MultiInviter.js b/src/utils/MultiInviter.js index 02c413ac83..a0f33f5c39 100644 --- a/src/utils/MultiInviter.js +++ b/src/utils/MultiInviter.js @@ -119,7 +119,7 @@ export default class MultiInviter { let doInvite; if (this.groupId !== null) { doInvite = GroupStoreCache - .getGroupStore(MatrixClientPeg.get(), this.groupId) + .getGroupStore(this.groupId) .inviteUserToGroup(addr); } else { doInvite = inviteToRoom(this.roomId, addr);