/* Copyright 2018-2020 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 * as sdk from '../../../index'; import Modal from '../../../Modal'; import { _t } from '../../../languageHandler'; import {MatrixClientPeg} from "../../../MatrixClientPeg"; export default class RoomUpgradeWarningBar extends React.Component { static propTypes = { room: PropTypes.object.isRequired, recommendation: PropTypes.object.isRequired, }; constructor(props) { super(props); this.state = {}; } componentDidMount() { const tombstone = this.props.room.currentState.getStateEvents("m.room.tombstone", ""); this.setState({upgraded: tombstone && tombstone.getContent().replacement_room}); MatrixClientPeg.get().on("RoomState.events", this._onStateEvents); } componentWillUnmount() { const cli = MatrixClientPeg.get(); if (cli) { cli.removeListener("RoomState.events", this._onStateEvents); } } _onStateEvents = (event, state) => { if (!this.props.room || event.getRoomId() !== this.props.room.roomId) { return; } if (event.getType() !== "m.room.tombstone") return; const tombstone = this.props.room.currentState.getStateEvents("m.room.tombstone", ""); this.setState({upgraded: tombstone && tombstone.getContent().replacement_room}); }; onUpgradeClick = () => { const RoomUpgradeDialog = sdk.getComponent('dialogs.RoomUpgradeDialog'); Modal.createTrackedDialog('Upgrade Room Version', '', RoomUpgradeDialog, {room: this.props.room}); }; render() { const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); let doUpgradeWarnings = (

{_t( "Upgrading this room will shut down the current instance of the room and create " + "an upgraded room with the same name.", )}

{_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")}

); if (this.state.upgraded) { doUpgradeWarnings = (

{_t("This room has already been upgraded.")}

); } return (
{_t( "This room is running room version , which this homeserver has " + "marked as unstable.", {}, { "roomVersion": () => {this.props.room.getVersion()}, "i": (sub) => {sub}, }, )}
{doUpgradeWarnings}
{_t("Only room administrators will see this warning")}
); } }