From e8533beafb08a2b4378f48029ecc2c98bb047ba6 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 7 Feb 2019 18:04:30 +0000 Subject: [PATCH 1/2] guard custom tags with feature flag --- src/components/structures/LeftPanel.js | 5 ++++- src/components/views/rooms/RoomList.js | 14 +++++++++----- src/i18n/strings/en_EN.json | 1 + src/settings/Settings.js | 6 ++++++ src/stores/CustomRoomTagStore.js | 6 ++++++ src/stores/RoomListStore.js | 4 +++- 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/components/structures/LeftPanel.js b/src/components/structures/LeftPanel.js index 0ae9b032d1..bd49f8acd4 100644 --- a/src/components/structures/LeftPanel.js +++ b/src/components/structures/LeftPanel.js @@ -190,10 +190,13 @@ const LeftPanel = React.createClass({ const tagPanelEnabled = SettingsStore.getValue("TagPanel.enableTagPanel"); let tagPanelContainer; + + const isCustomTagsEnabled = SettingsStore.isFeatureEnabled("feature_custom_tags"); + if (tagPanelEnabled) { tagPanelContainer = (
- + { isCustomTagsEnabled ? : undefined }
); } diff --git a/src/components/views/rooms/RoomList.js b/src/components/views/rooms/RoomList.js index 8418ab6d6f..e1a3c397e6 100644 --- a/src/components/views/rooms/RoomList.js +++ b/src/components/views/rooms/RoomList.js @@ -172,11 +172,14 @@ module.exports = React.createClass({ this._delayedRefreshRoomList(); }); - this._customTagStoreToken = CustomRoomTagStore.addListener(() => { - this.setState({ - customTags: CustomRoomTagStore.getTags(), + + if (SettingsStore.isFeatureEnabled("feature_custom_tags")) { + this._customTagStoreToken = CustomRoomTagStore.addListener(() => { + this.setState({ + customTags: CustomRoomTagStore.getTags(), + }); }); - }); + } this.refreshRoomList(); @@ -728,7 +731,8 @@ module.exports = React.createClass({ ]; const tagSubLists = Object.keys(this.state.lists) .filter((tagName) => { - return this.state.customTags[tagName] && !tagName.match(STANDARD_TAGS_REGEX); + return (!this.state.customTags || this.state.customTags[tagName]) && + !tagName.match(STANDARD_TAGS_REGEX); }).map((tagName) => { return { list: this.state.lists[tagName], diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index b586d2f8f7..a5b04f1981 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -264,6 +264,7 @@ "Failed to join room": "Failed to join room", "Message Pinning": "Message Pinning", "Custom user status messages": "Custom user status messages", + "Group & filter rooms by custom tags (refresh to apply changes)": "Group & filter rooms by custom tags (refresh to apply changes)", "Increase performance by only loading room members on first view": "Increase performance by only loading room members on first view", "Backup of encryption keys to server": "Backup of encryption keys to server", "Render simple counters in room header": "Render simple counters in room header", diff --git a/src/settings/Settings.js b/src/settings/Settings.js index c5de7298de..d9363315f5 100644 --- a/src/settings/Settings.js +++ b/src/settings/Settings.js @@ -100,6 +100,12 @@ export const SETTINGS = { default: false, controller: new CustomStatusController(), }, + "feature_custom_tags": { + isFeature: true, + displayName: _td("Group & filter rooms by custom tags (refresh to apply changes)"), + supportedLevels: LEVELS_FEATURE, + default: false, + }, "feature_lazyloading": { isFeature: true, displayName: _td("Increase performance by only loading room members on first view"), diff --git a/src/stores/CustomRoomTagStore.js b/src/stores/CustomRoomTagStore.js index 9795abadc6..0f7f99aad9 100644 --- a/src/stores/CustomRoomTagStore.js +++ b/src/stores/CustomRoomTagStore.js @@ -18,6 +18,7 @@ import * as RoomNotifs from '../RoomNotifs'; import RoomListStore from './RoomListStore'; import EventEmitter from 'events'; import { throttle } from "lodash"; +import SettingsStore from "../settings/SettingsStore"; const STANDARD_TAGS_REGEX = /^(m\.(favourite|lowpriority|server_notice)|im\.vector\.fake\.(invite|recent|direct|archived))$/; @@ -50,6 +51,7 @@ class CustomRoomTagStore extends EventEmitter { super(); // Initialise state this._state = {tags: {}}; + // as RoomListStore gets updated by every timeline event // throttle this to only run every 500ms this._getUpdatedTags = throttle( @@ -133,6 +135,10 @@ class CustomRoomTagStore extends EventEmitter { } _getUpdatedTags() { + if (!SettingsStore.isFeatureEnabled("feature_custom_tags")) { + return; + } + const newTagNames = Object.keys(RoomListStore.getRoomLists()) .filter((tagName) => { return !tagName.match(STANDARD_TAGS_REGEX); diff --git a/src/stores/RoomListStore.js b/src/stores/RoomListStore.js index 61e17821bd..d98adc5cae 100644 --- a/src/stores/RoomListStore.js +++ b/src/stores/RoomListStore.js @@ -202,6 +202,8 @@ class RoomListStore extends Store { // If somehow we dispatched a RoomListActions.tagRoom.failure before a MatrixActions.sync if (!this._matrixClient) return; + const isCustomTagsEnabled = SettingsStore.isFeatureEnabled("feature_custom_tags"); + this._matrixClient.getRooms().forEach((room, index) => { const myUserId = this._matrixClient.getUserId(); const membership = room.getMyMembership(); @@ -226,7 +228,7 @@ class RoomListStore extends Store { // ignore any m. tag names we don't know about tagNames = tagNames.filter((t) => { - return !t.startsWith('m.') || lists[t] !== undefined; + return (isCustomTagsEnabled && !t.startsWith('m.')) || lists[t] !== undefined; }); if (tagNames.length) { From 2eff03ba78c0f9ac6c028de5059b9546b1e49526 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 8 Feb 2019 12:03:58 +0000 Subject: [PATCH 2/2] fix whitespace --- src/components/views/rooms/RoomList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/rooms/RoomList.js b/src/components/views/rooms/RoomList.js index e1a3c397e6..56eb4b713d 100644 --- a/src/components/views/rooms/RoomList.js +++ b/src/components/views/rooms/RoomList.js @@ -731,7 +731,7 @@ module.exports = React.createClass({ ]; const tagSubLists = Object.keys(this.state.lists) .filter((tagName) => { - return (!this.state.customTags || this.state.customTags[tagName]) && + return (!this.state.customTags || this.state.customTags[tagName]) && !tagName.match(STANDARD_TAGS_REGEX); }).map((tagName) => { return {