2018-08-17 14:54:43 +01:00
|
|
|
/*
|
2021-08-26 08:02:36 +01:00
|
|
|
Copyright 2018-2021 The Matrix.org Foundation C.I.C.
|
2018-08-17 14:54:43 +01:00
|
|
|
|
|
|
|
|
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';
|
2021-08-25 09:48:29 +01:00
|
|
|
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
|
|
|
|
|
import { Room } from 'matrix-js-sdk/src/models/room';
|
2022-02-24 14:39:25 +00:00
|
|
|
import { RoomStateEvent } from 'matrix-js-sdk/src/models/room-state';
|
2021-08-25 09:48:29 +01:00
|
|
|
|
2018-08-17 14:54:43 +01:00
|
|
|
import Modal from '../../../Modal';
|
|
|
|
|
import { _t } from '../../../languageHandler';
|
2021-06-29 13:11:58 +01:00
|
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
2021-08-17 18:05:10 +01:00
|
|
|
import RoomUpgradeDialog from '../dialogs/RoomUpgradeDialog';
|
|
|
|
|
import AccessibleButton from '../elements/AccessibleButton';
|
2021-11-29 11:06:19 +00:00
|
|
|
import MatrixClientContext from "../../../contexts/MatrixClientContext";
|
2018-08-17 14:54:43 +01:00
|
|
|
|
2021-08-14 10:46:38 +02:00
|
|
|
interface IProps {
|
|
|
|
|
room: Room;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
|
upgraded?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 20:12:00 -07:00
|
|
|
@replaceableComponent("views.rooms.RoomUpgradeWarningBar")
|
2021-08-14 10:46:38 +02:00
|
|
|
export default class RoomUpgradeWarningBar extends React.PureComponent<IProps, IState> {
|
2021-11-29 11:06:19 +00:00
|
|
|
static contextType = MatrixClientContext;
|
|
|
|
|
public context!: React.ContextType<typeof MatrixClientContext>;
|
2019-04-08 15:39:36 -06:00
|
|
|
|
2021-11-29 11:06:19 +00:00
|
|
|
constructor(props, context) {
|
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
|
|
const tombstone = this.props.room.currentState.getStateEvents("m.room.tombstone", "");
|
|
|
|
|
this.state = {
|
|
|
|
|
upgraded: tombstone?.getContent().replacement_room,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public componentDidMount(): void {
|
2022-02-22 12:18:08 +00:00
|
|
|
this.context.on(RoomStateEvent.Events, this.onStateEvents);
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
2019-04-08 15:39:36 -06:00
|
|
|
|
2021-08-14 10:46:38 +02:00
|
|
|
public componentWillUnmount(): void {
|
2022-02-22 12:18:08 +00:00
|
|
|
this.context.removeListener(RoomStateEvent.Events, this.onStateEvents);
|
2020-09-27 21:48:36 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-24 14:39:25 +00:00
|
|
|
private onStateEvents = (event: MatrixEvent): void => {
|
2019-04-08 15:39:36 -06:00
|
|
|
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", "");
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ upgraded: tombstone && tombstone.getContent().replacement_room });
|
2020-08-29 12:14:16 +01:00
|
|
|
};
|
2019-04-08 15:39:36 -06:00
|
|
|
|
2021-08-14 10:46:38 +02:00
|
|
|
private onUpgradeClick = (): void => {
|
2021-06-29 13:11:58 +01:00
|
|
|
Modal.createTrackedDialog('Upgrade Room Version', '', RoomUpgradeDialog, { room: this.props.room });
|
2020-08-29 12:14:16 +01:00
|
|
|
};
|
2018-08-17 14:54:43 +01:00
|
|
|
|
2021-08-14 10:46:38 +02:00
|
|
|
public render(): JSX.Element {
|
2019-04-08 15:39:36 -06:00
|
|
|
let doUpgradeWarnings = (
|
|
|
|
|
<div>
|
2018-08-17 14:54:43 +01:00
|
|
|
<div className="mx_RoomUpgradeWarningBar_body">
|
2019-03-15 16:00:34 -06:00
|
|
|
<p>
|
2021-07-19 22:43:11 +01:00
|
|
|
{ _t(
|
2019-03-15 16:00:34 -06:00
|
|
|
"Upgrading this room will shut down the current instance of the room and create " +
|
|
|
|
|
"an upgraded room with the same name.",
|
2021-07-19 22:43:11 +01:00
|
|
|
) }
|
2019-03-15 16:00:34 -06:00
|
|
|
</p>
|
|
|
|
|
<p>
|
2021-07-19 22:43:11 +01:00
|
|
|
{ _t(
|
2019-03-15 16:00:34 -06:00
|
|
|
"<b>Warning</b>: Upgrading a room will <i>not automatically migrate room members " +
|
|
|
|
|
"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.",
|
|
|
|
|
{}, {
|
2021-07-19 22:43:11 +01:00
|
|
|
"b": (sub) => <b>{ sub }</b>,
|
|
|
|
|
"i": (sub) => <i>{ sub }</i>,
|
2019-03-15 16:00:34 -06:00
|
|
|
},
|
2021-07-19 22:43:11 +01:00
|
|
|
) }
|
2019-03-15 16:00:34 -06:00
|
|
|
</p>
|
2018-08-17 14:54:43 +01:00
|
|
|
</div>
|
|
|
|
|
<p className="mx_RoomUpgradeWarningBar_upgradelink">
|
|
|
|
|
<AccessibleButton onClick={this.onUpgradeClick}>
|
2021-07-19 22:43:11 +01:00
|
|
|
{ _t("Upgrade this room to the recommended room version") }
|
2018-08-17 14:54:43 +01:00
|
|
|
</AccessibleButton>
|
|
|
|
|
</p>
|
2019-04-08 15:39:36 -06:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (this.state.upgraded) {
|
|
|
|
|
doUpgradeWarnings = (
|
|
|
|
|
<div className="mx_RoomUpgradeWarningBar_body">
|
|
|
|
|
<p>
|
2021-07-19 22:43:11 +01:00
|
|
|
{ _t("This room has already been upgraded.") }
|
2019-04-08 15:39:36 -06:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx_RoomUpgradeWarningBar">
|
2019-06-25 15:40:22 -06:00
|
|
|
<div className="mx_RoomUpgradeWarningBar_wrapped">
|
|
|
|
|
<div className="mx_RoomUpgradeWarningBar_header">
|
2021-07-19 22:43:11 +01:00
|
|
|
{ _t(
|
2019-06-25 15:40:22 -06:00
|
|
|
"This room is running room version <roomVersion />, which this homeserver has " +
|
|
|
|
|
"marked as <i>unstable</i>.",
|
|
|
|
|
{},
|
|
|
|
|
{
|
2021-07-19 22:43:11 +01:00
|
|
|
"roomVersion": () => <code>{ this.props.room.getVersion() }</code>,
|
|
|
|
|
"i": (sub) => <i>{ sub }</i>,
|
2019-06-25 15:40:22 -06:00
|
|
|
},
|
2021-07-19 22:43:11 +01:00
|
|
|
) }
|
2019-06-25 15:40:22 -06:00
|
|
|
</div>
|
2021-07-19 22:43:11 +01:00
|
|
|
{ doUpgradeWarnings }
|
2019-06-25 15:40:22 -06:00
|
|
|
<div className="mx_RoomUpgradeWarningBar_small">
|
2021-07-19 22:43:11 +01:00
|
|
|
{ _t("Only room administrators will see this warning") }
|
2019-06-25 15:40:22 -06:00
|
|
|
</div>
|
2018-08-17 14:54:43 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
|
|
|
|
}
|