2017-07-25 17:56:16 +03:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd.
|
2017-08-25 14:10:13 +03:00
|
|
|
Copyright 2017 New Vector Ltd.
|
2019-12-06 09:34:44 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2017-07-25 17:56:16 +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.
|
|
|
|
*/
|
|
|
|
import React from 'react';
|
2019-09-06 20:35:52 +03:00
|
|
|
import createReactClass from 'create-react-class';
|
2017-07-25 17:56:16 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
|
|
|
import sdk from '../../../index';
|
2018-12-11 13:09:11 +03:00
|
|
|
import dis from '../../../dispatcher';
|
2018-05-01 13:18:45 +03:00
|
|
|
import GroupStore from '../../../stores/GroupStore';
|
2017-07-25 17:56:16 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2018-12-10 19:21:55 +03:00
|
|
|
import { showGroupInviteDialog } from '../../../GroupAddressPicker';
|
|
|
|
import AccessibleButton from '../elements/AccessibleButton';
|
|
|
|
import TintableSvg from '../elements/TintableSvg';
|
2019-12-06 09:34:44 +03:00
|
|
|
import {RIGHT_PANEL_PHASES} from "../../../stores/RightPanelStorePhases";
|
2017-07-25 17:56:16 +03:00
|
|
|
|
|
|
|
const INITIAL_LOAD_NUM_MEMBERS = 30;
|
|
|
|
|
2019-09-06 20:35:52 +03:00
|
|
|
export default createReactClass({
|
2017-07-25 17:56:16 +03:00
|
|
|
displayName: 'GroupMemberList',
|
|
|
|
|
2017-10-23 18:04:26 +03:00
|
|
|
propTypes: {
|
2017-07-25 17:56:16 +03:00
|
|
|
groupId: PropTypes.string.isRequired,
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
members: null,
|
2018-12-05 01:42:50 +03:00
|
|
|
membersError: null,
|
2017-10-16 19:21:05 +03:00
|
|
|
invitedMembers: null,
|
2018-12-05 01:42:50 +03:00
|
|
|
invitedMembersError: null,
|
2017-08-21 21:30:28 +03:00
|
|
|
truncateAt: INITIAL_LOAD_NUM_MEMBERS,
|
|
|
|
};
|
2017-07-25 17:56:16 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount: function() {
|
|
|
|
this._unmounted = false;
|
2017-10-23 18:04:26 +03:00
|
|
|
this._initGroupStore(this.props.groupId);
|
2017-07-25 17:56:16 +03:00
|
|
|
},
|
|
|
|
|
2018-05-01 13:18:45 +03:00
|
|
|
componentWillUnmount: function() {
|
|
|
|
this._unmounted = true;
|
|
|
|
},
|
|
|
|
|
2017-10-23 18:04:26 +03:00
|
|
|
_initGroupStore: function(groupId) {
|
2018-05-01 13:18:45 +03:00
|
|
|
GroupStore.registerListener(groupId, () => {
|
2017-10-23 18:04:26 +03:00
|
|
|
this._fetchMembers();
|
2017-10-16 19:21:05 +03:00
|
|
|
});
|
2018-12-05 01:42:50 +03:00
|
|
|
GroupStore.on('error', (err, errorGroupId, stateKey) => {
|
|
|
|
if (this._unmounted || groupId !== errorGroupId) return;
|
|
|
|
if (stateKey === GroupStore.STATE_KEY.GroupMembers) {
|
|
|
|
this.setState({
|
|
|
|
membersError: err,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (stateKey === GroupStore.STATE_KEY.GroupInvitedMembers) {
|
|
|
|
this.setState({
|
|
|
|
invitedMembersError: err,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2017-10-23 18:04:26 +03:00
|
|
|
},
|
2017-10-16 18:38:32 +03:00
|
|
|
|
2017-10-23 18:04:26 +03:00
|
|
|
_fetchMembers: function() {
|
2017-10-24 11:58:45 +03:00
|
|
|
if (this._unmounted) return;
|
2017-10-23 18:04:26 +03:00
|
|
|
this.setState({
|
2018-05-01 13:18:45 +03:00
|
|
|
members: GroupStore.getGroupMembers(this.props.groupId),
|
|
|
|
invitedMembers: GroupStore.getGroupInvitedMembers(this.props.groupId),
|
2017-10-16 18:38:32 +03:00
|
|
|
});
|
2017-07-25 17:56:16 +03: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={
|
2019-01-11 04:37:28 +03:00
|
|
|
<BaseAvatar url={require("../../../../res/img/ellipsis.svg")} name="..." width={36} height={36} />
|
2017-07-25 17:56:16 +03:00
|
|
|
} name={text} presenceState="online" suppressOnHover={true}
|
|
|
|
onClick={this._showFullMemberList} />
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
_showFullMemberList: function() {
|
|
|
|
this.setState({
|
2017-08-21 21:30:28 +03:00
|
|
|
truncateAt: -1,
|
2017-07-25 17:56:16 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onSearchQueryChanged: function(ev) {
|
|
|
|
this.setState({ searchQuery: ev.target.value });
|
|
|
|
},
|
|
|
|
|
2018-12-05 01:42:50 +03:00
|
|
|
makeGroupMemberTiles: function(query, memberList, memberListError) {
|
|
|
|
if (memberListError) {
|
|
|
|
return <div className="warning">{ _t("Failed to load group members") }</div>;
|
|
|
|
}
|
|
|
|
|
2017-07-25 17:56:16 +03:00
|
|
|
const GroupMemberTile = sdk.getComponent("groups.GroupMemberTile");
|
2017-10-16 19:21:05 +03:00
|
|
|
const TruncatedList = sdk.getComponent("elements.TruncatedList");
|
2017-07-25 17:56:16 +03:00
|
|
|
query = (query || "").toLowerCase();
|
2017-08-25 14:10:13 +03:00
|
|
|
if (query) {
|
|
|
|
memberList = memberList.filter((m) => {
|
2017-11-20 19:02:20 +03:00
|
|
|
const matchesName = (m.displayname || "").toLowerCase().includes(query);
|
2017-08-25 14:10:13 +03:00
|
|
|
const matchesId = m.userId.toLowerCase().includes(query);
|
2017-07-25 17:56:16 +03:00
|
|
|
|
2017-09-22 16:52:52 +03:00
|
|
|
if (!matchesName && !matchesId) {
|
2017-07-25 17:56:16 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-25 14:10:13 +03:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-24 12:50:31 +03:00
|
|
|
const uniqueMembers = {};
|
|
|
|
memberList.forEach((m) => {
|
|
|
|
if (!uniqueMembers[m.userId]) uniqueMembers[m.userId] = m;
|
2017-07-25 17:56:16 +03:00
|
|
|
});
|
2017-10-24 12:50:31 +03:00
|
|
|
memberList = Object.keys(uniqueMembers).map((userId) => uniqueMembers[userId]);
|
2017-11-08 14:51:58 +03:00
|
|
|
// Descending sort on isPrivileged = true = 1 to isPrivileged = false = 0
|
2017-07-25 17:56:16 +03:00
|
|
|
memberList.sort((a, b) => {
|
2017-11-08 16:57:38 +03:00
|
|
|
if (a.isPrivileged === b.isPrivileged) {
|
|
|
|
const aName = a.displayname || a.userId;
|
|
|
|
const bName = b.displayname || b.userId;
|
|
|
|
if (aName < bName) {
|
|
|
|
return -1;
|
|
|
|
} else if (aName > bName) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return a.isPrivileged ? -1 : 1;
|
|
|
|
}
|
2017-07-25 17:56:16 +03:00
|
|
|
});
|
|
|
|
|
2017-10-24 12:50:31 +03:00
|
|
|
const memberTiles = memberList.map((m) => {
|
|
|
|
return (
|
|
|
|
<GroupMemberTile key={m.userId} groupId={this.props.groupId} member={m} />
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2017-10-16 19:21:05 +03:00
|
|
|
return <TruncatedList className="mx_MemberList_wrapper" truncateAt={this.state.truncateAt}
|
|
|
|
createOverflowElement={this._createOverflowTile}
|
|
|
|
>
|
2017-10-24 12:50:31 +03:00
|
|
|
{ memberTiles }
|
2017-10-16 19:21:05 +03:00
|
|
|
</TruncatedList>;
|
2017-07-25 17:56:16 +03:00
|
|
|
},
|
|
|
|
|
2018-12-10 19:21:55 +03:00
|
|
|
onInviteToGroupButtonClick() {
|
|
|
|
showGroupInviteDialog(this.props.groupId).then(() => {
|
|
|
|
dis.dispatch({
|
2019-12-06 09:34:44 +03:00
|
|
|
action: 'set_right_panel_phase',
|
|
|
|
phase: RIGHT_PANEL_PHASES.GroupMemberList,
|
2018-12-10 19:21:55 +03:00
|
|
|
groupId: this.props.groupId,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-07-25 17:56:16 +03:00
|
|
|
render: function() {
|
2018-03-21 15:00:56 +03:00
|
|
|
const GeminiScrollbarWrapper = sdk.getComponent("elements.GeminiScrollbarWrapper");
|
2017-10-16 19:21:05 +03:00
|
|
|
if (this.state.fetching || this.state.fetchingInvitedMembers) {
|
2017-07-25 17:56:16 +03:00
|
|
|
const Spinner = sdk.getComponent("elements.Spinner");
|
2017-09-27 12:36:44 +03:00
|
|
|
return (<div className="mx_MemberList">
|
|
|
|
<Spinner />
|
|
|
|
</div>);
|
2017-07-25 17:56:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const inputBox = (
|
2018-12-10 19:45:30 +03:00
|
|
|
<input className="mx_GroupMemberList_query mx_textinput" id="mx_GroupMemberList_query" type="text"
|
|
|
|
onChange={this.onSearchQueryChanged} value={this.state.searchQuery}
|
2018-12-11 12:54:36 +03:00
|
|
|
placeholder={_t('Filter community members')} autoComplete="off" />
|
2017-07-25 17:56:16 +03:00
|
|
|
);
|
|
|
|
|
2017-10-16 19:21:05 +03:00
|
|
|
const joined = this.state.members ? <div className="mx_MemberList_joined">
|
2018-12-05 01:42:50 +03:00
|
|
|
{
|
|
|
|
this.makeGroupMemberTiles(
|
|
|
|
this.state.searchQuery,
|
|
|
|
this.state.members,
|
|
|
|
this.state.membersError,
|
|
|
|
)
|
|
|
|
}
|
2017-10-16 19:21:05 +03:00
|
|
|
</div> : <div />;
|
|
|
|
|
2017-10-17 11:49:39 +03:00
|
|
|
const invited = (this.state.invitedMembers && this.state.invitedMembers.length > 0) ?
|
2017-10-16 19:59:53 +03:00
|
|
|
<div className="mx_MemberList_invited">
|
2018-12-05 01:42:50 +03:00
|
|
|
<h2>{_t("Invited")}</h2>
|
|
|
|
{
|
|
|
|
this.makeGroupMemberTiles(
|
|
|
|
this.state.searchQuery,
|
|
|
|
this.state.invitedMembers,
|
|
|
|
this.state.invitedMembersError,
|
|
|
|
)
|
|
|
|
}
|
2017-10-16 19:59:53 +03:00
|
|
|
</div> : <div />;
|
2017-10-16 19:21:05 +03:00
|
|
|
|
2018-12-10 19:21:55 +03:00
|
|
|
let inviteButton;
|
|
|
|
if (GroupStore.isUserPrivileged(this.props.groupId)) {
|
2018-12-11 13:09:11 +03:00
|
|
|
inviteButton = (
|
|
|
|
<AccessibleButton
|
|
|
|
className="mx_RightPanel_invite"
|
|
|
|
onClick={this.onInviteToGroupButtonClick}
|
|
|
|
>
|
2018-12-10 19:21:55 +03:00
|
|
|
<div className="mx_RightPanel_icon" >
|
2019-01-11 04:37:28 +03:00
|
|
|
<TintableSvg src={require("../../../../res/img/icon-invite-people.svg")} width="18" height="14" />
|
2018-12-10 19:21:55 +03:00
|
|
|
</div>
|
|
|
|
<div className="mx_RightPanel_message">{ _t('Invite to this community') }</div>
|
|
|
|
</AccessibleButton>);
|
|
|
|
}
|
|
|
|
|
2017-07-25 17:56:16 +03:00
|
|
|
return (
|
2019-10-03 11:35:39 +03:00
|
|
|
<div className="mx_MemberList" role="tabpanel">
|
2018-12-10 19:21:55 +03:00
|
|
|
{ inviteButton }
|
2018-10-23 00:14:21 +03:00
|
|
|
<GeminiScrollbarWrapper autoshow={true}>
|
2017-10-16 19:21:05 +03:00
|
|
|
{ joined }
|
|
|
|
{ invited }
|
2018-03-21 15:00:56 +03:00
|
|
|
</GeminiScrollbarWrapper>
|
2018-12-10 19:21:55 +03:00
|
|
|
{ inputBox }
|
2017-07-25 17:56:16 +03:00
|
|
|
</div>
|
|
|
|
);
|
2017-08-21 21:34:07 +03:00
|
|
|
},
|
2017-11-28 14:54:05 +03:00
|
|
|
});
|