Merge pull request #1635 from matrix-org/luke/allow-guest-view-group

Allow guests to view individual groups
This commit is contained in:
Luke Barnard 2017-11-28 14:07:22 +00:00 committed by GitHub
commit 6761c9f526
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 42 additions and 49 deletions

View file

@ -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

View file

@ -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,

View file

@ -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);

View file

@ -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);
},

View file

@ -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({
</div>
);
},
}));
});

View file

@ -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(),

View file

@ -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);
},

View file

@ -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();
});

View file

@ -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));
}
}

View file

@ -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;

View file

@ -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);