Split updatedSelectedTagsRooms

because we don't need to get the rooms for all groups when
the filtered tags change.
This commit is contained in:
Luke Barnard 2017-12-15 14:23:35 +00:00
parent df1134f092
commit 961d5e1868

View file

@ -102,11 +102,12 @@ module.exports = React.createClass({
this._groupStores[tag] = GroupStoreCache.getGroupStore(tag); this._groupStores[tag] = GroupStoreCache.getGroupStore(tag);
this._groupStores[tag].registerListener(() => { this._groupStores[tag].registerListener(() => {
// This group's rooms or members may have updated, update rooms for its tag // This group's rooms or members may have updated, update rooms for its tag
this.updateSelectedTagsRooms(dmRoomMap, [tag]); this.updateSelectedTagsRoomsForGroups(dmRoomMap, tag);
this.updateSelectedTagsRooms();
}); });
}); });
// Filters themselves have changed, refresh the selected tags // Filters themselves have changed, refresh the selected tags
this.updateSelectedTagsRooms(dmRoomMap, FilterStore.getSelectedTags()); this.updateSelectedTagsRooms();
}); });
this.refreshRoomList(); this.refreshRoomList();
@ -269,24 +270,24 @@ module.exports = React.createClass({
}, 500), }, 500),
// Update which rooms and users should appear in RoomList as dictated by selected tags // Update which rooms and users should appear in RoomList as dictated by selected tags
updateSelectedTagsRooms: function(dmRoomMap, updatedTags) { updateSelectedTagsRoomsForGroups: function(dmRoomMap, tag) {
if (!this.mounted) return; if (!this.mounted) return;
updatedTags.forEach((tag) => { // For now, only handle group tags
// For now, only handle group tags const store = this._groupStores[tag];
const store = this._groupStores[tag]; if (!store) return;
if (!store) return;
this._selectedTagsRoomIdsForGroup[tag] = []; this._selectedTagsRoomIdsForGroup[tag] = [];
store.getGroupRooms().forEach((room) => this._selectedTagsRoomIdsForGroup[tag].push(room.roomId)); store.getGroupRooms().forEach((room) => this._selectedTagsRoomIdsForGroup[tag].push(room.roomId));
store.getGroupMembers().forEach((member) => { store.getGroupMembers().forEach((member) => {
if (member.userId === MatrixClientPeg.get().credentials.userId) return; if (member.userId === MatrixClientPeg.get().credentials.userId) return;
dmRoomMap.getDMRoomsForUserId(member.userId).forEach( dmRoomMap.getDMRoomsForUserId(member.userId).forEach(
(roomId) => this._selectedTagsRoomIdsForGroup[tag].push(roomId), (roomId) => this._selectedTagsRoomIdsForGroup[tag].push(roomId),
); );
});
// TODO: Check if room has been tagged to the group by the user
}); });
// TODO: Check if room has been tagged to the group by the user
},
updateSelectedTagsRooms: function() {
this._selectedTagsRoomIds = []; this._selectedTagsRoomIds = [];
FilterStore.getSelectedTags().forEach((tag) => { FilterStore.getSelectedTags().forEach((tag) => {
(this._selectedTagsRoomIdsForGroup[tag] || []).forEach( (this._selectedTagsRoomIdsForGroup[tag] || []).forEach(