Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2553 from matrix-org/travis/settings/fixes-3
Browse files Browse the repository at this point in the history
Misc fixes to settings
  • Loading branch information
turt2live authored Feb 1, 2019
2 parents 22178f2 + b4fd0c3 commit dca194f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 22 deletions.
38 changes: 38 additions & 0 deletions src/components/views/settings/tabs/GeneralRoomSettingsTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import sdk from "../../../../index";
import AccessibleButton from "../../elements/AccessibleButton";
import {MatrixClient} from "matrix-js-sdk";
import dis from "../../../../dispatcher";
import LabelledToggleSwitch from "../../elements/LabelledToggleSwitch";

export default class GeneralRoomSettingsTab extends React.Component {
static childContextTypes = {
Expand All @@ -33,12 +34,40 @@ export default class GeneralRoomSettingsTab extends React.Component {
roomId: PropTypes.string.isRequired,
};

constructor() {
super();

this.state = {
isRoomPublished: false, // loaded async
};
}

getChildContext() {
return {
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) => {
// TODO: Live modification?
if (!this.refs.aliasSettings) return;
Expand Down Expand Up @@ -67,6 +96,7 @@ export default class GeneralRoomSettingsTab extends React.Component {
const room = client.getRoom(this.props.roomId);

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 canonicalAliasEv = room.currentState.getStateEvents("m.room.canonical_alias", '');
const aliasEvents = room.currentState.getStateEvents("m.room.aliases");
Expand All @@ -90,6 +120,14 @@ export default class GeneralRoomSettingsTab extends React.Component {
{_t("Save")}
</AccessibleButton>
</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>
<div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'>
Expand Down
21 changes: 0 additions & 21 deletions src/components/views/settings/tabs/GeneralUserSettingsTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ limitations under the License.

import React from 'react';
import {_t} from "../../../../languageHandler";
import MatrixClientPeg from "../../../../MatrixClientPeg";
import GroupUserSettings from "../../groups/GroupUserSettings";
import PropTypes from "prop-types";
import {MatrixClient} from "matrix-js-sdk";
import { DragDropContext } from 'react-beautiful-dnd';
import ProfileSettings from "../ProfileSettings";
import EmailAddresses from "../EmailAddresses";
import PhoneNumbers from "../PhoneNumbers";
Expand All @@ -37,10 +32,6 @@ const Modal = require("../../../../Modal");
const dis = require("../../../../dispatcher");

export default class GeneralUserSettingsTab extends React.Component {
static childContextTypes = {
matrixClient: PropTypes.instanceOf(MatrixClient),
};

constructor() {
super();

Expand All @@ -50,12 +41,6 @@ export default class GeneralUserSettingsTab extends React.Component {
};
}

getChildContext() {
return {
matrixClient: MatrixClientPeg.get(),
};
}

_onLanguageChange = (newLanguage) => {
if (this.state.language === newLanguage) return;

Expand Down Expand Up @@ -105,16 +90,10 @@ export default class GeneralUserSettingsTab extends React.Component {
};

_renderProfileSection() {
// HACK/TODO: Using DragDropContext feels wrong, but we need it.
return (
<div className="mx_SettingsTab_section">
<span className="mx_SettingsTab_subheading">{_t("Profile")}</span>
<ProfileSettings />

<span className="mx_SettingsTab_subheading">{_t("Flair")}</span>
<DragDropContext>
<GroupUserSettings />
</DragDropContext>
</div>
);
}
Expand Down
8 changes: 7 additions & 1 deletion src/components/views/settings/tabs/VoiceSettingsTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ export default class VoiceSettingsTab extends React.Component {
this._refreshMediaDevices();
}

_refreshMediaDevices = async () => {
_refreshMediaDevices = async (stream) => {
if (stream) {
// kill stream so that we don't leave it lingering around with webcam enabled etc
// as here we called gUM to ask user for permission to their device names only
stream.getTracks().forEach((track) => track.stop());
}

this.setState({
mediaDevices: await CallMediaHandler.getDevices(),
activeAudioOutput: CallMediaHandler.getAudioOutput(),
Expand Down

0 comments on commit dca194f

Please sign in to comment.