2020-07-30 05:36:04 +03:00
|
|
|
/*
|
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
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 * as React from 'react';
|
|
|
|
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 19:17:47 +03:00
|
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
2020-08-25 22:58:15 +03:00
|
|
|
import { IDialogProps } from "./IDialogProps";
|
2021-03-09 05:59:41 +03:00
|
|
|
import {replaceableComponent} from "../../../utils/replaceableComponent";
|
2020-07-30 05:36:04 +03:00
|
|
|
|
2020-08-25 22:58:15 +03:00
|
|
|
interface IProps extends IDialogProps {
|
2020-07-30 05:36:04 +03:00
|
|
|
}
|
|
|
|
|
2021-03-09 05:59:41 +03:00
|
|
|
@replaceableComponent("views.dialogs.ServerOfflineDialog")
|
2020-07-30 05:36:04 +03:00
|
|
|
export default class ServerOfflineDialog extends React.PureComponent<IProps> {
|
|
|
|
public componentDidMount() {
|
|
|
|
EchoStore.instance.on(UPDATE_EVENT, this.onEchosUpdated);
|
|
|
|
}
|
|
|
|
|
|
|
|
public componentWillUnmount() {
|
|
|
|
EchoStore.instance.off(UPDATE_EVENT, this.onEchosUpdated);
|
|
|
|
}
|
|
|
|
|
|
|
|
private onEchosUpdated = () => {
|
|
|
|
this.forceUpdate(); // no state to worry about
|
|
|
|
};
|
|
|
|
|
|
|
|
private renderTimeline(): React.ReactElement[] {
|
|
|
|
return EchoStore.instance.contexts.map((c, i) => {
|
|
|
|
if (!c.firstFailedTime) return null; // not useful
|
|
|
|
if (!(c instanceof RoomEchoContext)) throw new Error("Cannot render unknown context: " + c);
|
|
|
|
const header = (
|
|
|
|
<div className="mx_ServerOfflineDialog_content_context_timeline_header">
|
|
|
|
<RoomAvatar width={24} height={24} room={c.room} />
|
|
|
|
<span>{c.room.name}</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
const entries = c.transactions
|
2020-07-31 19:00:02 +03:00
|
|
|
.filter(t => t.status === TransactionStatus.Error || t.didPreviouslyFail)
|
2020-07-30 05:36:04 +03:00
|
|
|
.map((t, j) => {
|
|
|
|
let button = <Spinner w={19} h={19} />;
|
2020-07-31 19:00:02 +03:00
|
|
|
if (t.status === TransactionStatus.Error) {
|
2020-07-30 05:36:04 +03:00
|
|
|
button = (
|
|
|
|
<AccessibleButton kind="link" onClick={() => t.run()}>{_t("Resend")}</AccessibleButton>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div className="mx_ServerOfflineDialog_content_context_txn" key={`txn-${j}`}>
|
|
|
|
<span className="mx_ServerOfflineDialog_content_context_txn_desc">
|
|
|
|
{t.auditName}
|
|
|
|
</span>
|
|
|
|
{button}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
return (
|
|
|
|
<div className="mx_ServerOfflineDialog_content_context" key={`context-${i}`}>
|
|
|
|
<div className="mx_ServerOfflineDialog_content_context_timestamp">
|
|
|
|
{formatTime(c.firstFailedTime, SettingsStore.getValue("showTwelveHourTimestamps"))}
|
|
|
|
</div>
|
|
|
|
<div className="mx_ServerOfflineDialog_content_context_timeline">
|
|
|
|
{header}
|
|
|
|
{entries}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
let timeline = this.renderTimeline().filter(c => !!c); // remove nulls for next check
|
|
|
|
if (timeline.length === 0) {
|
|
|
|
timeline = [<div key={1}>{_t("You're all caught up.")}</div>];
|
|
|
|
}
|
|
|
|
|
2020-07-30 19:17:47 +03:00
|
|
|
const serverName = MatrixClientPeg.getHomeserverName();
|
2020-07-30 05:36:04 +03:00
|
|
|
return <BaseDialog title={_t("Server isn't responding")}
|
|
|
|
className='mx_ServerOfflineDialog'
|
|
|
|
contentId='mx_Dialog_content'
|
|
|
|
onFinished={this.props.onFinished}
|
|
|
|
hasCancel={true}
|
|
|
|
>
|
|
|
|
<div className="mx_ServerOfflineDialog_content">
|
|
|
|
<p>{_t(
|
2020-07-30 19:17:47 +03:00
|
|
|
"Your server isn't responding to some of your requests. " +
|
|
|
|
"Below are some of the most likely reasons.",
|
2020-07-30 05:36:04 +03:00
|
|
|
)}</p>
|
|
|
|
<ul>
|
2020-07-30 19:17:47 +03:00
|
|
|
<li>{_t("The server (%(serverName)s) took too long to respond.", {serverName})}</li>
|
2020-07-30 05:36:04 +03:00
|
|
|
<li>{_t("Your firewall or anti-virus is blocking the request.")}</li>
|
|
|
|
<li>{_t("A browser extension is preventing the request.")}</li>
|
|
|
|
<li>{_t("The server is offline.")}</li>
|
|
|
|
<li>{_t("The server has denied your request.")}</li>
|
|
|
|
<li>{_t("Your area is experiencing difficulties connecting to the internet.")}</li>
|
|
|
|
<li>{_t("A connection error occurred while trying to contact the server.")}</li>
|
|
|
|
<li>{_t("The server is not configured to indicate what the problem is (CORS).")}</li>
|
|
|
|
</ul>
|
|
|
|
<hr />
|
|
|
|
<h2>{_t("Recent changes that have not yet been received")}</h2>
|
|
|
|
{timeline}
|
|
|
|
</div>
|
|
|
|
</BaseDialog>;
|
|
|
|
}
|
|
|
|
}
|