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
|
|
|
|
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.
|
2019-12-02 17:27:12 +00:00
|
|
|
*/
|
|
|
|
|
|
2025-03-27 10:43:58 +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";
|
2023-05-03 09:14:36 +12:00
|
|
|
import SettingsTab from "../SettingsTab";
|
|
|
|
|
import { SettingsSection } from "../../shared/SettingsSection";
|
2023-06-14 13:42:07 +01:00
|
|
|
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 {
|
2023-04-27 13:20:02 +12:00
|
|
|
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> {
|
2023-06-14 13:42:07 +01:00
|
|
|
public static contextType = MatrixClientContext;
|
2024-12-02 09:39:36 +00:00
|
|
|
declare public context: React.ContextType<typeof MatrixClientContext>;
|
2023-06-14 13:42:07 +01:00
|
|
|
|
2023-02-16 09:38:44 +00:00
|
|
|
private renderBridgeCard(event: MatrixEvent, room: Room | null): ReactNode {
|
2019-12-02 17:27:12 +00:00
|
|
|
const content = event.getContent();
|
2023-02-16 09:38:44 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2023-06-14 13:42:07 +01:00
|
|
|
public static getBridgeStateEvents(client: MatrixClient, roomId: string): MatrixEvent[] {
|
2023-02-16 09:38:44 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2023-02-13 17:01:43 +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.
|
2023-06-14 13:42:07 +01:00
|
|
|
const bridgeEvents = BridgeSettingsTab.getBridgeStateEvents(this.context, this.props.room.roomId);
|
2023-04-27 13:20:02 +12:00
|
|
|
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;
|
2020-01-21 18:41:43 +00:00
|
|
|
if (bridgeEvents.length > 0) {
|
|
|
|
|
content = (
|
|
|
|
|
<div>
|
2021-07-19 22:43:11 +01:00
|
|
|
<p>
|
|
|
|
|
{_t(
|
2023-09-26 18:35:55 +01:00
|
|
|
"room_settings|bridges|description",
|
2020-01-21 18:41:43 +00:00
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
// TODO: We don't have this link yet: this will prevent the translators
|
|
|
|
|
// having to re-translate the string when we do.
|
2021-07-19 22:43:11 +01:00
|
|
|
a: (sub) => (
|
|
|
|
|
<a href={BRIDGES_LINK} target="_blank" rel="noreferrer noopener">
|
|
|
|
|
{sub}
|
|
|
|
|
</a>
|
|
|
|
|
),
|
2020-01-21 18:41:43 +00:00
|
|
|
},
|
2021-07-19 22:43:11 +01:00
|
|
|
)}
|
|
|
|
|
</p>
|
2020-01-21 18:41:43 +00:00
|
|
|
<ul className="mx_RoomSettingsDialog_BridgeList">
|
2020-08-08 11:38:57 +01:00
|
|
|
{bridgeEvents.map((event) => this.renderBridgeCard(event, room))}
|
2020-01-21 18:41:43 +00:00
|
|
|
</ul>
|
2020-01-27 14:42:46 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2021-07-19 22:43:11 +01:00
|
|
|
content = (
|
|
|
|
|
<p>
|
|
|
|
|
{_t(
|
2023-09-26 18:35:55 +01:00
|
|
|
"room_settings|bridges|empty",
|
2020-01-21 18:41:43 +00:00
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
// TODO: We don't have this link yet: this will prevent the translators
|
|
|
|
|
// having to re-translate the string when we do.
|
2021-07-19 22:43:11 +01:00
|
|
|
a: (sub) => (
|
|
|
|
|
<a href={BRIDGES_LINK} target="_blank" rel="noreferrer noopener">
|
|
|
|
|
{sub}
|
|
|
|
|
</a>
|
|
|
|
|
),
|
2020-01-21 18:41:43 +00:00
|
|
|
},
|
2021-07-19 22:43:11 +01:00
|
|
|
)}
|
|
|
|
|
</p>
|
|
|
|
|
);
|
2020-01-21 18:41:43 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-02 17:27:12 +00:00
|
|
|
return (
|
2023-05-03 09:14:36 +12:00
|
|
|
<SettingsTab>
|
2023-09-26 18:35:55 +01:00
|
|
|
<SettingsSection heading={_t("room_settings|bridges|title")}>{content}</SettingsSection>
|
2023-05-03 09:14:36 +12:00
|
|
|
</SettingsTab>
|
2019-12-02 17:27:12 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|