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