Add room directory publish button

This was previously missed in the tab's layout.
This commit is contained in:
Travis Ralston 2019-01-31 22:06:15 -07:00
parent 0c0db4ecc7
commit b4fd0c3fbf

View file

@ -23,6 +23,7 @@ import sdk from "../../../../index";
import AccessibleButton from "../../elements/AccessibleButton"; import AccessibleButton from "../../elements/AccessibleButton";
import {MatrixClient} from "matrix-js-sdk"; import {MatrixClient} from "matrix-js-sdk";
import dis from "../../../../dispatcher"; import dis from "../../../../dispatcher";
import LabelledToggleSwitch from "../../elements/LabelledToggleSwitch";
export default class GeneralRoomSettingsTab extends React.Component { export default class GeneralRoomSettingsTab extends React.Component {
static childContextTypes = { static childContextTypes = {
@ -33,12 +34,40 @@ export default class GeneralRoomSettingsTab extends React.Component {
roomId: PropTypes.string.isRequired, roomId: PropTypes.string.isRequired,
}; };
constructor() {
super();
this.state = {
isRoomPublished: false, // loaded async
};
}
getChildContext() { getChildContext() {
return { return {
matrixClient: MatrixClientPeg.get(), matrixClient: MatrixClientPeg.get(),
}; };
} }
componentWillMount() {
MatrixClientPeg.get().getRoomDirectoryVisibility(this.props.roomId).then((result => {
this.setState({isRoomPublished: result.visibility === 'public'});
}));
}
onRoomPublishChange = (e) => {
const valueBefore = this.state.isRoomPublished;
const newValue = !valueBefore;
this.setState({isRoomPublished: newValue});
MatrixClientPeg.get().setRoomDirectoryVisibility(
this.props.roomId,
newValue ? 'public' : 'private',
).catch(() => {
// Roll back the local echo on the change
this.setState({isRoomPublished: valueBefore});
});
};
_saveAliases = (e) => { _saveAliases = (e) => {
// TODO: Live modification? // TODO: Live modification?
if (!this.refs.aliasSettings) return; if (!this.refs.aliasSettings) return;
@ -67,6 +96,7 @@ export default class GeneralRoomSettingsTab extends React.Component {
const room = client.getRoom(this.props.roomId); const room = client.getRoom(this.props.roomId);
const canSetAliases = true; // Previously, we arbitrarily only allowed admins to do this const canSetAliases = true; // Previously, we arbitrarily only allowed admins to do this
const canActuallySetAliases = room.currentState.mayClientSendStateEvent("m.room.aliases", client);
const canSetCanonical = room.currentState.mayClientSendStateEvent("m.room.canonical_alias", client); const canSetCanonical = room.currentState.mayClientSendStateEvent("m.room.canonical_alias", client);
const canonicalAliasEv = room.currentState.getStateEvents("m.room.canonical_alias", ''); const canonicalAliasEv = room.currentState.getStateEvents("m.room.canonical_alias", '');
const aliasEvents = room.currentState.getStateEvents("m.room.aliases"); const aliasEvents = room.currentState.getStateEvents("m.room.aliases");
@ -90,6 +120,14 @@ export default class GeneralRoomSettingsTab extends React.Component {
{_t("Save")} {_t("Save")}
</AccessibleButton> </AccessibleButton>
</div> </div>
<div className='mx_SettingsTab_section'>
<LabelledToggleSwitch value={this.state.isRoomPublished}
onChange={this.onRoomPublishChange}
disabled={!canActuallySetAliases}
label={_t("Publish this room to the public in %(domain)s's room directory?", {
domain: client.getDomain(),
})} />
</div>
<span className='mx_SettingsTab_subheading'>{_t("Flair")}</span> <span className='mx_SettingsTab_subheading'>{_t("Flair")}</span>
<div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'> <div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'>