From e094c32c62861de392a76417e8cb543dcdd274f9 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 27 Oct 2017 11:36:32 +0100 Subject: [PATCH 1/2] Simplify GroupStore listener registration --- src/components/structures/GroupView.js | 3 +-- src/components/views/groups/GroupMemberList.js | 5 +---- src/components/views/groups/GroupRoomList.js | 4 +--- src/stores/GroupStore.js | 14 +++++++++++--- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/components/structures/GroupView.js b/src/components/structures/GroupView.js index 9d87f84aef..1564efd8d3 100644 --- a/src/components/structures/GroupView.js +++ b/src/components/structures/GroupView.js @@ -447,7 +447,7 @@ export default React.createClass({ _initGroupStore: function(groupId) { this._groupStore = GroupStoreCache.getGroupStore(MatrixClientPeg.get(), groupId); - this._groupStore.on('update', () => { + this._groupStore.registerListener(() => { const summary = this._groupStore.getSummary(); if (summary.profile) { // Default profile fields should be "" for later sending to the server (which @@ -464,7 +464,6 @@ export default React.createClass({ }); }); this._groupStore.on('error', (err) => { - console.error(err); this.setState({ summary: null, error: err, diff --git a/src/components/views/groups/GroupMemberList.js b/src/components/views/groups/GroupMemberList.js index a5ab22eb0e..8658ac19a5 100644 --- a/src/components/views/groups/GroupMemberList.js +++ b/src/components/views/groups/GroupMemberList.js @@ -50,12 +50,9 @@ export default withMatrixClient(React.createClass({ _initGroupStore: function(groupId) { this._groupStore = GroupStoreCache.getGroupStore(this.context.matrixClient, groupId); - this._groupStore.on('update', () => { + this._groupStore.registerListener(() => { this._fetchMembers(); }); - this._groupStore.on('error', (err) => { - console.error(err); - }); }, _fetchMembers: function() { diff --git a/src/components/views/groups/GroupRoomList.js b/src/components/views/groups/GroupRoomList.js index 3fcfedd486..aeded2dfb0 100644 --- a/src/components/views/groups/GroupRoomList.js +++ b/src/components/views/groups/GroupRoomList.js @@ -47,16 +47,14 @@ export default React.createClass({ _initGroupStore: function(groupId) { this._groupStore = GroupStoreCache.getGroupStore(this.context.matrixClient, groupId); - this._groupStore.on('update', () => { + this._groupStore.registerListener(() => { this._fetchRooms(); }); this._groupStore.on('error', (err) => { - console.error('Error in group store (listened to by GroupRoomList)', err); this.setState({ rooms: null, }); }); - this._fetchRooms(); }, _fetchRooms: function() { diff --git a/src/stores/GroupStore.js b/src/stores/GroupStore.js index 1da1c35a2b..1d3526ecd5 100644 --- a/src/stores/GroupStore.js +++ b/src/stores/GroupStore.js @@ -29,9 +29,10 @@ export default class GroupStore extends EventEmitter { this._matrixClient = matrixClient; this._summary = {}; this._rooms = []; - this._fetchSummary(); - this._fetchRooms(); - this._fetchMembers(); + + this.on('error', (err) => { + console.error(`GroupStore for ${this.groupId} encountered error`, err); + }); } _fetchMembers() { @@ -80,6 +81,13 @@ export default class GroupStore extends EventEmitter { this.emit('update'); } + registerListener(fn) { + this.on('update', fn); + this._fetchSummary(); + this._fetchRooms(); + this._fetchMembers(); + } + getSummary() { return this._summary; } From 5d0aa8d7f75eabaf2694f00b2fb51a0f1bead43c Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 27 Oct 2017 11:37:45 +0100 Subject: [PATCH 2/2] Handle 403 when inspecting invited users as non-member --- src/stores/GroupStore.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/stores/GroupStore.js b/src/stores/GroupStore.js index 1d3526ecd5..e169e13ddc 100644 --- a/src/stores/GroupStore.js +++ b/src/stores/GroupStore.js @@ -52,6 +52,10 @@ export default class GroupStore extends EventEmitter { }); this._notifyListeners(); }).catch((err) => { + // Invited users not visible to non-members + if (err.httpStatus === 403) { + return; + } console.error("Failed to get group invited member list: " + err); this.emit('error', err); });