2020-07-29 20:36:04 -06:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2020-07-29 20:36:04 -06:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2024-09-09 14:57:16 +01:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2020-07-29 20:36:04 -06:00
|
|
|
*/
|
|
|
|
|
|
2023-04-05 09:02:40 +01:00
|
|
|
import React, { ReactNode } from "react";
|
2021-10-22 17:23:32 -05:00
|
|
|
|
2020-07-29 20:36:04 -06:00
|
|
|
import BaseDialog from "./BaseDialog";
|
|
|
|
|
import { _t } from "../../../languageHandler";
|
|
|
|
|
import { EchoStore } from "../../../stores/local-echo/EchoStore";
|
|
|
|
|
import { formatTime } from "../../../DateUtils";
|
|
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
|
|
|
|
import { RoomEchoContext } from "../../../stores/local-echo/RoomEchoContext";
|
|
|
|
|
import RoomAvatar from "../avatars/RoomAvatar";
|
|
|
|
|
import { TransactionStatus } from "../../../stores/local-echo/EchoTransaction";
|
|
|
|
|
import Spinner from "../elements/Spinner";
|
|
|
|
|
import AccessibleButton from "../elements/AccessibleButton";
|
|
|
|
|
import { UPDATE_EVENT } from "../../../stores/AsyncStore";
|
2020-07-30 10:17:47 -06:00
|
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
2020-07-29 20:36:04 -06:00
|
|
|
|
2023-02-28 10:31:48 +00:00
|
|
|
interface IProps {
|
|
|
|
|
onFinished(): void;
|
|
|
|
|
}
|
2020-07-29 20:36:04 -06:00
|
|
|
|
|
|
|
|
export default class ServerOfflineDialog extends React.PureComponent<IProps> {
|
2023-01-12 13:25:14 +00:00
|
|
|
public componentDidMount(): void {
|
2020-07-29 20:36:04 -06:00
|
|
|
EchoStore.instance.on(UPDATE_EVENT, this.onEchosUpdated);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public componentWillUnmount(): void {
|
2020-07-29 20:36:04 -06:00
|
|
|
EchoStore.instance.off(UPDATE_EVENT, this.onEchosUpdated);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onEchosUpdated = (): void => {
|
2020-07-29 20:36:04 -06:00
|
|
|
this.forceUpdate(); // no state to worry about
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-05 09:02:40 +01:00
|
|
|
private renderTimeline(): ReactNode[] {
|
2020-07-29 20:36:04 -06:00
|
|
|
return EchoStore.instance.contexts.map((c, i) => {
|
|
|
|
|
if (!c.firstFailedTime) return null; // not useful
|
2023-02-07 10:08:10 +00:00
|
|
|
if (!(c instanceof RoomEchoContext))
|
|
|
|
|
throw new Error("Cannot render unknown context: " + c.constructor.name);
|
2020-07-29 20:36:04 -06:00
|
|
|
const header = (
|
|
|
|
|
<div className="mx_ServerOfflineDialog_content_context_timeline_header">
|
2023-08-24 04:48:35 +01:00
|
|
|
<RoomAvatar size="24px" room={c.room} />
|
2021-07-19 22:43:11 +01:00
|
|
|
<span>{c.room.name}</span>
|
2020-07-29 20:36:04 -06:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
const entries = c.transactions
|
2020-07-31 10:00:02 -06:00
|
|
|
.filter((t) => t.status === TransactionStatus.Error || t.didPreviouslyFail)
|
2020-07-29 20:36:04 -06:00
|
|
|
.map((t, j) => {
|
|
|
|
|
let button = <Spinner w={19} h={19} />;
|
2020-07-31 10:00:02 -06:00
|
|
|
if (t.status === TransactionStatus.Error) {
|
2020-07-29 20:36:04 -06:00
|
|
|
button = (
|
2021-07-19 22:43:11 +01:00
|
|
|
<AccessibleButton kind="link" onClick={() => t.run()}>
|
2023-08-23 11:57:22 +01:00
|
|
|
{_t("action|resend")}
|
2021-07-19 22:43:11 +01:00
|
|
|
</AccessibleButton>
|
2020-07-29 20:36:04 -06:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx_ServerOfflineDialog_content_context_txn" key={`txn-${j}`}>
|
|
|
|
|
<span className="mx_ServerOfflineDialog_content_context_txn_desc">{t.auditName}</span>
|
2021-07-19 22:43:11 +01:00
|
|
|
{button}
|
2020-07-29 20:36:04 -06:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx_ServerOfflineDialog_content_context" key={`context-${i}`}>
|
|
|
|
|
<div className="mx_ServerOfflineDialog_content_context_timestamp">
|
2021-07-19 22:43:11 +01:00
|
|
|
{formatTime(c.firstFailedTime, SettingsStore.getValue("showTwelveHourTimestamps"))}
|
2020-07-29 20:36:04 -06:00
|
|
|
</div>
|
|
|
|
|
<div className="mx_ServerOfflineDialog_content_context_timeline">
|
2021-07-19 22:43:11 +01:00
|
|
|
{header}
|
|
|
|
|
{entries}
|
2020-07-29 20:36:04 -06:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-06-29 13:11:58 +01:00
|
|
|
);
|
2020-07-29 20:36:04 -06:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2020-07-29 20:36:04 -06:00
|
|
|
let timeline = this.renderTimeline().filter((c) => !!c); // remove nulls for next check
|
|
|
|
|
if (timeline.length === 0) {
|
2023-10-03 19:17:26 +01:00
|
|
|
timeline = [<div key={1}>{_t("server_offline|empty_timeline")}</div>];
|
2020-07-29 20:36:04 -06:00
|
|
|
}
|
|
|
|
|
|
2024-05-28 08:41:20 +01:00
|
|
|
const serverName = MatrixClientPeg.safeGet().getDomain();
|
2020-07-29 20:36:04 -06:00
|
|
|
return (
|
|
|
|
|
<BaseDialog
|
2023-10-03 19:17:26 +01:00
|
|
|
title={_t("server_offline|title")}
|
2020-07-29 20:36:04 -06:00
|
|
|
className="mx_ServerOfflineDialog"
|
|
|
|
|
contentId="mx_Dialog_content"
|
|
|
|
|
onFinished={this.props.onFinished}
|
|
|
|
|
hasCancel={true}
|
|
|
|
|
>
|
|
|
|
|
<div className="mx_ServerOfflineDialog_content">
|
2023-10-03 19:17:26 +01:00
|
|
|
<p>{_t("server_offline|description")}</p>
|
2020-07-29 20:36:04 -06:00
|
|
|
<ul>
|
2023-10-03 19:17:26 +01:00
|
|
|
<li>{_t("server_offline|description_1", { serverName })}</li>
|
|
|
|
|
<li>{_t("server_offline|description_2")}</li>
|
|
|
|
|
<li>{_t("server_offline|description_3")}</li>
|
|
|
|
|
<li>{_t("server_offline|description_4")}</li>
|
|
|
|
|
<li>{_t("server_offline|description_5")}</li>
|
|
|
|
|
<li>{_t("server_offline|description_6")}</li>
|
|
|
|
|
<li>{_t("server_offline|description_7")}</li>
|
|
|
|
|
<li>{_t("server_offline|description_8")}</li>
|
2020-07-29 20:36:04 -06:00
|
|
|
</ul>
|
|
|
|
|
<hr />
|
2023-10-03 19:17:26 +01:00
|
|
|
<h2>{_t("server_offline|recent_changes_heading")}</h2>
|
2021-07-19 22:43:11 +01:00
|
|
|
{timeline}
|
2020-07-29 20:36:04 -06:00
|
|
|
</div>
|
|
|
|
|
</BaseDialog>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|