From e3a07be12790ddade32caa990a7fb40fb95a211f Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Tue, 1 May 2018 13:14:01 +0100 Subject: [PATCH 1/4] Remove GroupStore logging --- src/stores/GroupStore.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/stores/GroupStore.js b/src/stores/GroupStore.js index 23ce5314ec..49596550ea 100644 --- a/src/stores/GroupStore.js +++ b/src/stores/GroupStore.js @@ -140,7 +140,6 @@ class GroupStore extends EventEmitter { clientPromise.then((result) => { this._state[stateKey][groupId] = result; - console.info(this._state); this._ready[stateKey][groupId] = true; this._notifyListeners(); }).catch((err) => { From 4d8394954c2db411608608dd9cf3fac57034b788 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Tue, 1 May 2018 14:24:58 +0100 Subject: [PATCH 2/4] Only create one group store listener in RoomList Instead of creating several and destroying the reference to the one created before. --- src/components/views/rooms/RoomList.js | 19 +++++++++++-------- src/stores/GroupStore.js | 10 ++++++---- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/components/views/rooms/RoomList.js b/src/components/views/rooms/RoomList.js index b70c4a994e..fc1872249f 100644 --- a/src/components/views/rooms/RoomList.js +++ b/src/components/views/rooms/RoomList.js @@ -91,19 +91,22 @@ module.exports = React.createClass({ // All rooms that should be kept in the room list when filtering. // By default, show all rooms. this._visibleRooms = MatrixClientPeg.get().getRooms(); - // When the selected tags are changed, initialise a group store if necessary - this._tagStoreToken = TagOrderStore.addListener(() => { + + // Listen to updates to group data. RoomList cares about members and rooms in order + // to filter the room list when group tags are selected. + this._groupStoreToken = GroupStore.registerListener(null, () => { (TagOrderStore.getOrderedTags() || []).forEach((tag) => { if (tag[0] !== '+') { return; } - this._groupStoreToken = GroupStore.registerListener(tag, () => { - // This group's rooms or members may have updated, update rooms for its tag - this.updateVisibleRoomsForTag(dmRoomMap, tag); - this.updateVisibleRooms(); - }); + // This group's rooms or members may have updated, update rooms for its tag + this.updateVisibleRoomsForTag(dmRoomMap, tag); + this.updateVisibleRooms(); }); - // Filters themselves have changed, refresh the selected tags + }); + + this._tagStoreToken = TagOrderStore.addListener(() => { + // Filters themselves have changed this.updateVisibleRooms(); }); diff --git a/src/stores/GroupStore.js b/src/stores/GroupStore.js index 49596550ea..b0c7f8f19f 100644 --- a/src/stores/GroupStore.js +++ b/src/stores/GroupStore.js @@ -183,10 +183,12 @@ class GroupStore extends EventEmitter { // Call to set initial state (before fetching starts) this.emit('update'); - this._fetchResource(this.STATE_KEY.Summary, groupId); - this._fetchResource(this.STATE_KEY.GroupRooms, groupId); - this._fetchResource(this.STATE_KEY.GroupMembers, groupId); - this._fetchResource(this.STATE_KEY.GroupInvitedMembers, groupId); + if (groupId) { + this._fetchResource(this.STATE_KEY.Summary, groupId); + this._fetchResource(this.STATE_KEY.GroupRooms, groupId); + this._fetchResource(this.STATE_KEY.GroupMembers, groupId); + this._fetchResource(this.STATE_KEY.GroupInvitedMembers, groupId); + } // Similar to the Store of flux/utils, we return a "token" that // can be used to unregister the listener. From 56ec7713bb81804a9cda6ae97aa19915ea2e4971 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Tue, 1 May 2018 16:54:14 +0100 Subject: [PATCH 3/4] Refresh group rooms and members when selecting a tag --- src/components/views/elements/TagTile.js | 12 ++++++++++++ src/stores/GroupStore.js | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/src/components/views/elements/TagTile.js b/src/components/views/elements/TagTile.js index 4ea1b65123..c5fdea0a54 100644 --- a/src/components/views/elements/TagTile.js +++ b/src/components/views/elements/TagTile.js @@ -24,6 +24,7 @@ import { isOnlyCtrlOrCmdIgnoreShiftKeyEvent } from '../../../Keyboard'; import ContextualMenu from '../../structures/ContextualMenu'; import FlairStore from '../../../stores/FlairStore'; +import GroupStore from '../../../stores/GroupStore'; // A class for a child of TagPanel (possibly wrapped in a DNDTagTile) that represents // a thing to click on for the user to filter the visible rooms in the RoomList to: @@ -57,6 +58,8 @@ export default React.createClass({ if (this.props.tag[0] === '+') { FlairStore.addListener('updateGroupProfile', this._onFlairStoreUpdated); this._onFlairStoreUpdated(); + // New rooms or members may have been added to the group, fetch async + this._refreshGroup(this.props.tag); } }, @@ -80,6 +83,11 @@ export default React.createClass({ }); }, + _refreshGroup(groupId) { + GroupStore.refreshGroupRooms(groupId); + GroupStore.refreshGroupMembers(groupId); + }, + onClick: function(e) { e.preventDefault(); e.stopPropagation(); @@ -89,6 +97,10 @@ export default React.createClass({ ctrlOrCmdKey: isOnlyCtrlOrCmdIgnoreShiftKeyEvent(e), shiftKey: e.shiftKey, }); + if (this.props.tag[0] === '+') { + // New rooms or members may have been added to the group, fetch async + this._refreshGroup(this.props.tag); + } }, onContextButtonClick: function(e) { diff --git a/src/stores/GroupStore.js b/src/stores/GroupStore.js index b0c7f8f19f..e750dc1a6b 100644 --- a/src/stores/GroupStore.js +++ b/src/stores/GroupStore.js @@ -233,6 +233,14 @@ class GroupStore extends EventEmitter { (this._state[this.STATE_KEY.Summary][groupId] || {}).user.is_privileged : null; } + refreshGroupRooms(groupId) { + return this._fetchResource(this.STATE_KEY.GroupRooms, groupId); + } + + refreshGroupMembers(groupId) { + return this._fetchResource(this.STATE_KEY.GroupMembers, groupId); + } + addRoomToGroup(groupId, roomId, isPublic) { return MatrixClientPeg.get() .addRoomToGroup(groupId, roomId, isPublic) From bd703b17e58041d6e1cdb886af2939d0e30112b3 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Tue, 1 May 2018 16:57:28 +0100 Subject: [PATCH 4/4] Update documentation for GroupStore.registerListener --- src/stores/GroupStore.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/stores/GroupStore.js b/src/stores/GroupStore.js index e750dc1a6b..03132cd80f 100644 --- a/src/stores/GroupStore.js +++ b/src/stores/GroupStore.js @@ -167,11 +167,12 @@ class GroupStore extends EventEmitter { * immediately triggers an update to send the current state of the * store (which could be the initial state). * - * This also causes a fetch of all data of the specified group, - * which might cause 4 separate HTTP requests, but only if said - * requests aren't already ongoing. + * If a group ID is specified, this also causes a fetch of all data + * of the specified group, which might cause 4 separate HTTP + * requests, but only if said requests aren't already ongoing. * - * @param {string} groupId the ID of the group to fetch data for. + * @param {string?} groupId the ID of the group to fetch data for. + * Optional. * @param {function} fn the function to call when the store updates. * @return {Object} tok a registration "token" with a single * property `unregister`, a function that can