don't pass back {} when we have no `org.matrix.room.color_scheme`

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
pull/21833/head
Michael Telatynski 2018-01-17 18:06:19 +00:00
parent 952f2c6a21
commit b90a98b5c1
1 changed files with 7 additions and 6 deletions

View File

@ -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;
@ -38,13 +38,14 @@ export default class RoomAccountSettingsHandler extends SettingsHandler {
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 +56,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 +75,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();
} }
} }