2015-11-27 14:50:33 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-11-27 14:50:33 +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';
|
2015-11-27 14:50:33 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const MatrixClientPeg = require('../../../MatrixClientPeg');
|
|
|
|
const sdk = require('../../../index');
|
|
|
|
const dis = require('../../../dispatcher');
|
|
|
|
const Modal = require("../../../Modal");
|
2017-06-08 16:08:51 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2015-11-27 14:50:33 +03:00
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'MemberTile',
|
|
|
|
|
2016-01-13 18:55:28 +03:00
|
|
|
propTypes: {
|
2017-12-26 04:03:18 +03:00
|
|
|
member: PropTypes.any.isRequired, // RoomMember
|
2018-03-19 19:47:12 +03:00
|
|
|
showPresence: PropTypes.bool,
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
showPresence: true,
|
|
|
|
};
|
2016-01-13 18:55:28 +03:00
|
|
|
},
|
|
|
|
|
2015-11-27 14:50:33 +03:00
|
|
|
getInitialState: function() {
|
|
|
|
return {};
|
|
|
|
},
|
|
|
|
|
|
|
|
shouldComponentUpdate: function(nextProps, nextState) {
|
|
|
|
if (
|
|
|
|
this.member_last_modified_time === undefined ||
|
|
|
|
this.member_last_modified_time < nextProps.member.getLastModifiedTime()
|
|
|
|
) {
|
2016-01-18 18:19:49 +03:00
|
|
|
return true;
|
2015-11-27 14:50:33 +03:00
|
|
|
}
|
|
|
|
if (
|
|
|
|
nextProps.member.user &&
|
|
|
|
(this.user_last_modified_time === undefined ||
|
|
|
|
this.user_last_modified_time < nextProps.member.user.getLastModifiedTime())
|
|
|
|
) {
|
2017-01-20 17:22:27 +03:00
|
|
|
return true;
|
2015-11-27 14:50:33 +03:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
onClick: function(e) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_user',
|
|
|
|
member: this.props.member,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-01-13 19:55:28 +03:00
|
|
|
_getDisplayName: function() {
|
|
|
|
return this.props.member.name;
|
|
|
|
},
|
|
|
|
|
2015-11-27 14:50:33 +03:00
|
|
|
getPowerLabel: function() {
|
2017-06-08 16:08:51 +03:00
|
|
|
return _t("%(userName)s (power %(powerLevelNumber)s)", {userName: this.props.member.userId, powerLevelNumber: this.props.member.powerLevel});
|
2015-11-27 14:50:33 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2017-10-11 19:56:17 +03:00
|
|
|
const MemberAvatar = sdk.getComponent('avatars.MemberAvatar');
|
|
|
|
const BaseAvatar = sdk.getComponent('avatars.BaseAvatar');
|
|
|
|
const EntityTile = sdk.getComponent('rooms.EntityTile');
|
2016-01-18 18:19:49 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const member = this.props.member;
|
|
|
|
const name = this._getDisplayName();
|
|
|
|
const active = -1;
|
|
|
|
const presenceState = member.user ? member.user.presence : null;
|
2016-01-13 18:55:28 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const av = (
|
2016-01-18 19:55:51 +03:00
|
|
|
<MemberAvatar member={member} width={36} height={36} />
|
|
|
|
);
|
2016-01-18 18:19:49 +03:00
|
|
|
|
2016-01-18 19:55:51 +03:00
|
|
|
if (member.user) {
|
|
|
|
this.user_last_modified_time = member.user.getLastModifiedTime();
|
2016-01-15 19:13:25 +03:00
|
|
|
}
|
2016-01-18 19:55:51 +03:00
|
|
|
this.member_last_modified_time = member.getLastModifiedTime();
|
2016-04-18 03:35:40 +03:00
|
|
|
|
2017-11-06 19:37:16 +03:00
|
|
|
// We deliberately leave power levels that are not 100 or 50 undefined
|
|
|
|
const powerStatus = {
|
|
|
|
100: EntityTile.POWER_STATUS_ADMIN,
|
|
|
|
50: EntityTile.POWER_STATUS_MODERATOR,
|
|
|
|
}[this.props.member.powerLevel];
|
|
|
|
|
2015-11-27 14:50:33 +03:00
|
|
|
return (
|
2016-04-18 03:35:40 +03:00
|
|
|
<EntityTile {...this.props} presenceState={presenceState}
|
2017-10-11 19:56:17 +03:00
|
|
|
presenceLastActiveAgo={member.user ? member.user.lastActiveAgo : 0}
|
|
|
|
presenceLastTs={member.user ? member.user.lastPresenceTs : 0}
|
|
|
|
presenceCurrentlyActive={member.user ? member.user.currentlyActive : false}
|
2016-01-18 18:19:49 +03:00
|
|
|
avatarJsx={av} title={this.getPowerLabel()} onClick={this.onClick}
|
2018-03-19 19:47:12 +03:00
|
|
|
name={name} powerStatus={powerStatus} showPresence={this.props.showPresence} />
|
2015-11-27 14:50:33 +03:00
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
},
|
2015-11-27 14:50:33 +03:00
|
|
|
});
|