2019-05-02 15:11:06 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2019-05-02 15:11:06 +01:00
|
|
|
Copyright 2019 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.
|
2019-05-02 15:11:06 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
2022-03-01 20:42:05 +00:00
|
|
|
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/matrix";
|
2019-05-02 15:11:06 +01:00
|
|
|
import classNames from "classnames";
|
2021-10-22 17:23:32 -05:00
|
|
|
|
2021-05-18 10:02:21 +01:00
|
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
2022-01-03 18:51:58 +01:00
|
|
|
import { _t } from "../../../languageHandler";
|
2023-05-12 09:49:37 +01:00
|
|
|
import AccessibleButton, { ButtonEvent } from "../elements/AccessibleButton";
|
2019-05-02 15:11:06 +01:00
|
|
|
|
2021-07-22 17:11:23 +02:00
|
|
|
interface IProps {
|
|
|
|
|
mxEvent: MatrixEvent;
|
|
|
|
|
}
|
2019-05-02 15:11:06 +01:00
|
|
|
|
2021-07-22 17:11:23 +02:00
|
|
|
interface IState {
|
|
|
|
|
expanded: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default class ViewSourceEvent extends React.PureComponent<IProps, IState> {
|
2023-02-13 11:39:16 +00:00
|
|
|
public constructor(props: IProps) {
|
2019-05-02 15:11:06 +01:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
expanded: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-22 17:11:23 +02:00
|
|
|
public componentDidMount(): void {
|
2021-06-29 13:11:58 +01:00
|
|
|
const { mxEvent } = this.props;
|
2021-05-18 10:02:21 +01:00
|
|
|
|
2023-06-15 08:46:19 +01:00
|
|
|
const client = MatrixClientPeg.safeGet();
|
2021-05-18 13:01:38 +01:00
|
|
|
client.decryptEventIfNeeded(mxEvent);
|
2021-05-18 10:02:21 +01:00
|
|
|
|
2020-01-29 15:24:06 +01:00
|
|
|
if (mxEvent.isBeingDecrypted()) {
|
2022-02-22 12:18:08 +00:00
|
|
|
mxEvent.once(MatrixEventEvent.Decrypted, () => this.forceUpdate());
|
2020-01-29 15:24:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-12 09:49:37 +01:00
|
|
|
private onToggle = (ev: ButtonEvent): void => {
|
2019-05-02 15:11:06 +01:00
|
|
|
ev.preventDefault();
|
|
|
|
|
const { expanded } = this.state;
|
|
|
|
|
this.setState({
|
|
|
|
|
expanded: !expanded,
|
|
|
|
|
});
|
2021-07-22 17:11:23 +02:00
|
|
|
};
|
2019-05-02 15:11:06 +01:00
|
|
|
|
2021-07-22 17:11:23 +02:00
|
|
|
public render(): React.ReactNode {
|
2019-05-02 15:11:06 +01:00
|
|
|
const { mxEvent } = this.props;
|
|
|
|
|
const { expanded } = this.state;
|
|
|
|
|
|
|
|
|
|
let content;
|
|
|
|
|
if (expanded) {
|
2021-07-19 22:43:11 +01:00
|
|
|
content = <pre>{JSON.stringify(mxEvent, null, 4)}</pre>;
|
2019-05-02 15:11:06 +01:00
|
|
|
} else {
|
2021-07-19 22:43:11 +01:00
|
|
|
content = <code>{`{ "type": ${mxEvent.getType()} }`}</code>;
|
2019-05-02 15:11:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const classes = classNames("mx_ViewSourceEvent mx_EventTile_content", {
|
|
|
|
|
mx_ViewSourceEvent_expanded: expanded,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<span className={classes}>
|
2021-07-19 22:43:11 +01:00
|
|
|
{content}
|
2022-01-07 10:40:53 +01:00
|
|
|
<AccessibleButton
|
2022-06-29 22:37:34 +00:00
|
|
|
kind="link"
|
2023-10-03 19:17:26 +01:00
|
|
|
title={_t("devtools|toggle_event")}
|
2019-05-02 15:11:06 +01:00
|
|
|
className="mx_ViewSourceEvent_toggle"
|
|
|
|
|
onClick={this.onToggle}
|
|
|
|
|
/>
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-05-17 17:44:11 +01:00
|
|
|
}
|