2016-09-05 16:28:08 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2017-08-14 16:43:00 +00:00
|
|
|
Copyright 2017 New Vector Ltd
|
2016-09-05 16:28:08 +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.
|
|
|
|
*/
|
|
|
|
|
2017-05-30 14:09:57 +00:00
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import sdk from "../../../index";
|
|
|
|
import MatrixClientPeg from "../../../MatrixClientPeg";
|
|
|
|
import { _t } from '../../../languageHandler';
|
2017-08-15 12:42:23 +00:00
|
|
|
import { UserAddressType } from '../../../UserAddress.js';
|
2017-01-24 18:23:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
export default React.createClass({
|
2016-09-05 16:28:08 +00:00
|
|
|
displayName: 'AddressTile',
|
|
|
|
|
|
|
|
propTypes: {
|
2017-08-15 09:57:24 +00:00
|
|
|
address: UserAddressType.isRequired,
|
2016-09-05 16:28:08 +00:00
|
|
|
canDismiss: React.PropTypes.bool,
|
|
|
|
onDismissed: React.PropTypes.func,
|
2016-09-07 09:55:44 +00:00
|
|
|
justified: React.PropTypes.bool,
|
2016-09-05 16:28:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
canDismiss: false,
|
|
|
|
onDismissed: function() {}, // NOP
|
2016-09-07 09:55:44 +00:00
|
|
|
justified: false,
|
2016-09-05 16:28:08 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2017-01-24 18:23:34 +00:00
|
|
|
const address = this.props.address;
|
|
|
|
const name = address.displayName || address.address;
|
|
|
|
|
2017-09-27 14:30:58 +00:00
|
|
|
const imgUrls = [];
|
|
|
|
const isMatrixAddress = ['mx-user-id', 'mx-room-id'].includes(address.addressType);
|
2017-01-24 18:23:34 +00:00
|
|
|
|
2017-09-27 14:30:58 +00:00
|
|
|
if (isMatrixAddress && address.avatarMxc) {
|
2017-02-23 12:12:25 +00:00
|
|
|
imgUrls.push(MatrixClientPeg.get().mxcUrlToHttp(
|
2017-09-27 14:30:58 +00:00
|
|
|
address.avatarMxc, 25, 25, 'crop',
|
2017-02-23 12:12:25 +00:00
|
|
|
));
|
2017-01-24 18:23:34 +00:00
|
|
|
} else if (address.addressType === 'email') {
|
2017-02-23 12:12:25 +00:00
|
|
|
imgUrls.push('img/icon-email-user.svg');
|
2016-09-12 15:52:04 +00:00
|
|
|
}
|
2016-09-05 16:28:08 +00:00
|
|
|
|
2017-01-18 15:21:50 +00:00
|
|
|
// Removing networks for now as they're not really supported
|
|
|
|
/*
|
2016-09-07 15:18:50 +00:00
|
|
|
var network;
|
|
|
|
if (this.props.networkUrl !== "") {
|
|
|
|
network = (
|
|
|
|
<div className="mx_AddressTile_network">
|
2016-09-19 12:26:59 +00:00
|
|
|
<BaseAvatar width={25} height={25} name={this.props.networkName} title="Riot" url={this.props.networkUrl} />
|
2016-09-07 15:18:50 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-01-18 15:21:50 +00:00
|
|
|
*/
|
2016-09-07 15:18:50 +00:00
|
|
|
|
2017-01-24 18:23:34 +00:00
|
|
|
const BaseAvatar = sdk.getComponent('avatars.BaseAvatar');
|
|
|
|
const TintableSvg = sdk.getComponent("elements.TintableSvg");
|
|
|
|
|
2017-01-25 18:51:28 +00:00
|
|
|
const nameClasses = classNames({
|
|
|
|
"mx_AddressTile_name": true,
|
|
|
|
"mx_AddressTile_justified": this.props.justified,
|
|
|
|
});
|
|
|
|
|
2017-01-24 18:23:34 +00:00
|
|
|
let info;
|
|
|
|
let error = false;
|
2017-09-27 14:30:58 +00:00
|
|
|
if (isMatrixAddress && address.isKnown) {
|
2017-01-24 18:23:34 +00:00
|
|
|
const idClasses = classNames({
|
2016-09-12 15:52:04 +00:00
|
|
|
"mx_AddressTile_id": true,
|
|
|
|
"mx_AddressTile_justified": this.props.justified,
|
|
|
|
});
|
|
|
|
|
|
|
|
info = (
|
|
|
|
<div className="mx_AddressTile_mx">
|
|
|
|
<div className={nameClasses}>{ name }</div>
|
2017-10-17 17:02:35 +00:00
|
|
|
{ this.props.showAddress ?
|
|
|
|
<div className={idClasses}>{ address.address }</div> :
|
|
|
|
<div />
|
|
|
|
}
|
2016-09-12 15:52:04 +00:00
|
|
|
</div>
|
|
|
|
);
|
2017-09-27 14:30:58 +00:00
|
|
|
} else if (isMatrixAddress) {
|
2017-01-24 18:23:34 +00:00
|
|
|
const unknownMxClasses = classNames({
|
2016-09-13 16:09:40 +00:00
|
|
|
"mx_AddressTile_unknownMx": true,
|
|
|
|
"mx_AddressTile_justified": this.props.justified,
|
|
|
|
});
|
|
|
|
|
|
|
|
info = (
|
2017-01-24 18:23:34 +00:00
|
|
|
<div className={unknownMxClasses}>{ this.props.address.address }</div>
|
2016-09-13 16:09:40 +00:00
|
|
|
);
|
2017-01-24 18:23:34 +00:00
|
|
|
} else if (address.addressType === "email") {
|
2017-01-25 18:51:28 +00:00
|
|
|
const emailClasses = classNames({
|
2016-09-12 15:52:04 +00:00
|
|
|
"mx_AddressTile_email": true,
|
|
|
|
"mx_AddressTile_justified": this.props.justified,
|
|
|
|
});
|
|
|
|
|
2017-01-25 18:51:28 +00:00
|
|
|
let nameNode = null;
|
|
|
|
if (address.displayName) {
|
2017-10-11 16:56:17 +00:00
|
|
|
nameNode = <div className={nameClasses}>{ address.displayName }</div>;
|
2017-01-25 18:51:28 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 15:52:04 +00:00
|
|
|
info = (
|
2017-01-25 18:51:28 +00:00
|
|
|
<div className="mx_AddressTile_mx">
|
|
|
|
<div className={emailClasses}>{ address.address }</div>
|
2017-10-11 16:56:17 +00:00
|
|
|
{ nameNode }
|
2017-01-25 18:51:28 +00:00
|
|
|
</div>
|
2016-09-12 15:52:04 +00:00
|
|
|
);
|
|
|
|
} else {
|
2016-09-12 16:25:14 +00:00
|
|
|
error = true;
|
2017-10-11 16:56:17 +00:00
|
|
|
const unknownClasses = classNames({
|
2016-09-12 15:52:04 +00:00
|
|
|
"mx_AddressTile_unknown": true,
|
|
|
|
"mx_AddressTile_justified": this.props.justified,
|
|
|
|
});
|
|
|
|
|
|
|
|
info = (
|
2017-10-11 16:56:17 +00:00
|
|
|
<div className={unknownClasses}>{ _t("Unknown Address") }</div>
|
2016-09-12 15:52:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-24 18:23:34 +00:00
|
|
|
const classes = classNames({
|
2016-09-12 16:25:14 +00:00
|
|
|
"mx_AddressTile": true,
|
|
|
|
"mx_AddressTile_error": error,
|
|
|
|
});
|
|
|
|
|
2017-01-24 18:23:34 +00:00
|
|
|
let dismiss;
|
2016-09-05 16:28:08 +00:00
|
|
|
if (this.props.canDismiss) {
|
|
|
|
dismiss = (
|
|
|
|
<div className="mx_AddressTile_dismiss" onClick={this.props.onDismissed} >
|
|
|
|
<TintableSvg src="img/icon-address-delete.svg" width="9" height="9" />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2016-09-12 16:25:14 +00:00
|
|
|
<div className={classes}>
|
2016-09-05 16:28:08 +00:00
|
|
|
<div className="mx_AddressTile_avatar">
|
2017-02-23 12:12:25 +00:00
|
|
|
<BaseAvatar defaultToInitialLetter={true} width={25} height={25} name={name} title={name} urls={imgUrls} />
|
2016-09-05 16:28:08 +00:00
|
|
|
</div>
|
2016-09-12 15:52:04 +00:00
|
|
|
{ info }
|
2016-09-05 16:28:08 +00:00
|
|
|
{ dismiss }
|
|
|
|
</div>
|
|
|
|
);
|
2017-10-11 16:56:17 +00:00
|
|
|
},
|
2016-09-05 16:28:08 +00:00
|
|
|
});
|