Support semi-perma-disabling of lab features

Adding `override: true` will remove the feature from the labs section, and force Riot to always use the default value (i.e. ignoring localStorage). This is useful removing features entirely when they might be deliberately not working but we still want to do a release.
This commit is contained in:
Luke Barnard 2017-08-14 12:26:31 +01:00
parent 02217c8bd2
commit cbd8018ac8
2 changed files with 39 additions and 13 deletions

View file

@ -171,22 +171,36 @@ export default {
localStorage.setItem('mx_local_settings', JSON.stringify(settings));
},
isFeatureEnabled: function(feature: string): boolean {
getFeatureById(feature: string) {
for (let i = 0; i < this.LABS_FEATURES.length; i++) {
const f = this.LABS_FEATURES[i];
if (f.id === feature) {
return f;
}
}
return null;
},
isFeatureEnabled: function(featureId: string): boolean {
// Disable labs for guests.
if (MatrixClientPeg.get().isGuest()) return false;
if (localStorage.getItem(`mx_labs_feature_${feature}`) === null) {
for (let i = 0; i < this.LABS_FEATURES.length; i++) {
const f = this.LABS_FEATURES[i];
if (f.id === feature) {
return f.default;
}
}
const feature = this.getFeatureById(featureId);
if (!feature) {
console.warn('Unknown feature');
return false;
}
return localStorage.getItem(`mx_labs_feature_${feature}`) === 'true';
// Return the default if this feature has an override to be the default value or
// if the feature has never been toggled and is therefore not in localStorage
if (Object.keys(feature).includes('override') ||
localStorage.getItem(`mx_labs_feature_${featureId}`) === null
) {
return feature.default;
}
return localStorage.getItem(`mx_labs_feature_${featureId}`) === 'true';
},
setFeatureEnabled: function(feature: string, enabled: boolean) {
localStorage.setItem(`mx_labs_feature_${feature}`, enabled);
setFeatureEnabled: function(featureId: string, enabled: boolean) {
localStorage.setItem(`mx_labs_feature_${featureId}`, enabled);
},
};