2019-12-02 20:27:12 +03:00
|
|
|
/*
|
2020-01-03 16:57:59 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2019-12-02 20:27:12 +03: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import {_t} from "../../../../../languageHandler";
|
2020-01-10 00:16:32 +03:00
|
|
|
import {MatrixClientPeg} from "../../../../../MatrixClientPeg";
|
2019-12-02 20:27:12 +03:00
|
|
|
import Pill from "../../../elements/Pill";
|
|
|
|
import {makeUserPermalink} from "../../../../../utils/permalinks/Permalinks";
|
2019-12-04 18:02:36 +03:00
|
|
|
import BaseAvatar from "../../../avatars/BaseAvatar";
|
2020-01-10 00:16:32 +03:00
|
|
|
import {getHttpUriForMxc} from "matrix-js-sdk/src/content-repo";
|
2019-12-02 20:27:12 +03:00
|
|
|
|
|
|
|
const BRIDGE_EVENT_TYPES = [
|
|
|
|
"uk.half-shot.bridge",
|
|
|
|
// m.bridge
|
|
|
|
];
|
|
|
|
|
|
|
|
export default class BridgeSettingsTab extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
roomId: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
_renderBridgeCard(event, room) {
|
|
|
|
const content = event.getContent();
|
|
|
|
if (!content || !content.channel || !content.protocol) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-12-04 18:02:36 +03:00
|
|
|
const { channel, network } = content;
|
2019-12-02 20:27:12 +03:00
|
|
|
const protocolName = content.protocol.displayname || content.protocol.id;
|
2019-12-04 18:02:36 +03:00
|
|
|
const channelName = channel.displayname || channel.id;
|
2019-12-09 16:54:21 +03:00
|
|
|
const networkName = network ? network.displayname || network.id : protocolName;
|
2019-12-02 20:27:12 +03:00
|
|
|
|
|
|
|
let creator = null;
|
|
|
|
if (content.creator) {
|
2020-01-03 16:57:59 +03:00
|
|
|
creator = <p> { _t("This bridge was provisioned by <user />", {}, {
|
|
|
|
user: <Pill
|
|
|
|
type={Pill.TYPE_USER_MENTION}
|
|
|
|
room={room}
|
|
|
|
url={makeUserPermalink(content.creator)}
|
|
|
|
shouldShowPillAvatar={true}
|
|
|
|
/>,
|
|
|
|
})}</p>;
|
2019-12-02 20:27:12 +03:00
|
|
|
}
|
|
|
|
|
2020-01-03 17:04:59 +03:00
|
|
|
const bot = (<p> {_t("This bridge is managed by <user />.", {}, {
|
2020-01-03 16:57:59 +03:00
|
|
|
user: <Pill
|
2019-12-09 16:54:21 +03:00
|
|
|
type={Pill.TYPE_USER_MENTION}
|
|
|
|
room={room}
|
|
|
|
url={makeUserPermalink(event.getSender())}
|
|
|
|
shouldShowPillAvatar={true}
|
|
|
|
/>,
|
|
|
|
})} </p>);
|
2019-12-05 03:28:29 +03:00
|
|
|
let channelLink = channelName;
|
|
|
|
if (channel.external_url) {
|
2020-01-03 16:57:59 +03:00
|
|
|
channelLink = <a target="_blank" href={channel.external_url} rel="noopener">{channelName}</a>;
|
2019-12-05 03:28:29 +03:00
|
|
|
}
|
2019-12-02 20:27:12 +03:00
|
|
|
|
2019-12-05 03:28:29 +03:00
|
|
|
let networkLink = networkName;
|
|
|
|
if (network && network.external_url) {
|
2020-01-03 16:57:59 +03:00
|
|
|
networkLink = <a target="_blank" href={network.external_url} rel="noopener">{networkName}</a>;
|
2019-12-05 03:28:29 +03:00
|
|
|
}
|
2019-12-04 18:02:36 +03:00
|
|
|
|
2019-12-02 20:27:12 +03:00
|
|
|
const chanAndNetworkInfo = (
|
2020-01-03 16:57:59 +03:00
|
|
|
_t("Bridged into <channelLink /> <networkLink />, on <protocolName />", {}, {
|
2019-12-09 16:54:21 +03:00
|
|
|
channelLink,
|
|
|
|
networkLink,
|
|
|
|
protocolName,
|
2020-01-03 16:57:59 +03:00
|
|
|
})
|
2019-12-02 20:27:12 +03:00
|
|
|
);
|
|
|
|
|
2019-12-04 18:02:36 +03:00
|
|
|
let networkIcon = null;
|
|
|
|
if (networkName && network.avatar) {
|
2020-01-10 00:16:32 +03:00
|
|
|
const avatarUrl = getHttpUriForMxc(
|
2019-12-04 18:02:36 +03:00
|
|
|
MatrixClientPeg.get().getHomeserverUrl(),
|
|
|
|
network.avatar, 32, 32, "crop",
|
|
|
|
);
|
2020-01-03 16:57:59 +03:00
|
|
|
networkIcon = <BaseAvatar
|
2020-01-06 02:32:49 +03:00
|
|
|
width={32}
|
|
|
|
height={32}
|
|
|
|
resizeMethod='crop'
|
|
|
|
name={ networkName }
|
|
|
|
idName={ networkName }
|
|
|
|
url={ avatarUrl }
|
|
|
|
/>;
|
2019-12-04 18:02:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let channelIcon = null;
|
|
|
|
if (channel.avatar) {
|
2020-01-10 00:16:32 +03:00
|
|
|
const avatarUrl = getHttpUriForMxc(
|
2019-12-04 18:02:36 +03:00
|
|
|
MatrixClientPeg.get().getHomeserverUrl(),
|
|
|
|
channel.avatar, 32, 32, "crop",
|
|
|
|
);
|
2020-01-03 16:57:59 +03:00
|
|
|
channelIcon = <BaseAvatar
|
2020-01-06 02:32:49 +03:00
|
|
|
width={32}
|
|
|
|
height={32}
|
|
|
|
resizeMethod='crop'
|
|
|
|
name={ networkName }
|
|
|
|
idName={ networkName }
|
|
|
|
url={ avatarUrl }
|
|
|
|
/>;
|
2019-12-04 18:02:36 +03:00
|
|
|
}
|
|
|
|
|
2020-01-03 16:57:59 +03:00
|
|
|
const heading = _t("Connected to <channelIcon /> <channelName /> on <networkIcon /> <networkName />", { }, {
|
2019-12-09 16:54:21 +03:00
|
|
|
channelIcon,
|
|
|
|
channelName,
|
|
|
|
networkName,
|
|
|
|
networkIcon,
|
|
|
|
});
|
|
|
|
|
2019-12-02 20:27:12 +03:00
|
|
|
return (<li key={event.stateKey}>
|
|
|
|
<div>
|
2020-01-03 16:57:59 +03:00
|
|
|
<h3>{heading}</h3>
|
2019-12-09 16:54:21 +03:00
|
|
|
<p>{_t("Connected via %(protocolName)s", { protocolName })}</p>
|
2019-12-02 20:27:12 +03:00
|
|
|
<details>
|
|
|
|
{creator}
|
|
|
|
{bot}
|
2019-12-09 16:54:21 +03:00
|
|
|
<p>{chanAndNetworkInfo}</p>
|
2019-12-02 20:27:12 +03:00
|
|
|
</details>
|
|
|
|
</div>
|
|
|
|
</li>);
|
|
|
|
}
|
|
|
|
|
|
|
|
static getBridgeStateEvents(roomId) {
|
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
const roomState = (client.getRoom(roomId)).currentState;
|
|
|
|
|
|
|
|
const bridgeEvents = Array.concat(...BRIDGE_EVENT_TYPES.map((typeName) =>
|
|
|
|
Object.values(roomState.events[typeName] || {}),
|
|
|
|
));
|
|
|
|
|
|
|
|
return bridgeEvents;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
// 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.props.roomId);
|
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
const room = client.getRoom(this.props.roomId);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="mx_SettingsTab">
|
|
|
|
<div className="mx_SettingsTab_heading">{_t("Bridge Info")}</div>
|
|
|
|
<div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'>
|
2019-12-09 16:54:21 +03:00
|
|
|
<p>{ _t("Below is a list of bridges connected to this room.") }</p>
|
2019-12-02 20:27:12 +03:00
|
|
|
<ul className="mx_RoomSettingsDialog_BridgeList">
|
|
|
|
{ bridgeEvents.map((event) => this._renderBridgeCard(event, room)) }
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|