2019-01-29 18:23:01 -07:00
|
|
|
/*
|
2022-01-24 12:47:59 +01:00
|
|
|
Copyright 2019 - 2022 The Matrix.org Foundation C.I.C.
|
2019-01-29 18:23:01 -07: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";
|
2023-08-08 11:12:12 +01:00
|
|
|
import { EventType, Room } from "matrix-js-sdk/src/matrix";
|
2021-06-08 16:28:02 +01:00
|
|
|
|
|
|
|
|
import { _t } from "../../../../../languageHandler";
|
2023-01-27 14:07:05 +00:00
|
|
|
import AccessibleButton, { ButtonEvent } from "../../../elements/AccessibleButton";
|
2021-06-08 16:28:02 +01:00
|
|
|
import RoomUpgradeDialog from "../../../dialogs/RoomUpgradeDialog";
|
2019-02-22 10:47:18 -07:00
|
|
|
import Modal from "../../../../../Modal";
|
2020-05-13 20:41:41 -06:00
|
|
|
import dis from "../../../../../dispatcher/dispatcher";
|
2021-11-25 17:49:43 -03:00
|
|
|
import { Action } from "../../../../../dispatcher/actions";
|
2022-01-24 12:47:59 +01:00
|
|
|
import CopyableText from "../../../elements/CopyableText";
|
2022-02-10 14:29:55 +00:00
|
|
|
import { ViewRoomPayload } from "../../../../../dispatcher/payloads/ViewRoomPayload";
|
2023-01-27 14:07:05 +00:00
|
|
|
import SettingsStore from "../../../../../settings/SettingsStore";
|
2023-05-03 09:14:36 +12:00
|
|
|
import SettingsTab from "../SettingsTab";
|
|
|
|
|
import { SettingsSection } from "../../shared/SettingsSection";
|
|
|
|
|
import SettingsSubsection from "../../shared/SettingsSubsection";
|
2021-06-08 16:28:02 +01:00
|
|
|
|
|
|
|
|
interface IProps {
|
2023-04-27 13:20:02 +12:00
|
|
|
room: Room;
|
2021-06-08 16:28:02 +01:00
|
|
|
closeSettingsFn(): void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IRecommendedVersion {
|
|
|
|
|
version: string;
|
|
|
|
|
needsUpgrade: boolean;
|
|
|
|
|
urgent: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IState {
|
2023-02-16 09:38:44 +00:00
|
|
|
// This is eventually set to the value of room.getRecommendedVersion()
|
2021-06-08 16:28:02 +01:00
|
|
|
upgradeRecommendation?: IRecommendedVersion;
|
2023-04-12 16:26:45 +01:00
|
|
|
|
|
|
|
|
/** The room ID of this room's predecessor, if it exists. */
|
2021-06-08 16:28:02 +01:00
|
|
|
oldRoomId?: string;
|
2023-04-12 16:26:45 +01:00
|
|
|
|
|
|
|
|
/** The ID of tombstone event in this room's predecessor, if it exists. */
|
2021-06-08 16:28:02 +01:00
|
|
|
oldEventId?: string;
|
2023-04-12 16:26:45 +01:00
|
|
|
|
|
|
|
|
/** The via servers to use to find this room's predecessor, if it exists. */
|
|
|
|
|
oldViaServers?: string[];
|
|
|
|
|
|
2021-06-08 16:28:02 +01:00
|
|
|
upgraded?: boolean;
|
|
|
|
|
}
|
2019-01-29 18:23:01 -07:00
|
|
|
|
2021-06-08 16:28:02 +01:00
|
|
|
export default class AdvancedRoomSettingsTab extends React.Component<IProps, IState> {
|
2023-02-13 11:39:16 +00:00
|
|
|
public constructor(props: IProps) {
|
|
|
|
|
super(props);
|
2020-07-07 23:14:04 +01:00
|
|
|
|
2023-01-27 14:07:05 +00:00
|
|
|
const msc3946ProcessDynamicPredecessor = SettingsStore.getValue("feature_dynamic_room_predecessors");
|
|
|
|
|
|
2023-02-16 09:38:44 +00:00
|
|
|
this.state = {};
|
2019-01-29 18:23:01 -07:00
|
|
|
|
|
|
|
|
// we handle lack of this object gracefully later, so don't worry about it failing here.
|
2023-04-27 13:20:02 +12:00
|
|
|
const room = this.props.room;
|
|
|
|
|
room.getRecommendedVersion().then((v) => {
|
2021-06-22 22:01:18 +01:00
|
|
|
const tombstone = room.currentState.getStateEvents(EventType.RoomTombstone, "");
|
2019-04-10 15:00:02 -06:00
|
|
|
|
2021-06-08 16:28:02 +01:00
|
|
|
const additionalStateChanges: Partial<IState> = {};
|
2023-01-27 14:07:05 +00:00
|
|
|
const predecessor = room.findPredecessor(msc3946ProcessDynamicPredecessor);
|
|
|
|
|
if (predecessor) {
|
|
|
|
|
additionalStateChanges.oldRoomId = predecessor.roomId;
|
|
|
|
|
additionalStateChanges.oldEventId = predecessor.eventId;
|
2023-04-12 16:26:45 +01:00
|
|
|
additionalStateChanges.oldViaServers = predecessor.viaServers;
|
2019-04-10 15:00:02 -06:00
|
|
|
}
|
|
|
|
|
|
2019-04-08 15:39:36 -06:00
|
|
|
this.setState({
|
2021-06-08 16:28:02 +01:00
|
|
|
upgraded: !!tombstone?.getContent().replacement_room,
|
2019-04-08 15:39:36 -06:00
|
|
|
upgradeRecommendation: v,
|
2019-04-10 15:00:02 -06:00
|
|
|
...additionalStateChanges,
|
2019-04-08 15:39:36 -06:00
|
|
|
});
|
2019-01-29 18:23:01 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-27 14:07:05 +00:00
|
|
|
private upgradeRoom = (): void => {
|
2023-04-27 13:20:02 +12:00
|
|
|
Modal.createDialog(RoomUpgradeDialog, { room: this.props.room });
|
2019-01-29 18:23:01 -07:00
|
|
|
};
|
|
|
|
|
|
2023-01-27 14:07:05 +00:00
|
|
|
private onOldRoomClicked = (e: ButtonEvent): void => {
|
2019-04-10 15:00:02 -06:00
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
2022-02-10 14:29:55 +00:00
|
|
|
dis.dispatch<ViewRoomPayload>({
|
2021-11-25 17:49:43 -03:00
|
|
|
action: Action.ViewRoom,
|
2019-04-10 15:00:02 -06:00
|
|
|
room_id: this.state.oldRoomId,
|
|
|
|
|
event_id: this.state.oldEventId,
|
2023-04-12 16:26:45 +01:00
|
|
|
via_servers: this.state.oldViaServers,
|
2022-02-17 18:03:27 +00:00
|
|
|
metricsTrigger: "WebPredecessorSettings",
|
|
|
|
|
metricsViaKeyboard: e.type !== "click",
|
2019-04-10 15:00:02 -06:00
|
|
|
});
|
|
|
|
|
this.props.closeSettingsFn();
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2023-04-27 13:20:02 +12:00
|
|
|
const room = this.props.room;
|
|
|
|
|
const isSpace = room.isSpaceRoom();
|
2019-01-29 18:23:01 -07:00
|
|
|
|
2023-02-16 09:38:44 +00:00
|
|
|
let unfederatableSection: JSX.Element | undefined;
|
2023-04-27 13:20:02 +12:00
|
|
|
if (room.currentState.getStateEvents(EventType.RoomCreate, "")?.getContent()["m.federate"] === false) {
|
2023-09-21 18:16:04 +01:00
|
|
|
unfederatableSection = <div>{_t("room_settings|advanced|unfederated")}</div>;
|
2019-01-29 18:23:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let roomUpgradeButton;
|
2019-04-08 15:39:36 -06:00
|
|
|
if (this.state.upgradeRecommendation && this.state.upgradeRecommendation.needsUpgrade && !this.state.upgraded) {
|
2019-01-29 18:23:01 -07:00
|
|
|
roomUpgradeButton = (
|
2019-03-14 17:11:44 -06:00
|
|
|
<div>
|
|
|
|
|
<p className="mx_SettingsTab_warningText">
|
2021-06-22 22:01:18 +01:00
|
|
|
{_t(
|
2023-09-21 18:16:04 +01:00
|
|
|
"room_settings|advanced|room_upgrade_warning",
|
2019-03-15 15:49:18 -06:00
|
|
|
{},
|
|
|
|
|
{
|
2021-07-19 22:43:11 +01:00
|
|
|
b: (sub) => <b>{sub}</b>,
|
|
|
|
|
i: (sub) => <i>{sub}</i>,
|
2019-03-15 15:49:18 -06:00
|
|
|
},
|
2021-06-22 22:01:18 +01:00
|
|
|
)}
|
2019-03-14 17:11:44 -06:00
|
|
|
</p>
|
2021-06-08 16:28:02 +01:00
|
|
|
<AccessibleButton onClick={this.upgradeRoom} kind="primary">
|
2022-03-29 15:02:12 +01:00
|
|
|
{isSpace
|
2023-09-21 18:16:04 +01:00
|
|
|
? _t("room_settings|advanced|space_upgrade_button")
|
|
|
|
|
: _t("room_settings|advanced|room_upgrade_button")}
|
2019-03-14 17:11:44 -06:00
|
|
|
</AccessibleButton>
|
|
|
|
|
</div>
|
2019-01-29 18:23:01 -07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-16 09:38:44 +00:00
|
|
|
let oldRoomLink: JSX.Element | undefined;
|
2021-06-08 16:28:02 +01:00
|
|
|
if (this.state.oldRoomId) {
|
2022-03-29 15:02:12 +01:00
|
|
|
let copy: string;
|
|
|
|
|
if (isSpace) {
|
2023-09-21 18:16:04 +01:00
|
|
|
copy = _t("room_settings|advanced|space_predecessor", { spaceName: room.name ?? this.state.oldRoomId });
|
2022-03-29 15:02:12 +01:00
|
|
|
} else {
|
2023-09-21 18:16:04 +01:00
|
|
|
copy = _t("room_settings|advanced|room_predecessor", { roomName: room.name ?? this.state.oldRoomId });
|
2022-03-29 15:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
2019-04-10 15:00:02 -06:00
|
|
|
oldRoomLink = (
|
2021-06-08 16:28:02 +01:00
|
|
|
<AccessibleButton element="a" onClick={this.onOldRoomClicked}>
|
2022-03-29 15:02:12 +01:00
|
|
|
{copy}
|
2019-04-11 10:40:25 -06:00
|
|
|
</AccessibleButton>
|
2019-04-10 15:00:02 -06:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-29 18:23:01 -07:00
|
|
|
return (
|
2023-05-03 09:14:36 +12:00
|
|
|
<SettingsTab>
|
2023-09-26 13:04:17 +01:00
|
|
|
<SettingsSection heading={_t("common|advanced")}>
|
2023-05-03 09:14:36 +12:00
|
|
|
<SettingsSubsection heading={room.isSpaceRoom() ? _t("Space information") : _t("Room information")}>
|
|
|
|
|
<div>
|
2023-09-21 18:16:04 +01:00
|
|
|
<span>{_t("room_settings|advanced|room_id")}</span>
|
2023-05-03 09:14:36 +12:00
|
|
|
<CopyableText getTextToCopy={() => this.props.room.roomId}>
|
|
|
|
|
{this.props.room.roomId}
|
|
|
|
|
</CopyableText>
|
|
|
|
|
</div>
|
|
|
|
|
{unfederatableSection}
|
|
|
|
|
</SettingsSubsection>
|
2023-09-21 18:16:04 +01:00
|
|
|
<SettingsSubsection heading={_t("room_settings|advanced|room_version_section")}>
|
2023-05-03 09:14:36 +12:00
|
|
|
<div>
|
2023-09-21 18:16:04 +01:00
|
|
|
<span>{_t("room_settings|advanced|room_version")}</span>
|
2023-05-03 09:14:36 +12:00
|
|
|
{room.getVersion()}
|
|
|
|
|
</div>
|
|
|
|
|
{oldRoomLink}
|
|
|
|
|
{roomUpgradeButton}
|
|
|
|
|
</SettingsSubsection>
|
|
|
|
|
</SettingsSection>
|
|
|
|
|
</SettingsTab>
|
2019-01-29 18:23:01 -07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|