mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-16 01:31:30 +03:00
116 lines
3.9 KiB
JavaScript
116 lines
3.9 KiB
JavaScript
/*
|
|
Copyright 2020 New Vector Ltd
|
|
|
|
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 {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";
|
|
|
|
export default class BridgeTile extends React.PureComponent {
|
|
static propTypes = {
|
|
ev: PropTypes.object.isRequired,
|
|
room: PropTypes.object.isRequired,
|
|
}
|
|
|
|
state = {
|
|
visible: false,
|
|
}
|
|
|
|
_toggleVisible() {
|
|
this.setState({
|
|
visible: !this.state.visible,
|
|
});
|
|
}
|
|
|
|
render() {
|
|
const content = this.props.ev.getContent();
|
|
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) {
|
|
creator = _t("This bridge was provisioned by <user />.", {}, {
|
|
user: <Pill
|
|
type={Pill.TYPE_USER_MENTION}
|
|
room={this.props.room}
|
|
url={makeUserPermalink(content.creator)}
|
|
shouldShowPillAvatar={true}
|
|
/>,
|
|
});
|
|
}
|
|
|
|
const bot = _t("This bridge is managed by <user />.", {}, {
|
|
user: <Pill
|
|
type={Pill.TYPE_USER_MENTION}
|
|
room={this.props.room}
|
|
url={makeUserPermalink(this.props.ev.getSender())}
|
|
shouldShowPillAvatar={true}
|
|
/>,
|
|
});
|
|
|
|
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 {
|
|
networkIcon = <div class="noProtocolIcon"></div>;
|
|
}
|
|
|
|
|
|
const workspaceChannelDetails = _t("Workspace: %(networkName)s Channel: %(channelName)s", {
|
|
networkName,
|
|
channelName,
|
|
});
|
|
const id = this.props.ev.getId();
|
|
const metadataClassname = "metadata" + (this.state.visible ? " visible" : "");
|
|
return (<li key={id}>
|
|
<div className="column-icon">
|
|
{networkIcon}
|
|
</div>
|
|
<div className="column-data">
|
|
<h3>{protocolName}</h3>
|
|
<p className="workspace-channel-details">
|
|
{workspaceChannelDetails}
|
|
</p>
|
|
<p className={metadataClassname}>
|
|
{creator} {bot}
|
|
</p>
|
|
<AccessibleButton kind="secondary" onClick={this._toggleVisible.bind(this)}>
|
|
Show { this.state.visible ? "less" : "more" }
|
|
</AccessibleButton>
|
|
</div>
|
|
</li>);
|
|
}
|
|
}
|