mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 19:56:47 +03:00
Merge pull request #1710 from matrix-org/t3chguy/roomColor
don't pass back {} when we have no `org.matrix.room.color_scheme`
This commit is contained in:
commit
c090c2e7df
4 changed files with 29 additions and 22 deletions
|
@ -25,19 +25,20 @@ export default class AccountSettingHandler extends SettingsHandler {
|
||||||
getValue(settingName, roomId) {
|
getValue(settingName, roomId) {
|
||||||
// Special case URL previews
|
// Special case URL previews
|
||||||
if (settingName === "urlPreviewsEnabled") {
|
if (settingName === "urlPreviewsEnabled") {
|
||||||
const content = this._getSettings("org.matrix.preview_urls");
|
const content = this._getSettings("org.matrix.preview_urls") || {};
|
||||||
|
|
||||||
// Check to make sure that we actually got a boolean
|
// Check to make sure that we actually got a boolean
|
||||||
if (typeof(content['disable']) !== "boolean") return null;
|
if (typeof(content['disable']) !== "boolean") return null;
|
||||||
return !content['disable'];
|
return !content['disable'];
|
||||||
}
|
}
|
||||||
|
|
||||||
let preferredValue = this._getSettings()[settingName];
|
const settings = this._getSettings() || {};
|
||||||
|
let preferredValue = settings[settingName];
|
||||||
|
|
||||||
if (preferredValue === null || preferredValue === undefined) {
|
if (preferredValue === null || preferredValue === undefined) {
|
||||||
// Honour the old setting on read only
|
// Honour the old setting on read only
|
||||||
if (settingName === "hideAvatarChanges" || settingName === "hideDisplaynameChanges") {
|
if (settingName === "hideAvatarChanges" || settingName === "hideDisplaynameChanges") {
|
||||||
preferredValue = this._getSettings()["hideAvatarDisplaynameChanges"];
|
preferredValue = settings["hideAvatarDisplaynameChanges"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,12 +48,12 @@ export default class AccountSettingHandler extends SettingsHandler {
|
||||||
setValue(settingName, roomId, newValue) {
|
setValue(settingName, roomId, newValue) {
|
||||||
// Special case URL previews
|
// Special case URL previews
|
||||||
if (settingName === "urlPreviewsEnabled") {
|
if (settingName === "urlPreviewsEnabled") {
|
||||||
const content = this._getSettings("org.matrix.preview_urls");
|
const content = this._getSettings("org.matrix.preview_urls") || {};
|
||||||
content['disable'] = !newValue;
|
content['disable'] = !newValue;
|
||||||
return MatrixClientPeg.get().setAccountData("org.matrix.preview_urls", content);
|
return MatrixClientPeg.get().setAccountData("org.matrix.preview_urls", content);
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = this._getSettings();
|
const content = this._getSettings() || {};
|
||||||
content[settingName] = newValue;
|
content[settingName] = newValue;
|
||||||
return MatrixClientPeg.get().setAccountData("im.vector.web.settings", content);
|
return MatrixClientPeg.get().setAccountData("im.vector.web.settings", content);
|
||||||
}
|
}
|
||||||
|
@ -68,9 +69,10 @@ export default class AccountSettingHandler extends SettingsHandler {
|
||||||
|
|
||||||
_getSettings(eventType = "im.vector.web.settings") {
|
_getSettings(eventType = "im.vector.web.settings") {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.get();
|
||||||
if (!cli) return {};
|
if (!cli) return null;
|
||||||
|
|
||||||
const event = cli.getAccountData(eventType);
|
const event = cli.getAccountData(eventType);
|
||||||
if (!event || !event.getContent()) return {};
|
if (!event || !event.getContent()) return null;
|
||||||
return event.getContent();
|
return event.getContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,8 @@ export default class DeviceSettingsHandler extends SettingsHandler {
|
||||||
return null; // wrong type or otherwise not set
|
return null; // wrong type or otherwise not set
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._getSettings()[settingName];
|
const settings = this._getSettings() || {};
|
||||||
|
return settings[settingName];
|
||||||
}
|
}
|
||||||
|
|
||||||
setValue(settingName, roomId, newValue) {
|
setValue(settingName, roomId, newValue) {
|
||||||
|
@ -74,7 +75,7 @@ export default class DeviceSettingsHandler extends SettingsHandler {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
const settings = this._getSettings();
|
const settings = this._getSettings() || {};
|
||||||
settings[settingName] = newValue;
|
settings[settingName] = newValue;
|
||||||
localStorage.setItem("mx_local_settings", JSON.stringify(settings));
|
localStorage.setItem("mx_local_settings", JSON.stringify(settings));
|
||||||
|
|
||||||
|
@ -91,7 +92,7 @@ export default class DeviceSettingsHandler extends SettingsHandler {
|
||||||
|
|
||||||
_getSettings() {
|
_getSettings() {
|
||||||
const value = localStorage.getItem("mx_local_settings");
|
const value = localStorage.getItem("mx_local_settings");
|
||||||
if (!value) return {};
|
if (!value) return null;
|
||||||
return JSON.parse(value);
|
return JSON.parse(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ export default class RoomAccountSettingsHandler extends SettingsHandler {
|
||||||
getValue(settingName, roomId) {
|
getValue(settingName, roomId) {
|
||||||
// Special case URL previews
|
// Special case URL previews
|
||||||
if (settingName === "urlPreviewsEnabled") {
|
if (settingName === "urlPreviewsEnabled") {
|
||||||
const content = this._getSettings(roomId, "org.matrix.room.preview_urls");
|
const content = this._getSettings(roomId, "org.matrix.room.preview_urls") || {};
|
||||||
|
|
||||||
// Check to make sure that we actually got a boolean
|
// Check to make sure that we actually got a boolean
|
||||||
if (typeof(content['disable']) !== "boolean") return null;
|
if (typeof(content['disable']) !== "boolean") return null;
|
||||||
|
@ -35,16 +35,18 @@ export default class RoomAccountSettingsHandler extends SettingsHandler {
|
||||||
if (settingName === "roomColor") {
|
if (settingName === "roomColor") {
|
||||||
// The event content should already be in an appropriate format, we just need
|
// The event content should already be in an appropriate format, we just need
|
||||||
// to get the right value.
|
// to get the right value.
|
||||||
|
// don't fallback to {} because thats truthy and would imply there is an event specifying tint
|
||||||
return this._getSettings(roomId, "org.matrix.room.color_scheme");
|
return this._getSettings(roomId, "org.matrix.room.color_scheme");
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._getSettings(roomId)[settingName];
|
const settings = this._getSettings(roomId) || {};
|
||||||
|
return settings[settingName];
|
||||||
}
|
}
|
||||||
|
|
||||||
setValue(settingName, roomId, newValue) {
|
setValue(settingName, roomId, newValue) {
|
||||||
// Special case URL previews
|
// Special case URL previews
|
||||||
if (settingName === "urlPreviewsEnabled") {
|
if (settingName === "urlPreviewsEnabled") {
|
||||||
const content = this._getSettings(roomId, "org.matrix.room.preview_urls");
|
const content = this._getSettings(roomId, "org.matrix.room.preview_urls") || {};
|
||||||
content['disable'] = !newValue;
|
content['disable'] = !newValue;
|
||||||
return MatrixClientPeg.get().setRoomAccountData(roomId, "org.matrix.room.preview_urls", content);
|
return MatrixClientPeg.get().setRoomAccountData(roomId, "org.matrix.room.preview_urls", content);
|
||||||
}
|
}
|
||||||
|
@ -55,7 +57,7 @@ export default class RoomAccountSettingsHandler extends SettingsHandler {
|
||||||
return MatrixClientPeg.get().setRoomAccountData(roomId, "org.matrix.room.color_scheme", newValue);
|
return MatrixClientPeg.get().setRoomAccountData(roomId, "org.matrix.room.color_scheme", newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = this._getSettings(roomId);
|
const content = this._getSettings(roomId) || {};
|
||||||
content[settingName] = newValue;
|
content[settingName] = newValue;
|
||||||
return MatrixClientPeg.get().setRoomAccountData(roomId, "im.vector.web.settings", content);
|
return MatrixClientPeg.get().setRoomAccountData(roomId, "im.vector.web.settings", content);
|
||||||
}
|
}
|
||||||
|
@ -74,10 +76,10 @@ export default class RoomAccountSettingsHandler extends SettingsHandler {
|
||||||
|
|
||||||
_getSettings(roomId, eventType = "im.vector.settings") {
|
_getSettings(roomId, eventType = "im.vector.settings") {
|
||||||
const room = MatrixClientPeg.get().getRoom(roomId);
|
const room = MatrixClientPeg.get().getRoom(roomId);
|
||||||
if (!room) return {};
|
if (!room) return null;
|
||||||
|
|
||||||
const event = room.getAccountData(eventType);
|
const event = room.getAccountData(eventType);
|
||||||
if (!event || !event.getContent()) return {};
|
if (!event || !event.getContent()) return null;
|
||||||
return event.getContent();
|
return event.getContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,25 +24,26 @@ export default class RoomSettingsHandler extends SettingsHandler {
|
||||||
getValue(settingName, roomId) {
|
getValue(settingName, roomId) {
|
||||||
// Special case URL previews
|
// Special case URL previews
|
||||||
if (settingName === "urlPreviewsEnabled") {
|
if (settingName === "urlPreviewsEnabled") {
|
||||||
const content = this._getSettings(roomId, "org.matrix.room.preview_urls");
|
const content = this._getSettings(roomId, "org.matrix.room.preview_urls") || {};
|
||||||
|
|
||||||
// Check to make sure that we actually got a boolean
|
// Check to make sure that we actually got a boolean
|
||||||
if (typeof(content['disable']) !== "boolean") return null;
|
if (typeof(content['disable']) !== "boolean") return null;
|
||||||
return !content['disable'];
|
return !content['disable'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._getSettings(roomId)[settingName];
|
const settings = this._getSettings(roomId) || {};
|
||||||
|
return settings[settingName];
|
||||||
}
|
}
|
||||||
|
|
||||||
setValue(settingName, roomId, newValue) {
|
setValue(settingName, roomId, newValue) {
|
||||||
// Special case URL previews
|
// Special case URL previews
|
||||||
if (settingName === "urlPreviewsEnabled") {
|
if (settingName === "urlPreviewsEnabled") {
|
||||||
const content = this._getSettings(roomId, "org.matrix.room.preview_urls");
|
const content = this._getSettings(roomId, "org.matrix.room.preview_urls") || {};
|
||||||
content['disable'] = !newValue;
|
content['disable'] = !newValue;
|
||||||
return MatrixClientPeg.get().sendStateEvent(roomId, "org.matrix.room.preview_urls", content);
|
return MatrixClientPeg.get().sendStateEvent(roomId, "org.matrix.room.preview_urls", content);
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = this._getSettings(roomId);
|
const content = this._getSettings(roomId) || {};
|
||||||
content[settingName] = newValue;
|
content[settingName] = newValue;
|
||||||
return MatrixClientPeg.get().sendStateEvent(roomId, "im.vector.web.settings", content, "");
|
return MatrixClientPeg.get().sendStateEvent(roomId, "im.vector.web.settings", content, "");
|
||||||
}
|
}
|
||||||
|
@ -65,9 +66,10 @@ export default class RoomSettingsHandler extends SettingsHandler {
|
||||||
|
|
||||||
_getSettings(roomId, eventType = "im.vector.web.settings") {
|
_getSettings(roomId, eventType = "im.vector.web.settings") {
|
||||||
const room = MatrixClientPeg.get().getRoom(roomId);
|
const room = MatrixClientPeg.get().getRoom(roomId);
|
||||||
if (!room) return {};
|
if (!room) return null;
|
||||||
|
|
||||||
const event = room.currentState.getStateEvents(eventType, "");
|
const event = room.currentState.getStateEvents(eventType, "");
|
||||||
if (!event || !event.getContent()) return {};
|
if (!event || !event.getContent()) return null;
|
||||||
return event.getContent();
|
return event.getContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue