Merge pull request #3577 from matrix-org/travis/riot-settings

Handle breadcrumbs, integration manager provisioning, and allowed widgets Riot settings
pull/21833/head
Travis Ralston 2019-11-01 12:05:57 -06:00 committed by GitHub
commit bb6ae14a03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 8 deletions

View File

@ -279,6 +279,14 @@ export const SETTINGS = {
supportedLevels: ['account'],
default: [],
},
"integrationProvisioning": {
supportedLevels: ['account'],
default: true,
},
"allowedWidgets": {
supportedLevels: ['room-account'],
default: {}, // none allowed
},
"analyticsOptIn": {
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td('Send analytics data'),

View File

@ -19,7 +19,11 @@ import MatrixClientPeg from '../../MatrixClientPeg';
import MatrixClientBackedSettingsHandler from "./MatrixClientBackedSettingsHandler";
import {SettingLevel} from "../SettingsStore";
const BREADCRUMBS_EVENT_TYPE = "im.vector.riot.breadcrumb_rooms";
const BREADCRUMBS_LEGACY_EVENT_TYPE = "im.vector.riot.breadcrumb_rooms";
const BREADCRUMBS_EVENT_TYPE = "im.vector.setting.breadcrumbs";
const BREADCRUMBS_EVENT_TYPES = [BREADCRUMBS_LEGACY_EVENT_TYPE, BREADCRUMBS_EVENT_TYPE];
const INTEG_PROVISIONING_EVENT_TYPE = "im.vector.setting.integration_provisioning";
/**
* Gets and sets settings at the "account" level for the current user.
@ -57,9 +61,11 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
const val = event.getContent()[settingName];
this._watchers.notifyUpdate(settingName, null, SettingLevel.ACCOUNT, val);
}
} else if (event.getType() === BREADCRUMBS_EVENT_TYPE) {
const val = event.getContent()['rooms'] || [];
this._watchers.notifyUpdate("breadcrumb_rooms", null, SettingLevel.ACCOUNT, val);
} else if (BREADCRUMBS_EVENT_TYPES.includes(event.getType())) {
this._notifyBreadcrumbsUpdate(event);
} else if (event.getType() === INTEG_PROVISIONING_EVENT_TYPE) {
const val = event.getContent()['enabled'];
this._watchers.notifyUpdate("integrationProvisioning", null, SettingLevel.ACCOUNT, val);
}
}
@ -75,8 +81,21 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
// Special case for breadcrumbs
if (settingName === "breadcrumb_rooms") {
const content = this._getSettings(BREADCRUMBS_EVENT_TYPE) || {};
return content['rooms'] || [];
let content = this._getSettings(BREADCRUMBS_EVENT_TYPE);
if (!content || !content['recent_rooms']) {
content = this._getSettings(BREADCRUMBS_LEGACY_EVENT_TYPE);
// This is a bit of a hack, but it makes things slightly easier
if (content) content['recent_rooms'] = content['rooms'];
}
return content && content['recent_rooms'] ? content['recent_rooms'] : [];
}
// Special case integration manager provisioning
if (settingName === "integrationProvisioning") {
const content = this._getSettings(INTEG_PROVISIONING_EVENT_TYPE);
return content ? content['enabled'] : null;
}
const settings = this._getSettings() || {};
@ -102,11 +121,23 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
// Special case for breadcrumbs
if (settingName === "breadcrumb_rooms") {
const content = this._getSettings(BREADCRUMBS_EVENT_TYPE) || {};
content['rooms'] = newValue;
// We read the value first just to make sure we preserve whatever random keys might be present.
let content = this._getSettings(BREADCRUMBS_EVENT_TYPE);
if (!content || !content['recent_rooms']) {
content = this._getSettings(BREADCRUMBS_LEGACY_EVENT_TYPE);
}
content['recent_rooms'] = newValue;
return MatrixClientPeg.get().setAccountData(BREADCRUMBS_EVENT_TYPE, content);
}
// Special case integration manager provisioning
if (settingName === "integrationProvisioning") {
const content = this._getSettings(INTEG_PROVISIONING_EVENT_TYPE) || {};
content['enabled'] = newValue;
return MatrixClientPeg.get().setAccountData(INTEG_PROVISIONING_EVENT_TYPE, content);
}
const content = this._getSettings() || {};
content[settingName] = newValue;
return MatrixClientPeg.get().setAccountData("im.vector.web.settings", content);
@ -129,4 +160,19 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
if (!event || !event.getContent()) return null;
return event.getContent();
}
_notifyBreadcrumbsUpdate(event) {
let val = [];
if (event.getType() === BREADCRUMBS_LEGACY_EVENT_TYPE) {
// This seems fishy - try and get the event for the new rooms
const newType = this._getSettings(BREADCRUMBS_EVENT_TYPE);
if (newType) val = newType['recent_rooms'];
else val = event.getContent()['rooms'];
} else if (event.getType() === BREADCRUMBS_EVENT_TYPE) {
val = event.getContent()['recent_rooms'];
} else {
return; // for sanity, not because we expect to be here.
}
this._watchers.notifyUpdate("breadcrumb_rooms", null, SettingLevel.ACCOUNT, val || []);
}
}

View File

@ -19,6 +19,8 @@ import MatrixClientPeg from '../../MatrixClientPeg';
import MatrixClientBackedSettingsHandler from "./MatrixClientBackedSettingsHandler";
import {SettingLevel} from "../SettingsStore";
const ALLOWED_WIDGETS_EVENT_TYPE = "im.vector.setting.allowed_widgets";
/**
* Gets and sets settings at the "room-account" level for the current user.
*/
@ -58,6 +60,8 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin
const val = event.getContent()[settingName];
this._watchers.notifyUpdate(settingName, roomId, SettingLevel.ROOM_ACCOUNT, val);
}
} else if (event.getType() === ALLOWED_WIDGETS_EVENT_TYPE) {
this._watchers.notifyUpdate("allowedWidgets", roomId, SettingLevel.ROOM_ACCOUNT, event.getContent());
}
}
@ -79,6 +83,11 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin
return this._getSettings(roomId, "org.matrix.room.color_scheme");
}
// Special case allowed widgets
if (settingName === "allowedWidgets") {
return this._getSettings(roomId, ALLOWED_WIDGETS_EVENT_TYPE);
}
const settings = this._getSettings(roomId) || {};
return settings[settingName];
}
@ -97,6 +106,11 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin
return MatrixClientPeg.get().setRoomAccountData(roomId, "org.matrix.room.color_scheme", newValue);
}
// Special case allowed widgets
if (settingName === "allowedWidgets") {
return MatrixClientPeg.get().setRoomAccountData(roomId, ALLOWED_WIDGETS_EVENT_TYPE, newValue);
}
const content = this._getSettings(roomId) || {};
content[settingName] = newValue;
return MatrixClientPeg.get().setRoomAccountData(roomId, "im.vector.web.settings", content);