Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2589 from matrix-org/bwindels/customtags-featureflag
Browse files Browse the repository at this point in the history
guard custom tags with feature flag
  • Loading branch information
bwindels authored Feb 8, 2019
2 parents 00a1ca5 + 3c5fb61 commit 0087765
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/components/structures/LeftPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (<div className="mx_LeftPanel_tagPanelContainer">
<TagPanel />
<CustomRoomTagPanel />
{ isCustomTagsEnabled ? <CustomRoomTagPanel /> : undefined }
<TagPanelButtons />
</div>);
}
Expand Down
14 changes: 9 additions & 5 deletions src/components/views/rooms/RoomList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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],
Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
"Backup of encryption keys to server": "Backup of encryption keys to server",
"Render simple counters in room header": "Render simple counters in room header",
"Two-way device verification using short text": "Two-way device verification using short text",
Expand Down
6 changes: 6 additions & 0 deletions src/settings/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,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_keybackup": {
isFeature: true,
displayName: _td("Backup of encryption keys to server"),
Expand Down
6 changes: 6 additions & 0 deletions src/stores/CustomRoomTagStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))$/;

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/stores/RoomListStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down

0 comments on commit 0087765

Please sign in to comment.