2019-11-28 06:29:11 +03:00
|
|
|
/*
|
2021-07-02 16:51:55 +03:00
|
|
|
Copyright 2019 - 2021 The Matrix.org Foundation C.I.C.
|
2019-11-28 06:29:11 +03: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.
|
|
|
|
*/
|
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
import React, { ReactNode } from 'react';
|
|
|
|
import { EventType } from 'matrix-js-sdk/src/@types/event';
|
|
|
|
import { JoinRule } from 'matrix-js-sdk/src/@types/partials';
|
|
|
|
|
2021-06-29 15:11:58 +03:00
|
|
|
import { _t } from "../../../languageHandler";
|
2020-07-10 21:07:11 +03:00
|
|
|
import SdkConfig from "../../../SdkConfig";
|
2019-11-28 06:29:11 +03:00
|
|
|
import LabelledToggleSwitch from "../elements/LabelledToggleSwitch";
|
2021-06-29 15:11:58 +03:00
|
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
2019-12-03 03:26:08 +03:00
|
|
|
import Modal from "../../../Modal";
|
2021-06-29 15:11:58 +03:00
|
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
2021-07-02 16:51:55 +03:00
|
|
|
import { IDialogProps } from "./IDialogProps";
|
|
|
|
import BugReportDialog from './BugReportDialog';
|
|
|
|
import BaseDialog from "./BaseDialog";
|
|
|
|
import DialogButtons from "../elements/DialogButtons";
|
|
|
|
|
|
|
|
interface IProps extends IDialogProps {
|
|
|
|
roomId: string;
|
|
|
|
targetVersion: string;
|
|
|
|
description?: ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
inviteUsersToNewRoom: boolean;
|
|
|
|
}
|
2019-11-28 06:29:11 +03:00
|
|
|
|
2021-03-09 05:59:41 +03:00
|
|
|
@replaceableComponent("views.dialogs.RoomUpgradeWarningDialog")
|
2021-07-02 16:51:55 +03:00
|
|
|
export default class RoomUpgradeWarningDialog extends React.Component<IProps, IState> {
|
|
|
|
private readonly isPrivate: boolean;
|
|
|
|
private readonly currentVersion: string;
|
2019-11-28 06:29:11 +03:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
2021-07-02 16:51:55 +03:00
|
|
|
const joinRules = room?.currentState.getStateEvents(EventType.RoomJoinRules, "");
|
|
|
|
this.isPrivate = joinRules?.getContent()['join_rule'] !== JoinRule.Public ?? true;
|
|
|
|
this.currentVersion = room?.getVersion() || "1";
|
|
|
|
|
2019-11-28 06:29:11 +03:00
|
|
|
this.state = {
|
|
|
|
inviteUsersToNewRoom: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
private onContinue = () => {
|
|
|
|
this.props.onFinished({ continue: true, invite: this.isPrivate && this.state.inviteUsersToNewRoom });
|
2019-11-28 06:29:11 +03:00
|
|
|
};
|
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
private onCancel = () => {
|
2021-06-29 15:11:58 +03:00
|
|
|
this.props.onFinished({ continue: false, invite: false });
|
2019-11-28 06:29:11 +03:00
|
|
|
};
|
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
private onInviteUsersToggle = (inviteUsersToNewRoom: boolean) => {
|
|
|
|
this.setState({ inviteUsersToNewRoom });
|
2019-11-28 06:29:11 +03:00
|
|
|
};
|
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
private openBugReportDialog = (e) => {
|
2019-12-03 03:21:53 +03:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2019-12-03 03:26:08 +03:00
|
|
|
Modal.createTrackedDialog('Bug Report Dialog', '', BugReportDialog, {});
|
2019-12-03 03:21:53 +03:00
|
|
|
};
|
|
|
|
|
2019-11-28 06:29:11 +03:00
|
|
|
render() {
|
2020-07-10 21:07:11 +03:00
|
|
|
const brand = SdkConfig.get().brand;
|
2019-11-28 06:29:11 +03:00
|
|
|
|
|
|
|
let inviteToggle = null;
|
2021-07-02 16:51:55 +03:00
|
|
|
if (this.isPrivate) {
|
2019-11-28 06:29:11 +03:00
|
|
|
inviteToggle = (
|
|
|
|
<LabelledToggleSwitch
|
2019-12-03 03:21:53 +03:00
|
|
|
value={this.state.inviteUsersToNewRoom}
|
2021-07-02 16:51:55 +03:00
|
|
|
onChange={this.onInviteUsersToggle}
|
|
|
|
label={_t("Automatically invite members from this room to the new one")} />
|
2019-11-28 06:29:11 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
const title = this.isPrivate ? _t("Upgrade private room") : _t("Upgrade public room");
|
2019-12-03 03:21:53 +03:00
|
|
|
|
2021-03-16 22:50:43 +03:00
|
|
|
let bugReports = (
|
|
|
|
<p>
|
2021-07-02 16:51:55 +03:00
|
|
|
{ _t(
|
2021-03-16 22:50:43 +03:00
|
|
|
"This usually only affects how the room is processed on the server. If you're " +
|
2021-06-29 15:11:58 +03:00
|
|
|
"having problems with your %(brand)s, please report a bug.", { brand },
|
2021-07-02 16:51:55 +03:00
|
|
|
) }
|
2021-03-16 22:50:43 +03:00
|
|
|
</p>
|
|
|
|
);
|
|
|
|
if (SdkConfig.get().bug_report_endpoint_url) {
|
|
|
|
bugReports = (
|
|
|
|
<p>
|
2021-07-02 16:51:55 +03:00
|
|
|
{ _t(
|
2021-03-16 22:50:43 +03:00
|
|
|
"This usually only affects how the room is processed on the server. If you're " +
|
|
|
|
"having problems with your %(brand)s, please <a>report a bug</a>.",
|
|
|
|
{
|
|
|
|
brand,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"a": (sub) => {
|
2021-07-21 12:46:41 +03:00
|
|
|
return <a href='#' onClick={this.openBugReportDialog}>{ sub }</a>;
|
2021-03-16 22:50:43 +03:00
|
|
|
},
|
|
|
|
},
|
2021-07-02 16:51:55 +03:00
|
|
|
) }
|
2021-03-16 22:50:43 +03:00
|
|
|
</p>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-28 06:29:11 +03:00
|
|
|
return (
|
2019-12-03 03:21:53 +03:00
|
|
|
<BaseDialog
|
|
|
|
className='mx_RoomUpgradeWarningDialog'
|
|
|
|
hasCancel={true}
|
|
|
|
fixedWidth={false}
|
|
|
|
onFinished={this.props.onFinished}
|
|
|
|
title={title}
|
|
|
|
>
|
2019-11-28 06:29:11 +03:00
|
|
|
<div>
|
|
|
|
<p>
|
2021-07-02 16:51:55 +03:00
|
|
|
{ this.props.description || _t(
|
2019-12-03 03:21:53 +03:00
|
|
|
"Upgrading a room is an advanced action and is usually recommended when a room " +
|
|
|
|
"is unstable due to bugs, missing features or security vulnerabilities.",
|
2021-07-02 16:51:55 +03:00
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
{ _t(
|
|
|
|
"<b>Please note upgrading will make a new version of the room</b>. " +
|
|
|
|
"All current messages will stay in this archived room.", {}, {
|
|
|
|
b: sub => <b>{ sub }</b>,
|
|
|
|
},
|
|
|
|
) }
|
2019-11-28 06:29:11 +03:00
|
|
|
</p>
|
2021-07-02 16:51:55 +03:00
|
|
|
{ bugReports }
|
2019-11-28 06:29:11 +03:00
|
|
|
<p>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ _t(
|
2019-12-03 03:21:53 +03:00
|
|
|
"You'll upgrade this room from <oldVersion /> to <newVersion />.",
|
2019-11-28 06:29:11 +03:00
|
|
|
{},
|
|
|
|
{
|
2021-07-02 16:51:55 +03:00
|
|
|
oldVersion: () => <code>{ this.currentVersion }</code>,
|
|
|
|
newVersion: () => <code>{ this.props.targetVersion }</code>,
|
2019-11-28 06:29:11 +03:00
|
|
|
},
|
2021-07-20 00:43:11 +03:00
|
|
|
) }
|
2019-11-28 06:29:11 +03:00
|
|
|
</p>
|
2021-07-02 16:51:55 +03:00
|
|
|
{ inviteToggle }
|
2019-11-28 06:29:11 +03:00
|
|
|
</div>
|
|
|
|
<DialogButtons
|
2019-12-03 03:21:53 +03:00
|
|
|
primaryButton={_t("Upgrade")}
|
2021-07-02 16:51:55 +03:00
|
|
|
onPrimaryButtonClick={this.onContinue}
|
2019-11-28 06:29:11 +03:00
|
|
|
cancelButton={_t("Cancel")}
|
2021-07-02 16:51:55 +03:00
|
|
|
onCancel={this.onCancel}
|
2019-11-28 06:29:11 +03:00
|
|
|
/>
|
|
|
|
</BaseDialog>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|