2017-07-25 14:56:16 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd.
|
2017-08-25 11:10:13 +00:00
|
|
|
Copyright 2017 New Vector Ltd.
|
2017-07-25 14:56:16 +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.
|
|
|
|
*/
|
|
|
|
import React from 'react';
|
|
|
|
import { _t } from '../../../languageHandler';
|
|
|
|
import sdk from '../../../index';
|
2017-10-23 15:04:26 +00:00
|
|
|
import GroupStoreCache from '../../../stores/GroupStoreCache';
|
2017-07-25 14:56:16 +00:00
|
|
|
import GeminiScrollbar from 'react-gemini-scrollbar';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import withMatrixClient from '../../../wrappers/withMatrixClient';
|
|
|
|
|
|
|
|
const INITIAL_LOAD_NUM_MEMBERS = 30;
|
|
|
|
|
|
|
|
export default withMatrixClient(React.createClass({
|
|
|
|
displayName: 'GroupMemberList',
|
|
|
|
|
2017-10-23 15:04:26 +00:00
|
|
|
contextTypes: {
|
2017-07-25 14:56:16 +00:00
|
|
|
matrixClient: PropTypes.object.isRequired,
|
2017-10-23 15:04:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
propTypes: {
|
2017-07-25 14:56:16 +00:00
|
|
|
groupId: PropTypes.string.isRequired,
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
members: null,
|
2017-10-16 16:21:05 +00:00
|
|
|
invitedMembers: null,
|
2017-08-21 18:30:28 +00:00
|
|
|
truncateAt: INITIAL_LOAD_NUM_MEMBERS,
|
|
|
|
};
|
2017-07-25 14:56:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount: function() {
|
|
|
|
this._unmounted = false;
|
2017-10-23 15:04:26 +00:00
|
|
|
this._initGroupStore(this.props.groupId);
|
2017-07-25 14:56:16 +00:00
|
|
|
},
|
|
|
|
|
2017-10-23 15:04:26 +00:00
|
|
|
_initGroupStore: function(groupId) {
|
|
|
|
this._groupStore = GroupStoreCache.getGroupStore(this.context.matrixClient, groupId);
|
|
|
|
this._groupStore.on('update', () => {
|
|
|
|
this._fetchMembers();
|
2017-10-16 16:21:05 +00:00
|
|
|
});
|
2017-10-23 15:04:26 +00:00
|
|
|
this._groupStore.on('error', (err) => {
|
|
|
|
console.error(err);
|
2017-07-25 14:56:16 +00:00
|
|
|
});
|
2017-10-23 15:04:26 +00:00
|
|
|
},
|
2017-10-16 15:38:32 +00:00
|
|
|
|
2017-10-23 15:04:26 +00:00
|
|
|
_fetchMembers: function() {
|
2017-10-24 08:58:45 +00:00
|
|
|
if (this._unmounted) return;
|
2017-10-23 15:04:26 +00:00
|
|
|
this.setState({
|
|
|
|
members: this._groupStore.getGroupMembers(),
|
|
|
|
invitedMembers: this._groupStore.getGroupInvitedMembers(),
|
2017-10-16 15:38:32 +00:00
|
|
|
});
|
2017-07-25 14:56:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_createOverflowTile: function(overflowCount, totalCount) {
|
|
|
|
// For now we'll pretend this is any entity. It should probably be a separate tile.
|
|
|
|
const EntityTile = sdk.getComponent("rooms.EntityTile");
|
|
|
|
const BaseAvatar = sdk.getComponent("avatars.BaseAvatar");
|
|
|
|
const text = _t("and %(count)s others...", { count: overflowCount });
|
|
|
|
return (
|
|
|
|
<EntityTile className="mx_EntityTile_ellipsis" avatarJsx={
|
|
|
|
<BaseAvatar url="img/ellipsis.svg" name="..." width={36} height={36} />
|
|
|
|
} name={text} presenceState="online" suppressOnHover={true}
|
|
|
|
onClick={this._showFullMemberList} />
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
_showFullMemberList: function() {
|
|
|
|
this.setState({
|
2017-08-21 18:30:28 +00:00
|
|
|
truncateAt: -1,
|
2017-07-25 14:56:16 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onSearchQueryChanged: function(ev) {
|
|
|
|
this.setState({ searchQuery: ev.target.value });
|
|
|
|
},
|
|
|
|
|
2017-10-16 15:38:32 +00:00
|
|
|
makeGroupMemberTiles: function(query, memberList) {
|
2017-07-25 14:56:16 +00:00
|
|
|
const GroupMemberTile = sdk.getComponent("groups.GroupMemberTile");
|
2017-10-16 16:21:05 +00:00
|
|
|
const TruncatedList = sdk.getComponent("elements.TruncatedList");
|
2017-07-25 14:56:16 +00:00
|
|
|
query = (query || "").toLowerCase();
|
2017-08-25 11:10:13 +00:00
|
|
|
if (query) {
|
|
|
|
memberList = memberList.filter((m) => {
|
2017-09-22 13:52:52 +00:00
|
|
|
const matchesName = m.displayname.toLowerCase().indexOf(query) !== -1;
|
2017-08-25 11:10:13 +00:00
|
|
|
const matchesId = m.userId.toLowerCase().includes(query);
|
2017-07-25 14:56:16 +00:00
|
|
|
|
2017-09-22 13:52:52 +00:00
|
|
|
if (!matchesName && !matchesId) {
|
2017-07-25 14:56:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-25 11:10:13 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-24 08:58:45 +00:00
|
|
|
memberList = memberList.map((m, index) => {
|
2017-07-25 14:56:16 +00:00
|
|
|
return (
|
2017-10-24 08:58:45 +00:00
|
|
|
<GroupMemberTile key={index} groupId={this.props.groupId} member={m} />
|
2017-07-25 14:56:16 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
memberList.sort((a, b) => {
|
2017-08-25 11:10:13 +00:00
|
|
|
// TODO: should put admins at the top: we don't yet have that info
|
2017-07-25 14:56:16 +00:00
|
|
|
if (a < b) {
|
|
|
|
return -1;
|
|
|
|
} else if (a > b) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-16 16:21:05 +00:00
|
|
|
return <TruncatedList className="mx_MemberList_wrapper" truncateAt={this.state.truncateAt}
|
|
|
|
createOverflowElement={this._createOverflowTile}
|
|
|
|
>
|
|
|
|
{ memberList }
|
|
|
|
</TruncatedList>;
|
2017-07-25 14:56:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2017-10-16 16:21:05 +00:00
|
|
|
if (this.state.fetching || this.state.fetchingInvitedMembers) {
|
2017-07-25 14:56:16 +00:00
|
|
|
const Spinner = sdk.getComponent("elements.Spinner");
|
2017-09-27 09:36:44 +00:00
|
|
|
return (<div className="mx_MemberList">
|
|
|
|
<Spinner />
|
|
|
|
</div>);
|
2017-07-25 14:56:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const inputBox = (
|
|
|
|
<form autoComplete="off">
|
2017-09-26 13:49:13 +00:00
|
|
|
<input className="mx_GroupMemberList_query" id="mx_GroupMemberList_query" type="text"
|
2017-07-25 14:56:16 +00:00
|
|
|
onChange={this.onSearchQueryChanged} value={this.state.searchQuery}
|
2017-10-19 14:01:16 +00:00
|
|
|
placeholder={_t('Filter community members')} />
|
2017-07-25 14:56:16 +00:00
|
|
|
</form>
|
|
|
|
);
|
|
|
|
|
2017-10-16 16:21:05 +00:00
|
|
|
const joined = this.state.members ? <div className="mx_MemberList_joined">
|
|
|
|
{ this.makeGroupMemberTiles(this.state.searchQuery, this.state.members) }
|
|
|
|
</div> : <div />;
|
|
|
|
|
2017-10-17 08:49:39 +00:00
|
|
|
const invited = (this.state.invitedMembers && this.state.invitedMembers.length > 0) ?
|
2017-10-16 16:59:53 +00:00
|
|
|
<div className="mx_MemberList_invited">
|
|
|
|
<h2>{ _t("Invited") }</h2>
|
|
|
|
{ this.makeGroupMemberTiles(this.state.searchQuery, this.state.invitedMembers) }
|
|
|
|
</div> : <div />;
|
2017-10-16 16:21:05 +00:00
|
|
|
|
2017-07-25 14:56:16 +00:00
|
|
|
return (
|
|
|
|
<div className="mx_MemberList">
|
|
|
|
{ inputBox }
|
2017-10-16 15:38:32 +00:00
|
|
|
<GeminiScrollbar autoshow={true} className="mx_MemberList_outerWrapper">
|
2017-10-16 16:21:05 +00:00
|
|
|
{ joined }
|
|
|
|
{ invited }
|
2017-07-25 14:56:16 +00:00
|
|
|
</GeminiScrollbar>
|
|
|
|
</div>
|
|
|
|
);
|
2017-08-21 18:34:07 +00:00
|
|
|
},
|
2017-07-25 14:56:16 +00:00
|
|
|
}));
|