mirror of https://github.com/vector-im/riot-web
Merge pull request #2593 from matrix-org/travis/settings/local-echo
Local echo on room access settingspull/21833/head
commit
47b79c0cf6
|
@ -27,8 +27,27 @@ export default class SecurityRoomSettingsTab extends React.Component {
|
||||||
roomId: PropTypes.string.isRequired,
|
roomId: PropTypes.string.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
joinRule: "invite",
|
||||||
|
guestAccess: "can_join",
|
||||||
|
history: "shared",
|
||||||
|
encrypted: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
componentWillMount(): void {
|
componentWillMount(): void {
|
||||||
MatrixClientPeg.get().on("RoomState.events", this._onStateEvent);
|
MatrixClientPeg.get().on("RoomState.events", this._onStateEvent);
|
||||||
|
|
||||||
|
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 encrypted = MatrixClientPeg.get().isRoomEncrypted(this.props.roomId);
|
||||||
|
this.setState({joinRule, guestAccess, history, encrypted});
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount(): void {
|
componentWillUnmount(): void {
|
||||||
|
@ -46,19 +65,37 @@ export default class SecurityRoomSettingsTab extends React.Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
_onEncryptionChange = (e) => {
|
_onEncryptionChange = (e) => {
|
||||||
|
const beforeEncrypted = this.state.encrypted;
|
||||||
|
this.setState({encrypted: true});
|
||||||
MatrixClientPeg.get().sendStateEvent(
|
MatrixClientPeg.get().sendStateEvent(
|
||||||
this.props.roomId, "m.room.encryption",
|
this.props.roomId, "m.room.encryption",
|
||||||
{ algorithm: "m.megolm.v1.aes-sha2" },
|
{ algorithm: "m.megolm.v1.aes-sha2" },
|
||||||
);
|
).catch((e) => {
|
||||||
|
console.error(e);
|
||||||
|
this.setState({encrypted: beforeEncrypted});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
_fixGuestAccess = (e) => {
|
_fixGuestAccess = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
|
const joinRule = "invite";
|
||||||
|
const guestAccess = "can_join";
|
||||||
|
|
||||||
|
const beforeJoinRule = this.state.joinRule;
|
||||||
|
const beforeGuestAccess = this.state.guestAccess;
|
||||||
|
this.setState({joinRule, guestAccess});
|
||||||
|
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
client.sendStateEvent(this.props.roomId, "m.room.join_rules", {join_rule: "invite"}, "");
|
client.sendStateEvent(this.props.roomId, "m.room.join_rules", {join_rule: joinRule}, "").catch((e) => {
|
||||||
client.sendStateEvent(this.props.roomId, "m.room.guest_access", {guest_access: "can_join"}, "");
|
console.error(e);
|
||||||
|
this.setState({joinRule: beforeJoinRule});
|
||||||
|
});
|
||||||
|
client.sendStateEvent(this.props.roomId, "m.room.guest_access", {guest_access: guestAccess}, "").catch((e) => {
|
||||||
|
console.error(e);
|
||||||
|
this.setState({guestAccess: beforeGuestAccess});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
_onRoomAccessRadioToggle = (ev) => {
|
_onRoomAccessRadioToggle = (ev) => {
|
||||||
|
@ -92,24 +129,39 @@ export default class SecurityRoomSettingsTab extends React.Component {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const beforeJoinRule = this.state.joinRule;
|
||||||
|
const beforeGuestAccess = this.state.guestAccess;
|
||||||
|
this.setState({joinRule, guestAccess});
|
||||||
|
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
client.sendStateEvent(this.props.roomId, "m.room.join_rules", {join_rule: joinRule}, "");
|
client.sendStateEvent(this.props.roomId, "m.room.join_rules", {join_rule: joinRule}, "").catch((e) => {
|
||||||
client.sendStateEvent(this.props.roomId, "m.room.guest_access", {guest_access: guestAccess}, "");
|
console.error(e);
|
||||||
|
this.setState({joinRule: beforeJoinRule});
|
||||||
|
});
|
||||||
|
client.sendStateEvent(this.props.roomId, "m.room.guest_access", {guest_access: guestAccess}, "").catch((e) => {
|
||||||
|
console.error(e);
|
||||||
|
this.setState({guestAccess: beforeGuestAccess});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
_onHistoryRadioToggle = (ev) => {
|
_onHistoryRadioToggle = (ev) => {
|
||||||
|
const beforeHistory = this.state.history;
|
||||||
|
this.setState({history: ev.target.value});
|
||||||
MatrixClientPeg.get().sendStateEvent(this.props.roomId, "m.room.history_visibility", {
|
MatrixClientPeg.get().sendStateEvent(this.props.roomId, "m.room.history_visibility", {
|
||||||
history_visibility: ev.target.value,
|
history_visibility: ev.target.value,
|
||||||
}, "");
|
}, "").catch((e) => {
|
||||||
|
console.error(e);
|
||||||
|
this.setState({history: beforeHistory});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
_renderRoomAccess() {
|
_renderRoomAccess() {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
const room = client.getRoom(this.props.roomId);
|
const room = client.getRoom(this.props.roomId);
|
||||||
const joinRule = room.currentState.getStateEvents("m.room.join_rules", "").getContent()['join_rule'];
|
const joinRule = this.state.joinRule;
|
||||||
const guestAccess = room.currentState.getStateEvents("m.room.guest_access", "").getContent()['guest_access'];
|
const guestAccess = this.state.guestAccess;
|
||||||
const aliasEvents = room.currentState.getStateEvents("m.room.aliases") || [];
|
const aliasEvents = room.currentState.getStateEvents("m.room.aliases") || [];
|
||||||
const hasAliases = aliasEvents.includes((ev) => (ev.getContent().aliases || []).length);
|
const hasAliases = !!aliasEvents.find((ev) => (ev.getContent().aliases || []).length > 0);
|
||||||
|
|
||||||
const canChangeAccess = room.currentState.mayClientSendStateEvent("m.room.join_rules", client)
|
const canChangeAccess = room.currentState.mayClientSendStateEvent("m.room.join_rules", client)
|
||||||
&& room.currentState.mayClientSendStateEvent("m.room.guest_access", client);
|
&& room.currentState.mayClientSendStateEvent("m.room.guest_access", client);
|
||||||
|
@ -170,9 +222,8 @@ export default class SecurityRoomSettingsTab extends React.Component {
|
||||||
|
|
||||||
_renderHistory() {
|
_renderHistory() {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
const room = client.getRoom(this.props.roomId);
|
const history = this.state.history;
|
||||||
const state = room.currentState;
|
const state = client.getRoom(this.props.roomId).currentState;
|
||||||
const history = state.getStateEvents("m.room.history_visibility", "").getContent()['history_visibility'];
|
|
||||||
const canChangeHistory = state.mayClientSendStateEvent('m.room.history_visibility', client);
|
const canChangeHistory = state.mayClientSendStateEvent('m.room.history_visibility', client);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -218,7 +269,7 @@ export default class SecurityRoomSettingsTab 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 isEncrypted = client.isRoomEncrypted(this.props.roomId);
|
const isEncrypted = this.state.encrypted;
|
||||||
const hasEncryptionPermission = room.currentState.mayClientSendStateEvent("m.room.encryption", client);
|
const hasEncryptionPermission = room.currentState.mayClientSendStateEvent("m.room.encryption", client);
|
||||||
const canEnableEncryption = !isEncrypted && hasEncryptionPermission;
|
const canEnableEncryption = !isEncrypted && hasEncryptionPermission;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue