2019-12-02 17:27:12 +00:00
|
|
|
/*
|
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
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-02-16 09:38:44 +00:00
|
|
|
import React, { ReactNode } from "react";
|
2023-08-07 09:24:58 +01:00
|
|
|
import { Room, MatrixClient, 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;
|
|
|
|
|
public context!: React.ContextType<typeof MatrixClientContext>;
|
|
|
|
|
|
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-08-22 16:32:05 +01:00
|
|
|
"This room is bridging messages to the following platforms. <a>Learn more.</a>",
|
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-08-22 16:32:05 +01:00
|
|
|
"This room isn't bridging messages to any platforms. <a>Learn more.</a>",
|
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>
|
|
|
|
|
<SettingsSection heading={_t("Bridges")}>{content}</SettingsSection>
|
|
|
|
|
</SettingsTab>
|
2019-12-02 17:27:12 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|