mirror of https://github.com/vector-im/riot-web
Merge pull request #2648 from matrix-org/travis/fix-room-settings
Add a bit of safety around reading events for room settingspull/21833/head
commit
424de00109
|
@ -116,7 +116,8 @@ export default class RolesRoomSettingsTab extends React.Component {
|
||||||
_onPowerLevelsChanged = (value, powerLevelKey) => {
|
_onPowerLevelsChanged = (value, powerLevelKey) => {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
const room = client.getRoom(this.props.roomId);
|
const room = client.getRoom(this.props.roomId);
|
||||||
let plContent = room.currentState.getStateEvents('m.room.power_levels', '').getContent() || {};
|
const plEvent = room.currentState.getStateEvents('m.room.power_levels', '');
|
||||||
|
let plContent = plEvent ? (plEvent.getContent() || {}) : {};
|
||||||
|
|
||||||
// Clone the power levels just in case
|
// Clone the power levels just in case
|
||||||
plContent = Object.assign({}, plContent);
|
plContent = Object.assign({}, plContent);
|
||||||
|
@ -151,7 +152,8 @@ export default class RolesRoomSettingsTab extends React.Component {
|
||||||
|
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
const room = client.getRoom(this.props.roomId);
|
const room = client.getRoom(this.props.roomId);
|
||||||
const plContent = room.currentState.getStateEvents('m.room.power_levels', '').getContent() || {};
|
const plEvent = room.currentState.getStateEvents('m.room.power_levels', '');
|
||||||
|
const plContent = plEvent ? (plEvent.getContent() || {}) : {};
|
||||||
const canChangeLevels = room.currentState.mayClientSendStateEvent('m.room.power_levels', client);
|
const canChangeLevels = room.currentState.mayClientSendStateEvent('m.room.power_levels', client);
|
||||||
|
|
||||||
const powerLevelDescriptors = {
|
const powerLevelDescriptors = {
|
||||||
|
|
|
@ -43,13 +43,31 @@ export default class SecurityRoomSettingsTab extends React.Component {
|
||||||
|
|
||||||
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
||||||
const state = room.currentState;
|
const state = room.currentState;
|
||||||
const joinRule = state.getStateEvents("m.room.join_rules", "").getContent()['join_rule'];
|
|
||||||
const guestAccess = state.getStateEvents("m.room.guest_access", "").getContent()['guest_access'];
|
const joinRule = this._pullContentPropertyFromEvent(
|
||||||
const history = state.getStateEvents("m.room.history_visibility", "").getContent()['history_visibility'];
|
state.getStateEvents("m.room.join_rules", ""),
|
||||||
|
'join_rule',
|
||||||
|
'invite',
|
||||||
|
);
|
||||||
|
const guestAccess = this._pullContentPropertyFromEvent(
|
||||||
|
state.getStateEvents("m.room.guest_access", ""),
|
||||||
|
'guest_access',
|
||||||
|
'forbidden',
|
||||||
|
);
|
||||||
|
const history = this._pullContentPropertyFromEvent(
|
||||||
|
state.getStateEvents("m.room.history_visibility", ""),
|
||||||
|
'history_visibility',
|
||||||
|
'shared',
|
||||||
|
);
|
||||||
const encrypted = MatrixClientPeg.get().isRoomEncrypted(this.props.roomId);
|
const encrypted = MatrixClientPeg.get().isRoomEncrypted(this.props.roomId);
|
||||||
this.setState({joinRule, guestAccess, history, encrypted});
|
this.setState({joinRule, guestAccess, history, encrypted});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_pullContentPropertyFromEvent(event, key, defaultValue) {
|
||||||
|
if (!event || !event.getContent()) return defaultValue;
|
||||||
|
return event.getContent()[key] || defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
componentWillUnmount(): void {
|
componentWillUnmount(): void {
|
||||||
MatrixClientPeg.get().removeListener("RoomState.events", this._onStateEvent);
|
MatrixClientPeg.get().removeListener("RoomState.events", this._onStateEvent);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue