2016-08-23 14:30:15 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
|
Copyright 2016-2022 The Matrix.org Foundation C.I.C.
|
2016-08-23 14:30:15 +01:00
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2016-08-23 14:30:15 +01:00
|
|
|
*/
|
|
|
|
|
|
2025-03-27 10:43:58 +00:00
|
|
|
import React, { type JSX } from "react";
|
2021-10-22 17:23:32 -05:00
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
2024-07-24 10:49:33 +01:00
|
|
|
import NotificationsIcon from "@vector-im/compound-design-tokens/assets/web/icons/notifications";
|
2020-09-08 10:19:51 +01:00
|
|
|
|
2017-05-25 11:39:08 +01:00
|
|
|
import { _t } from "../../languageHandler";
|
2021-06-03 08:41:22 +01:00
|
|
|
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
2020-09-08 10:19:51 +01:00
|
|
|
import BaseCard from "../views/right_panel/BaseCard";
|
2021-05-25 12:15:37 +01:00
|
|
|
import TimelinePanel from "./TimelinePanel";
|
|
|
|
|
import Spinner from "../views/elements/Spinner";
|
2021-11-17 08:19:30 -07:00
|
|
|
import { Layout } from "../../settings/enums/Layout";
|
2021-10-11 11:26:05 +02:00
|
|
|
import RoomContext, { TimelineRenderingType } from "../../contexts/RoomContext";
|
2022-02-23 14:03:46 +00:00
|
|
|
import Measured from "../views/elements/Measured";
|
2024-07-19 18:17:40 +01:00
|
|
|
import EmptyState from "../views/right_panel/EmptyState";
|
2024-12-02 09:49:52 +00:00
|
|
|
import { ScopedRoomContextProvider } from "../../contexts/ScopedRoomContext.tsx";
|
2021-05-25 12:15:37 +01:00
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
|
onClose(): void;
|
|
|
|
|
}
|
2016-08-23 14:30:15 +01:00
|
|
|
|
2022-02-23 14:03:46 +00:00
|
|
|
interface IState {
|
|
|
|
|
narrow: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 14:30:15 +01:00
|
|
|
/*
|
2016-09-08 14:38:34 +01:00
|
|
|
* Component which shows the global notification list using a TimelinePanel
|
2016-08-23 14:30:15 +01:00
|
|
|
*/
|
2022-02-23 14:03:46 +00:00
|
|
|
export default class NotificationPanel extends React.PureComponent<IProps, IState> {
|
2022-12-16 12:29:59 +00:00
|
|
|
public static contextType = RoomContext;
|
2024-12-02 09:39:36 +00:00
|
|
|
declare public context: React.ContextType<typeof RoomContext>;
|
2022-02-23 14:03:46 +00:00
|
|
|
|
|
|
|
|
private card = React.createRef<HTMLDivElement>();
|
|
|
|
|
|
2025-03-19 10:40:06 +00:00
|
|
|
public constructor(props: IProps) {
|
|
|
|
|
super(props);
|
2022-02-23 14:03:46 +00:00
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
narrow: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private onMeasurement = (narrow: boolean): void => {
|
|
|
|
|
this.setState({ narrow });
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2020-07-31 18:31:22 +02:00
|
|
|
const emptyState = (
|
2024-07-19 18:17:40 +01:00
|
|
|
<EmptyState
|
|
|
|
|
Icon={NotificationsIcon}
|
|
|
|
|
title={_t("notif_panel|empty_heading")}
|
|
|
|
|
description={_t("notif_panel|empty_description")}
|
|
|
|
|
/>
|
2020-07-31 18:31:22 +02:00
|
|
|
);
|
|
|
|
|
|
2023-06-15 15:11:49 +01:00
|
|
|
let content: JSX.Element;
|
|
|
|
|
const timelineSet = MatrixClientPeg.safeGet().getNotifTimelineSet();
|
2016-09-08 03:02:31 +01:00
|
|
|
if (timelineSet) {
|
2021-05-25 12:15:37 +01:00
|
|
|
// wrap a TimelinePanel with the jump-to-event bits turned off.
|
2020-09-08 10:19:51 +01:00
|
|
|
content = (
|
|
|
|
|
<TimelinePanel
|
|
|
|
|
manageReadReceipts={false}
|
|
|
|
|
manageReadMarkers={false}
|
|
|
|
|
timelineSet={timelineSet}
|
|
|
|
|
showUrlPreview={false}
|
|
|
|
|
empty={emptyState}
|
2021-06-07 17:11:14 +01:00
|
|
|
alwaysShowTimestamps={true}
|
2021-07-22 16:00:41 +02:00
|
|
|
layout={Layout.Group}
|
2020-09-08 10:19:51 +01:00
|
|
|
/>
|
2016-09-08 03:02:31 +01:00
|
|
|
);
|
2017-10-11 17:56:17 +01:00
|
|
|
} else {
|
2021-10-15 16:30:53 +02:00
|
|
|
logger.error("No notifTimelineSet available!");
|
2021-05-25 12:15:37 +01:00
|
|
|
content = <Spinner />;
|
2016-09-08 03:02:31 +01:00
|
|
|
}
|
2020-09-08 10:19:51 +01:00
|
|
|
|
2021-10-11 11:26:05 +02:00
|
|
|
return (
|
2024-12-02 09:49:52 +00:00
|
|
|
<ScopedRoomContextProvider
|
|
|
|
|
{...this.context}
|
|
|
|
|
timelineRenderingType={TimelineRenderingType.Notification}
|
|
|
|
|
narrow={this.state.narrow}
|
2021-10-11 11:26:05 +02:00
|
|
|
>
|
2022-12-21 10:25:50 +00:00
|
|
|
<BaseCard
|
2024-10-03 09:59:41 +01:00
|
|
|
header={_t("notifications|enable_prompt_toast_title")}
|
2022-12-21 10:25:50 +00:00
|
|
|
/**
|
|
|
|
|
* Need to rename this CSS class to something more generic
|
|
|
|
|
* Will be done once all the panels are using a similar layout
|
|
|
|
|
*/
|
|
|
|
|
className="mx_ThreadPanel"
|
|
|
|
|
onClose={this.props.onClose}
|
|
|
|
|
withoutScrollContainer={true}
|
|
|
|
|
>
|
2025-01-16 12:26:00 +00:00
|
|
|
<Measured sensor={this.card} onMeasurement={this.onMeasurement} />
|
2021-10-11 11:26:05 +02:00
|
|
|
{content}
|
2021-10-11 14:33:40 -04:00
|
|
|
</BaseCard>
|
2024-12-02 09:49:52 +00:00
|
|
|
</ScopedRoomContextProvider>
|
2021-10-11 11:26:05 +02:00
|
|
|
);
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
|
|
|
|
}
|