2020-01-27 17:05:22 +03:00
|
|
|
/*
|
2020-01-28 14:17:51 +03:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2020-01-27 17:05:22 +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.
|
|
|
|
*/
|
|
|
|
|
2020-11-30 15:01:16 +03:00
|
|
|
import React, { ReactNode } from 'react';
|
2020-01-27 17:05:22 +03:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import {getHttpUriForMxc} from "matrix-js-sdk/src/content-repo";
|
|
|
|
import {_t} from "../../../languageHandler";
|
|
|
|
import {MatrixClientPeg} from "../../../MatrixClientPeg";
|
|
|
|
import Pill from "../elements/Pill";
|
|
|
|
import {makeUserPermalink} from "../../../utils/permalinks/Permalinks";
|
|
|
|
import BaseAvatar from "../avatars/BaseAvatar";
|
|
|
|
import AccessibleButton from "../elements/AccessibleButton";
|
2020-11-30 15:01:16 +03:00
|
|
|
import {replaceableComponentTs} from "../../../utils/replaceableComponent";
|
2020-09-02 19:26:23 +03:00
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2020-11-30 15:47:51 +03:00
|
|
|
import {MatrixEvent} from "matrix-js-sdk/src/models/event";
|
2020-11-30 15:05:30 +03:00
|
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
ev: MatrixEvent;
|
|
|
|
room: Room;
|
|
|
|
}
|
|
|
|
|
2020-11-30 15:47:27 +03:00
|
|
|
/**
|
2020-11-30 15:47:51 +03:00
|
|
|
* This should match https://github.com/matrix-org/matrix-doc/blob/hs/msc-bridge-inf/proposals/2346-bridge-info-state-event.md#mbridge
|
|
|
|
*/
|
|
|
|
interface IBridgeStateEvent {
|
|
|
|
bridgebot: string;
|
|
|
|
creator?: string;
|
|
|
|
protocol: {
|
|
|
|
id: string;
|
|
|
|
displayname?: string;
|
|
|
|
avatar_url?: string;
|
|
|
|
external_url?: string;
|
|
|
|
};
|
|
|
|
network?: {
|
|
|
|
id: string;
|
|
|
|
displayname?: string;
|
|
|
|
avatar_url?: string;
|
|
|
|
external_url?: string;
|
|
|
|
};
|
|
|
|
channel: {
|
|
|
|
id: string;
|
|
|
|
displayname?: string;
|
|
|
|
avatar_url?: string;
|
|
|
|
external_url?: string;
|
|
|
|
};
|
2020-11-30 15:05:30 +03:00
|
|
|
}
|
2020-01-28 14:33:51 +03:00
|
|
|
|
2020-11-30 15:01:16 +03:00
|
|
|
@replaceableComponentTs("views.settings.BridgeTile")
|
2020-11-30 15:47:27 +03:00
|
|
|
export default class BridgeTile extends React.PureComponent<IProps> {
|
2020-01-27 17:05:22 +03:00
|
|
|
static propTypes = {
|
|
|
|
ev: PropTypes.object.isRequired,
|
|
|
|
room: PropTypes.object.isRequired,
|
|
|
|
}
|
2020-01-27 17:42:46 +03:00
|
|
|
|
2020-01-27 17:05:22 +03:00
|
|
|
|
2020-11-30 15:05:30 +03:00
|
|
|
render() {
|
2020-11-30 15:47:51 +03:00
|
|
|
const content: IBridgeStateEvent = this.props.ev.getContent();
|
|
|
|
// Validate
|
|
|
|
if (!content.bridgebot || !content.channel?.id || !content.protocol?.id) {
|
|
|
|
console.warn(`Bridge info event ${this.props.ev.getId()} has missing content. Tile will not render`);
|
|
|
|
return null;
|
|
|
|
}
|
2020-01-27 17:05:22 +03:00
|
|
|
const { channel, network, protocol } = content;
|
|
|
|
const protocolName = protocol.displayname || protocol.id;
|
|
|
|
const channelName = channel.displayname || channel.id;
|
|
|
|
const networkName = network ? network.displayname || network.id : protocolName;
|
|
|
|
|
|
|
|
let creator = null;
|
|
|
|
if (content.creator) {
|
2020-11-30 15:47:27 +03:00
|
|
|
creator = <li>{_t("This bridge was provisioned by <user />.", {}, {
|
2020-11-30 15:05:30 +03:00
|
|
|
user: () => <Pill
|
|
|
|
type={Pill.TYPE_USER_MENTION}
|
|
|
|
room={this.props.room}
|
|
|
|
url={makeUserPermalink(content.creator)}
|
|
|
|
shouldShowPillAvatar={SettingsStore.getValue("Pill.shouldShowPillAvatar")}
|
|
|
|
/>,
|
2020-11-30 15:47:27 +03:00
|
|
|
})}</li>;
|
2020-01-27 17:05:22 +03:00
|
|
|
}
|
|
|
|
|
2020-11-30 15:47:27 +03:00
|
|
|
const bot = <li>{_t("This bridge is managed by <user />.", {}, {
|
2020-11-30 15:05:30 +03:00
|
|
|
user: () => <Pill
|
2020-01-27 17:05:22 +03:00
|
|
|
type={Pill.TYPE_USER_MENTION}
|
|
|
|
room={this.props.room}
|
2020-11-30 15:47:27 +03:00
|
|
|
url={makeUserPermalink(content.bridgebot)}
|
2020-09-02 19:26:23 +03:00
|
|
|
shouldShowPillAvatar={SettingsStore.getValue("Pill.shouldShowPillAvatar")}
|
2020-11-30 15:05:30 +03:00
|
|
|
/>,
|
2020-11-30 15:47:27 +03:00
|
|
|
})}</li>;
|
2020-01-27 17:05:22 +03:00
|
|
|
|
|
|
|
let networkIcon;
|
|
|
|
|
|
|
|
if (protocol.avatar) {
|
|
|
|
const avatarUrl = getHttpUriForMxc(
|
|
|
|
MatrixClientPeg.get().getHomeserverUrl(),
|
|
|
|
protocol.avatar, 64, 64, "crop",
|
|
|
|
);
|
|
|
|
|
|
|
|
networkIcon = <BaseAvatar className="protocol-icon"
|
|
|
|
width={48}
|
|
|
|
height={48}
|
|
|
|
resizeMethod='crop'
|
|
|
|
name={ protocolName }
|
|
|
|
idName={ protocolName }
|
|
|
|
url={ avatarUrl }
|
|
|
|
/>;
|
|
|
|
} else {
|
2020-11-30 15:05:30 +03:00
|
|
|
networkIcon = <div className="noProtocolIcon"></div>;
|
2020-01-27 17:05:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const id = this.props.ev.getId();
|
|
|
|
return (<li key={id}>
|
|
|
|
<div className="column-icon">
|
|
|
|
{networkIcon}
|
|
|
|
</div>
|
|
|
|
<div className="column-data">
|
|
|
|
<h3>{protocolName}</h3>
|
|
|
|
<p className="workspace-channel-details">
|
2020-01-28 14:17:51 +03:00
|
|
|
<span>{_t("Workspace: %(networkName)s", {networkName})}</span>
|
|
|
|
<span className="channel">{_t("Channel: %(channelName)s", {channelName})}</span>
|
2020-01-27 17:05:22 +03:00
|
|
|
</p>
|
2020-11-30 15:47:27 +03:00
|
|
|
<ul className="metadata">
|
2020-01-27 17:05:22 +03:00
|
|
|
{creator} {bot}
|
2020-11-30 15:47:27 +03:00
|
|
|
</ul>
|
2020-01-27 17:05:22 +03:00
|
|
|
</div>
|
|
|
|
</li>);
|
|
|
|
}
|
|
|
|
}
|