Files
ThreadNet-Web/src/components/views/settings/tabs/room/BridgeSettingsTab.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
3.8 KiB
TypeScript
Raw Normal View History

2019-12-02 17:27:12 +00:00
/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
2020-08-08 11:38:57 +01:00
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
2019-12-02 17:27:12 +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.
2019-12-02 17:27:12 +00:00
*/
import React, { type JSX, type ReactNode } from "react";
2025-02-05 13:25:06 +00:00
import { type Room, type MatrixClient, type MatrixEvent } from "matrix-js-sdk/src/matrix";
2020-08-08 11:38:57 +01:00
2021-06-29 13:11:58 +01:00
import { _t } from "../../../../../languageHandler";
2020-01-27 14:05:22 +00:00
import BridgeTile from "../../BridgeTile";
import SettingsTab from "../SettingsTab";
import { SettingsSection } from "../../shared/SettingsSection";
import MatrixClientContext from "../../../../../contexts/MatrixClientContext";
2019-12-02 17:27:12 +00:00
const BRIDGE_EVENT_TYPES = [
"uk.half-shot.bridge",
// m.bridge
];
2020-01-28 14:42:58 +00:00
const BRIDGES_LINK = "https://matrix.org/bridges/";
2020-08-08 11:38:57 +01:00
interface IProps {
room: Room;
2020-08-08 11:38:57 +01:00
}
2019-12-02 17:27:12 +00:00
2020-08-08 11:38:57 +01:00
export default class BridgeSettingsTab extends React.Component<IProps> {
public static contextType = MatrixClientContext;
2024-12-02 09:39:36 +00:00
declare public context: React.ContextType<typeof MatrixClientContext>;
private renderBridgeCard(event: MatrixEvent, room: Room | null): ReactNode {
2019-12-02 17:27:12 +00:00
const content = event.getContent();
if (!room || !content?.channel || !content.protocol) return null;
2020-08-08 11:38:57 +01:00
return <BridgeTile key={event.getId()} room={room} ev={event} />;
2019-12-02 17:27:12 +00:00
}
public static getBridgeStateEvents(client: MatrixClient, roomId: string): MatrixEvent[] {
const roomState = client.getRoom(roomId)?.currentState;
if (!roomState) return [];
2019-12-02 17:27:12 +00:00
2021-06-17 14:49:27 +01:00
return BRIDGE_EVENT_TYPES.map((typeName) => roomState.getStateEvents(typeName)).flat(1);
2019-12-02 17:27:12 +00:00
}
public render(): React.ReactNode {
2019-12-02 17:27:12 +00:00
// This settings tab will only be invoked if the following function returns more
// than 0 events, so no validation is needed at this stage.
const bridgeEvents = BridgeSettingsTab.getBridgeStateEvents(this.context, this.props.room.roomId);
const room = this.props.room;
2019-12-02 17:27:12 +00:00
2020-08-08 11:38:57 +01:00
let content: JSX.Element;
if (bridgeEvents.length > 0) {
content = (
<div>
<p>
{_t(
"room_settings|bridges|description",
{},
{
// TODO: We don't have this link yet: this will prevent the translators
// having to re-translate the string when we do.
a: (sub) => (
<a href={BRIDGES_LINK} target="_blank" rel="noreferrer noopener">
{sub}
</a>
),
},
)}
</p>
<ul className="mx_RoomSettingsDialog_BridgeList">
2020-08-08 11:38:57 +01:00
{bridgeEvents.map((event) => this.renderBridgeCard(event, room))}
</ul>
2020-01-27 14:42:46 +00:00
</div>
);
} else {
content = (
<p>
{_t(
"room_settings|bridges|empty",
{},
{
// TODO: We don't have this link yet: this will prevent the translators
// having to re-translate the string when we do.
a: (sub) => (
<a href={BRIDGES_LINK} target="_blank" rel="noreferrer noopener">
{sub}
</a>
),
},
)}
</p>
);
}
2019-12-02 17:27:12 +00:00
return (
<SettingsTab>
<SettingsSection heading={_t("room_settings|bridges|title")}>{content}</SettingsSection>
</SettingsTab>
2019-12-02 17:27:12 +00:00
);
}
}