/* Copyright 2015, 2016 OpenMarket Ltd Copyright 2017 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 classNames from 'classnames'; import sdk from "../../../index"; import MatrixClientPeg from "../../../MatrixClientPeg"; import { _t } from '../../../languageHandler'; import { UserAddressType } from '../../../Invite.js'; export default React.createClass({ displayName: 'AddressTile', propTypes: { address: UserAddressType.isRequired, canDismiss: React.PropTypes.bool, onDismissed: React.PropTypes.func, justified: React.PropTypes.bool, }, getDefaultProps: function() { return { canDismiss: false, onDismissed: function() {}, // NOP justified: false, }; }, render: function() { const address = this.props.address; const name = address.displayName || address.address; let imgUrls = []; if (address.addressType === "mx" && address.avatarMxc) { imgUrls.push(MatrixClientPeg.get().mxcUrlToHttp( address.avatarMxc, 25, 25, 'crop' )); } else if (address.addressType === 'email') { imgUrls.push('img/icon-email-user.svg'); } // Removing networks for now as they're not really supported /* var network; if (this.props.networkUrl !== "") { network = (
); } */ const BaseAvatar = sdk.getComponent('avatars.BaseAvatar'); const TintableSvg = sdk.getComponent("elements.TintableSvg"); const nameClasses = classNames({ "mx_AddressTile_name": true, "mx_AddressTile_justified": this.props.justified, }); let info; let error = false; if (address.addressType === "mx" && address.isKnown) { const idClasses = classNames({ "mx_AddressTile_id": true, "mx_AddressTile_justified": this.props.justified, }); info = (
{ name }
{ address.address }
); } else if (address.addressType === "mx") { const unknownMxClasses = classNames({ "mx_AddressTile_unknownMx": true, "mx_AddressTile_justified": this.props.justified, }); info = (
{ this.props.address.address }
); } else if (address.addressType === "email") { const emailClasses = classNames({ "mx_AddressTile_email": true, "mx_AddressTile_justified": this.props.justified, }); let nameNode = null; if (address.displayName) { nameNode =
{ address.displayName }
} info = (
{ address.address }
{nameNode}
); } else { error = true; var unknownClasses = classNames({ "mx_AddressTile_unknown": true, "mx_AddressTile_justified": this.props.justified, }); info = (
{_t("Unknown Address")}
); } const classes = classNames({ "mx_AddressTile": true, "mx_AddressTile_error": error, }); let dismiss; if (this.props.canDismiss) { dismiss = (
); } return (
{ info } { dismiss }
); } });