/* 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"; import {MatrixClientPeg} from "../../../../../MatrixClientPeg"; import * as sdk from "../../../../.."; import AccessibleButton from "../../../elements/AccessibleButton"; import Modal from "../../../../../Modal"; import dis from "../../../../../dispatcher"; export default class AdvancedRoomSettingsTab extends React.Component { static propTypes = { roomId: PropTypes.string.isRequired, closeSettingsFn: PropTypes.func.isRequired, }; constructor() { super(); this.state = { // This is eventually set to the value of room.getRecommendedVersion() upgradeRecommendation: null, }; } componentWillMount() { // we handle lack of this object gracefully later, so don't worry about it failing here. const room = MatrixClientPeg.get().getRoom(this.props.roomId); room.getRecommendedVersion().then((v) => { const tombstone = room.currentState.getStateEvents("m.room.tombstone", ""); const additionalStateChanges = {}; const createEvent = room.currentState.getStateEvents("m.room.create", ""); const predecessor = createEvent ? createEvent.getContent().predecessor : null; if (predecessor && predecessor.room_id) { additionalStateChanges['oldRoomId'] = predecessor.room_id; additionalStateChanges['oldEventId'] = predecessor.event_id; additionalStateChanges['hasPreviousRoom'] = true; } this.setState({ upgraded: tombstone && tombstone.getContent().replacement_room, upgradeRecommendation: v, ...additionalStateChanges, }); }); } _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}); }; _onOldRoomClicked = (e) => { e.preventDefault(); e.stopPropagation(); dis.dispatch({ action: 'view_room', room_id: this.state.oldRoomId, event_id: this.state.oldEventId, }); this.props.closeSettingsFn(); }; 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 =
{_t('This room is not accessible by remote Matrix servers')}
; } let roomUpgradeButton; if (this.state.upgradeRecommendation && this.state.upgradeRecommendation.needsUpgrade && !this.state.upgraded) { roomUpgradeButton = (

{_t( "Warning: Upgrading a room will not automatically migrate room members " + "to the new version of the room. 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.", {}, { "b": (sub) => {sub}, "i": (sub) => {sub}, }, )}

{_t("Upgrade this room to the recommended room version")}
); } let oldRoomLink; if (this.state.hasPreviousRoom) { let name = _t("this room"); const room = MatrixClientPeg.get().getRoom(this.props.roomId); if (room && room.name) name = room.name; oldRoomLink = ( {_t("View older messages in %(roomName)s.", {roomName: name})} ); } return (
{_t("Advanced")}
{_t("Room information")}
{_t("Internal room ID:")}  {this.props.roomId}
{unfederatableSection}
{_t("Room version")}
{_t("Room version:")}  {room.getVersion()}
{oldRoomLink} {roomUpgradeButton}
{_t("Developer options")} {_t("Open Devtools")}
); } }