2019-01-30 04:23:01 +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';
|
2019-02-22 20:47:18 +03:00
|
|
|
import {_t} from "../../../../../languageHandler";
|
2019-12-21 00:13:46 +03:00
|
|
|
import {MatrixClientPeg} from "../../../../../MatrixClientPeg";
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from "../../../../..";
|
2019-02-22 20:47:18 +03:00
|
|
|
import AccessibleButton from "../../../elements/AccessibleButton";
|
|
|
|
import Modal from "../../../../../Modal";
|
2019-04-11 00:00:02 +03:00
|
|
|
import dis from "../../../../../dispatcher";
|
2019-01-30 04:23:01 +03:00
|
|
|
|
|
|
|
export default class AdvancedRoomSettingsTab extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
roomId: PropTypes.string.isRequired,
|
2019-04-11 00:00:02 +03:00
|
|
|
closeSettingsFn: PropTypes.func.isRequired,
|
2019-01-30 04:23:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
// This is eventually set to the value of room.getRecommendedVersion()
|
|
|
|
upgradeRecommendation: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-30 07:46:51 +03:00
|
|
|
componentWillMount() {
|
2019-01-30 04:23:01 +03:00
|
|
|
// we handle lack of this object gracefully later, so don't worry about it failing here.
|
2019-04-09 00:39:36 +03:00
|
|
|
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
|
|
|
room.getRecommendedVersion().then((v) => {
|
|
|
|
const tombstone = room.currentState.getStateEvents("m.room.tombstone", "");
|
2019-04-11 00:00:02 +03:00
|
|
|
|
2019-04-11 00:34:06 +03:00
|
|
|
const additionalStateChanges = {};
|
2019-04-11 00:00:02 +03:00
|
|
|
const createEvent = room.currentState.getStateEvents("m.room.create", "");
|
2019-04-11 00:34:06 +03:00
|
|
|
const predecessor = createEvent ? createEvent.getContent().predecessor : null;
|
2019-04-11 00:00:02 +03:00
|
|
|
if (predecessor && predecessor.room_id) {
|
|
|
|
additionalStateChanges['oldRoomId'] = predecessor.room_id;
|
|
|
|
additionalStateChanges['oldEventId'] = predecessor.event_id;
|
|
|
|
additionalStateChanges['hasPreviousRoom'] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-09 00:39:36 +03:00
|
|
|
this.setState({
|
|
|
|
upgraded: tombstone && tombstone.getContent().replacement_room,
|
|
|
|
upgradeRecommendation: v,
|
2019-04-11 00:00:02 +03:00
|
|
|
...additionalStateChanges,
|
2019-04-09 00:39:36 +03:00
|
|
|
});
|
2019-01-30 04:23:01 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_upgradeRoom = (e) => {
|
|
|
|
const RoomUpgradeDialog = sdk.getComponent('dialogs.RoomUpgradeDialog');
|
|
|
|
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
|
|
|
Modal.createTrackedDialog('Upgrade Room Version', '', RoomUpgradeDialog, {room: room});
|
|
|
|
};
|
|
|
|
|
|
|
|
_openDevtools = (e) => {
|
|
|
|
const DevtoolsDialog = sdk.getComponent('dialogs.DevtoolsDialog');
|
|
|
|
Modal.createDialog(DevtoolsDialog, {roomId: this.props.roomId});
|
|
|
|
};
|
|
|
|
|
2019-04-11 00:00:02 +03:00
|
|
|
_onOldRoomClicked = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
|
|
|
room_id: this.state.oldRoomId,
|
|
|
|
event_id: this.state.oldEventId,
|
|
|
|
});
|
|
|
|
this.props.closeSettingsFn();
|
|
|
|
};
|
|
|
|
|
2019-01-30 04:23:01 +03:00
|
|
|
render() {
|
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
const room = client.getRoom(this.props.roomId);
|
|
|
|
|
|
|
|
let unfederatableSection;
|
|
|
|
const createEvent = room.currentState.getStateEvents('m.room.create', '');
|
|
|
|
if (createEvent && createEvent.getContent()['m.federate'] === false) {
|
|
|
|
unfederatableSection = <div>{_t('This room is not accessible by remote Matrix servers')}</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
let roomUpgradeButton;
|
2019-04-09 00:39:36 +03:00
|
|
|
if (this.state.upgradeRecommendation && this.state.upgradeRecommendation.needsUpgrade && !this.state.upgraded) {
|
2019-01-30 04:23:01 +03:00
|
|
|
roomUpgradeButton = (
|
2019-03-15 02:11:44 +03:00
|
|
|
<div>
|
|
|
|
<p className='mx_SettingsTab_warningText'>
|
|
|
|
{_t(
|
2019-03-16 00:49:18 +03:00
|
|
|
"<b>Warning</b>: Upgrading a room will <i>not automatically migrate room members " +
|
2019-03-16 01:44:27 +03:00
|
|
|
"to the new version of the room.</i> We'll post a link to the new room in the old " +
|
|
|
|
"version of the room - room members will have to click this link to join the new room.",
|
2019-03-16 00:49:18 +03:00
|
|
|
{}, {
|
|
|
|
"b": (sub) => <b>{sub}</b>,
|
|
|
|
"i": (sub) => <i>{sub}</i>,
|
|
|
|
},
|
2019-03-15 02:11:44 +03:00
|
|
|
)}
|
|
|
|
</p>
|
|
|
|
<AccessibleButton onClick={this._upgradeRoom} kind='primary'>
|
2019-03-16 00:49:18 +03:00
|
|
|
{_t("Upgrade this room to the recommended room version")}
|
2019-03-15 02:11:44 +03:00
|
|
|
</AccessibleButton>
|
|
|
|
</div>
|
2019-01-30 04:23:01 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-11 00:00:02 +03:00
|
|
|
let oldRoomLink;
|
|
|
|
if (this.state.hasPreviousRoom) {
|
2019-04-11 19:40:25 +03:00
|
|
|
let name = _t("this room");
|
|
|
|
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
|
|
|
if (room && room.name) name = room.name;
|
2019-04-11 00:00:02 +03:00
|
|
|
oldRoomLink = (
|
2019-04-11 19:40:25 +03:00
|
|
|
<AccessibleButton element='a' onClick={this._onOldRoomClicked}>
|
|
|
|
{_t("View older messages in %(roomName)s.", {roomName: name})}
|
|
|
|
</AccessibleButton>
|
2019-04-11 00:00:02 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-30 04:23:01 +03:00
|
|
|
return (
|
|
|
|
<div className="mx_SettingsTab">
|
|
|
|
<div className="mx_SettingsTab_heading">{_t("Advanced")}</div>
|
|
|
|
<div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'>
|
|
|
|
<span className='mx_SettingsTab_subheading'>{_t("Room information")}</span>
|
|
|
|
<div>
|
|
|
|
<span>{_t("Internal room ID:")}</span>
|
|
|
|
{this.props.roomId}
|
|
|
|
</div>
|
|
|
|
{unfederatableSection}
|
|
|
|
</div>
|
|
|
|
<div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'>
|
|
|
|
<span className='mx_SettingsTab_subheading'>{_t("Room version")}</span>
|
|
|
|
<div>
|
|
|
|
<span>{_t("Room version:")}</span>
|
|
|
|
{room.getVersion()}
|
|
|
|
</div>
|
2019-04-11 00:00:02 +03:00
|
|
|
{oldRoomLink}
|
2019-01-30 04:23:01 +03:00
|
|
|
{roomUpgradeButton}
|
|
|
|
</div>
|
|
|
|
<div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'>
|
|
|
|
<span className='mx_SettingsTab_subheading'>{_t("Developer options")}</span>
|
|
|
|
<AccessibleButton onClick={this._openDevtools} kind='primary'>
|
|
|
|
{_t("Open Devtools")}
|
|
|
|
</AccessibleButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|