Pass matrixClient as an argument to GSS constructor

pull/21833/head
Luke Barnard 2017-09-25 10:02:13 +01:00
parent 791bc5e7ac
commit b8dca58f4f
2 changed files with 10 additions and 8 deletions

View File

@ -430,7 +430,9 @@ export default React.createClass({
}, },
_loadGroupFromServer: function(groupId) { _loadGroupFromServer: function(groupId) {
this._groupSummaryStore = new GroupSummaryStore(this.props.groupId); this._groupSummaryStore = new GroupSummaryStore(
MatrixClientPeg.get(), this.props.groupId,
);
this._groupSummaryStore.on('update', () => { this._groupSummaryStore.on('update', () => {
this.setState({ this.setState({
summary: this._groupSummaryStore.getSummary(), summary: this._groupSummaryStore.getSummary(),

View File

@ -15,21 +15,21 @@ limitations under the License.
*/ */
import EventEmitter from 'events'; import EventEmitter from 'events';
import MatrixClientPeg from '../MatrixClientPeg';
/** /**
* Stores the group summary for a room and provides an API to change it * Stores the group summary for a room and provides an API to change it
*/ */
export default class GroupSummaryStore extends EventEmitter { export default class GroupSummaryStore extends EventEmitter {
constructor(groupId) { constructor(matrixClient, groupId) {
super(); super();
this._groupId = groupId; this._groupId = groupId;
this._matrixClient = matrixClient;
this._summary = {}; this._summary = {};
this._fetchSummary(); this._fetchSummary();
} }
_fetchSummary() { _fetchSummary() {
MatrixClientPeg.get().getGroupSummary(this._groupId).then((resp) => { this._matrixClient.getGroupSummary(this._groupId).then((resp) => {
this._summary = resp; this._summary = resp;
this._notifyListeners(); this._notifyListeners();
}).catch((err) => { }).catch((err) => {
@ -46,25 +46,25 @@ export default class GroupSummaryStore extends EventEmitter {
} }
addRoomToGroupSummary(roomId, categoryId) { addRoomToGroupSummary(roomId, categoryId) {
return MatrixClientPeg.get() return this._matrixClient
.addRoomToGroupSummary(this._groupId, roomId, categoryId) .addRoomToGroupSummary(this._groupId, roomId, categoryId)
.then(this._fetchSummary.bind(this)); .then(this._fetchSummary.bind(this));
} }
addUserToGroupSummary(userId, roleId) { addUserToGroupSummary(userId, roleId) {
return MatrixClientPeg.get() return this._matrixClient
.addUserToGroupSummary(this._groupId, userId, roleId) .addUserToGroupSummary(this._groupId, userId, roleId)
.then(this._fetchSummary.bind(this)); .then(this._fetchSummary.bind(this));
} }
removeRoomFromGroupSummary(roomId) { removeRoomFromGroupSummary(roomId) {
return MatrixClientPeg.get() return this._matrixClient
.removeRoomFromGroupSummary(this._groupId, roomId) .removeRoomFromGroupSummary(this._groupId, roomId)
.then(this._fetchSummary.bind(this)); .then(this._fetchSummary.bind(this));
} }
removeUserFromGroupSummary(userId) { removeUserFromGroupSummary(userId) {
return MatrixClientPeg.get() return this._matrixClient
.removeUserFromGroupSummary(this._groupId, userId) .removeUserFromGroupSummary(this._groupId, userId)
.then(this._fetchSummary.bind(this)); .then(this._fetchSummary.bind(this));
} }