2017-08-04 17:00:34 +03:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
2017-08-25 14:10:13 +03:00
|
|
|
Copyright 2017 New Vector Ltd
|
2017-08-04 17:00:34 +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 PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import dis from '../../../dispatcher';
|
|
|
|
import Modal from '../../../Modal';
|
|
|
|
import sdk from '../../../index';
|
|
|
|
import { _t } from '../../../languageHandler';
|
|
|
|
import { GroupMemberType } from '../../../groups';
|
2017-08-09 20:15:31 +03:00
|
|
|
import { groupMemberFromApiObject } from '../../../groups';
|
2017-08-04 17:00:34 +03:00
|
|
|
import withMatrixClient from '../../../wrappers/withMatrixClient';
|
|
|
|
import AccessibleButton from '../elements/AccessibleButton';
|
|
|
|
import GeminiScrollbar from 'react-gemini-scrollbar';
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = withMatrixClient(React.createClass({
|
|
|
|
displayName: 'GroupMemberInfo',
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
matrixClient: PropTypes.object.isRequired,
|
|
|
|
groupId: PropTypes.string,
|
2017-08-25 14:10:13 +03:00
|
|
|
groupMember: GroupMemberType,
|
2017-08-04 17:00:34 +03:00
|
|
|
},
|
|
|
|
|
2017-08-21 21:18:32 +03:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
fetching: false,
|
|
|
|
removingUser: false,
|
2017-08-25 14:10:13 +03:00
|
|
|
groupMembers: null,
|
2017-08-21 21:34:07 +03:00
|
|
|
};
|
2017-08-21 21:18:32 +03:00
|
|
|
},
|
|
|
|
|
2017-08-04 17:00:34 +03:00
|
|
|
componentWillMount: function() {
|
|
|
|
this._fetchMembers();
|
|
|
|
},
|
|
|
|
|
|
|
|
_fetchMembers: function() {
|
|
|
|
this.setState({fetching: true});
|
|
|
|
this.props.matrixClient.getGroupUsers(this.props.groupId).then((result) => {
|
|
|
|
this.setState({
|
2017-08-25 14:10:13 +03:00
|
|
|
groupMembers: result.chunk.map((apiMember) => {
|
2017-08-09 20:15:31 +03:00
|
|
|
return groupMemberFromApiObject(apiMember);
|
|
|
|
}),
|
2017-08-04 17:00:34 +03:00
|
|
|
fetching: false,
|
|
|
|
});
|
|
|
|
}).catch((e) => {
|
|
|
|
this.setState({fetching: false});
|
2017-08-25 14:10:13 +03:00
|
|
|
console.error("Failed to get group groupMember list: ", e);
|
2017-08-04 17:00:34 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_onKick: function() {
|
|
|
|
const ConfirmUserActionDialog = sdk.getComponent("dialogs.ConfirmUserActionDialog");
|
|
|
|
Modal.createDialog(ConfirmUserActionDialog, {
|
2017-08-25 14:10:13 +03:00
|
|
|
groupMember: this.props.groupMember,
|
2017-08-04 17:00:34 +03:00
|
|
|
action: _t('Remove from group'),
|
|
|
|
danger: true,
|
|
|
|
onFinished: (proceed) => {
|
2017-08-21 21:18:32 +03:00
|
|
|
if (!proceed) return;
|
|
|
|
|
|
|
|
this.setState({removingUser: true});
|
2017-08-25 14:10:13 +03:00
|
|
|
this.props.matrixClient.removeUserFromGroup(this.props.groupId, this.props.groupMember.userId).then(() => {
|
|
|
|
// return to the user list
|
2017-08-21 21:18:32 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: "view_user",
|
2017-08-30 11:22:26 +03:00
|
|
|
member: null,
|
2017-08-21 21:18:32 +03:00
|
|
|
});
|
|
|
|
}).catch((e) => {
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createTrackedDialog('Failed to remove user from group', '', ErrorDialog, {
|
|
|
|
title: _t('Error'),
|
|
|
|
description: _t('Failed to remove user from group'),
|
|
|
|
});
|
|
|
|
}).finally(() => {
|
|
|
|
this.setState({removingUser: false});
|
|
|
|
});
|
2017-08-04 17:00:34 +03:00
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-08-21 21:18:32 +03:00
|
|
|
_onCancel: function(e) {
|
2017-08-25 14:10:13 +03:00
|
|
|
// Go back to the user list
|
2017-08-04 17:00:34 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: "view_user",
|
2017-08-30 11:22:26 +03:00
|
|
|
member: null,
|
2017-08-04 17:00:34 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onRoomTileClick(roomId) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
|
|
|
room_id: roomId,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2017-08-21 21:18:32 +03:00
|
|
|
if (this.state.fetching || this.state.removingUser) {
|
2017-08-25 14:10:13 +03:00
|
|
|
const Spinner = sdk.getComponent("elements.Spinner");
|
|
|
|
return <Spinner />;
|
2017-08-04 17:00:34 +03:00
|
|
|
}
|
2017-08-25 14:10:13 +03:00
|
|
|
if (!this.state.groupMembers) return null;
|
2017-08-04 17:00:34 +03:00
|
|
|
|
2017-08-25 14:10:13 +03:00
|
|
|
const targetIsInGroup = this.state.groupMembers.some((m) => {
|
2017-08-30 11:22:26 +03:00
|
|
|
return m.userId === this.props.groupMember.userId;
|
2017-08-25 14:10:13 +03:00
|
|
|
});
|
2017-08-04 17:00:34 +03:00
|
|
|
|
2017-08-21 21:34:07 +03:00
|
|
|
let kickButton;
|
|
|
|
let adminButton;
|
2017-08-04 17:00:34 +03:00
|
|
|
|
|
|
|
if (targetIsInGroup) {
|
|
|
|
kickButton = (
|
|
|
|
<AccessibleButton className="mx_MemberInfo_field"
|
|
|
|
onClick={this._onKick}>
|
|
|
|
{_t('Remove from group')}
|
|
|
|
</AccessibleButton>
|
|
|
|
);
|
|
|
|
|
|
|
|
// No make/revoke admin API yet
|
|
|
|
/*const opLabel = this.state.isTargetMod ? _t("Revoke Moderator") : _t("Make Moderator");
|
|
|
|
giveModButton = <AccessibleButton className="mx_MemberInfo_field" onClick={this.onModToggle}>
|
|
|
|
{giveOpLabel}
|
|
|
|
</AccessibleButton>;*/
|
|
|
|
}
|
|
|
|
|
|
|
|
let adminTools;
|
|
|
|
if (kickButton || adminButton) {
|
|
|
|
adminTools =
|
2017-08-25 14:10:13 +03:00
|
|
|
<div className="mx_MemberInfo_adminTools">
|
|
|
|
<h3>{_t("Admin Tools")}</h3>
|
2017-08-04 17:00:34 +03:00
|
|
|
|
|
|
|
<div className="mx_MemberInfo_buttons">
|
|
|
|
{kickButton}
|
|
|
|
{adminButton}
|
|
|
|
</div>
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
const BaseAvatar = sdk.getComponent('avatars.BaseAvatar');
|
|
|
|
const avatar = (
|
2017-08-25 14:10:13 +03:00
|
|
|
<BaseAvatar name={this.props.groupMember.userId} width={36} height={36} />
|
2017-08-04 17:00:34 +03:00
|
|
|
);
|
|
|
|
|
2017-08-25 14:10:13 +03:00
|
|
|
const groupMemberName = this.props.groupMember.userId;
|
2017-08-04 17:00:34 +03:00
|
|
|
|
|
|
|
const EmojiText = sdk.getComponent('elements.EmojiText');
|
|
|
|
return (
|
|
|
|
<div className="mx_MemberInfo">
|
|
|
|
<GeminiScrollbar autoshow={true}>
|
2017-08-25 14:10:13 +03:00
|
|
|
<AccessibleButton className="mx_MemberInfo_cancel"onClick={this._onCancel}>
|
|
|
|
<img src="img/cancel.svg" width="18" height="18"/>
|
|
|
|
</AccessibleButton>
|
2017-08-04 17:00:34 +03:00
|
|
|
<div className="mx_MemberInfo_avatar">
|
|
|
|
{avatar}
|
|
|
|
</div>
|
|
|
|
|
2017-08-25 14:10:13 +03:00
|
|
|
<EmojiText element="h2">{groupMemberName}</EmojiText>
|
2017-08-04 17:00:34 +03:00
|
|
|
|
|
|
|
<div className="mx_MemberInfo_profile">
|
|
|
|
<div className="mx_MemberInfo_profileField">
|
2017-08-25 14:10:13 +03:00
|
|
|
{ this.props.groupMember.userId }
|
2017-08-04 17:00:34 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{ adminTools }
|
|
|
|
</GeminiScrollbar>
|
|
|
|
</div>
|
|
|
|
);
|
2017-08-21 21:34:07 +03:00
|
|
|
},
|
2017-08-04 17:00:34 +03:00
|
|
|
}));
|