2019-01-26 06:38:35 +03:00
|
|
|
/*
|
|
|
|
Copyright 2019 New Vector Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import {_t} from "../../../../languageHandler";
|
2019-01-28 21:36:09 +03:00
|
|
|
import RoomProfileSettings from "../../room_settings/RoomProfileSettings";
|
2019-01-26 06:53:38 +03:00
|
|
|
import MatrixClientPeg from "../../../../MatrixClientPeg";
|
|
|
|
import sdk from "../../../../index";
|
|
|
|
import AccessibleButton from "../../elements/AccessibleButton";
|
2019-01-28 22:49:31 +03:00
|
|
|
import {MatrixClient} from "matrix-js-sdk";
|
2019-01-26 06:38:35 +03:00
|
|
|
|
|
|
|
export default class GeneralRoomSettingsTab extends React.Component {
|
2019-01-28 22:49:31 +03:00
|
|
|
static childContextTypes = {
|
|
|
|
matrixClient: PropTypes.instanceOf(MatrixClient),
|
|
|
|
};
|
|
|
|
|
2019-01-26 06:38:35 +03:00
|
|
|
static propTypes = {
|
|
|
|
roomId: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
2019-01-28 22:49:31 +03:00
|
|
|
getChildContext() {
|
|
|
|
return {
|
|
|
|
matrixClient: MatrixClientPeg.get(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-26 06:53:38 +03:00
|
|
|
_saveAliases = (e) => {
|
|
|
|
// TODO: Live modification of aliases?
|
|
|
|
if (!this.refs.aliasSettings) return;
|
|
|
|
this.refs.aliasSettings.saveSettings();
|
|
|
|
};
|
|
|
|
|
2019-01-28 22:49:31 +03:00
|
|
|
_saveGroups = (e) => {
|
|
|
|
// TODO: Live modification of aliases?
|
|
|
|
if (!this.refs.flairSettings) return;
|
|
|
|
this.refs.flairSettings.saveSettings();
|
|
|
|
};
|
|
|
|
|
2019-01-26 06:38:35 +03:00
|
|
|
render() {
|
2019-01-26 06:53:38 +03:00
|
|
|
const AliasSettings = sdk.getComponent("room_settings.AliasSettings");
|
2019-01-28 22:49:31 +03:00
|
|
|
const RelatedGroupSettings = sdk.getComponent("room_settings.RelatedGroupSettings");
|
2019-01-26 06:53:38 +03:00
|
|
|
|
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
const room = client.getRoom(this.props.roomId);
|
|
|
|
|
|
|
|
const canSetAliases = true; // Previously, we arbitrarily only allowed admins to do this
|
|
|
|
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");
|
|
|
|
|
2019-01-28 22:49:31 +03:00
|
|
|
const canChangeGroups = room.currentState.mayClientSendStateEvent("m.room.related_groups", client);
|
|
|
|
const groupsEvent = room.currentState.getStateEvents("m.room.related_groups", "");
|
|
|
|
|
2019-01-26 06:38:35 +03:00
|
|
|
return (
|
|
|
|
<div className="mx_SettingsTab mx_GeneralRoomSettingsTab">
|
|
|
|
<div className="mx_SettingsTab_heading">{_t("General")}</div>
|
|
|
|
<div className='mx_SettingsTab_section mx_GeneralRoomSettingsTab_profileSection'>
|
|
|
|
<RoomProfileSettings roomId={this.props.roomId} />
|
|
|
|
</div>
|
2019-01-26 06:53:38 +03:00
|
|
|
|
|
|
|
<span className='mx_SettingsTab_subheading'>{_t("Room Addresses")}</span>
|
|
|
|
<div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'>
|
|
|
|
<AliasSettings ref="aliasSettings" roomId={this.props.roomId}
|
|
|
|
canSetCanonicalAlias={canSetCanonical} canSetAliases={canSetAliases}
|
|
|
|
canonicalAliasEvent={canonicalAliasEv} aliasEvents={aliasEvents} />
|
|
|
|
<AccessibleButton onClick={this._saveAliases} kind='primary'>
|
|
|
|
{_t("Save")}
|
|
|
|
</AccessibleButton>
|
|
|
|
</div>
|
2019-01-28 22:49:31 +03:00
|
|
|
|
|
|
|
<span className='mx_SettingsTab_subheading'>{_t("Flair")}</span>
|
|
|
|
<div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'>
|
|
|
|
<RelatedGroupSettings ref="flairSettings" roomId={room.roomId}
|
|
|
|
canSetRelatedGroups={canChangeGroups}
|
|
|
|
relatedGroupsEvent={groupsEvent} />
|
|
|
|
<AccessibleButton onClick={this._saveGroups} kind='primary'>
|
|
|
|
{_t("Save")}
|
|
|
|
</AccessibleButton>
|
|
|
|
</div>
|
2019-01-26 06:38:35 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|