2015-09-17 20:23:38 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-09-17 20:23:38 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const React = require('react');
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-10-11 19:56:17 +03:00
|
|
|
const Avatar = require('../../../Avatar');
|
|
|
|
const sdk = require("../../../index");
|
2016-11-10 18:18:59 +03:00
|
|
|
const dispatcher = require("../../../dispatcher");
|
2015-09-17 20:23:38 +03:00
|
|
|
|
2015-11-26 15:02:31 +03:00
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'MemberAvatar',
|
|
|
|
|
2015-09-17 20:23:38 +03:00
|
|
|
propTypes: {
|
2017-12-26 04:03:18 +03:00
|
|
|
member: PropTypes.object.isRequired,
|
|
|
|
width: PropTypes.number,
|
|
|
|
height: PropTypes.number,
|
|
|
|
resizeMethod: PropTypes.string,
|
2016-11-10 20:30:35 +03:00
|
|
|
// The onClick to give the avatar
|
2017-12-26 04:03:18 +03:00
|
|
|
onClick: PropTypes.func,
|
2016-11-10 20:30:35 +03:00
|
|
|
// Whether the onClick of the avatar should be overriden to dispatch 'view_user'
|
2017-12-26 04:03:18 +03:00
|
|
|
viewUserOnClick: PropTypes.bool,
|
|
|
|
title: PropTypes.string,
|
2015-09-17 20:23:38 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
width: 40,
|
|
|
|
height: 40,
|
2016-11-10 18:18:59 +03:00
|
|
|
resizeMethod: 'crop',
|
2016-11-10 20:27:59 +03:00
|
|
|
viewUserOnClick: false,
|
2017-01-20 17:22:27 +03:00
|
|
|
};
|
2015-09-17 20:23:38 +03:00
|
|
|
},
|
|
|
|
|
2016-01-13 19:55:28 +03:00
|
|
|
getInitialState: function() {
|
2016-01-15 15:02:28 +03:00
|
|
|
return this._getState(this.props);
|
2015-10-28 18:15:35 +03:00
|
|
|
},
|
|
|
|
|
2016-01-13 19:55:28 +03:00
|
|
|
componentWillReceiveProps: function(nextProps) {
|
2016-01-15 15:02:28 +03:00
|
|
|
this.setState(this._getState(nextProps));
|
2015-10-28 18:15:35 +03:00
|
|
|
},
|
|
|
|
|
2016-01-15 15:02:28 +03:00
|
|
|
_getState: function(props) {
|
2016-08-27 03:18:48 +03:00
|
|
|
if (!props.member) {
|
|
|
|
console.error("MemberAvatar called somehow with null member");
|
|
|
|
}
|
2016-01-15 15:02:28 +03:00
|
|
|
return {
|
|
|
|
name: props.member.name,
|
2016-12-08 19:23:20 +03:00
|
|
|
title: props.title || props.member.userId,
|
2016-01-15 15:02:28 +03:00
|
|
|
imageUrl: Avatar.avatarUrlForMember(props.member,
|
|
|
|
props.width,
|
|
|
|
props.height,
|
2017-10-11 19:56:17 +03:00
|
|
|
props.resizeMethod),
|
2017-01-20 17:22:27 +03:00
|
|
|
};
|
2015-10-28 18:15:35 +03:00
|
|
|
},
|
|
|
|
|
2015-11-26 15:02:31 +03:00
|
|
|
render: function() {
|
2017-10-11 19:56:17 +03:00
|
|
|
const BaseAvatar = sdk.getComponent("avatars.BaseAvatar");
|
2016-08-01 19:10:46 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
let {member, onClick, viewUserOnClick, ...otherProps} = this.props;
|
2016-08-01 19:10:46 +03:00
|
|
|
|
2016-11-16 17:42:30 +03:00
|
|
|
if (viewUserOnClick) {
|
2016-11-10 18:18:59 +03:00
|
|
|
onClick = () => {
|
|
|
|
dispatcher.dispatch({
|
|
|
|
action: 'view_user',
|
|
|
|
member: this.props.member,
|
|
|
|
});
|
2017-01-20 17:22:27 +03:00
|
|
|
};
|
2016-11-10 18:18:59 +03:00
|
|
|
}
|
|
|
|
|
2015-11-26 15:02:31 +03:00
|
|
|
return (
|
2016-08-01 19:10:46 +03:00
|
|
|
<BaseAvatar {...otherProps} name={this.state.name} title={this.state.title}
|
2017-10-11 19:56:17 +03:00
|
|
|
idName={member.userId} url={this.state.imageUrl} onClick={onClick} />
|
2015-11-26 15:02:31 +03:00
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
},
|
2015-11-26 15:02:31 +03:00
|
|
|
});
|