2016-09-05 16:28:08 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var React = require('react');
|
2016-09-07 09:55:44 +00:00
|
|
|
var classNames = require('classnames');
|
2016-09-05 16:28:08 +00:00
|
|
|
var sdk = require("../../../index");
|
2016-09-12 15:52:04 +00:00
|
|
|
var Invite = require("../../../Invite");
|
|
|
|
var MatrixClientPeg = require("../../../MatrixClientPeg");
|
2016-09-05 16:28:08 +00:00
|
|
|
var Avatar = require('../../../Avatar');
|
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'AddressTile',
|
|
|
|
|
|
|
|
propTypes: {
|
2016-09-12 15:52:04 +00:00
|
|
|
address: React.PropTypes.string.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-07 15:18:50 +00:00
|
|
|
networkName: React.PropTypes.string,
|
|
|
|
networkUrl: React.PropTypes.string,
|
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-07 15:18:50 +00:00
|
|
|
networkName: "",
|
|
|
|
networkUrl: "",
|
2016-09-05 16:28:08 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2016-09-12 15:52:04 +00:00
|
|
|
var userId, name, imgUrl, email;
|
2016-09-05 16:28:08 +00:00
|
|
|
var BaseAvatar = sdk.getComponent('avatars.BaseAvatar');
|
|
|
|
var TintableSvg = sdk.getComponent("elements.TintableSvg");
|
2016-09-12 15:52:04 +00:00
|
|
|
|
|
|
|
// Check if the addr is a valid type
|
|
|
|
var addrType = Invite.getAddressType(this.props.address);
|
|
|
|
if (addrType === "mx") {
|
|
|
|
let user = MatrixClientPeg.get().getUser(this.props.address);
|
|
|
|
if (user) {
|
|
|
|
userId = user.userId;
|
2016-09-16 02:19:33 +00:00
|
|
|
name = user.rawDisplayName || userId;
|
2016-09-12 15:52:04 +00:00
|
|
|
imgUrl = Avatar.avatarUrlForUser(user, 25, 25, "crop");
|
2016-09-12 16:15:56 +00:00
|
|
|
} else {
|
2016-09-13 16:09:40 +00:00
|
|
|
name=this.props.address;
|
|
|
|
imgUrl = "img/icon-mx-user.svg";
|
2016-09-12 15:52:04 +00:00
|
|
|
}
|
|
|
|
} else if (addrType === "email") {
|
|
|
|
email = this.props.address;
|
|
|
|
name="email";
|
|
|
|
imgUrl = "img/icon-email-user.svg";
|
|
|
|
} else {
|
|
|
|
name="Unknown";
|
2016-09-12 16:25:14 +00:00
|
|
|
imgUrl = "img/avatar-error.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
|
|
|
|
2016-09-12 15:52:04 +00:00
|
|
|
var info;
|
2016-09-12 16:25:14 +00:00
|
|
|
var error = false;
|
2016-09-13 16:09:40 +00:00
|
|
|
if (addrType === "mx" && userId) {
|
2016-09-12 15:52:04 +00:00
|
|
|
var nameClasses = classNames({
|
|
|
|
"mx_AddressTile_name": true,
|
|
|
|
"mx_AddressTile_justified": this.props.justified,
|
|
|
|
});
|
|
|
|
|
|
|
|
var idClasses = classNames({
|
|
|
|
"mx_AddressTile_id": true,
|
|
|
|
"mx_AddressTile_justified": this.props.justified,
|
|
|
|
});
|
|
|
|
|
|
|
|
info = (
|
|
|
|
<div className="mx_AddressTile_mx">
|
|
|
|
<div className={nameClasses}>{ name }</div>
|
|
|
|
<div className={idClasses}>{ userId }</div>
|
|
|
|
</div>
|
|
|
|
);
|
2016-09-13 16:09:40 +00:00
|
|
|
} else if (addrType === "mx") {
|
|
|
|
var unknownMxClasses = classNames({
|
|
|
|
"mx_AddressTile_unknownMx": true,
|
|
|
|
"mx_AddressTile_justified": this.props.justified,
|
|
|
|
});
|
|
|
|
|
|
|
|
info = (
|
|
|
|
<div className={unknownMxClasses}>{ this.props.address }</div>
|
|
|
|
);
|
2017-01-20 14:22:27 +00:00
|
|
|
} else if (email) {
|
2016-09-12 15:52:04 +00:00
|
|
|
var emailClasses = classNames({
|
|
|
|
"mx_AddressTile_email": true,
|
|
|
|
"mx_AddressTile_justified": this.props.justified,
|
|
|
|
});
|
|
|
|
|
|
|
|
info = (
|
|
|
|
<div className={emailClasses}>{ email }</div>
|
|
|
|
);
|
|
|
|
} else {
|
2016-09-12 16:25:14 +00:00
|
|
|
error = true;
|
2016-09-12 15:52:04 +00:00
|
|
|
var unknownClasses = classNames({
|
|
|
|
"mx_AddressTile_unknown": true,
|
|
|
|
"mx_AddressTile_justified": this.props.justified,
|
|
|
|
});
|
|
|
|
|
|
|
|
info = (
|
|
|
|
<div className={unknownClasses}>Unknown Address</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-09-12 16:25:14 +00:00
|
|
|
var classes = classNames({
|
|
|
|
"mx_AddressTile": true,
|
|
|
|
"mx_AddressTile_error": error,
|
|
|
|
});
|
|
|
|
|
2016-09-05 16:28:08 +00:00
|
|
|
var dismiss;
|
|
|
|
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">
|
2016-09-06 12:07:06 +00:00
|
|
|
<BaseAvatar width={25} height={25} name={name} title={name} url={imgUrl} />
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|