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

Handle breadcrumbs, integration manager provisioning, and allowed widgets Riot settings #3577

Merged
merged 6 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/settings/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
62 changes: 54 additions & 8 deletions src/settings/handlers/AccountSettingsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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() || {};
Expand All @@ -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);
Expand All @@ -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 || []);
}
}
14 changes: 14 additions & 0 deletions src/settings/handlers/RoomAccountSettingsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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];
}
Expand All @@ -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);
Expand Down