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) => {
|
||||
const client = MatrixClientPeg.get();
|
||||
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
|
||||
plContent = Object.assign({}, plContent);
|
||||
|
@ -151,7 +152,8 @@ export default class RolesRoomSettingsTab extends React.Component {
|
|||
|
||||
const client = MatrixClientPeg.get();
|
||||
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 powerLevelDescriptors = {
|
||||
|
|
|
@ -43,13 +43,31 @@ export default class SecurityRoomSettingsTab extends React.Component {
|
|||
|
||||
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
||||
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 history = state.getStateEvents("m.room.history_visibility", "").getContent()['history_visibility'];
|
||||
|
||||
const joinRule = this._pullContentPropertyFromEvent(
|
||||
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);
|
||||
this.setState({joinRule, guestAccess, history, encrypted});
|
||||
}
|
||||
|
||||
_pullContentPropertyFromEvent(event, key, defaultValue) {
|
||||
if (!event || !event.getContent()) return defaultValue;
|
||||
return event.getContent()[key] || defaultValue;
|
||||
}
|
||||
|
||||
componentWillUnmount(): void {
|
||||
MatrixClientPeg.get().removeListener("RoomState.events", this._onStateEvent);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue