2015-11-27 11:50:33 +00:00
|
|
|
/*
|
2016-01-07 04:06:39 +00:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-11-27 11:50:33 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var React = require('react');
|
|
|
|
|
|
|
|
var MatrixClientPeg = require('../../../MatrixClientPeg');
|
|
|
|
var sdk = require('../../../index');
|
|
|
|
var dis = require('../../../dispatcher');
|
|
|
|
var Modal = require("../../../Modal");
|
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'MemberTile',
|
|
|
|
|
2016-01-13 15:55:28 +00:00
|
|
|
propTypes: {
|
2016-01-18 16:55:51 +00:00
|
|
|
member: React.PropTypes.any.isRequired, // RoomMember
|
2016-01-13 15:55:28 +00:00
|
|
|
},
|
|
|
|
|
2015-11-27 11:50:33 +00: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 15:19:49 +00:00
|
|
|
return true;
|
2015-11-27 11:50:33 +00:00
|
|
|
}
|
|
|
|
if (
|
|
|
|
nextProps.member.user &&
|
|
|
|
(this.user_last_modified_time === undefined ||
|
|
|
|
this.user_last_modified_time < nextProps.member.user.getLastModifiedTime())
|
|
|
|
) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
onClick: function(e) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_user',
|
|
|
|
member: this.props.member,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-01-13 16:55:28 +00:00
|
|
|
_getDisplayName: function() {
|
|
|
|
return this.props.member.name;
|
|
|
|
},
|
|
|
|
|
2015-11-27 11:50:33 +00:00
|
|
|
getPowerLabel: function() {
|
2016-01-18 17:31:26 +00:00
|
|
|
return this.props.member.userId + " (power " + this.props.member.powerLevel + ")";
|
2015-11-27 11:50:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2016-01-18 15:19:49 +00:00
|
|
|
var MemberAvatar = sdk.getComponent('avatars.MemberAvatar');
|
|
|
|
var BaseAvatar = sdk.getComponent('avatars.BaseAvatar');
|
|
|
|
var EntityTile = sdk.getComponent('rooms.EntityTile');
|
|
|
|
|
2016-01-13 16:55:28 +00:00
|
|
|
var member = this.props.member;
|
|
|
|
var name = this._getDisplayName();
|
|
|
|
var active = -1;
|
2016-01-18 16:55:51 +00:00
|
|
|
var presenceState = member.user ? member.user.presence : null;
|
2016-01-13 15:55:28 +00:00
|
|
|
|
2016-01-18 16:55:51 +00:00
|
|
|
var av = (
|
|
|
|
<MemberAvatar member={member} width={36} height={36} />
|
|
|
|
);
|
2016-01-18 15:19:49 +00:00
|
|
|
|
2016-01-18 16:55:51 +00:00
|
|
|
if (member.user) {
|
|
|
|
this.user_last_modified_time = member.user.getLastModifiedTime();
|
2016-01-13 16:55:28 +00:00
|
|
|
|
2016-01-18 16:55:51 +00:00
|
|
|
// FIXME: make presence data update whenever User.presence changes...
|
2016-03-16 22:25:57 +00:00
|
|
|
active = member.user.lastActiveAgo ?
|
|
|
|
(Date.now() - (member.user.lastPresenceTs - member.user.lastActiveAgo)) : -1;
|
2016-01-15 16:13:25 +00:00
|
|
|
}
|
2016-01-18 16:55:51 +00:00
|
|
|
this.member_last_modified_time = member.getLastModifiedTime();
|
2016-01-18 15:19:49 +00:00
|
|
|
|
2015-11-27 11:50:33 +00:00
|
|
|
return (
|
2016-01-18 15:19:49 +00:00
|
|
|
<EntityTile {...this.props} presenceActiveAgo={active} presenceState={presenceState}
|
2016-03-16 22:44:54 +00:00
|
|
|
presenceCurrentlyActive={ member.user ? member.user.currentlyActive : false }
|
2016-01-18 15:19:49 +00:00
|
|
|
avatarJsx={av} title={this.getPowerLabel()} onClick={this.onClick}
|
2016-01-18 17:31:26 +00:00
|
|
|
name={name} powerLevel={this.props.member.powerLevel} />
|
2015-11-27 11:50:33 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|