Fix room upgrade warnings popping up in upgraded rooms

Rooms which are already upgraded shouldn't be asked to upgrade. Additionally, this fixes a bug where the room upgrade dialog would stay open even after upgrading the room.
pull/21833/head
Travis Ralston 2019-04-08 15:39:36 -06:00
parent 054011f5f8
commit 4beecb50c9
4 changed files with 62 additions and 20 deletions

View File

@ -47,7 +47,9 @@ export default React.createClass({
_onUpgradeClick: function() { _onUpgradeClick: function() {
this.setState({busy: true}); this.setState({busy: true});
MatrixClientPeg.get().upgradeRoom(this.props.room.roomId, this._targetVersion).catch((err) => { MatrixClientPeg.get().upgradeRoom(this.props.room.roomId, this._targetVersion).then(() => {
this.props.onFinished(true);
}).catch((err) => {
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
Modal.createTrackedDialog('Failed to upgrade room', '', ErrorDialog, { Modal.createTrackedDialog('Failed to upgrade room', '', ErrorDialog, {
title: _t("Failed to upgrade room"), title: _t("Failed to upgrade room"),
@ -82,10 +84,9 @@ export default React.createClass({
return ( return (
<BaseDialog className="mx_RoomUpgradeDialog" <BaseDialog className="mx_RoomUpgradeDialog"
onFinished={this.onCancelled} onFinished={this.props.onFinished}
title={_t("Upgrade Room Version")} title={_t("Upgrade Room Version")}
contentId='mx_Dialog_content' contentId='mx_Dialog_content'
onFinished={this.props.onFinished}
hasCancel={true} hasCancel={true}
> >
<p> <p>

View File

@ -20,6 +20,7 @@ import sdk from '../../../index';
import Modal from '../../../Modal'; import Modal from '../../../Modal';
import { _t } from '../../../languageHandler'; import { _t } from '../../../languageHandler';
import MatrixClientPeg from "../../../MatrixClientPeg";
module.exports = React.createClass({ module.exports = React.createClass({
displayName: 'RoomUpgradeWarningBar', displayName: 'RoomUpgradeWarningBar',
@ -29,6 +30,24 @@ module.exports = React.createClass({
recommendation: PropTypes.object.isRequired, recommendation: PropTypes.object.isRequired,
}, },
componentWillMount: function() {
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);
},
_onStateEvents: function(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: function() { onUpgradeClick: function() {
const RoomUpgradeDialog = sdk.getComponent('dialogs.RoomUpgradeDialog'); const RoomUpgradeDialog = sdk.getComponent('dialogs.RoomUpgradeDialog');
Modal.createTrackedDialog('Upgrade Room Version', '', RoomUpgradeDialog, {room: this.props.room}); Modal.createTrackedDialog('Upgrade Room Version', '', RoomUpgradeDialog, {room: this.props.room});
@ -37,19 +56,8 @@ module.exports = React.createClass({
render: function() { render: function() {
const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
return ( let doUpgradeWarnings = (
<div className="mx_RoomUpgradeWarningBar"> <div>
<div className="mx_RoomUpgradeWarningBar_header">
{_t(
"This room is running room version <roomVersion />, which this homeserver has " +
"marked as <i>unstable</i>.",
{},
{
"roomVersion": () => <code>{this.props.room.getVersion()}</code>,
"i": (sub) => <i>{sub}</i>,
},
)}
</div>
<div className="mx_RoomUpgradeWarningBar_body"> <div className="mx_RoomUpgradeWarningBar_body">
<p> <p>
{_t( {_t(
@ -74,6 +82,33 @@ module.exports = React.createClass({
{_t("Upgrade this room to the recommended room version")} {_t("Upgrade this room to the recommended room version")}
</AccessibleButton> </AccessibleButton>
</p> </p>
</div>
);
if (this.state.upgraded) {
doUpgradeWarnings = (
<div className="mx_RoomUpgradeWarningBar_body">
<p>
{_t("This room has already been upgraded.")}
</p>
</div>
);
}
return (
<div className="mx_RoomUpgradeWarningBar">
<div className="mx_RoomUpgradeWarningBar_header">
{_t(
"This room is running room version <roomVersion />, which this homeserver has " +
"marked as <i>unstable</i>.",
{},
{
"roomVersion": () => <code>{this.props.room.getVersion()}</code>,
"i": (sub) => <i>{sub}</i>,
},
)}
</div>
{doUpgradeWarnings}
<div className="mx_RoomUpgradeWarningBar_small"> <div className="mx_RoomUpgradeWarningBar_small">
{_t("Only room administrators will see this warning")} {_t("Only room administrators will see this warning")}
</div> </div>

View File

@ -38,8 +38,13 @@ export default class AdvancedRoomSettingsTab extends React.Component {
componentWillMount() { componentWillMount() {
// we handle lack of this object gracefully later, so don't worry about it failing here. // we handle lack of this object gracefully later, so don't worry about it failing here.
MatrixClientPeg.get().getRoom(this.props.roomId).getRecommendedVersion().then((v) => { const room = MatrixClientPeg.get().getRoom(this.props.roomId);
this.setState({upgradeRecommendation: v}); room.getRecommendedVersion().then((v) => {
const tombstone = room.currentState.getStateEvents("m.room.tombstone", "");
this.setState({
upgraded: tombstone && tombstone.getContent().replacement_room,
upgradeRecommendation: v,
});
}); });
} }
@ -65,7 +70,7 @@ export default class AdvancedRoomSettingsTab extends React.Component {
} }
let roomUpgradeButton; let roomUpgradeButton;
if (this.state.upgradeRecommendation && this.state.upgradeRecommendation.needsUpgrade) { if (this.state.upgradeRecommendation && this.state.upgradeRecommendation.needsUpgrade && !this.state.upgraded) {
roomUpgradeButton = ( roomUpgradeButton = (
<div> <div>
<p className='mx_SettingsTab_warningText'> <p className='mx_SettingsTab_warningText'>

View File

@ -812,8 +812,9 @@
"Not now": "Not now", "Not now": "Not now",
"Don't ask me again": "Don't ask me again", "Don't ask me again": "Don't ask me again",
"Add a topic": "Add a topic", "Add a topic": "Add a topic",
"This room is running room version <roomVersion />, which this homeserver has marked as <i>unstable</i>.": "This room is running room version <roomVersion />, which this homeserver has marked as <i>unstable</i>.",
"Upgrading this room will shut down the current instance of the room and create an upgraded room with the same name.": "Upgrading this room will shut down the current instance of the room and create an upgraded room with the same name.", "Upgrading this room will shut down the current instance of the room and create an upgraded room with the same name.": "Upgrading this room will shut down the current instance of the room and create an upgraded room with the same name.",
"This room has already been upgraded.": "This room has already been upgraded.",
"This room is running room version <roomVersion />, which this homeserver has marked as <i>unstable</i>.": "This room is running room version <roomVersion />, which this homeserver has marked as <i>unstable</i>.",
"Only room administrators will see this warning": "Only room administrators will see this warning", "Only room administrators will see this warning": "Only room administrators will see this warning",
"This Room": "This Room", "This Room": "This Room",
"All Rooms": "All Rooms", "All Rooms": "All Rooms",